2 * collectd - src/netapp.c
3 * Copyright (C) 2009 Sven Trenkel
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Sven Trenkel <collectd at semidefinite.de>
29 #include "utils_ignorelist.h"
31 #include <netapp_api.h>
32 #include <netapp_errno.h>
34 #define HAS_ALL_FLAGS(has,needs) (((has) & (needs)) == (needs))
36 typedef struct host_config_s host_config_t;
37 typedef void service_handler_t(host_config_t *host, na_elem_t *result, void *data);
44 typedef struct cna_interval_s cna_interval_t;
46 /*! Data types for WAFL statistics {{{
48 * \brief Persistent data for WAFL performance counters. (a.k.a. cache performance)
50 * The cache counters use old counter values to calculate a hit ratio for each
51 * counter. The "cfg_wafl_t" struct therefore contains old counter values along
52 * with flags, which are set if the counter is valid.
54 * The function "cna_handle_wafl_data" will fill a new structure of this kind
55 * with new values, then pass both, new and old data, to "submit_wafl_data".
56 * That function calculates the hit ratios, submits the calculated values and
57 * updates the old counter values for the next iteration.
59 #define CFG_WAFL_NAME_CACHE 0x0001
60 #define CFG_WAFL_DIR_CACHE 0x0002
61 #define CFG_WAFL_BUF_CACHE 0x0004
62 #define CFG_WAFL_INODE_CACHE 0x0008
63 #define CFG_WAFL_ALL 0x000F
64 #define HAVE_WAFL_NAME_CACHE_HIT 0x0100
65 #define HAVE_WAFL_NAME_CACHE_MISS 0x0200
66 #define HAVE_WAFL_NAME_CACHE (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
67 #define HAVE_WAFL_FIND_DIR_HIT 0x0400
68 #define HAVE_WAFL_FIND_DIR_MISS 0x0800
69 #define HAVE_WAFL_FIND_DIR (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
70 #define HAVE_WAFL_BUF_HASH_HIT 0x1000
71 #define HAVE_WAFL_BUF_HASH_MISS 0x2000
72 #define HAVE_WAFL_BUF_HASH (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
73 #define HAVE_WAFL_INODE_CACHE_HIT 0x4000
74 #define HAVE_WAFL_INODE_CACHE_MISS 0x8000
75 #define HAVE_WAFL_INODE_CACHE (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
76 #define HAVE_WAFL_ALL 0xff00
79 cna_interval_t interval;
83 uint64_t name_cache_hit;
84 uint64_t name_cache_miss;
85 uint64_t find_dir_hit;
86 uint64_t find_dir_miss;
87 uint64_t buf_hash_hit;
88 uint64_t buf_hash_miss;
89 uint64_t inode_cache_hit;
90 uint64_t inode_cache_miss;
94 /*! Data types for disk statistics {{{
96 * \brief A disk in the NetApp.
98 * A disk doesn't have any more information than its name at the moment.
99 * The name includes the "disk_" prefix.
101 #define HAVE_DISK_BUSY 0x10
102 #define HAVE_DISK_BASE 0x20
103 #define HAVE_DISK_ALL 0x30
104 typedef struct disk_s {
109 uint64_t base_for_disk_busy;
110 double disk_busy_percent;
114 #define CFG_DISK_BUSIEST 0x01
115 #define CFG_DISK_ALL 0x01
118 cna_interval_t interval;
124 /*! Data types for volume performance statistics {{{
126 * \brief Persistent data for volume performance data.
128 * The code below uses the difference of the operations and latency counters to
129 * calculate an average per-operation latency. For this, old counters need to
130 * be stored in the "data_volume_perf_t" structure. The byte-counters are just
131 * kept for completeness sake. The "flags" member indicates if each counter is
134 * The "cna_handle_volume_perf_data" function will fill a new struct of this
135 * type and pass both, old and new data, to "submit_volume_perf_data". In that
136 * function, the per-operation latency is calculated and dispatched, then the
137 * old counters are updated.
139 #define CFG_VOLUME_PERF_INIT 0x0001
140 #define CFG_VOLUME_PERF_IO 0x0002
141 #define CFG_VOLUME_PERF_OPS 0x0003
142 #define CFG_VOLUME_PERF_LATENCY 0x0008
143 #define CFG_VOLUME_PERF_ALL 0x000F
144 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
145 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
146 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
147 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
148 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
149 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
150 #define HAVE_VOLUME_PERF_ALL 0x03F0
151 struct data_volume_perf_s;
152 typedef struct data_volume_perf_s data_volume_perf_t;
153 struct data_volume_perf_s {
159 uint64_t write_bytes;
162 uint64_t read_latency;
163 uint64_t write_latency;
165 data_volume_perf_t *next;
169 cna_interval_t interval;
172 ignorelist_t *il_octets;
173 ignorelist_t *il_operations;
174 ignorelist_t *il_latency;
176 data_volume_perf_t *volumes;
178 /* }}} data_volume_perf_t */
180 /*! Data types for volume usage statistics {{{
182 * \brief Configuration struct for volume usage data (free / used).
184 #define CFG_VOLUME_USAGE_DF 0x0002
185 #define CFG_VOLUME_USAGE_SNAP 0x0004
186 #define CFG_VOLUME_USAGE_ALL 0x0006
187 #define HAVE_VOLUME_USAGE_NORM_FREE 0x0010
188 #define HAVE_VOLUME_USAGE_NORM_USED 0x0020
189 #define HAVE_VOLUME_USAGE_SNAP_RSVD 0x0040
190 #define HAVE_VOLUME_USAGE_SNAP_USED 0x0080
191 #define HAVE_VOLUME_USAGE_SIS_SAVED 0x0100
192 #define HAVE_VOLUME_USAGE_ALL 0x01f0
193 #define IS_VOLUME_USAGE_OFFLINE 0x0200
194 struct data_volume_usage_s;
195 typedef struct data_volume_usage_s data_volume_usage_t;
196 struct data_volume_usage_s {
200 na_elem_t *snap_query;
204 uint64_t snap_reserved;
208 data_volume_usage_t *next;
212 cna_interval_t interval;
215 ignorelist_t *il_capacity;
216 ignorelist_t *il_snapshot;
218 data_volume_usage_t *volumes;
219 } cfg_volume_usage_t;
220 /* }}} cfg_volume_usage_t */
222 /*! Data types for system statistics {{{
224 * \brief Persistent data for system performance counters
226 #define CFG_SYSTEM_CPU 0x01
227 #define CFG_SYSTEM_NET 0x02
228 #define CFG_SYSTEM_OPS 0x04
229 #define CFG_SYSTEM_DISK 0x08
230 #define CFG_SYSTEM_ALL 0x0F
233 cna_interval_t interval;
236 /* }}} cfg_system_t */
238 struct host_config_s {
240 na_server_transport_t protocol;
248 cfg_wafl_t *cfg_wafl;
249 cfg_disk_t *cfg_disk;
250 cfg_volume_perf_t *cfg_volume_perf;
251 cfg_volume_usage_t *cfg_volume_usage;
252 cfg_system_t *cfg_system;
254 struct host_config_s *next;
260 * Used to free the various structures above.
262 static void free_disk (disk_t *disk) /* {{{ */
275 } /* }}} void free_disk */
277 static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
282 if (cw->query != NULL)
283 na_elem_free (cw->query);
286 } /* }}} void free_cfg_wafl */
288 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
290 if (cfg_disk == NULL)
293 if (cfg_disk->query != NULL)
294 na_elem_free (cfg_disk->query);
296 free_disk (cfg_disk->disks);
298 } /* }}} void free_cfg_disk */
300 static void free_cfg_volume_perf (cfg_volume_perf_t *cvp) /* {{{ */
302 data_volume_perf_t *data;
307 /* Free the ignorelists */
308 ignorelist_free (cvp->il_octets);
309 ignorelist_free (cvp->il_operations);
310 ignorelist_free (cvp->il_latency);
312 /* Free the linked list of volumes */
316 data_volume_perf_t *next = data->next;
322 if (cvp->query != NULL)
323 na_elem_free (cvp->query);
326 } /* }}} void free_cfg_volume_perf */
328 static void free_cfg_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
330 data_volume_usage_t *data;
335 /* Free the ignorelists */
336 ignorelist_free (cvu->il_capacity);
337 ignorelist_free (cvu->il_snapshot);
339 /* Free the linked list of volumes */
343 data_volume_usage_t *next = data->next;
345 if (data->snap_query != NULL)
346 na_elem_free(data->snap_query);
351 if (cvu->query != NULL)
352 na_elem_free (cvu->query);
355 } /* }}} void free_cfg_volume_usage */
357 static void free_cfg_system (cfg_system_t *cs) /* {{{ */
362 if (cs->query != NULL)
363 na_elem_free (cs->query);
366 } /* }}} void free_cfg_system */
368 static void free_host_config (host_config_t *hc) /* {{{ */
379 sfree (hc->username);
380 sfree (hc->password);
382 free_cfg_disk (hc->cfg_disk);
383 free_cfg_wafl (hc->cfg_wafl);
384 free_cfg_volume_perf (hc->cfg_volume_perf);
385 free_cfg_volume_usage (hc->cfg_volume_usage);
386 free_cfg_system (hc->cfg_system);
389 na_server_close (hc->srv);
393 free_host_config (next);
394 } /* }}} void free_host_config */
397 * Auxiliary functions
399 * Used to look up volumes and disks or to handle flags.
401 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
405 if ((cd == NULL) || (name == NULL))
408 for (d = cd->disks; d != NULL; d = d->next) {
409 if (strcmp(d->name, name) == 0)
413 d = malloc(sizeof(*d));
416 memset (d, 0, sizeof (*d));
419 d->name = strdup(name);
420 if (d->name == NULL) {
429 } /* }}} disk_t *get_disk */
431 static data_volume_usage_t *get_volume_usage (cfg_volume_usage_t *cvu, /* {{{ */
434 data_volume_usage_t *last;
435 data_volume_usage_t *new;
437 int ignore_capacity = 0;
438 int ignore_snapshot = 0;
440 if ((cvu == NULL) || (name == NULL))
446 if (strcmp (last->name, name) == 0)
449 if (last->next == NULL)
455 /* Check the ignorelists. If *both* tell us to ignore a volume, return NULL. */
456 ignore_capacity = ignorelist_match (cvu->il_capacity, name);
457 ignore_snapshot = ignorelist_match (cvu->il_snapshot, name);
458 if ((ignore_capacity != 0) && (ignore_snapshot != 0))
461 /* Not found: allocate. */
462 new = malloc (sizeof (*new));
465 memset (new, 0, sizeof (*new));
468 new->name = strdup (name);
469 if (new->name == NULL)
475 if (ignore_capacity == 0)
476 new->flags |= CFG_VOLUME_USAGE_DF;
477 if (ignore_snapshot == 0) {
478 new->flags |= CFG_VOLUME_USAGE_SNAP;
479 new->snap_query = na_elem_new ("snapshot-list-info");
480 na_child_add_string(new->snap_query, "target-type", "volume");
481 na_child_add_string(new->snap_query, "target-name", name);
483 new->snap_query = NULL;
486 /* Add to end of list. */
493 } /* }}} data_volume_usage_t *get_volume_usage */
495 static data_volume_perf_t *get_volume_perf (cfg_volume_perf_t *cvp, /* {{{ */
498 data_volume_perf_t *last;
499 data_volume_perf_t *new;
501 int ignore_octets = 0;
502 int ignore_operations = 0;
503 int ignore_latency = 0;
505 if ((cvp == NULL) || (name == NULL))
511 if (strcmp (last->name, name) == 0)
514 if (last->next == NULL)
520 /* Check the ignorelists. If *all three* tell us to ignore a volume, return
522 ignore_octets = ignorelist_match (cvp->il_octets, name);
523 ignore_operations = ignorelist_match (cvp->il_operations, name);
524 ignore_latency = ignorelist_match (cvp->il_latency, name);
525 if ((ignore_octets != 0) || (ignore_operations != 0)
526 || (ignore_latency != 0))
529 /* Not found: allocate. */
530 new = malloc (sizeof (*new));
533 memset (new, 0, sizeof (*new));
536 new->name = strdup (name);
537 if (new->name == NULL)
543 if (ignore_octets == 0)
544 new->flags |= CFG_VOLUME_PERF_IO;
545 if (ignore_operations == 0)
546 new->flags |= CFG_VOLUME_PERF_OPS;
547 if (ignore_latency == 0)
548 new->flags |= CFG_VOLUME_PERF_LATENCY;
550 /* Add to end of list. */
557 } /* }}} data_volume_perf_t *get_volume_perf */
560 * Various submit functions.
562 * They all eventually call "submit_values" which creates a value_list_t and
563 * dispatches it to the daemon.
565 static int submit_values (const char *host, /* {{{ */
566 const char *plugin_inst,
567 const char *type, const char *type_inst,
568 value_t *values, int values_len,
571 value_list_t vl = VALUE_LIST_INIT;
574 vl.values_len = values_len;
580 sstrncpy (vl.host, host, sizeof (vl.host));
582 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
583 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
584 if (plugin_inst != NULL)
585 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
586 sstrncpy (vl.type, type, sizeof (vl.type));
587 if (type_inst != NULL)
588 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
590 return (plugin_dispatch_values (&vl));
591 } /* }}} int submit_uint64 */
593 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
594 const char *type, const char *type_inst, counter_t val0, counter_t val1,
599 values[0].counter = val0;
600 values[1].counter = val1;
602 return (submit_values (host, plugin_inst, type, type_inst,
603 values, 2, timestamp));
604 } /* }}} int submit_two_counters */
606 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
607 const char *type, const char *type_inst, counter_t counter, cdtime_t timestamp)
613 return (submit_values (host, plugin_inst, type, type_inst,
615 } /* }}} int submit_counter */
617 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
618 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
623 values[0].gauge = val0;
624 values[1].gauge = val1;
626 return (submit_values (host, plugin_inst, type, type_inst,
627 values, 2, timestamp));
628 } /* }}} int submit_two_gauge */
630 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
631 const char *type, const char *type_inst, double d, cdtime_t timestamp)
635 v.gauge = (gauge_t) d;
637 return (submit_values (host, plugin_inst, type, type_inst,
639 } /* }}} int submit_uint64 */
641 /* Calculate hit ratio from old and new counters and submit the resulting
642 * percentage. Used by "submit_wafl_data". */
643 static int submit_cache_ratio (const char *host, /* {{{ */
644 const char *plugin_inst,
645 const char *type_inst,
654 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
658 hits = new_hits - old_hits;
659 misses = new_misses - old_misses;
661 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
666 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
668 } /* }}} int submit_cache_ratio */
670 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
671 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
672 cfg_wafl_t *old_data, const cfg_wafl_t *new_data)
674 /* Submit requested counters */
675 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
676 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
677 submit_cache_ratio (hostname, instance, "name_cache_hit",
678 new_data->name_cache_hit, new_data->name_cache_miss,
679 old_data->name_cache_hit, old_data->name_cache_miss,
680 new_data->timestamp);
682 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
683 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
684 submit_cache_ratio (hostname, instance, "find_dir_hit",
685 new_data->find_dir_hit, new_data->find_dir_miss,
686 old_data->find_dir_hit, old_data->find_dir_miss,
687 new_data->timestamp);
689 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
690 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
691 submit_cache_ratio (hostname, instance, "buf_hash_hit",
692 new_data->buf_hash_hit, new_data->buf_hash_miss,
693 old_data->buf_hash_hit, old_data->buf_hash_miss,
694 new_data->timestamp);
696 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
697 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
698 submit_cache_ratio (hostname, instance, "inode_cache_hit",
699 new_data->inode_cache_hit, new_data->inode_cache_miss,
700 old_data->inode_cache_hit, old_data->inode_cache_miss,
701 new_data->timestamp);
703 /* Clear old HAVE_* flags */
704 old_data->flags &= ~HAVE_WAFL_ALL;
706 /* Copy all counters */
707 old_data->timestamp = new_data->timestamp;
708 old_data->name_cache_hit = new_data->name_cache_hit;
709 old_data->name_cache_miss = new_data->name_cache_miss;
710 old_data->find_dir_hit = new_data->find_dir_hit;
711 old_data->find_dir_miss = new_data->find_dir_miss;
712 old_data->buf_hash_hit = new_data->buf_hash_hit;
713 old_data->buf_hash_miss = new_data->buf_hash_miss;
714 old_data->inode_cache_hit = new_data->inode_cache_hit;
715 old_data->inode_cache_miss = new_data->inode_cache_miss;
717 /* Copy HAVE_* flags */
718 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
721 } /* }}} int submit_wafl_data */
723 /* Submits volume performance data to the daemon, taking care to honor and
724 * update flags appropriately. */
725 static int submit_volume_perf_data (const char *hostname, /* {{{ */
726 data_volume_perf_t *old_data,
727 const data_volume_perf_t *new_data)
729 char plugin_instance[DATA_MAX_NAME_LEN];
731 if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
734 ssnprintf (plugin_instance, sizeof (plugin_instance),
735 "volume-%s", old_data->name);
737 /* Check for and submit disk-octet values */
738 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
739 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
741 submit_two_counters (hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
742 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
745 /* Check for and submit disk-operations values */
746 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
747 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
749 submit_two_counters (hostname, plugin_instance, "disk_ops", /* type instance = */ NULL,
750 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
753 /* Check for, calculate and submit disk-latency values */
754 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
755 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
756 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
757 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
758 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
760 gauge_t latency_per_op_read;
761 gauge_t latency_per_op_write;
763 latency_per_op_read = NAN;
764 latency_per_op_write = NAN;
766 /* Check if a counter wrapped around. */
767 if ((new_data->read_ops > old_data->read_ops)
768 && (new_data->read_latency > old_data->read_latency))
770 uint64_t diff_ops_read;
771 uint64_t diff_latency_read;
773 diff_ops_read = new_data->read_ops - old_data->read_ops;
774 diff_latency_read = new_data->read_latency - old_data->read_latency;
776 if (diff_ops_read > 0)
777 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
780 if ((new_data->write_ops > old_data->write_ops)
781 && (new_data->write_latency > old_data->write_latency))
783 uint64_t diff_ops_write;
784 uint64_t diff_latency_write;
786 diff_ops_write = new_data->write_ops - old_data->write_ops;
787 diff_latency_write = new_data->write_latency - old_data->write_latency;
789 if (diff_ops_write > 0)
790 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
793 submit_two_gauge (hostname, plugin_instance, "disk_latency", /* type instance = */ NULL,
794 latency_per_op_read, latency_per_op_write, new_data->timestamp);
797 /* Clear all HAVE_* flags. */
798 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
800 /* Copy all counters */
801 old_data->timestamp = new_data->timestamp;
802 old_data->read_bytes = new_data->read_bytes;
803 old_data->write_bytes = new_data->write_bytes;
804 old_data->read_ops = new_data->read_ops;
805 old_data->write_ops = new_data->write_ops;
806 old_data->read_latency = new_data->read_latency;
807 old_data->write_latency = new_data->write_latency;
809 /* Copy the HAVE_* flags */
810 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
813 } /* }}} int submit_volume_perf_data */
815 static cdtime_t cna_child_get_cdtime (na_elem_t *data) /* {{{ */
819 t = (time_t) na_child_get_uint64 (data, "timestamp", /* default = */ 0);
821 return (TIME_T_TO_CDTIME_T (t));
822 } /* }}} cdtime_t cna_child_get_cdtime */
828 * These functions are called with appropriate data returned by the libnetapp
829 * interface which is parsed and submitted with the above functions.
831 /* Data corresponding to <WAFL /> */
832 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
835 cfg_wafl_t perf_data;
836 const char *plugin_inst;
838 na_elem_t *instances;
840 na_elem_iter_t counter_iter;
842 memset (&perf_data, 0, sizeof (perf_data));
844 perf_data.timestamp = cna_child_get_cdtime (data);
846 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
847 if (instances == NULL)
849 ERROR ("netapp plugin: cna_handle_wafl_data: "
850 "na_elem_child (\"instances\") failed "
851 "for host %s.", hostname);
855 plugin_inst = na_child_get_string(instances, "name");
856 if (plugin_inst == NULL)
858 ERROR ("netapp plugin: cna_handle_wafl_data: "
859 "na_child_get_string (\"name\") failed "
860 "for host %s.", hostname);
864 /* Iterate over all counters */
865 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
866 for (counter = na_iterator_next (&counter_iter);
868 counter = na_iterator_next (&counter_iter))
873 name = na_child_get_string(counter, "name");
877 value = na_child_get_uint64(counter, "value", UINT64_MAX);
878 if (value == UINT64_MAX)
881 if (!strcmp(name, "name_cache_hit")) {
882 perf_data.name_cache_hit = value;
883 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
884 } else if (!strcmp(name, "name_cache_miss")) {
885 perf_data.name_cache_miss = value;
886 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
887 } else if (!strcmp(name, "find_dir_hit")) {
888 perf_data.find_dir_hit = value;
889 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
890 } else if (!strcmp(name, "find_dir_miss")) {
891 perf_data.find_dir_miss = value;
892 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
893 } else if (!strcmp(name, "buf_hash_hit")) {
894 perf_data.buf_hash_hit = value;
895 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
896 } else if (!strcmp(name, "buf_hash_miss")) {
897 perf_data.buf_hash_miss = value;
898 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
899 } else if (!strcmp(name, "inode_cache_hit")) {
900 perf_data.inode_cache_hit = value;
901 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
902 } else if (!strcmp(name, "inode_cache_miss")) {
903 perf_data.inode_cache_miss = value;
904 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
906 DEBUG("netapp plugin: cna_handle_wafl_data: "
907 "Found unexpected child: %s "
908 "for host %s.", name, hostname);
912 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data));
913 } /* }}} void cna_handle_wafl_data */
915 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
922 if (cw->query != NULL)
925 cw->query = na_elem_new("perf-object-get-instances");
926 if (cw->query == NULL)
928 ERROR ("netapp plugin: na_elem_new failed.");
931 na_child_add_string (cw->query, "objectname", "wafl");
933 e = na_elem_new("counters");
936 na_elem_free (cw->query);
938 ERROR ("netapp plugin: na_elem_new failed.");
941 na_child_add_string(e, "counter", "name_cache_hit");
942 na_child_add_string(e, "counter", "name_cache_miss");
943 na_child_add_string(e, "counter", "find_dir_hit");
944 na_child_add_string(e, "counter", "find_dir_miss");
945 na_child_add_string(e, "counter", "buf_hash_hit");
946 na_child_add_string(e, "counter", "buf_hash_miss");
947 na_child_add_string(e, "counter", "inode_cache_hit");
948 na_child_add_string(e, "counter", "inode_cache_miss");
950 na_child_add(cw->query, e);
953 } /* }}} int cna_setup_wafl */
955 static int cna_query_wafl (host_config_t *host) /* {{{ */
964 /* If WAFL was not configured, return without doing anything. */
965 if (host->cfg_wafl == NULL)
969 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
972 status = cna_setup_wafl (host->cfg_wafl);
975 assert (host->cfg_wafl->query != NULL);
977 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
978 if (na_results_status (data) != NA_OK)
980 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed for host %s: %s",
981 host->name, na_results_reason (data));
986 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data);
989 host->cfg_wafl->interval.last_read = now;
993 } /* }}} int cna_query_wafl */
995 /* Data corresponding to <Disks /> */
996 static int cna_handle_disk_data (const char *hostname, /* {{{ */
997 cfg_disk_t *cfg_disk, na_elem_t *data)
1000 na_elem_t *instances;
1001 na_elem_t *instance;
1002 na_elem_iter_t instance_iter;
1003 disk_t *worst_disk = NULL;
1005 if ((cfg_disk == NULL) || (data == NULL))
1008 timestamp = cna_child_get_cdtime (data);
1010 instances = na_elem_child (data, "instances");
1011 if (instances == NULL)
1013 ERROR ("netapp plugin: cna_handle_disk_data: "
1014 "na_elem_child (\"instances\") failed "
1015 "for host %s.", hostname);
1019 /* Iterate over all children */
1020 instance_iter = na_child_iterator (instances);
1021 for (instance = na_iterator_next (&instance_iter);
1023 instance = na_iterator_next(&instance_iter))
1028 na_elem_iter_t counter_iterator;
1031 memset (&new_data, 0, sizeof (new_data));
1032 new_data.timestamp = timestamp;
1033 new_data.disk_busy_percent = NAN;
1035 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1036 if (old_data == NULL)
1039 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1040 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1041 for (counter = na_iterator_next(&counter_iterator);
1043 counter = na_iterator_next(&counter_iterator))
1048 name = na_child_get_string(counter, "name");
1052 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1053 if (value == UINT64_MAX)
1056 if (strcmp(name, "disk_busy") == 0)
1058 new_data.disk_busy = value;
1059 new_data.flags |= HAVE_DISK_BUSY;
1061 else if (strcmp(name, "base_for_disk_busy") == 0)
1063 new_data.base_for_disk_busy = value;
1064 new_data.flags |= HAVE_DISK_BASE;
1068 DEBUG ("netapp plugin: cna_handle_disk_data: "
1069 "Counter not handled: %s = %"PRIu64,
1074 /* If all required counters are available and did not just wrap around,
1075 * calculate the busy percentage. Otherwise, the value is initialized to
1076 * NAN at the top of the for-loop. */
1077 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1078 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1079 && (new_data.disk_busy >= old_data->disk_busy)
1080 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1085 busy_diff = new_data.disk_busy - old_data->disk_busy;
1086 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1088 new_data.disk_busy_percent = 100.0
1089 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1092 /* Clear HAVE_* flags */
1093 old_data->flags &= ~HAVE_DISK_ALL;
1096 old_data->timestamp = new_data.timestamp;
1097 old_data->disk_busy = new_data.disk_busy;
1098 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1099 old_data->disk_busy_percent = new_data.disk_busy_percent;
1102 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1104 if ((worst_disk == NULL)
1105 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1106 worst_disk = old_data;
1107 } /* for (all disks) */
1109 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1110 submit_double (hostname, "system", "percent", "disk_busy",
1111 worst_disk->disk_busy_percent, timestamp);
1114 } /* }}} int cna_handle_disk_data */
1116 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1123 if (cd->query != NULL)
1126 cd->query = na_elem_new ("perf-object-get-instances");
1127 if (cd->query == NULL)
1129 ERROR ("netapp plugin: na_elem_new failed.");
1132 na_child_add_string (cd->query, "objectname", "disk");
1134 e = na_elem_new("counters");
1137 na_elem_free (cd->query);
1139 ERROR ("netapp plugin: na_elem_new failed.");
1142 na_child_add_string(e, "counter", "disk_busy");
1143 na_child_add_string(e, "counter", "base_for_disk_busy");
1144 na_child_add(cd->query, e);
1147 } /* }}} int cna_setup_disk */
1149 static int cna_query_disk (host_config_t *host) /* {{{ */
1158 /* If the user did not configure disk statistics, return without doing
1160 if (host->cfg_disk == NULL)
1164 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1167 status = cna_setup_disk (host->cfg_disk);
1170 assert (host->cfg_disk->query != NULL);
1172 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1173 if (na_results_status (data) != NA_OK)
1175 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed for host %s: %s",
1176 host->name, na_results_reason (data));
1177 na_elem_free (data);
1181 status = cna_handle_disk_data (host->name, host->cfg_disk, data);
1184 host->cfg_disk->interval.last_read = now;
1186 na_elem_free (data);
1188 } /* }}} int cna_query_disk */
1190 /* Data corresponding to <VolumePerf /> */
1191 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1192 cfg_volume_perf_t *cvp, na_elem_t *data)
1195 na_elem_t *elem_instances;
1196 na_elem_iter_t iter_instances;
1197 na_elem_t *elem_instance;
1199 timestamp = cna_child_get_cdtime (data);
1201 elem_instances = na_elem_child(data, "instances");
1202 if (elem_instances == NULL)
1204 ERROR ("netapp plugin: handle_volume_perf_data: "
1205 "na_elem_child (\"instances\") failed "
1206 "for host %s.", hostname);
1210 iter_instances = na_child_iterator (elem_instances);
1211 for (elem_instance = na_iterator_next(&iter_instances);
1212 elem_instance != NULL;
1213 elem_instance = na_iterator_next(&iter_instances))
1217 data_volume_perf_t perf_data;
1218 data_volume_perf_t *v;
1220 na_elem_t *elem_counters;
1221 na_elem_iter_t iter_counters;
1222 na_elem_t *elem_counter;
1224 memset (&perf_data, 0, sizeof (perf_data));
1225 perf_data.timestamp = timestamp;
1227 name = na_child_get_string (elem_instance, "name");
1231 /* get_volume_perf may return NULL if this volume is to be ignored. */
1232 v = get_volume_perf (cvp, name);
1236 elem_counters = na_elem_child (elem_instance, "counters");
1237 if (elem_counters == NULL)
1240 iter_counters = na_child_iterator (elem_counters);
1241 for (elem_counter = na_iterator_next(&iter_counters);
1242 elem_counter != NULL;
1243 elem_counter = na_iterator_next(&iter_counters))
1248 name = na_child_get_string (elem_counter, "name");
1252 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1253 if (value == UINT64_MAX)
1256 if (!strcmp(name, "read_data")) {
1257 perf_data.read_bytes = value;
1258 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1259 } else if (!strcmp(name, "write_data")) {
1260 perf_data.write_bytes = value;
1261 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1262 } else if (!strcmp(name, "read_ops")) {
1263 perf_data.read_ops = value;
1264 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1265 } else if (!strcmp(name, "write_ops")) {
1266 perf_data.write_ops = value;
1267 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1268 } else if (!strcmp(name, "read_latency")) {
1269 perf_data.read_latency = value;
1270 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1271 } else if (!strcmp(name, "write_latency")) {
1272 perf_data.write_latency = value;
1273 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1275 } /* for (elem_counter) */
1277 submit_volume_perf_data (hostname, v, &perf_data);
1278 } /* for (volume) */
1281 } /* }}} int cna_handle_volume_perf_data */
1283 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1290 if (cd->query != NULL)
1293 cd->query = na_elem_new ("perf-object-get-instances");
1294 if (cd->query == NULL)
1296 ERROR ("netapp plugin: na_elem_new failed.");
1299 na_child_add_string (cd->query, "objectname", "volume");
1301 e = na_elem_new("counters");
1304 na_elem_free (cd->query);
1306 ERROR ("netapp plugin: na_elem_new failed.");
1309 na_child_add_string(e, "counter", "read_ops");
1310 na_child_add_string(e, "counter", "write_ops");
1311 na_child_add_string(e, "counter", "read_data");
1312 na_child_add_string(e, "counter", "write_data");
1313 na_child_add_string(e, "counter", "read_latency");
1314 na_child_add_string(e, "counter", "write_latency");
1315 na_child_add(cd->query, e);
1318 } /* }}} int cna_setup_volume_perf */
1320 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1329 /* If the user did not configure volume performance statistics, return
1330 * without doing anything. */
1331 if (host->cfg_volume_perf == NULL)
1335 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1338 status = cna_setup_volume_perf (host->cfg_volume_perf);
1341 assert (host->cfg_volume_perf->query != NULL);
1343 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1344 if (na_results_status (data) != NA_OK)
1346 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed for host %s: %s",
1347 host->name, na_results_reason (data));
1348 na_elem_free (data);
1352 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data);
1355 host->cfg_volume_perf->interval.last_read = now;
1357 na_elem_free (data);
1359 } /* }}} int cna_query_volume_perf */
1361 /* Data corresponding to <VolumeUsage /> */
1362 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1363 cfg_volume_usage_t *cfg_volume)
1365 data_volume_usage_t *v;
1367 for (v = cfg_volume->volumes; v != NULL; v = v->next)
1369 char plugin_instance[DATA_MAX_NAME_LEN];
1371 uint64_t norm_used = v->norm_used;
1372 uint64_t norm_free = v->norm_free;
1373 uint64_t sis_saved = v->sis_saved;
1374 uint64_t snap_reserve_used = 0;
1375 uint64_t snap_reserve_free = v->snap_reserved;
1376 uint64_t snap_norm_used = v->snap_used;
1378 ssnprintf (plugin_instance, sizeof (plugin_instance),
1379 "volume-%s", v->name);
1381 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD)) {
1382 if (v->snap_reserved > v->snap_used) {
1383 snap_reserve_free = v->snap_reserved - v->snap_used;
1384 snap_reserve_used = v->snap_used;
1387 snap_reserve_free = 0;
1388 snap_reserve_used = v->snap_reserved;
1389 snap_norm_used = v->snap_used - v->snap_reserved;
1393 /* The space used by snapshots but not reserved for them is included in
1394 * both, norm_used and snap_norm_used. If possible, subtract this here. */
1395 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED))
1397 if (norm_used >= snap_norm_used)
1398 norm_used -= snap_norm_used;
1401 ERROR ("netapp plugin: (norm_used = %"PRIu64") < (snap_norm_used = "
1402 "%"PRIu64") for host %s. Invalidating both.",
1403 norm_used, snap_norm_used, hostname);
1404 v->flags &= ~(HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED);
1408 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1409 submit_double (hostname, /* plugin instance = */ plugin_instance,
1410 "df_complex", "free",
1411 (double) norm_free, /* timestamp = */ 0);
1413 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1414 submit_double (hostname, /* plugin instance = */ plugin_instance,
1415 "df_complex", "sis_saved",
1416 (double) sis_saved, /* timestamp = */ 0);
1418 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1419 submit_double (hostname, /* plugin instance = */ plugin_instance,
1420 "df_complex", "used",
1421 (double) norm_used, /* timestamp = */ 0);
1423 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1424 submit_double (hostname, /* plugin instance = */ plugin_instance,
1425 "df_complex", "snap_reserved",
1426 (double) snap_reserve_free, /* timestamp = */ 0);
1428 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
1429 submit_double (hostname, /* plugin instance = */ plugin_instance,
1430 "df_complex", "snap_reserve_used",
1431 (double) snap_reserve_used, /* timestamp = */ 0);
1433 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1434 submit_double (hostname, /* plugin instance = */ plugin_instance,
1435 "df_complex", "snap_normal_used",
1436 (double) snap_norm_used, /* timestamp = */ 0);
1438 /* Clear all the HAVE_* flags */
1439 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1440 } /* for (v = cfg_volume->volumes) */
1443 } /* }}} int cna_submit_volume_usage_data */
1445 /* Switch the state of a volume between online and offline and send out a
1447 static int cna_change_volume_status (const char *hostname, /* {{{ */
1448 data_volume_usage_t *v)
1452 memset (&n, 0, sizeof (&n));
1454 sstrncpy (n.host, hostname, sizeof (n.host));
1455 sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
1456 sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance));
1458 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
1459 n.severity = NOTIF_OKAY;
1460 ssnprintf (n.message, sizeof (n.message),
1461 "Volume %s is now online.", v->name);
1462 v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
1464 n.severity = NOTIF_WARNING;
1465 ssnprintf (n.message, sizeof (n.message),
1466 "Volume %s is now offline.", v->name);
1467 v->flags |= IS_VOLUME_USAGE_OFFLINE;
1470 return (plugin_dispatch_notification (&n));
1471 } /* }}} int cna_change_volume_status */
1473 static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
1474 data_volume_usage_t *v)
1476 uint64_t snap_used = 0, value;
1477 na_elem_t *data, *elem_snap, *elem_snapshots;
1478 na_elem_iter_t iter_snap;
1480 data = na_server_invoke_elem(host->srv, v->snap_query);
1481 if (na_results_status(data) != NA_OK)
1483 if (na_results_errno(data) == EVOLUMEOFFLINE) {
1484 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
1485 cna_change_volume_status (host->name, v);
1487 ERROR ("netapp plugin: cna_handle_volume_snap_usage: na_server_invoke_elem for "
1488 "volume \"%s\" on host %s failed with error %d: %s", v->name,
1489 host->name, na_results_errno(data), na_results_reason(data));
1495 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0)
1496 cna_change_volume_status (host->name, v);
1498 elem_snapshots = na_elem_child (data, "snapshots");
1499 if (elem_snapshots == NULL)
1501 ERROR ("netapp plugin: cna_handle_volume_snap_usage: "
1502 "na_elem_child (\"snapshots\") failed "
1503 "for host %s.", host->name);
1508 iter_snap = na_child_iterator (elem_snapshots);
1509 for (elem_snap = na_iterator_next (&iter_snap);
1511 elem_snap = na_iterator_next (&iter_snap))
1513 value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
1514 /* "cumulative-total" is the total size of the oldest snapshot plus all
1515 * newer ones in blocks (1KB). We therefore are looking for the highest
1516 * number of all snapshots - that's the size required for the snapshots. */
1517 if (value > snap_used)
1520 na_elem_free (data);
1521 /* snap_used is in 1024 byte blocks */
1522 v->snap_used = snap_used * 1024;
1523 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1524 } /* }}} void cna_handle_volume_snap_usage */
1526 static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
1527 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1529 na_elem_t *elem_volume;
1530 na_elem_t *elem_volumes;
1531 na_elem_iter_t iter_volume;
1533 elem_volumes = na_elem_child (data, "volumes");
1534 if (elem_volumes == NULL)
1536 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1537 "na_elem_child (\"volumes\") failed "
1538 "for host %s.", host->name);
1542 iter_volume = na_child_iterator (elem_volumes);
1543 for (elem_volume = na_iterator_next (&iter_volume);
1544 elem_volume != NULL;
1545 elem_volume = na_iterator_next (&iter_volume))
1547 const char *volume_name, *state;
1549 data_volume_usage_t *v;
1553 const char *sis_state;
1554 uint64_t sis_saved_reported;
1556 volume_name = na_child_get_string (elem_volume, "name");
1557 if (volume_name == NULL)
1560 state = na_child_get_string (elem_volume, "state");
1561 if ((state == NULL) || (strcmp(state, "online") != 0))
1564 /* get_volume_usage may return NULL if the volume is to be ignored. */
1565 v = get_volume_usage (cfg_volume, volume_name);
1569 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1570 cna_handle_volume_snap_usage(host, v);
1572 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1575 /* 2^4 exa-bytes? This will take a while ;) */
1576 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1577 if (value != UINT64_MAX) {
1578 v->norm_free = value;
1579 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1582 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1583 if (value != UINT64_MAX) {
1584 v->norm_used = value;
1585 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1588 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1589 if (value != UINT64_MAX) {
1590 /* 1 block == 1024 bytes as per API docs */
1591 v->snap_reserved = 1024 * value;
1592 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1595 sis = na_elem_child(elem_volume, "sis");
1599 sis_state = na_child_get_string(sis, "state");
1600 if (sis_state == NULL)
1603 /* If SIS is not enabled, there's nothing left to do for this volume. */
1604 if (strcmp ("enabled", sis_state) != 0)
1607 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1608 if (sis_saved_reported == UINT64_MAX)
1611 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1612 if ((sis_saved_reported >> 32) != 0) {
1613 /* In case they ever fix this bug. */
1614 v->sis_saved = sis_saved_reported;
1615 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1616 } else { /* really hacky work-around code. {{{ */
1617 uint64_t sis_saved_percent;
1618 uint64_t sis_saved_guess;
1619 uint64_t overflow_guess;
1620 uint64_t guess1, guess2, guess3;
1622 /* Check if we have v->norm_used. Without it, we cannot calculate
1623 * sis_saved_guess. */
1624 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1627 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1628 if (sis_saved_percent > 100)
1631 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1632 * will hopefully be fixed in later versions. To work around the bug, try
1633 * to figure out how often the 32bit integer wrapped around by using the
1634 * "percentage-saved" value. Because the percentage is in the range
1635 * [0-100], this should work as long as the saved space does not exceed
1637 /* percentage-saved = size-saved / (size-saved + size-used) */
1638 if (sis_saved_percent < 100)
1639 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1641 sis_saved_guess = v->norm_used;
1643 overflow_guess = sis_saved_guess >> 32;
1644 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1645 guess2 = (overflow_guess << 32) + sis_saved_reported;
1646 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1648 if (sis_saved_guess < guess2) {
1649 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1650 v->sis_saved = guess1;
1652 v->sis_saved = guess2;
1654 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1655 v->sis_saved = guess2;
1657 v->sis_saved = guess3;
1659 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1660 } /* }}} end of 32-bit workaround */
1661 } /* for (elem_volume) */
1663 return (cna_submit_volume_usage_data (host->name, cfg_volume));
1664 } /* }}} int cna_handle_volume_usage_data */
1666 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1671 if (cvu->query != NULL)
1674 cvu->query = na_elem_new ("volume-list-info");
1675 if (cvu->query == NULL)
1677 ERROR ("netapp plugin: na_elem_new failed.");
1682 } /* }}} int cna_setup_volume_usage */
1684 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1693 /* If the user did not configure volume_usage statistics, return without
1694 * doing anything. */
1695 if (host->cfg_volume_usage == NULL)
1699 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1702 status = cna_setup_volume_usage (host->cfg_volume_usage);
1705 assert (host->cfg_volume_usage->query != NULL);
1707 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1708 if (na_results_status (data) != NA_OK)
1710 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed for host %s: %s",
1711 host->name, na_results_reason (data));
1712 na_elem_free (data);
1716 status = cna_handle_volume_usage_data (host, host->cfg_volume_usage, data);
1719 host->cfg_volume_usage->interval.last_read = now;
1721 na_elem_free (data);
1723 } /* }}} int cna_query_volume_usage */
1725 /* Data corresponding to <System /> */
1726 static int cna_handle_system_data (const char *hostname, /* {{{ */
1727 cfg_system_t *cfg_system, na_elem_t *data)
1729 na_elem_t *instances;
1731 na_elem_iter_t counter_iter;
1733 counter_t disk_read = 0, disk_written = 0;
1734 counter_t net_recv = 0, net_sent = 0;
1735 counter_t cpu_busy = 0, cpu_total = 0;
1736 uint32_t counter_flags = 0;
1738 const char *instance;
1741 timestamp = cna_child_get_cdtime (data);
1743 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1744 if (instances == NULL)
1746 ERROR ("netapp plugin: cna_handle_system_data: "
1747 "na_elem_child (\"instances\") failed "
1748 "for host %s.", hostname);
1752 instance = na_child_get_string (instances, "name");
1753 if (instance == NULL)
1755 ERROR ("netapp plugin: cna_handle_system_data: "
1756 "na_child_get_string (\"name\") failed "
1757 "for host %s.", hostname);
1761 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
1762 for (counter = na_iterator_next (&counter_iter);
1764 counter = na_iterator_next (&counter_iter))
1769 name = na_child_get_string(counter, "name");
1773 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1774 if (value == UINT64_MAX)
1777 if (!strcmp(name, "disk_data_read")) {
1778 disk_read = (counter_t) (value * 1024);
1779 counter_flags |= 0x01;
1780 } else if (!strcmp(name, "disk_data_written")) {
1781 disk_written = (counter_t) (value * 1024);
1782 counter_flags |= 0x02;
1783 } else if (!strcmp(name, "net_data_recv")) {
1784 net_recv = (counter_t) (value * 1024);
1785 counter_flags |= 0x04;
1786 } else if (!strcmp(name, "net_data_sent")) {
1787 net_sent = (counter_t) (value * 1024);
1788 counter_flags |= 0x08;
1789 } else if (!strcmp(name, "cpu_busy")) {
1790 cpu_busy = (counter_t) value;
1791 counter_flags |= 0x10;
1792 } else if (!strcmp(name, "cpu_elapsed_time")) {
1793 cpu_total = (counter_t) value;
1794 counter_flags |= 0x20;
1795 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1796 && (value > 0) && (strlen(name) > 4)
1797 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1798 submit_counter (hostname, instance, "disk_ops_complex", name,
1799 (counter_t) value, timestamp);
1801 } /* for (counter) */
1803 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1804 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
1805 submit_two_counters (hostname, instance, "disk_octets", NULL,
1806 disk_read, disk_written, timestamp);
1808 if ((cfg_system->flags & CFG_SYSTEM_NET)
1809 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
1810 submit_two_counters (hostname, instance, "if_octets", NULL,
1811 net_recv, net_sent, timestamp);
1813 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1814 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
1816 submit_counter (hostname, instance, "cpu", "system",
1817 cpu_busy, timestamp);
1818 submit_counter (hostname, instance, "cpu", "idle",
1819 cpu_total - cpu_busy, timestamp);
1823 } /* }}} int cna_handle_system_data */
1825 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
1830 if (cs->query != NULL)
1833 cs->query = na_elem_new ("perf-object-get-instances");
1834 if (cs->query == NULL)
1836 ERROR ("netapp plugin: na_elem_new failed.");
1839 na_child_add_string (cs->query, "objectname", "system");
1842 } /* }}} int cna_setup_system */
1844 static int cna_query_system (host_config_t *host) /* {{{ */
1853 /* If system statistics were not configured, return without doing anything. */
1854 if (host->cfg_system == NULL)
1858 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
1861 status = cna_setup_system (host->cfg_system);
1864 assert (host->cfg_system->query != NULL);
1866 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
1867 if (na_results_status (data) != NA_OK)
1869 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed for host %s: %s",
1870 host->name, na_results_reason (data));
1871 na_elem_free (data);
1875 status = cna_handle_system_data (host->name, host->cfg_system, data);
1878 host->cfg_system->interval.last_read = now;
1880 na_elem_free (data);
1882 } /* }}} int cna_query_system */
1885 * Configuration handling
1887 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1888 * is false. On error, the flag-field is not changed. */
1889 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1890 uint32_t *flags, uint32_t flag)
1892 if ((ci == NULL) || (flags == NULL))
1895 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1897 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1902 if (ci->values[0].value.boolean)
1908 } /* }}} int cna_config_bool_to_flag */
1910 /* Handling of the "Interval" option which is allowed in every block. */
1911 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1912 cna_interval_t *out_interval)
1917 status = cf_util_get_cdtime (ci, &tmp);
1921 out_interval->interval = tmp;
1922 out_interval->last_read = 0;
1925 } /* }}} int cna_config_get_interval */
1927 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1928 * <VolumePerf /> block. */
1929 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
1930 const oconfig_item_t *ci)
1935 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1937 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1942 name = ci->values[0].value.string;
1944 if (strcasecmp ("GetIO", ci->key) == 0)
1945 il = cvp->il_octets;
1946 else if (strcasecmp ("GetOps", ci->key) == 0)
1947 il = cvp->il_operations;
1948 else if (strcasecmp ("GetLatency", ci->key) == 0)
1949 il = cvp->il_latency;
1953 ignorelist_add (il, name);
1954 } /* }}} void cna_config_volume_perf_option */
1956 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
1957 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
1958 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
1959 const oconfig_item_t *ci)
1963 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1965 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1970 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
1971 il = cvp->il_octets;
1972 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
1973 il = cvp->il_operations;
1974 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
1975 il = cvp->il_latency;
1979 if (ci->values[0].value.boolean)
1980 ignorelist_set_invert (il, /* invert = */ 0);
1982 ignorelist_set_invert (il, /* invert = */ 1);
1983 } /* }}} void cna_config_volume_perf_default */
1985 /* Corresponds to a <Disks /> block */
1990 * IgnoreSelectedIO false
1994 * IgnoreSelectedOps false
1998 * IgnoreSelectedLatency false
2001 /* Corresponds to a <VolumePerf /> block */
2002 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
2003 const oconfig_item_t *ci)
2005 cfg_volume_perf_t *cfg_volume_perf;
2008 if ((host == NULL) || (ci == NULL))
2011 if (host->cfg_volume_perf == NULL)
2013 cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
2014 if (cfg_volume_perf == NULL)
2016 memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
2018 /* Set default flags */
2019 cfg_volume_perf->query = NULL;
2020 cfg_volume_perf->volumes = NULL;
2022 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
2023 if (cfg_volume_perf->il_octets == NULL)
2025 sfree (cfg_volume_perf);
2029 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
2030 if (cfg_volume_perf->il_operations == NULL)
2032 ignorelist_free (cfg_volume_perf->il_octets);
2033 sfree (cfg_volume_perf);
2037 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
2038 if (cfg_volume_perf->il_latency == NULL)
2040 ignorelist_free (cfg_volume_perf->il_octets);
2041 ignorelist_free (cfg_volume_perf->il_operations);
2042 sfree (cfg_volume_perf);
2046 host->cfg_volume_perf = cfg_volume_perf;
2048 cfg_volume_perf = host->cfg_volume_perf;
2050 for (i = 0; i < ci->children_num; ++i) {
2051 oconfig_item_t *item = ci->children + i;
2053 /* if (!item || !item->key || !*item->key) continue; */
2054 if (strcasecmp(item->key, "Interval") == 0)
2055 cna_config_get_interval (item, &cfg_volume_perf->interval);
2056 else if (!strcasecmp(item->key, "GetIO"))
2057 cna_config_volume_perf_option (cfg_volume_perf, item);
2058 else if (!strcasecmp(item->key, "GetOps"))
2059 cna_config_volume_perf_option (cfg_volume_perf, item);
2060 else if (!strcasecmp(item->key, "GetLatency"))
2061 cna_config_volume_perf_option (cfg_volume_perf, item);
2062 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
2063 cna_config_volume_perf_default (cfg_volume_perf, item);
2064 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
2065 cna_config_volume_perf_default (cfg_volume_perf, item);
2066 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2067 cna_config_volume_perf_default (cfg_volume_perf, item);
2069 WARNING ("netapp plugin: The option %s is not allowed within "
2070 "`VolumePerf' blocks.", item->key);
2074 } /* }}} int cna_config_volume_performance */
2076 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2077 * <VolumeUsage /> block. */
2078 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
2079 const oconfig_item_t *ci)
2084 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2086 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2091 name = ci->values[0].value.string;
2093 if (strcasecmp ("GetCapacity", ci->key) == 0)
2094 il = cvu->il_capacity;
2095 else if (strcasecmp ("GetSnapshot", ci->key) == 0)
2096 il = cvu->il_snapshot;
2100 ignorelist_add (il, name);
2101 } /* }}} void cna_config_volume_usage_option */
2103 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2104 * options within a <VolumeUsage /> block. */
2105 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
2106 const oconfig_item_t *ci)
2110 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2112 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2117 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2118 il = cvu->il_capacity;
2119 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2120 il = cvu->il_snapshot;
2124 if (ci->values[0].value.boolean)
2125 ignorelist_set_invert (il, /* invert = */ 0);
2127 ignorelist_set_invert (il, /* invert = */ 1);
2128 } /* }}} void cna_config_volume_usage_default */
2130 /* Corresponds to a <Disks /> block */
2131 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2132 cfg_disk_t *cfg_disk;
2135 if ((host == NULL) || (ci == NULL))
2138 if (host->cfg_disk == NULL)
2140 cfg_disk = malloc (sizeof (*cfg_disk));
2141 if (cfg_disk == NULL)
2143 memset (cfg_disk, 0, sizeof (*cfg_disk));
2145 /* Set default flags */
2146 cfg_disk->flags = CFG_DISK_ALL;
2147 cfg_disk->query = NULL;
2148 cfg_disk->disks = NULL;
2150 host->cfg_disk = cfg_disk;
2152 cfg_disk = host->cfg_disk;
2154 for (i = 0; i < ci->children_num; ++i) {
2155 oconfig_item_t *item = ci->children + i;
2157 /* if (!item || !item->key || !*item->key) continue; */
2158 if (strcasecmp(item->key, "Interval") == 0)
2159 cna_config_get_interval (item, &cfg_disk->interval);
2160 else if (strcasecmp(item->key, "GetBusy") == 0)
2161 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2164 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2166 NOTICE ("netapp plugin: All disk related values have been disabled. "
2167 "Collection of per-disk data will be disabled entirely.");
2168 free_cfg_disk (host->cfg_disk);
2169 host->cfg_disk = NULL;
2173 } /* }}} int cna_config_disk */
2175 /* Corresponds to a <WAFL /> block */
2176 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2178 cfg_wafl_t *cfg_wafl;
2181 if ((host == NULL) || (ci == NULL))
2184 if (host->cfg_wafl == NULL)
2186 cfg_wafl = malloc (sizeof (*cfg_wafl));
2187 if (cfg_wafl == NULL)
2189 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
2191 /* Set default flags */
2192 cfg_wafl->flags = CFG_WAFL_ALL;
2194 host->cfg_wafl = cfg_wafl;
2196 cfg_wafl = host->cfg_wafl;
2198 for (i = 0; i < ci->children_num; ++i) {
2199 oconfig_item_t *item = ci->children + i;
2201 if (strcasecmp(item->key, "Interval") == 0)
2202 cna_config_get_interval (item, &cfg_wafl->interval);
2203 else if (!strcasecmp(item->key, "GetNameCache"))
2204 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2205 else if (!strcasecmp(item->key, "GetDirCache"))
2206 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2207 else if (!strcasecmp(item->key, "GetBufferCache"))
2208 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2209 else if (!strcasecmp(item->key, "GetInodeCache"))
2210 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2212 WARNING ("netapp plugin: The %s config option is not allowed within "
2213 "`WAFL' blocks.", item->key);
2216 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2218 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2219 "Collection of WAFL data will be disabled entirely.");
2220 free_cfg_wafl (host->cfg_wafl);
2221 host->cfg_wafl = NULL;
2225 } /* }}} int cna_config_wafl */
2229 * GetCapacity "vol0"
2230 * GetCapacity "vol1"
2231 * GetCapacity "vol2"
2232 * GetCapacity "vol3"
2233 * GetCapacity "vol4"
2234 * IgnoreSelectedCapacity false
2236 * GetSnapshot "vol0"
2237 * GetSnapshot "vol3"
2238 * GetSnapshot "vol4"
2239 * GetSnapshot "vol7"
2240 * IgnoreSelectedSnapshot false
2243 /* Corresponds to a <VolumeUsage /> block */
2244 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2245 const oconfig_item_t *ci)
2247 cfg_volume_usage_t *cfg_volume_usage;
2250 if ((host == NULL) || (ci == NULL))
2253 if (host->cfg_volume_usage == NULL)
2255 cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
2256 if (cfg_volume_usage == NULL)
2258 memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
2260 /* Set default flags */
2261 cfg_volume_usage->query = NULL;
2262 cfg_volume_usage->volumes = NULL;
2264 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2265 if (cfg_volume_usage->il_capacity == NULL)
2267 sfree (cfg_volume_usage);
2271 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2272 if (cfg_volume_usage->il_snapshot == NULL)
2274 ignorelist_free (cfg_volume_usage->il_capacity);
2275 sfree (cfg_volume_usage);
2279 host->cfg_volume_usage = cfg_volume_usage;
2281 cfg_volume_usage = host->cfg_volume_usage;
2283 for (i = 0; i < ci->children_num; ++i) {
2284 oconfig_item_t *item = ci->children + i;
2286 /* if (!item || !item->key || !*item->key) continue; */
2287 if (strcasecmp(item->key, "Interval") == 0)
2288 cna_config_get_interval (item, &cfg_volume_usage->interval);
2289 else if (!strcasecmp(item->key, "GetCapacity"))
2290 cna_config_volume_usage_option (cfg_volume_usage, item);
2291 else if (!strcasecmp(item->key, "GetSnapshot"))
2292 cna_config_volume_usage_option (cfg_volume_usage, item);
2293 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2294 cna_config_volume_usage_default (cfg_volume_usage, item);
2295 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2296 cna_config_volume_usage_default (cfg_volume_usage, item);
2298 WARNING ("netapp plugin: The option %s is not allowed within "
2299 "`VolumeUsage' blocks.", item->key);
2303 } /* }}} int cna_config_volume_usage */
2305 /* Corresponds to a <System /> block */
2306 static int cna_config_system (host_config_t *host, /* {{{ */
2309 cfg_system_t *cfg_system;
2312 if ((host == NULL) || (ci == NULL))
2315 if (host->cfg_system == NULL)
2317 cfg_system = malloc (sizeof (*cfg_system));
2318 if (cfg_system == NULL)
2320 memset (cfg_system, 0, sizeof (*cfg_system));
2322 /* Set default flags */
2323 cfg_system->flags = CFG_SYSTEM_ALL;
2324 cfg_system->query = NULL;
2326 host->cfg_system = cfg_system;
2328 cfg_system = host->cfg_system;
2330 for (i = 0; i < ci->children_num; ++i) {
2331 oconfig_item_t *item = ci->children + i;
2333 if (strcasecmp(item->key, "Interval") == 0) {
2334 cna_config_get_interval (item, &cfg_system->interval);
2335 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2336 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2337 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2338 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2339 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2340 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2341 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2342 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2344 WARNING ("netapp plugin: The %s config option is not allowed within "
2345 "`System' blocks.", item->key);
2349 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2351 NOTICE ("netapp plugin: All system related values have been disabled. "
2352 "Collection of system data will be disabled entirely.");
2353 free_cfg_system (host->cfg_system);
2354 host->cfg_system = NULL;
2358 } /* }}} int cna_config_system */
2360 /* Corresponds to a <Host /> block. */
2361 static host_config_t *cna_config_host (const oconfig_item_t *ci) /* {{{ */
2363 oconfig_item_t *item;
2364 host_config_t *host;
2368 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2369 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
2373 host = malloc(sizeof(*host));
2374 memset (host, 0, sizeof (*host));
2376 host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2378 host->username = NULL;
2379 host->password = NULL;
2381 host->cfg_wafl = NULL;
2382 host->cfg_disk = NULL;
2383 host->cfg_volume_perf = NULL;
2384 host->cfg_volume_usage = NULL;
2385 host->cfg_system = NULL;
2387 status = cf_util_get_string (ci, &host->name);
2394 for (i = 0; i < ci->children_num; ++i) {
2395 item = ci->children + i;
2399 if (!strcasecmp(item->key, "Address")) {
2400 status = cf_util_get_string (item, &host->host);
2401 } else if (!strcasecmp(item->key, "Port")) {
2404 tmp = cf_util_get_port_number (item);
2407 } else if (!strcasecmp(item->key, "Protocol")) {
2408 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"))) {
2409 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2412 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2413 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2414 } else if (!strcasecmp(item->key, "User")) {
2415 status = cf_util_get_string (item, &host->username);
2416 } else if (!strcasecmp(item->key, "Password")) {
2417 status = cf_util_get_string (item, &host->password);
2418 } else if (!strcasecmp(item->key, "Interval")) {
2419 status = cf_util_get_cdtime (item, &host->interval);
2420 } else if (!strcasecmp(item->key, "WAFL")) {
2421 cna_config_wafl(host, item);
2422 } else if (!strcasecmp(item->key, "Disks")) {
2423 cna_config_disk(host, item);
2424 } else if (!strcasecmp(item->key, "VolumePerf")) {
2425 cna_config_volume_performance(host, item);
2426 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2427 cna_config_volume_usage(host, item);
2428 } else if (!strcasecmp(item->key, "System")) {
2429 cna_config_system(host, item);
2431 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
2432 item->key, ci->values[0].value.string);
2439 if (host->host == NULL)
2440 host->host = strdup (host->name);
2442 if (host->host == NULL)
2445 if (host->port <= 0)
2446 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2448 if ((host->username == NULL) || (host->password == NULL)) {
2449 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2450 "Ignoring host block.", host->name);
2456 free_host_config (host);
2461 } /* }}} host_config_t *cna_config_host */
2464 * Callbacks registered with the daemon
2466 * Pretty standard stuff here.
2468 static int cna_init_host (host_config_t *host) /* {{{ */
2473 if (host->srv != NULL)
2476 /* Request version 1.1 of the ONTAP API */
2477 host->srv = na_server_open(host->host,
2478 /* major version = */ 1, /* minor version = */ 1);
2479 if (host->srv == NULL) {
2480 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
2484 na_server_set_transport_type(host->srv, host->protocol,
2485 /* transportarg = */ NULL);
2486 na_server_set_port(host->srv, host->port);
2487 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
2488 na_server_adminuser(host->srv, host->username, host->password);
2489 na_server_set_timeout(host->srv, 5 /* seconds */);
2492 } /* }}} int cna_init_host */
2494 static int cna_init (void) /* {{{ */
2498 memset (err, 0, sizeof (err));
2499 if (!na_startup(err, sizeof(err))) {
2500 err[sizeof (err) - 1] = 0;
2501 ERROR("netapp plugin: Error initializing netapp API: %s", err);
2506 } /* }}} cna_init */
2508 static int cna_read (user_data_t *ud) { /* {{{ */
2509 host_config_t *host;
2512 if ((ud == NULL) || (ud->data == NULL))
2517 status = cna_init_host (host);
2521 cna_query_wafl (host);
2522 cna_query_disk (host);
2523 cna_query_volume_perf (host);
2524 cna_query_volume_usage (host);
2525 cna_query_system (host);
2528 } /* }}} int cna_read */
2530 static int cna_config (oconfig_item_t *ci) { /* {{{ */
2532 oconfig_item_t *item;
2534 for (i = 0; i < ci->children_num; ++i) {
2535 item = ci->children + i;
2537 if (strcasecmp(item->key, "Host") == 0)
2539 host_config_t *host;
2541 struct timespec interval;
2544 host = cna_config_host (item);
2548 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name);
2550 CDTIME_T_TO_TIMESPEC (host->interval, &interval);
2552 memset (&ud, 0, sizeof (ud));
2554 ud.free_func = (void (*) (void *)) free_host_config;
2556 plugin_register_complex_read (/* group = */ NULL, cb_name,
2557 /* callback = */ cna_read,
2558 /* interval = */ (host->interval > 0) ? &interval : NULL,
2559 /* user data = */ &ud);
2562 else /* if (item->key != "Host") */
2564 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
2568 } /* }}} int cna_config */
2570 static int cna_shutdown (void) /* {{{ */
2572 /* Clean up system resources and stuff. */
2576 } /* }}} int cna_shutdown */
2578 void module_register(void) {
2579 plugin_register_complex_config("netapp", cna_config);
2580 plugin_register_init("netapp", cna_init);
2581 plugin_register_shutdown("netapp", cna_shutdown);
2584 /* vim: set sw=2 ts=2 noet fdm=marker : */