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 quota statistics {{{
228 * \brief Persistent data for quota statistics
231 cna_interval_t interval;
234 /* }}} cfg_quota_t */
236 /*! Data types for SnapVault statistics {{{
238 * \brief Persistent data for SnapVault(R) statistics
241 cna_interval_t interval;
244 /* }}} cfg_snapvault_t */
246 /*! Data types for system statistics {{{
248 * \brief Persistent data for system performance counters
250 #define CFG_SYSTEM_CPU 0x01
251 #define CFG_SYSTEM_NET 0x02
252 #define CFG_SYSTEM_OPS 0x04
253 #define CFG_SYSTEM_DISK 0x08
254 #define CFG_SYSTEM_ALL 0x0F
257 cna_interval_t interval;
260 /* }}} cfg_system_t */
262 struct host_config_s {
264 na_server_transport_t protocol;
273 cfg_wafl_t *cfg_wafl;
274 cfg_disk_t *cfg_disk;
275 cfg_volume_perf_t *cfg_volume_perf;
276 cfg_volume_usage_t *cfg_volume_usage;
277 cfg_quota_t *cfg_quota;
278 cfg_snapvault_t *cfg_snapvault;
279 cfg_system_t *cfg_system;
281 struct host_config_s *next;
287 * Used to free the various structures above.
289 static void free_disk (disk_t *disk) /* {{{ */
302 } /* }}} void free_disk */
304 static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
309 if (cw->query != NULL)
310 na_elem_free (cw->query);
313 } /* }}} void free_cfg_wafl */
315 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
317 if (cfg_disk == NULL)
320 if (cfg_disk->query != NULL)
321 na_elem_free (cfg_disk->query);
323 free_disk (cfg_disk->disks);
325 } /* }}} void free_cfg_disk */
327 static void free_cfg_volume_perf (cfg_volume_perf_t *cvp) /* {{{ */
329 data_volume_perf_t *data;
334 /* Free the ignorelists */
335 ignorelist_free (cvp->il_octets);
336 ignorelist_free (cvp->il_operations);
337 ignorelist_free (cvp->il_latency);
339 /* Free the linked list of volumes */
343 data_volume_perf_t *next = data->next;
349 if (cvp->query != NULL)
350 na_elem_free (cvp->query);
353 } /* }}} void free_cfg_volume_perf */
355 static void free_cfg_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
357 data_volume_usage_t *data;
362 /* Free the ignorelists */
363 ignorelist_free (cvu->il_capacity);
364 ignorelist_free (cvu->il_snapshot);
366 /* Free the linked list of volumes */
370 data_volume_usage_t *next = data->next;
372 if (data->snap_query != NULL)
373 na_elem_free(data->snap_query);
378 if (cvu->query != NULL)
379 na_elem_free (cvu->query);
382 } /* }}} void free_cfg_volume_usage */
384 static void free_cfg_quota (cfg_quota_t *q) /* {{{ */
389 if (q->query != NULL)
390 na_elem_free (q->query);
393 } /* }}} void free_cfg_quota */
395 static void free_cfg_snapvault (cfg_snapvault_t *sv) /* {{{ */
400 if (sv->query != NULL)
401 na_elem_free (sv->query);
404 } /* }}} void free_cfg_snapvault */
406 static void free_cfg_system (cfg_system_t *cs) /* {{{ */
411 if (cs->query != NULL)
412 na_elem_free (cs->query);
415 } /* }}} void free_cfg_system */
417 static void free_host_config (host_config_t *hc) /* {{{ */
428 sfree (hc->username);
429 sfree (hc->password);
432 free_cfg_disk (hc->cfg_disk);
433 free_cfg_wafl (hc->cfg_wafl);
434 free_cfg_volume_perf (hc->cfg_volume_perf);
435 free_cfg_volume_usage (hc->cfg_volume_usage);
436 free_cfg_quota (hc->cfg_quota);
437 free_cfg_snapvault (hc->cfg_snapvault);
438 free_cfg_system (hc->cfg_system);
441 na_server_close (hc->srv);
445 free_host_config (next);
446 } /* }}} void free_host_config */
449 * Auxiliary functions
451 * Used to look up volumes and disks or to handle flags.
453 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
457 if ((cd == NULL) || (name == NULL))
460 for (d = cd->disks; d != NULL; d = d->next) {
461 if (strcmp(d->name, name) == 0)
465 d = malloc(sizeof(*d));
468 memset (d, 0, sizeof (*d));
471 d->name = strdup(name);
472 if (d->name == NULL) {
481 } /* }}} disk_t *get_disk */
483 static data_volume_usage_t *get_volume_usage (cfg_volume_usage_t *cvu, /* {{{ */
486 data_volume_usage_t *last;
487 data_volume_usage_t *new;
489 int ignore_capacity = 0;
490 int ignore_snapshot = 0;
492 if ((cvu == NULL) || (name == NULL))
498 if (strcmp (last->name, name) == 0)
501 if (last->next == NULL)
507 /* Check the ignorelists. If *both* tell us to ignore a volume, return NULL. */
508 ignore_capacity = ignorelist_match (cvu->il_capacity, name);
509 ignore_snapshot = ignorelist_match (cvu->il_snapshot, name);
510 if ((ignore_capacity != 0) && (ignore_snapshot != 0))
513 /* Not found: allocate. */
514 new = malloc (sizeof (*new));
517 memset (new, 0, 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 = malloc (sizeof (*new));
585 memset (new, 0, sizeof (*new));
588 new->name = strdup (name);
589 if (new->name == NULL)
595 if (ignore_octets == 0)
596 new->flags |= CFG_VOLUME_PERF_IO;
597 if (ignore_operations == 0)
598 new->flags |= CFG_VOLUME_PERF_OPS;
599 if (ignore_latency == 0)
600 new->flags |= CFG_VOLUME_PERF_LATENCY;
602 /* Add to end of list. */
609 } /* }}} data_volume_perf_t *get_volume_perf */
612 * Various submit functions.
614 * They all eventually call "submit_values" which creates a value_list_t and
615 * dispatches it to the daemon.
617 static int submit_values (const char *host, /* {{{ */
618 const char *plugin_inst,
619 const char *type, const char *type_inst,
620 value_t *values, int values_len,
621 cdtime_t timestamp, cdtime_t interval)
623 value_list_t vl = VALUE_LIST_INIT;
626 vl.values_len = values_len;
632 vl.interval = interval;
635 sstrncpy (vl.host, host, sizeof (vl.host));
637 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
638 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
639 if (plugin_inst != NULL)
640 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
641 sstrncpy (vl.type, type, sizeof (vl.type));
642 if (type_inst != NULL)
643 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
645 return (plugin_dispatch_values (&vl));
646 } /* }}} int submit_uint64 */
648 static int submit_two_derive (const char *host, const char *plugin_inst, /* {{{ */
649 const char *type, const char *type_inst, derive_t val0, derive_t val1,
650 cdtime_t timestamp, cdtime_t interval)
654 values[0].derive = val0;
655 values[1].derive = val1;
657 return (submit_values (host, plugin_inst, type, type_inst,
658 values, 2, timestamp, interval));
659 } /* }}} int submit_two_derive */
661 static int submit_derive (const char *host, const char *plugin_inst, /* {{{ */
662 const char *type, const char *type_inst, derive_t counter,
663 cdtime_t timestamp, cdtime_t interval)
669 return (submit_values (host, plugin_inst, type, type_inst,
670 &v, 1, timestamp, interval));
671 } /* }}} int submit_derive */
673 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
674 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
675 cdtime_t timestamp, cdtime_t interval)
679 values[0].gauge = val0;
680 values[1].gauge = val1;
682 return (submit_values (host, plugin_inst, type, type_inst,
683 values, 2, timestamp, interval));
684 } /* }}} int submit_two_gauge */
686 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
687 const char *type, const char *type_inst, double d,
688 cdtime_t timestamp, cdtime_t interval)
692 v.gauge = (gauge_t) d;
694 return (submit_values (host, plugin_inst, type, type_inst,
695 &v, 1, timestamp, interval));
696 } /* }}} int submit_uint64 */
698 /* Calculate hit ratio from old and new counters and submit the resulting
699 * percentage. Used by "submit_wafl_data". */
700 static int submit_cache_ratio (const char *host, /* {{{ */
701 const char *plugin_inst,
702 const char *type_inst,
712 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
716 hits = new_hits - old_hits;
717 misses = new_misses - old_misses;
719 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
724 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
725 &v, 1, timestamp, interval));
726 } /* }}} int submit_cache_ratio */
728 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
729 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
730 cfg_wafl_t *old_data, const cfg_wafl_t *new_data, int interval)
732 /* Submit requested counters */
733 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
734 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
735 submit_cache_ratio (hostname, instance, "name_cache_hit",
736 new_data->name_cache_hit, new_data->name_cache_miss,
737 old_data->name_cache_hit, old_data->name_cache_miss,
738 new_data->timestamp, interval);
740 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
741 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
742 submit_cache_ratio (hostname, instance, "find_dir_hit",
743 new_data->find_dir_hit, new_data->find_dir_miss,
744 old_data->find_dir_hit, old_data->find_dir_miss,
745 new_data->timestamp, interval);
747 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
748 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
749 submit_cache_ratio (hostname, instance, "buf_hash_hit",
750 new_data->buf_hash_hit, new_data->buf_hash_miss,
751 old_data->buf_hash_hit, old_data->buf_hash_miss,
752 new_data->timestamp, interval);
754 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
755 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
756 submit_cache_ratio (hostname, instance, "inode_cache_hit",
757 new_data->inode_cache_hit, new_data->inode_cache_miss,
758 old_data->inode_cache_hit, old_data->inode_cache_miss,
759 new_data->timestamp, interval);
761 /* Clear old HAVE_* flags */
762 old_data->flags &= ~HAVE_WAFL_ALL;
764 /* Copy all counters */
765 old_data->timestamp = new_data->timestamp;
766 old_data->name_cache_hit = new_data->name_cache_hit;
767 old_data->name_cache_miss = new_data->name_cache_miss;
768 old_data->find_dir_hit = new_data->find_dir_hit;
769 old_data->find_dir_miss = new_data->find_dir_miss;
770 old_data->buf_hash_hit = new_data->buf_hash_hit;
771 old_data->buf_hash_miss = new_data->buf_hash_miss;
772 old_data->inode_cache_hit = new_data->inode_cache_hit;
773 old_data->inode_cache_miss = new_data->inode_cache_miss;
775 /* Copy HAVE_* flags */
776 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
779 } /* }}} int submit_wafl_data */
781 /* Submits volume performance data to the daemon, taking care to honor and
782 * update flags appropriately. */
783 static int submit_volume_perf_data (const char *hostname, /* {{{ */
784 data_volume_perf_t *old_data,
785 const data_volume_perf_t *new_data, int interval)
787 char plugin_instance[DATA_MAX_NAME_LEN];
789 if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
792 ssnprintf (plugin_instance, sizeof (plugin_instance),
793 "volume-%s", old_data->name);
795 /* Check for and submit disk-octet values */
796 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
797 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
799 submit_two_derive (hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
800 (derive_t) new_data->read_bytes, (derive_t) new_data->write_bytes, new_data->timestamp, interval);
803 /* Check for and submit disk-operations values */
804 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
805 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
807 submit_two_derive (hostname, plugin_instance, "disk_ops", /* type instance = */ NULL,
808 (derive_t) new_data->read_ops, (derive_t) new_data->write_ops, new_data->timestamp, interval);
811 /* Check for, calculate and submit disk-latency values */
812 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
813 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
814 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
815 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
816 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
818 gauge_t latency_per_op_read;
819 gauge_t latency_per_op_write;
821 latency_per_op_read = NAN;
822 latency_per_op_write = NAN;
824 /* Check if a counter wrapped around. */
825 if ((new_data->read_ops > old_data->read_ops)
826 && (new_data->read_latency > old_data->read_latency))
828 uint64_t diff_ops_read;
829 uint64_t diff_latency_read;
831 diff_ops_read = new_data->read_ops - old_data->read_ops;
832 diff_latency_read = new_data->read_latency - old_data->read_latency;
834 if (diff_ops_read > 0)
835 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
838 if ((new_data->write_ops > old_data->write_ops)
839 && (new_data->write_latency > old_data->write_latency))
841 uint64_t diff_ops_write;
842 uint64_t diff_latency_write;
844 diff_ops_write = new_data->write_ops - old_data->write_ops;
845 diff_latency_write = new_data->write_latency - old_data->write_latency;
847 if (diff_ops_write > 0)
848 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
851 submit_two_gauge (hostname, plugin_instance, "disk_latency", /* type instance = */ NULL,
852 latency_per_op_read, latency_per_op_write, new_data->timestamp, interval);
855 /* Clear all HAVE_* flags. */
856 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
858 /* Copy all counters */
859 old_data->timestamp = new_data->timestamp;
860 old_data->read_bytes = new_data->read_bytes;
861 old_data->write_bytes = new_data->write_bytes;
862 old_data->read_ops = new_data->read_ops;
863 old_data->write_ops = new_data->write_ops;
864 old_data->read_latency = new_data->read_latency;
865 old_data->write_latency = new_data->write_latency;
867 /* Copy the HAVE_* flags */
868 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
871 } /* }}} int submit_volume_perf_data */
873 static cdtime_t cna_child_get_cdtime (na_elem_t *data) /* {{{ */
877 t = (time_t) na_child_get_uint64 (data, "timestamp", /* default = */ 0);
879 return (TIME_T_TO_CDTIME_T (t));
880 } /* }}} cdtime_t cna_child_get_cdtime */
886 * These functions are called with appropriate data returned by the libnetapp
887 * interface which is parsed and submitted with the above functions.
889 /* Data corresponding to <WAFL /> */
890 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
891 na_elem_t *data, int interval)
893 cfg_wafl_t perf_data;
894 const char *plugin_inst;
896 na_elem_t *instances;
898 na_elem_iter_t counter_iter;
900 memset (&perf_data, 0, sizeof (perf_data));
902 perf_data.timestamp = cna_child_get_cdtime (data);
904 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
905 if (instances == NULL)
907 ERROR ("netapp plugin: cna_handle_wafl_data: "
908 "na_elem_child (\"instances\") failed "
909 "for host %s.", hostname);
913 plugin_inst = na_child_get_string(instances, "name");
914 if (plugin_inst == NULL)
916 ERROR ("netapp plugin: cna_handle_wafl_data: "
917 "na_child_get_string (\"name\") failed "
918 "for host %s.", hostname);
922 /* Iterate over all counters */
923 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
924 for (counter = na_iterator_next (&counter_iter);
926 counter = na_iterator_next (&counter_iter))
931 name = na_child_get_string(counter, "name");
935 value = na_child_get_uint64(counter, "value", UINT64_MAX);
936 if (value == UINT64_MAX)
939 if (!strcmp(name, "name_cache_hit")) {
940 perf_data.name_cache_hit = value;
941 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
942 } else if (!strcmp(name, "name_cache_miss")) {
943 perf_data.name_cache_miss = value;
944 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
945 } else if (!strcmp(name, "find_dir_hit")) {
946 perf_data.find_dir_hit = value;
947 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
948 } else if (!strcmp(name, "find_dir_miss")) {
949 perf_data.find_dir_miss = value;
950 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
951 } else if (!strcmp(name, "buf_hash_hit")) {
952 perf_data.buf_hash_hit = value;
953 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
954 } else if (!strcmp(name, "buf_hash_miss")) {
955 perf_data.buf_hash_miss = value;
956 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
957 } else if (!strcmp(name, "inode_cache_hit")) {
958 perf_data.inode_cache_hit = value;
959 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
960 } else if (!strcmp(name, "inode_cache_miss")) {
961 perf_data.inode_cache_miss = value;
962 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
964 DEBUG("netapp plugin: cna_handle_wafl_data: "
965 "Found unexpected child: %s "
966 "for host %s.", name, hostname);
970 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data, interval));
971 } /* }}} void cna_handle_wafl_data */
973 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
980 if (cw->query != NULL)
983 cw->query = na_elem_new("perf-object-get-instances");
984 if (cw->query == NULL)
986 ERROR ("netapp plugin: na_elem_new failed.");
989 na_child_add_string (cw->query, "objectname", "wafl");
991 e = na_elem_new("counters");
994 na_elem_free (cw->query);
996 ERROR ("netapp plugin: na_elem_new failed.");
999 na_child_add_string(e, "counter", "name_cache_hit");
1000 na_child_add_string(e, "counter", "name_cache_miss");
1001 na_child_add_string(e, "counter", "find_dir_hit");
1002 na_child_add_string(e, "counter", "find_dir_miss");
1003 na_child_add_string(e, "counter", "buf_hash_hit");
1004 na_child_add_string(e, "counter", "buf_hash_miss");
1005 na_child_add_string(e, "counter", "inode_cache_hit");
1006 na_child_add_string(e, "counter", "inode_cache_miss");
1008 na_child_add(cw->query, e);
1011 } /* }}} int cna_setup_wafl */
1013 static int cna_query_wafl (host_config_t *host) /* {{{ */
1022 /* If WAFL was not configured, return without doing anything. */
1023 if (host->cfg_wafl == NULL)
1027 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
1030 status = cna_setup_wafl (host->cfg_wafl);
1033 assert (host->cfg_wafl->query != NULL);
1035 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
1036 if (na_results_status (data) != NA_OK)
1038 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed for host %s: %s",
1039 host->name, na_results_reason (data));
1040 na_elem_free (data);
1044 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data, host->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, host->interval);
1242 host->cfg_disk->interval.last_read = now;
1244 na_elem_free (data);
1246 } /* }}} int cna_query_disk */
1248 /* Data corresponding to <VolumePerf /> */
1249 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1250 cfg_volume_perf_t *cvp, na_elem_t *data, cdtime_t interval)
1253 na_elem_t *elem_instances;
1254 na_elem_iter_t iter_instances;
1255 na_elem_t *elem_instance;
1257 timestamp = cna_child_get_cdtime (data);
1259 elem_instances = na_elem_child(data, "instances");
1260 if (elem_instances == NULL)
1262 ERROR ("netapp plugin: handle_volume_perf_data: "
1263 "na_elem_child (\"instances\") failed "
1264 "for host %s.", hostname);
1268 iter_instances = na_child_iterator (elem_instances);
1269 for (elem_instance = na_iterator_next(&iter_instances);
1270 elem_instance != NULL;
1271 elem_instance = na_iterator_next(&iter_instances))
1275 data_volume_perf_t perf_data;
1276 data_volume_perf_t *v;
1278 na_elem_t *elem_counters;
1279 na_elem_iter_t iter_counters;
1280 na_elem_t *elem_counter;
1282 memset (&perf_data, 0, sizeof (perf_data));
1283 perf_data.timestamp = timestamp;
1285 name = na_child_get_string (elem_instance, "name");
1289 /* get_volume_perf may return NULL if this volume is to be ignored. */
1290 v = get_volume_perf (cvp, name);
1294 elem_counters = na_elem_child (elem_instance, "counters");
1295 if (elem_counters == NULL)
1298 iter_counters = na_child_iterator (elem_counters);
1299 for (elem_counter = na_iterator_next(&iter_counters);
1300 elem_counter != NULL;
1301 elem_counter = na_iterator_next(&iter_counters))
1306 name = na_child_get_string (elem_counter, "name");
1310 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1311 if (value == UINT64_MAX)
1314 if (!strcmp(name, "read_data")) {
1315 perf_data.read_bytes = value;
1316 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1317 } else if (!strcmp(name, "write_data")) {
1318 perf_data.write_bytes = value;
1319 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1320 } else if (!strcmp(name, "read_ops")) {
1321 perf_data.read_ops = value;
1322 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1323 } else if (!strcmp(name, "write_ops")) {
1324 perf_data.write_ops = value;
1325 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1326 } else if (!strcmp(name, "read_latency")) {
1327 perf_data.read_latency = value;
1328 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1329 } else if (!strcmp(name, "write_latency")) {
1330 perf_data.write_latency = value;
1331 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1333 } /* for (elem_counter) */
1335 submit_volume_perf_data (hostname, v, &perf_data, interval);
1336 } /* for (volume) */
1339 } /* }}} int cna_handle_volume_perf_data */
1341 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1348 if (cd->query != NULL)
1351 cd->query = na_elem_new ("perf-object-get-instances");
1352 if (cd->query == NULL)
1354 ERROR ("netapp plugin: na_elem_new failed.");
1357 na_child_add_string (cd->query, "objectname", "volume");
1359 e = na_elem_new("counters");
1362 na_elem_free (cd->query);
1364 ERROR ("netapp plugin: na_elem_new failed.");
1367 na_child_add_string(e, "counter", "read_ops");
1368 na_child_add_string(e, "counter", "write_ops");
1369 na_child_add_string(e, "counter", "read_data");
1370 na_child_add_string(e, "counter", "write_data");
1371 na_child_add_string(e, "counter", "read_latency");
1372 na_child_add_string(e, "counter", "write_latency");
1373 na_child_add(cd->query, e);
1376 } /* }}} int cna_setup_volume_perf */
1378 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1387 /* If the user did not configure volume performance statistics, return
1388 * without doing anything. */
1389 if (host->cfg_volume_perf == NULL)
1393 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1396 status = cna_setup_volume_perf (host->cfg_volume_perf);
1399 assert (host->cfg_volume_perf->query != NULL);
1401 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1402 if (na_results_status (data) != NA_OK)
1404 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed for host %s: %s",
1405 host->name, na_results_reason (data));
1406 na_elem_free (data);
1410 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data, host->interval);
1413 host->cfg_volume_perf->interval.last_read = now;
1415 na_elem_free (data);
1417 } /* }}} int cna_query_volume_perf */
1419 /* Data corresponding to <VolumeUsage /> */
1420 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1421 cfg_volume_usage_t *cfg_volume, int interval)
1423 data_volume_usage_t *v;
1425 for (v = cfg_volume->volumes; v != NULL; v = v->next)
1427 char plugin_instance[DATA_MAX_NAME_LEN];
1429 uint64_t norm_used = v->norm_used;
1430 uint64_t norm_free = v->norm_free;
1431 uint64_t sis_saved = v->sis_saved;
1432 uint64_t compress_saved = v->compress_saved;
1433 uint64_t dedup_saved = v->dedup_saved;
1434 uint64_t snap_reserve_used = 0;
1435 uint64_t snap_reserve_free = v->snap_reserved;
1436 uint64_t snap_norm_used = v->snap_used;
1438 ssnprintf (plugin_instance, sizeof (plugin_instance),
1439 "volume-%s", v->name);
1441 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD)) {
1442 if (v->snap_reserved > v->snap_used) {
1443 snap_reserve_free = v->snap_reserved - v->snap_used;
1444 snap_reserve_used = v->snap_used;
1447 snap_reserve_free = 0;
1448 snap_reserve_used = v->snap_reserved;
1449 snap_norm_used = v->snap_used - v->snap_reserved;
1453 /* The space used by snapshots but not reserved for them is included in
1454 * both, norm_used and snap_norm_used. If possible, subtract this here. */
1455 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED))
1457 if (norm_used >= snap_norm_used)
1458 norm_used -= snap_norm_used;
1461 ERROR ("netapp plugin: (norm_used = %"PRIu64") < (snap_norm_used = "
1462 "%"PRIu64") for host %s. Invalidating both.",
1463 norm_used, snap_norm_used, hostname);
1464 v->flags &= ~(HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED);
1468 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1469 submit_double (hostname, /* plugin instance = */ plugin_instance,
1470 "df_complex", "free",
1471 (double) norm_free, /* timestamp = */ 0, interval);
1473 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1474 submit_double (hostname, /* plugin instance = */ plugin_instance,
1475 "df_complex", "sis_saved",
1476 (double) sis_saved, /* timestamp = */ 0, interval);
1478 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_COMPRESS_SAVED))
1479 submit_double (hostname, /* plugin instance = */ plugin_instance,
1480 "df_complex", "compression_saved",
1481 (double) compress_saved, /* timestamp = */ 0, interval);
1483 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_DEDUP_SAVED))
1484 submit_double (hostname, /* plugin instance = */ plugin_instance,
1485 "df_complex", "dedup_saved",
1486 (double) dedup_saved, /* timestamp = */ 0, interval);
1488 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1489 submit_double (hostname, /* plugin instance = */ plugin_instance,
1490 "df_complex", "used",
1491 (double) norm_used, /* timestamp = */ 0, interval);
1493 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1494 submit_double (hostname, /* plugin instance = */ plugin_instance,
1495 "df_complex", "snap_reserved",
1496 (double) snap_reserve_free, /* timestamp = */ 0, interval);
1498 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
1499 submit_double (hostname, /* plugin instance = */ plugin_instance,
1500 "df_complex", "snap_reserve_used",
1501 (double) snap_reserve_used, /* timestamp = */ 0, interval);
1503 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1504 submit_double (hostname, /* plugin instance = */ plugin_instance,
1505 "df_complex", "snap_normal_used",
1506 (double) snap_norm_used, /* timestamp = */ 0, interval);
1508 /* Clear all the HAVE_* flags */
1509 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1510 } /* for (v = cfg_volume->volumes) */
1513 } /* }}} int cna_submit_volume_usage_data */
1515 /* Switch the state of a volume between online and offline and send out a
1517 static int cna_change_volume_status (const char *hostname, /* {{{ */
1518 data_volume_usage_t *v)
1522 memset (&n, 0, sizeof (&n));
1524 sstrncpy (n.host, hostname, sizeof (n.host));
1525 sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
1526 sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance));
1528 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
1529 n.severity = NOTIF_OKAY;
1530 ssnprintf (n.message, sizeof (n.message),
1531 "Volume %s is now online.", v->name);
1532 v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
1534 n.severity = NOTIF_WARNING;
1535 ssnprintf (n.message, sizeof (n.message),
1536 "Volume %s is now offline.", v->name);
1537 v->flags |= IS_VOLUME_USAGE_OFFLINE;
1540 return (plugin_dispatch_notification (&n));
1541 } /* }}} int cna_change_volume_status */
1543 static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
1544 data_volume_usage_t *v)
1546 uint64_t snap_used = 0, value;
1547 na_elem_t *data, *elem_snap, *elem_snapshots;
1548 na_elem_iter_t iter_snap;
1550 data = na_server_invoke_elem(host->srv, v->snap_query);
1551 if (na_results_status(data) != NA_OK)
1553 if (na_results_errno(data) == EVOLUMEOFFLINE) {
1554 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
1555 cna_change_volume_status (host->name, v);
1557 ERROR ("netapp plugin: cna_handle_volume_snap_usage: na_server_invoke_elem for "
1558 "volume \"%s\" on host %s failed with error %d: %s", v->name,
1559 host->name, na_results_errno(data), na_results_reason(data));
1565 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0)
1566 cna_change_volume_status (host->name, v);
1568 elem_snapshots = na_elem_child (data, "snapshots");
1569 if (elem_snapshots == NULL)
1571 ERROR ("netapp plugin: cna_handle_volume_snap_usage: "
1572 "na_elem_child (\"snapshots\") failed "
1573 "for host %s.", host->name);
1578 iter_snap = na_child_iterator (elem_snapshots);
1579 for (elem_snap = na_iterator_next (&iter_snap);
1581 elem_snap = na_iterator_next (&iter_snap))
1583 value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
1584 /* "cumulative-total" is the total size of the oldest snapshot plus all
1585 * newer ones in blocks (1KB). We therefore are looking for the highest
1586 * number of all snapshots - that's the size required for the snapshots. */
1587 if (value > snap_used)
1590 na_elem_free (data);
1591 /* snap_used is in 1024 byte blocks */
1592 v->snap_used = snap_used * 1024;
1593 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1594 } /* }}} void cna_handle_volume_snap_usage */
1596 static void cna_handle_volume_sis_data (const host_config_t *host, /* {{{ */
1597 data_volume_usage_t *v, na_elem_t *sis)
1599 const char *sis_state;
1600 uint64_t sis_saved_reported;
1602 if (na_elem_child(sis, "sis-info"))
1603 sis = na_elem_child(sis, "sis-info");
1605 sis_state = na_child_get_string(sis, "state");
1606 if (sis_state == NULL)
1609 /* If SIS is not enabled, there's nothing left to do for this volume. */
1610 if (strcmp ("enabled", sis_state) != 0)
1613 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1614 if (sis_saved_reported == UINT64_MAX)
1617 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1618 if ((sis_saved_reported >> 32) != 0) {
1619 /* In case they ever fix this bug. */
1620 v->sis_saved = sis_saved_reported;
1621 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1622 } else { /* really hacky work-around code. {{{ */
1623 uint64_t sis_saved_percent;
1624 uint64_t sis_saved_guess;
1625 uint64_t overflow_guess;
1626 uint64_t guess1, guess2, guess3;
1628 /* Check if we have v->norm_used. Without it, we cannot calculate
1629 * sis_saved_guess. */
1630 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1633 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1634 if (sis_saved_percent > 100)
1637 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1638 * will hopefully be fixed in later versions. To work around the bug, try
1639 * to figure out how often the 32bit integer wrapped around by using the
1640 * "percentage-saved" value. Because the percentage is in the range
1641 * [0-100], this should work as long as the saved space does not exceed
1643 /* percentage-saved = size-saved / (size-saved + size-used) */
1644 if (sis_saved_percent < 100)
1645 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1647 sis_saved_guess = v->norm_used;
1649 overflow_guess = sis_saved_guess >> 32;
1650 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1651 guess2 = (overflow_guess << 32) + sis_saved_reported;
1652 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1654 if (sis_saved_guess < guess2) {
1655 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1656 v->sis_saved = guess1;
1658 v->sis_saved = guess2;
1660 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1661 v->sis_saved = guess2;
1663 v->sis_saved = guess3;
1665 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1666 } /* }}} end of 32-bit workaround */
1667 } /* }}} void cna_handle_volume_sis_data */
1669 /* ONTAP >= 8.1 uses SIS for managing dedup and compression */
1670 static void cna_handle_volume_sis_saved (const host_config_t *host, /* {{{ */
1671 data_volume_usage_t *v, na_elem_t *sis)
1675 if (na_elem_child(sis, "sis-info"))
1676 sis = na_elem_child(sis, "sis-info");
1678 saved = na_child_get_uint64(sis, "compress-saved", UINT64_MAX);
1679 if (saved != UINT64_MAX) {
1680 v->compress_saved = saved;
1681 v->flags |= HAVE_VOLUME_USAGE_COMPRESS_SAVED;
1684 saved = na_child_get_uint64(sis, "dedup-saved", UINT64_MAX);
1685 if (saved != UINT64_MAX) {
1686 v->dedup_saved = saved;
1687 v->flags |= HAVE_VOLUME_USAGE_DEDUP_SAVED;
1689 } /* }}} void cna_handle_volume_sis_saved */
1691 static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
1692 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1694 na_elem_t *elem_volume;
1695 na_elem_t *elem_volumes;
1696 na_elem_iter_t iter_volume;
1698 elem_volumes = na_elem_child (data, "volumes");
1699 if (elem_volumes == NULL)
1701 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1702 "na_elem_child (\"volumes\") failed "
1703 "for host %s.", host->name);
1707 iter_volume = na_child_iterator (elem_volumes);
1708 for (elem_volume = na_iterator_next (&iter_volume);
1709 elem_volume != NULL;
1710 elem_volume = na_iterator_next (&iter_volume))
1712 const char *volume_name, *state;
1714 data_volume_usage_t *v;
1719 volume_name = na_child_get_string (elem_volume, "name");
1720 if (volume_name == NULL)
1723 state = na_child_get_string (elem_volume, "state");
1724 if ((state == NULL) || (strcmp(state, "online") != 0))
1727 /* get_volume_usage may return NULL if the volume is to be ignored. */
1728 v = get_volume_usage (cfg_volume, volume_name);
1732 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1733 cna_handle_volume_snap_usage(host, v);
1735 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1738 /* 2^4 exa-bytes? This will take a while ;) */
1739 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1740 if (value != UINT64_MAX) {
1741 v->norm_free = value;
1742 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1745 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1746 if (value != UINT64_MAX) {
1747 v->norm_used = value;
1748 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1751 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1752 if (value != UINT64_MAX) {
1753 /* 1 block == 1024 bytes as per API docs */
1754 v->snap_reserved = 1024 * value;
1755 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1758 sis = na_elem_child(elem_volume, "sis");
1760 cna_handle_volume_sis_data (host, v, sis);
1761 cna_handle_volume_sis_saved (host, v, sis);
1763 } /* for (elem_volume) */
1765 return (cna_submit_volume_usage_data (host->name, cfg_volume, host->interval));
1766 } /* }}} int cna_handle_volume_usage_data */
1768 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1773 if (cvu->query != NULL)
1776 cvu->query = na_elem_new ("volume-list-info");
1777 if (cvu->query == NULL)
1779 ERROR ("netapp plugin: na_elem_new failed.");
1784 } /* }}} int cna_setup_volume_usage */
1786 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1795 /* If the user did not configure volume_usage statistics, return without
1796 * doing anything. */
1797 if (host->cfg_volume_usage == NULL)
1801 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1804 status = cna_setup_volume_usage (host->cfg_volume_usage);
1807 assert (host->cfg_volume_usage->query != NULL);
1809 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1810 if (na_results_status (data) != NA_OK)
1812 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed for host %s: %s",
1813 host->name, na_results_reason (data));
1814 na_elem_free (data);
1818 status = cna_handle_volume_usage_data (host, host->cfg_volume_usage, data);
1821 host->cfg_volume_usage->interval.last_read = now;
1823 na_elem_free (data);
1825 } /* }}} int cna_query_volume_usage */
1827 /* Data corresponding to <Quota /> */
1828 static int cna_handle_quota_data (const host_config_t *host, /* {{{ */
1829 cfg_quota_t *cfg_quota, na_elem_t *data)
1831 na_elem_t *elem_quota;
1832 na_elem_t *elem_quotas;
1833 na_elem_iter_t iter_quota;
1835 elem_quotas = na_elem_child (data, "quotas");
1836 if (elem_quotas == NULL)
1838 ERROR ("netapp plugin: cna_handle_quota_data: "
1839 "na_elem_child (\"quotas\") failed "
1840 "for host %s.", host->name);
1844 iter_quota = na_child_iterator (elem_quotas);
1845 for (elem_quota = na_iterator_next (&iter_quota);
1847 elem_quota = na_iterator_next (&iter_quota))
1849 const char *quota_type, *volume_name, *tree_name;
1852 char plugin_instance[DATA_MAX_NAME_LEN];
1854 quota_type = na_child_get_string (elem_quota, "quota-type");
1855 if (quota_type == NULL)
1858 /* possible TODO: support other types as well */
1859 if (strcmp (quota_type, "tree") != 0)
1862 tree_name = na_child_get_string (elem_quota, "tree");
1863 if ((tree_name == NULL) || (*tree_name == '\0'))
1866 volume_name = na_child_get_string (elem_quota, "volume");
1867 if (volume_name == NULL)
1870 ssnprintf (plugin_instance, sizeof (plugin_instance),
1871 "quota-%s-%s", volume_name, tree_name);
1873 value = na_child_get_uint64 (elem_quota, "disk-used", UINT64_MAX);
1874 if (value != UINT64_MAX) {
1875 value *= 1024; /* disk-used reports kilobytes */
1876 submit_double (host->name, plugin_instance,
1877 /* type = */ "df_complex", /* type instance = */ NULL,
1878 (double)value, /* timestamp = */ 0, host->interval);
1881 value = na_child_get_uint64 (elem_quota, "files-used", UINT64_MAX);
1882 if (value != UINT64_MAX) {
1883 submit_double (host->name, plugin_instance,
1884 /* type = */ "files", /* type instance = */ NULL,
1885 (double)value, /* timestamp = */ 0, host->interval);
1887 } /* for (elem_quota) */
1890 } /* }}} int cna_handle_volume_usage_data */
1892 static int cna_setup_quota (cfg_quota_t *cq) /* {{{ */
1897 if (cq->query != NULL)
1900 cq->query = na_elem_new ("quota-report");
1901 if (cq->query == NULL)
1903 ERROR ("netapp plugin: na_elem_new failed.");
1908 } /* }}} int cna_setup_quota */
1910 static int cna_query_quota (host_config_t *host) /* {{{ */
1919 /* If the user did not configure quota statistics, return without
1920 * doing anything. */
1921 if (host->cfg_quota == NULL)
1925 if ((host->cfg_quota->interval.interval + host->cfg_quota->interval.last_read) > now)
1928 status = cna_setup_quota (host->cfg_quota);
1931 assert (host->cfg_quota->query != NULL);
1933 data = na_server_invoke_elem (host->srv, host->cfg_quota->query);
1934 if (na_results_status (data) != NA_OK)
1936 ERROR ("netapp plugin: cna_query_quota: na_server_invoke_elem failed for host %s: %s",
1937 host->name, na_results_reason (data));
1938 na_elem_free (data);
1942 status = cna_handle_quota_data (host, host->cfg_quota, data);
1945 host->cfg_quota->interval.last_read = now;
1947 na_elem_free (data);
1949 } /* }}} int cna_query_quota */
1951 /* Data corresponding to <SnapVault /> */
1952 static int cna_handle_snapvault_data (const char *hostname, /* {{{ */
1953 cfg_snapvault_t *cfg_snapvault, na_elem_t *data, cdtime_t interval)
1956 na_elem_iter_t status_iter;
1958 status = na_elem_child (data, "status-list");
1960 ERROR ("netapp plugin: SnapVault status record missing status-list");
1964 status_iter = na_child_iterator (status);
1965 for (status = na_iterator_next (&status_iter);
1967 status = na_iterator_next (&status_iter))
1969 const char *dest_sys, *dest_path, *src_sys, *src_path;
1970 char plugin_instance[DATA_MAX_NAME_LEN];
1973 dest_sys = na_child_get_string (status, "destination-system");
1974 dest_path = na_child_get_string (status, "destination-path");
1975 src_sys = na_child_get_string (status, "source-system");
1976 src_path = na_child_get_string (status, "source-path");
1978 if ((! dest_sys) || (! dest_path) || (! src_sys) || (! src_path))
1981 value = na_child_get_uint64 (status, "lag-time", UINT64_MAX);
1982 if (value == UINT64_MAX) /* no successful baseline transfer yet */
1985 /* possible TODO: make plugin instance configurable */
1986 ssnprintf (plugin_instance, sizeof (plugin_instance),
1987 "snapvault-%s", dest_path);
1988 submit_double (hostname, plugin_instance, /* type = */ "delay", NULL,
1989 (double)value, /* timestamp = */ 0, interval);
1991 value = na_child_get_uint64 (status, "last-transfer-duration", UINT64_MAX);
1992 if (value != UINT64_MAX)
1993 submit_double (hostname, plugin_instance, /* type = */ "duration", "last_transfer",
1994 (double)value, /* timestamp = */ 0, interval);
1996 value = na_child_get_uint64 (status, "transfer-progress", UINT64_MAX);
1997 if (value == UINT64_MAX)
1998 value = na_child_get_uint64 (status, "last-transfer-size", UINT64_MAX);
1999 if (value != UINT64_MAX) {
2000 value *= 1024; /* this is kilobytes */
2001 submit_derive (hostname, plugin_instance, /* type = */ "if_rx_octets", "transferred",
2002 value, /* timestamp = */ 0, interval);
2004 } /* for (status) */
2007 } /* }}} int cna_handle_snapvault_data */
2009 static int cna_handle_snapvault_iter (host_config_t *host, /* {{{ */
2014 uint32_t records_count;
2017 records_count = na_child_get_uint32 (data, "records", UINT32_MAX);
2018 if (records_count == UINT32_MAX)
2021 tag = na_child_get_string (data, "tag");
2025 DEBUG ("netapp plugin: Iterating %u SV records (tag = %s)", records_count, tag);
2027 for (i = 0; i < records_count; ++i) {
2030 elem = na_server_invoke (host->srv,
2031 "snapvault-secondary-relationship-status-list-iter-next",
2032 "maximum", "1", "tag", tag, NULL);
2034 if (na_results_status (elem) != NA_OK)
2036 ERROR ("netapp plugin: cna_handle_snapvault_iter: "
2037 "na_server_invoke failed for host %s: %s",
2038 host->name, na_results_reason (data));
2039 na_elem_free (elem);
2043 cna_handle_snapvault_data (host->name, host->cfg_snapvault, elem, host->interval);
2044 na_elem_free (elem);
2047 na_elem_free (na_server_invoke (host->srv,
2048 "snapvault-secondary-relationship-status-list-iter-end",
2051 } /* }}} int cna_handle_snapvault_iter */
2053 static int cna_setup_snapvault (cfg_snapvault_t *sv) /* {{{ */
2058 if (sv->query != NULL)
2061 sv->query = na_elem_new ("snapvault-secondary-relationship-status-list-iter-start");
2062 if (sv->query == NULL)
2064 ERROR ("netapp plugin: na_elem_new failed.");
2069 } /* }}} int cna_setup_snapvault */
2071 static int cna_query_snapvault (host_config_t *host) /* {{{ */
2080 if (host->cfg_snapvault == NULL)
2084 if ((host->cfg_snapvault->interval.interval + host->cfg_snapvault->interval.last_read) > now)
2087 status = cna_setup_snapvault (host->cfg_snapvault);
2090 assert (host->cfg_snapvault->query != NULL);
2092 data = na_server_invoke_elem (host->srv, host->cfg_snapvault->query);
2093 if (na_results_status (data) != NA_OK)
2095 ERROR ("netapp plugin: cna_query_snapvault: na_server_invoke_elem failed for host %s: %s",
2096 host->name, na_results_reason (data));
2097 na_elem_free (data);
2101 status = cna_handle_snapvault_iter (host, data);
2104 host->cfg_snapvault->interval.last_read = now;
2106 na_elem_free (data);
2108 } /* }}} int cna_query_snapvault */
2110 /* Data corresponding to <System /> */
2111 static int cna_handle_system_data (const char *hostname, /* {{{ */
2112 cfg_system_t *cfg_system, na_elem_t *data, int interval)
2114 na_elem_t *instances;
2116 na_elem_iter_t counter_iter;
2118 derive_t disk_read = 0, disk_written = 0;
2119 derive_t net_recv = 0, net_sent = 0;
2120 derive_t cpu_busy = 0, cpu_total = 0;
2121 uint32_t counter_flags = 0;
2123 const char *instance;
2126 timestamp = cna_child_get_cdtime (data);
2128 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
2129 if (instances == NULL)
2131 ERROR ("netapp plugin: cna_handle_system_data: "
2132 "na_elem_child (\"instances\") failed "
2133 "for host %s.", hostname);
2137 instance = na_child_get_string (instances, "name");
2138 if (instance == NULL)
2140 ERROR ("netapp plugin: cna_handle_system_data: "
2141 "na_child_get_string (\"name\") failed "
2142 "for host %s.", hostname);
2146 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
2147 for (counter = na_iterator_next (&counter_iter);
2149 counter = na_iterator_next (&counter_iter))
2154 name = na_child_get_string(counter, "name");
2158 value = na_child_get_uint64(counter, "value", UINT64_MAX);
2159 if (value == UINT64_MAX)
2162 if (!strcmp(name, "disk_data_read")) {
2163 disk_read = (derive_t) (value * 1024);
2164 counter_flags |= 0x01;
2165 } else if (!strcmp(name, "disk_data_written")) {
2166 disk_written = (derive_t) (value * 1024);
2167 counter_flags |= 0x02;
2168 } else if (!strcmp(name, "net_data_recv")) {
2169 net_recv = (derive_t) (value * 1024);
2170 counter_flags |= 0x04;
2171 } else if (!strcmp(name, "net_data_sent")) {
2172 net_sent = (derive_t) (value * 1024);
2173 counter_flags |= 0x08;
2174 } else if (!strcmp(name, "cpu_busy")) {
2175 cpu_busy = (derive_t) value;
2176 counter_flags |= 0x10;
2177 } else if (!strcmp(name, "cpu_elapsed_time")) {
2178 cpu_total = (derive_t) value;
2179 counter_flags |= 0x20;
2180 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
2181 && (value > 0) && (strlen(name) > 4)
2182 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
2183 submit_derive (hostname, instance, "disk_ops_complex", name,
2184 (derive_t) value, timestamp, interval);
2186 } /* for (counter) */
2188 if ((cfg_system->flags & CFG_SYSTEM_DISK)
2189 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
2190 submit_two_derive (hostname, instance, "disk_octets", NULL,
2191 disk_read, disk_written, timestamp, interval);
2193 if ((cfg_system->flags & CFG_SYSTEM_NET)
2194 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
2195 submit_two_derive (hostname, instance, "if_octets", NULL,
2196 net_recv, net_sent, timestamp, interval);
2198 if ((cfg_system->flags & CFG_SYSTEM_CPU)
2199 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
2201 submit_derive (hostname, instance, "cpu", "system",
2202 cpu_busy, timestamp, interval);
2203 submit_derive (hostname, instance, "cpu", "idle",
2204 cpu_total - cpu_busy, timestamp, interval);
2208 } /* }}} int cna_handle_system_data */
2210 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
2215 if (cs->query != NULL)
2218 cs->query = na_elem_new ("perf-object-get-instances");
2219 if (cs->query == NULL)
2221 ERROR ("netapp plugin: na_elem_new failed.");
2224 na_child_add_string (cs->query, "objectname", "system");
2227 } /* }}} int cna_setup_system */
2229 static int cna_query_system (host_config_t *host) /* {{{ */
2238 /* If system statistics were not configured, return without doing anything. */
2239 if (host->cfg_system == NULL)
2243 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
2246 status = cna_setup_system (host->cfg_system);
2249 assert (host->cfg_system->query != NULL);
2251 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
2252 if (na_results_status (data) != NA_OK)
2254 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed for host %s: %s",
2255 host->name, na_results_reason (data));
2256 na_elem_free (data);
2260 status = cna_handle_system_data (host->name, host->cfg_system, data, host->interval);
2263 host->cfg_system->interval.last_read = now;
2265 na_elem_free (data);
2267 } /* }}} int cna_query_system */
2270 * Configuration handling
2272 /* Sets a given flag if the boolean argument is true and unsets the flag if it
2273 * is false. On error, the flag-field is not changed. */
2274 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
2275 uint32_t *flags, uint32_t flag)
2277 if ((ci == NULL) || (flags == NULL))
2280 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2282 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
2287 if (ci->values[0].value.boolean)
2293 } /* }}} int cna_config_bool_to_flag */
2295 /* Handling of the "Interval" option which is allowed in every block. */
2296 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
2297 cna_interval_t *out_interval)
2302 status = cf_util_get_cdtime (ci, &tmp);
2306 out_interval->interval = tmp;
2307 out_interval->last_read = 0;
2310 } /* }}} int cna_config_get_interval */
2312 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
2313 * <VolumePerf /> block. */
2314 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
2315 const oconfig_item_t *ci)
2320 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2322 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2327 name = ci->values[0].value.string;
2329 if (strcasecmp ("GetIO", ci->key) == 0)
2330 il = cvp->il_octets;
2331 else if (strcasecmp ("GetOps", ci->key) == 0)
2332 il = cvp->il_operations;
2333 else if (strcasecmp ("GetLatency", ci->key) == 0)
2334 il = cvp->il_latency;
2338 ignorelist_add (il, name);
2339 } /* }}} void cna_config_volume_perf_option */
2341 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
2342 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
2343 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
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 ("IgnoreSelectedIO", ci->key) == 0)
2356 il = cvp->il_octets;
2357 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
2358 il = cvp->il_operations;
2359 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
2360 il = cvp->il_latency;
2364 if (ci->values[0].value.boolean)
2365 ignorelist_set_invert (il, /* invert = */ 0);
2367 ignorelist_set_invert (il, /* invert = */ 1);
2368 } /* }}} void cna_config_volume_perf_default */
2370 /* Corresponds to a <Disks /> block */
2375 * IgnoreSelectedIO false
2379 * IgnoreSelectedOps false
2383 * IgnoreSelectedLatency false
2386 /* Corresponds to a <VolumePerf /> block */
2387 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
2388 const oconfig_item_t *ci)
2390 cfg_volume_perf_t *cfg_volume_perf;
2393 if ((host == NULL) || (ci == NULL))
2396 if (host->cfg_volume_perf == NULL)
2398 cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
2399 if (cfg_volume_perf == NULL)
2401 memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
2403 /* Set default flags */
2404 cfg_volume_perf->query = NULL;
2405 cfg_volume_perf->volumes = NULL;
2407 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
2408 if (cfg_volume_perf->il_octets == NULL)
2410 sfree (cfg_volume_perf);
2414 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
2415 if (cfg_volume_perf->il_operations == NULL)
2417 ignorelist_free (cfg_volume_perf->il_octets);
2418 sfree (cfg_volume_perf);
2422 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
2423 if (cfg_volume_perf->il_latency == NULL)
2425 ignorelist_free (cfg_volume_perf->il_octets);
2426 ignorelist_free (cfg_volume_perf->il_operations);
2427 sfree (cfg_volume_perf);
2431 host->cfg_volume_perf = cfg_volume_perf;
2433 cfg_volume_perf = host->cfg_volume_perf;
2435 for (i = 0; i < ci->children_num; ++i) {
2436 oconfig_item_t *item = ci->children + i;
2438 /* if (!item || !item->key || !*item->key) continue; */
2439 if (strcasecmp(item->key, "Interval") == 0)
2440 cna_config_get_interval (item, &cfg_volume_perf->interval);
2441 else if (!strcasecmp(item->key, "GetIO"))
2442 cna_config_volume_perf_option (cfg_volume_perf, item);
2443 else if (!strcasecmp(item->key, "GetOps"))
2444 cna_config_volume_perf_option (cfg_volume_perf, item);
2445 else if (!strcasecmp(item->key, "GetLatency"))
2446 cna_config_volume_perf_option (cfg_volume_perf, item);
2447 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
2448 cna_config_volume_perf_default (cfg_volume_perf, item);
2449 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
2450 cna_config_volume_perf_default (cfg_volume_perf, item);
2451 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2452 cna_config_volume_perf_default (cfg_volume_perf, item);
2454 WARNING ("netapp plugin: The option %s is not allowed within "
2455 "`VolumePerf' blocks.", item->key);
2459 } /* }}} int cna_config_volume_performance */
2461 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2462 * <VolumeUsage /> block. */
2463 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
2464 const oconfig_item_t *ci)
2469 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2471 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2476 name = ci->values[0].value.string;
2478 if (strcasecmp ("GetCapacity", ci->key) == 0)
2479 il = cvu->il_capacity;
2480 else if (strcasecmp ("GetSnapshot", ci->key) == 0)
2481 il = cvu->il_snapshot;
2485 ignorelist_add (il, name);
2486 } /* }}} void cna_config_volume_usage_option */
2488 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2489 * options within a <VolumeUsage /> block. */
2490 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
2491 const oconfig_item_t *ci)
2495 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2497 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2502 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2503 il = cvu->il_capacity;
2504 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2505 il = cvu->il_snapshot;
2509 if (ci->values[0].value.boolean)
2510 ignorelist_set_invert (il, /* invert = */ 0);
2512 ignorelist_set_invert (il, /* invert = */ 1);
2513 } /* }}} void cna_config_volume_usage_default */
2515 /* Corresponds to a <Quota /> block */
2516 static int cna_config_quota (host_config_t *host, oconfig_item_t *ci) /* {{{ */
2518 cfg_quota_t *cfg_quota;
2521 if ((host == NULL) || (ci == NULL))
2524 if (host->cfg_quota == NULL)
2526 cfg_quota = malloc (sizeof (*cfg_quota));
2527 if (cfg_quota == NULL)
2529 memset (cfg_quota, 0, sizeof (*cfg_quota));
2530 cfg_quota->query = NULL;
2532 host->cfg_quota = cfg_quota;
2534 cfg_quota = host->cfg_quota;
2536 for (i = 0; i < ci->children_num; ++i) {
2537 oconfig_item_t *item = ci->children + i;
2539 if (strcasecmp (item->key, "Interval") == 0)
2540 cna_config_get_interval (item, &cfg_quota->interval);
2542 WARNING ("netapp plugin: The option %s is not allowed within "
2543 "`Quota' blocks.", item->key);
2547 } /* }}} int cna_config_quota */
2549 /* Corresponds to a <Disks /> block */
2550 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2551 cfg_disk_t *cfg_disk;
2554 if ((host == NULL) || (ci == NULL))
2557 if (host->cfg_disk == NULL)
2559 cfg_disk = malloc (sizeof (*cfg_disk));
2560 if (cfg_disk == NULL)
2562 memset (cfg_disk, 0, sizeof (*cfg_disk));
2564 /* Set default flags */
2565 cfg_disk->flags = CFG_DISK_ALL;
2566 cfg_disk->query = NULL;
2567 cfg_disk->disks = NULL;
2569 host->cfg_disk = cfg_disk;
2571 cfg_disk = host->cfg_disk;
2573 for (i = 0; i < ci->children_num; ++i) {
2574 oconfig_item_t *item = ci->children + i;
2576 /* if (!item || !item->key || !*item->key) continue; */
2577 if (strcasecmp(item->key, "Interval") == 0)
2578 cna_config_get_interval (item, &cfg_disk->interval);
2579 else if (strcasecmp(item->key, "GetBusy") == 0)
2580 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2583 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2585 NOTICE ("netapp plugin: All disk related values have been disabled. "
2586 "Collection of per-disk data will be disabled entirely.");
2587 free_cfg_disk (host->cfg_disk);
2588 host->cfg_disk = NULL;
2592 } /* }}} int cna_config_disk */
2594 /* Corresponds to a <WAFL /> block */
2595 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2597 cfg_wafl_t *cfg_wafl;
2600 if ((host == NULL) || (ci == NULL))
2603 if (host->cfg_wafl == NULL)
2605 cfg_wafl = malloc (sizeof (*cfg_wafl));
2606 if (cfg_wafl == NULL)
2608 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
2610 /* Set default flags */
2611 cfg_wafl->flags = CFG_WAFL_ALL;
2613 host->cfg_wafl = cfg_wafl;
2615 cfg_wafl = host->cfg_wafl;
2617 for (i = 0; i < ci->children_num; ++i) {
2618 oconfig_item_t *item = ci->children + i;
2620 if (strcasecmp(item->key, "Interval") == 0)
2621 cna_config_get_interval (item, &cfg_wafl->interval);
2622 else if (!strcasecmp(item->key, "GetNameCache"))
2623 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2624 else if (!strcasecmp(item->key, "GetDirCache"))
2625 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2626 else if (!strcasecmp(item->key, "GetBufferCache"))
2627 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2628 else if (!strcasecmp(item->key, "GetInodeCache"))
2629 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2631 WARNING ("netapp plugin: The %s config option is not allowed within "
2632 "`WAFL' blocks.", item->key);
2635 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2637 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2638 "Collection of WAFL data will be disabled entirely.");
2639 free_cfg_wafl (host->cfg_wafl);
2640 host->cfg_wafl = NULL;
2644 } /* }}} int cna_config_wafl */
2648 * GetCapacity "vol0"
2649 * GetCapacity "vol1"
2650 * GetCapacity "vol2"
2651 * GetCapacity "vol3"
2652 * GetCapacity "vol4"
2653 * IgnoreSelectedCapacity false
2655 * GetSnapshot "vol0"
2656 * GetSnapshot "vol3"
2657 * GetSnapshot "vol4"
2658 * GetSnapshot "vol7"
2659 * IgnoreSelectedSnapshot false
2662 /* Corresponds to a <VolumeUsage /> block */
2663 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2664 const oconfig_item_t *ci)
2666 cfg_volume_usage_t *cfg_volume_usage;
2669 if ((host == NULL) || (ci == NULL))
2672 if (host->cfg_volume_usage == NULL)
2674 cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
2675 if (cfg_volume_usage == NULL)
2677 memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
2679 /* Set default flags */
2680 cfg_volume_usage->query = NULL;
2681 cfg_volume_usage->volumes = NULL;
2683 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2684 if (cfg_volume_usage->il_capacity == NULL)
2686 sfree (cfg_volume_usage);
2690 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2691 if (cfg_volume_usage->il_snapshot == NULL)
2693 ignorelist_free (cfg_volume_usage->il_capacity);
2694 sfree (cfg_volume_usage);
2698 host->cfg_volume_usage = cfg_volume_usage;
2700 cfg_volume_usage = host->cfg_volume_usage;
2702 for (i = 0; i < ci->children_num; ++i) {
2703 oconfig_item_t *item = ci->children + i;
2705 /* if (!item || !item->key || !*item->key) continue; */
2706 if (strcasecmp(item->key, "Interval") == 0)
2707 cna_config_get_interval (item, &cfg_volume_usage->interval);
2708 else if (!strcasecmp(item->key, "GetCapacity"))
2709 cna_config_volume_usage_option (cfg_volume_usage, item);
2710 else if (!strcasecmp(item->key, "GetSnapshot"))
2711 cna_config_volume_usage_option (cfg_volume_usage, item);
2712 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2713 cna_config_volume_usage_default (cfg_volume_usage, item);
2714 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2715 cna_config_volume_usage_default (cfg_volume_usage, item);
2717 WARNING ("netapp plugin: The option %s is not allowed within "
2718 "`VolumeUsage' blocks.", item->key);
2722 } /* }}} int cna_config_volume_usage */
2724 /* Corresponds to a <SnapVault /> block */
2725 static int cna_config_snapvault (host_config_t *host, /* {{{ */
2726 const oconfig_item_t *ci)
2728 cfg_snapvault_t *cfg_snapvault;
2731 if ((host == NULL) || (ci == NULL))
2734 if (host->cfg_snapvault == NULL)
2736 cfg_snapvault = malloc (sizeof (*cfg_snapvault));
2737 if (cfg_snapvault == NULL)
2739 memset (cfg_snapvault, 0, sizeof (*cfg_snapvault));
2740 cfg_snapvault->query = NULL;
2742 host->cfg_snapvault = cfg_snapvault;
2745 cfg_snapvault = host->cfg_snapvault;
2747 for (i = 0; i < ci->children_num; ++i) {
2748 oconfig_item_t *item = ci->children + i;
2750 if (strcasecmp (item->key, "Interval") == 0)
2751 cna_config_get_interval (item, &cfg_snapvault->interval);
2753 WARNING ("netapp plugin: The option %s is not allowed within "
2754 "`SnapVault' blocks.", item->key);
2758 } /* }}} int cna_config_snapvault */
2760 /* Corresponds to a <System /> block */
2761 static int cna_config_system (host_config_t *host, /* {{{ */
2764 cfg_system_t *cfg_system;
2767 if ((host == NULL) || (ci == NULL))
2770 if (host->cfg_system == NULL)
2772 cfg_system = malloc (sizeof (*cfg_system));
2773 if (cfg_system == NULL)
2775 memset (cfg_system, 0, sizeof (*cfg_system));
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 = malloc(sizeof(*host));
2823 memset (host, 0, sizeof (*host));
2826 host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2828 host->username = NULL;
2829 host->password = NULL;
2830 host->vfiler = NULL;
2832 host->cfg_wafl = NULL;
2833 host->cfg_disk = NULL;
2834 host->cfg_volume_perf = NULL;
2835 host->cfg_volume_usage = NULL;
2836 host->cfg_quota = NULL;
2837 host->cfg_snapvault = NULL;
2838 host->cfg_system = NULL;
2841 } /* }}} host_config_t *cna_alloc_host */
2843 static host_config_t *cna_shallow_clone_host (host_config_t *host) /* {{{ */
2845 host_config_t *clone;
2850 clone = cna_alloc_host ();
2854 if (host->name != NULL) {
2855 clone->name = strdup (host->name);
2856 if (clone->name == NULL) {
2857 free_host_config (clone);
2862 clone->protocol = host->protocol;
2864 if (host->host != NULL) {
2865 clone->host = strdup (host->host);
2866 if (clone->host == NULL) {
2867 free_host_config (clone);
2872 clone->port = host->port;
2874 if (host->username != NULL) {
2875 clone->username = strdup (host->username);
2876 if (clone->username == NULL) {
2877 free_host_config (clone);
2881 if (host->password != NULL) {
2882 clone->password = strdup (host->password);
2883 if (clone->password == NULL) {
2884 free_host_config (clone);
2889 clone->interval = host->interval;
2892 } /* }}} host_config_t *cna_shallow_clone_host */
2894 static int cna_read (user_data_t *ud);
2896 static int cna_register_host (host_config_t *host) /* {{{ */
2899 struct timespec interval;
2903 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s-%s",
2904 host->name, host->vfiler);
2906 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name);
2908 CDTIME_T_TO_TIMESPEC (host->interval, &interval);
2910 memset (&ud, 0, sizeof (ud));
2912 ud.free_func = (void (*) (void *)) free_host_config;
2914 plugin_register_complex_read (/* group = */ NULL, cb_name,
2915 /* callback = */ cna_read,
2916 /* interval = */ (host->interval > 0) ? &interval : NULL,
2917 /* user data = */ &ud);
2920 } /* }}} int cna_register_host */
2922 static int cna_config_host (host_config_t *host, /* {{{ */
2923 const oconfig_item_t *ci)
2925 oconfig_item_t *item;
2926 _Bool is_vfiler = 0;
2930 if (! strcasecmp (ci->key, "VFiler"))
2933 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2934 WARNING ("netapp plugin: \"%s\" needs exactly one string argument. Ignoring host block.", ci->key);
2938 status = cf_util_get_string (ci, &host->name);
2942 for (i = 0; i < ci->children_num; ++i) {
2943 item = ci->children + i;
2947 if (!strcasecmp(item->key, "Address")) {
2948 status = cf_util_get_string (item, &host->host);
2949 } else if (!strcasecmp(item->key, "Port")) {
2952 tmp = cf_util_get_port_number (item);
2955 } else if (!strcasecmp(item->key, "Protocol")) {
2956 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"))) {
2957 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2960 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2961 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2962 } else if (!strcasecmp(item->key, "User")) {
2963 status = cf_util_get_string (item, &host->username);
2964 } else if (!strcasecmp(item->key, "Password")) {
2965 status = cf_util_get_string (item, &host->password);
2966 } else if (!strcasecmp(item->key, "Interval")) {
2967 status = cf_util_get_cdtime (item, &host->interval);
2968 } else if (!strcasecmp(item->key, "WAFL")) {
2969 cna_config_wafl(host, item);
2970 } else if (!strcasecmp(item->key, "Disks")) {
2971 cna_config_disk(host, item);
2972 } else if (!strcasecmp(item->key, "VolumePerf")) {
2973 cna_config_volume_performance(host, item);
2974 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2975 cna_config_volume_usage(host, item);
2976 } else if (!strcasecmp(item->key, "Quota")) {
2977 cna_config_quota(host, item);
2978 } else if (!strcasecmp(item->key, "SnapVault")) {
2979 cna_config_snapvault(host, item);
2980 } else if (!strcasecmp(item->key, "System")) {
2981 cna_config_system(host, item);
2982 } else if ((!strcasecmp(item->key, "VFiler")) && (! is_vfiler)) {
2983 host_config_t *vfiler;
2985 vfiler = cna_shallow_clone_host (host);
2987 ERROR ("netapp plugin: Failed to allocate host object for vfiler.");
2991 if (cna_config_host (vfiler, item)) {
2992 free_host_config (vfiler);
2996 cna_register_host (vfiler);
2997 } else if ((!strcasecmp(item->key, "VFilerName")) && is_vfiler) {
2998 status = cf_util_get_string (item, &host->vfiler);
3000 WARNING ("netapp plugin: Ignoring unknown config option \"%s\" in %s block \"%s\".",
3001 item->key, is_vfiler ? "vfiler" : "host", ci->values[0].value.string);
3008 if (host->host == NULL)
3009 host->host = strdup (host->name);
3011 if (is_vfiler && (! host->vfiler))
3012 host->vfiler = strdup (host->name);
3014 if (host->host == NULL)
3017 if (host->port <= 0)
3018 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
3020 if ((host->username == NULL) || (host->password == NULL)) {
3021 WARNING("netapp plugin: Please supply login information for host \"%s\". "
3022 "Ignoring host block.", host->name);
3030 } /* }}} host_config_t *cna_config_host */
3033 * Callbacks registered with the daemon
3035 * Pretty standard stuff here.
3037 static int cna_init_host (host_config_t *host) /* {{{ */
3039 /* Request version 1.1 of the ONTAP API */
3040 int major_version = 1, minor_version = 1;
3045 if (host->srv != NULL)
3048 if (host->vfiler != NULL) /* Request version 1.7 of the ONTAP API */
3051 host->srv = na_server_open (host->host, major_version, minor_version);
3052 if (host->srv == NULL) {
3053 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
3057 na_server_set_transport_type(host->srv, host->protocol,
3058 /* transportarg = */ NULL);
3059 na_server_set_port(host->srv, host->port);
3060 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
3061 na_server_adminuser(host->srv, host->username, host->password);
3062 na_server_set_timeout(host->srv, 5 /* seconds */);
3064 if (host->vfiler != NULL) {
3065 if (! na_server_set_vfiler (host->srv, host->vfiler)) {
3066 ERROR ("netapp plugin: Failed to connect to VFiler '%s' on host '%s'.",
3067 host->vfiler, host->host);
3071 INFO ("netapp plugin: Connected to VFiler '%s' on host '%s'.",
3072 host->vfiler, host->host);
3077 } /* }}} int cna_init_host */
3079 static int cna_init (void) /* {{{ */
3083 memset (err, 0, sizeof (err));
3084 if (!na_startup(err, sizeof(err))) {
3085 err[sizeof (err) - 1] = 0;
3086 ERROR("netapp plugin: Error initializing netapp API: %s", err);
3091 } /* }}} cna_init */
3093 static int cna_read_internal (host_config_t *host) { /* {{{ */
3096 status = cna_query_wafl (host);
3100 status = cna_query_disk (host);
3104 status = cna_query_volume_perf (host);
3108 status = cna_query_volume_usage (host);
3112 status = cna_query_quota (host);
3116 status = cna_query_snapvault (host);
3120 status = cna_query_system (host);
3125 } /* }}} int cna_read_internal */
3127 static int cna_read (user_data_t *ud) { /* {{{ */
3128 host_config_t *host;
3131 if ((ud == NULL) || (ud->data == NULL))
3136 status = cna_init_host (host);
3140 status = cna_read_internal (host);
3143 if (host->srv != NULL)
3144 na_server_close (host->srv);
3149 } /* }}} int cna_read */
3151 static int cna_config (oconfig_item_t *ci) { /* {{{ */
3153 oconfig_item_t *item;
3155 for (i = 0; i < ci->children_num; ++i) {
3156 item = ci->children + i;
3158 if (strcasecmp(item->key, "Host") == 0)
3160 host_config_t *host;
3162 host = cna_alloc_host ();
3164 ERROR ("netapp plugin: Failed to allocate host object.");
3168 if (cna_config_host (host, item) != 0) {
3169 free_host_config (host);
3173 cna_register_host (host);
3175 else /* if (item->key != "Host") */
3177 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
3181 } /* }}} int cna_config */
3183 static int cna_shutdown (void) /* {{{ */
3185 /* Clean up system resources and stuff. */
3189 } /* }}} int cna_shutdown */
3191 void module_register(void) {
3192 plugin_register_complex_config("netapp", cna_config);
3193 plugin_register_init("netapp", cna_init);
3194 plugin_register_shutdown("netapp", cna_shutdown);
3197 /* vim: set sw=2 ts=2 noet fdm=marker : */