2 * collectd - src/netapp.c
3 * Copyright (C) 2009,2010 Sven Trenkel
4 * Copyright (C) 2012-2013 teamix GmbH
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Sven Trenkel <collectd at semidefinite.de>
26 * Sebastian 'tokkee' Harl <sh@teamix.net>
31 #include "utils_ignorelist.h"
33 #include <netapp_api.h>
34 #include <netapp_errno.h>
36 #define HAS_ALL_FLAGS(has,needs) (((has) & (needs)) == (needs))
38 typedef struct host_config_s host_config_t;
39 typedef void service_handler_t(host_config_t *host, na_elem_t *result, void *data);
46 typedef struct cna_interval_s cna_interval_t;
48 /*! Data types for WAFL statistics {{{
50 * \brief Persistent data for WAFL performance counters. (a.k.a. cache performance)
52 * The cache counters use old counter values to calculate a hit ratio for each
53 * counter. The "cfg_wafl_t" struct therefore contains old counter values along
54 * with flags, which are set if the counter is valid.
56 * The function "cna_handle_wafl_data" will fill a new structure of this kind
57 * with new values, then pass both, new and old data, to "submit_wafl_data".
58 * That function calculates the hit ratios, submits the calculated values and
59 * updates the old counter values for the next iteration.
61 #define CFG_WAFL_NAME_CACHE 0x0001
62 #define CFG_WAFL_DIR_CACHE 0x0002
63 #define CFG_WAFL_BUF_CACHE 0x0004
64 #define CFG_WAFL_INODE_CACHE 0x0008
65 #define CFG_WAFL_ALL 0x000F
66 #define HAVE_WAFL_NAME_CACHE_HIT 0x0100
67 #define HAVE_WAFL_NAME_CACHE_MISS 0x0200
68 #define HAVE_WAFL_NAME_CACHE (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
69 #define HAVE_WAFL_FIND_DIR_HIT 0x0400
70 #define HAVE_WAFL_FIND_DIR_MISS 0x0800
71 #define HAVE_WAFL_FIND_DIR (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
72 #define HAVE_WAFL_BUF_HASH_HIT 0x1000
73 #define HAVE_WAFL_BUF_HASH_MISS 0x2000
74 #define HAVE_WAFL_BUF_HASH (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
75 #define HAVE_WAFL_INODE_CACHE_HIT 0x4000
76 #define HAVE_WAFL_INODE_CACHE_MISS 0x8000
77 #define HAVE_WAFL_INODE_CACHE (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
78 #define HAVE_WAFL_ALL 0xff00
81 cna_interval_t interval;
85 uint64_t name_cache_hit;
86 uint64_t name_cache_miss;
87 uint64_t find_dir_hit;
88 uint64_t find_dir_miss;
89 uint64_t buf_hash_hit;
90 uint64_t buf_hash_miss;
91 uint64_t inode_cache_hit;
92 uint64_t inode_cache_miss;
96 /*! Data types for disk statistics {{{
98 * \brief A disk in the NetApp.
100 * A disk doesn't have any more information than its name at the moment.
101 * The name includes the "disk_" prefix.
103 #define HAVE_DISK_BUSY 0x10
104 #define HAVE_DISK_BASE 0x20
105 #define HAVE_DISK_ALL 0x30
106 typedef struct disk_s {
111 uint64_t base_for_disk_busy;
112 double disk_busy_percent;
116 #define CFG_DISK_BUSIEST 0x01
117 #define CFG_DISK_ALL 0x01
120 cna_interval_t interval;
126 /*! Data types for volume performance statistics {{{
128 * \brief Persistent data for volume performance data.
130 * The code below uses the difference of the operations and latency counters to
131 * calculate an average per-operation latency. For this, old counters need to
132 * be stored in the "data_volume_perf_t" structure. The byte-counters are just
133 * kept for completeness sake. The "flags" member indicates if each counter is
136 * The "cna_handle_volume_perf_data" function will fill a new struct of this
137 * type and pass both, old and new data, to "submit_volume_perf_data". In that
138 * function, the per-operation latency is calculated and dispatched, then the
139 * old counters are updated.
141 #define CFG_VOLUME_PERF_INIT 0x0001
142 #define CFG_VOLUME_PERF_IO 0x0002
143 #define CFG_VOLUME_PERF_OPS 0x0003
144 #define CFG_VOLUME_PERF_LATENCY 0x0008
145 #define CFG_VOLUME_PERF_ALL 0x000F
146 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
147 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
148 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
149 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
150 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
151 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
152 #define HAVE_VOLUME_PERF_ALL 0x03F0
153 struct data_volume_perf_s;
154 typedef struct data_volume_perf_s data_volume_perf_t;
155 struct data_volume_perf_s {
161 uint64_t write_bytes;
164 uint64_t read_latency;
165 uint64_t write_latency;
167 data_volume_perf_t *next;
171 cna_interval_t interval;
174 ignorelist_t *il_octets;
175 ignorelist_t *il_operations;
176 ignorelist_t *il_latency;
178 data_volume_perf_t *volumes;
180 /* }}} data_volume_perf_t */
182 /*! Data types for volume usage statistics {{{
184 * \brief Configuration struct for volume usage data (free / used).
186 #define CFG_VOLUME_USAGE_DF 0x0002
187 #define CFG_VOLUME_USAGE_SNAP 0x0004
188 #define CFG_VOLUME_USAGE_ALL 0x0006
189 #define HAVE_VOLUME_USAGE_NORM_FREE 0x0010
190 #define HAVE_VOLUME_USAGE_NORM_USED 0x0020
191 #define HAVE_VOLUME_USAGE_SNAP_RSVD 0x0040
192 #define HAVE_VOLUME_USAGE_SNAP_USED 0x0080
193 #define HAVE_VOLUME_USAGE_SIS_SAVED 0x0100
194 #define HAVE_VOLUME_USAGE_COMPRESS_SAVED 0x0200
195 #define HAVE_VOLUME_USAGE_DEDUP_SAVED 0x0400
196 #define HAVE_VOLUME_USAGE_ALL 0x07f0
197 #define IS_VOLUME_USAGE_OFFLINE 0x0800
198 struct data_volume_usage_s;
199 typedef struct data_volume_usage_s data_volume_usage_t;
200 struct data_volume_usage_s {
204 na_elem_t *snap_query;
208 uint64_t snap_reserved;
211 uint64_t compress_saved;
212 uint64_t dedup_saved;
214 data_volume_usage_t *next;
218 cna_interval_t interval;
221 ignorelist_t *il_capacity;
222 ignorelist_t *il_snapshot;
224 data_volume_usage_t *volumes;
225 } cfg_volume_usage_t;
226 /* }}} cfg_volume_usage_t */
228 /*! Data types for quota statistics {{{
230 * \brief Persistent data for quota statistics
233 cna_interval_t interval;
236 /* }}} cfg_quota_t */
238 /*! Data types for SnapVault statistics {{{
240 * \brief Persistent data for SnapVault(R) statistics
243 cna_interval_t interval;
246 /* }}} cfg_snapvault_t */
248 /*! Data types for system statistics {{{
250 * \brief Persistent data for system performance counters
252 #define CFG_SYSTEM_CPU 0x01
253 #define CFG_SYSTEM_NET 0x02
254 #define CFG_SYSTEM_OPS 0x04
255 #define CFG_SYSTEM_DISK 0x08
256 #define CFG_SYSTEM_ALL 0x0F
259 cna_interval_t interval;
262 /* }}} cfg_system_t */
264 struct host_config_s {
266 na_server_transport_t protocol;
275 cfg_wafl_t *cfg_wafl;
276 cfg_disk_t *cfg_disk;
277 cfg_volume_perf_t *cfg_volume_perf;
278 cfg_volume_usage_t *cfg_volume_usage;
279 cfg_quota_t *cfg_quota;
280 cfg_snapvault_t *cfg_snapvault;
281 cfg_system_t *cfg_system;
283 struct host_config_s *next;
289 * Used to free the various structures above.
291 static void free_disk (disk_t *disk) /* {{{ */
304 } /* }}} void free_disk */
306 static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
311 if (cw->query != NULL)
312 na_elem_free (cw->query);
315 } /* }}} void free_cfg_wafl */
317 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
319 if (cfg_disk == NULL)
322 if (cfg_disk->query != NULL)
323 na_elem_free (cfg_disk->query);
325 free_disk (cfg_disk->disks);
327 } /* }}} void free_cfg_disk */
329 static void free_cfg_volume_perf (cfg_volume_perf_t *cvp) /* {{{ */
331 data_volume_perf_t *data;
336 /* Free the ignorelists */
337 ignorelist_free (cvp->il_octets);
338 ignorelist_free (cvp->il_operations);
339 ignorelist_free (cvp->il_latency);
341 /* Free the linked list of volumes */
345 data_volume_perf_t *next = data->next;
351 if (cvp->query != NULL)
352 na_elem_free (cvp->query);
355 } /* }}} void free_cfg_volume_perf */
357 static void free_cfg_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
359 data_volume_usage_t *data;
364 /* Free the ignorelists */
365 ignorelist_free (cvu->il_capacity);
366 ignorelist_free (cvu->il_snapshot);
368 /* Free the linked list of volumes */
372 data_volume_usage_t *next = data->next;
374 if (data->snap_query != NULL)
375 na_elem_free(data->snap_query);
380 if (cvu->query != NULL)
381 na_elem_free (cvu->query);
384 } /* }}} void free_cfg_volume_usage */
386 static void free_cfg_quota (cfg_quota_t *q) /* {{{ */
391 if (q->query != NULL)
392 na_elem_free (q->query);
395 } /* }}} void free_cfg_quota */
397 static void free_cfg_snapvault (cfg_snapvault_t *sv) /* {{{ */
402 if (sv->query != NULL)
403 na_elem_free (sv->query);
406 } /* }}} void free_cfg_snapvault */
408 static void free_cfg_system (cfg_system_t *cs) /* {{{ */
413 if (cs->query != NULL)
414 na_elem_free (cs->query);
417 } /* }}} void free_cfg_system */
419 static void free_host_config (host_config_t *hc) /* {{{ */
430 sfree (hc->username);
431 sfree (hc->password);
434 free_cfg_disk (hc->cfg_disk);
435 free_cfg_wafl (hc->cfg_wafl);
436 free_cfg_volume_perf (hc->cfg_volume_perf);
437 free_cfg_volume_usage (hc->cfg_volume_usage);
438 free_cfg_quota (hc->cfg_quota);
439 free_cfg_snapvault (hc->cfg_snapvault);
440 free_cfg_system (hc->cfg_system);
443 na_server_close (hc->srv);
447 free_host_config (next);
448 } /* }}} void free_host_config */
451 * Auxiliary functions
453 * Used to look up volumes and disks or to handle flags.
455 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
459 if ((cd == NULL) || (name == NULL))
462 for (d = cd->disks; d != NULL; d = d->next) {
463 if (strcmp(d->name, name) == 0)
467 d = calloc (1, sizeof (*d));
472 d->name = strdup(name);
473 if (d->name == NULL) {
482 } /* }}} disk_t *get_disk */
484 static data_volume_usage_t *get_volume_usage (cfg_volume_usage_t *cvu, /* {{{ */
487 data_volume_usage_t *last;
488 data_volume_usage_t *new;
490 int ignore_capacity = 0;
491 int ignore_snapshot = 0;
493 if ((cvu == NULL) || (name == NULL))
499 if (strcmp (last->name, name) == 0)
502 if (last->next == NULL)
508 /* Check the ignorelists. If *both* tell us to ignore a volume, return NULL. */
509 ignore_capacity = ignorelist_match (cvu->il_capacity, name);
510 ignore_snapshot = ignorelist_match (cvu->il_snapshot, name);
511 if ((ignore_capacity != 0) && (ignore_snapshot != 0))
514 /* Not found: allocate. */
515 new = calloc (1, sizeof (*new));
520 new->name = strdup (name);
521 if (new->name == NULL)
527 if (ignore_capacity == 0)
528 new->flags |= CFG_VOLUME_USAGE_DF;
529 if (ignore_snapshot == 0) {
530 new->flags |= CFG_VOLUME_USAGE_SNAP;
531 new->snap_query = na_elem_new ("snapshot-list-info");
532 na_child_add_string(new->snap_query, "target-type", "volume");
533 na_child_add_string(new->snap_query, "target-name", name);
535 new->snap_query = NULL;
538 /* Add to end of list. */
545 } /* }}} data_volume_usage_t *get_volume_usage */
547 static data_volume_perf_t *get_volume_perf (cfg_volume_perf_t *cvp, /* {{{ */
550 data_volume_perf_t *last;
551 data_volume_perf_t *new;
553 int ignore_octets = 0;
554 int ignore_operations = 0;
555 int ignore_latency = 0;
557 if ((cvp == NULL) || (name == NULL))
563 if (strcmp (last->name, name) == 0)
566 if (last->next == NULL)
572 /* Check the ignorelists. If *all three* tell us to ignore a volume, return
574 ignore_octets = ignorelist_match (cvp->il_octets, name);
575 ignore_operations = ignorelist_match (cvp->il_operations, name);
576 ignore_latency = ignorelist_match (cvp->il_latency, name);
577 if ((ignore_octets != 0) || (ignore_operations != 0)
578 || (ignore_latency != 0))
581 /* Not found: allocate. */
582 new = calloc (1, sizeof (*new));
587 new->name = strdup (name);
588 if (new->name == NULL)
594 if (ignore_octets == 0)
595 new->flags |= CFG_VOLUME_PERF_IO;
596 if (ignore_operations == 0)
597 new->flags |= CFG_VOLUME_PERF_OPS;
598 if (ignore_latency == 0)
599 new->flags |= CFG_VOLUME_PERF_LATENCY;
601 /* Add to end of list. */
608 } /* }}} data_volume_perf_t *get_volume_perf */
611 * Various submit functions.
613 * They all eventually call "submit_values" which creates a value_list_t and
614 * dispatches it to the daemon.
616 static int submit_values (const char *host, /* {{{ */
617 const char *plugin_inst,
618 const char *type, const char *type_inst,
619 value_t *values, int values_len,
620 cdtime_t timestamp, cdtime_t interval)
622 value_list_t vl = VALUE_LIST_INIT;
625 vl.values_len = values_len;
631 vl.interval = interval;
634 sstrncpy (vl.host, host, sizeof (vl.host));
636 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
637 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
638 if (plugin_inst != NULL)
639 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
640 sstrncpy (vl.type, type, sizeof (vl.type));
641 if (type_inst != NULL)
642 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
644 return (plugin_dispatch_values (&vl));
645 } /* }}} int submit_uint64 */
647 static int submit_two_derive (const char *host, const char *plugin_inst, /* {{{ */
648 const char *type, const char *type_inst, derive_t val0, derive_t val1,
649 cdtime_t timestamp, cdtime_t interval)
653 values[0].derive = val0;
654 values[1].derive = val1;
656 return (submit_values (host, plugin_inst, type, type_inst,
657 values, 2, timestamp, interval));
658 } /* }}} int submit_two_derive */
660 static int submit_derive (const char *host, const char *plugin_inst, /* {{{ */
661 const char *type, const char *type_inst, derive_t counter,
662 cdtime_t timestamp, cdtime_t interval)
668 return (submit_values (host, plugin_inst, type, type_inst,
669 &v, 1, timestamp, interval));
670 } /* }}} int submit_derive */
672 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
673 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
674 cdtime_t timestamp, cdtime_t interval)
678 values[0].gauge = val0;
679 values[1].gauge = val1;
681 return (submit_values (host, plugin_inst, type, type_inst,
682 values, 2, timestamp, interval));
683 } /* }}} int submit_two_gauge */
685 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
686 const char *type, const char *type_inst, double d,
687 cdtime_t timestamp, cdtime_t interval)
691 v.gauge = (gauge_t) d;
693 return (submit_values (host, plugin_inst, type, type_inst,
694 &v, 1, timestamp, interval));
695 } /* }}} int submit_uint64 */
697 /* Calculate hit ratio from old and new counters and submit the resulting
698 * percentage. Used by "submit_wafl_data". */
699 static int submit_cache_ratio (const char *host, /* {{{ */
700 const char *plugin_inst,
701 const char *type_inst,
711 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
715 hits = new_hits - old_hits;
716 misses = new_misses - old_misses;
718 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
723 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
724 &v, 1, timestamp, interval));
725 } /* }}} int submit_cache_ratio */
727 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
728 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
729 cfg_wafl_t *old_data, const cfg_wafl_t *new_data, cdtime_t interval)
731 /* Submit requested counters */
732 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
733 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
734 submit_cache_ratio (hostname, instance, "name_cache_hit",
735 new_data->name_cache_hit, new_data->name_cache_miss,
736 old_data->name_cache_hit, old_data->name_cache_miss,
737 new_data->timestamp, interval);
739 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
740 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
741 submit_cache_ratio (hostname, instance, "find_dir_hit",
742 new_data->find_dir_hit, new_data->find_dir_miss,
743 old_data->find_dir_hit, old_data->find_dir_miss,
744 new_data->timestamp, interval);
746 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
747 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
748 submit_cache_ratio (hostname, instance, "buf_hash_hit",
749 new_data->buf_hash_hit, new_data->buf_hash_miss,
750 old_data->buf_hash_hit, old_data->buf_hash_miss,
751 new_data->timestamp, interval);
753 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
754 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
755 submit_cache_ratio (hostname, instance, "inode_cache_hit",
756 new_data->inode_cache_hit, new_data->inode_cache_miss,
757 old_data->inode_cache_hit, old_data->inode_cache_miss,
758 new_data->timestamp, interval);
760 /* Clear old HAVE_* flags */
761 old_data->flags &= ~HAVE_WAFL_ALL;
763 /* Copy all counters */
764 old_data->timestamp = new_data->timestamp;
765 old_data->name_cache_hit = new_data->name_cache_hit;
766 old_data->name_cache_miss = new_data->name_cache_miss;
767 old_data->find_dir_hit = new_data->find_dir_hit;
768 old_data->find_dir_miss = new_data->find_dir_miss;
769 old_data->buf_hash_hit = new_data->buf_hash_hit;
770 old_data->buf_hash_miss = new_data->buf_hash_miss;
771 old_data->inode_cache_hit = new_data->inode_cache_hit;
772 old_data->inode_cache_miss = new_data->inode_cache_miss;
774 /* Copy HAVE_* flags */
775 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
778 } /* }}} int submit_wafl_data */
780 /* Submits volume performance data to the daemon, taking care to honor and
781 * update flags appropriately. */
782 static int submit_volume_perf_data (const char *hostname, /* {{{ */
783 data_volume_perf_t *old_data,
784 const data_volume_perf_t *new_data, int interval)
786 char plugin_instance[DATA_MAX_NAME_LEN];
788 if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
791 ssnprintf (plugin_instance, sizeof (plugin_instance),
792 "volume-%s", old_data->name);
794 /* Check for and submit disk-octet values */
795 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
796 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
798 submit_two_derive (hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
799 (derive_t) new_data->read_bytes, (derive_t) new_data->write_bytes, new_data->timestamp, interval);
802 /* Check for and submit disk-operations values */
803 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
804 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
806 submit_two_derive (hostname, plugin_instance, "disk_ops", /* type instance = */ NULL,
807 (derive_t) new_data->read_ops, (derive_t) new_data->write_ops, new_data->timestamp, interval);
810 /* Check for, calculate and submit disk-latency values */
811 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
812 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
813 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
814 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
815 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
817 gauge_t latency_per_op_read;
818 gauge_t latency_per_op_write;
820 latency_per_op_read = NAN;
821 latency_per_op_write = NAN;
823 /* Check if a counter wrapped around. */
824 if ((new_data->read_ops > old_data->read_ops)
825 && (new_data->read_latency > old_data->read_latency))
827 uint64_t diff_ops_read;
828 uint64_t diff_latency_read;
830 diff_ops_read = new_data->read_ops - old_data->read_ops;
831 diff_latency_read = new_data->read_latency - old_data->read_latency;
833 if (diff_ops_read > 0)
834 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
837 if ((new_data->write_ops > old_data->write_ops)
838 && (new_data->write_latency > old_data->write_latency))
840 uint64_t diff_ops_write;
841 uint64_t diff_latency_write;
843 diff_ops_write = new_data->write_ops - old_data->write_ops;
844 diff_latency_write = new_data->write_latency - old_data->write_latency;
846 if (diff_ops_write > 0)
847 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
850 submit_two_gauge (hostname, plugin_instance, "disk_latency", /* type instance = */ NULL,
851 latency_per_op_read, latency_per_op_write, new_data->timestamp, interval);
854 /* Clear all HAVE_* flags. */
855 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
857 /* Copy all counters */
858 old_data->timestamp = new_data->timestamp;
859 old_data->read_bytes = new_data->read_bytes;
860 old_data->write_bytes = new_data->write_bytes;
861 old_data->read_ops = new_data->read_ops;
862 old_data->write_ops = new_data->write_ops;
863 old_data->read_latency = new_data->read_latency;
864 old_data->write_latency = new_data->write_latency;
866 /* Copy the HAVE_* flags */
867 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
870 } /* }}} int submit_volume_perf_data */
872 static cdtime_t cna_child_get_cdtime (na_elem_t *data) /* {{{ */
876 t = (time_t) na_child_get_uint64 (data, "timestamp", /* default = */ 0);
878 return (TIME_T_TO_CDTIME_T (t));
879 } /* }}} cdtime_t cna_child_get_cdtime */
885 * These functions are called with appropriate data returned by the libnetapp
886 * interface which is parsed and submitted with the above functions.
888 /* Data corresponding to <WAFL /> */
889 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
890 na_elem_t *data, cdtime_t interval)
892 cfg_wafl_t perf_data;
893 const char *plugin_inst;
895 na_elem_t *instances;
897 na_elem_iter_t counter_iter;
899 memset (&perf_data, 0, sizeof (perf_data));
901 perf_data.timestamp = cna_child_get_cdtime (data);
903 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
904 if (instances == NULL)
906 ERROR ("netapp plugin: cna_handle_wafl_data: "
907 "na_elem_child (\"instances\") failed "
908 "for host %s.", hostname);
912 plugin_inst = na_child_get_string(instances, "name");
913 if (plugin_inst == NULL)
915 ERROR ("netapp plugin: cna_handle_wafl_data: "
916 "na_child_get_string (\"name\") failed "
917 "for host %s.", hostname);
921 /* Iterate over all counters */
922 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
923 for (counter = na_iterator_next (&counter_iter);
925 counter = na_iterator_next (&counter_iter))
930 name = na_child_get_string(counter, "name");
934 value = na_child_get_uint64(counter, "value", UINT64_MAX);
935 if (value == UINT64_MAX)
938 if (!strcmp(name, "name_cache_hit")) {
939 perf_data.name_cache_hit = value;
940 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
941 } else if (!strcmp(name, "name_cache_miss")) {
942 perf_data.name_cache_miss = value;
943 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
944 } else if (!strcmp(name, "find_dir_hit")) {
945 perf_data.find_dir_hit = value;
946 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
947 } else if (!strcmp(name, "find_dir_miss")) {
948 perf_data.find_dir_miss = value;
949 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
950 } else if (!strcmp(name, "buf_hash_hit")) {
951 perf_data.buf_hash_hit = value;
952 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
953 } else if (!strcmp(name, "buf_hash_miss")) {
954 perf_data.buf_hash_miss = value;
955 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
956 } else if (!strcmp(name, "inode_cache_hit")) {
957 perf_data.inode_cache_hit = value;
958 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
959 } else if (!strcmp(name, "inode_cache_miss")) {
960 perf_data.inode_cache_miss = value;
961 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
963 DEBUG("netapp plugin: cna_handle_wafl_data: "
964 "Found unexpected child: %s "
965 "for host %s.", name, hostname);
969 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data, interval));
970 } /* }}} void cna_handle_wafl_data */
972 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
979 if (cw->query != NULL)
982 cw->query = na_elem_new("perf-object-get-instances");
983 if (cw->query == NULL)
985 ERROR ("netapp plugin: na_elem_new failed.");
988 na_child_add_string (cw->query, "objectname", "wafl");
990 e = na_elem_new("counters");
993 na_elem_free (cw->query);
995 ERROR ("netapp plugin: na_elem_new failed.");
998 na_child_add_string(e, "counter", "name_cache_hit");
999 na_child_add_string(e, "counter", "name_cache_miss");
1000 na_child_add_string(e, "counter", "find_dir_hit");
1001 na_child_add_string(e, "counter", "find_dir_miss");
1002 na_child_add_string(e, "counter", "buf_hash_hit");
1003 na_child_add_string(e, "counter", "buf_hash_miss");
1004 na_child_add_string(e, "counter", "inode_cache_hit");
1005 na_child_add_string(e, "counter", "inode_cache_miss");
1007 na_child_add(cw->query, e);
1010 } /* }}} int cna_setup_wafl */
1012 static int cna_query_wafl (host_config_t *host) /* {{{ */
1021 /* If WAFL was not configured, return without doing anything. */
1022 if (host->cfg_wafl == NULL)
1026 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
1029 status = cna_setup_wafl (host->cfg_wafl);
1032 assert (host->cfg_wafl->query != NULL);
1034 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
1035 if (na_results_status (data) != NA_OK)
1037 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed for host %s: %s",
1038 host->name, na_results_reason (data));
1039 na_elem_free (data);
1043 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data,
1044 host->cfg_wafl->interval.interval);
1047 host->cfg_wafl->interval.last_read = now;
1049 na_elem_free (data);
1051 } /* }}} int cna_query_wafl */
1053 /* Data corresponding to <Disks /> */
1054 static int cna_handle_disk_data (const char *hostname, /* {{{ */
1055 cfg_disk_t *cfg_disk, na_elem_t *data, cdtime_t interval)
1058 na_elem_t *instances;
1059 na_elem_t *instance;
1060 na_elem_iter_t instance_iter;
1061 disk_t *worst_disk = NULL;
1063 if ((cfg_disk == NULL) || (data == NULL))
1066 timestamp = cna_child_get_cdtime (data);
1068 instances = na_elem_child (data, "instances");
1069 if (instances == NULL)
1071 ERROR ("netapp plugin: cna_handle_disk_data: "
1072 "na_elem_child (\"instances\") failed "
1073 "for host %s.", hostname);
1077 /* Iterate over all children */
1078 instance_iter = na_child_iterator (instances);
1079 for (instance = na_iterator_next (&instance_iter);
1081 instance = na_iterator_next(&instance_iter))
1086 na_elem_iter_t counter_iterator;
1089 memset (&new_data, 0, sizeof (new_data));
1090 new_data.timestamp = timestamp;
1091 new_data.disk_busy_percent = NAN;
1093 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1094 if (old_data == NULL)
1097 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1098 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1099 for (counter = na_iterator_next(&counter_iterator);
1101 counter = na_iterator_next(&counter_iterator))
1106 name = na_child_get_string(counter, "name");
1110 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1111 if (value == UINT64_MAX)
1114 if (strcmp(name, "disk_busy") == 0)
1116 new_data.disk_busy = value;
1117 new_data.flags |= HAVE_DISK_BUSY;
1119 else if (strcmp(name, "base_for_disk_busy") == 0)
1121 new_data.base_for_disk_busy = value;
1122 new_data.flags |= HAVE_DISK_BASE;
1126 DEBUG ("netapp plugin: cna_handle_disk_data: "
1127 "Counter not handled: %s = %"PRIu64,
1132 /* If all required counters are available and did not just wrap around,
1133 * calculate the busy percentage. Otherwise, the value is initialized to
1134 * NAN at the top of the for-loop. */
1135 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1136 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1137 && (new_data.disk_busy >= old_data->disk_busy)
1138 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1143 busy_diff = new_data.disk_busy - old_data->disk_busy;
1144 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1146 new_data.disk_busy_percent = 100.0
1147 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1150 /* Clear HAVE_* flags */
1151 old_data->flags &= ~HAVE_DISK_ALL;
1154 old_data->timestamp = new_data.timestamp;
1155 old_data->disk_busy = new_data.disk_busy;
1156 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1157 old_data->disk_busy_percent = new_data.disk_busy_percent;
1160 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1162 if ((worst_disk == NULL)
1163 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1164 worst_disk = old_data;
1165 } /* for (all disks) */
1167 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1168 submit_double (hostname, "system", "percent", "disk_busy",
1169 worst_disk->disk_busy_percent, timestamp, interval);
1172 } /* }}} int cna_handle_disk_data */
1174 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1181 if (cd->query != NULL)
1184 cd->query = na_elem_new ("perf-object-get-instances");
1185 if (cd->query == NULL)
1187 ERROR ("netapp plugin: na_elem_new failed.");
1190 na_child_add_string (cd->query, "objectname", "disk");
1192 e = na_elem_new("counters");
1195 na_elem_free (cd->query);
1197 ERROR ("netapp plugin: na_elem_new failed.");
1200 na_child_add_string(e, "counter", "disk_busy");
1201 na_child_add_string(e, "counter", "base_for_disk_busy");
1202 na_child_add(cd->query, e);
1205 } /* }}} int cna_setup_disk */
1207 static int cna_query_disk (host_config_t *host) /* {{{ */
1216 /* If the user did not configure disk statistics, return without doing
1218 if (host->cfg_disk == NULL)
1222 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1225 status = cna_setup_disk (host->cfg_disk);
1228 assert (host->cfg_disk->query != NULL);
1230 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1231 if (na_results_status (data) != NA_OK)
1233 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed for host %s: %s",
1234 host->name, na_results_reason (data));
1235 na_elem_free (data);
1239 status = cna_handle_disk_data (host->name, host->cfg_disk, data,
1240 host->cfg_disk->interval.interval);
1243 host->cfg_disk->interval.last_read = now;
1245 na_elem_free (data);
1247 } /* }}} int cna_query_disk */
1249 /* Data corresponding to <VolumePerf /> */
1250 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1251 cfg_volume_perf_t *cvp, na_elem_t *data, cdtime_t interval)
1254 na_elem_t *elem_instances;
1255 na_elem_iter_t iter_instances;
1256 na_elem_t *elem_instance;
1258 timestamp = cna_child_get_cdtime (data);
1260 elem_instances = na_elem_child(data, "instances");
1261 if (elem_instances == NULL)
1263 ERROR ("netapp plugin: handle_volume_perf_data: "
1264 "na_elem_child (\"instances\") failed "
1265 "for host %s.", hostname);
1269 iter_instances = na_child_iterator (elem_instances);
1270 for (elem_instance = na_iterator_next(&iter_instances);
1271 elem_instance != NULL;
1272 elem_instance = na_iterator_next(&iter_instances))
1276 data_volume_perf_t perf_data;
1277 data_volume_perf_t *v;
1279 na_elem_t *elem_counters;
1280 na_elem_iter_t iter_counters;
1281 na_elem_t *elem_counter;
1283 memset (&perf_data, 0, sizeof (perf_data));
1284 perf_data.timestamp = timestamp;
1286 name = na_child_get_string (elem_instance, "name");
1290 /* get_volume_perf may return NULL if this volume is to be ignored. */
1291 v = get_volume_perf (cvp, name);
1295 elem_counters = na_elem_child (elem_instance, "counters");
1296 if (elem_counters == NULL)
1299 iter_counters = na_child_iterator (elem_counters);
1300 for (elem_counter = na_iterator_next(&iter_counters);
1301 elem_counter != NULL;
1302 elem_counter = na_iterator_next(&iter_counters))
1307 name = na_child_get_string (elem_counter, "name");
1311 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1312 if (value == UINT64_MAX)
1315 if (!strcmp(name, "read_data")) {
1316 perf_data.read_bytes = value;
1317 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1318 } else if (!strcmp(name, "write_data")) {
1319 perf_data.write_bytes = value;
1320 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1321 } else if (!strcmp(name, "read_ops")) {
1322 perf_data.read_ops = value;
1323 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1324 } else if (!strcmp(name, "write_ops")) {
1325 perf_data.write_ops = value;
1326 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1327 } else if (!strcmp(name, "read_latency")) {
1328 perf_data.read_latency = value;
1329 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1330 } else if (!strcmp(name, "write_latency")) {
1331 perf_data.write_latency = value;
1332 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1334 } /* for (elem_counter) */
1336 submit_volume_perf_data (hostname, v, &perf_data, interval);
1337 } /* for (volume) */
1340 } /* }}} int cna_handle_volume_perf_data */
1342 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1349 if (cd->query != NULL)
1352 cd->query = na_elem_new ("perf-object-get-instances");
1353 if (cd->query == NULL)
1355 ERROR ("netapp plugin: na_elem_new failed.");
1358 na_child_add_string (cd->query, "objectname", "volume");
1360 e = na_elem_new("counters");
1363 na_elem_free (cd->query);
1365 ERROR ("netapp plugin: na_elem_new failed.");
1368 na_child_add_string(e, "counter", "read_ops");
1369 na_child_add_string(e, "counter", "write_ops");
1370 na_child_add_string(e, "counter", "read_data");
1371 na_child_add_string(e, "counter", "write_data");
1372 na_child_add_string(e, "counter", "read_latency");
1373 na_child_add_string(e, "counter", "write_latency");
1374 na_child_add(cd->query, e);
1377 } /* }}} int cna_setup_volume_perf */
1379 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1388 /* If the user did not configure volume performance statistics, return
1389 * without doing anything. */
1390 if (host->cfg_volume_perf == NULL)
1394 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1397 status = cna_setup_volume_perf (host->cfg_volume_perf);
1400 assert (host->cfg_volume_perf->query != NULL);
1402 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1403 if (na_results_status (data) != NA_OK)
1405 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed for host %s: %s",
1406 host->name, na_results_reason (data));
1407 na_elem_free (data);
1411 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data,
1412 host->cfg_volume_perf->interval.interval);
1415 host->cfg_volume_perf->interval.last_read = now;
1417 na_elem_free (data);
1419 } /* }}} int cna_query_volume_perf */
1421 /* Data corresponding to <VolumeUsage /> */
1422 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1423 cfg_volume_usage_t *cfg_volume, int interval)
1425 data_volume_usage_t *v;
1427 for (v = cfg_volume->volumes; v != NULL; v = v->next)
1429 char plugin_instance[DATA_MAX_NAME_LEN];
1431 uint64_t norm_used = v->norm_used;
1432 uint64_t norm_free = v->norm_free;
1433 uint64_t sis_saved = v->sis_saved;
1434 uint64_t compress_saved = v->compress_saved;
1435 uint64_t dedup_saved = v->dedup_saved;
1436 uint64_t snap_reserve_used = 0;
1437 uint64_t snap_reserve_free = v->snap_reserved;
1438 uint64_t snap_norm_used = v->snap_used;
1440 ssnprintf (plugin_instance, sizeof (plugin_instance),
1441 "volume-%s", v->name);
1443 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD)) {
1444 if (v->snap_reserved > v->snap_used) {
1445 snap_reserve_free = v->snap_reserved - v->snap_used;
1446 snap_reserve_used = v->snap_used;
1449 snap_reserve_free = 0;
1450 snap_reserve_used = v->snap_reserved;
1451 snap_norm_used = v->snap_used - v->snap_reserved;
1455 /* The space used by snapshots but not reserved for them is included in
1456 * both, norm_used and snap_norm_used. If possible, subtract this here. */
1457 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED))
1459 if (norm_used >= snap_norm_used)
1460 norm_used -= snap_norm_used;
1463 ERROR ("netapp plugin: (norm_used = %"PRIu64") < (snap_norm_used = "
1464 "%"PRIu64") for host %s. Invalidating both.",
1465 norm_used, snap_norm_used, hostname);
1466 v->flags &= ~(HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED);
1470 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1471 submit_double (hostname, /* plugin instance = */ plugin_instance,
1472 "df_complex", "free",
1473 (double) norm_free, /* timestamp = */ 0, interval);
1475 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1476 submit_double (hostname, /* plugin instance = */ plugin_instance,
1477 "df_complex", "sis_saved",
1478 (double) sis_saved, /* timestamp = */ 0, interval);
1480 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_COMPRESS_SAVED))
1481 submit_double (hostname, /* plugin instance = */ plugin_instance,
1482 "df_complex", "compression_saved",
1483 (double) compress_saved, /* timestamp = */ 0, interval);
1485 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_DEDUP_SAVED))
1486 submit_double (hostname, /* plugin instance = */ plugin_instance,
1487 "df_complex", "dedup_saved",
1488 (double) dedup_saved, /* timestamp = */ 0, interval);
1490 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1491 submit_double (hostname, /* plugin instance = */ plugin_instance,
1492 "df_complex", "used",
1493 (double) norm_used, /* timestamp = */ 0, interval);
1495 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1496 submit_double (hostname, /* plugin instance = */ plugin_instance,
1497 "df_complex", "snap_reserved",
1498 (double) snap_reserve_free, /* timestamp = */ 0, interval);
1500 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
1501 submit_double (hostname, /* plugin instance = */ plugin_instance,
1502 "df_complex", "snap_reserve_used",
1503 (double) snap_reserve_used, /* timestamp = */ 0, interval);
1505 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1506 submit_double (hostname, /* plugin instance = */ plugin_instance,
1507 "df_complex", "snap_normal_used",
1508 (double) snap_norm_used, /* timestamp = */ 0, interval);
1510 /* Clear all the HAVE_* flags */
1511 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1512 } /* for (v = cfg_volume->volumes) */
1515 } /* }}} int cna_submit_volume_usage_data */
1517 /* Switch the state of a volume between online and offline and send out a
1519 static int cna_change_volume_status (const char *hostname, /* {{{ */
1520 data_volume_usage_t *v)
1524 memset (&n, 0, sizeof (n));
1526 sstrncpy (n.host, hostname, sizeof (n.host));
1527 sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
1528 sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance));
1530 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
1531 n.severity = NOTIF_OKAY;
1532 ssnprintf (n.message, sizeof (n.message),
1533 "Volume %s is now online.", v->name);
1534 v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
1536 n.severity = NOTIF_WARNING;
1537 ssnprintf (n.message, sizeof (n.message),
1538 "Volume %s is now offline.", v->name);
1539 v->flags |= IS_VOLUME_USAGE_OFFLINE;
1542 return (plugin_dispatch_notification (&n));
1543 } /* }}} int cna_change_volume_status */
1545 static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
1546 data_volume_usage_t *v)
1548 uint64_t snap_used = 0, value;
1549 na_elem_t *data, *elem_snap, *elem_snapshots;
1550 na_elem_iter_t iter_snap;
1552 data = na_server_invoke_elem(host->srv, v->snap_query);
1553 if (na_results_status(data) != NA_OK)
1555 if (na_results_errno(data) == EVOLUMEOFFLINE) {
1556 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
1557 cna_change_volume_status (host->name, v);
1559 ERROR ("netapp plugin: cna_handle_volume_snap_usage: na_server_invoke_elem for "
1560 "volume \"%s\" on host %s failed with error %d: %s", v->name,
1561 host->name, na_results_errno(data), na_results_reason(data));
1567 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0)
1568 cna_change_volume_status (host->name, v);
1570 elem_snapshots = na_elem_child (data, "snapshots");
1571 if (elem_snapshots == NULL)
1573 ERROR ("netapp plugin: cna_handle_volume_snap_usage: "
1574 "na_elem_child (\"snapshots\") failed "
1575 "for host %s.", host->name);
1580 iter_snap = na_child_iterator (elem_snapshots);
1581 for (elem_snap = na_iterator_next (&iter_snap);
1583 elem_snap = na_iterator_next (&iter_snap))
1585 value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
1586 /* "cumulative-total" is the total size of the oldest snapshot plus all
1587 * newer ones in blocks (1KB). We therefore are looking for the highest
1588 * number of all snapshots - that's the size required for the snapshots. */
1589 if (value > snap_used)
1592 na_elem_free (data);
1593 /* snap_used is in 1024 byte blocks */
1594 v->snap_used = snap_used * 1024;
1595 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1596 } /* }}} void cna_handle_volume_snap_usage */
1598 static void cna_handle_volume_sis_data (const host_config_t *host, /* {{{ */
1599 data_volume_usage_t *v, na_elem_t *sis)
1601 const char *sis_state;
1602 uint64_t sis_saved_reported;
1604 if (na_elem_child(sis, "sis-info"))
1605 sis = na_elem_child(sis, "sis-info");
1607 sis_state = na_child_get_string(sis, "state");
1608 if (sis_state == NULL)
1611 /* If SIS is not enabled, there's nothing left to do for this volume. */
1612 if (strcmp ("enabled", sis_state) != 0)
1615 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1616 if (sis_saved_reported == UINT64_MAX)
1619 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1620 if ((sis_saved_reported >> 32) != 0) {
1621 /* In case they ever fix this bug. */
1622 v->sis_saved = sis_saved_reported;
1623 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1624 } else { /* really hacky work-around code. {{{ */
1625 uint64_t sis_saved_percent;
1626 uint64_t sis_saved_guess;
1627 uint64_t overflow_guess;
1628 uint64_t guess1, guess2, guess3;
1630 /* Check if we have v->norm_used. Without it, we cannot calculate
1631 * sis_saved_guess. */
1632 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1635 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1636 if (sis_saved_percent > 100)
1639 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1640 * will hopefully be fixed in later versions. To work around the bug, try
1641 * to figure out how often the 32bit integer wrapped around by using the
1642 * "percentage-saved" value. Because the percentage is in the range
1643 * [0-100], this should work as long as the saved space does not exceed
1645 /* percentage-saved = size-saved / (size-saved + size-used) */
1646 if (sis_saved_percent < 100)
1647 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1649 sis_saved_guess = v->norm_used;
1651 overflow_guess = sis_saved_guess >> 32;
1652 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1653 guess2 = (overflow_guess << 32) + sis_saved_reported;
1654 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1656 if (sis_saved_guess < guess2) {
1657 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1658 v->sis_saved = guess1;
1660 v->sis_saved = guess2;
1662 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1663 v->sis_saved = guess2;
1665 v->sis_saved = guess3;
1667 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1668 } /* }}} end of 32-bit workaround */
1669 } /* }}} void cna_handle_volume_sis_data */
1671 /* ONTAP >= 8.1 uses SIS for managing dedup and compression */
1672 static void cna_handle_volume_sis_saved (const host_config_t *host, /* {{{ */
1673 data_volume_usage_t *v, na_elem_t *sis)
1677 if (na_elem_child(sis, "sis-info"))
1678 sis = na_elem_child(sis, "sis-info");
1680 saved = na_child_get_uint64(sis, "compress-saved", UINT64_MAX);
1681 if (saved != UINT64_MAX) {
1682 v->compress_saved = saved;
1683 v->flags |= HAVE_VOLUME_USAGE_COMPRESS_SAVED;
1686 saved = na_child_get_uint64(sis, "dedup-saved", UINT64_MAX);
1687 if (saved != UINT64_MAX) {
1688 v->dedup_saved = saved;
1689 v->flags |= HAVE_VOLUME_USAGE_DEDUP_SAVED;
1691 } /* }}} void cna_handle_volume_sis_saved */
1693 static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
1694 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1696 na_elem_t *elem_volume;
1697 na_elem_t *elem_volumes;
1698 na_elem_iter_t iter_volume;
1700 elem_volumes = na_elem_child (data, "volumes");
1701 if (elem_volumes == NULL)
1703 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1704 "na_elem_child (\"volumes\") failed "
1705 "for host %s.", host->name);
1709 iter_volume = na_child_iterator (elem_volumes);
1710 for (elem_volume = na_iterator_next (&iter_volume);
1711 elem_volume != NULL;
1712 elem_volume = na_iterator_next (&iter_volume))
1714 const char *volume_name, *state;
1716 data_volume_usage_t *v;
1721 volume_name = na_child_get_string (elem_volume, "name");
1722 if (volume_name == NULL)
1725 state = na_child_get_string (elem_volume, "state");
1726 if ((state == NULL) || (strcmp(state, "online") != 0))
1729 /* get_volume_usage may return NULL if the volume is to be ignored. */
1730 v = get_volume_usage (cfg_volume, volume_name);
1734 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1735 cna_handle_volume_snap_usage(host, v);
1737 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1740 /* 2^4 exa-bytes? This will take a while ;) */
1741 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1742 if (value != UINT64_MAX) {
1743 v->norm_free = value;
1744 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1747 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1748 if (value != UINT64_MAX) {
1749 v->norm_used = value;
1750 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1753 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1754 if (value != UINT64_MAX) {
1755 /* 1 block == 1024 bytes as per API docs */
1756 v->snap_reserved = 1024 * value;
1757 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1760 sis = na_elem_child(elem_volume, "sis");
1762 cna_handle_volume_sis_data (host, v, sis);
1763 cna_handle_volume_sis_saved (host, v, sis);
1765 } /* for (elem_volume) */
1767 return (cna_submit_volume_usage_data (host->name, cfg_volume,
1768 host->cfg_volume_usage->interval.interval));
1769 } /* }}} int cna_handle_volume_usage_data */
1771 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1776 if (cvu->query != NULL)
1779 cvu->query = na_elem_new ("volume-list-info");
1780 if (cvu->query == NULL)
1782 ERROR ("netapp plugin: na_elem_new failed.");
1787 } /* }}} int cna_setup_volume_usage */
1789 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1798 /* If the user did not configure volume_usage statistics, return without
1799 * doing anything. */
1800 if (host->cfg_volume_usage == NULL)
1804 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1807 status = cna_setup_volume_usage (host->cfg_volume_usage);
1810 assert (host->cfg_volume_usage->query != NULL);
1812 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1813 if (na_results_status (data) != NA_OK)
1815 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed for host %s: %s",
1816 host->name, na_results_reason (data));
1817 na_elem_free (data);
1821 status = cna_handle_volume_usage_data (host, host->cfg_volume_usage, data);
1824 host->cfg_volume_usage->interval.last_read = now;
1826 na_elem_free (data);
1828 } /* }}} int cna_query_volume_usage */
1830 /* Data corresponding to <Quota /> */
1831 static int cna_handle_quota_data (const host_config_t *host, /* {{{ */
1832 cfg_quota_t *cfg_quota, na_elem_t *data)
1834 na_elem_t *elem_quota;
1835 na_elem_t *elem_quotas;
1836 na_elem_iter_t iter_quota;
1838 elem_quotas = na_elem_child (data, "quotas");
1839 if (elem_quotas == NULL)
1841 ERROR ("netapp plugin: cna_handle_quota_data: "
1842 "na_elem_child (\"quotas\") failed "
1843 "for host %s.", host->name);
1847 iter_quota = na_child_iterator (elem_quotas);
1848 for (elem_quota = na_iterator_next (&iter_quota);
1850 elem_quota = na_iterator_next (&iter_quota))
1852 const char *quota_type, *volume_name, *tree_name;
1855 char plugin_instance[DATA_MAX_NAME_LEN];
1857 quota_type = na_child_get_string (elem_quota, "quota-type");
1858 if (quota_type == NULL)
1861 /* possible TODO: support other types as well */
1862 if (strcmp (quota_type, "tree") != 0)
1865 tree_name = na_child_get_string (elem_quota, "tree");
1866 if ((tree_name == NULL) || (*tree_name == '\0'))
1869 volume_name = na_child_get_string (elem_quota, "volume");
1870 if (volume_name == NULL)
1873 ssnprintf (plugin_instance, sizeof (plugin_instance),
1874 "quota-%s-%s", volume_name, tree_name);
1876 value = na_child_get_uint64 (elem_quota, "disk-used", UINT64_MAX);
1877 if (value != UINT64_MAX) {
1878 value *= 1024; /* disk-used reports kilobytes */
1879 submit_double (host->name, plugin_instance,
1880 /* type = */ "df_complex", /* type instance = */ NULL,
1881 (double)value, /* timestamp = */ 0,
1882 host->cfg_quota->interval.interval);
1885 value = na_child_get_uint64 (elem_quota, "files-used", UINT64_MAX);
1886 if (value != UINT64_MAX) {
1887 submit_double (host->name, plugin_instance,
1888 /* type = */ "files", /* type instance = */ NULL,
1889 (double)value, /* timestamp = */ 0,
1890 host->cfg_quota->interval.interval);
1892 } /* for (elem_quota) */
1895 } /* }}} int cna_handle_volume_usage_data */
1897 static int cna_setup_quota (cfg_quota_t *cq) /* {{{ */
1902 if (cq->query != NULL)
1905 cq->query = na_elem_new ("quota-report");
1906 if (cq->query == NULL)
1908 ERROR ("netapp plugin: na_elem_new failed.");
1913 } /* }}} int cna_setup_quota */
1915 static int cna_query_quota (host_config_t *host) /* {{{ */
1924 /* If the user did not configure quota statistics, return without
1925 * doing anything. */
1926 if (host->cfg_quota == NULL)
1930 if ((host->cfg_quota->interval.interval + host->cfg_quota->interval.last_read) > now)
1933 status = cna_setup_quota (host->cfg_quota);
1936 assert (host->cfg_quota->query != NULL);
1938 data = na_server_invoke_elem (host->srv, host->cfg_quota->query);
1939 if (na_results_status (data) != NA_OK)
1941 ERROR ("netapp plugin: cna_query_quota: na_server_invoke_elem failed for host %s: %s",
1942 host->name, na_results_reason (data));
1943 na_elem_free (data);
1947 status = cna_handle_quota_data (host, host->cfg_quota, data);
1950 host->cfg_quota->interval.last_read = now;
1952 na_elem_free (data);
1954 } /* }}} int cna_query_quota */
1956 /* Data corresponding to <SnapVault /> */
1957 static int cna_handle_snapvault_data (const char *hostname, /* {{{ */
1958 cfg_snapvault_t *cfg_snapvault, na_elem_t *data, cdtime_t interval)
1961 na_elem_iter_t status_iter;
1963 status = na_elem_child (data, "status-list");
1965 ERROR ("netapp plugin: SnapVault status record missing status-list");
1969 status_iter = na_child_iterator (status);
1970 for (status = na_iterator_next (&status_iter);
1972 status = na_iterator_next (&status_iter))
1974 const char *dest_sys, *dest_path, *src_sys, *src_path;
1975 char plugin_instance[DATA_MAX_NAME_LEN];
1978 dest_sys = na_child_get_string (status, "destination-system");
1979 dest_path = na_child_get_string (status, "destination-path");
1980 src_sys = na_child_get_string (status, "source-system");
1981 src_path = na_child_get_string (status, "source-path");
1983 if ((! dest_sys) || (! dest_path) || (! src_sys) || (! src_path))
1986 value = na_child_get_uint64 (status, "lag-time", UINT64_MAX);
1987 if (value == UINT64_MAX) /* no successful baseline transfer yet */
1990 /* possible TODO: make plugin instance configurable */
1991 ssnprintf (plugin_instance, sizeof (plugin_instance),
1992 "snapvault-%s", dest_path);
1993 submit_double (hostname, plugin_instance, /* type = */ "delay", NULL,
1994 (double)value, /* timestamp = */ 0, interval);
1996 value = na_child_get_uint64 (status, "last-transfer-duration", UINT64_MAX);
1997 if (value != UINT64_MAX)
1998 submit_double (hostname, plugin_instance, /* type = */ "duration", "last_transfer",
1999 (double)value, /* timestamp = */ 0, interval);
2001 value = na_child_get_uint64 (status, "transfer-progress", UINT64_MAX);
2002 if (value == UINT64_MAX)
2003 value = na_child_get_uint64 (status, "last-transfer-size", UINT64_MAX);
2004 if (value != UINT64_MAX) {
2005 value *= 1024; /* this is kilobytes */
2006 submit_derive (hostname, plugin_instance, /* type = */ "if_rx_octets", "transferred",
2007 value, /* timestamp = */ 0, interval);
2009 } /* for (status) */
2012 } /* }}} int cna_handle_snapvault_data */
2014 static int cna_handle_snapvault_iter (host_config_t *host, /* {{{ */
2019 uint32_t records_count;
2022 records_count = na_child_get_uint32 (data, "records", UINT32_MAX);
2023 if (records_count == UINT32_MAX)
2026 tag = na_child_get_string (data, "tag");
2030 DEBUG ("netapp plugin: Iterating %u SV records (tag = %s)", records_count, tag);
2032 for (i = 0; i < records_count; ++i) {
2035 elem = na_server_invoke (host->srv,
2036 "snapvault-secondary-relationship-status-list-iter-next",
2037 "maximum", "1", "tag", tag, NULL);
2039 if (na_results_status (elem) != NA_OK)
2041 ERROR ("netapp plugin: cna_handle_snapvault_iter: "
2042 "na_server_invoke failed for host %s: %s",
2043 host->name, na_results_reason (data));
2044 na_elem_free (elem);
2048 cna_handle_snapvault_data (host->name, host->cfg_snapvault, elem,
2049 host->cfg_snapvault->interval.interval);
2050 na_elem_free (elem);
2053 na_elem_free (na_server_invoke (host->srv,
2054 "snapvault-secondary-relationship-status-list-iter-end",
2057 } /* }}} int cna_handle_snapvault_iter */
2059 static int cna_setup_snapvault (cfg_snapvault_t *sv) /* {{{ */
2064 if (sv->query != NULL)
2067 sv->query = na_elem_new ("snapvault-secondary-relationship-status-list-iter-start");
2068 if (sv->query == NULL)
2070 ERROR ("netapp plugin: na_elem_new failed.");
2075 } /* }}} int cna_setup_snapvault */
2077 static int cna_query_snapvault (host_config_t *host) /* {{{ */
2086 if (host->cfg_snapvault == NULL)
2090 if ((host->cfg_snapvault->interval.interval + host->cfg_snapvault->interval.last_read) > now)
2093 status = cna_setup_snapvault (host->cfg_snapvault);
2096 assert (host->cfg_snapvault->query != NULL);
2098 data = na_server_invoke_elem (host->srv, host->cfg_snapvault->query);
2099 if (na_results_status (data) != NA_OK)
2101 ERROR ("netapp plugin: cna_query_snapvault: na_server_invoke_elem failed for host %s: %s",
2102 host->name, na_results_reason (data));
2103 na_elem_free (data);
2107 status = cna_handle_snapvault_iter (host, data);
2110 host->cfg_snapvault->interval.last_read = now;
2112 na_elem_free (data);
2114 } /* }}} int cna_query_snapvault */
2116 /* Data corresponding to <System /> */
2117 static int cna_handle_system_data (const char *hostname, /* {{{ */
2118 cfg_system_t *cfg_system, na_elem_t *data, int interval)
2120 na_elem_t *instances;
2122 na_elem_iter_t counter_iter;
2124 derive_t disk_read = 0, disk_written = 0;
2125 derive_t net_recv = 0, net_sent = 0;
2126 derive_t cpu_busy = 0, cpu_total = 0;
2127 uint32_t counter_flags = 0;
2129 const char *instance;
2132 timestamp = cna_child_get_cdtime (data);
2134 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
2135 if (instances == NULL)
2137 ERROR ("netapp plugin: cna_handle_system_data: "
2138 "na_elem_child (\"instances\") failed "
2139 "for host %s.", hostname);
2143 instance = na_child_get_string (instances, "name");
2144 if (instance == NULL)
2146 ERROR ("netapp plugin: cna_handle_system_data: "
2147 "na_child_get_string (\"name\") failed "
2148 "for host %s.", hostname);
2152 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
2153 for (counter = na_iterator_next (&counter_iter);
2155 counter = na_iterator_next (&counter_iter))
2160 name = na_child_get_string(counter, "name");
2164 value = na_child_get_uint64(counter, "value", UINT64_MAX);
2165 if (value == UINT64_MAX)
2168 if (!strcmp(name, "disk_data_read")) {
2169 disk_read = (derive_t) (value * 1024);
2170 counter_flags |= 0x01;
2171 } else if (!strcmp(name, "disk_data_written")) {
2172 disk_written = (derive_t) (value * 1024);
2173 counter_flags |= 0x02;
2174 } else if (!strcmp(name, "net_data_recv")) {
2175 net_recv = (derive_t) (value * 1024);
2176 counter_flags |= 0x04;
2177 } else if (!strcmp(name, "net_data_sent")) {
2178 net_sent = (derive_t) (value * 1024);
2179 counter_flags |= 0x08;
2180 } else if (!strcmp(name, "cpu_busy")) {
2181 cpu_busy = (derive_t) value;
2182 counter_flags |= 0x10;
2183 } else if (!strcmp(name, "cpu_elapsed_time")) {
2184 cpu_total = (derive_t) value;
2185 counter_flags |= 0x20;
2186 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
2187 && (value > 0) && (strlen(name) > 4)
2188 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
2189 submit_derive (hostname, instance, "disk_ops_complex", name,
2190 (derive_t) value, timestamp, interval);
2192 } /* for (counter) */
2194 if ((cfg_system->flags & CFG_SYSTEM_DISK)
2195 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
2196 submit_two_derive (hostname, instance, "disk_octets", NULL,
2197 disk_read, disk_written, timestamp, interval);
2199 if ((cfg_system->flags & CFG_SYSTEM_NET)
2200 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
2201 submit_two_derive (hostname, instance, "if_octets", NULL,
2202 net_recv, net_sent, timestamp, interval);
2204 if ((cfg_system->flags & CFG_SYSTEM_CPU)
2205 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
2207 submit_derive (hostname, instance, "cpu", "system",
2208 cpu_busy, timestamp, interval);
2209 submit_derive (hostname, instance, "cpu", "idle",
2210 cpu_total - cpu_busy, timestamp, interval);
2214 } /* }}} int cna_handle_system_data */
2216 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
2221 if (cs->query != NULL)
2224 cs->query = na_elem_new ("perf-object-get-instances");
2225 if (cs->query == NULL)
2227 ERROR ("netapp plugin: na_elem_new failed.");
2230 na_child_add_string (cs->query, "objectname", "system");
2233 } /* }}} int cna_setup_system */
2235 static int cna_query_system (host_config_t *host) /* {{{ */
2244 /* If system statistics were not configured, return without doing anything. */
2245 if (host->cfg_system == NULL)
2249 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
2252 status = cna_setup_system (host->cfg_system);
2255 assert (host->cfg_system->query != NULL);
2257 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
2258 if (na_results_status (data) != NA_OK)
2260 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed for host %s: %s",
2261 host->name, na_results_reason (data));
2262 na_elem_free (data);
2266 status = cna_handle_system_data (host->name, host->cfg_system, data,
2267 host->cfg_system->interval.interval);
2270 host->cfg_system->interval.last_read = now;
2272 na_elem_free (data);
2274 } /* }}} int cna_query_system */
2277 * Configuration handling
2279 /* Sets a given flag if the boolean argument is true and unsets the flag if it
2280 * is false. On error, the flag-field is not changed. */
2281 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
2282 uint32_t *flags, uint32_t flag)
2284 if ((ci == NULL) || (flags == NULL))
2287 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2289 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
2294 if (ci->values[0].value.boolean)
2300 } /* }}} int cna_config_bool_to_flag */
2302 /* Handling of the "Interval" option which is allowed in every block. */
2303 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
2304 cna_interval_t *out_interval)
2309 status = cf_util_get_cdtime (ci, &tmp);
2313 out_interval->interval = tmp;
2314 out_interval->last_read = 0;
2317 } /* }}} int cna_config_get_interval */
2319 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
2320 * <VolumePerf /> block. */
2321 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
2322 const oconfig_item_t *ci)
2327 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2329 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2334 name = ci->values[0].value.string;
2336 if (strcasecmp ("GetIO", ci->key) == 0)
2337 il = cvp->il_octets;
2338 else if (strcasecmp ("GetOps", ci->key) == 0)
2339 il = cvp->il_operations;
2340 else if (strcasecmp ("GetLatency", ci->key) == 0)
2341 il = cvp->il_latency;
2345 ignorelist_add (il, name);
2346 } /* }}} void cna_config_volume_perf_option */
2348 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
2349 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
2350 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
2351 const oconfig_item_t *ci)
2355 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2357 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2362 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
2363 il = cvp->il_octets;
2364 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
2365 il = cvp->il_operations;
2366 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
2367 il = cvp->il_latency;
2371 if (ci->values[0].value.boolean)
2372 ignorelist_set_invert (il, /* invert = */ 0);
2374 ignorelist_set_invert (il, /* invert = */ 1);
2375 } /* }}} void cna_config_volume_perf_default */
2377 /* Corresponds to a <Disks /> block */
2382 * IgnoreSelectedIO false
2386 * IgnoreSelectedOps false
2390 * IgnoreSelectedLatency false
2393 /* Corresponds to a <VolumePerf /> block */
2394 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
2395 const oconfig_item_t *ci)
2397 cfg_volume_perf_t *cfg_volume_perf;
2400 if ((host == NULL) || (ci == NULL))
2403 if (host->cfg_volume_perf == NULL)
2405 cfg_volume_perf = calloc (1, sizeof (*cfg_volume_perf));
2406 if (cfg_volume_perf == NULL)
2409 /* Set default flags */
2410 cfg_volume_perf->query = NULL;
2411 cfg_volume_perf->volumes = NULL;
2413 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
2414 if (cfg_volume_perf->il_octets == NULL)
2416 sfree (cfg_volume_perf);
2420 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
2421 if (cfg_volume_perf->il_operations == NULL)
2423 ignorelist_free (cfg_volume_perf->il_octets);
2424 sfree (cfg_volume_perf);
2428 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
2429 if (cfg_volume_perf->il_latency == NULL)
2431 ignorelist_free (cfg_volume_perf->il_octets);
2432 ignorelist_free (cfg_volume_perf->il_operations);
2433 sfree (cfg_volume_perf);
2437 host->cfg_volume_perf = cfg_volume_perf;
2439 cfg_volume_perf = host->cfg_volume_perf;
2441 for (i = 0; i < ci->children_num; ++i) {
2442 oconfig_item_t *item = ci->children + i;
2444 /* if (!item || !item->key || !*item->key) continue; */
2445 if (strcasecmp(item->key, "Interval") == 0)
2446 cna_config_get_interval (item, &cfg_volume_perf->interval);
2447 else if (!strcasecmp(item->key, "GetIO"))
2448 cna_config_volume_perf_option (cfg_volume_perf, item);
2449 else if (!strcasecmp(item->key, "GetOps"))
2450 cna_config_volume_perf_option (cfg_volume_perf, item);
2451 else if (!strcasecmp(item->key, "GetLatency"))
2452 cna_config_volume_perf_option (cfg_volume_perf, item);
2453 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
2454 cna_config_volume_perf_default (cfg_volume_perf, item);
2455 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
2456 cna_config_volume_perf_default (cfg_volume_perf, item);
2457 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2458 cna_config_volume_perf_default (cfg_volume_perf, item);
2460 WARNING ("netapp plugin: The option %s is not allowed within "
2461 "`VolumePerf' blocks.", item->key);
2465 } /* }}} int cna_config_volume_performance */
2467 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2468 * <VolumeUsage /> block. */
2469 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
2470 const oconfig_item_t *ci)
2475 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2477 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2482 name = ci->values[0].value.string;
2484 if (strcasecmp ("GetCapacity", ci->key) == 0)
2485 il = cvu->il_capacity;
2486 else if (strcasecmp ("GetSnapshot", ci->key) == 0)
2487 il = cvu->il_snapshot;
2491 ignorelist_add (il, name);
2492 } /* }}} void cna_config_volume_usage_option */
2494 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2495 * options within a <VolumeUsage /> block. */
2496 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
2497 const oconfig_item_t *ci)
2501 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2503 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2508 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2509 il = cvu->il_capacity;
2510 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2511 il = cvu->il_snapshot;
2515 if (ci->values[0].value.boolean)
2516 ignorelist_set_invert (il, /* invert = */ 0);
2518 ignorelist_set_invert (il, /* invert = */ 1);
2519 } /* }}} void cna_config_volume_usage_default */
2521 /* Corresponds to a <Quota /> block */
2522 static int cna_config_quota (host_config_t *host, oconfig_item_t *ci) /* {{{ */
2524 cfg_quota_t *cfg_quota;
2527 if ((host == NULL) || (ci == NULL))
2530 if (host->cfg_quota == NULL)
2532 cfg_quota = calloc (1, sizeof (*cfg_quota));
2533 if (cfg_quota == NULL)
2535 cfg_quota->query = NULL;
2537 host->cfg_quota = cfg_quota;
2539 cfg_quota = host->cfg_quota;
2541 for (i = 0; i < ci->children_num; ++i) {
2542 oconfig_item_t *item = ci->children + i;
2544 if (strcasecmp (item->key, "Interval") == 0)
2545 cna_config_get_interval (item, &cfg_quota->interval);
2547 WARNING ("netapp plugin: The option %s is not allowed within "
2548 "`Quota' blocks.", item->key);
2552 } /* }}} int cna_config_quota */
2554 /* Corresponds to a <Disks /> block */
2555 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2556 cfg_disk_t *cfg_disk;
2559 if ((host == NULL) || (ci == NULL))
2562 if (host->cfg_disk == NULL)
2564 cfg_disk = calloc (1, sizeof (*cfg_disk));
2565 if (cfg_disk == NULL)
2568 /* Set default flags */
2569 cfg_disk->flags = CFG_DISK_ALL;
2570 cfg_disk->query = NULL;
2571 cfg_disk->disks = NULL;
2573 host->cfg_disk = cfg_disk;
2575 cfg_disk = host->cfg_disk;
2577 for (i = 0; i < ci->children_num; ++i) {
2578 oconfig_item_t *item = ci->children + i;
2580 /* if (!item || !item->key || !*item->key) continue; */
2581 if (strcasecmp(item->key, "Interval") == 0)
2582 cna_config_get_interval (item, &cfg_disk->interval);
2583 else if (strcasecmp(item->key, "GetBusy") == 0)
2584 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2587 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2589 NOTICE ("netapp plugin: All disk related values have been disabled. "
2590 "Collection of per-disk data will be disabled entirely.");
2591 free_cfg_disk (host->cfg_disk);
2592 host->cfg_disk = NULL;
2596 } /* }}} int cna_config_disk */
2598 /* Corresponds to a <WAFL /> block */
2599 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2601 cfg_wafl_t *cfg_wafl;
2604 if ((host == NULL) || (ci == NULL))
2607 if (host->cfg_wafl == NULL)
2609 cfg_wafl = calloc (1, sizeof (*cfg_wafl));
2610 if (cfg_wafl == NULL)
2613 /* Set default flags */
2614 cfg_wafl->flags = CFG_WAFL_ALL;
2616 host->cfg_wafl = cfg_wafl;
2618 cfg_wafl = host->cfg_wafl;
2620 for (i = 0; i < ci->children_num; ++i) {
2621 oconfig_item_t *item = ci->children + i;
2623 if (strcasecmp(item->key, "Interval") == 0)
2624 cna_config_get_interval (item, &cfg_wafl->interval);
2625 else if (!strcasecmp(item->key, "GetNameCache"))
2626 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2627 else if (!strcasecmp(item->key, "GetDirCache"))
2628 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2629 else if (!strcasecmp(item->key, "GetBufferCache"))
2630 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2631 else if (!strcasecmp(item->key, "GetInodeCache"))
2632 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2634 WARNING ("netapp plugin: The %s config option is not allowed within "
2635 "`WAFL' blocks.", item->key);
2638 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2640 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2641 "Collection of WAFL data will be disabled entirely.");
2642 free_cfg_wafl (host->cfg_wafl);
2643 host->cfg_wafl = NULL;
2647 } /* }}} int cna_config_wafl */
2651 * GetCapacity "vol0"
2652 * GetCapacity "vol1"
2653 * GetCapacity "vol2"
2654 * GetCapacity "vol3"
2655 * GetCapacity "vol4"
2656 * IgnoreSelectedCapacity false
2658 * GetSnapshot "vol0"
2659 * GetSnapshot "vol3"
2660 * GetSnapshot "vol4"
2661 * GetSnapshot "vol7"
2662 * IgnoreSelectedSnapshot false
2665 /* Corresponds to a <VolumeUsage /> block */
2666 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2667 const oconfig_item_t *ci)
2669 cfg_volume_usage_t *cfg_volume_usage;
2672 if ((host == NULL) || (ci == NULL))
2675 if (host->cfg_volume_usage == NULL)
2677 cfg_volume_usage = calloc (1, sizeof (*cfg_volume_usage));
2678 if (cfg_volume_usage == NULL)
2681 /* Set default flags */
2682 cfg_volume_usage->query = NULL;
2683 cfg_volume_usage->volumes = NULL;
2685 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2686 if (cfg_volume_usage->il_capacity == NULL)
2688 sfree (cfg_volume_usage);
2692 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2693 if (cfg_volume_usage->il_snapshot == NULL)
2695 ignorelist_free (cfg_volume_usage->il_capacity);
2696 sfree (cfg_volume_usage);
2700 host->cfg_volume_usage = cfg_volume_usage;
2702 cfg_volume_usage = host->cfg_volume_usage;
2704 for (i = 0; i < ci->children_num; ++i) {
2705 oconfig_item_t *item = ci->children + i;
2707 /* if (!item || !item->key || !*item->key) continue; */
2708 if (strcasecmp(item->key, "Interval") == 0)
2709 cna_config_get_interval (item, &cfg_volume_usage->interval);
2710 else if (!strcasecmp(item->key, "GetCapacity"))
2711 cna_config_volume_usage_option (cfg_volume_usage, item);
2712 else if (!strcasecmp(item->key, "GetSnapshot"))
2713 cna_config_volume_usage_option (cfg_volume_usage, item);
2714 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2715 cna_config_volume_usage_default (cfg_volume_usage, item);
2716 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2717 cna_config_volume_usage_default (cfg_volume_usage, item);
2719 WARNING ("netapp plugin: The option %s is not allowed within "
2720 "`VolumeUsage' blocks.", item->key);
2724 } /* }}} int cna_config_volume_usage */
2726 /* Corresponds to a <SnapVault /> block */
2727 static int cna_config_snapvault (host_config_t *host, /* {{{ */
2728 const oconfig_item_t *ci)
2730 cfg_snapvault_t *cfg_snapvault;
2733 if ((host == NULL) || (ci == NULL))
2736 if (host->cfg_snapvault == NULL)
2738 cfg_snapvault = calloc (1, sizeof (*cfg_snapvault));
2739 if (cfg_snapvault == NULL)
2741 cfg_snapvault->query = NULL;
2743 host->cfg_snapvault = cfg_snapvault;
2746 cfg_snapvault = host->cfg_snapvault;
2748 for (i = 0; i < ci->children_num; ++i) {
2749 oconfig_item_t *item = ci->children + i;
2751 if (strcasecmp (item->key, "Interval") == 0)
2752 cna_config_get_interval (item, &cfg_snapvault->interval);
2754 WARNING ("netapp plugin: The option %s is not allowed within "
2755 "`SnapVault' blocks.", item->key);
2759 } /* }}} int cna_config_snapvault */
2761 /* Corresponds to a <System /> block */
2762 static int cna_config_system (host_config_t *host, /* {{{ */
2765 cfg_system_t *cfg_system;
2768 if ((host == NULL) || (ci == NULL))
2771 if (host->cfg_system == NULL)
2773 cfg_system = calloc (1, sizeof (*cfg_system));
2774 if (cfg_system == NULL)
2777 /* Set default flags */
2778 cfg_system->flags = CFG_SYSTEM_ALL;
2779 cfg_system->query = NULL;
2781 host->cfg_system = cfg_system;
2783 cfg_system = host->cfg_system;
2785 for (i = 0; i < ci->children_num; ++i) {
2786 oconfig_item_t *item = ci->children + i;
2788 if (strcasecmp(item->key, "Interval") == 0) {
2789 cna_config_get_interval (item, &cfg_system->interval);
2790 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2791 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2792 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2793 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2794 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2795 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2796 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2797 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2799 WARNING ("netapp plugin: The %s config option is not allowed within "
2800 "`System' blocks.", item->key);
2804 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2806 NOTICE ("netapp plugin: All system related values have been disabled. "
2807 "Collection of system data will be disabled entirely.");
2808 free_cfg_system (host->cfg_system);
2809 host->cfg_system = NULL;
2813 } /* }}} int cna_config_system */
2815 /* Corresponds to a <Host /> block. */
2816 static host_config_t *cna_alloc_host (void) /* {{{ */
2818 host_config_t *host;
2820 host = calloc (1, sizeof (*host));
2825 host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2827 host->username = NULL;
2828 host->password = NULL;
2829 host->vfiler = NULL;
2831 host->cfg_wafl = NULL;
2832 host->cfg_disk = NULL;
2833 host->cfg_volume_perf = NULL;
2834 host->cfg_volume_usage = NULL;
2835 host->cfg_quota = NULL;
2836 host->cfg_snapvault = NULL;
2837 host->cfg_system = NULL;
2840 } /* }}} host_config_t *cna_alloc_host */
2842 static host_config_t *cna_shallow_clone_host (host_config_t *host) /* {{{ */
2844 host_config_t *clone;
2849 clone = cna_alloc_host ();
2853 if (host->name != NULL) {
2854 clone->name = strdup (host->name);
2855 if (clone->name == NULL) {
2856 free_host_config (clone);
2861 clone->protocol = host->protocol;
2863 if (host->host != NULL) {
2864 clone->host = strdup (host->host);
2865 if (clone->host == NULL) {
2866 free_host_config (clone);
2871 clone->port = host->port;
2873 if (host->username != NULL) {
2874 clone->username = strdup (host->username);
2875 if (clone->username == NULL) {
2876 free_host_config (clone);
2880 if (host->password != NULL) {
2881 clone->password = strdup (host->password);
2882 if (clone->password == NULL) {
2883 free_host_config (clone);
2888 clone->interval = host->interval;
2891 } /* }}} host_config_t *cna_shallow_clone_host */
2893 static int cna_read (user_data_t *ud);
2895 static int cna_register_host (host_config_t *host) /* {{{ */
2901 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s-%s",
2902 host->name, host->vfiler);
2904 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name);
2906 memset (&ud, 0, sizeof (ud));
2908 ud.free_func = (void (*) (void *)) free_host_config;
2910 plugin_register_complex_read (/* group = */ NULL, cb_name,
2911 /* callback = */ cna_read,
2912 /* interval = */ host->interval,
2913 /* user data = */ &ud);
2916 } /* }}} int cna_register_host */
2918 static int cna_config_host (host_config_t *host, /* {{{ */
2919 const oconfig_item_t *ci)
2921 oconfig_item_t *item;
2922 _Bool is_vfiler = 0;
2926 if (! strcasecmp (ci->key, "VFiler"))
2929 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2930 WARNING ("netapp plugin: \"%s\" needs exactly one string argument. Ignoring host block.", ci->key);
2934 status = cf_util_get_string (ci, &host->name);
2938 for (i = 0; i < ci->children_num; ++i) {
2939 item = ci->children + i;
2943 if (!strcasecmp(item->key, "Address")) {
2944 status = cf_util_get_string (item, &host->host);
2945 } else if (!strcasecmp(item->key, "Port")) {
2948 tmp = cf_util_get_port_number (item);
2951 } else if (!strcasecmp(item->key, "Protocol")) {
2952 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"))) {
2953 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2956 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2957 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2958 } else if (!strcasecmp(item->key, "User")) {
2959 status = cf_util_get_string (item, &host->username);
2960 } else if (!strcasecmp(item->key, "Password")) {
2961 status = cf_util_get_string (item, &host->password);
2962 } else if (!strcasecmp(item->key, "Interval")) {
2963 status = cf_util_get_cdtime (item, &host->interval);
2964 } else if (!strcasecmp(item->key, "WAFL")) {
2965 cna_config_wafl(host, item);
2966 } else if (!strcasecmp(item->key, "Disks")) {
2967 cna_config_disk(host, item);
2968 } else if (!strcasecmp(item->key, "VolumePerf")) {
2969 cna_config_volume_performance(host, item);
2970 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2971 cna_config_volume_usage(host, item);
2972 } else if (!strcasecmp(item->key, "Quota")) {
2973 cna_config_quota(host, item);
2974 } else if (!strcasecmp(item->key, "SnapVault")) {
2975 cna_config_snapvault(host, item);
2976 } else if (!strcasecmp(item->key, "System")) {
2977 cna_config_system(host, item);
2978 } else if ((!strcasecmp(item->key, "VFiler")) && (! is_vfiler)) {
2979 host_config_t *vfiler;
2981 vfiler = cna_shallow_clone_host (host);
2983 ERROR ("netapp plugin: Failed to allocate host object for vfiler.");
2987 if (cna_config_host (vfiler, item)) {
2988 free_host_config (vfiler);
2992 cna_register_host (vfiler);
2993 } else if ((!strcasecmp(item->key, "VFilerName")) && is_vfiler) {
2994 status = cf_util_get_string (item, &host->vfiler);
2996 WARNING ("netapp plugin: Ignoring unknown config option \"%s\" in %s block \"%s\".",
2997 item->key, is_vfiler ? "vfiler" : "host", ci->values[0].value.string);
3004 if (host->host == NULL)
3005 host->host = strdup (host->name);
3007 if (is_vfiler && (! host->vfiler))
3008 host->vfiler = strdup (host->name);
3010 if (host->host == NULL)
3013 if (host->port <= 0)
3014 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
3016 if ((host->username == NULL) || (host->password == NULL)) {
3017 WARNING("netapp plugin: Please supply login information for host \"%s\". "
3018 "Ignoring host block.", host->name);
3026 } /* }}} host_config_t *cna_config_host */
3029 * Callbacks registered with the daemon
3031 * Pretty standard stuff here.
3033 static int cna_init_host (host_config_t *host) /* {{{ */
3035 /* Request version 1.1 of the ONTAP API */
3036 int major_version = 1, minor_version = 1;
3041 if (host->srv != NULL)
3044 if (host->vfiler != NULL) /* Request version 1.7 of the ONTAP API */
3047 host->srv = na_server_open (host->host, major_version, minor_version);
3048 if (host->srv == NULL) {
3049 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
3053 na_server_set_transport_type(host->srv, host->protocol,
3054 /* transportarg = */ NULL);
3055 na_server_set_port(host->srv, host->port);
3056 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
3057 na_server_adminuser(host->srv, host->username, host->password);
3058 na_server_set_timeout(host->srv, 5 /* seconds */);
3060 if (host->vfiler != NULL) {
3061 if (! na_server_set_vfiler (host->srv, host->vfiler)) {
3062 ERROR ("netapp plugin: Failed to connect to VFiler '%s' on host '%s'.",
3063 host->vfiler, host->host);
3067 INFO ("netapp plugin: Connected to VFiler '%s' on host '%s'.",
3068 host->vfiler, host->host);
3073 } /* }}} int cna_init_host */
3075 static int cna_init (void) /* {{{ */
3079 memset (err, 0, sizeof (err));
3080 if (!na_startup(err, sizeof(err))) {
3081 err[sizeof (err) - 1] = 0;
3082 ERROR("netapp plugin: Error initializing netapp API: %s", err);
3087 } /* }}} cna_init */
3089 static int cna_read_internal (host_config_t *host) { /* {{{ */
3092 status = cna_query_wafl (host);
3096 status = cna_query_disk (host);
3100 status = cna_query_volume_perf (host);
3104 status = cna_query_volume_usage (host);
3108 status = cna_query_quota (host);
3112 status = cna_query_snapvault (host);
3116 status = cna_query_system (host);
3121 } /* }}} int cna_read_internal */
3123 static int cna_read (user_data_t *ud) { /* {{{ */
3124 host_config_t *host;
3127 if ((ud == NULL) || (ud->data == NULL))
3132 status = cna_init_host (host);
3136 status = cna_read_internal (host);
3139 if (host->srv != NULL)
3140 na_server_close (host->srv);
3145 } /* }}} int cna_read */
3147 static int cna_config (oconfig_item_t *ci) { /* {{{ */
3149 oconfig_item_t *item;
3151 for (i = 0; i < ci->children_num; ++i) {
3152 item = ci->children + i;
3154 if (strcasecmp(item->key, "Host") == 0)
3156 host_config_t *host;
3158 host = cna_alloc_host ();
3160 ERROR ("netapp plugin: Failed to allocate host object.");
3164 if (cna_config_host (host, item) != 0) {
3165 free_host_config (host);
3169 cna_register_host (host);
3171 else /* if (item->key != "Host") */
3173 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
3177 } /* }}} int cna_config */
3179 static int cna_shutdown (void) /* {{{ */
3181 /* Clean up system resources and stuff. */
3185 } /* }}} int cna_shutdown */
3187 void module_register(void) {
3188 plugin_register_complex_config("netapp", cna_config);
3189 plugin_register_init("netapp", cna_init);
3190 plugin_register_shutdown("netapp", cna_shutdown);
3193 /* vim: set sw=2 ts=2 noet fdm=marker : */