2 * collectd - src/netapp.c
3 * Copyright (C) 2009,2010 Sven Trenkel
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Sven Trenkel <collectd at semidefinite.de>
29 #include "utils_ignorelist.h"
31 #include <netapp_api.h>
32 #include <netapp_errno.h>
34 #define HAS_ALL_FLAGS(has,needs) (((has) & (needs)) == (needs))
36 typedef struct host_config_s host_config_t;
37 typedef void service_handler_t(host_config_t *host, na_elem_t *result, void *data);
44 typedef struct cna_interval_s cna_interval_t;
46 /*! Data types for WAFL statistics {{{
48 * \brief Persistent data for WAFL performance counters. (a.k.a. cache performance)
50 * The cache counters use old counter values to calculate a hit ratio for each
51 * counter. The "cfg_wafl_t" struct therefore contains old counter values along
52 * with flags, which are set if the counter is valid.
54 * The function "cna_handle_wafl_data" will fill a new structure of this kind
55 * with new values, then pass both, new and old data, to "submit_wafl_data".
56 * That function calculates the hit ratios, submits the calculated values and
57 * updates the old counter values for the next iteration.
59 #define CFG_WAFL_NAME_CACHE 0x0001
60 #define CFG_WAFL_DIR_CACHE 0x0002
61 #define CFG_WAFL_BUF_CACHE 0x0004
62 #define CFG_WAFL_INODE_CACHE 0x0008
63 #define CFG_WAFL_ALL 0x000F
64 #define HAVE_WAFL_NAME_CACHE_HIT 0x0100
65 #define HAVE_WAFL_NAME_CACHE_MISS 0x0200
66 #define HAVE_WAFL_NAME_CACHE (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
67 #define HAVE_WAFL_FIND_DIR_HIT 0x0400
68 #define HAVE_WAFL_FIND_DIR_MISS 0x0800
69 #define HAVE_WAFL_FIND_DIR (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
70 #define HAVE_WAFL_BUF_HASH_HIT 0x1000
71 #define HAVE_WAFL_BUF_HASH_MISS 0x2000
72 #define HAVE_WAFL_BUF_HASH (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
73 #define HAVE_WAFL_INODE_CACHE_HIT 0x4000
74 #define HAVE_WAFL_INODE_CACHE_MISS 0x8000
75 #define HAVE_WAFL_INODE_CACHE (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
76 #define HAVE_WAFL_ALL 0xff00
79 cna_interval_t interval;
83 uint64_t name_cache_hit;
84 uint64_t name_cache_miss;
85 uint64_t find_dir_hit;
86 uint64_t find_dir_miss;
87 uint64_t buf_hash_hit;
88 uint64_t buf_hash_miss;
89 uint64_t inode_cache_hit;
90 uint64_t inode_cache_miss;
94 /*! Data types for disk statistics {{{
96 * \brief A disk in the NetApp.
98 * A disk doesn't have any more information than its name at the moment.
99 * The name includes the "disk_" prefix.
101 #define HAVE_DISK_BUSY 0x10
102 #define HAVE_DISK_BASE 0x20
103 #define HAVE_DISK_ALL 0x30
104 typedef struct disk_s {
109 uint64_t base_for_disk_busy;
110 double disk_busy_percent;
114 #define CFG_DISK_BUSIEST 0x01
115 #define CFG_DISK_ALL 0x01
118 cna_interval_t interval;
124 /*! Data types for volume performance statistics {{{
126 * \brief Persistent data for volume performance data.
128 * The code below uses the difference of the operations and latency counters to
129 * calculate an average per-operation latency. For this, old counters need to
130 * be stored in the "data_volume_perf_t" structure. The byte-counters are just
131 * kept for completeness sake. The "flags" member indicates if each counter is
134 * The "cna_handle_volume_perf_data" function will fill a new struct of this
135 * type and pass both, old and new data, to "submit_volume_perf_data". In that
136 * function, the per-operation latency is calculated and dispatched, then the
137 * old counters are updated.
139 #define CFG_VOLUME_PERF_INIT 0x0001
140 #define CFG_VOLUME_PERF_IO 0x0002
141 #define CFG_VOLUME_PERF_OPS 0x0003
142 #define CFG_VOLUME_PERF_LATENCY 0x0008
143 #define CFG_VOLUME_PERF_ALL 0x000F
144 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
145 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
146 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
147 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
148 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
149 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
150 #define HAVE_VOLUME_PERF_ALL 0x03F0
151 struct data_volume_perf_s;
152 typedef struct data_volume_perf_s data_volume_perf_t;
153 struct data_volume_perf_s {
159 uint64_t write_bytes;
162 uint64_t read_latency;
163 uint64_t write_latency;
165 data_volume_perf_t *next;
169 cna_interval_t interval;
172 ignorelist_t *il_octets;
173 ignorelist_t *il_operations;
174 ignorelist_t *il_latency;
176 data_volume_perf_t *volumes;
178 /* }}} data_volume_perf_t */
180 /*! Data types for volume usage statistics {{{
182 * \brief Configuration struct for volume usage data (free / used).
184 #define CFG_VOLUME_USAGE_DF 0x0002
185 #define CFG_VOLUME_USAGE_SNAP 0x0004
186 #define CFG_VOLUME_USAGE_ALL 0x0006
187 #define HAVE_VOLUME_USAGE_NORM_FREE 0x0010
188 #define HAVE_VOLUME_USAGE_NORM_USED 0x0020
189 #define HAVE_VOLUME_USAGE_SNAP_RSVD 0x0040
190 #define HAVE_VOLUME_USAGE_SNAP_USED 0x0080
191 #define HAVE_VOLUME_USAGE_SIS_SAVED 0x0100
192 #define HAVE_VOLUME_USAGE_ALL 0x01f0
193 #define IS_VOLUME_USAGE_OFFLINE 0x0200
194 struct data_volume_usage_s;
195 typedef struct data_volume_usage_s data_volume_usage_t;
196 struct data_volume_usage_s {
200 na_elem_t *snap_query;
204 uint64_t snap_reserved;
208 data_volume_usage_t *next;
212 cna_interval_t interval;
215 ignorelist_t *il_capacity;
216 ignorelist_t *il_snapshot;
218 data_volume_usage_t *volumes;
219 } cfg_volume_usage_t;
220 /* }}} cfg_volume_usage_t */
222 /*! Data types for SnapVault statistics {{{
224 * \brief Persistent data for SnapVault(R) statistics
227 cna_interval_t interval;
230 /* }}} cfg_snapvault_t */
232 /*! Data types for system statistics {{{
234 * \brief Persistent data for system performance counters
236 #define CFG_SYSTEM_CPU 0x01
237 #define CFG_SYSTEM_NET 0x02
238 #define CFG_SYSTEM_OPS 0x04
239 #define CFG_SYSTEM_DISK 0x08
240 #define CFG_SYSTEM_ALL 0x0F
243 cna_interval_t interval;
246 /* }}} cfg_system_t */
248 struct host_config_s {
250 na_server_transport_t protocol;
259 cfg_wafl_t *cfg_wafl;
260 cfg_disk_t *cfg_disk;
261 cfg_volume_perf_t *cfg_volume_perf;
262 cfg_volume_usage_t *cfg_volume_usage;
263 cfg_snapvault_t *cfg_snapvault;
264 cfg_system_t *cfg_system;
266 struct host_config_s *next;
272 * Used to free the various structures above.
274 static void free_disk (disk_t *disk) /* {{{ */
287 } /* }}} void free_disk */
289 static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
294 if (cw->query != NULL)
295 na_elem_free (cw->query);
298 } /* }}} void free_cfg_wafl */
300 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
302 if (cfg_disk == NULL)
305 if (cfg_disk->query != NULL)
306 na_elem_free (cfg_disk->query);
308 free_disk (cfg_disk->disks);
310 } /* }}} void free_cfg_disk */
312 static void free_cfg_volume_perf (cfg_volume_perf_t *cvp) /* {{{ */
314 data_volume_perf_t *data;
319 /* Free the ignorelists */
320 ignorelist_free (cvp->il_octets);
321 ignorelist_free (cvp->il_operations);
322 ignorelist_free (cvp->il_latency);
324 /* Free the linked list of volumes */
328 data_volume_perf_t *next = data->next;
334 if (cvp->query != NULL)
335 na_elem_free (cvp->query);
338 } /* }}} void free_cfg_volume_perf */
340 static void free_cfg_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
342 data_volume_usage_t *data;
347 /* Free the ignorelists */
348 ignorelist_free (cvu->il_capacity);
349 ignorelist_free (cvu->il_snapshot);
351 /* Free the linked list of volumes */
355 data_volume_usage_t *next = data->next;
357 if (data->snap_query != NULL)
358 na_elem_free(data->snap_query);
363 if (cvu->query != NULL)
364 na_elem_free (cvu->query);
367 } /* }}} void free_cfg_volume_usage */
369 static void free_cfg_snapvault (cfg_snapvault_t *sv) /* {{{ */
374 if (sv->query != NULL)
375 na_elem_free (sv->query);
378 } /* }}} void free_cfg_snapvault */
380 static void free_cfg_system (cfg_system_t *cs) /* {{{ */
385 if (cs->query != NULL)
386 na_elem_free (cs->query);
389 } /* }}} void free_cfg_system */
391 static void free_host_config (host_config_t *hc) /* {{{ */
402 sfree (hc->username);
403 sfree (hc->password);
406 free_cfg_disk (hc->cfg_disk);
407 free_cfg_wafl (hc->cfg_wafl);
408 free_cfg_volume_perf (hc->cfg_volume_perf);
409 free_cfg_volume_usage (hc->cfg_volume_usage);
410 free_cfg_snapvault (hc->cfg_snapvault);
411 free_cfg_system (hc->cfg_system);
414 na_server_close (hc->srv);
418 free_host_config (next);
419 } /* }}} void free_host_config */
422 * Auxiliary functions
424 * Used to look up volumes and disks or to handle flags.
426 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
430 if ((cd == NULL) || (name == NULL))
433 for (d = cd->disks; d != NULL; d = d->next) {
434 if (strcmp(d->name, name) == 0)
438 d = malloc(sizeof(*d));
441 memset (d, 0, sizeof (*d));
444 d->name = strdup(name);
445 if (d->name == NULL) {
454 } /* }}} disk_t *get_disk */
456 static data_volume_usage_t *get_volume_usage (cfg_volume_usage_t *cvu, /* {{{ */
459 data_volume_usage_t *last;
460 data_volume_usage_t *new;
462 int ignore_capacity = 0;
463 int ignore_snapshot = 0;
465 if ((cvu == NULL) || (name == NULL))
471 if (strcmp (last->name, name) == 0)
474 if (last->next == NULL)
480 /* Check the ignorelists. If *both* tell us to ignore a volume, return NULL. */
481 ignore_capacity = ignorelist_match (cvu->il_capacity, name);
482 ignore_snapshot = ignorelist_match (cvu->il_snapshot, name);
483 if ((ignore_capacity != 0) && (ignore_snapshot != 0))
486 /* Not found: allocate. */
487 new = malloc (sizeof (*new));
490 memset (new, 0, sizeof (*new));
493 new->name = strdup (name);
494 if (new->name == NULL)
500 if (ignore_capacity == 0)
501 new->flags |= CFG_VOLUME_USAGE_DF;
502 if (ignore_snapshot == 0) {
503 new->flags |= CFG_VOLUME_USAGE_SNAP;
504 new->snap_query = na_elem_new ("snapshot-list-info");
505 na_child_add_string(new->snap_query, "target-type", "volume");
506 na_child_add_string(new->snap_query, "target-name", name);
508 new->snap_query = NULL;
511 /* Add to end of list. */
518 } /* }}} data_volume_usage_t *get_volume_usage */
520 static data_volume_perf_t *get_volume_perf (cfg_volume_perf_t *cvp, /* {{{ */
523 data_volume_perf_t *last;
524 data_volume_perf_t *new;
526 int ignore_octets = 0;
527 int ignore_operations = 0;
528 int ignore_latency = 0;
530 if ((cvp == NULL) || (name == NULL))
536 if (strcmp (last->name, name) == 0)
539 if (last->next == NULL)
545 /* Check the ignorelists. If *all three* tell us to ignore a volume, return
547 ignore_octets = ignorelist_match (cvp->il_octets, name);
548 ignore_operations = ignorelist_match (cvp->il_operations, name);
549 ignore_latency = ignorelist_match (cvp->il_latency, name);
550 if ((ignore_octets != 0) || (ignore_operations != 0)
551 || (ignore_latency != 0))
554 /* Not found: allocate. */
555 new = malloc (sizeof (*new));
558 memset (new, 0, sizeof (*new));
561 new->name = strdup (name);
562 if (new->name == NULL)
568 if (ignore_octets == 0)
569 new->flags |= CFG_VOLUME_PERF_IO;
570 if (ignore_operations == 0)
571 new->flags |= CFG_VOLUME_PERF_OPS;
572 if (ignore_latency == 0)
573 new->flags |= CFG_VOLUME_PERF_LATENCY;
575 /* Add to end of list. */
582 } /* }}} data_volume_perf_t *get_volume_perf */
585 * Various submit functions.
587 * They all eventually call "submit_values" which creates a value_list_t and
588 * dispatches it to the daemon.
590 static int submit_values (const char *host, /* {{{ */
591 const char *plugin_inst,
592 const char *type, const char *type_inst,
593 value_t *values, int values_len,
594 cdtime_t timestamp, cdtime_t interval)
596 value_list_t vl = VALUE_LIST_INIT;
599 vl.values_len = values_len;
605 vl.interval = interval;
608 sstrncpy (vl.host, host, sizeof (vl.host));
610 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
611 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
612 if (plugin_inst != NULL)
613 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
614 sstrncpy (vl.type, type, sizeof (vl.type));
615 if (type_inst != NULL)
616 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
618 return (plugin_dispatch_values (&vl));
619 } /* }}} int submit_uint64 */
621 static int submit_two_derive (const char *host, const char *plugin_inst, /* {{{ */
622 const char *type, const char *type_inst, derive_t val0, derive_t val1,
623 cdtime_t timestamp, cdtime_t interval)
627 values[0].derive = val0;
628 values[1].derive = val1;
630 return (submit_values (host, plugin_inst, type, type_inst,
631 values, 2, timestamp, interval));
632 } /* }}} int submit_two_derive */
634 static int submit_derive (const char *host, const char *plugin_inst, /* {{{ */
635 const char *type, const char *type_inst, derive_t counter,
636 cdtime_t timestamp, cdtime_t interval)
642 return (submit_values (host, plugin_inst, type, type_inst,
643 &v, 1, timestamp, interval));
644 } /* }}} int submit_derive */
646 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
647 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
648 cdtime_t timestamp, cdtime_t interval)
652 values[0].gauge = val0;
653 values[1].gauge = val1;
655 return (submit_values (host, plugin_inst, type, type_inst,
656 values, 2, timestamp, interval));
657 } /* }}} int submit_two_gauge */
659 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
660 const char *type, const char *type_inst, double d,
661 cdtime_t timestamp, cdtime_t interval)
665 v.gauge = (gauge_t) d;
667 return (submit_values (host, plugin_inst, type, type_inst,
668 &v, 1, timestamp, interval));
669 } /* }}} int submit_uint64 */
671 /* Calculate hit ratio from old and new counters and submit the resulting
672 * percentage. Used by "submit_wafl_data". */
673 static int submit_cache_ratio (const char *host, /* {{{ */
674 const char *plugin_inst,
675 const char *type_inst,
685 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
689 hits = new_hits - old_hits;
690 misses = new_misses - old_misses;
692 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
697 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
698 &v, 1, timestamp, interval));
699 } /* }}} int submit_cache_ratio */
701 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
702 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
703 cfg_wafl_t *old_data, const cfg_wafl_t *new_data, int interval)
705 /* Submit requested counters */
706 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
707 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
708 submit_cache_ratio (hostname, instance, "name_cache_hit",
709 new_data->name_cache_hit, new_data->name_cache_miss,
710 old_data->name_cache_hit, old_data->name_cache_miss,
711 new_data->timestamp, interval);
713 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
714 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
715 submit_cache_ratio (hostname, instance, "find_dir_hit",
716 new_data->find_dir_hit, new_data->find_dir_miss,
717 old_data->find_dir_hit, old_data->find_dir_miss,
718 new_data->timestamp, interval);
720 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
721 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
722 submit_cache_ratio (hostname, instance, "buf_hash_hit",
723 new_data->buf_hash_hit, new_data->buf_hash_miss,
724 old_data->buf_hash_hit, old_data->buf_hash_miss,
725 new_data->timestamp, interval);
727 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
728 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
729 submit_cache_ratio (hostname, instance, "inode_cache_hit",
730 new_data->inode_cache_hit, new_data->inode_cache_miss,
731 old_data->inode_cache_hit, old_data->inode_cache_miss,
732 new_data->timestamp, interval);
734 /* Clear old HAVE_* flags */
735 old_data->flags &= ~HAVE_WAFL_ALL;
737 /* Copy all counters */
738 old_data->timestamp = new_data->timestamp;
739 old_data->name_cache_hit = new_data->name_cache_hit;
740 old_data->name_cache_miss = new_data->name_cache_miss;
741 old_data->find_dir_hit = new_data->find_dir_hit;
742 old_data->find_dir_miss = new_data->find_dir_miss;
743 old_data->buf_hash_hit = new_data->buf_hash_hit;
744 old_data->buf_hash_miss = new_data->buf_hash_miss;
745 old_data->inode_cache_hit = new_data->inode_cache_hit;
746 old_data->inode_cache_miss = new_data->inode_cache_miss;
748 /* Copy HAVE_* flags */
749 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
752 } /* }}} int submit_wafl_data */
754 /* Submits volume performance data to the daemon, taking care to honor and
755 * update flags appropriately. */
756 static int submit_volume_perf_data (const char *hostname, /* {{{ */
757 data_volume_perf_t *old_data,
758 const data_volume_perf_t *new_data, int interval)
760 char plugin_instance[DATA_MAX_NAME_LEN];
762 if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
765 ssnprintf (plugin_instance, sizeof (plugin_instance),
766 "volume-%s", old_data->name);
768 /* Check for and submit disk-octet values */
769 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
770 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
772 submit_two_derive (hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
773 (derive_t) new_data->read_bytes, (derive_t) new_data->write_bytes, new_data->timestamp, interval);
776 /* Check for and submit disk-operations values */
777 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
778 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
780 submit_two_derive (hostname, plugin_instance, "disk_ops", /* type instance = */ NULL,
781 (derive_t) new_data->read_ops, (derive_t) new_data->write_ops, new_data->timestamp, interval);
784 /* Check for, calculate and submit disk-latency values */
785 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
786 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
787 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
788 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
789 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
791 gauge_t latency_per_op_read;
792 gauge_t latency_per_op_write;
794 latency_per_op_read = NAN;
795 latency_per_op_write = NAN;
797 /* Check if a counter wrapped around. */
798 if ((new_data->read_ops > old_data->read_ops)
799 && (new_data->read_latency > old_data->read_latency))
801 uint64_t diff_ops_read;
802 uint64_t diff_latency_read;
804 diff_ops_read = new_data->read_ops - old_data->read_ops;
805 diff_latency_read = new_data->read_latency - old_data->read_latency;
807 if (diff_ops_read > 0)
808 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
811 if ((new_data->write_ops > old_data->write_ops)
812 && (new_data->write_latency > old_data->write_latency))
814 uint64_t diff_ops_write;
815 uint64_t diff_latency_write;
817 diff_ops_write = new_data->write_ops - old_data->write_ops;
818 diff_latency_write = new_data->write_latency - old_data->write_latency;
820 if (diff_ops_write > 0)
821 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
824 submit_two_gauge (hostname, plugin_instance, "disk_latency", /* type instance = */ NULL,
825 latency_per_op_read, latency_per_op_write, new_data->timestamp, interval);
828 /* Clear all HAVE_* flags. */
829 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
831 /* Copy all counters */
832 old_data->timestamp = new_data->timestamp;
833 old_data->read_bytes = new_data->read_bytes;
834 old_data->write_bytes = new_data->write_bytes;
835 old_data->read_ops = new_data->read_ops;
836 old_data->write_ops = new_data->write_ops;
837 old_data->read_latency = new_data->read_latency;
838 old_data->write_latency = new_data->write_latency;
840 /* Copy the HAVE_* flags */
841 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
844 } /* }}} int submit_volume_perf_data */
846 static cdtime_t cna_child_get_cdtime (na_elem_t *data) /* {{{ */
850 t = (time_t) na_child_get_uint64 (data, "timestamp", /* default = */ 0);
852 return (TIME_T_TO_CDTIME_T (t));
853 } /* }}} cdtime_t cna_child_get_cdtime */
859 * These functions are called with appropriate data returned by the libnetapp
860 * interface which is parsed and submitted with the above functions.
862 /* Data corresponding to <WAFL /> */
863 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
864 na_elem_t *data, int interval)
866 cfg_wafl_t perf_data;
867 const char *plugin_inst;
869 na_elem_t *instances;
871 na_elem_iter_t counter_iter;
873 memset (&perf_data, 0, sizeof (perf_data));
875 perf_data.timestamp = cna_child_get_cdtime (data);
877 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
878 if (instances == NULL)
880 ERROR ("netapp plugin: cna_handle_wafl_data: "
881 "na_elem_child (\"instances\") failed "
882 "for host %s.", hostname);
886 plugin_inst = na_child_get_string(instances, "name");
887 if (plugin_inst == NULL)
889 ERROR ("netapp plugin: cna_handle_wafl_data: "
890 "na_child_get_string (\"name\") failed "
891 "for host %s.", hostname);
895 /* Iterate over all counters */
896 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
897 for (counter = na_iterator_next (&counter_iter);
899 counter = na_iterator_next (&counter_iter))
904 name = na_child_get_string(counter, "name");
908 value = na_child_get_uint64(counter, "value", UINT64_MAX);
909 if (value == UINT64_MAX)
912 if (!strcmp(name, "name_cache_hit")) {
913 perf_data.name_cache_hit = value;
914 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
915 } else if (!strcmp(name, "name_cache_miss")) {
916 perf_data.name_cache_miss = value;
917 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
918 } else if (!strcmp(name, "find_dir_hit")) {
919 perf_data.find_dir_hit = value;
920 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
921 } else if (!strcmp(name, "find_dir_miss")) {
922 perf_data.find_dir_miss = value;
923 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
924 } else if (!strcmp(name, "buf_hash_hit")) {
925 perf_data.buf_hash_hit = value;
926 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
927 } else if (!strcmp(name, "buf_hash_miss")) {
928 perf_data.buf_hash_miss = value;
929 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
930 } else if (!strcmp(name, "inode_cache_hit")) {
931 perf_data.inode_cache_hit = value;
932 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
933 } else if (!strcmp(name, "inode_cache_miss")) {
934 perf_data.inode_cache_miss = value;
935 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
937 DEBUG("netapp plugin: cna_handle_wafl_data: "
938 "Found unexpected child: %s "
939 "for host %s.", name, hostname);
943 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data, interval));
944 } /* }}} void cna_handle_wafl_data */
946 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
953 if (cw->query != NULL)
956 cw->query = na_elem_new("perf-object-get-instances");
957 if (cw->query == NULL)
959 ERROR ("netapp plugin: na_elem_new failed.");
962 na_child_add_string (cw->query, "objectname", "wafl");
964 e = na_elem_new("counters");
967 na_elem_free (cw->query);
969 ERROR ("netapp plugin: na_elem_new failed.");
972 na_child_add_string(e, "counter", "name_cache_hit");
973 na_child_add_string(e, "counter", "name_cache_miss");
974 na_child_add_string(e, "counter", "find_dir_hit");
975 na_child_add_string(e, "counter", "find_dir_miss");
976 na_child_add_string(e, "counter", "buf_hash_hit");
977 na_child_add_string(e, "counter", "buf_hash_miss");
978 na_child_add_string(e, "counter", "inode_cache_hit");
979 na_child_add_string(e, "counter", "inode_cache_miss");
981 na_child_add(cw->query, e);
984 } /* }}} int cna_setup_wafl */
986 static int cna_query_wafl (host_config_t *host) /* {{{ */
995 /* If WAFL was not configured, return without doing anything. */
996 if (host->cfg_wafl == NULL)
1000 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
1003 status = cna_setup_wafl (host->cfg_wafl);
1006 assert (host->cfg_wafl->query != NULL);
1008 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
1009 if (na_results_status (data) != NA_OK)
1011 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed for host %s: %s",
1012 host->name, na_results_reason (data));
1013 na_elem_free (data);
1017 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data, host->interval);
1020 host->cfg_wafl->interval.last_read = now;
1022 na_elem_free (data);
1024 } /* }}} int cna_query_wafl */
1026 /* Data corresponding to <Disks /> */
1027 static int cna_handle_disk_data (const char *hostname, /* {{{ */
1028 cfg_disk_t *cfg_disk, na_elem_t *data, cdtime_t interval)
1031 na_elem_t *instances;
1032 na_elem_t *instance;
1033 na_elem_iter_t instance_iter;
1034 disk_t *worst_disk = NULL;
1036 if ((cfg_disk == NULL) || (data == NULL))
1039 timestamp = cna_child_get_cdtime (data);
1041 instances = na_elem_child (data, "instances");
1042 if (instances == NULL)
1044 ERROR ("netapp plugin: cna_handle_disk_data: "
1045 "na_elem_child (\"instances\") failed "
1046 "for host %s.", hostname);
1050 /* Iterate over all children */
1051 instance_iter = na_child_iterator (instances);
1052 for (instance = na_iterator_next (&instance_iter);
1054 instance = na_iterator_next(&instance_iter))
1059 na_elem_iter_t counter_iterator;
1062 memset (&new_data, 0, sizeof (new_data));
1063 new_data.timestamp = timestamp;
1064 new_data.disk_busy_percent = NAN;
1066 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1067 if (old_data == NULL)
1070 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1071 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1072 for (counter = na_iterator_next(&counter_iterator);
1074 counter = na_iterator_next(&counter_iterator))
1079 name = na_child_get_string(counter, "name");
1083 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1084 if (value == UINT64_MAX)
1087 if (strcmp(name, "disk_busy") == 0)
1089 new_data.disk_busy = value;
1090 new_data.flags |= HAVE_DISK_BUSY;
1092 else if (strcmp(name, "base_for_disk_busy") == 0)
1094 new_data.base_for_disk_busy = value;
1095 new_data.flags |= HAVE_DISK_BASE;
1099 DEBUG ("netapp plugin: cna_handle_disk_data: "
1100 "Counter not handled: %s = %"PRIu64,
1105 /* If all required counters are available and did not just wrap around,
1106 * calculate the busy percentage. Otherwise, the value is initialized to
1107 * NAN at the top of the for-loop. */
1108 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1109 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1110 && (new_data.disk_busy >= old_data->disk_busy)
1111 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1116 busy_diff = new_data.disk_busy - old_data->disk_busy;
1117 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1119 new_data.disk_busy_percent = 100.0
1120 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1123 /* Clear HAVE_* flags */
1124 old_data->flags &= ~HAVE_DISK_ALL;
1127 old_data->timestamp = new_data.timestamp;
1128 old_data->disk_busy = new_data.disk_busy;
1129 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1130 old_data->disk_busy_percent = new_data.disk_busy_percent;
1133 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1135 if ((worst_disk == NULL)
1136 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1137 worst_disk = old_data;
1138 } /* for (all disks) */
1140 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1141 submit_double (hostname, "system", "percent", "disk_busy",
1142 worst_disk->disk_busy_percent, timestamp, interval);
1145 } /* }}} int cna_handle_disk_data */
1147 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1154 if (cd->query != NULL)
1157 cd->query = na_elem_new ("perf-object-get-instances");
1158 if (cd->query == NULL)
1160 ERROR ("netapp plugin: na_elem_new failed.");
1163 na_child_add_string (cd->query, "objectname", "disk");
1165 e = na_elem_new("counters");
1168 na_elem_free (cd->query);
1170 ERROR ("netapp plugin: na_elem_new failed.");
1173 na_child_add_string(e, "counter", "disk_busy");
1174 na_child_add_string(e, "counter", "base_for_disk_busy");
1175 na_child_add(cd->query, e);
1178 } /* }}} int cna_setup_disk */
1180 static int cna_query_disk (host_config_t *host) /* {{{ */
1189 /* If the user did not configure disk statistics, return without doing
1191 if (host->cfg_disk == NULL)
1195 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1198 status = cna_setup_disk (host->cfg_disk);
1201 assert (host->cfg_disk->query != NULL);
1203 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1204 if (na_results_status (data) != NA_OK)
1206 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed for host %s: %s",
1207 host->name, na_results_reason (data));
1208 na_elem_free (data);
1212 status = cna_handle_disk_data (host->name, host->cfg_disk, data, host->interval);
1215 host->cfg_disk->interval.last_read = now;
1217 na_elem_free (data);
1219 } /* }}} int cna_query_disk */
1221 /* Data corresponding to <VolumePerf /> */
1222 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1223 cfg_volume_perf_t *cvp, na_elem_t *data, cdtime_t interval)
1226 na_elem_t *elem_instances;
1227 na_elem_iter_t iter_instances;
1228 na_elem_t *elem_instance;
1230 timestamp = cna_child_get_cdtime (data);
1232 elem_instances = na_elem_child(data, "instances");
1233 if (elem_instances == NULL)
1235 ERROR ("netapp plugin: handle_volume_perf_data: "
1236 "na_elem_child (\"instances\") failed "
1237 "for host %s.", hostname);
1241 iter_instances = na_child_iterator (elem_instances);
1242 for (elem_instance = na_iterator_next(&iter_instances);
1243 elem_instance != NULL;
1244 elem_instance = na_iterator_next(&iter_instances))
1248 data_volume_perf_t perf_data;
1249 data_volume_perf_t *v;
1251 na_elem_t *elem_counters;
1252 na_elem_iter_t iter_counters;
1253 na_elem_t *elem_counter;
1255 memset (&perf_data, 0, sizeof (perf_data));
1256 perf_data.timestamp = timestamp;
1258 name = na_child_get_string (elem_instance, "name");
1262 /* get_volume_perf may return NULL if this volume is to be ignored. */
1263 v = get_volume_perf (cvp, name);
1267 elem_counters = na_elem_child (elem_instance, "counters");
1268 if (elem_counters == NULL)
1271 iter_counters = na_child_iterator (elem_counters);
1272 for (elem_counter = na_iterator_next(&iter_counters);
1273 elem_counter != NULL;
1274 elem_counter = na_iterator_next(&iter_counters))
1279 name = na_child_get_string (elem_counter, "name");
1283 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1284 if (value == UINT64_MAX)
1287 if (!strcmp(name, "read_data")) {
1288 perf_data.read_bytes = value;
1289 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1290 } else if (!strcmp(name, "write_data")) {
1291 perf_data.write_bytes = value;
1292 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1293 } else if (!strcmp(name, "read_ops")) {
1294 perf_data.read_ops = value;
1295 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1296 } else if (!strcmp(name, "write_ops")) {
1297 perf_data.write_ops = value;
1298 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1299 } else if (!strcmp(name, "read_latency")) {
1300 perf_data.read_latency = value;
1301 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1302 } else if (!strcmp(name, "write_latency")) {
1303 perf_data.write_latency = value;
1304 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1306 } /* for (elem_counter) */
1308 submit_volume_perf_data (hostname, v, &perf_data, interval);
1309 } /* for (volume) */
1312 } /* }}} int cna_handle_volume_perf_data */
1314 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1321 if (cd->query != NULL)
1324 cd->query = na_elem_new ("perf-object-get-instances");
1325 if (cd->query == NULL)
1327 ERROR ("netapp plugin: na_elem_new failed.");
1330 na_child_add_string (cd->query, "objectname", "volume");
1332 e = na_elem_new("counters");
1335 na_elem_free (cd->query);
1337 ERROR ("netapp plugin: na_elem_new failed.");
1340 na_child_add_string(e, "counter", "read_ops");
1341 na_child_add_string(e, "counter", "write_ops");
1342 na_child_add_string(e, "counter", "read_data");
1343 na_child_add_string(e, "counter", "write_data");
1344 na_child_add_string(e, "counter", "read_latency");
1345 na_child_add_string(e, "counter", "write_latency");
1346 na_child_add(cd->query, e);
1349 } /* }}} int cna_setup_volume_perf */
1351 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1360 /* If the user did not configure volume performance statistics, return
1361 * without doing anything. */
1362 if (host->cfg_volume_perf == NULL)
1366 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1369 status = cna_setup_volume_perf (host->cfg_volume_perf);
1372 assert (host->cfg_volume_perf->query != NULL);
1374 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1375 if (na_results_status (data) != NA_OK)
1377 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed for host %s: %s",
1378 host->name, na_results_reason (data));
1379 na_elem_free (data);
1383 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data, host->interval);
1386 host->cfg_volume_perf->interval.last_read = now;
1388 na_elem_free (data);
1390 } /* }}} int cna_query_volume_perf */
1392 /* Data corresponding to <VolumeUsage /> */
1393 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1394 cfg_volume_usage_t *cfg_volume, int interval)
1396 data_volume_usage_t *v;
1398 for (v = cfg_volume->volumes; v != NULL; v = v->next)
1400 char plugin_instance[DATA_MAX_NAME_LEN];
1402 uint64_t norm_used = v->norm_used;
1403 uint64_t norm_free = v->norm_free;
1404 uint64_t sis_saved = v->sis_saved;
1405 uint64_t snap_reserve_used = 0;
1406 uint64_t snap_reserve_free = v->snap_reserved;
1407 uint64_t snap_norm_used = v->snap_used;
1409 ssnprintf (plugin_instance, sizeof (plugin_instance),
1410 "volume-%s", v->name);
1412 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD)) {
1413 if (v->snap_reserved > v->snap_used) {
1414 snap_reserve_free = v->snap_reserved - v->snap_used;
1415 snap_reserve_used = v->snap_used;
1418 snap_reserve_free = 0;
1419 snap_reserve_used = v->snap_reserved;
1420 snap_norm_used = v->snap_used - v->snap_reserved;
1424 /* The space used by snapshots but not reserved for them is included in
1425 * both, norm_used and snap_norm_used. If possible, subtract this here. */
1426 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED))
1428 if (norm_used >= snap_norm_used)
1429 norm_used -= snap_norm_used;
1432 ERROR ("netapp plugin: (norm_used = %"PRIu64") < (snap_norm_used = "
1433 "%"PRIu64") for host %s. Invalidating both.",
1434 norm_used, snap_norm_used, hostname);
1435 v->flags &= ~(HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED);
1439 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1440 submit_double (hostname, /* plugin instance = */ plugin_instance,
1441 "df_complex", "free",
1442 (double) norm_free, /* timestamp = */ 0, interval);
1444 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1445 submit_double (hostname, /* plugin instance = */ plugin_instance,
1446 "df_complex", "sis_saved",
1447 (double) sis_saved, /* timestamp = */ 0, interval);
1449 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1450 submit_double (hostname, /* plugin instance = */ plugin_instance,
1451 "df_complex", "used",
1452 (double) norm_used, /* timestamp = */ 0, interval);
1454 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1455 submit_double (hostname, /* plugin instance = */ plugin_instance,
1456 "df_complex", "snap_reserved",
1457 (double) snap_reserve_free, /* timestamp = */ 0, interval);
1459 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
1460 submit_double (hostname, /* plugin instance = */ plugin_instance,
1461 "df_complex", "snap_reserve_used",
1462 (double) snap_reserve_used, /* timestamp = */ 0, interval);
1464 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1465 submit_double (hostname, /* plugin instance = */ plugin_instance,
1466 "df_complex", "snap_normal_used",
1467 (double) snap_norm_used, /* timestamp = */ 0, interval);
1469 /* Clear all the HAVE_* flags */
1470 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1471 } /* for (v = cfg_volume->volumes) */
1474 } /* }}} int cna_submit_volume_usage_data */
1476 /* Switch the state of a volume between online and offline and send out a
1478 static int cna_change_volume_status (const char *hostname, /* {{{ */
1479 data_volume_usage_t *v)
1483 memset (&n, 0, sizeof (&n));
1485 sstrncpy (n.host, hostname, sizeof (n.host));
1486 sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
1487 sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance));
1489 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
1490 n.severity = NOTIF_OKAY;
1491 ssnprintf (n.message, sizeof (n.message),
1492 "Volume %s is now online.", v->name);
1493 v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
1495 n.severity = NOTIF_WARNING;
1496 ssnprintf (n.message, sizeof (n.message),
1497 "Volume %s is now offline.", v->name);
1498 v->flags |= IS_VOLUME_USAGE_OFFLINE;
1501 return (plugin_dispatch_notification (&n));
1502 } /* }}} int cna_change_volume_status */
1504 static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
1505 data_volume_usage_t *v)
1507 uint64_t snap_used = 0, value;
1508 na_elem_t *data, *elem_snap, *elem_snapshots;
1509 na_elem_iter_t iter_snap;
1511 data = na_server_invoke_elem(host->srv, v->snap_query);
1512 if (na_results_status(data) != NA_OK)
1514 if (na_results_errno(data) == EVOLUMEOFFLINE) {
1515 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
1516 cna_change_volume_status (host->name, v);
1518 ERROR ("netapp plugin: cna_handle_volume_snap_usage: na_server_invoke_elem for "
1519 "volume \"%s\" on host %s failed with error %d: %s", v->name,
1520 host->name, na_results_errno(data), na_results_reason(data));
1526 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0)
1527 cna_change_volume_status (host->name, v);
1529 elem_snapshots = na_elem_child (data, "snapshots");
1530 if (elem_snapshots == NULL)
1532 ERROR ("netapp plugin: cna_handle_volume_snap_usage: "
1533 "na_elem_child (\"snapshots\") failed "
1534 "for host %s.", host->name);
1539 iter_snap = na_child_iterator (elem_snapshots);
1540 for (elem_snap = na_iterator_next (&iter_snap);
1542 elem_snap = na_iterator_next (&iter_snap))
1544 value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
1545 /* "cumulative-total" is the total size of the oldest snapshot plus all
1546 * newer ones in blocks (1KB). We therefore are looking for the highest
1547 * number of all snapshots - that's the size required for the snapshots. */
1548 if (value > snap_used)
1551 na_elem_free (data);
1552 /* snap_used is in 1024 byte blocks */
1553 v->snap_used = snap_used * 1024;
1554 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1555 } /* }}} void cna_handle_volume_snap_usage */
1557 static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
1558 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1560 na_elem_t *elem_volume;
1561 na_elem_t *elem_volumes;
1562 na_elem_iter_t iter_volume;
1564 elem_volumes = na_elem_child (data, "volumes");
1565 if (elem_volumes == NULL)
1567 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1568 "na_elem_child (\"volumes\") failed "
1569 "for host %s.", host->name);
1573 iter_volume = na_child_iterator (elem_volumes);
1574 for (elem_volume = na_iterator_next (&iter_volume);
1575 elem_volume != NULL;
1576 elem_volume = na_iterator_next (&iter_volume))
1578 const char *volume_name, *state;
1580 data_volume_usage_t *v;
1584 const char *sis_state;
1585 uint64_t sis_saved_reported;
1587 volume_name = na_child_get_string (elem_volume, "name");
1588 if (volume_name == NULL)
1591 state = na_child_get_string (elem_volume, "state");
1592 if ((state == NULL) || (strcmp(state, "online") != 0))
1595 /* get_volume_usage may return NULL if the volume is to be ignored. */
1596 v = get_volume_usage (cfg_volume, volume_name);
1600 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1601 cna_handle_volume_snap_usage(host, v);
1603 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1606 /* 2^4 exa-bytes? This will take a while ;) */
1607 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1608 if (value != UINT64_MAX) {
1609 v->norm_free = value;
1610 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1613 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1614 if (value != UINT64_MAX) {
1615 v->norm_used = value;
1616 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1619 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1620 if (value != UINT64_MAX) {
1621 /* 1 block == 1024 bytes as per API docs */
1622 v->snap_reserved = 1024 * value;
1623 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1626 sis = na_elem_child(elem_volume, "sis");
1630 if (na_elem_child(sis, "sis-info"))
1631 sis = na_elem_child(sis, "sis-info");
1633 sis_state = na_child_get_string(sis, "state");
1634 if (sis_state == NULL)
1637 /* If SIS is not enabled, there's nothing left to do for this volume. */
1638 if (strcmp ("enabled", sis_state) != 0)
1641 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1642 if (sis_saved_reported == UINT64_MAX)
1645 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1646 if ((sis_saved_reported >> 32) != 0) {
1647 /* In case they ever fix this bug. */
1648 v->sis_saved = sis_saved_reported;
1649 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1650 } else { /* really hacky work-around code. {{{ */
1651 uint64_t sis_saved_percent;
1652 uint64_t sis_saved_guess;
1653 uint64_t overflow_guess;
1654 uint64_t guess1, guess2, guess3;
1656 /* Check if we have v->norm_used. Without it, we cannot calculate
1657 * sis_saved_guess. */
1658 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1661 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1662 if (sis_saved_percent > 100)
1665 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1666 * will hopefully be fixed in later versions. To work around the bug, try
1667 * to figure out how often the 32bit integer wrapped around by using the
1668 * "percentage-saved" value. Because the percentage is in the range
1669 * [0-100], this should work as long as the saved space does not exceed
1671 /* percentage-saved = size-saved / (size-saved + size-used) */
1672 if (sis_saved_percent < 100)
1673 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1675 sis_saved_guess = v->norm_used;
1677 overflow_guess = sis_saved_guess >> 32;
1678 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1679 guess2 = (overflow_guess << 32) + sis_saved_reported;
1680 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1682 if (sis_saved_guess < guess2) {
1683 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1684 v->sis_saved = guess1;
1686 v->sis_saved = guess2;
1688 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1689 v->sis_saved = guess2;
1691 v->sis_saved = guess3;
1693 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1694 } /* }}} end of 32-bit workaround */
1695 } /* for (elem_volume) */
1697 return (cna_submit_volume_usage_data (host->name, cfg_volume, host->interval));
1698 } /* }}} int cna_handle_volume_usage_data */
1700 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1705 if (cvu->query != NULL)
1708 cvu->query = na_elem_new ("volume-list-info");
1709 if (cvu->query == NULL)
1711 ERROR ("netapp plugin: na_elem_new failed.");
1716 } /* }}} int cna_setup_volume_usage */
1718 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1727 /* If the user did not configure volume_usage statistics, return without
1728 * doing anything. */
1729 if (host->cfg_volume_usage == NULL)
1733 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1736 status = cna_setup_volume_usage (host->cfg_volume_usage);
1739 assert (host->cfg_volume_usage->query != NULL);
1741 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1742 if (na_results_status (data) != NA_OK)
1744 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed for host %s: %s",
1745 host->name, na_results_reason (data));
1746 na_elem_free (data);
1750 status = cna_handle_volume_usage_data (host, host->cfg_volume_usage, data);
1753 host->cfg_volume_usage->interval.last_read = now;
1755 na_elem_free (data);
1757 } /* }}} int cna_query_volume_usage */
1759 /* Data corresponding to <SnapVault /> */
1760 static int cna_handle_snapvault_data (const char *hostname, /* {{{ */
1761 cfg_snapvault_t *cfg_snapvault, na_elem_t *data, cdtime_t interval)
1764 na_elem_iter_t status_iter;
1766 status = na_elem_child (data, "status-list");
1768 ERROR ("netapp plugin: SnapVault status record missing status-list");
1772 status_iter = na_child_iterator (status);
1773 for (status = na_iterator_next (&status_iter);
1775 status = na_iterator_next (&status_iter))
1777 const char *dest_sys, *dest_path, *src_sys, *src_path;
1778 char plugin_instance[DATA_MAX_NAME_LEN];
1781 dest_sys = na_child_get_string (status, "destination-system");
1782 dest_path = na_child_get_string (status, "destination-path");
1783 src_sys = na_child_get_string (status, "source-system");
1784 src_path = na_child_get_string (status, "source-path");
1786 if ((! dest_sys) || (! dest_path) || (! src_sys) || (! src_path))
1789 value = na_child_get_uint64 (status, "lag-time", UINT64_MAX);
1790 if (value == UINT64_MAX) /* no successful baseline transfer yet */
1793 /* possible TODO: make plugin instance configurable */
1794 ssnprintf (plugin_instance, sizeof (plugin_instance),
1795 "snapvault-%s", dest_path);
1796 submit_double (hostname, plugin_instance, /* type = */ "delay", NULL,
1797 (double)value, /* timestamp = */ 0, interval);
1799 value = na_child_get_uint64 (status, "last-transfer-duration", UINT64_MAX);
1800 if (value != UINT64_MAX)
1801 submit_double (hostname, plugin_instance, /* type = */ "duration", "last_transfer",
1802 (double)value, /* timestamp = */ 0, interval);
1804 value = na_child_get_uint64 (status, "transfer-progress", UINT64_MAX);
1805 if (value == UINT64_MAX)
1806 value = na_child_get_uint64 (status, "last-transfer-size", UINT64_MAX);
1807 if (value != UINT64_MAX) {
1808 value *= 1024; /* this is kilobytes */
1809 submit_derive (hostname, plugin_instance, /* type = */ "if_rx_octets", "transferred",
1810 value, /* timestamp = */ 0, interval);
1812 } /* for (status) */
1815 } /* }}} int cna_handle_snapvault_data */
1817 static int cna_handle_snapvault_iter (host_config_t *host, /* {{{ */
1822 uint32_t records_count;
1825 records_count = na_child_get_uint32 (data, "records", UINT32_MAX);
1826 if (records_count == UINT32_MAX)
1829 tag = na_child_get_string (data, "tag");
1833 DEBUG ("netapp plugin: Iterating %u SV records (tag = %s)", records_count, tag);
1835 for (i = 0; i < records_count; ++i) {
1838 elem = na_server_invoke (host->srv,
1839 "snapvault-secondary-relationship-status-list-iter-next",
1840 "maximum", "1", "tag", tag, NULL);
1842 if (na_results_status (elem) != NA_OK)
1844 ERROR ("netapp plugin: cna_handle_snapvault_iter: "
1845 "na_server_invoke failed for host %s: %s",
1846 host->name, na_results_reason (data));
1847 na_elem_free (elem);
1851 cna_handle_snapvault_data (host->name, host->cfg_snapvault, elem, host->interval);
1852 na_elem_free (elem);
1855 na_elem_free (na_server_invoke (host->srv,
1856 "snapvault-secondary-relationship-status-list-iter-end",
1859 } /* }}} int cna_handle_snapvault_iter */
1861 static int cna_setup_snapvault (cfg_snapvault_t *sv) /* {{{ */
1866 if (sv->query != NULL)
1869 sv->query = na_elem_new ("snapvault-secondary-relationship-status-list-iter-start");
1870 if (sv->query == NULL)
1872 ERROR ("netapp plugin: na_elem_new failed.");
1877 } /* }}} int cna_setup_snapvault */
1879 static int cna_query_snapvault (host_config_t *host) /* {{{ */
1888 if (host->cfg_snapvault == NULL)
1892 if ((host->cfg_snapvault->interval.interval + host->cfg_snapvault->interval.last_read) > now)
1895 status = cna_setup_snapvault (host->cfg_snapvault);
1898 assert (host->cfg_snapvault->query != NULL);
1900 data = na_server_invoke_elem (host->srv, host->cfg_snapvault->query);
1901 if (na_results_status (data) != NA_OK)
1903 ERROR ("netapp plugin: cna_query_snapvault: na_server_invoke_elem failed for host %s: %s",
1904 host->name, na_results_reason (data));
1905 na_elem_free (data);
1909 status = cna_handle_snapvault_iter (host, data);
1912 host->cfg_snapvault->interval.last_read = now;
1914 na_elem_free (data);
1916 } /* }}} int cna_query_snapvault */
1918 /* Data corresponding to <System /> */
1919 static int cna_handle_system_data (const char *hostname, /* {{{ */
1920 cfg_system_t *cfg_system, na_elem_t *data, int interval)
1922 na_elem_t *instances;
1924 na_elem_iter_t counter_iter;
1926 derive_t disk_read = 0, disk_written = 0;
1927 derive_t net_recv = 0, net_sent = 0;
1928 derive_t cpu_busy = 0, cpu_total = 0;
1929 uint32_t counter_flags = 0;
1931 const char *instance;
1934 timestamp = cna_child_get_cdtime (data);
1936 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1937 if (instances == NULL)
1939 ERROR ("netapp plugin: cna_handle_system_data: "
1940 "na_elem_child (\"instances\") failed "
1941 "for host %s.", hostname);
1945 instance = na_child_get_string (instances, "name");
1946 if (instance == NULL)
1948 ERROR ("netapp plugin: cna_handle_system_data: "
1949 "na_child_get_string (\"name\") failed "
1950 "for host %s.", hostname);
1954 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
1955 for (counter = na_iterator_next (&counter_iter);
1957 counter = na_iterator_next (&counter_iter))
1962 name = na_child_get_string(counter, "name");
1966 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1967 if (value == UINT64_MAX)
1970 if (!strcmp(name, "disk_data_read")) {
1971 disk_read = (derive_t) (value * 1024);
1972 counter_flags |= 0x01;
1973 } else if (!strcmp(name, "disk_data_written")) {
1974 disk_written = (derive_t) (value * 1024);
1975 counter_flags |= 0x02;
1976 } else if (!strcmp(name, "net_data_recv")) {
1977 net_recv = (derive_t) (value * 1024);
1978 counter_flags |= 0x04;
1979 } else if (!strcmp(name, "net_data_sent")) {
1980 net_sent = (derive_t) (value * 1024);
1981 counter_flags |= 0x08;
1982 } else if (!strcmp(name, "cpu_busy")) {
1983 cpu_busy = (derive_t) value;
1984 counter_flags |= 0x10;
1985 } else if (!strcmp(name, "cpu_elapsed_time")) {
1986 cpu_total = (derive_t) value;
1987 counter_flags |= 0x20;
1988 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1989 && (value > 0) && (strlen(name) > 4)
1990 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1991 submit_derive (hostname, instance, "disk_ops_complex", name,
1992 (derive_t) value, timestamp, interval);
1994 } /* for (counter) */
1996 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1997 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
1998 submit_two_derive (hostname, instance, "disk_octets", NULL,
1999 disk_read, disk_written, timestamp, interval);
2001 if ((cfg_system->flags & CFG_SYSTEM_NET)
2002 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
2003 submit_two_derive (hostname, instance, "if_octets", NULL,
2004 net_recv, net_sent, timestamp, interval);
2006 if ((cfg_system->flags & CFG_SYSTEM_CPU)
2007 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
2009 submit_derive (hostname, instance, "cpu", "system",
2010 cpu_busy, timestamp, interval);
2011 submit_derive (hostname, instance, "cpu", "idle",
2012 cpu_total - cpu_busy, timestamp, interval);
2016 } /* }}} int cna_handle_system_data */
2018 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
2023 if (cs->query != NULL)
2026 cs->query = na_elem_new ("perf-object-get-instances");
2027 if (cs->query == NULL)
2029 ERROR ("netapp plugin: na_elem_new failed.");
2032 na_child_add_string (cs->query, "objectname", "system");
2035 } /* }}} int cna_setup_system */
2037 static int cna_query_system (host_config_t *host) /* {{{ */
2046 /* If system statistics were not configured, return without doing anything. */
2047 if (host->cfg_system == NULL)
2051 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
2054 status = cna_setup_system (host->cfg_system);
2057 assert (host->cfg_system->query != NULL);
2059 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
2060 if (na_results_status (data) != NA_OK)
2062 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed for host %s: %s",
2063 host->name, na_results_reason (data));
2064 na_elem_free (data);
2068 status = cna_handle_system_data (host->name, host->cfg_system, data, host->interval);
2071 host->cfg_system->interval.last_read = now;
2073 na_elem_free (data);
2075 } /* }}} int cna_query_system */
2078 * Configuration handling
2080 /* Sets a given flag if the boolean argument is true and unsets the flag if it
2081 * is false. On error, the flag-field is not changed. */
2082 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
2083 uint32_t *flags, uint32_t flag)
2085 if ((ci == NULL) || (flags == NULL))
2088 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2090 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
2095 if (ci->values[0].value.boolean)
2101 } /* }}} int cna_config_bool_to_flag */
2103 /* Handling of the "Interval" option which is allowed in every block. */
2104 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
2105 cna_interval_t *out_interval)
2110 status = cf_util_get_cdtime (ci, &tmp);
2114 out_interval->interval = tmp;
2115 out_interval->last_read = 0;
2118 } /* }}} int cna_config_get_interval */
2120 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
2121 * <VolumePerf /> block. */
2122 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
2123 const oconfig_item_t *ci)
2128 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2130 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2135 name = ci->values[0].value.string;
2137 if (strcasecmp ("GetIO", ci->key) == 0)
2138 il = cvp->il_octets;
2139 else if (strcasecmp ("GetOps", ci->key) == 0)
2140 il = cvp->il_operations;
2141 else if (strcasecmp ("GetLatency", ci->key) == 0)
2142 il = cvp->il_latency;
2146 ignorelist_add (il, name);
2147 } /* }}} void cna_config_volume_perf_option */
2149 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
2150 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
2151 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
2152 const oconfig_item_t *ci)
2156 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2158 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2163 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
2164 il = cvp->il_octets;
2165 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
2166 il = cvp->il_operations;
2167 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
2168 il = cvp->il_latency;
2172 if (ci->values[0].value.boolean)
2173 ignorelist_set_invert (il, /* invert = */ 0);
2175 ignorelist_set_invert (il, /* invert = */ 1);
2176 } /* }}} void cna_config_volume_perf_default */
2178 /* Corresponds to a <Disks /> block */
2183 * IgnoreSelectedIO false
2187 * IgnoreSelectedOps false
2191 * IgnoreSelectedLatency false
2194 /* Corresponds to a <VolumePerf /> block */
2195 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
2196 const oconfig_item_t *ci)
2198 cfg_volume_perf_t *cfg_volume_perf;
2201 if ((host == NULL) || (ci == NULL))
2204 if (host->cfg_volume_perf == NULL)
2206 cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
2207 if (cfg_volume_perf == NULL)
2209 memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
2211 /* Set default flags */
2212 cfg_volume_perf->query = NULL;
2213 cfg_volume_perf->volumes = NULL;
2215 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
2216 if (cfg_volume_perf->il_octets == NULL)
2218 sfree (cfg_volume_perf);
2222 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
2223 if (cfg_volume_perf->il_operations == NULL)
2225 ignorelist_free (cfg_volume_perf->il_octets);
2226 sfree (cfg_volume_perf);
2230 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
2231 if (cfg_volume_perf->il_latency == NULL)
2233 ignorelist_free (cfg_volume_perf->il_octets);
2234 ignorelist_free (cfg_volume_perf->il_operations);
2235 sfree (cfg_volume_perf);
2239 host->cfg_volume_perf = cfg_volume_perf;
2241 cfg_volume_perf = host->cfg_volume_perf;
2243 for (i = 0; i < ci->children_num; ++i) {
2244 oconfig_item_t *item = ci->children + i;
2246 /* if (!item || !item->key || !*item->key) continue; */
2247 if (strcasecmp(item->key, "Interval") == 0)
2248 cna_config_get_interval (item, &cfg_volume_perf->interval);
2249 else if (!strcasecmp(item->key, "GetIO"))
2250 cna_config_volume_perf_option (cfg_volume_perf, item);
2251 else if (!strcasecmp(item->key, "GetOps"))
2252 cna_config_volume_perf_option (cfg_volume_perf, item);
2253 else if (!strcasecmp(item->key, "GetLatency"))
2254 cna_config_volume_perf_option (cfg_volume_perf, item);
2255 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
2256 cna_config_volume_perf_default (cfg_volume_perf, item);
2257 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
2258 cna_config_volume_perf_default (cfg_volume_perf, item);
2259 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2260 cna_config_volume_perf_default (cfg_volume_perf, item);
2262 WARNING ("netapp plugin: The option %s is not allowed within "
2263 "`VolumePerf' blocks.", item->key);
2267 } /* }}} int cna_config_volume_performance */
2269 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2270 * <VolumeUsage /> block. */
2271 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
2272 const oconfig_item_t *ci)
2277 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2279 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2284 name = ci->values[0].value.string;
2286 if (strcasecmp ("GetCapacity", ci->key) == 0)
2287 il = cvu->il_capacity;
2288 else if (strcasecmp ("GetSnapshot", ci->key) == 0)
2289 il = cvu->il_snapshot;
2293 ignorelist_add (il, name);
2294 } /* }}} void cna_config_volume_usage_option */
2296 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2297 * options within a <VolumeUsage /> block. */
2298 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
2299 const oconfig_item_t *ci)
2303 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2305 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2310 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2311 il = cvu->il_capacity;
2312 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2313 il = cvu->il_snapshot;
2317 if (ci->values[0].value.boolean)
2318 ignorelist_set_invert (il, /* invert = */ 0);
2320 ignorelist_set_invert (il, /* invert = */ 1);
2321 } /* }}} void cna_config_volume_usage_default */
2323 /* Corresponds to a <Disks /> block */
2324 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2325 cfg_disk_t *cfg_disk;
2328 if ((host == NULL) || (ci == NULL))
2331 if (host->cfg_disk == NULL)
2333 cfg_disk = malloc (sizeof (*cfg_disk));
2334 if (cfg_disk == NULL)
2336 memset (cfg_disk, 0, sizeof (*cfg_disk));
2338 /* Set default flags */
2339 cfg_disk->flags = CFG_DISK_ALL;
2340 cfg_disk->query = NULL;
2341 cfg_disk->disks = NULL;
2343 host->cfg_disk = cfg_disk;
2345 cfg_disk = host->cfg_disk;
2347 for (i = 0; i < ci->children_num; ++i) {
2348 oconfig_item_t *item = ci->children + i;
2350 /* if (!item || !item->key || !*item->key) continue; */
2351 if (strcasecmp(item->key, "Interval") == 0)
2352 cna_config_get_interval (item, &cfg_disk->interval);
2353 else if (strcasecmp(item->key, "GetBusy") == 0)
2354 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2357 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2359 NOTICE ("netapp plugin: All disk related values have been disabled. "
2360 "Collection of per-disk data will be disabled entirely.");
2361 free_cfg_disk (host->cfg_disk);
2362 host->cfg_disk = NULL;
2366 } /* }}} int cna_config_disk */
2368 /* Corresponds to a <WAFL /> block */
2369 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2371 cfg_wafl_t *cfg_wafl;
2374 if ((host == NULL) || (ci == NULL))
2377 if (host->cfg_wafl == NULL)
2379 cfg_wafl = malloc (sizeof (*cfg_wafl));
2380 if (cfg_wafl == NULL)
2382 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
2384 /* Set default flags */
2385 cfg_wafl->flags = CFG_WAFL_ALL;
2387 host->cfg_wafl = cfg_wafl;
2389 cfg_wafl = host->cfg_wafl;
2391 for (i = 0; i < ci->children_num; ++i) {
2392 oconfig_item_t *item = ci->children + i;
2394 if (strcasecmp(item->key, "Interval") == 0)
2395 cna_config_get_interval (item, &cfg_wafl->interval);
2396 else if (!strcasecmp(item->key, "GetNameCache"))
2397 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2398 else if (!strcasecmp(item->key, "GetDirCache"))
2399 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2400 else if (!strcasecmp(item->key, "GetBufferCache"))
2401 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2402 else if (!strcasecmp(item->key, "GetInodeCache"))
2403 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2405 WARNING ("netapp plugin: The %s config option is not allowed within "
2406 "`WAFL' blocks.", item->key);
2409 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2411 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2412 "Collection of WAFL data will be disabled entirely.");
2413 free_cfg_wafl (host->cfg_wafl);
2414 host->cfg_wafl = NULL;
2418 } /* }}} int cna_config_wafl */
2422 * GetCapacity "vol0"
2423 * GetCapacity "vol1"
2424 * GetCapacity "vol2"
2425 * GetCapacity "vol3"
2426 * GetCapacity "vol4"
2427 * IgnoreSelectedCapacity false
2429 * GetSnapshot "vol0"
2430 * GetSnapshot "vol3"
2431 * GetSnapshot "vol4"
2432 * GetSnapshot "vol7"
2433 * IgnoreSelectedSnapshot false
2436 /* Corresponds to a <VolumeUsage /> block */
2437 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2438 const oconfig_item_t *ci)
2440 cfg_volume_usage_t *cfg_volume_usage;
2443 if ((host == NULL) || (ci == NULL))
2446 if (host->cfg_volume_usage == NULL)
2448 cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
2449 if (cfg_volume_usage == NULL)
2451 memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
2453 /* Set default flags */
2454 cfg_volume_usage->query = NULL;
2455 cfg_volume_usage->volumes = NULL;
2457 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2458 if (cfg_volume_usage->il_capacity == NULL)
2460 sfree (cfg_volume_usage);
2464 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2465 if (cfg_volume_usage->il_snapshot == NULL)
2467 ignorelist_free (cfg_volume_usage->il_capacity);
2468 sfree (cfg_volume_usage);
2472 host->cfg_volume_usage = cfg_volume_usage;
2474 cfg_volume_usage = host->cfg_volume_usage;
2476 for (i = 0; i < ci->children_num; ++i) {
2477 oconfig_item_t *item = ci->children + i;
2479 /* if (!item || !item->key || !*item->key) continue; */
2480 if (strcasecmp(item->key, "Interval") == 0)
2481 cna_config_get_interval (item, &cfg_volume_usage->interval);
2482 else if (!strcasecmp(item->key, "GetCapacity"))
2483 cna_config_volume_usage_option (cfg_volume_usage, item);
2484 else if (!strcasecmp(item->key, "GetSnapshot"))
2485 cna_config_volume_usage_option (cfg_volume_usage, item);
2486 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2487 cna_config_volume_usage_default (cfg_volume_usage, item);
2488 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2489 cna_config_volume_usage_default (cfg_volume_usage, item);
2491 WARNING ("netapp plugin: The option %s is not allowed within "
2492 "`VolumeUsage' blocks.", item->key);
2496 } /* }}} int cna_config_volume_usage */
2498 /* Corresponds to a <SnapVault /> block */
2499 static int cna_config_snapvault (host_config_t *host, /* {{{ */
2500 const oconfig_item_t *ci)
2502 cfg_snapvault_t *cfg_snapvault;
2505 if ((host == NULL) || (ci == NULL))
2508 if (host->cfg_snapvault == NULL)
2510 cfg_snapvault = malloc (sizeof (*cfg_snapvault));
2511 if (cfg_snapvault == NULL)
2513 memset (cfg_snapvault, 0, sizeof (*cfg_snapvault));
2514 cfg_snapvault->query = NULL;
2516 host->cfg_snapvault = cfg_snapvault;
2519 cfg_snapvault = host->cfg_snapvault;
2521 for (i = 0; i < ci->children_num; ++i) {
2522 oconfig_item_t *item = ci->children + i;
2524 if (strcasecmp (item->key, "Interval") == 0)
2525 cna_config_get_interval (item, &cfg_snapvault->interval);
2527 WARNING ("netapp plugin: The option %s is not allowed within "
2528 "`SnapVault' blocks.", item->key);
2532 } /* }}} int cna_config_snapvault */
2534 /* Corresponds to a <System /> block */
2535 static int cna_config_system (host_config_t *host, /* {{{ */
2538 cfg_system_t *cfg_system;
2541 if ((host == NULL) || (ci == NULL))
2544 if (host->cfg_system == NULL)
2546 cfg_system = malloc (sizeof (*cfg_system));
2547 if (cfg_system == NULL)
2549 memset (cfg_system, 0, sizeof (*cfg_system));
2551 /* Set default flags */
2552 cfg_system->flags = CFG_SYSTEM_ALL;
2553 cfg_system->query = NULL;
2555 host->cfg_system = cfg_system;
2557 cfg_system = host->cfg_system;
2559 for (i = 0; i < ci->children_num; ++i) {
2560 oconfig_item_t *item = ci->children + i;
2562 if (strcasecmp(item->key, "Interval") == 0) {
2563 cna_config_get_interval (item, &cfg_system->interval);
2564 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2565 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2566 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2567 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2568 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2569 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2570 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2571 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2573 WARNING ("netapp plugin: The %s config option is not allowed within "
2574 "`System' blocks.", item->key);
2578 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2580 NOTICE ("netapp plugin: All system related values have been disabled. "
2581 "Collection of system data will be disabled entirely.");
2582 free_cfg_system (host->cfg_system);
2583 host->cfg_system = NULL;
2587 } /* }}} int cna_config_system */
2589 /* Corresponds to a <Host /> block. */
2590 static host_config_t *cna_alloc_host (void) /* {{{ */
2592 host_config_t *host;
2594 host = malloc(sizeof(*host));
2597 memset (host, 0, sizeof (*host));
2600 host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2602 host->username = NULL;
2603 host->password = NULL;
2604 host->vfiler = NULL;
2606 host->cfg_wafl = NULL;
2607 host->cfg_disk = NULL;
2608 host->cfg_volume_perf = NULL;
2609 host->cfg_volume_usage = NULL;
2610 host->cfg_snapvault = NULL;
2611 host->cfg_system = NULL;
2614 } /* }}} host_config_t *cna_alloc_host */
2616 static host_config_t *cna_shallow_clone_host (host_config_t *host) /* {{{ */
2618 host_config_t *clone;
2623 clone = cna_alloc_host ();
2627 if (host->name != NULL) {
2628 clone->name = strdup (host->name);
2629 if (clone->name == NULL) {
2630 free_host_config (clone);
2635 clone->protocol = host->protocol;
2637 if (host->host != NULL) {
2638 clone->host = strdup (host->host);
2639 if (clone->host == NULL) {
2640 free_host_config (clone);
2645 clone->port = host->port;
2647 if (host->username != NULL) {
2648 clone->username = strdup (host->username);
2649 if (clone->username == NULL) {
2650 free_host_config (clone);
2654 if (host->password != NULL) {
2655 clone->password = strdup (host->password);
2656 if (clone->password == NULL) {
2657 free_host_config (clone);
2662 clone->interval = host->interval;
2665 } /* }}} host_config_t *cna_shallow_clone_host */
2667 static int cna_read (user_data_t *ud);
2669 static int cna_register_host (host_config_t *host) /* {{{ */
2672 struct timespec interval;
2676 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s-%s",
2677 host->name, host->vfiler);
2679 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name);
2681 CDTIME_T_TO_TIMESPEC (host->interval, &interval);
2683 memset (&ud, 0, sizeof (ud));
2685 ud.free_func = (void (*) (void *)) free_host_config;
2687 plugin_register_complex_read (/* group = */ NULL, cb_name,
2688 /* callback = */ cna_read,
2689 /* interval = */ (host->interval > 0) ? &interval : NULL,
2690 /* user data = */ &ud);
2693 } /* }}} int cna_register_host */
2695 static int cna_config_host (host_config_t *host, /* {{{ */
2696 const oconfig_item_t *ci)
2698 oconfig_item_t *item;
2699 _Bool is_vfiler = 0;
2703 if (! strcasecmp (ci->key, "VFiler"))
2706 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2707 WARNING ("netapp plugin: \"%s\" needs exactly one string argument. Ignoring host block.", ci->key);
2711 status = cf_util_get_string (ci, &host->name);
2715 for (i = 0; i < ci->children_num; ++i) {
2716 item = ci->children + i;
2720 if (!strcasecmp(item->key, "Address")) {
2721 status = cf_util_get_string (item, &host->host);
2722 } else if (!strcasecmp(item->key, "Port")) {
2725 tmp = cf_util_get_port_number (item);
2728 } else if (!strcasecmp(item->key, "Protocol")) {
2729 if ((item->values_num != 1) || (item->values[0].type != OCONFIG_TYPE_STRING) || (strcasecmp(item->values[0].value.string, "http") && strcasecmp(item->values[0].value.string, "https"))) {
2730 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2733 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2734 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2735 } else if (!strcasecmp(item->key, "User")) {
2736 status = cf_util_get_string (item, &host->username);
2737 } else if (!strcasecmp(item->key, "Password")) {
2738 status = cf_util_get_string (item, &host->password);
2739 } else if (!strcasecmp(item->key, "Interval")) {
2740 status = cf_util_get_cdtime (item, &host->interval);
2741 } else if (!strcasecmp(item->key, "WAFL")) {
2742 cna_config_wafl(host, item);
2743 } else if (!strcasecmp(item->key, "Disks")) {
2744 cna_config_disk(host, item);
2745 } else if (!strcasecmp(item->key, "VolumePerf")) {
2746 cna_config_volume_performance(host, item);
2747 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2748 cna_config_volume_usage(host, item);
2749 } else if (!strcasecmp(item->key, "SnapVault")) {
2750 cna_config_snapvault(host, item);
2751 } else if (!strcasecmp(item->key, "System")) {
2752 cna_config_system(host, item);
2753 } else if ((!strcasecmp(item->key, "VFiler")) && (! is_vfiler)) {
2754 host_config_t *vfiler;
2756 vfiler = cna_shallow_clone_host (host);
2758 ERROR ("netapp plugin: Failed to allocate host object for vfiler.");
2762 if (cna_config_host (vfiler, item)) {
2763 free_host_config (vfiler);
2767 cna_register_host (vfiler);
2768 } else if ((!strcasecmp(item->key, "VFilerName")) && is_vfiler) {
2769 status = cf_util_get_string (item, &host->vfiler);
2771 WARNING ("netapp plugin: Ignoring unknown config option \"%s\" in %s block \"%s\".",
2772 item->key, is_vfiler ? "vfiler" : "host", ci->values[0].value.string);
2779 if (host->host == NULL)
2780 host->host = strdup (host->name);
2782 if (is_vfiler && (! host->vfiler))
2783 host->vfiler = strdup (host->name);
2785 if (host->host == NULL)
2788 if (host->port <= 0)
2789 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2791 if ((host->username == NULL) || (host->password == NULL)) {
2792 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2793 "Ignoring host block.", host->name);
2801 } /* }}} host_config_t *cna_config_host */
2804 * Callbacks registered with the daemon
2806 * Pretty standard stuff here.
2808 static int cna_init_host (host_config_t *host) /* {{{ */
2810 /* Request version 1.1 of the ONTAP API */
2811 int major_version = 1, minor_version = 1;
2816 if (host->srv != NULL)
2819 if (host->vfiler != NULL) /* Request version 1.7 of the ONTAP API */
2822 host->srv = na_server_open (host->host, major_version, minor_version);
2823 if (host->srv == NULL) {
2824 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
2828 na_server_set_transport_type(host->srv, host->protocol,
2829 /* transportarg = */ NULL);
2830 na_server_set_port(host->srv, host->port);
2831 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
2832 na_server_adminuser(host->srv, host->username, host->password);
2833 na_server_set_timeout(host->srv, 5 /* seconds */);
2835 if (host->vfiler != NULL) {
2836 if (! na_server_set_vfiler (host->srv, host->vfiler)) {
2837 ERROR ("netapp plugin: Failed to connect to VFiler '%s' on host '%s'.",
2838 host->vfiler, host->host);
2842 INFO ("netapp plugin: Connected to VFiler '%s' on host '%s'.",
2843 host->vfiler, host->host);
2848 } /* }}} int cna_init_host */
2850 static int cna_init (void) /* {{{ */
2854 memset (err, 0, sizeof (err));
2855 if (!na_startup(err, sizeof(err))) {
2856 err[sizeof (err) - 1] = 0;
2857 ERROR("netapp plugin: Error initializing netapp API: %s", err);
2862 } /* }}} cna_init */
2864 static int cna_read_internal (host_config_t *host) { /* {{{ */
2867 status = cna_query_wafl (host);
2871 status = cna_query_disk (host);
2875 status = cna_query_volume_perf (host);
2879 status = cna_query_volume_usage (host);
2883 status = cna_query_snapvault (host);
2887 status = cna_query_system (host);
2892 } /* }}} int cna_read_internal */
2894 static int cna_read (user_data_t *ud) { /* {{{ */
2895 host_config_t *host;
2898 if ((ud == NULL) || (ud->data == NULL))
2903 status = cna_init_host (host);
2907 status = cna_read_internal (host);
2910 if (host->srv != NULL)
2911 na_server_close (host->srv);
2916 } /* }}} int cna_read */
2918 static int cna_config (oconfig_item_t *ci) { /* {{{ */
2920 oconfig_item_t *item;
2922 for (i = 0; i < ci->children_num; ++i) {
2923 item = ci->children + i;
2925 if (strcasecmp(item->key, "Host") == 0)
2927 host_config_t *host;
2929 host = cna_alloc_host ();
2931 ERROR ("netapp plugin: Failed to allocate host object.");
2935 if (cna_config_host (host, item) != 0) {
2936 free_host_config (host);
2940 cna_register_host (host);
2942 else /* if (item->key != "Host") */
2944 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
2948 } /* }}} int cna_config */
2950 static int cna_shutdown (void) /* {{{ */
2952 /* Clean up system resources and stuff. */
2956 } /* }}} int cna_shutdown */
2958 void module_register(void) {
2959 plugin_register_complex_config("netapp", cna_config);
2960 plugin_register_init("netapp", cna_init);
2961 plugin_register_shutdown("netapp", cna_shutdown);
2964 /* vim: set sw=2 ts=2 noet fdm=marker : */