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/common/common.h"
32 #include "utils/ignorelist/ignorelist.h"
34 #include <netapp_api.h>
35 #include <netapp_errno.h>
37 #define HAS_ALL_FLAGS(has, needs) (((has) & (needs)) == (needs))
39 typedef struct host_config_s host_config_t;
40 typedef void service_handler_t(host_config_t *host, na_elem_t *result,
43 struct cna_interval_s {
47 typedef struct cna_interval_s cna_interval_t;
49 /*! Data types for WAFL statistics {{{
51 * \brief Persistent data for WAFL performance counters. (a.k.a. cache
54 * The cache counters use old counter values to calculate a hit ratio for each
55 * counter. The "cfg_wafl_t" struct therefore contains old counter values along
56 * with flags, which are set if the counter is valid.
58 * The function "cna_handle_wafl_data" will fill a new structure of this kind
59 * with new values, then pass both, new and old data, to "submit_wafl_data".
60 * That function calculates the hit ratios, submits the calculated values and
61 * updates the old counter values for the next iteration.
63 #define CFG_WAFL_NAME_CACHE 0x0001
64 #define CFG_WAFL_DIR_CACHE 0x0002
65 #define CFG_WAFL_BUF_CACHE 0x0004
66 #define CFG_WAFL_INODE_CACHE 0x0008
67 #define CFG_WAFL_ALL 0x000F
68 #define HAVE_WAFL_NAME_CACHE_HIT 0x0100
69 #define HAVE_WAFL_NAME_CACHE_MISS 0x0200
70 #define HAVE_WAFL_NAME_CACHE \
71 (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
72 #define HAVE_WAFL_FIND_DIR_HIT 0x0400
73 #define HAVE_WAFL_FIND_DIR_MISS 0x0800
74 #define HAVE_WAFL_FIND_DIR (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
75 #define HAVE_WAFL_BUF_HASH_HIT 0x1000
76 #define HAVE_WAFL_BUF_HASH_MISS 0x2000
77 #define HAVE_WAFL_BUF_HASH (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
78 #define HAVE_WAFL_INODE_CACHE_HIT 0x4000
79 #define HAVE_WAFL_INODE_CACHE_MISS 0x8000
80 #define HAVE_WAFL_INODE_CACHE \
81 (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
82 #define HAVE_WAFL_ALL 0xff00
85 cna_interval_t interval;
89 uint64_t name_cache_hit;
90 uint64_t name_cache_miss;
91 uint64_t find_dir_hit;
92 uint64_t find_dir_miss;
93 uint64_t buf_hash_hit;
94 uint64_t buf_hash_miss;
95 uint64_t inode_cache_hit;
96 uint64_t inode_cache_miss;
100 /*! Data types for disk statistics {{{
102 * \brief A disk in the NetApp.
104 * A disk doesn't have any more information than its name at the moment.
105 * The name includes the "disk_" prefix.
107 #define HAVE_DISK_BUSY 0x10
108 #define HAVE_DISK_BASE 0x20
109 #define HAVE_DISK_ALL 0x30
110 typedef struct disk_s {
115 uint64_t base_for_disk_busy;
116 double disk_busy_percent;
120 #define CFG_DISK_BUSIEST 0x01
121 #define CFG_DISK_ALL 0x01
124 cna_interval_t interval;
130 /*! Data types for volume performance statistics {{{
132 * \brief Persistent data for volume performance data.
134 * The code below uses the difference of the operations and latency counters to
135 * calculate an average per-operation latency. For this, old counters need to
136 * be stored in the "data_volume_perf_t" structure. The byte-counters are just
137 * kept for completeness sake. The "flags" member indicates if each counter is
140 * The "cna_handle_volume_perf_data" function will fill a new struct of this
141 * type and pass both, old and new data, to "submit_volume_perf_data". In that
142 * function, the per-operation latency is calculated and dispatched, then the
143 * old counters are updated.
145 #define CFG_VOLUME_PERF_INIT 0x0001
146 #define CFG_VOLUME_PERF_IO 0x0002
147 #define CFG_VOLUME_PERF_OPS 0x0003
148 #define CFG_VOLUME_PERF_LATENCY 0x0008
149 #define CFG_VOLUME_PERF_ALL 0x000F
150 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
151 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
152 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
153 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
154 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
155 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
156 #define HAVE_VOLUME_PERF_ALL 0x03F0
157 struct data_volume_perf_s;
158 typedef struct data_volume_perf_s data_volume_perf_t;
159 struct data_volume_perf_s {
165 uint64_t write_bytes;
168 uint64_t read_latency;
169 uint64_t write_latency;
171 data_volume_perf_t *next;
175 cna_interval_t interval;
178 ignorelist_t *il_octets;
179 ignorelist_t *il_operations;
180 ignorelist_t *il_latency;
182 data_volume_perf_t *volumes;
184 /* }}} data_volume_perf_t */
186 /*! Data types for volume usage statistics {{{
188 * \brief Configuration struct for volume usage data (free / used).
190 #define CFG_VOLUME_USAGE_DF 0x0002
191 #define CFG_VOLUME_USAGE_SNAP 0x0004
192 #define CFG_VOLUME_USAGE_ALL 0x0006
193 #define HAVE_VOLUME_USAGE_NORM_FREE 0x0010
194 #define HAVE_VOLUME_USAGE_NORM_USED 0x0020
195 #define HAVE_VOLUME_USAGE_SNAP_RSVD 0x0040
196 #define HAVE_VOLUME_USAGE_SNAP_USED 0x0080
197 #define HAVE_VOLUME_USAGE_SIS_SAVED 0x0100
198 #define HAVE_VOLUME_USAGE_COMPRESS_SAVED 0x0200
199 #define HAVE_VOLUME_USAGE_DEDUP_SAVED 0x0400
200 #define HAVE_VOLUME_USAGE_ALL 0x07f0
201 #define IS_VOLUME_USAGE_OFFLINE 0x0800
202 struct data_volume_usage_s;
203 typedef struct data_volume_usage_s data_volume_usage_t;
204 struct data_volume_usage_s {
208 na_elem_t *snap_query;
212 uint64_t snap_reserved;
215 uint64_t compress_saved;
216 uint64_t dedup_saved;
218 data_volume_usage_t *next;
222 cna_interval_t interval;
225 ignorelist_t *il_capacity;
226 ignorelist_t *il_snapshot;
228 data_volume_usage_t *volumes;
229 } cfg_volume_usage_t;
230 /* }}} cfg_volume_usage_t */
232 /*! Data types for quota statistics {{{
234 * \brief Persistent data for quota statistics
237 cna_interval_t interval;
240 /* }}} cfg_quota_t */
242 /*! Data types for SnapVault statistics {{{
244 * \brief Persistent data for SnapVault(R) statistics
247 cna_interval_t interval;
250 /* }}} cfg_snapvault_t */
252 /*! Data types for system statistics {{{
254 * \brief Persistent data for system performance counters
256 #define CFG_SYSTEM_CPU 0x01
257 #define CFG_SYSTEM_NET 0x02
258 #define CFG_SYSTEM_OPS 0x04
259 #define CFG_SYSTEM_DISK 0x08
260 #define CFG_SYSTEM_ALL 0x0F
263 cna_interval_t interval;
266 /* }}} cfg_system_t */
268 struct host_config_s {
270 na_server_transport_t protocol;
279 cfg_wafl_t *cfg_wafl;
280 cfg_disk_t *cfg_disk;
281 cfg_volume_perf_t *cfg_volume_perf;
282 cfg_volume_usage_t *cfg_volume_usage;
283 cfg_quota_t *cfg_quota;
284 cfg_snapvault_t *cfg_snapvault;
285 cfg_system_t *cfg_system;
287 struct host_config_s *next;
293 * Used to free the various structures above.
295 static void free_disk(disk_t *disk) /* {{{ */
308 } /* }}} void free_disk */
310 static void free_cfg_wafl(cfg_wafl_t *cw) /* {{{ */
315 if (cw->query != NULL)
316 na_elem_free(cw->query);
319 } /* }}} void free_cfg_wafl */
321 static void free_cfg_disk(cfg_disk_t *cfg_disk) /* {{{ */
323 if (cfg_disk == NULL)
326 if (cfg_disk->query != NULL)
327 na_elem_free(cfg_disk->query);
329 free_disk(cfg_disk->disks);
331 } /* }}} void free_cfg_disk */
333 static void free_cfg_volume_perf(cfg_volume_perf_t *cvp) /* {{{ */
335 data_volume_perf_t *data;
340 /* Free the ignorelists */
341 ignorelist_free(cvp->il_octets);
342 ignorelist_free(cvp->il_operations);
343 ignorelist_free(cvp->il_latency);
345 /* Free the linked list of volumes */
347 while (data != NULL) {
348 data_volume_perf_t *next = data->next;
354 if (cvp->query != NULL)
355 na_elem_free(cvp->query);
358 } /* }}} void free_cfg_volume_perf */
360 static void free_cfg_volume_usage(cfg_volume_usage_t *cvu) /* {{{ */
362 data_volume_usage_t *data;
367 /* Free the ignorelists */
368 ignorelist_free(cvu->il_capacity);
369 ignorelist_free(cvu->il_snapshot);
371 /* Free the linked list of volumes */
373 while (data != NULL) {
374 data_volume_usage_t *next = data->next;
376 if (data->snap_query != NULL)
377 na_elem_free(data->snap_query);
382 if (cvu->query != NULL)
383 na_elem_free(cvu->query);
386 } /* }}} void free_cfg_volume_usage */
388 static void free_cfg_quota(cfg_quota_t *q) /* {{{ */
393 if (q->query != NULL)
394 na_elem_free(q->query);
397 } /* }}} void free_cfg_quota */
399 static void free_cfg_snapvault(cfg_snapvault_t *sv) /* {{{ */
404 if (sv->query != NULL)
405 na_elem_free(sv->query);
408 } /* }}} void free_cfg_snapvault */
410 static void free_cfg_system(cfg_system_t *cs) /* {{{ */
415 if (cs->query != NULL)
416 na_elem_free(cs->query);
419 } /* }}} void free_cfg_system */
421 static void free_host_config(host_config_t *hc) /* {{{ */
436 free_cfg_disk(hc->cfg_disk);
437 free_cfg_wafl(hc->cfg_wafl);
438 free_cfg_volume_perf(hc->cfg_volume_perf);
439 free_cfg_volume_usage(hc->cfg_volume_usage);
440 free_cfg_quota(hc->cfg_quota);
441 free_cfg_snapvault(hc->cfg_snapvault);
442 free_cfg_system(hc->cfg_system);
445 na_server_close(hc->srv);
449 free_host_config(next);
450 } /* }}} void free_host_config */
453 * Auxiliary functions
455 * Used to look up volumes and disks or to handle flags.
457 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
461 if ((cd == NULL) || (name == NULL))
464 for (d = cd->disks; d != NULL; d = d->next) {
465 if (strcmp(d->name, name) == 0)
469 d = calloc(1, sizeof(*d));
474 d->name = strdup(name);
475 if (d->name == NULL) {
484 } /* }}} disk_t *get_disk */
486 static data_volume_usage_t *get_volume_usage(cfg_volume_usage_t *cvu, /* {{{ */
488 data_volume_usage_t *last;
489 data_volume_usage_t *new;
491 int ignore_capacity = 0;
492 int ignore_snapshot = 0;
494 if ((cvu == NULL) || (name == NULL))
498 while (last != 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.
510 ignore_capacity = ignorelist_match(cvu->il_capacity, name);
511 ignore_snapshot = ignorelist_match(cvu->il_snapshot, name);
512 if ((ignore_capacity != 0) && (ignore_snapshot != 0))
515 /* Not found: allocate. */
516 new = calloc(1, sizeof(*new));
521 new->name = strdup(name);
522 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, /* {{{ */
549 data_volume_perf_t *last;
550 data_volume_perf_t *new;
552 int ignore_octets = 0;
553 int ignore_operations = 0;
554 int ignore_latency = 0;
556 if ((cvp == NULL) || (name == NULL))
560 while (last != NULL) {
561 if (strcmp(last->name, name) == 0)
564 if (last->next == NULL)
570 /* Check the ignorelists. If *all three* tell us to ignore a volume, return
572 ignore_octets = ignorelist_match(cvp->il_octets, name);
573 ignore_operations = ignorelist_match(cvp->il_operations, name);
574 ignore_latency = ignorelist_match(cvp->il_latency, name);
575 if ((ignore_octets != 0) || (ignore_operations != 0) || (ignore_latency != 0))
578 /* Not found: allocate. */
579 new = calloc(1, sizeof(*new));
584 new->name = strdup(name);
585 if (new->name == NULL) {
590 if (ignore_octets == 0)
591 new->flags |= CFG_VOLUME_PERF_IO;
592 if (ignore_operations == 0)
593 new->flags |= CFG_VOLUME_PERF_OPS;
594 if (ignore_latency == 0)
595 new->flags |= CFG_VOLUME_PERF_LATENCY;
597 /* Add to end of list. */
604 } /* }}} data_volume_perf_t *get_volume_perf */
607 * Various submit functions.
609 * They all eventually call "submit_values" which creates a value_list_t and
610 * dispatches it to the daemon.
612 static int submit_values(const char *host, /* {{{ */
613 const char *plugin_inst, const char *type,
614 const char *type_inst, value_t *values,
615 size_t values_len, cdtime_t timestamp,
617 value_list_t vl = VALUE_LIST_INIT;
620 vl.values_len = values_len;
626 vl.interval = interval;
629 sstrncpy(vl.host, host, sizeof(vl.host));
630 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
631 if (plugin_inst != NULL)
632 sstrncpy(vl.plugin_instance, plugin_inst, sizeof(vl.plugin_instance));
633 sstrncpy(vl.type, type, sizeof(vl.type));
634 if (type_inst != NULL)
635 sstrncpy(vl.type_instance, type_inst, sizeof(vl.type_instance));
637 return plugin_dispatch_values(&vl);
638 } /* }}} int submit_uint64 */
640 static int submit_two_derive(const char *host,
641 const char *plugin_inst, /* {{{ */
642 const char *type, const char *type_inst,
643 derive_t val0, derive_t val1, cdtime_t timestamp,
650 return submit_values(host, plugin_inst, type, type_inst, values,
651 STATIC_ARRAY_SIZE(values), timestamp, interval);
652 } /* }}} int submit_two_derive */
654 static int submit_derive(const char *host, const char *plugin_inst, /* {{{ */
655 const char *type, const char *type_inst,
656 derive_t counter, cdtime_t timestamp,
658 return submit_values(host, plugin_inst, type, type_inst,
662 1, timestamp, interval);
663 } /* }}} int submit_derive */
665 static int submit_two_gauge(const char *host, const char *plugin_inst, /* {{{ */
666 const char *type, const char *type_inst,
667 gauge_t val0, gauge_t val1, cdtime_t timestamp,
674 return submit_values(host, plugin_inst, type, type_inst, values,
675 STATIC_ARRAY_SIZE(values), timestamp, interval);
676 } /* }}} int submit_two_gauge */
678 static int submit_double(const char *host, const char *plugin_inst, /* {{{ */
679 const char *type, const char *type_inst, double d,
680 cdtime_t timestamp, cdtime_t interval) {
681 return submit_values(host, plugin_inst, type, type_inst,
685 1, timestamp, interval);
686 } /* }}} int submit_uint64 */
688 /* Calculate hit ratio from old and new counters and submit the resulting
689 * percentage. Used by "submit_wafl_data". */
690 static int submit_cache_ratio(const char *host, /* {{{ */
691 const char *plugin_inst, const char *type_inst,
692 uint64_t new_hits, uint64_t new_misses,
693 uint64_t old_hits, uint64_t old_misses,
694 cdtime_t timestamp, cdtime_t interval) {
695 value_t v = {.gauge = NAN};
697 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
701 hits = new_hits - old_hits;
702 misses = new_misses - old_misses;
704 v.gauge = 100.0 * ((gauge_t)hits) / ((gauge_t)(hits + misses));
707 return submit_values(host, plugin_inst, "cache_ratio", type_inst, &v, 1,
708 timestamp, interval);
709 } /* }}} int submit_cache_ratio */
711 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
712 static int submit_wafl_data(const char *hostname,
713 const char *instance, /* {{{ */
714 cfg_wafl_t *old_data, const cfg_wafl_t *new_data,
716 /* Submit requested counters */
717 if (HAS_ALL_FLAGS(old_data->flags,
718 CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE) &&
719 HAS_ALL_FLAGS(new_data->flags, HAVE_WAFL_NAME_CACHE))
720 submit_cache_ratio(hostname, instance, "name_cache_hit",
721 new_data->name_cache_hit, new_data->name_cache_miss,
722 old_data->name_cache_hit, old_data->name_cache_miss,
723 new_data->timestamp, interval);
725 if (HAS_ALL_FLAGS(old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR) &&
726 HAS_ALL_FLAGS(new_data->flags, HAVE_WAFL_FIND_DIR))
727 submit_cache_ratio(hostname, instance, "find_dir_hit",
728 new_data->find_dir_hit, new_data->find_dir_miss,
729 old_data->find_dir_hit, old_data->find_dir_miss,
730 new_data->timestamp, interval);
732 if (HAS_ALL_FLAGS(old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH) &&
733 HAS_ALL_FLAGS(new_data->flags, HAVE_WAFL_BUF_HASH))
734 submit_cache_ratio(hostname, instance, "buf_hash_hit",
735 new_data->buf_hash_hit, new_data->buf_hash_miss,
736 old_data->buf_hash_hit, old_data->buf_hash_miss,
737 new_data->timestamp, interval);
739 if (HAS_ALL_FLAGS(old_data->flags,
740 CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE) &&
741 HAS_ALL_FLAGS(new_data->flags, HAVE_WAFL_INODE_CACHE))
742 submit_cache_ratio(hostname, instance, "inode_cache_hit",
743 new_data->inode_cache_hit, new_data->inode_cache_miss,
744 old_data->inode_cache_hit, old_data->inode_cache_miss,
745 new_data->timestamp, interval);
747 /* Clear old HAVE_* flags */
748 old_data->flags &= ~HAVE_WAFL_ALL;
750 /* Copy all counters */
751 old_data->timestamp = new_data->timestamp;
752 old_data->name_cache_hit = new_data->name_cache_hit;
753 old_data->name_cache_miss = new_data->name_cache_miss;
754 old_data->find_dir_hit = new_data->find_dir_hit;
755 old_data->find_dir_miss = new_data->find_dir_miss;
756 old_data->buf_hash_hit = new_data->buf_hash_hit;
757 old_data->buf_hash_miss = new_data->buf_hash_miss;
758 old_data->inode_cache_hit = new_data->inode_cache_hit;
759 old_data->inode_cache_miss = new_data->inode_cache_miss;
761 /* Copy HAVE_* flags */
762 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
765 } /* }}} int submit_wafl_data */
767 /* Submits volume performance data to the daemon, taking care to honor and
768 * update flags appropriately. */
769 static int submit_volume_perf_data(const char *hostname, /* {{{ */
770 data_volume_perf_t *old_data,
771 const data_volume_perf_t *new_data,
773 char plugin_instance[DATA_MAX_NAME_LEN];
775 if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
778 ssnprintf(plugin_instance, sizeof(plugin_instance), "volume-%s",
781 /* Check for and submit disk-octet values */
782 if (HAS_ALL_FLAGS(old_data->flags, CFG_VOLUME_PERF_IO) &&
783 HAS_ALL_FLAGS(new_data->flags, HAVE_VOLUME_PERF_BYTES_READ |
784 HAVE_VOLUME_PERF_BYTES_WRITE)) {
786 hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
787 (derive_t)new_data->read_bytes, (derive_t)new_data->write_bytes,
788 new_data->timestamp, interval);
791 /* Check for and submit disk-operations values */
792 if (HAS_ALL_FLAGS(old_data->flags, CFG_VOLUME_PERF_OPS) &&
793 HAS_ALL_FLAGS(new_data->flags,
794 HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE)) {
795 submit_two_derive(hostname, plugin_instance, "disk_ops",
796 /* type instance = */ NULL, (derive_t)new_data->read_ops,
797 (derive_t)new_data->write_ops, new_data->timestamp,
801 /* Check for, calculate and submit disk-latency values */
802 if (HAS_ALL_FLAGS(old_data->flags, CFG_VOLUME_PERF_LATENCY |
803 HAVE_VOLUME_PERF_OPS_READ |
804 HAVE_VOLUME_PERF_OPS_WRITE |
805 HAVE_VOLUME_PERF_LATENCY_READ |
806 HAVE_VOLUME_PERF_LATENCY_WRITE) &&
807 HAS_ALL_FLAGS(new_data->flags, HAVE_VOLUME_PERF_OPS_READ |
808 HAVE_VOLUME_PERF_OPS_WRITE |
809 HAVE_VOLUME_PERF_LATENCY_READ |
810 HAVE_VOLUME_PERF_LATENCY_WRITE)) {
811 gauge_t latency_per_op_read;
812 gauge_t latency_per_op_write;
814 latency_per_op_read = NAN;
815 latency_per_op_write = NAN;
817 /* Check if a counter wrapped around. */
818 if ((new_data->read_ops > old_data->read_ops) &&
819 (new_data->read_latency > old_data->read_latency)) {
820 uint64_t diff_ops_read;
821 uint64_t diff_latency_read;
823 diff_ops_read = new_data->read_ops - old_data->read_ops;
824 diff_latency_read = new_data->read_latency - old_data->read_latency;
826 if (diff_ops_read > 0)
827 latency_per_op_read =
828 ((gauge_t)diff_latency_read) / ((gauge_t)diff_ops_read);
831 if ((new_data->write_ops > old_data->write_ops) &&
832 (new_data->write_latency > old_data->write_latency)) {
833 uint64_t diff_ops_write;
834 uint64_t diff_latency_write;
836 diff_ops_write = new_data->write_ops - old_data->write_ops;
837 diff_latency_write = new_data->write_latency - old_data->write_latency;
839 if (diff_ops_write > 0)
840 latency_per_op_write =
841 ((gauge_t)diff_latency_write) / ((gauge_t)diff_ops_write);
844 submit_two_gauge(hostname, plugin_instance, "disk_latency",
845 /* type instance = */ NULL, latency_per_op_read,
846 latency_per_op_write, new_data->timestamp, interval);
849 /* Clear all HAVE_* flags. */
850 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
852 /* Copy all counters */
853 old_data->timestamp = new_data->timestamp;
854 old_data->read_bytes = new_data->read_bytes;
855 old_data->write_bytes = new_data->write_bytes;
856 old_data->read_ops = new_data->read_ops;
857 old_data->write_ops = new_data->write_ops;
858 old_data->read_latency = new_data->read_latency;
859 old_data->write_latency = new_data->write_latency;
861 /* Copy the HAVE_* flags */
862 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
865 } /* }}} int submit_volume_perf_data */
867 static cdtime_t cna_child_get_cdtime(na_elem_t *data) /* {{{ */
871 t = (time_t)na_child_get_uint64(data, "timestamp", /* default = */ 0);
873 return TIME_T_TO_CDTIME_T(t);
874 } /* }}} cdtime_t cna_child_get_cdtime */
879 * These functions are called with appropriate data returned by the libnetapp
880 * interface which is parsed and submitted with the above functions.
882 /* Data corresponding to <WAFL /> */
883 static int cna_handle_wafl_data(const char *hostname,
884 cfg_wafl_t *cfg_wafl, /* {{{ */
885 na_elem_t *data, cdtime_t interval) {
886 cfg_wafl_t perf_data = {0};
887 const char *plugin_inst;
889 na_elem_t *instances;
890 na_elem_iter_t counter_iter;
892 perf_data.timestamp = cna_child_get_cdtime(data);
894 instances = na_elem_child(na_elem_child(data, "instances"), "instance-data");
895 if (instances == NULL) {
896 ERROR("netapp plugin: cna_handle_wafl_data: "
897 "na_elem_child (\"instances\") failed "
903 plugin_inst = na_child_get_string(instances, "name");
904 if (plugin_inst == NULL) {
905 ERROR("netapp plugin: cna_handle_wafl_data: "
906 "na_child_get_string (\"name\") failed "
912 /* Iterate over all counters */
913 counter_iter = na_child_iterator(na_elem_child(instances, "counters"));
914 for (na_elem_t *counter = na_iterator_next(&counter_iter); counter != NULL;
915 counter = na_iterator_next(&counter_iter)) {
919 name = na_child_get_string(counter, "name");
923 value = na_child_get_uint64(counter, "value", UINT64_MAX);
924 if (value == UINT64_MAX)
927 if (!strcmp(name, "name_cache_hit")) {
928 perf_data.name_cache_hit = value;
929 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
930 } else if (!strcmp(name, "name_cache_miss")) {
931 perf_data.name_cache_miss = value;
932 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
933 } else if (!strcmp(name, "find_dir_hit")) {
934 perf_data.find_dir_hit = value;
935 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
936 } else if (!strcmp(name, "find_dir_miss")) {
937 perf_data.find_dir_miss = value;
938 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
939 } else if (!strcmp(name, "buf_hash_hit")) {
940 perf_data.buf_hash_hit = value;
941 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
942 } else if (!strcmp(name, "buf_hash_miss")) {
943 perf_data.buf_hash_miss = value;
944 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
945 } else if (!strcmp(name, "inode_cache_hit")) {
946 perf_data.inode_cache_hit = value;
947 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
948 } else if (!strcmp(name, "inode_cache_miss")) {
949 perf_data.inode_cache_miss = value;
950 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
952 DEBUG("netapp plugin: cna_handle_wafl_data: "
953 "Found unexpected child: %s "
959 return submit_wafl_data(hostname, plugin_inst, cfg_wafl, &perf_data,
961 } /* }}} void cna_handle_wafl_data */
963 static int cna_setup_wafl(cfg_wafl_t *cw) /* {{{ */
970 if (cw->query != NULL)
973 cw->query = na_elem_new("perf-object-get-instances");
974 if (cw->query == NULL) {
975 ERROR("netapp plugin: na_elem_new failed.");
978 na_child_add_string(cw->query, "objectname", "wafl");
980 e = na_elem_new("counters");
982 na_elem_free(cw->query);
984 ERROR("netapp plugin: na_elem_new failed.");
987 na_child_add_string(e, "counter", "name_cache_hit");
988 na_child_add_string(e, "counter", "name_cache_miss");
989 na_child_add_string(e, "counter", "find_dir_hit");
990 na_child_add_string(e, "counter", "find_dir_miss");
991 na_child_add_string(e, "counter", "buf_hash_hit");
992 na_child_add_string(e, "counter", "buf_hash_miss");
993 na_child_add_string(e, "counter", "inode_cache_hit");
994 na_child_add_string(e, "counter", "inode_cache_miss");
996 na_child_add(cw->query, e);
999 } /* }}} int cna_setup_wafl */
1001 static int cna_query_wafl(host_config_t *host) /* {{{ */
1010 /* If WAFL was not configured, return without doing anything. */
1011 if (host->cfg_wafl == NULL)
1015 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) >
1019 status = cna_setup_wafl(host->cfg_wafl);
1022 assert(host->cfg_wafl->query != NULL);
1024 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
1025 if (na_results_status(data) != NA_OK) {
1026 ERROR("netapp plugin: cna_query_wafl: na_server_invoke_elem failed for "
1028 host->name, na_results_reason(data));
1033 status = cna_handle_wafl_data(host->name, host->cfg_wafl, data,
1034 host->cfg_wafl->interval.interval);
1037 host->cfg_wafl->interval.last_read = now;
1041 } /* }}} int cna_query_wafl */
1043 /* Data corresponding to <Disks /> */
1044 static int cna_handle_disk_data(const char *hostname, /* {{{ */
1045 cfg_disk_t *cfg_disk, na_elem_t *data,
1046 cdtime_t interval) {
1048 na_elem_t *instances;
1049 na_elem_iter_t instance_iter;
1050 disk_t *worst_disk = NULL;
1052 if ((cfg_disk == NULL) || (data == NULL))
1055 timestamp = cna_child_get_cdtime(data);
1057 instances = na_elem_child(data, "instances");
1058 if (instances == NULL) {
1059 ERROR("netapp plugin: cna_handle_disk_data: "
1060 "na_elem_child (\"instances\") failed "
1066 /* Iterate over all children */
1067 instance_iter = na_child_iterator(instances);
1068 for (na_elem_t *instance = na_iterator_next(&instance_iter); instance != NULL;
1069 instance = na_iterator_next(&instance_iter)) {
1071 disk_t new_data = {0};
1073 na_elem_iter_t counter_iterator;
1075 new_data.timestamp = timestamp;
1076 new_data.disk_busy_percent = NAN;
1078 old_data = get_disk(cfg_disk, na_child_get_string(instance, "name"));
1079 if (old_data == NULL)
1082 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1083 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1084 for (na_elem_t *counter = na_iterator_next(&counter_iterator);
1085 counter != NULL; counter = na_iterator_next(&counter_iterator)) {
1089 name = na_child_get_string(counter, "name");
1093 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1094 if (value == UINT64_MAX)
1097 if (strcmp(name, "disk_busy") == 0) {
1098 new_data.disk_busy = value;
1099 new_data.flags |= HAVE_DISK_BUSY;
1100 } else if (strcmp(name, "base_for_disk_busy") == 0) {
1101 new_data.base_for_disk_busy = value;
1102 new_data.flags |= HAVE_DISK_BASE;
1104 DEBUG("netapp plugin: cna_handle_disk_data: "
1105 "Counter not handled: %s = %" PRIu64,
1110 /* If all required counters are available and did not just wrap around,
1111 * calculate the busy percentage. Otherwise, the value is initialized to
1112 * NAN at the top of the for-loop. */
1113 if (HAS_ALL_FLAGS(old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE) &&
1114 HAS_ALL_FLAGS(new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE) &&
1115 (new_data.disk_busy >= old_data->disk_busy) &&
1116 (new_data.base_for_disk_busy > old_data->base_for_disk_busy)) {
1120 busy_diff = new_data.disk_busy - old_data->disk_busy;
1121 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1123 new_data.disk_busy_percent =
1124 100.0 * ((gauge_t)busy_diff) / ((gauge_t)base_diff);
1127 /* Clear HAVE_* flags */
1128 old_data->flags &= ~HAVE_DISK_ALL;
1131 old_data->timestamp = new_data.timestamp;
1132 old_data->disk_busy = new_data.disk_busy;
1133 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1134 old_data->disk_busy_percent = new_data.disk_busy_percent;
1137 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1139 if ((worst_disk == NULL) ||
1140 (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1141 worst_disk = old_data;
1142 } /* for (all disks) */
1144 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1145 submit_double(hostname, "system", "percent", "disk_busy",
1146 worst_disk->disk_busy_percent, timestamp, interval);
1149 } /* }}} int cna_handle_disk_data */
1151 static int cna_setup_disk(cfg_disk_t *cd) /* {{{ */
1158 if (cd->query != NULL)
1161 cd->query = na_elem_new("perf-object-get-instances");
1162 if (cd->query == NULL) {
1163 ERROR("netapp plugin: na_elem_new failed.");
1166 na_child_add_string(cd->query, "objectname", "disk");
1168 e = na_elem_new("counters");
1170 na_elem_free(cd->query);
1172 ERROR("netapp plugin: na_elem_new failed.");
1175 na_child_add_string(e, "counter", "disk_busy");
1176 na_child_add_string(e, "counter", "base_for_disk_busy");
1177 na_child_add(cd->query, e);
1180 } /* }}} int cna_setup_disk */
1182 static int cna_query_disk(host_config_t *host) /* {{{ */
1191 /* If the user did not configure disk statistics, return without doing
1193 if (host->cfg_disk == NULL)
1197 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) >
1201 status = cna_setup_disk(host->cfg_disk);
1204 assert(host->cfg_disk->query != NULL);
1206 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1207 if (na_results_status(data) != NA_OK) {
1208 ERROR("netapp plugin: cna_query_disk: na_server_invoke_elem failed for "
1210 host->name, na_results_reason(data));
1215 status = cna_handle_disk_data(host->name, host->cfg_disk, data,
1216 host->cfg_disk->interval.interval);
1219 host->cfg_disk->interval.last_read = now;
1223 } /* }}} int cna_query_disk */
1225 /* Data corresponding to <VolumePerf /> */
1226 static int cna_handle_volume_perf_data(const char *hostname, /* {{{ */
1227 cfg_volume_perf_t *cvp, na_elem_t *data,
1228 cdtime_t interval) {
1230 na_elem_t *elem_instances;
1231 na_elem_iter_t iter_instances;
1233 timestamp = cna_child_get_cdtime(data);
1235 elem_instances = na_elem_child(data, "instances");
1236 if (elem_instances == NULL) {
1237 ERROR("netapp plugin: handle_volume_perf_data: "
1238 "na_elem_child (\"instances\") failed "
1244 iter_instances = na_child_iterator(elem_instances);
1245 for (na_elem_t *elem_instance = na_iterator_next(&iter_instances);
1246 elem_instance != NULL;
1247 elem_instance = na_iterator_next(&iter_instances)) {
1250 data_volume_perf_t perf_data = {0};
1251 data_volume_perf_t *v;
1253 na_elem_t *elem_counters;
1254 na_elem_iter_t iter_counters;
1256 perf_data.timestamp = timestamp;
1258 name = na_child_get_string(elem_instance, "name");
1262 /* get_volume_perf may return NULL if this volume is to be ignored. */
1263 v = get_volume_perf(cvp, name);
1267 elem_counters = na_elem_child(elem_instance, "counters");
1268 if (elem_counters == NULL)
1271 iter_counters = na_child_iterator(elem_counters);
1272 for (na_elem_t *elem_counter = na_iterator_next(&iter_counters);
1273 elem_counter != NULL;
1274 elem_counter = na_iterator_next(&iter_counters)) {
1278 name = na_child_get_string(elem_counter, "name");
1282 value = na_child_get_uint64(elem_counter, "value", UINT64_MAX);
1283 if (value == UINT64_MAX)
1286 if (!strcmp(name, "read_data")) {
1287 perf_data.read_bytes = value;
1288 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1289 } else if (!strcmp(name, "write_data")) {
1290 perf_data.write_bytes = value;
1291 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1292 } else if (!strcmp(name, "read_ops")) {
1293 perf_data.read_ops = value;
1294 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1295 } else if (!strcmp(name, "write_ops")) {
1296 perf_data.write_ops = value;
1297 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1298 } else if (!strcmp(name, "read_latency")) {
1299 perf_data.read_latency = value;
1300 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1301 } else if (!strcmp(name, "write_latency")) {
1302 perf_data.write_latency = value;
1303 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1305 } /* for (elem_counter) */
1307 submit_volume_perf_data(hostname, v, &perf_data, interval);
1308 } /* for (volume) */
1311 } /* }}} int cna_handle_volume_perf_data */
1313 static int cna_setup_volume_perf(cfg_volume_perf_t *cd) /* {{{ */
1320 if (cd->query != NULL)
1323 cd->query = na_elem_new("perf-object-get-instances");
1324 if (cd->query == NULL) {
1325 ERROR("netapp plugin: na_elem_new failed.");
1328 na_child_add_string(cd->query, "objectname", "volume");
1330 e = na_elem_new("counters");
1332 na_elem_free(cd->query);
1334 ERROR("netapp plugin: na_elem_new failed.");
1337 na_child_add_string(e, "counter", "read_ops");
1338 na_child_add_string(e, "counter", "write_ops");
1339 na_child_add_string(e, "counter", "read_data");
1340 na_child_add_string(e, "counter", "write_data");
1341 na_child_add_string(e, "counter", "read_latency");
1342 na_child_add_string(e, "counter", "write_latency");
1343 na_child_add(cd->query, e);
1346 } /* }}} int cna_setup_volume_perf */
1348 static int cna_query_volume_perf(host_config_t *host) /* {{{ */
1357 /* If the user did not configure volume performance statistics, return
1358 * without doing anything. */
1359 if (host->cfg_volume_perf == NULL)
1363 if ((host->cfg_volume_perf->interval.interval +
1364 host->cfg_volume_perf->interval.last_read) > now)
1367 status = cna_setup_volume_perf(host->cfg_volume_perf);
1370 assert(host->cfg_volume_perf->query != NULL);
1372 data = na_server_invoke_elem(host->srv, host->cfg_volume_perf->query);
1373 if (na_results_status(data) != NA_OK) {
1374 ERROR("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed "
1376 host->name, na_results_reason(data));
1382 cna_handle_volume_perf_data(host->name, host->cfg_volume_perf, data,
1383 host->cfg_volume_perf->interval.interval);
1386 host->cfg_volume_perf->interval.last_read = now;
1390 } /* }}} int cna_query_volume_perf */
1392 /* Data corresponding to <VolumeUsage /> */
1393 static int cna_submit_volume_usage_data(const char *hostname, /* {{{ */
1394 cfg_volume_usage_t *cfg_volume,
1396 for (data_volume_usage_t *v = cfg_volume->volumes; v != NULL; v = v->next) {
1397 char plugin_instance[DATA_MAX_NAME_LEN];
1399 uint64_t norm_used = v->norm_used;
1400 uint64_t norm_free = v->norm_free;
1401 uint64_t sis_saved = v->sis_saved;
1402 uint64_t compress_saved = v->compress_saved;
1403 uint64_t dedup_saved = v->dedup_saved;
1404 uint64_t snap_reserve_used = 0;
1405 uint64_t snap_reserve_free = v->snap_reserved;
1406 uint64_t snap_norm_used = v->snap_used;
1408 ssnprintf(plugin_instance, sizeof(plugin_instance), "volume-%s", v->name);
1410 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_SNAP_USED |
1411 HAVE_VOLUME_USAGE_SNAP_RSVD)) {
1412 if (v->snap_reserved > v->snap_used) {
1413 snap_reserve_free = v->snap_reserved - v->snap_used;
1414 snap_reserve_used = v->snap_used;
1417 snap_reserve_free = 0;
1418 snap_reserve_used = v->snap_reserved;
1419 snap_norm_used = v->snap_used - v->snap_reserved;
1423 /* The space used by snapshots but not reserved for them is included in
1424 * both, norm_used and snap_norm_used. If possible, subtract this here. */
1425 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_NORM_USED |
1426 HAVE_VOLUME_USAGE_SNAP_USED)) {
1427 if (norm_used >= snap_norm_used)
1428 norm_used -= snap_norm_used;
1430 ERROR("netapp plugin: (norm_used = %" PRIu64 ") < (snap_norm_used = "
1431 "%" PRIu64 ") for host %s. Invalidating both.",
1432 norm_used, snap_norm_used, hostname);
1434 ~(HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED);
1438 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1439 submit_double(hostname, /* plugin instance = */ plugin_instance,
1440 "df_complex", "free", (double)norm_free,
1441 /* timestamp = */ 0, interval);
1443 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1444 submit_double(hostname, /* plugin instance = */ plugin_instance,
1445 "df_complex", "sis_saved", (double)sis_saved,
1446 /* timestamp = */ 0, interval);
1448 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_COMPRESS_SAVED))
1449 submit_double(hostname, /* plugin instance = */ plugin_instance,
1450 "df_complex", "compression_saved", (double)compress_saved,
1451 /* timestamp = */ 0, interval);
1453 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_DEDUP_SAVED))
1454 submit_double(hostname, /* plugin instance = */ plugin_instance,
1455 "df_complex", "dedup_saved", (double)dedup_saved,
1456 /* timestamp = */ 0, interval);
1458 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1459 submit_double(hostname, /* plugin instance = */ plugin_instance,
1460 "df_complex", "used", (double)norm_used,
1461 /* timestamp = */ 0, interval);
1463 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1464 submit_double(hostname, /* plugin instance = */ plugin_instance,
1465 "df_complex", "snap_reserved", (double)snap_reserve_free,
1466 /* timestamp = */ 0, interval);
1468 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_SNAP_USED |
1469 HAVE_VOLUME_USAGE_SNAP_RSVD))
1470 submit_double(hostname, /* plugin instance = */ plugin_instance,
1471 "df_complex", "snap_reserve_used",
1472 (double)snap_reserve_used, /* timestamp = */ 0, interval);
1474 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1475 submit_double(hostname, /* plugin instance = */ plugin_instance,
1476 "df_complex", "snap_normal_used", (double)snap_norm_used,
1477 /* timestamp = */ 0, interval);
1479 /* Clear all the HAVE_* flags */
1480 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1481 } /* for (v = cfg_volume->volumes) */
1484 } /* }}} int cna_submit_volume_usage_data */
1486 /* Switch the state of a volume between online and offline and send out a
1488 static int cna_change_volume_status(const char *hostname, /* {{{ */
1489 data_volume_usage_t *v) {
1490 notification_t n = {0};
1493 sstrncpy(n.host, hostname, sizeof(n.host));
1494 sstrncpy(n.plugin, "netapp", sizeof(n.plugin));
1495 sstrncpy(n.plugin_instance, v->name, sizeof(n.plugin_instance));
1497 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
1498 n.severity = NOTIF_OKAY;
1499 ssnprintf(n.message, sizeof(n.message), "Volume %s is now online.",
1501 v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
1503 n.severity = NOTIF_WARNING;
1504 ssnprintf(n.message, sizeof(n.message), "Volume %s is now offline.",
1506 v->flags |= IS_VOLUME_USAGE_OFFLINE;
1509 return plugin_dispatch_notification(&n);
1510 } /* }}} int cna_change_volume_status */
1512 static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
1513 data_volume_usage_t *v) {
1514 uint64_t snap_used = 0, value;
1515 na_elem_t *data, *elem_snapshots;
1516 na_elem_iter_t iter_snap;
1518 data = na_server_invoke_elem(host->srv, v->snap_query);
1519 if (na_results_status(data) != NA_OK) {
1520 if (na_results_errno(data) == EVOLUMEOFFLINE) {
1521 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
1522 cna_change_volume_status(host->name, v);
1524 ERROR("netapp plugin: cna_handle_volume_snap_usage: "
1525 "na_server_invoke_elem for "
1526 "volume \"%s\" on host %s failed with error %d: %s",
1527 v->name, host->name, na_results_errno(data),
1528 na_results_reason(data));
1534 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0)
1535 cna_change_volume_status(host->name, v);
1537 elem_snapshots = na_elem_child(data, "snapshots");
1538 if (elem_snapshots == NULL) {
1539 ERROR("netapp plugin: cna_handle_volume_snap_usage: "
1540 "na_elem_child (\"snapshots\") failed "
1547 iter_snap = na_child_iterator(elem_snapshots);
1548 for (na_elem_t *elem_snap = na_iterator_next(&iter_snap); elem_snap != NULL;
1549 elem_snap = na_iterator_next(&iter_snap)) {
1550 value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
1551 /* "cumulative-total" is the total size of the oldest snapshot plus all
1552 * newer ones in blocks (1KB). We therefore are looking for the highest
1553 * number of all snapshots - that's the size required for the snapshots. */
1554 if (value > snap_used)
1558 /* snap_used is in 1024 byte blocks */
1559 v->snap_used = snap_used * 1024;
1560 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1561 } /* }}} void cna_handle_volume_snap_usage */
1563 static void cna_handle_volume_sis_data(const host_config_t *host, /* {{{ */
1564 data_volume_usage_t *v, na_elem_t *sis) {
1565 const char *sis_state;
1566 uint64_t sis_saved_reported;
1568 if (na_elem_child(sis, "sis-info"))
1569 sis = na_elem_child(sis, "sis-info");
1571 sis_state = na_child_get_string(sis, "state");
1572 if (sis_state == NULL)
1575 /* If SIS is not enabled, there's nothing left to do for this volume. */
1576 if (strcmp("enabled", sis_state) != 0)
1579 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1580 if (sis_saved_reported == UINT64_MAX)
1583 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1584 if ((sis_saved_reported >> 32) != 0) {
1585 /* In case they ever fix this bug. */
1586 v->sis_saved = sis_saved_reported;
1587 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1588 } else { /* really hacky work-around code. {{{ */
1589 uint64_t sis_saved_percent;
1590 uint64_t sis_saved_guess;
1591 uint64_t overflow_guess;
1592 uint64_t guess1, guess2, guess3;
1594 /* Check if we have v->norm_used. Without it, we cannot calculate
1595 * sis_saved_guess. */
1596 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1600 na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1601 if (sis_saved_percent > 100)
1604 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1605 * will hopefully be fixed in later versions. To work around the bug, try
1606 * to figure out how often the 32bit integer wrapped around by using the
1607 * "percentage-saved" value. Because the percentage is in the range
1608 * [0-100], this should work as long as the saved space does not exceed
1610 /* percentage-saved = size-saved / (size-saved + size-used) */
1611 if (sis_saved_percent < 100)
1613 v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1615 sis_saved_guess = v->norm_used;
1617 overflow_guess = sis_saved_guess >> 32;
1618 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported
1619 : sis_saved_reported;
1620 guess2 = (overflow_guess << 32) + sis_saved_reported;
1621 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1623 if (sis_saved_guess < guess2) {
1624 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1625 v->sis_saved = guess1;
1627 v->sis_saved = guess2;
1629 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1630 v->sis_saved = guess2;
1632 v->sis_saved = guess3;
1634 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1635 } /* }}} end of 32-bit workaround */
1636 } /* }}} void cna_handle_volume_sis_data */
1638 /* ONTAP >= 8.1 uses SIS for managing dedup and compression */
1639 static void cna_handle_volume_sis_saved(const host_config_t *host, /* {{{ */
1640 data_volume_usage_t *v,
1644 if (na_elem_child(sis, "sis-info"))
1645 sis = na_elem_child(sis, "sis-info");
1647 saved = na_child_get_uint64(sis, "compress-saved", UINT64_MAX);
1648 if (saved != UINT64_MAX) {
1649 v->compress_saved = saved;
1650 v->flags |= HAVE_VOLUME_USAGE_COMPRESS_SAVED;
1653 saved = na_child_get_uint64(sis, "dedup-saved", UINT64_MAX);
1654 if (saved != UINT64_MAX) {
1655 v->dedup_saved = saved;
1656 v->flags |= HAVE_VOLUME_USAGE_DEDUP_SAVED;
1658 } /* }}} void cna_handle_volume_sis_saved */
1660 static int cna_handle_volume_usage_data(const host_config_t *host, /* {{{ */
1661 cfg_volume_usage_t *cfg_volume,
1663 na_elem_t *elem_volumes;
1664 na_elem_iter_t iter_volume;
1666 elem_volumes = na_elem_child(data, "volumes");
1667 if (elem_volumes == NULL) {
1668 ERROR("netapp plugin: cna_handle_volume_usage_data: "
1669 "na_elem_child (\"volumes\") failed "
1675 iter_volume = na_child_iterator(elem_volumes);
1676 for (na_elem_t *elem_volume = na_iterator_next(&iter_volume);
1677 elem_volume != NULL; elem_volume = na_iterator_next(&iter_volume)) {
1678 const char *volume_name, *state;
1680 data_volume_usage_t *v;
1685 volume_name = na_child_get_string(elem_volume, "name");
1686 if (volume_name == NULL)
1689 state = na_child_get_string(elem_volume, "state");
1690 if ((state == NULL) || (strcmp(state, "online") != 0))
1693 /* get_volume_usage may return NULL if the volume is to be ignored. */
1694 v = get_volume_usage(cfg_volume, volume_name);
1698 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1699 cna_handle_volume_snap_usage(host, v);
1701 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1704 /* 2^4 exa-bytes? This will take a while ;) */
1705 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1706 if (value != UINT64_MAX) {
1707 v->norm_free = value;
1708 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1711 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1712 if (value != UINT64_MAX) {
1713 v->norm_used = value;
1714 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1717 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved",
1719 if (value != UINT64_MAX) {
1720 /* 1 block == 1024 bytes as per API docs */
1721 v->snap_reserved = 1024 * value;
1722 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1725 sis = na_elem_child(elem_volume, "sis");
1727 cna_handle_volume_sis_data(host, v, sis);
1728 cna_handle_volume_sis_saved(host, v, sis);
1730 } /* for (elem_volume) */
1732 return cna_submit_volume_usage_data(
1733 host->name, cfg_volume, host->cfg_volume_usage->interval.interval);
1734 } /* }}} int cna_handle_volume_usage_data */
1736 static int cna_setup_volume_usage(cfg_volume_usage_t *cvu) /* {{{ */
1741 if (cvu->query != NULL)
1744 cvu->query = na_elem_new("volume-list-info");
1745 if (cvu->query == NULL) {
1746 ERROR("netapp plugin: na_elem_new failed.");
1751 } /* }}} int cna_setup_volume_usage */
1753 static int cna_query_volume_usage(host_config_t *host) /* {{{ */
1762 /* If the user did not configure volume_usage statistics, return without
1763 * doing anything. */
1764 if (host->cfg_volume_usage == NULL)
1768 if ((host->cfg_volume_usage->interval.interval +
1769 host->cfg_volume_usage->interval.last_read) > now)
1772 status = cna_setup_volume_usage(host->cfg_volume_usage);
1775 assert(host->cfg_volume_usage->query != NULL);
1777 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1778 if (na_results_status(data) != NA_OK) {
1779 ERROR("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed "
1781 host->name, na_results_reason(data));
1786 status = cna_handle_volume_usage_data(host, host->cfg_volume_usage, data);
1789 host->cfg_volume_usage->interval.last_read = now;
1793 } /* }}} int cna_query_volume_usage */
1795 /* Data corresponding to <Quota /> */
1796 static int cna_handle_quota_data(const host_config_t *host, /* {{{ */
1797 cfg_quota_t *cfg_quota, na_elem_t *data) {
1798 na_elem_t *elem_quotas;
1799 na_elem_iter_t iter_quota;
1801 elem_quotas = na_elem_child(data, "quotas");
1802 if (elem_quotas == NULL) {
1803 ERROR("netapp plugin: cna_handle_quota_data: "
1804 "na_elem_child (\"quotas\") failed "
1810 iter_quota = na_child_iterator(elem_quotas);
1811 for (na_elem_t *elem_quota = na_iterator_next(&iter_quota);
1812 elem_quota != NULL; elem_quota = na_iterator_next(&iter_quota)) {
1813 const char *quota_type, *volume_name, *tree_name;
1816 char plugin_instance[DATA_MAX_NAME_LEN];
1818 quota_type = na_child_get_string(elem_quota, "quota-type");
1819 if (quota_type == NULL)
1822 /* possible TODO: support other types as well */
1823 if (strcmp(quota_type, "tree") != 0)
1826 tree_name = na_child_get_string(elem_quota, "tree");
1827 if ((tree_name == NULL) || (*tree_name == '\0'))
1830 volume_name = na_child_get_string(elem_quota, "volume");
1831 if (volume_name == NULL)
1834 ssnprintf(plugin_instance, sizeof(plugin_instance), "quota-%s-%s",
1835 volume_name, tree_name);
1837 value = na_child_get_uint64(elem_quota, "disk-used", UINT64_MAX);
1838 if (value != UINT64_MAX) {
1839 value *= 1024; /* disk-used reports kilobytes */
1840 submit_double(host->name, plugin_instance,
1841 /* type = */ "df_complex", /* type instance = */ NULL,
1842 (double)value, /* timestamp = */ 0,
1843 host->cfg_quota->interval.interval);
1846 value = na_child_get_uint64(elem_quota, "files-used", UINT64_MAX);
1847 if (value != UINT64_MAX) {
1848 submit_double(host->name, plugin_instance,
1849 /* type = */ "files", /* type instance = */ NULL,
1850 (double)value, /* timestamp = */ 0,
1851 host->cfg_quota->interval.interval);
1853 } /* for (elem_quota) */
1856 } /* }}} int cna_handle_volume_usage_data */
1858 static int cna_setup_quota(cfg_quota_t *cq) /* {{{ */
1863 if (cq->query != NULL)
1866 cq->query = na_elem_new("quota-report");
1867 if (cq->query == NULL) {
1868 ERROR("netapp plugin: na_elem_new failed.");
1873 } /* }}} int cna_setup_quota */
1875 static int cna_query_quota(host_config_t *host) /* {{{ */
1884 /* If the user did not configure quota statistics, return without
1885 * doing anything. */
1886 if (host->cfg_quota == NULL)
1890 if ((host->cfg_quota->interval.interval +
1891 host->cfg_quota->interval.last_read) > now)
1894 status = cna_setup_quota(host->cfg_quota);
1897 assert(host->cfg_quota->query != NULL);
1899 data = na_server_invoke_elem(host->srv, host->cfg_quota->query);
1900 if (na_results_status(data) != NA_OK) {
1901 ERROR("netapp plugin: cna_query_quota: na_server_invoke_elem failed for "
1903 host->name, na_results_reason(data));
1908 status = cna_handle_quota_data(host, host->cfg_quota, data);
1911 host->cfg_quota->interval.last_read = now;
1915 } /* }}} int cna_query_quota */
1917 /* Data corresponding to <SnapVault /> */
1918 static int cna_handle_snapvault_data(const char *hostname, /* {{{ */
1919 cfg_snapvault_t *cfg_snapvault,
1920 na_elem_t *data, cdtime_t interval) {
1921 na_elem_t *status_list = na_elem_child(data, "status-list");
1922 if (status_list == NULL) {
1923 ERROR("netapp plugin: SnapVault status record missing status-list");
1927 na_elem_iter_t status_iter = na_child_iterator(status_list);
1928 for (na_elem_t *status = na_iterator_next(&status_iter); status != NULL;
1929 status = na_iterator_next(&status_iter)) {
1930 const char *dest_sys, *dest_path, *src_sys, *src_path;
1931 char plugin_instance[DATA_MAX_NAME_LEN];
1934 dest_sys = na_child_get_string(status, "destination-system");
1935 dest_path = na_child_get_string(status, "destination-path");
1936 src_sys = na_child_get_string(status, "source-system");
1937 src_path = na_child_get_string(status, "source-path");
1939 if ((!dest_sys) || (!dest_path) || (!src_sys) || (!src_path))
1942 value = na_child_get_uint64(status, "lag-time", UINT64_MAX);
1943 if (value == UINT64_MAX) /* no successful baseline transfer yet */
1946 /* possible TODO: make plugin instance configurable */
1947 ssnprintf(plugin_instance, sizeof(plugin_instance), "snapvault-%s",
1949 submit_double(hostname, plugin_instance, /* type = */ "delay", NULL,
1950 (double)value, /* timestamp = */ 0, interval);
1952 value = na_child_get_uint64(status, "last-transfer-duration", UINT64_MAX);
1953 if (value != UINT64_MAX)
1954 submit_double(hostname, plugin_instance, /* type = */ "duration",
1955 "last_transfer", (double)value, /* timestamp = */ 0,
1958 value = na_child_get_uint64(status, "transfer-progress", UINT64_MAX);
1959 if (value == UINT64_MAX)
1960 value = na_child_get_uint64(status, "last-transfer-size", UINT64_MAX);
1961 if (value != UINT64_MAX) {
1962 value *= 1024; /* this is kilobytes */
1963 submit_derive(hostname, plugin_instance, /* type = */ "if_rx_octets",
1964 "transferred", value, /* timestamp = */ 0, interval);
1966 } /* for (status) */
1969 } /* }}} int cna_handle_snapvault_data */
1971 static int cna_handle_snapvault_iter(host_config_t *host, /* {{{ */
1975 uint32_t records_count;
1977 records_count = na_child_get_uint32(data, "records", UINT32_MAX);
1978 if (records_count == UINT32_MAX)
1981 tag = na_child_get_string(data, "tag");
1985 DEBUG("netapp plugin: Iterating %u SV records (tag = %s)", records_count,
1988 for (uint32_t i = 0; i < records_count; ++i) {
1991 elem = na_server_invoke(
1992 host->srv, "snapvault-secondary-relationship-status-list-iter-next",
1993 "maximum", "1", "tag", tag, NULL);
1995 if (na_results_status(elem) != NA_OK) {
1996 ERROR("netapp plugin: cna_handle_snapvault_iter: "
1997 "na_server_invoke failed for host %s: %s",
1998 host->name, na_results_reason(data));
2003 cna_handle_snapvault_data(host->name, host->cfg_snapvault, elem,
2004 host->cfg_snapvault->interval.interval);
2008 na_elem_free(na_server_invoke(
2009 host->srv, "snapvault-secondary-relationship-status-list-iter-end", "tag",
2012 } /* }}} int cna_handle_snapvault_iter */
2014 static int cna_setup_snapvault(cfg_snapvault_t *sv) /* {{{ */
2019 if (sv->query != NULL)
2023 na_elem_new("snapvault-secondary-relationship-status-list-iter-start");
2024 if (sv->query == NULL) {
2025 ERROR("netapp plugin: na_elem_new failed.");
2030 } /* }}} int cna_setup_snapvault */
2032 static int cna_query_snapvault(host_config_t *host) /* {{{ */
2041 if (host->cfg_snapvault == NULL)
2045 if ((host->cfg_snapvault->interval.interval +
2046 host->cfg_snapvault->interval.last_read) > now)
2049 status = cna_setup_snapvault(host->cfg_snapvault);
2052 assert(host->cfg_snapvault->query != NULL);
2054 data = na_server_invoke_elem(host->srv, host->cfg_snapvault->query);
2055 if (na_results_status(data) != NA_OK) {
2056 ERROR("netapp plugin: cna_query_snapvault: na_server_invoke_elem failed "
2058 host->name, na_results_reason(data));
2063 status = cna_handle_snapvault_iter(host, data);
2066 host->cfg_snapvault->interval.last_read = now;
2070 } /* }}} int cna_query_snapvault */
2072 /* Data corresponding to <System /> */
2073 static int cna_handle_system_data(const char *hostname, /* {{{ */
2074 cfg_system_t *cfg_system, na_elem_t *data,
2076 na_elem_t *instances;
2077 na_elem_iter_t counter_iter;
2079 derive_t disk_read = 0, disk_written = 0;
2080 derive_t net_recv = 0, net_sent = 0;
2081 derive_t cpu_busy = 0, cpu_total = 0;
2082 uint32_t counter_flags = 0;
2084 const char *instance;
2087 timestamp = cna_child_get_cdtime(data);
2089 instances = na_elem_child(na_elem_child(data, "instances"), "instance-data");
2090 if (instances == NULL) {
2091 ERROR("netapp plugin: cna_handle_system_data: "
2092 "na_elem_child (\"instances\") failed "
2098 instance = na_child_get_string(instances, "name");
2099 if (instance == NULL) {
2100 ERROR("netapp plugin: cna_handle_system_data: "
2101 "na_child_get_string (\"name\") failed "
2107 counter_iter = na_child_iterator(na_elem_child(instances, "counters"));
2108 for (na_elem_t *counter = na_iterator_next(&counter_iter); counter != NULL;
2109 counter = na_iterator_next(&counter_iter)) {
2113 name = na_child_get_string(counter, "name");
2117 value = na_child_get_uint64(counter, "value", UINT64_MAX);
2118 if (value == UINT64_MAX)
2121 if (!strcmp(name, "disk_data_read")) {
2122 disk_read = (derive_t)(value * 1024);
2123 counter_flags |= 0x01;
2124 } else if (!strcmp(name, "disk_data_written")) {
2125 disk_written = (derive_t)(value * 1024);
2126 counter_flags |= 0x02;
2127 } else if (!strcmp(name, "net_data_recv")) {
2128 net_recv = (derive_t)(value * 1024);
2129 counter_flags |= 0x04;
2130 } else if (!strcmp(name, "net_data_sent")) {
2131 net_sent = (derive_t)(value * 1024);
2132 counter_flags |= 0x08;
2133 } else if (!strcmp(name, "cpu_busy")) {
2134 cpu_busy = (derive_t)value;
2135 counter_flags |= 0x10;
2136 } else if (!strcmp(name, "cpu_elapsed_time")) {
2137 cpu_total = (derive_t)value;
2138 counter_flags |= 0x20;
2139 } else if ((cfg_system->flags & CFG_SYSTEM_OPS) && (value > 0) &&
2140 (strlen(name) > 4) &&
2141 (!strcmp(name + strlen(name) - 4, "_ops"))) {
2142 submit_derive(hostname, instance, "disk_ops_complex", name,
2143 (derive_t)value, timestamp, interval);
2145 } /* for (counter) */
2147 if ((cfg_system->flags & CFG_SYSTEM_DISK) &&
2148 (HAS_ALL_FLAGS(counter_flags, 0x01 | 0x02)))
2149 submit_two_derive(hostname, instance, "disk_octets", NULL, disk_read,
2150 disk_written, timestamp, interval);
2152 if ((cfg_system->flags & CFG_SYSTEM_NET) &&
2153 (HAS_ALL_FLAGS(counter_flags, 0x04 | 0x08)))
2154 submit_two_derive(hostname, instance, "if_octets", NULL, net_recv, net_sent,
2155 timestamp, interval);
2157 if ((cfg_system->flags & CFG_SYSTEM_CPU) &&
2158 (HAS_ALL_FLAGS(counter_flags, 0x10 | 0x20))) {
2159 submit_derive(hostname, instance, "cpu", "system", cpu_busy, timestamp,
2161 submit_derive(hostname, instance, "cpu", "idle", cpu_total - cpu_busy,
2162 timestamp, interval);
2166 } /* }}} int cna_handle_system_data */
2168 static int cna_setup_system(cfg_system_t *cs) /* {{{ */
2173 if (cs->query != NULL)
2176 cs->query = na_elem_new("perf-object-get-instances");
2177 if (cs->query == NULL) {
2178 ERROR("netapp plugin: na_elem_new failed.");
2181 na_child_add_string(cs->query, "objectname", "system");
2184 } /* }}} int cna_setup_system */
2186 static int cna_query_system(host_config_t *host) /* {{{ */
2195 /* If system statistics were not configured, return without doing anything. */
2196 if (host->cfg_system == NULL)
2200 if ((host->cfg_system->interval.interval +
2201 host->cfg_system->interval.last_read) > now)
2204 status = cna_setup_system(host->cfg_system);
2207 assert(host->cfg_system->query != NULL);
2209 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
2210 if (na_results_status(data) != NA_OK) {
2211 ERROR("netapp plugin: cna_query_system: na_server_invoke_elem failed for "
2213 host->name, na_results_reason(data));
2218 status = cna_handle_system_data(host->name, host->cfg_system, data,
2219 host->cfg_system->interval.interval);
2222 host->cfg_system->interval.last_read = now;
2226 } /* }}} int cna_query_system */
2229 * Configuration handling
2232 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
2233 * <VolumePerf /> block. */
2234 static void cna_config_volume_perf_option(cfg_volume_perf_t *cvp, /* {{{ */
2235 const oconfig_item_t *ci) {
2239 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2241 "netapp plugin: The %s option requires exactly one string argument.",
2246 name = ci->values[0].value.string;
2248 if (strcasecmp("GetIO", ci->key) == 0)
2249 il = cvp->il_octets;
2250 else if (strcasecmp("GetOps", ci->key) == 0)
2251 il = cvp->il_operations;
2252 else if (strcasecmp("GetLatency", ci->key) == 0)
2253 il = cvp->il_latency;
2257 ignorelist_add(il, name);
2258 } /* }}} void cna_config_volume_perf_option */
2260 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
2261 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
2262 static void cna_config_volume_perf_default(cfg_volume_perf_t *cvp, /* {{{ */
2263 const oconfig_item_t *ci) {
2266 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
2268 "netapp plugin: The %s option requires exactly one string argument.",
2273 if (strcasecmp("IgnoreSelectedIO", ci->key) == 0)
2274 il = cvp->il_octets;
2275 else if (strcasecmp("IgnoreSelectedOps", ci->key) == 0)
2276 il = cvp->il_operations;
2277 else if (strcasecmp("IgnoreSelectedLatency", ci->key) == 0)
2278 il = cvp->il_latency;
2282 if (ci->values[0].value.boolean)
2283 ignorelist_set_invert(il, /* invert = */ 0);
2285 ignorelist_set_invert(il, /* invert = */ 1);
2286 } /* }}} void cna_config_volume_perf_default */
2288 /* Corresponds to a <Disks /> block */
2293 * IgnoreSelectedIO false
2297 * IgnoreSelectedOps false
2301 * IgnoreSelectedLatency false
2304 /* Corresponds to a <VolumePerf /> block */
2305 static int cna_config_volume_performance(host_config_t *host, /* {{{ */
2306 const oconfig_item_t *ci) {
2307 cfg_volume_perf_t *cfg_volume_perf;
2309 if ((host == NULL) || (ci == NULL))
2312 if (host->cfg_volume_perf == NULL) {
2313 cfg_volume_perf = calloc(1, sizeof(*cfg_volume_perf));
2314 if (cfg_volume_perf == NULL)
2317 /* Set default flags */
2318 cfg_volume_perf->query = NULL;
2319 cfg_volume_perf->volumes = NULL;
2321 cfg_volume_perf->il_octets = ignorelist_create(/* invert = */ 1);
2322 if (cfg_volume_perf->il_octets == NULL) {
2323 sfree(cfg_volume_perf);
2327 cfg_volume_perf->il_operations = ignorelist_create(/* invert = */ 1);
2328 if (cfg_volume_perf->il_operations == NULL) {
2329 ignorelist_free(cfg_volume_perf->il_octets);
2330 sfree(cfg_volume_perf);
2334 cfg_volume_perf->il_latency = ignorelist_create(/* invert = */ 1);
2335 if (cfg_volume_perf->il_latency == NULL) {
2336 ignorelist_free(cfg_volume_perf->il_octets);
2337 ignorelist_free(cfg_volume_perf->il_operations);
2338 sfree(cfg_volume_perf);
2342 host->cfg_volume_perf = cfg_volume_perf;
2344 cfg_volume_perf = host->cfg_volume_perf;
2346 for (int i = 0; i < ci->children_num; ++i) {
2347 oconfig_item_t *item = ci->children + i;
2349 /* if (!item || !item->key || !*item->key) continue; */
2350 if (strcasecmp(item->key, "Interval") == 0)
2351 cf_util_get_cdtime(item, &cfg_volume_perf->interval.interval);
2352 else if (!strcasecmp(item->key, "GetIO"))
2353 cna_config_volume_perf_option(cfg_volume_perf, item);
2354 else if (!strcasecmp(item->key, "GetOps"))
2355 cna_config_volume_perf_option(cfg_volume_perf, item);
2356 else if (!strcasecmp(item->key, "GetLatency"))
2357 cna_config_volume_perf_option(cfg_volume_perf, item);
2358 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
2359 cna_config_volume_perf_default(cfg_volume_perf, item);
2360 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
2361 cna_config_volume_perf_default(cfg_volume_perf, item);
2362 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2363 cna_config_volume_perf_default(cfg_volume_perf, item);
2365 WARNING("netapp plugin: The option %s is not allowed within "
2366 "`VolumePerf' blocks.",
2371 } /* }}} int cna_config_volume_performance */
2373 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2374 * <VolumeUsage /> block. */
2375 static void cna_config_volume_usage_option(cfg_volume_usage_t *cvu, /* {{{ */
2376 const oconfig_item_t *ci) {
2380 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2382 "netapp plugin: The %s option requires exactly one string argument.",
2387 name = ci->values[0].value.string;
2389 if (strcasecmp("GetCapacity", ci->key) == 0)
2390 il = cvu->il_capacity;
2391 else if (strcasecmp("GetSnapshot", ci->key) == 0)
2392 il = cvu->il_snapshot;
2396 ignorelist_add(il, name);
2397 } /* }}} void cna_config_volume_usage_option */
2399 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2400 * options within a <VolumeUsage /> block. */
2401 static void cna_config_volume_usage_default(cfg_volume_usage_t *cvu, /* {{{ */
2402 const oconfig_item_t *ci) {
2405 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
2407 "netapp plugin: The %s option requires exactly one string argument.",
2412 if (strcasecmp("IgnoreSelectedCapacity", ci->key) == 0)
2413 il = cvu->il_capacity;
2414 else if (strcasecmp("IgnoreSelectedSnapshot", ci->key) == 0)
2415 il = cvu->il_snapshot;
2419 if (ci->values[0].value.boolean)
2420 ignorelist_set_invert(il, /* invert = */ 0);
2422 ignorelist_set_invert(il, /* invert = */ 1);
2423 } /* }}} void cna_config_volume_usage_default */
2425 /* Corresponds to a <Quota /> block */
2426 static int cna_config_quota(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2428 cfg_quota_t *cfg_quota;
2430 if ((host == NULL) || (ci == NULL))
2433 if (host->cfg_quota == NULL) {
2434 cfg_quota = calloc(1, sizeof(*cfg_quota));
2435 if (cfg_quota == NULL)
2437 cfg_quota->query = NULL;
2439 host->cfg_quota = cfg_quota;
2441 cfg_quota = host->cfg_quota;
2443 for (int i = 0; i < ci->children_num; ++i) {
2444 oconfig_item_t *item = ci->children + i;
2446 if (strcasecmp(item->key, "Interval") == 0)
2447 cf_util_get_cdtime(item, &cfg_quota->interval.interval);
2449 WARNING("netapp plugin: The option %s is not allowed within "
2455 } /* }}} int cna_config_quota */
2457 /* Corresponds to a <Disks /> block */
2458 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2459 cfg_disk_t *cfg_disk;
2461 if ((host == NULL) || (ci == NULL))
2464 if (host->cfg_disk == NULL) {
2465 cfg_disk = calloc(1, sizeof(*cfg_disk));
2466 if (cfg_disk == NULL)
2469 /* Set default flags */
2470 cfg_disk->flags = CFG_DISK_ALL;
2471 cfg_disk->query = NULL;
2472 cfg_disk->disks = NULL;
2474 host->cfg_disk = cfg_disk;
2476 cfg_disk = host->cfg_disk;
2478 for (int i = 0; i < ci->children_num; ++i) {
2479 oconfig_item_t *item = ci->children + i;
2481 /* if (!item || !item->key || !*item->key) continue; */
2482 if (strcasecmp(item->key, "Interval") == 0)
2483 cf_util_get_cdtime(item, &cfg_disk->interval.interval);
2484 else if (strcasecmp(item->key, "GetBusy") == 0)
2485 cf_util_get_flag(item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2488 if ((cfg_disk->flags & CFG_DISK_ALL) == 0) {
2489 NOTICE("netapp plugin: All disk related values have been disabled. "
2490 "Collection of per-disk data will be disabled entirely.");
2491 free_cfg_disk(host->cfg_disk);
2492 host->cfg_disk = NULL;
2496 } /* }}} int cna_config_disk */
2498 /* Corresponds to a <WAFL /> block */
2499 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2501 cfg_wafl_t *cfg_wafl;
2503 if ((host == NULL) || (ci == NULL))
2506 if (host->cfg_wafl == NULL) {
2507 cfg_wafl = calloc(1, sizeof(*cfg_wafl));
2508 if (cfg_wafl == NULL)
2511 /* Set default flags */
2512 cfg_wafl->flags = CFG_WAFL_ALL;
2514 host->cfg_wafl = cfg_wafl;
2516 cfg_wafl = host->cfg_wafl;
2518 for (int i = 0; i < ci->children_num; ++i) {
2519 oconfig_item_t *item = ci->children + i;
2521 if (strcasecmp(item->key, "Interval") == 0)
2522 cf_util_get_cdtime(item, &cfg_wafl->interval.interval);
2523 else if (!strcasecmp(item->key, "GetNameCache"))
2524 cf_util_get_flag(item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2525 else if (!strcasecmp(item->key, "GetDirCache"))
2526 cf_util_get_flag(item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2527 else if (!strcasecmp(item->key, "GetBufferCache"))
2528 cf_util_get_flag(item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2529 else if (!strcasecmp(item->key, "GetInodeCache"))
2530 cf_util_get_flag(item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2532 WARNING("netapp plugin: The %s config option is not allowed within "
2537 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0) {
2538 NOTICE("netapp plugin: All WAFL related values have been disabled. "
2539 "Collection of WAFL data will be disabled entirely.");
2540 free_cfg_wafl(host->cfg_wafl);
2541 host->cfg_wafl = NULL;
2545 } /* }}} int cna_config_wafl */
2549 * GetCapacity "vol0"
2550 * GetCapacity "vol1"
2551 * GetCapacity "vol2"
2552 * GetCapacity "vol3"
2553 * GetCapacity "vol4"
2554 * IgnoreSelectedCapacity false
2556 * GetSnapshot "vol0"
2557 * GetSnapshot "vol3"
2558 * GetSnapshot "vol4"
2559 * GetSnapshot "vol7"
2560 * IgnoreSelectedSnapshot false
2563 /* Corresponds to a <VolumeUsage /> block */
2564 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2565 const oconfig_item_t *ci) {
2566 cfg_volume_usage_t *cfg_volume_usage;
2568 if ((host == NULL) || (ci == NULL))
2571 if (host->cfg_volume_usage == NULL) {
2572 cfg_volume_usage = calloc(1, sizeof(*cfg_volume_usage));
2573 if (cfg_volume_usage == NULL)
2576 /* Set default flags */
2577 cfg_volume_usage->query = NULL;
2578 cfg_volume_usage->volumes = NULL;
2580 cfg_volume_usage->il_capacity = ignorelist_create(/* invert = */ 1);
2581 if (cfg_volume_usage->il_capacity == NULL) {
2582 sfree(cfg_volume_usage);
2586 cfg_volume_usage->il_snapshot = ignorelist_create(/* invert = */ 1);
2587 if (cfg_volume_usage->il_snapshot == NULL) {
2588 ignorelist_free(cfg_volume_usage->il_capacity);
2589 sfree(cfg_volume_usage);
2593 host->cfg_volume_usage = cfg_volume_usage;
2595 cfg_volume_usage = host->cfg_volume_usage;
2597 for (int i = 0; i < ci->children_num; ++i) {
2598 oconfig_item_t *item = ci->children + i;
2600 /* if (!item || !item->key || !*item->key) continue; */
2601 if (strcasecmp(item->key, "Interval") == 0)
2602 cf_util_get_cdtime(item, &cfg_volume_usage->interval.interval);
2603 else if (!strcasecmp(item->key, "GetCapacity"))
2604 cna_config_volume_usage_option(cfg_volume_usage, item);
2605 else if (!strcasecmp(item->key, "GetSnapshot"))
2606 cna_config_volume_usage_option(cfg_volume_usage, item);
2607 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2608 cna_config_volume_usage_default(cfg_volume_usage, item);
2609 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2610 cna_config_volume_usage_default(cfg_volume_usage, item);
2612 WARNING("netapp plugin: The option %s is not allowed within "
2613 "`VolumeUsage' blocks.",
2618 } /* }}} int cna_config_volume_usage */
2620 /* Corresponds to a <SnapVault /> block */
2621 static int cna_config_snapvault(host_config_t *host, /* {{{ */
2622 const oconfig_item_t *ci) {
2623 cfg_snapvault_t *cfg_snapvault;
2625 if ((host == NULL) || (ci == NULL))
2628 if (host->cfg_snapvault == NULL) {
2629 cfg_snapvault = calloc(1, sizeof(*cfg_snapvault));
2630 if (cfg_snapvault == NULL)
2632 cfg_snapvault->query = NULL;
2634 host->cfg_snapvault = cfg_snapvault;
2637 cfg_snapvault = host->cfg_snapvault;
2639 for (int i = 0; i < ci->children_num; ++i) {
2640 oconfig_item_t *item = ci->children + i;
2642 if (strcasecmp(item->key, "Interval") == 0)
2643 cf_util_get_cdtime(item, &cfg_snapvault->interval.interval);
2645 WARNING("netapp plugin: The option %s is not allowed within "
2646 "`SnapVault' blocks.",
2651 } /* }}} int cna_config_snapvault */
2653 /* Corresponds to a <System /> block */
2654 static int cna_config_system(host_config_t *host, /* {{{ */
2655 oconfig_item_t *ci) {
2656 cfg_system_t *cfg_system;
2658 if ((host == NULL) || (ci == NULL))
2661 if (host->cfg_system == NULL) {
2662 cfg_system = calloc(1, sizeof(*cfg_system));
2663 if (cfg_system == NULL)
2666 /* Set default flags */
2667 cfg_system->flags = CFG_SYSTEM_ALL;
2668 cfg_system->query = NULL;
2670 host->cfg_system = cfg_system;
2672 cfg_system = host->cfg_system;
2674 for (int i = 0; i < ci->children_num; ++i) {
2675 oconfig_item_t *item = ci->children + i;
2677 if (strcasecmp(item->key, "Interval") == 0) {
2678 cf_util_get_cdtime(item, &cfg_system->interval.interval);
2679 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2680 cf_util_get_flag(item, &cfg_system->flags, CFG_SYSTEM_CPU);
2681 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2682 cf_util_get_flag(item, &cfg_system->flags, CFG_SYSTEM_NET);
2683 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2684 cf_util_get_flag(item, &cfg_system->flags, CFG_SYSTEM_OPS);
2685 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2686 cf_util_get_flag(item, &cfg_system->flags, CFG_SYSTEM_DISK);
2688 WARNING("netapp plugin: The %s config option is not allowed within "
2694 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0) {
2695 NOTICE("netapp plugin: All system related values have been disabled. "
2696 "Collection of system data will be disabled entirely.");
2697 free_cfg_system(host->cfg_system);
2698 host->cfg_system = NULL;
2702 } /* }}} int cna_config_system */
2704 /* Corresponds to a <Host /> block. */
2705 static host_config_t *cna_alloc_host(void) /* {{{ */
2707 host_config_t *host;
2709 host = calloc(1, sizeof(*host));
2714 host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2716 host->username = NULL;
2717 host->password = NULL;
2718 host->vfiler = NULL;
2720 host->cfg_wafl = NULL;
2721 host->cfg_disk = NULL;
2722 host->cfg_volume_perf = NULL;
2723 host->cfg_volume_usage = NULL;
2724 host->cfg_quota = NULL;
2725 host->cfg_snapvault = NULL;
2726 host->cfg_system = NULL;
2729 } /* }}} host_config_t *cna_alloc_host */
2731 static host_config_t *cna_shallow_clone_host(host_config_t *host) /* {{{ */
2733 host_config_t *clone;
2738 clone = cna_alloc_host();
2742 if (host->name != NULL) {
2743 clone->name = strdup(host->name);
2744 if (clone->name == NULL) {
2745 free_host_config(clone);
2750 clone->protocol = host->protocol;
2752 if (host->host != NULL) {
2753 clone->host = strdup(host->host);
2754 if (clone->host == NULL) {
2755 free_host_config(clone);
2760 clone->port = host->port;
2762 if (host->username != NULL) {
2763 clone->username = strdup(host->username);
2764 if (clone->username == NULL) {
2765 free_host_config(clone);
2769 if (host->password != NULL) {
2770 clone->password = strdup(host->password);
2771 if (clone->password == NULL) {
2772 free_host_config(clone);
2777 clone->interval = host->interval;
2780 } /* }}} host_config_t *cna_shallow_clone_host */
2782 static int cna_read(user_data_t *ud);
2784 static int cna_register_host(host_config_t *host) /* {{{ */
2789 ssnprintf(cb_name, sizeof(cb_name), "netapp-%s-%s", host->name,
2792 ssnprintf(cb_name, sizeof(cb_name), "netapp-%s", host->name);
2794 plugin_register_complex_read(
2795 /* group = */ NULL, cb_name,
2796 /* callback = */ cna_read,
2797 /* interval = */ host->interval,
2800 .free_func = (void *)free_host_config,
2804 } /* }}} int cna_register_host */
2806 static int cna_config_host(host_config_t *host, /* {{{ */
2807 const oconfig_item_t *ci) {
2808 oconfig_item_t *item;
2809 bool is_vfiler = false;
2812 if (!strcasecmp(ci->key, "VFiler"))
2815 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2816 WARNING("netapp plugin: \"%s\" needs exactly one string argument. Ignoring "
2822 status = cf_util_get_string(ci, &host->name);
2826 for (int i = 0; i < ci->children_num; ++i) {
2827 item = ci->children + i;
2831 if (!strcasecmp(item->key, "Address")) {
2832 status = cf_util_get_string(item, &host->host);
2833 } else if (!strcasecmp(item->key, "Port")) {
2836 tmp = cf_util_get_port_number(item);
2839 } else if (!strcasecmp(item->key, "Protocol")) {
2840 if ((item->values_num != 1) ||
2841 (item->values[0].type != OCONFIG_TYPE_STRING) ||
2842 (strcasecmp(item->values[0].value.string, "http") &&
2843 strcasecmp(item->values[0].value.string, "https"))) {
2844 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or "
2845 "\"https\". Ignoring host block \"%s\".",
2846 ci->values[0].value.string);
2849 if (!strcasecmp(item->values[0].value.string, "http"))
2850 host->protocol = NA_SERVER_TRANSPORT_HTTP;
2852 host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2853 } else if (!strcasecmp(item->key, "User")) {
2854 status = cf_util_get_string(item, &host->username);
2855 } else if (!strcasecmp(item->key, "Password")) {
2856 status = cf_util_get_string(item, &host->password);
2857 } else if (!strcasecmp(item->key, "Interval")) {
2858 status = cf_util_get_cdtime(item, &host->interval);
2859 } else if (!strcasecmp(item->key, "WAFL")) {
2860 cna_config_wafl(host, item);
2861 } else if (!strcasecmp(item->key, "Disks")) {
2862 cna_config_disk(host, item);
2863 } else if (!strcasecmp(item->key, "VolumePerf")) {
2864 cna_config_volume_performance(host, item);
2865 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2866 cna_config_volume_usage(host, item);
2867 } else if (!strcasecmp(item->key, "Quota")) {
2868 cna_config_quota(host, item);
2869 } else if (!strcasecmp(item->key, "SnapVault")) {
2870 cna_config_snapvault(host, item);
2871 } else if (!strcasecmp(item->key, "System")) {
2872 cna_config_system(host, item);
2873 } else if ((!strcasecmp(item->key, "VFiler")) && (!is_vfiler)) {
2874 host_config_t *vfiler;
2876 vfiler = cna_shallow_clone_host(host);
2878 ERROR("netapp plugin: Failed to allocate host object for vfiler.");
2882 if (cna_config_host(vfiler, item)) {
2883 free_host_config(vfiler);
2887 cna_register_host(vfiler);
2888 } else if ((!strcasecmp(item->key, "VFilerName")) && is_vfiler) {
2889 status = cf_util_get_string(item, &host->vfiler);
2891 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in %s "
2893 item->key, is_vfiler ? "vfiler" : "host",
2894 ci->values[0].value.string);
2901 if (host->host == NULL)
2902 host->host = strdup(host->name);
2904 if (is_vfiler && (!host->vfiler))
2905 host->vfiler = strdup(host->name);
2907 if (host->host == NULL)
2910 if (host->port <= 0)
2911 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2913 if ((host->username == NULL) || (host->password == NULL)) {
2914 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2915 "Ignoring host block.",
2924 } /* }}} host_config_t *cna_config_host */
2927 * Callbacks registered with the daemon
2929 * Pretty standard stuff here.
2931 static int cna_init_host(host_config_t *host) /* {{{ */
2933 /* Request version 1.1 of the ONTAP API */
2934 int major_version = 1, minor_version = 1;
2939 if (host->srv != NULL)
2942 if (host->vfiler != NULL) /* Request version 1.7 of the ONTAP API */
2945 host->srv = na_server_open(host->host, major_version, minor_version);
2946 if (host->srv == NULL) {
2947 ERROR("netapp plugin: na_server_open (%s) failed.", host->host);
2951 na_server_set_transport_type(host->srv, host->protocol,
2952 /* transportarg = */ NULL);
2953 na_server_set_port(host->srv, host->port);
2954 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
2955 na_server_adminuser(host->srv, host->username, host->password);
2956 na_server_set_timeout(host->srv, 5 /* seconds */);
2958 if (host->vfiler != NULL) {
2959 if (!na_server_set_vfiler(host->srv, host->vfiler)) {
2960 ERROR("netapp plugin: Failed to connect to VFiler '%s' on host '%s'.",
2961 host->vfiler, host->host);
2964 INFO("netapp plugin: Connected to VFiler '%s' on host '%s'.",
2965 host->vfiler, host->host);
2970 } /* }}} int cna_init_host */
2972 static int cna_init(void) /* {{{ */
2974 char err[256] = {0};
2976 if (!na_startup(err, sizeof(err))) {
2977 err[sizeof(err) - 1] = '\0';
2978 ERROR("netapp plugin: Error initializing netapp API: %s", err);
2983 } /* }}} cna_init */
2985 static int cna_read_internal(host_config_t *host) { /* {{{ */
2988 status = cna_query_wafl(host);
2992 status = cna_query_disk(host);
2996 status = cna_query_volume_perf(host);
3000 status = cna_query_volume_usage(host);
3004 status = cna_query_quota(host);
3008 status = cna_query_snapvault(host);
3012 status = cna_query_system(host);
3017 } /* }}} int cna_read_internal */
3019 static int cna_read(user_data_t *ud) { /* {{{ */
3020 host_config_t *host;
3023 if ((ud == NULL) || (ud->data == NULL))
3028 status = cna_init_host(host);
3032 status = cna_read_internal(host);
3034 if (host->srv != NULL)
3035 na_server_close(host->srv);
3040 } /* }}} int cna_read */
3042 static int cna_config(oconfig_item_t *ci) { /* {{{ */
3043 oconfig_item_t *item;
3045 for (int i = 0; i < ci->children_num; ++i) {
3046 item = ci->children + i;
3048 if (strcasecmp(item->key, "Host") == 0) {
3049 host_config_t *host;
3051 host = cna_alloc_host();
3053 ERROR("netapp plugin: Failed to allocate host object.");
3057 if (cna_config_host(host, item) != 0) {
3058 free_host_config(host);
3062 cna_register_host(host);
3063 } else /* if (item->key != "Host") */
3065 WARNING("netapp plugin: Ignoring unknown config option \"%s\".",
3070 } /* }}} int cna_config */
3072 static int cna_shutdown(void) /* {{{ */
3074 /* Clean up system resources and stuff. */
3078 } /* }}} int cna_shutdown */
3080 void module_register(void) {
3081 plugin_register_complex_config("netapp", cna_config);
3082 plugin_register_init("netapp", cna_init);
3083 plugin_register_shutdown("netapp", cna_shutdown);