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_COMPRESS_SAVED 0x0200
193 #define HAVE_VOLUME_USAGE_DEDUP_SAVED 0x0400
194 #define HAVE_VOLUME_USAGE_ALL 0x07f0
195 #define IS_VOLUME_USAGE_OFFLINE 0x0800
196 struct data_volume_usage_s;
197 typedef struct data_volume_usage_s data_volume_usage_t;
198 struct data_volume_usage_s {
202 na_elem_t *snap_query;
206 uint64_t snap_reserved;
209 uint64_t compress_saved;
210 uint64_t dedup_saved;
212 data_volume_usage_t *next;
216 cna_interval_t interval;
219 ignorelist_t *il_capacity;
220 ignorelist_t *il_snapshot;
222 data_volume_usage_t *volumes;
223 } cfg_volume_usage_t;
224 /* }}} cfg_volume_usage_t */
226 /*! Data types for SnapVault statistics {{{
228 * \brief Persistent data for SnapVault(R) statistics
231 cna_interval_t interval;
234 /* }}} cfg_snapvault_t */
236 /*! Data types for system statistics {{{
238 * \brief Persistent data for system performance counters
240 #define CFG_SYSTEM_CPU 0x01
241 #define CFG_SYSTEM_NET 0x02
242 #define CFG_SYSTEM_OPS 0x04
243 #define CFG_SYSTEM_DISK 0x08
244 #define CFG_SYSTEM_ALL 0x0F
247 cna_interval_t interval;
250 /* }}} cfg_system_t */
252 struct host_config_s {
254 na_server_transport_t protocol;
263 cfg_wafl_t *cfg_wafl;
264 cfg_disk_t *cfg_disk;
265 cfg_volume_perf_t *cfg_volume_perf;
266 cfg_volume_usage_t *cfg_volume_usage;
267 cfg_snapvault_t *cfg_snapvault;
268 cfg_system_t *cfg_system;
270 struct host_config_s *next;
276 * Used to free the various structures above.
278 static void free_disk (disk_t *disk) /* {{{ */
291 } /* }}} void free_disk */
293 static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
298 if (cw->query != NULL)
299 na_elem_free (cw->query);
302 } /* }}} void free_cfg_wafl */
304 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
306 if (cfg_disk == NULL)
309 if (cfg_disk->query != NULL)
310 na_elem_free (cfg_disk->query);
312 free_disk (cfg_disk->disks);
314 } /* }}} void free_cfg_disk */
316 static void free_cfg_volume_perf (cfg_volume_perf_t *cvp) /* {{{ */
318 data_volume_perf_t *data;
323 /* Free the ignorelists */
324 ignorelist_free (cvp->il_octets);
325 ignorelist_free (cvp->il_operations);
326 ignorelist_free (cvp->il_latency);
328 /* Free the linked list of volumes */
332 data_volume_perf_t *next = data->next;
338 if (cvp->query != NULL)
339 na_elem_free (cvp->query);
342 } /* }}} void free_cfg_volume_perf */
344 static void free_cfg_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
346 data_volume_usage_t *data;
351 /* Free the ignorelists */
352 ignorelist_free (cvu->il_capacity);
353 ignorelist_free (cvu->il_snapshot);
355 /* Free the linked list of volumes */
359 data_volume_usage_t *next = data->next;
361 if (data->snap_query != NULL)
362 na_elem_free(data->snap_query);
367 if (cvu->query != NULL)
368 na_elem_free (cvu->query);
371 } /* }}} void free_cfg_volume_usage */
373 static void free_cfg_snapvault (cfg_snapvault_t *sv) /* {{{ */
378 if (sv->query != NULL)
379 na_elem_free (sv->query);
382 } /* }}} void free_cfg_snapvault */
384 static void free_cfg_system (cfg_system_t *cs) /* {{{ */
389 if (cs->query != NULL)
390 na_elem_free (cs->query);
393 } /* }}} void free_cfg_system */
395 static void free_host_config (host_config_t *hc) /* {{{ */
406 sfree (hc->username);
407 sfree (hc->password);
410 free_cfg_disk (hc->cfg_disk);
411 free_cfg_wafl (hc->cfg_wafl);
412 free_cfg_volume_perf (hc->cfg_volume_perf);
413 free_cfg_volume_usage (hc->cfg_volume_usage);
414 free_cfg_snapvault (hc->cfg_snapvault);
415 free_cfg_system (hc->cfg_system);
418 na_server_close (hc->srv);
422 free_host_config (next);
423 } /* }}} void free_host_config */
426 * Auxiliary functions
428 * Used to look up volumes and disks or to handle flags.
430 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
434 if ((cd == NULL) || (name == NULL))
437 for (d = cd->disks; d != NULL; d = d->next) {
438 if (strcmp(d->name, name) == 0)
442 d = malloc(sizeof(*d));
445 memset (d, 0, sizeof (*d));
448 d->name = strdup(name);
449 if (d->name == NULL) {
458 } /* }}} disk_t *get_disk */
460 static data_volume_usage_t *get_volume_usage (cfg_volume_usage_t *cvu, /* {{{ */
463 data_volume_usage_t *last;
464 data_volume_usage_t *new;
466 int ignore_capacity = 0;
467 int ignore_snapshot = 0;
469 if ((cvu == NULL) || (name == NULL))
475 if (strcmp (last->name, name) == 0)
478 if (last->next == NULL)
484 /* Check the ignorelists. If *both* tell us to ignore a volume, return NULL. */
485 ignore_capacity = ignorelist_match (cvu->il_capacity, name);
486 ignore_snapshot = ignorelist_match (cvu->il_snapshot, name);
487 if ((ignore_capacity != 0) && (ignore_snapshot != 0))
490 /* Not found: allocate. */
491 new = malloc (sizeof (*new));
494 memset (new, 0, sizeof (*new));
497 new->name = strdup (name);
498 if (new->name == NULL)
504 if (ignore_capacity == 0)
505 new->flags |= CFG_VOLUME_USAGE_DF;
506 if (ignore_snapshot == 0) {
507 new->flags |= CFG_VOLUME_USAGE_SNAP;
508 new->snap_query = na_elem_new ("snapshot-list-info");
509 na_child_add_string(new->snap_query, "target-type", "volume");
510 na_child_add_string(new->snap_query, "target-name", name);
512 new->snap_query = NULL;
515 /* Add to end of list. */
522 } /* }}} data_volume_usage_t *get_volume_usage */
524 static data_volume_perf_t *get_volume_perf (cfg_volume_perf_t *cvp, /* {{{ */
527 data_volume_perf_t *last;
528 data_volume_perf_t *new;
530 int ignore_octets = 0;
531 int ignore_operations = 0;
532 int ignore_latency = 0;
534 if ((cvp == NULL) || (name == NULL))
540 if (strcmp (last->name, name) == 0)
543 if (last->next == NULL)
549 /* Check the ignorelists. If *all three* tell us to ignore a volume, return
551 ignore_octets = ignorelist_match (cvp->il_octets, name);
552 ignore_operations = ignorelist_match (cvp->il_operations, name);
553 ignore_latency = ignorelist_match (cvp->il_latency, name);
554 if ((ignore_octets != 0) || (ignore_operations != 0)
555 || (ignore_latency != 0))
558 /* Not found: allocate. */
559 new = malloc (sizeof (*new));
562 memset (new, 0, sizeof (*new));
565 new->name = strdup (name);
566 if (new->name == NULL)
572 if (ignore_octets == 0)
573 new->flags |= CFG_VOLUME_PERF_IO;
574 if (ignore_operations == 0)
575 new->flags |= CFG_VOLUME_PERF_OPS;
576 if (ignore_latency == 0)
577 new->flags |= CFG_VOLUME_PERF_LATENCY;
579 /* Add to end of list. */
586 } /* }}} data_volume_perf_t *get_volume_perf */
589 * Various submit functions.
591 * They all eventually call "submit_values" which creates a value_list_t and
592 * dispatches it to the daemon.
594 static int submit_values (const char *host, /* {{{ */
595 const char *plugin_inst,
596 const char *type, const char *type_inst,
597 value_t *values, int values_len,
598 cdtime_t timestamp, cdtime_t interval)
600 value_list_t vl = VALUE_LIST_INIT;
603 vl.values_len = values_len;
609 vl.interval = interval;
612 sstrncpy (vl.host, host, sizeof (vl.host));
614 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
615 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
616 if (plugin_inst != NULL)
617 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
618 sstrncpy (vl.type, type, sizeof (vl.type));
619 if (type_inst != NULL)
620 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
622 return (plugin_dispatch_values (&vl));
623 } /* }}} int submit_uint64 */
625 static int submit_two_derive (const char *host, const char *plugin_inst, /* {{{ */
626 const char *type, const char *type_inst, derive_t val0, derive_t val1,
627 cdtime_t timestamp, cdtime_t interval)
631 values[0].derive = val0;
632 values[1].derive = val1;
634 return (submit_values (host, plugin_inst, type, type_inst,
635 values, 2, timestamp, interval));
636 } /* }}} int submit_two_derive */
638 static int submit_derive (const char *host, const char *plugin_inst, /* {{{ */
639 const char *type, const char *type_inst, derive_t counter,
640 cdtime_t timestamp, cdtime_t interval)
646 return (submit_values (host, plugin_inst, type, type_inst,
647 &v, 1, timestamp, interval));
648 } /* }}} int submit_derive */
650 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
651 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
652 cdtime_t timestamp, cdtime_t interval)
656 values[0].gauge = val0;
657 values[1].gauge = val1;
659 return (submit_values (host, plugin_inst, type, type_inst,
660 values, 2, timestamp, interval));
661 } /* }}} int submit_two_gauge */
663 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
664 const char *type, const char *type_inst, double d,
665 cdtime_t timestamp, cdtime_t interval)
669 v.gauge = (gauge_t) d;
671 return (submit_values (host, plugin_inst, type, type_inst,
672 &v, 1, timestamp, interval));
673 } /* }}} int submit_uint64 */
675 /* Calculate hit ratio from old and new counters and submit the resulting
676 * percentage. Used by "submit_wafl_data". */
677 static int submit_cache_ratio (const char *host, /* {{{ */
678 const char *plugin_inst,
679 const char *type_inst,
689 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
693 hits = new_hits - old_hits;
694 misses = new_misses - old_misses;
696 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
701 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
702 &v, 1, timestamp, interval));
703 } /* }}} int submit_cache_ratio */
705 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
706 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
707 cfg_wafl_t *old_data, const cfg_wafl_t *new_data, int interval)
709 /* Submit requested counters */
710 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
711 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
712 submit_cache_ratio (hostname, instance, "name_cache_hit",
713 new_data->name_cache_hit, new_data->name_cache_miss,
714 old_data->name_cache_hit, old_data->name_cache_miss,
715 new_data->timestamp, interval);
717 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
718 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
719 submit_cache_ratio (hostname, instance, "find_dir_hit",
720 new_data->find_dir_hit, new_data->find_dir_miss,
721 old_data->find_dir_hit, old_data->find_dir_miss,
722 new_data->timestamp, interval);
724 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
725 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
726 submit_cache_ratio (hostname, instance, "buf_hash_hit",
727 new_data->buf_hash_hit, new_data->buf_hash_miss,
728 old_data->buf_hash_hit, old_data->buf_hash_miss,
729 new_data->timestamp, interval);
731 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
732 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
733 submit_cache_ratio (hostname, instance, "inode_cache_hit",
734 new_data->inode_cache_hit, new_data->inode_cache_miss,
735 old_data->inode_cache_hit, old_data->inode_cache_miss,
736 new_data->timestamp, interval);
738 /* Clear old HAVE_* flags */
739 old_data->flags &= ~HAVE_WAFL_ALL;
741 /* Copy all counters */
742 old_data->timestamp = new_data->timestamp;
743 old_data->name_cache_hit = new_data->name_cache_hit;
744 old_data->name_cache_miss = new_data->name_cache_miss;
745 old_data->find_dir_hit = new_data->find_dir_hit;
746 old_data->find_dir_miss = new_data->find_dir_miss;
747 old_data->buf_hash_hit = new_data->buf_hash_hit;
748 old_data->buf_hash_miss = new_data->buf_hash_miss;
749 old_data->inode_cache_hit = new_data->inode_cache_hit;
750 old_data->inode_cache_miss = new_data->inode_cache_miss;
752 /* Copy HAVE_* flags */
753 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
756 } /* }}} int submit_wafl_data */
758 /* Submits volume performance data to the daemon, taking care to honor and
759 * update flags appropriately. */
760 static int submit_volume_perf_data (const char *hostname, /* {{{ */
761 data_volume_perf_t *old_data,
762 const data_volume_perf_t *new_data, int interval)
764 char plugin_instance[DATA_MAX_NAME_LEN];
766 if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
769 ssnprintf (plugin_instance, sizeof (plugin_instance),
770 "volume-%s", old_data->name);
772 /* Check for and submit disk-octet values */
773 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
774 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
776 submit_two_derive (hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
777 (derive_t) new_data->read_bytes, (derive_t) new_data->write_bytes, new_data->timestamp, interval);
780 /* Check for and submit disk-operations values */
781 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
782 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
784 submit_two_derive (hostname, plugin_instance, "disk_ops", /* type instance = */ NULL,
785 (derive_t) new_data->read_ops, (derive_t) new_data->write_ops, new_data->timestamp, interval);
788 /* Check for, calculate and submit disk-latency values */
789 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
790 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
791 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
792 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
793 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
795 gauge_t latency_per_op_read;
796 gauge_t latency_per_op_write;
798 latency_per_op_read = NAN;
799 latency_per_op_write = NAN;
801 /* Check if a counter wrapped around. */
802 if ((new_data->read_ops > old_data->read_ops)
803 && (new_data->read_latency > old_data->read_latency))
805 uint64_t diff_ops_read;
806 uint64_t diff_latency_read;
808 diff_ops_read = new_data->read_ops - old_data->read_ops;
809 diff_latency_read = new_data->read_latency - old_data->read_latency;
811 if (diff_ops_read > 0)
812 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
815 if ((new_data->write_ops > old_data->write_ops)
816 && (new_data->write_latency > old_data->write_latency))
818 uint64_t diff_ops_write;
819 uint64_t diff_latency_write;
821 diff_ops_write = new_data->write_ops - old_data->write_ops;
822 diff_latency_write = new_data->write_latency - old_data->write_latency;
824 if (diff_ops_write > 0)
825 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
828 submit_two_gauge (hostname, plugin_instance, "disk_latency", /* type instance = */ NULL,
829 latency_per_op_read, latency_per_op_write, new_data->timestamp, interval);
832 /* Clear all HAVE_* flags. */
833 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
835 /* Copy all counters */
836 old_data->timestamp = new_data->timestamp;
837 old_data->read_bytes = new_data->read_bytes;
838 old_data->write_bytes = new_data->write_bytes;
839 old_data->read_ops = new_data->read_ops;
840 old_data->write_ops = new_data->write_ops;
841 old_data->read_latency = new_data->read_latency;
842 old_data->write_latency = new_data->write_latency;
844 /* Copy the HAVE_* flags */
845 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
848 } /* }}} int submit_volume_perf_data */
850 static cdtime_t cna_child_get_cdtime (na_elem_t *data) /* {{{ */
854 t = (time_t) na_child_get_uint64 (data, "timestamp", /* default = */ 0);
856 return (TIME_T_TO_CDTIME_T (t));
857 } /* }}} cdtime_t cna_child_get_cdtime */
863 * These functions are called with appropriate data returned by the libnetapp
864 * interface which is parsed and submitted with the above functions.
866 /* Data corresponding to <WAFL /> */
867 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
868 na_elem_t *data, int interval)
870 cfg_wafl_t perf_data;
871 const char *plugin_inst;
873 na_elem_t *instances;
875 na_elem_iter_t counter_iter;
877 memset (&perf_data, 0, sizeof (perf_data));
879 perf_data.timestamp = cna_child_get_cdtime (data);
881 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
882 if (instances == NULL)
884 ERROR ("netapp plugin: cna_handle_wafl_data: "
885 "na_elem_child (\"instances\") failed "
886 "for host %s.", hostname);
890 plugin_inst = na_child_get_string(instances, "name");
891 if (plugin_inst == NULL)
893 ERROR ("netapp plugin: cna_handle_wafl_data: "
894 "na_child_get_string (\"name\") failed "
895 "for host %s.", hostname);
899 /* Iterate over all counters */
900 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
901 for (counter = na_iterator_next (&counter_iter);
903 counter = na_iterator_next (&counter_iter))
908 name = na_child_get_string(counter, "name");
912 value = na_child_get_uint64(counter, "value", UINT64_MAX);
913 if (value == UINT64_MAX)
916 if (!strcmp(name, "name_cache_hit")) {
917 perf_data.name_cache_hit = value;
918 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
919 } else if (!strcmp(name, "name_cache_miss")) {
920 perf_data.name_cache_miss = value;
921 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
922 } else if (!strcmp(name, "find_dir_hit")) {
923 perf_data.find_dir_hit = value;
924 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
925 } else if (!strcmp(name, "find_dir_miss")) {
926 perf_data.find_dir_miss = value;
927 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
928 } else if (!strcmp(name, "buf_hash_hit")) {
929 perf_data.buf_hash_hit = value;
930 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
931 } else if (!strcmp(name, "buf_hash_miss")) {
932 perf_data.buf_hash_miss = value;
933 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
934 } else if (!strcmp(name, "inode_cache_hit")) {
935 perf_data.inode_cache_hit = value;
936 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
937 } else if (!strcmp(name, "inode_cache_miss")) {
938 perf_data.inode_cache_miss = value;
939 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
941 DEBUG("netapp plugin: cna_handle_wafl_data: "
942 "Found unexpected child: %s "
943 "for host %s.", name, hostname);
947 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data, interval));
948 } /* }}} void cna_handle_wafl_data */
950 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
957 if (cw->query != NULL)
960 cw->query = na_elem_new("perf-object-get-instances");
961 if (cw->query == NULL)
963 ERROR ("netapp plugin: na_elem_new failed.");
966 na_child_add_string (cw->query, "objectname", "wafl");
968 e = na_elem_new("counters");
971 na_elem_free (cw->query);
973 ERROR ("netapp plugin: na_elem_new failed.");
976 na_child_add_string(e, "counter", "name_cache_hit");
977 na_child_add_string(e, "counter", "name_cache_miss");
978 na_child_add_string(e, "counter", "find_dir_hit");
979 na_child_add_string(e, "counter", "find_dir_miss");
980 na_child_add_string(e, "counter", "buf_hash_hit");
981 na_child_add_string(e, "counter", "buf_hash_miss");
982 na_child_add_string(e, "counter", "inode_cache_hit");
983 na_child_add_string(e, "counter", "inode_cache_miss");
985 na_child_add(cw->query, e);
988 } /* }}} int cna_setup_wafl */
990 static int cna_query_wafl (host_config_t *host) /* {{{ */
999 /* If WAFL was not configured, return without doing anything. */
1000 if (host->cfg_wafl == NULL)
1004 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
1007 status = cna_setup_wafl (host->cfg_wafl);
1010 assert (host->cfg_wafl->query != NULL);
1012 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
1013 if (na_results_status (data) != NA_OK)
1015 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed for host %s: %s",
1016 host->name, na_results_reason (data));
1017 na_elem_free (data);
1021 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data, host->interval);
1024 host->cfg_wafl->interval.last_read = now;
1026 na_elem_free (data);
1028 } /* }}} int cna_query_wafl */
1030 /* Data corresponding to <Disks /> */
1031 static int cna_handle_disk_data (const char *hostname, /* {{{ */
1032 cfg_disk_t *cfg_disk, na_elem_t *data, cdtime_t interval)
1035 na_elem_t *instances;
1036 na_elem_t *instance;
1037 na_elem_iter_t instance_iter;
1038 disk_t *worst_disk = NULL;
1040 if ((cfg_disk == NULL) || (data == NULL))
1043 timestamp = cna_child_get_cdtime (data);
1045 instances = na_elem_child (data, "instances");
1046 if (instances == NULL)
1048 ERROR ("netapp plugin: cna_handle_disk_data: "
1049 "na_elem_child (\"instances\") failed "
1050 "for host %s.", hostname);
1054 /* Iterate over all children */
1055 instance_iter = na_child_iterator (instances);
1056 for (instance = na_iterator_next (&instance_iter);
1058 instance = na_iterator_next(&instance_iter))
1063 na_elem_iter_t counter_iterator;
1066 memset (&new_data, 0, sizeof (new_data));
1067 new_data.timestamp = timestamp;
1068 new_data.disk_busy_percent = NAN;
1070 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1071 if (old_data == NULL)
1074 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1075 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1076 for (counter = na_iterator_next(&counter_iterator);
1078 counter = na_iterator_next(&counter_iterator))
1083 name = na_child_get_string(counter, "name");
1087 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1088 if (value == UINT64_MAX)
1091 if (strcmp(name, "disk_busy") == 0)
1093 new_data.disk_busy = value;
1094 new_data.flags |= HAVE_DISK_BUSY;
1096 else if (strcmp(name, "base_for_disk_busy") == 0)
1098 new_data.base_for_disk_busy = value;
1099 new_data.flags |= HAVE_DISK_BASE;
1103 DEBUG ("netapp plugin: cna_handle_disk_data: "
1104 "Counter not handled: %s = %"PRIu64,
1109 /* If all required counters are available and did not just wrap around,
1110 * calculate the busy percentage. Otherwise, the value is initialized to
1111 * NAN at the top of the for-loop. */
1112 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1113 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1114 && (new_data.disk_busy >= old_data->disk_busy)
1115 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1120 busy_diff = new_data.disk_busy - old_data->disk_busy;
1121 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1123 new_data.disk_busy_percent = 100.0
1124 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1127 /* Clear HAVE_* flags */
1128 old_data->flags &= ~HAVE_DISK_ALL;
1131 old_data->timestamp = new_data.timestamp;
1132 old_data->disk_busy = new_data.disk_busy;
1133 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1134 old_data->disk_busy_percent = new_data.disk_busy_percent;
1137 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1139 if ((worst_disk == NULL)
1140 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1141 worst_disk = old_data;
1142 } /* for (all disks) */
1144 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1145 submit_double (hostname, "system", "percent", "disk_busy",
1146 worst_disk->disk_busy_percent, timestamp, interval);
1149 } /* }}} int cna_handle_disk_data */
1151 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1158 if (cd->query != NULL)
1161 cd->query = na_elem_new ("perf-object-get-instances");
1162 if (cd->query == NULL)
1164 ERROR ("netapp plugin: na_elem_new failed.");
1167 na_child_add_string (cd->query, "objectname", "disk");
1169 e = na_elem_new("counters");
1172 na_elem_free (cd->query);
1174 ERROR ("netapp plugin: na_elem_new failed.");
1177 na_child_add_string(e, "counter", "disk_busy");
1178 na_child_add_string(e, "counter", "base_for_disk_busy");
1179 na_child_add(cd->query, e);
1182 } /* }}} int cna_setup_disk */
1184 static int cna_query_disk (host_config_t *host) /* {{{ */
1193 /* If the user did not configure disk statistics, return without doing
1195 if (host->cfg_disk == NULL)
1199 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1202 status = cna_setup_disk (host->cfg_disk);
1205 assert (host->cfg_disk->query != NULL);
1207 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1208 if (na_results_status (data) != NA_OK)
1210 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed for host %s: %s",
1211 host->name, na_results_reason (data));
1212 na_elem_free (data);
1216 status = cna_handle_disk_data (host->name, host->cfg_disk, data, host->interval);
1219 host->cfg_disk->interval.last_read = now;
1221 na_elem_free (data);
1223 } /* }}} int cna_query_disk */
1225 /* Data corresponding to <VolumePerf /> */
1226 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1227 cfg_volume_perf_t *cvp, na_elem_t *data, cdtime_t interval)
1230 na_elem_t *elem_instances;
1231 na_elem_iter_t iter_instances;
1232 na_elem_t *elem_instance;
1234 timestamp = cna_child_get_cdtime (data);
1236 elem_instances = na_elem_child(data, "instances");
1237 if (elem_instances == NULL)
1239 ERROR ("netapp plugin: handle_volume_perf_data: "
1240 "na_elem_child (\"instances\") failed "
1241 "for host %s.", hostname);
1245 iter_instances = na_child_iterator (elem_instances);
1246 for (elem_instance = na_iterator_next(&iter_instances);
1247 elem_instance != NULL;
1248 elem_instance = na_iterator_next(&iter_instances))
1252 data_volume_perf_t perf_data;
1253 data_volume_perf_t *v;
1255 na_elem_t *elem_counters;
1256 na_elem_iter_t iter_counters;
1257 na_elem_t *elem_counter;
1259 memset (&perf_data, 0, sizeof (perf_data));
1260 perf_data.timestamp = timestamp;
1262 name = na_child_get_string (elem_instance, "name");
1266 /* get_volume_perf may return NULL if this volume is to be ignored. */
1267 v = get_volume_perf (cvp, name);
1271 elem_counters = na_elem_child (elem_instance, "counters");
1272 if (elem_counters == NULL)
1275 iter_counters = na_child_iterator (elem_counters);
1276 for (elem_counter = na_iterator_next(&iter_counters);
1277 elem_counter != NULL;
1278 elem_counter = na_iterator_next(&iter_counters))
1283 name = na_child_get_string (elem_counter, "name");
1287 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1288 if (value == UINT64_MAX)
1291 if (!strcmp(name, "read_data")) {
1292 perf_data.read_bytes = value;
1293 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1294 } else if (!strcmp(name, "write_data")) {
1295 perf_data.write_bytes = value;
1296 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1297 } else if (!strcmp(name, "read_ops")) {
1298 perf_data.read_ops = value;
1299 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1300 } else if (!strcmp(name, "write_ops")) {
1301 perf_data.write_ops = value;
1302 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1303 } else if (!strcmp(name, "read_latency")) {
1304 perf_data.read_latency = value;
1305 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1306 } else if (!strcmp(name, "write_latency")) {
1307 perf_data.write_latency = value;
1308 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1310 } /* for (elem_counter) */
1312 submit_volume_perf_data (hostname, v, &perf_data, interval);
1313 } /* for (volume) */
1316 } /* }}} int cna_handle_volume_perf_data */
1318 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1325 if (cd->query != NULL)
1328 cd->query = na_elem_new ("perf-object-get-instances");
1329 if (cd->query == NULL)
1331 ERROR ("netapp plugin: na_elem_new failed.");
1334 na_child_add_string (cd->query, "objectname", "volume");
1336 e = na_elem_new("counters");
1339 na_elem_free (cd->query);
1341 ERROR ("netapp plugin: na_elem_new failed.");
1344 na_child_add_string(e, "counter", "read_ops");
1345 na_child_add_string(e, "counter", "write_ops");
1346 na_child_add_string(e, "counter", "read_data");
1347 na_child_add_string(e, "counter", "write_data");
1348 na_child_add_string(e, "counter", "read_latency");
1349 na_child_add_string(e, "counter", "write_latency");
1350 na_child_add(cd->query, e);
1353 } /* }}} int cna_setup_volume_perf */
1355 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1364 /* If the user did not configure volume performance statistics, return
1365 * without doing anything. */
1366 if (host->cfg_volume_perf == NULL)
1370 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1373 status = cna_setup_volume_perf (host->cfg_volume_perf);
1376 assert (host->cfg_volume_perf->query != NULL);
1378 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1379 if (na_results_status (data) != NA_OK)
1381 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed for host %s: %s",
1382 host->name, na_results_reason (data));
1383 na_elem_free (data);
1387 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data, host->interval);
1390 host->cfg_volume_perf->interval.last_read = now;
1392 na_elem_free (data);
1394 } /* }}} int cna_query_volume_perf */
1396 /* Data corresponding to <VolumeUsage /> */
1397 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1398 cfg_volume_usage_t *cfg_volume, int interval)
1400 data_volume_usage_t *v;
1402 for (v = cfg_volume->volumes; v != NULL; v = v->next)
1404 char plugin_instance[DATA_MAX_NAME_LEN];
1406 uint64_t norm_used = v->norm_used;
1407 uint64_t norm_free = v->norm_free;
1408 uint64_t sis_saved = v->sis_saved;
1409 uint64_t compress_saved = v->compress_saved;
1410 uint64_t dedup_saved = v->dedup_saved;
1411 uint64_t snap_reserve_used = 0;
1412 uint64_t snap_reserve_free = v->snap_reserved;
1413 uint64_t snap_norm_used = v->snap_used;
1415 ssnprintf (plugin_instance, sizeof (plugin_instance),
1416 "volume-%s", v->name);
1418 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD)) {
1419 if (v->snap_reserved > v->snap_used) {
1420 snap_reserve_free = v->snap_reserved - v->snap_used;
1421 snap_reserve_used = v->snap_used;
1424 snap_reserve_free = 0;
1425 snap_reserve_used = v->snap_reserved;
1426 snap_norm_used = v->snap_used - v->snap_reserved;
1430 /* The space used by snapshots but not reserved for them is included in
1431 * both, norm_used and snap_norm_used. If possible, subtract this here. */
1432 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED))
1434 if (norm_used >= snap_norm_used)
1435 norm_used -= snap_norm_used;
1438 ERROR ("netapp plugin: (norm_used = %"PRIu64") < (snap_norm_used = "
1439 "%"PRIu64") for host %s. Invalidating both.",
1440 norm_used, snap_norm_used, hostname);
1441 v->flags &= ~(HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED);
1445 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1446 submit_double (hostname, /* plugin instance = */ plugin_instance,
1447 "df_complex", "free",
1448 (double) norm_free, /* timestamp = */ 0, interval);
1450 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1451 submit_double (hostname, /* plugin instance = */ plugin_instance,
1452 "df_complex", "sis_saved",
1453 (double) sis_saved, /* timestamp = */ 0, interval);
1455 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_COMPRESS_SAVED))
1456 submit_double (hostname, /* plugin instance = */ plugin_instance,
1457 "df_complex", "compression_saved",
1458 (double) compress_saved, /* timestamp = */ 0, interval);
1460 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_DEDUP_SAVED))
1461 submit_double (hostname, /* plugin instance = */ plugin_instance,
1462 "df_complex", "dedup_saved",
1463 (double) dedup_saved, /* timestamp = */ 0, interval);
1465 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1466 submit_double (hostname, /* plugin instance = */ plugin_instance,
1467 "df_complex", "used",
1468 (double) norm_used, /* timestamp = */ 0, interval);
1470 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1471 submit_double (hostname, /* plugin instance = */ plugin_instance,
1472 "df_complex", "snap_reserved",
1473 (double) snap_reserve_free, /* timestamp = */ 0, interval);
1475 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
1476 submit_double (hostname, /* plugin instance = */ plugin_instance,
1477 "df_complex", "snap_reserve_used",
1478 (double) snap_reserve_used, /* timestamp = */ 0, interval);
1480 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1481 submit_double (hostname, /* plugin instance = */ plugin_instance,
1482 "df_complex", "snap_normal_used",
1483 (double) snap_norm_used, /* timestamp = */ 0, interval);
1485 /* Clear all the HAVE_* flags */
1486 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1487 } /* for (v = cfg_volume->volumes) */
1490 } /* }}} int cna_submit_volume_usage_data */
1492 /* Switch the state of a volume between online and offline and send out a
1494 static int cna_change_volume_status (const char *hostname, /* {{{ */
1495 data_volume_usage_t *v)
1499 memset (&n, 0, sizeof (&n));
1501 sstrncpy (n.host, hostname, sizeof (n.host));
1502 sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
1503 sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance));
1505 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
1506 n.severity = NOTIF_OKAY;
1507 ssnprintf (n.message, sizeof (n.message),
1508 "Volume %s is now online.", v->name);
1509 v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
1511 n.severity = NOTIF_WARNING;
1512 ssnprintf (n.message, sizeof (n.message),
1513 "Volume %s is now offline.", v->name);
1514 v->flags |= IS_VOLUME_USAGE_OFFLINE;
1517 return (plugin_dispatch_notification (&n));
1518 } /* }}} int cna_change_volume_status */
1520 static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
1521 data_volume_usage_t *v)
1523 uint64_t snap_used = 0, value;
1524 na_elem_t *data, *elem_snap, *elem_snapshots;
1525 na_elem_iter_t iter_snap;
1527 data = na_server_invoke_elem(host->srv, v->snap_query);
1528 if (na_results_status(data) != NA_OK)
1530 if (na_results_errno(data) == EVOLUMEOFFLINE) {
1531 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
1532 cna_change_volume_status (host->name, v);
1534 ERROR ("netapp plugin: cna_handle_volume_snap_usage: na_server_invoke_elem for "
1535 "volume \"%s\" on host %s failed with error %d: %s", v->name,
1536 host->name, na_results_errno(data), na_results_reason(data));
1542 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0)
1543 cna_change_volume_status (host->name, v);
1545 elem_snapshots = na_elem_child (data, "snapshots");
1546 if (elem_snapshots == NULL)
1548 ERROR ("netapp plugin: cna_handle_volume_snap_usage: "
1549 "na_elem_child (\"snapshots\") failed "
1550 "for host %s.", host->name);
1555 iter_snap = na_child_iterator (elem_snapshots);
1556 for (elem_snap = na_iterator_next (&iter_snap);
1558 elem_snap = na_iterator_next (&iter_snap))
1560 value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
1561 /* "cumulative-total" is the total size of the oldest snapshot plus all
1562 * newer ones in blocks (1KB). We therefore are looking for the highest
1563 * number of all snapshots - that's the size required for the snapshots. */
1564 if (value > snap_used)
1567 na_elem_free (data);
1568 /* snap_used is in 1024 byte blocks */
1569 v->snap_used = snap_used * 1024;
1570 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1571 } /* }}} void cna_handle_volume_snap_usage */
1573 static void cna_handle_volume_sis_data (const host_config_t *host, /* {{{ */
1574 data_volume_usage_t *v, na_elem_t *sis)
1576 const char *sis_state;
1577 uint64_t sis_saved_reported;
1579 if (na_elem_child(sis, "sis-info"))
1580 sis = na_elem_child(sis, "sis-info");
1582 sis_state = na_child_get_string(sis, "state");
1583 if (sis_state == NULL)
1586 /* If SIS is not enabled, there's nothing left to do for this volume. */
1587 if (strcmp ("enabled", sis_state) != 0)
1590 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1591 if (sis_saved_reported == UINT64_MAX)
1594 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1595 if ((sis_saved_reported >> 32) != 0) {
1596 /* In case they ever fix this bug. */
1597 v->sis_saved = sis_saved_reported;
1598 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1599 } else { /* really hacky work-around code. {{{ */
1600 uint64_t sis_saved_percent;
1601 uint64_t sis_saved_guess;
1602 uint64_t overflow_guess;
1603 uint64_t guess1, guess2, guess3;
1605 /* Check if we have v->norm_used. Without it, we cannot calculate
1606 * sis_saved_guess. */
1607 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1610 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1611 if (sis_saved_percent > 100)
1614 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1615 * will hopefully be fixed in later versions. To work around the bug, try
1616 * to figure out how often the 32bit integer wrapped around by using the
1617 * "percentage-saved" value. Because the percentage is in the range
1618 * [0-100], this should work as long as the saved space does not exceed
1620 /* percentage-saved = size-saved / (size-saved + size-used) */
1621 if (sis_saved_percent < 100)
1622 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1624 sis_saved_guess = v->norm_used;
1626 overflow_guess = sis_saved_guess >> 32;
1627 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1628 guess2 = (overflow_guess << 32) + sis_saved_reported;
1629 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1631 if (sis_saved_guess < guess2) {
1632 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1633 v->sis_saved = guess1;
1635 v->sis_saved = guess2;
1637 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1638 v->sis_saved = guess2;
1640 v->sis_saved = guess3;
1642 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1643 } /* }}} end of 32-bit workaround */
1644 } /* }}} void cna_handle_volume_sis_data */
1646 /* ONTAP >= 8.1 uses SIS for managing dedup and compression */
1647 static void cna_handle_volume_sis_saved (const host_config_t *host, /* {{{ */
1648 data_volume_usage_t *v, na_elem_t *sis)
1652 if (na_elem_child(sis, "sis-info"))
1653 sis = na_elem_child(sis, "sis-info");
1655 saved = na_child_get_uint64(sis, "compress-saved", UINT64_MAX);
1656 if (saved != UINT64_MAX) {
1657 v->compress_saved = saved;
1658 v->flags |= HAVE_VOLUME_USAGE_COMPRESS_SAVED;
1661 saved = na_child_get_uint64(sis, "dedup-saved", UINT64_MAX);
1662 if (saved != UINT64_MAX) {
1663 v->dedup_saved = saved;
1664 v->flags |= HAVE_VOLUME_USAGE_DEDUP_SAVED;
1666 } /* }}} void cna_handle_volume_sis_saved */
1668 static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
1669 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1671 na_elem_t *elem_volume;
1672 na_elem_t *elem_volumes;
1673 na_elem_iter_t iter_volume;
1675 elem_volumes = na_elem_child (data, "volumes");
1676 if (elem_volumes == NULL)
1678 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1679 "na_elem_child (\"volumes\") failed "
1680 "for host %s.", host->name);
1684 iter_volume = na_child_iterator (elem_volumes);
1685 for (elem_volume = na_iterator_next (&iter_volume);
1686 elem_volume != NULL;
1687 elem_volume = na_iterator_next (&iter_volume))
1689 const char *volume_name, *state;
1691 data_volume_usage_t *v;
1696 volume_name = na_child_get_string (elem_volume, "name");
1697 if (volume_name == NULL)
1700 state = na_child_get_string (elem_volume, "state");
1701 if ((state == NULL) || (strcmp(state, "online") != 0))
1704 /* get_volume_usage may return NULL if the volume is to be ignored. */
1705 v = get_volume_usage (cfg_volume, volume_name);
1709 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1710 cna_handle_volume_snap_usage(host, v);
1712 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1715 /* 2^4 exa-bytes? This will take a while ;) */
1716 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1717 if (value != UINT64_MAX) {
1718 v->norm_free = value;
1719 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1722 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1723 if (value != UINT64_MAX) {
1724 v->norm_used = value;
1725 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1728 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1729 if (value != UINT64_MAX) {
1730 /* 1 block == 1024 bytes as per API docs */
1731 v->snap_reserved = 1024 * value;
1732 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1735 sis = na_elem_child(elem_volume, "sis");
1737 cna_handle_volume_sis_data (host, v, sis);
1738 cna_handle_volume_sis_saved (host, v, sis);
1740 } /* for (elem_volume) */
1742 return (cna_submit_volume_usage_data (host->name, cfg_volume, host->interval));
1743 } /* }}} int cna_handle_volume_usage_data */
1745 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1750 if (cvu->query != NULL)
1753 cvu->query = na_elem_new ("volume-list-info");
1754 if (cvu->query == NULL)
1756 ERROR ("netapp plugin: na_elem_new failed.");
1761 } /* }}} int cna_setup_volume_usage */
1763 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1772 /* If the user did not configure volume_usage statistics, return without
1773 * doing anything. */
1774 if (host->cfg_volume_usage == NULL)
1778 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1781 status = cna_setup_volume_usage (host->cfg_volume_usage);
1784 assert (host->cfg_volume_usage->query != NULL);
1786 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1787 if (na_results_status (data) != NA_OK)
1789 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed for host %s: %s",
1790 host->name, na_results_reason (data));
1791 na_elem_free (data);
1795 status = cna_handle_volume_usage_data (host, host->cfg_volume_usage, data);
1798 host->cfg_volume_usage->interval.last_read = now;
1800 na_elem_free (data);
1802 } /* }}} int cna_query_volume_usage */
1804 /* Data corresponding to <SnapVault /> */
1805 static int cna_handle_snapvault_data (const char *hostname, /* {{{ */
1806 cfg_snapvault_t *cfg_snapvault, na_elem_t *data, cdtime_t interval)
1809 na_elem_iter_t status_iter;
1811 status = na_elem_child (data, "status-list");
1813 ERROR ("netapp plugin: SnapVault status record missing status-list");
1817 status_iter = na_child_iterator (status);
1818 for (status = na_iterator_next (&status_iter);
1820 status = na_iterator_next (&status_iter))
1822 const char *dest_sys, *dest_path, *src_sys, *src_path;
1823 char plugin_instance[DATA_MAX_NAME_LEN];
1826 dest_sys = na_child_get_string (status, "destination-system");
1827 dest_path = na_child_get_string (status, "destination-path");
1828 src_sys = na_child_get_string (status, "source-system");
1829 src_path = na_child_get_string (status, "source-path");
1831 if ((! dest_sys) || (! dest_path) || (! src_sys) || (! src_path))
1834 value = na_child_get_uint64 (status, "lag-time", UINT64_MAX);
1835 if (value == UINT64_MAX) /* no successful baseline transfer yet */
1838 /* possible TODO: make plugin instance configurable */
1839 ssnprintf (plugin_instance, sizeof (plugin_instance),
1840 "snapvault-%s", dest_path);
1841 submit_double (hostname, plugin_instance, /* type = */ "delay", NULL,
1842 (double)value, /* timestamp = */ 0, interval);
1844 value = na_child_get_uint64 (status, "last-transfer-duration", UINT64_MAX);
1845 if (value != UINT64_MAX)
1846 submit_double (hostname, plugin_instance, /* type = */ "duration", "last_transfer",
1847 (double)value, /* timestamp = */ 0, interval);
1849 value = na_child_get_uint64 (status, "transfer-progress", UINT64_MAX);
1850 if (value == UINT64_MAX)
1851 value = na_child_get_uint64 (status, "last-transfer-size", UINT64_MAX);
1852 if (value != UINT64_MAX) {
1853 value *= 1024; /* this is kilobytes */
1854 submit_derive (hostname, plugin_instance, /* type = */ "if_rx_octets", "transferred",
1855 value, /* timestamp = */ 0, interval);
1857 } /* for (status) */
1860 } /* }}} int cna_handle_snapvault_data */
1862 static int cna_handle_snapvault_iter (host_config_t *host, /* {{{ */
1867 uint32_t records_count;
1870 records_count = na_child_get_uint32 (data, "records", UINT32_MAX);
1871 if (records_count == UINT32_MAX)
1874 tag = na_child_get_string (data, "tag");
1878 DEBUG ("netapp plugin: Iterating %u SV records (tag = %s)", records_count, tag);
1880 for (i = 0; i < records_count; ++i) {
1883 elem = na_server_invoke (host->srv,
1884 "snapvault-secondary-relationship-status-list-iter-next",
1885 "maximum", "1", "tag", tag, NULL);
1887 if (na_results_status (elem) != NA_OK)
1889 ERROR ("netapp plugin: cna_handle_snapvault_iter: "
1890 "na_server_invoke failed for host %s: %s",
1891 host->name, na_results_reason (data));
1892 na_elem_free (elem);
1896 cna_handle_snapvault_data (host->name, host->cfg_snapvault, elem, host->interval);
1897 na_elem_free (elem);
1900 na_elem_free (na_server_invoke (host->srv,
1901 "snapvault-secondary-relationship-status-list-iter-end",
1904 } /* }}} int cna_handle_snapvault_iter */
1906 static int cna_setup_snapvault (cfg_snapvault_t *sv) /* {{{ */
1911 if (sv->query != NULL)
1914 sv->query = na_elem_new ("snapvault-secondary-relationship-status-list-iter-start");
1915 if (sv->query == NULL)
1917 ERROR ("netapp plugin: na_elem_new failed.");
1922 } /* }}} int cna_setup_snapvault */
1924 static int cna_query_snapvault (host_config_t *host) /* {{{ */
1933 if (host->cfg_snapvault == NULL)
1937 if ((host->cfg_snapvault->interval.interval + host->cfg_snapvault->interval.last_read) > now)
1940 status = cna_setup_snapvault (host->cfg_snapvault);
1943 assert (host->cfg_snapvault->query != NULL);
1945 data = na_server_invoke_elem (host->srv, host->cfg_snapvault->query);
1946 if (na_results_status (data) != NA_OK)
1948 ERROR ("netapp plugin: cna_query_snapvault: na_server_invoke_elem failed for host %s: %s",
1949 host->name, na_results_reason (data));
1950 na_elem_free (data);
1954 status = cna_handle_snapvault_iter (host, data);
1957 host->cfg_snapvault->interval.last_read = now;
1959 na_elem_free (data);
1961 } /* }}} int cna_query_snapvault */
1963 /* Data corresponding to <System /> */
1964 static int cna_handle_system_data (const char *hostname, /* {{{ */
1965 cfg_system_t *cfg_system, na_elem_t *data, int interval)
1967 na_elem_t *instances;
1969 na_elem_iter_t counter_iter;
1971 derive_t disk_read = 0, disk_written = 0;
1972 derive_t net_recv = 0, net_sent = 0;
1973 derive_t cpu_busy = 0, cpu_total = 0;
1974 uint32_t counter_flags = 0;
1976 const char *instance;
1979 timestamp = cna_child_get_cdtime (data);
1981 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1982 if (instances == NULL)
1984 ERROR ("netapp plugin: cna_handle_system_data: "
1985 "na_elem_child (\"instances\") failed "
1986 "for host %s.", hostname);
1990 instance = na_child_get_string (instances, "name");
1991 if (instance == NULL)
1993 ERROR ("netapp plugin: cna_handle_system_data: "
1994 "na_child_get_string (\"name\") failed "
1995 "for host %s.", hostname);
1999 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
2000 for (counter = na_iterator_next (&counter_iter);
2002 counter = na_iterator_next (&counter_iter))
2007 name = na_child_get_string(counter, "name");
2011 value = na_child_get_uint64(counter, "value", UINT64_MAX);
2012 if (value == UINT64_MAX)
2015 if (!strcmp(name, "disk_data_read")) {
2016 disk_read = (derive_t) (value * 1024);
2017 counter_flags |= 0x01;
2018 } else if (!strcmp(name, "disk_data_written")) {
2019 disk_written = (derive_t) (value * 1024);
2020 counter_flags |= 0x02;
2021 } else if (!strcmp(name, "net_data_recv")) {
2022 net_recv = (derive_t) (value * 1024);
2023 counter_flags |= 0x04;
2024 } else if (!strcmp(name, "net_data_sent")) {
2025 net_sent = (derive_t) (value * 1024);
2026 counter_flags |= 0x08;
2027 } else if (!strcmp(name, "cpu_busy")) {
2028 cpu_busy = (derive_t) value;
2029 counter_flags |= 0x10;
2030 } else if (!strcmp(name, "cpu_elapsed_time")) {
2031 cpu_total = (derive_t) value;
2032 counter_flags |= 0x20;
2033 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
2034 && (value > 0) && (strlen(name) > 4)
2035 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
2036 submit_derive (hostname, instance, "disk_ops_complex", name,
2037 (derive_t) value, timestamp, interval);
2039 } /* for (counter) */
2041 if ((cfg_system->flags & CFG_SYSTEM_DISK)
2042 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
2043 submit_two_derive (hostname, instance, "disk_octets", NULL,
2044 disk_read, disk_written, timestamp, interval);
2046 if ((cfg_system->flags & CFG_SYSTEM_NET)
2047 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
2048 submit_two_derive (hostname, instance, "if_octets", NULL,
2049 net_recv, net_sent, timestamp, interval);
2051 if ((cfg_system->flags & CFG_SYSTEM_CPU)
2052 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
2054 submit_derive (hostname, instance, "cpu", "system",
2055 cpu_busy, timestamp, interval);
2056 submit_derive (hostname, instance, "cpu", "idle",
2057 cpu_total - cpu_busy, timestamp, interval);
2061 } /* }}} int cna_handle_system_data */
2063 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
2068 if (cs->query != NULL)
2071 cs->query = na_elem_new ("perf-object-get-instances");
2072 if (cs->query == NULL)
2074 ERROR ("netapp plugin: na_elem_new failed.");
2077 na_child_add_string (cs->query, "objectname", "system");
2080 } /* }}} int cna_setup_system */
2082 static int cna_query_system (host_config_t *host) /* {{{ */
2091 /* If system statistics were not configured, return without doing anything. */
2092 if (host->cfg_system == NULL)
2096 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
2099 status = cna_setup_system (host->cfg_system);
2102 assert (host->cfg_system->query != NULL);
2104 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
2105 if (na_results_status (data) != NA_OK)
2107 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed for host %s: %s",
2108 host->name, na_results_reason (data));
2109 na_elem_free (data);
2113 status = cna_handle_system_data (host->name, host->cfg_system, data, host->interval);
2116 host->cfg_system->interval.last_read = now;
2118 na_elem_free (data);
2120 } /* }}} int cna_query_system */
2123 * Configuration handling
2125 /* Sets a given flag if the boolean argument is true and unsets the flag if it
2126 * is false. On error, the flag-field is not changed. */
2127 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
2128 uint32_t *flags, uint32_t flag)
2130 if ((ci == NULL) || (flags == NULL))
2133 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2135 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
2140 if (ci->values[0].value.boolean)
2146 } /* }}} int cna_config_bool_to_flag */
2148 /* Handling of the "Interval" option which is allowed in every block. */
2149 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
2150 cna_interval_t *out_interval)
2155 status = cf_util_get_cdtime (ci, &tmp);
2159 out_interval->interval = tmp;
2160 out_interval->last_read = 0;
2163 } /* }}} int cna_config_get_interval */
2165 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
2166 * <VolumePerf /> block. */
2167 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
2168 const oconfig_item_t *ci)
2173 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2175 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2180 name = ci->values[0].value.string;
2182 if (strcasecmp ("GetIO", ci->key) == 0)
2183 il = cvp->il_octets;
2184 else if (strcasecmp ("GetOps", ci->key) == 0)
2185 il = cvp->il_operations;
2186 else if (strcasecmp ("GetLatency", ci->key) == 0)
2187 il = cvp->il_latency;
2191 ignorelist_add (il, name);
2192 } /* }}} void cna_config_volume_perf_option */
2194 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
2195 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
2196 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
2197 const oconfig_item_t *ci)
2201 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2203 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2208 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
2209 il = cvp->il_octets;
2210 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
2211 il = cvp->il_operations;
2212 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
2213 il = cvp->il_latency;
2217 if (ci->values[0].value.boolean)
2218 ignorelist_set_invert (il, /* invert = */ 0);
2220 ignorelist_set_invert (il, /* invert = */ 1);
2221 } /* }}} void cna_config_volume_perf_default */
2223 /* Corresponds to a <Disks /> block */
2228 * IgnoreSelectedIO false
2232 * IgnoreSelectedOps false
2236 * IgnoreSelectedLatency false
2239 /* Corresponds to a <VolumePerf /> block */
2240 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
2241 const oconfig_item_t *ci)
2243 cfg_volume_perf_t *cfg_volume_perf;
2246 if ((host == NULL) || (ci == NULL))
2249 if (host->cfg_volume_perf == NULL)
2251 cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
2252 if (cfg_volume_perf == NULL)
2254 memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
2256 /* Set default flags */
2257 cfg_volume_perf->query = NULL;
2258 cfg_volume_perf->volumes = NULL;
2260 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
2261 if (cfg_volume_perf->il_octets == NULL)
2263 sfree (cfg_volume_perf);
2267 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
2268 if (cfg_volume_perf->il_operations == NULL)
2270 ignorelist_free (cfg_volume_perf->il_octets);
2271 sfree (cfg_volume_perf);
2275 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
2276 if (cfg_volume_perf->il_latency == NULL)
2278 ignorelist_free (cfg_volume_perf->il_octets);
2279 ignorelist_free (cfg_volume_perf->il_operations);
2280 sfree (cfg_volume_perf);
2284 host->cfg_volume_perf = cfg_volume_perf;
2286 cfg_volume_perf = host->cfg_volume_perf;
2288 for (i = 0; i < ci->children_num; ++i) {
2289 oconfig_item_t *item = ci->children + i;
2291 /* if (!item || !item->key || !*item->key) continue; */
2292 if (strcasecmp(item->key, "Interval") == 0)
2293 cna_config_get_interval (item, &cfg_volume_perf->interval);
2294 else if (!strcasecmp(item->key, "GetIO"))
2295 cna_config_volume_perf_option (cfg_volume_perf, item);
2296 else if (!strcasecmp(item->key, "GetOps"))
2297 cna_config_volume_perf_option (cfg_volume_perf, item);
2298 else if (!strcasecmp(item->key, "GetLatency"))
2299 cna_config_volume_perf_option (cfg_volume_perf, item);
2300 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
2301 cna_config_volume_perf_default (cfg_volume_perf, item);
2302 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
2303 cna_config_volume_perf_default (cfg_volume_perf, item);
2304 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2305 cna_config_volume_perf_default (cfg_volume_perf, item);
2307 WARNING ("netapp plugin: The option %s is not allowed within "
2308 "`VolumePerf' blocks.", item->key);
2312 } /* }}} int cna_config_volume_performance */
2314 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2315 * <VolumeUsage /> block. */
2316 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
2317 const oconfig_item_t *ci)
2322 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2324 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2329 name = ci->values[0].value.string;
2331 if (strcasecmp ("GetCapacity", ci->key) == 0)
2332 il = cvu->il_capacity;
2333 else if (strcasecmp ("GetSnapshot", ci->key) == 0)
2334 il = cvu->il_snapshot;
2338 ignorelist_add (il, name);
2339 } /* }}} void cna_config_volume_usage_option */
2341 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2342 * options within a <VolumeUsage /> block. */
2343 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
2344 const oconfig_item_t *ci)
2348 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2350 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2355 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2356 il = cvu->il_capacity;
2357 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2358 il = cvu->il_snapshot;
2362 if (ci->values[0].value.boolean)
2363 ignorelist_set_invert (il, /* invert = */ 0);
2365 ignorelist_set_invert (il, /* invert = */ 1);
2366 } /* }}} void cna_config_volume_usage_default */
2368 /* Corresponds to a <Disks /> block */
2369 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2370 cfg_disk_t *cfg_disk;
2373 if ((host == NULL) || (ci == NULL))
2376 if (host->cfg_disk == NULL)
2378 cfg_disk = malloc (sizeof (*cfg_disk));
2379 if (cfg_disk == NULL)
2381 memset (cfg_disk, 0, sizeof (*cfg_disk));
2383 /* Set default flags */
2384 cfg_disk->flags = CFG_DISK_ALL;
2385 cfg_disk->query = NULL;
2386 cfg_disk->disks = NULL;
2388 host->cfg_disk = cfg_disk;
2390 cfg_disk = host->cfg_disk;
2392 for (i = 0; i < ci->children_num; ++i) {
2393 oconfig_item_t *item = ci->children + i;
2395 /* if (!item || !item->key || !*item->key) continue; */
2396 if (strcasecmp(item->key, "Interval") == 0)
2397 cna_config_get_interval (item, &cfg_disk->interval);
2398 else if (strcasecmp(item->key, "GetBusy") == 0)
2399 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2402 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2404 NOTICE ("netapp plugin: All disk related values have been disabled. "
2405 "Collection of per-disk data will be disabled entirely.");
2406 free_cfg_disk (host->cfg_disk);
2407 host->cfg_disk = NULL;
2411 } /* }}} int cna_config_disk */
2413 /* Corresponds to a <WAFL /> block */
2414 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2416 cfg_wafl_t *cfg_wafl;
2419 if ((host == NULL) || (ci == NULL))
2422 if (host->cfg_wafl == NULL)
2424 cfg_wafl = malloc (sizeof (*cfg_wafl));
2425 if (cfg_wafl == NULL)
2427 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
2429 /* Set default flags */
2430 cfg_wafl->flags = CFG_WAFL_ALL;
2432 host->cfg_wafl = cfg_wafl;
2434 cfg_wafl = host->cfg_wafl;
2436 for (i = 0; i < ci->children_num; ++i) {
2437 oconfig_item_t *item = ci->children + i;
2439 if (strcasecmp(item->key, "Interval") == 0)
2440 cna_config_get_interval (item, &cfg_wafl->interval);
2441 else if (!strcasecmp(item->key, "GetNameCache"))
2442 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2443 else if (!strcasecmp(item->key, "GetDirCache"))
2444 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2445 else if (!strcasecmp(item->key, "GetBufferCache"))
2446 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2447 else if (!strcasecmp(item->key, "GetInodeCache"))
2448 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2450 WARNING ("netapp plugin: The %s config option is not allowed within "
2451 "`WAFL' blocks.", item->key);
2454 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2456 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2457 "Collection of WAFL data will be disabled entirely.");
2458 free_cfg_wafl (host->cfg_wafl);
2459 host->cfg_wafl = NULL;
2463 } /* }}} int cna_config_wafl */
2467 * GetCapacity "vol0"
2468 * GetCapacity "vol1"
2469 * GetCapacity "vol2"
2470 * GetCapacity "vol3"
2471 * GetCapacity "vol4"
2472 * IgnoreSelectedCapacity false
2474 * GetSnapshot "vol0"
2475 * GetSnapshot "vol3"
2476 * GetSnapshot "vol4"
2477 * GetSnapshot "vol7"
2478 * IgnoreSelectedSnapshot false
2481 /* Corresponds to a <VolumeUsage /> block */
2482 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2483 const oconfig_item_t *ci)
2485 cfg_volume_usage_t *cfg_volume_usage;
2488 if ((host == NULL) || (ci == NULL))
2491 if (host->cfg_volume_usage == NULL)
2493 cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
2494 if (cfg_volume_usage == NULL)
2496 memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
2498 /* Set default flags */
2499 cfg_volume_usage->query = NULL;
2500 cfg_volume_usage->volumes = NULL;
2502 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2503 if (cfg_volume_usage->il_capacity == NULL)
2505 sfree (cfg_volume_usage);
2509 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2510 if (cfg_volume_usage->il_snapshot == NULL)
2512 ignorelist_free (cfg_volume_usage->il_capacity);
2513 sfree (cfg_volume_usage);
2517 host->cfg_volume_usage = cfg_volume_usage;
2519 cfg_volume_usage = host->cfg_volume_usage;
2521 for (i = 0; i < ci->children_num; ++i) {
2522 oconfig_item_t *item = ci->children + i;
2524 /* if (!item || !item->key || !*item->key) continue; */
2525 if (strcasecmp(item->key, "Interval") == 0)
2526 cna_config_get_interval (item, &cfg_volume_usage->interval);
2527 else if (!strcasecmp(item->key, "GetCapacity"))
2528 cna_config_volume_usage_option (cfg_volume_usage, item);
2529 else if (!strcasecmp(item->key, "GetSnapshot"))
2530 cna_config_volume_usage_option (cfg_volume_usage, item);
2531 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2532 cna_config_volume_usage_default (cfg_volume_usage, item);
2533 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2534 cna_config_volume_usage_default (cfg_volume_usage, item);
2536 WARNING ("netapp plugin: The option %s is not allowed within "
2537 "`VolumeUsage' blocks.", item->key);
2541 } /* }}} int cna_config_volume_usage */
2543 /* Corresponds to a <SnapVault /> block */
2544 static int cna_config_snapvault (host_config_t *host, /* {{{ */
2545 const oconfig_item_t *ci)
2547 cfg_snapvault_t *cfg_snapvault;
2550 if ((host == NULL) || (ci == NULL))
2553 if (host->cfg_snapvault == NULL)
2555 cfg_snapvault = malloc (sizeof (*cfg_snapvault));
2556 if (cfg_snapvault == NULL)
2558 memset (cfg_snapvault, 0, sizeof (*cfg_snapvault));
2559 cfg_snapvault->query = NULL;
2561 host->cfg_snapvault = cfg_snapvault;
2564 cfg_snapvault = host->cfg_snapvault;
2566 for (i = 0; i < ci->children_num; ++i) {
2567 oconfig_item_t *item = ci->children + i;
2569 if (strcasecmp (item->key, "Interval") == 0)
2570 cna_config_get_interval (item, &cfg_snapvault->interval);
2572 WARNING ("netapp plugin: The option %s is not allowed within "
2573 "`SnapVault' blocks.", item->key);
2577 } /* }}} int cna_config_snapvault */
2579 /* Corresponds to a <System /> block */
2580 static int cna_config_system (host_config_t *host, /* {{{ */
2583 cfg_system_t *cfg_system;
2586 if ((host == NULL) || (ci == NULL))
2589 if (host->cfg_system == NULL)
2591 cfg_system = malloc (sizeof (*cfg_system));
2592 if (cfg_system == NULL)
2594 memset (cfg_system, 0, sizeof (*cfg_system));
2596 /* Set default flags */
2597 cfg_system->flags = CFG_SYSTEM_ALL;
2598 cfg_system->query = NULL;
2600 host->cfg_system = cfg_system;
2602 cfg_system = host->cfg_system;
2604 for (i = 0; i < ci->children_num; ++i) {
2605 oconfig_item_t *item = ci->children + i;
2607 if (strcasecmp(item->key, "Interval") == 0) {
2608 cna_config_get_interval (item, &cfg_system->interval);
2609 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2610 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2611 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2612 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2613 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2614 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2615 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2616 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2618 WARNING ("netapp plugin: The %s config option is not allowed within "
2619 "`System' blocks.", item->key);
2623 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2625 NOTICE ("netapp plugin: All system related values have been disabled. "
2626 "Collection of system data will be disabled entirely.");
2627 free_cfg_system (host->cfg_system);
2628 host->cfg_system = NULL;
2632 } /* }}} int cna_config_system */
2634 /* Corresponds to a <Host /> block. */
2635 static host_config_t *cna_alloc_host (void) /* {{{ */
2637 host_config_t *host;
2639 host = malloc(sizeof(*host));
2642 memset (host, 0, sizeof (*host));
2645 host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2647 host->username = NULL;
2648 host->password = NULL;
2649 host->vfiler = NULL;
2651 host->cfg_wafl = NULL;
2652 host->cfg_disk = NULL;
2653 host->cfg_volume_perf = NULL;
2654 host->cfg_volume_usage = NULL;
2655 host->cfg_snapvault = NULL;
2656 host->cfg_system = NULL;
2659 } /* }}} host_config_t *cna_alloc_host */
2661 static host_config_t *cna_shallow_clone_host (host_config_t *host) /* {{{ */
2663 host_config_t *clone;
2668 clone = cna_alloc_host ();
2672 if (host->name != NULL) {
2673 clone->name = strdup (host->name);
2674 if (clone->name == NULL) {
2675 free_host_config (clone);
2680 clone->protocol = host->protocol;
2682 if (host->host != NULL) {
2683 clone->host = strdup (host->host);
2684 if (clone->host == NULL) {
2685 free_host_config (clone);
2690 clone->port = host->port;
2692 if (host->username != NULL) {
2693 clone->username = strdup (host->username);
2694 if (clone->username == NULL) {
2695 free_host_config (clone);
2699 if (host->password != NULL) {
2700 clone->password = strdup (host->password);
2701 if (clone->password == NULL) {
2702 free_host_config (clone);
2707 clone->interval = host->interval;
2710 } /* }}} host_config_t *cna_shallow_clone_host */
2712 static int cna_read (user_data_t *ud);
2714 static int cna_register_host (host_config_t *host) /* {{{ */
2717 struct timespec interval;
2721 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s-%s",
2722 host->name, host->vfiler);
2724 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name);
2726 CDTIME_T_TO_TIMESPEC (host->interval, &interval);
2728 memset (&ud, 0, sizeof (ud));
2730 ud.free_func = (void (*) (void *)) free_host_config;
2732 plugin_register_complex_read (/* group = */ NULL, cb_name,
2733 /* callback = */ cna_read,
2734 /* interval = */ (host->interval > 0) ? &interval : NULL,
2735 /* user data = */ &ud);
2738 } /* }}} int cna_register_host */
2740 static int cna_config_host (host_config_t *host, /* {{{ */
2741 const oconfig_item_t *ci)
2743 oconfig_item_t *item;
2744 _Bool is_vfiler = 0;
2748 if (! strcasecmp (ci->key, "VFiler"))
2751 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2752 WARNING ("netapp plugin: \"%s\" needs exactly one string argument. Ignoring host block.", ci->key);
2756 status = cf_util_get_string (ci, &host->name);
2760 for (i = 0; i < ci->children_num; ++i) {
2761 item = ci->children + i;
2765 if (!strcasecmp(item->key, "Address")) {
2766 status = cf_util_get_string (item, &host->host);
2767 } else if (!strcasecmp(item->key, "Port")) {
2770 tmp = cf_util_get_port_number (item);
2773 } else if (!strcasecmp(item->key, "Protocol")) {
2774 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"))) {
2775 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2778 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2779 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2780 } else if (!strcasecmp(item->key, "User")) {
2781 status = cf_util_get_string (item, &host->username);
2782 } else if (!strcasecmp(item->key, "Password")) {
2783 status = cf_util_get_string (item, &host->password);
2784 } else if (!strcasecmp(item->key, "Interval")) {
2785 status = cf_util_get_cdtime (item, &host->interval);
2786 } else if (!strcasecmp(item->key, "WAFL")) {
2787 cna_config_wafl(host, item);
2788 } else if (!strcasecmp(item->key, "Disks")) {
2789 cna_config_disk(host, item);
2790 } else if (!strcasecmp(item->key, "VolumePerf")) {
2791 cna_config_volume_performance(host, item);
2792 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2793 cna_config_volume_usage(host, item);
2794 } else if (!strcasecmp(item->key, "SnapVault")) {
2795 cna_config_snapvault(host, item);
2796 } else if (!strcasecmp(item->key, "System")) {
2797 cna_config_system(host, item);
2798 } else if ((!strcasecmp(item->key, "VFiler")) && (! is_vfiler)) {
2799 host_config_t *vfiler;
2801 vfiler = cna_shallow_clone_host (host);
2803 ERROR ("netapp plugin: Failed to allocate host object for vfiler.");
2807 if (cna_config_host (vfiler, item)) {
2808 free_host_config (vfiler);
2812 cna_register_host (vfiler);
2813 } else if ((!strcasecmp(item->key, "VFilerName")) && is_vfiler) {
2814 status = cf_util_get_string (item, &host->vfiler);
2816 WARNING ("netapp plugin: Ignoring unknown config option \"%s\" in %s block \"%s\".",
2817 item->key, is_vfiler ? "vfiler" : "host", ci->values[0].value.string);
2824 if (host->host == NULL)
2825 host->host = strdup (host->name);
2827 if (is_vfiler && (! host->vfiler))
2828 host->vfiler = strdup (host->name);
2830 if (host->host == NULL)
2833 if (host->port <= 0)
2834 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2836 if ((host->username == NULL) || (host->password == NULL)) {
2837 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2838 "Ignoring host block.", host->name);
2846 } /* }}} host_config_t *cna_config_host */
2849 * Callbacks registered with the daemon
2851 * Pretty standard stuff here.
2853 static int cna_init_host (host_config_t *host) /* {{{ */
2855 /* Request version 1.1 of the ONTAP API */
2856 int major_version = 1, minor_version = 1;
2861 if (host->srv != NULL)
2864 if (host->vfiler != NULL) /* Request version 1.7 of the ONTAP API */
2867 host->srv = na_server_open (host->host, major_version, minor_version);
2868 if (host->srv == NULL) {
2869 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
2873 na_server_set_transport_type(host->srv, host->protocol,
2874 /* transportarg = */ NULL);
2875 na_server_set_port(host->srv, host->port);
2876 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
2877 na_server_adminuser(host->srv, host->username, host->password);
2878 na_server_set_timeout(host->srv, 5 /* seconds */);
2880 if (host->vfiler != NULL) {
2881 if (! na_server_set_vfiler (host->srv, host->vfiler)) {
2882 ERROR ("netapp plugin: Failed to connect to VFiler '%s' on host '%s'.",
2883 host->vfiler, host->host);
2887 INFO ("netapp plugin: Connected to VFiler '%s' on host '%s'.",
2888 host->vfiler, host->host);
2893 } /* }}} int cna_init_host */
2895 static int cna_init (void) /* {{{ */
2899 memset (err, 0, sizeof (err));
2900 if (!na_startup(err, sizeof(err))) {
2901 err[sizeof (err) - 1] = 0;
2902 ERROR("netapp plugin: Error initializing netapp API: %s", err);
2907 } /* }}} cna_init */
2909 static int cna_read_internal (host_config_t *host) { /* {{{ */
2912 status = cna_query_wafl (host);
2916 status = cna_query_disk (host);
2920 status = cna_query_volume_perf (host);
2924 status = cna_query_volume_usage (host);
2928 status = cna_query_snapvault (host);
2932 status = cna_query_system (host);
2937 } /* }}} int cna_read_internal */
2939 static int cna_read (user_data_t *ud) { /* {{{ */
2940 host_config_t *host;
2943 if ((ud == NULL) || (ud->data == NULL))
2948 status = cna_init_host (host);
2952 status = cna_read_internal (host);
2955 if (host->srv != NULL)
2956 na_server_close (host->srv);
2961 } /* }}} int cna_read */
2963 static int cna_config (oconfig_item_t *ci) { /* {{{ */
2965 oconfig_item_t *item;
2967 for (i = 0; i < ci->children_num; ++i) {
2968 item = ci->children + i;
2970 if (strcasecmp(item->key, "Host") == 0)
2972 host_config_t *host;
2974 host = cna_alloc_host ();
2976 ERROR ("netapp plugin: Failed to allocate host object.");
2980 if (cna_config_host (host, item) != 0) {
2981 free_host_config (host);
2985 cna_register_host (host);
2987 else /* if (item->key != "Host") */
2989 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
2993 } /* }}} int cna_config */
2995 static int cna_shutdown (void) /* {{{ */
2997 /* Clean up system resources and stuff. */
3001 } /* }}} int cna_shutdown */
3003 void module_register(void) {
3004 plugin_register_complex_config("netapp", cna_config);
3005 plugin_register_init("netapp", cna_init);
3006 plugin_register_shutdown("netapp", cna_shutdown);
3009 /* vim: set sw=2 ts=2 noet fdm=marker : */