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,
569 time_t timestamp, int interval)
571 value_list_t vl = VALUE_LIST_INIT;
574 vl.values_len = values_len;
580 vl.interval = interval;
583 sstrncpy (vl.host, host, sizeof (vl.host));
585 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
586 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
587 if (plugin_inst != NULL)
588 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
589 sstrncpy (vl.type, type, sizeof (vl.type));
590 if (type_inst != NULL)
591 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
593 return (plugin_dispatch_values (&vl));
594 } /* }}} int submit_uint64 */
596 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
597 const char *type, const char *type_inst, counter_t val0, counter_t val1,
598 time_t timestamp, int interval)
602 values[0].counter = val0;
603 values[1].counter = val1;
605 return (submit_values (host, plugin_inst, type, type_inst,
606 values, 2, timestamp, interval));
607 } /* }}} int submit_two_counters */
609 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
610 const char *type, const char *type_inst, counter_t counter, time_t timestamp, int interval)
616 return (submit_values (host, plugin_inst, type, type_inst,
617 &v, 1, timestamp, interval));
618 } /* }}} int submit_counter */
620 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
621 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
622 time_t timestamp, int interval)
626 values[0].gauge = val0;
627 values[1].gauge = val1;
629 return (submit_values (host, plugin_inst, type, type_inst,
630 values, 2, timestamp, interval));
631 } /* }}} int submit_two_gauge */
633 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
634 const char *type, const char *type_inst, double d, time_t timestamp, int interval)
638 v.gauge = (gauge_t) d;
640 return (submit_values (host, plugin_inst, type, type_inst,
641 &v, 1, timestamp, interval));
642 } /* }}} int submit_uint64 */
644 /* Calculate hit ratio from old and new counters and submit the resulting
645 * percentage. Used by "submit_wafl_data". */
646 static int submit_cache_ratio (const char *host, /* {{{ */
647 const char *plugin_inst,
648 const char *type_inst,
658 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
662 hits = new_hits - old_hits;
663 misses = new_misses - old_misses;
665 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
670 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
671 &v, 1, timestamp, interval));
672 } /* }}} int submit_cache_ratio */
674 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
675 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
676 cfg_wafl_t *old_data, const cfg_wafl_t *new_data, int interval)
678 /* Submit requested counters */
679 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
680 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
681 submit_cache_ratio (hostname, instance, "name_cache_hit",
682 new_data->name_cache_hit, new_data->name_cache_miss,
683 old_data->name_cache_hit, old_data->name_cache_miss,
684 new_data->timestamp, interval);
686 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
687 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
688 submit_cache_ratio (hostname, instance, "find_dir_hit",
689 new_data->find_dir_hit, new_data->find_dir_miss,
690 old_data->find_dir_hit, old_data->find_dir_miss,
691 new_data->timestamp, interval);
693 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
694 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
695 submit_cache_ratio (hostname, instance, "buf_hash_hit",
696 new_data->buf_hash_hit, new_data->buf_hash_miss,
697 old_data->buf_hash_hit, old_data->buf_hash_miss,
698 new_data->timestamp, interval);
700 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
701 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
702 submit_cache_ratio (hostname, instance, "inode_cache_hit",
703 new_data->inode_cache_hit, new_data->inode_cache_miss,
704 old_data->inode_cache_hit, old_data->inode_cache_miss,
705 new_data->timestamp, interval);
707 /* Clear old HAVE_* flags */
708 old_data->flags &= ~HAVE_WAFL_ALL;
710 /* Copy all counters */
711 old_data->timestamp = new_data->timestamp;
712 old_data->name_cache_hit = new_data->name_cache_hit;
713 old_data->name_cache_miss = new_data->name_cache_miss;
714 old_data->find_dir_hit = new_data->find_dir_hit;
715 old_data->find_dir_miss = new_data->find_dir_miss;
716 old_data->buf_hash_hit = new_data->buf_hash_hit;
717 old_data->buf_hash_miss = new_data->buf_hash_miss;
718 old_data->inode_cache_hit = new_data->inode_cache_hit;
719 old_data->inode_cache_miss = new_data->inode_cache_miss;
721 /* Copy HAVE_* flags */
722 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
725 } /* }}} int submit_wafl_data */
727 /* Submits volume performance data to the daemon, taking care to honor and
728 * update flags appropriately. */
729 static int submit_volume_perf_data (const char *hostname, /* {{{ */
730 data_volume_perf_t *old_data,
731 const data_volume_perf_t *new_data, int interval)
733 char plugin_instance[DATA_MAX_NAME_LEN];
735 if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
738 ssnprintf (plugin_instance, sizeof (plugin_instance),
739 "volume-%s", old_data->name);
741 /* Check for and submit disk-octet values */
742 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
743 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
745 submit_two_counters (hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
746 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp, interval);
749 /* Check for and submit disk-operations values */
750 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
751 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
753 submit_two_counters (hostname, plugin_instance, "disk_ops", /* type instance = */ NULL,
754 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp, interval);
757 /* Check for, calculate and submit disk-latency values */
758 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
759 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
760 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
761 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
762 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
764 gauge_t latency_per_op_read;
765 gauge_t latency_per_op_write;
767 latency_per_op_read = NAN;
768 latency_per_op_write = NAN;
770 /* Check if a counter wrapped around. */
771 if ((new_data->read_ops > old_data->read_ops)
772 && (new_data->read_latency > old_data->read_latency))
774 uint64_t diff_ops_read;
775 uint64_t diff_latency_read;
777 diff_ops_read = new_data->read_ops - old_data->read_ops;
778 diff_latency_read = new_data->read_latency - old_data->read_latency;
780 if (diff_ops_read > 0)
781 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
784 if ((new_data->write_ops > old_data->write_ops)
785 && (new_data->write_latency > old_data->write_latency))
787 uint64_t diff_ops_write;
788 uint64_t diff_latency_write;
790 diff_ops_write = new_data->write_ops - old_data->write_ops;
791 diff_latency_write = new_data->write_latency - old_data->write_latency;
793 if (diff_ops_write > 0)
794 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
797 submit_two_gauge (hostname, plugin_instance, "disk_latency", /* type instance = */ NULL,
798 latency_per_op_read, latency_per_op_write, new_data->timestamp, interval);
801 /* Clear all HAVE_* flags. */
802 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
804 /* Copy all counters */
805 old_data->timestamp = new_data->timestamp;
806 old_data->read_bytes = new_data->read_bytes;
807 old_data->write_bytes = new_data->write_bytes;
808 old_data->read_ops = new_data->read_ops;
809 old_data->write_ops = new_data->write_ops;
810 old_data->read_latency = new_data->read_latency;
811 old_data->write_latency = new_data->write_latency;
813 /* Copy the HAVE_* flags */
814 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
817 } /* }}} int submit_volume_perf_data */
822 * These functions are called with appropriate data returned by the libnetapp
823 * interface which is parsed and submitted with the above functions.
825 /* Data corresponding to <WAFL /> */
826 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
827 na_elem_t *data, int interval)
829 cfg_wafl_t perf_data;
830 const char *plugin_inst;
832 na_elem_t *instances;
834 na_elem_iter_t counter_iter;
836 memset (&perf_data, 0, sizeof (perf_data));
838 perf_data.timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
840 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
841 if (instances == NULL)
843 ERROR ("netapp plugin: cna_handle_wafl_data: "
844 "na_elem_child (\"instances\") failed "
845 "for host %s.", hostname);
849 plugin_inst = na_child_get_string(instances, "name");
850 if (plugin_inst == NULL)
852 ERROR ("netapp plugin: cna_handle_wafl_data: "
853 "na_child_get_string (\"name\") failed "
854 "for host %s.", hostname);
858 /* Iterate over all counters */
859 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
860 for (counter = na_iterator_next (&counter_iter);
862 counter = na_iterator_next (&counter_iter))
867 name = na_child_get_string(counter, "name");
871 value = na_child_get_uint64(counter, "value", UINT64_MAX);
872 if (value == UINT64_MAX)
875 if (!strcmp(name, "name_cache_hit")) {
876 perf_data.name_cache_hit = value;
877 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
878 } else if (!strcmp(name, "name_cache_miss")) {
879 perf_data.name_cache_miss = value;
880 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
881 } else if (!strcmp(name, "find_dir_hit")) {
882 perf_data.find_dir_hit = value;
883 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
884 } else if (!strcmp(name, "find_dir_miss")) {
885 perf_data.find_dir_miss = value;
886 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
887 } else if (!strcmp(name, "buf_hash_hit")) {
888 perf_data.buf_hash_hit = value;
889 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
890 } else if (!strcmp(name, "buf_hash_miss")) {
891 perf_data.buf_hash_miss = value;
892 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
893 } else if (!strcmp(name, "inode_cache_hit")) {
894 perf_data.inode_cache_hit = value;
895 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
896 } else if (!strcmp(name, "inode_cache_miss")) {
897 perf_data.inode_cache_miss = value;
898 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
900 DEBUG("netapp plugin: cna_handle_wafl_data: "
901 "Found unexpected child: %s "
902 "for host %s.", name, hostname);
906 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data, interval));
907 } /* }}} void cna_handle_wafl_data */
909 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
916 if (cw->query != NULL)
919 cw->query = na_elem_new("perf-object-get-instances");
920 if (cw->query == NULL)
922 ERROR ("netapp plugin: na_elem_new failed.");
925 na_child_add_string (cw->query, "objectname", "wafl");
927 e = na_elem_new("counters");
930 na_elem_free (cw->query);
932 ERROR ("netapp plugin: na_elem_new failed.");
935 na_child_add_string(e, "counter", "name_cache_hit");
936 na_child_add_string(e, "counter", "name_cache_miss");
937 na_child_add_string(e, "counter", "find_dir_hit");
938 na_child_add_string(e, "counter", "find_dir_miss");
939 na_child_add_string(e, "counter", "buf_hash_hit");
940 na_child_add_string(e, "counter", "buf_hash_miss");
941 na_child_add_string(e, "counter", "inode_cache_hit");
942 na_child_add_string(e, "counter", "inode_cache_miss");
944 na_child_add(cw->query, e);
947 } /* }}} int cna_setup_wafl */
949 static int cna_query_wafl (host_config_t *host) /* {{{ */
958 /* If WAFL was not configured, return without doing anything. */
959 if (host->cfg_wafl == NULL)
963 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
966 status = cna_setup_wafl (host->cfg_wafl);
969 assert (host->cfg_wafl->query != NULL);
971 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
972 if (na_results_status (data) != NA_OK)
974 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed for host %s: %s",
975 host->name, na_results_reason (data));
980 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data, host->interval);
983 host->cfg_wafl->interval.last_read = now;
987 } /* }}} int cna_query_wafl */
989 /* Data corresponding to <Disks /> */
990 static int cna_handle_disk_data (const char *hostname, /* {{{ */
991 cfg_disk_t *cfg_disk, na_elem_t *data, int interval)
994 na_elem_t *instances;
996 na_elem_iter_t instance_iter;
997 disk_t *worst_disk = NULL;
999 if ((cfg_disk == NULL) || (data == NULL))
1002 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
1004 instances = na_elem_child (data, "instances");
1005 if (instances == NULL)
1007 ERROR ("netapp plugin: cna_handle_disk_data: "
1008 "na_elem_child (\"instances\") failed "
1009 "for host %s.", hostname);
1013 /* Iterate over all children */
1014 instance_iter = na_child_iterator (instances);
1015 for (instance = na_iterator_next (&instance_iter);
1017 instance = na_iterator_next(&instance_iter))
1022 na_elem_iter_t counter_iterator;
1025 memset (&new_data, 0, sizeof (new_data));
1026 new_data.timestamp = timestamp;
1027 new_data.disk_busy_percent = NAN;
1029 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1030 if (old_data == NULL)
1033 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1034 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1035 for (counter = na_iterator_next(&counter_iterator);
1037 counter = na_iterator_next(&counter_iterator))
1042 name = na_child_get_string(counter, "name");
1046 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1047 if (value == UINT64_MAX)
1050 if (strcmp(name, "disk_busy") == 0)
1052 new_data.disk_busy = value;
1053 new_data.flags |= HAVE_DISK_BUSY;
1055 else if (strcmp(name, "base_for_disk_busy") == 0)
1057 new_data.base_for_disk_busy = value;
1058 new_data.flags |= HAVE_DISK_BASE;
1062 DEBUG ("netapp plugin: cna_handle_disk_data: "
1063 "Counter not handled: %s = %"PRIu64,
1068 /* If all required counters are available and did not just wrap around,
1069 * calculate the busy percentage. Otherwise, the value is initialized to
1070 * NAN at the top of the for-loop. */
1071 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1072 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1073 && (new_data.disk_busy >= old_data->disk_busy)
1074 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1079 busy_diff = new_data.disk_busy - old_data->disk_busy;
1080 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1082 new_data.disk_busy_percent = 100.0
1083 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1086 /* Clear HAVE_* flags */
1087 old_data->flags &= ~HAVE_DISK_ALL;
1090 old_data->timestamp = new_data.timestamp;
1091 old_data->disk_busy = new_data.disk_busy;
1092 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1093 old_data->disk_busy_percent = new_data.disk_busy_percent;
1096 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1098 if ((worst_disk == NULL)
1099 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1100 worst_disk = old_data;
1101 } /* for (all disks) */
1103 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1104 submit_double (hostname, "system", "percent", "disk_busy",
1105 worst_disk->disk_busy_percent, timestamp, interval);
1108 } /* }}} int cna_handle_disk_data */
1110 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1117 if (cd->query != NULL)
1120 cd->query = na_elem_new ("perf-object-get-instances");
1121 if (cd->query == NULL)
1123 ERROR ("netapp plugin: na_elem_new failed.");
1126 na_child_add_string (cd->query, "objectname", "disk");
1128 e = na_elem_new("counters");
1131 na_elem_free (cd->query);
1133 ERROR ("netapp plugin: na_elem_new failed.");
1136 na_child_add_string(e, "counter", "disk_busy");
1137 na_child_add_string(e, "counter", "base_for_disk_busy");
1138 na_child_add(cd->query, e);
1141 } /* }}} int cna_setup_disk */
1143 static int cna_query_disk (host_config_t *host) /* {{{ */
1152 /* If the user did not configure disk statistics, return without doing
1154 if (host->cfg_disk == NULL)
1158 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1161 status = cna_setup_disk (host->cfg_disk);
1164 assert (host->cfg_disk->query != NULL);
1166 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1167 if (na_results_status (data) != NA_OK)
1169 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed for host %s: %s",
1170 host->name, na_results_reason (data));
1171 na_elem_free (data);
1175 status = cna_handle_disk_data (host->name, host->cfg_disk, data, host->interval);
1178 host->cfg_disk->interval.last_read = now;
1180 na_elem_free (data);
1182 } /* }}} int cna_query_disk */
1184 /* Data corresponding to <VolumePerf /> */
1185 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1186 cfg_volume_perf_t *cvp, na_elem_t *data, int interval)
1189 na_elem_t *elem_instances;
1190 na_elem_iter_t iter_instances;
1191 na_elem_t *elem_instance;
1193 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
1195 elem_instances = na_elem_child(data, "instances");
1196 if (elem_instances == NULL)
1198 ERROR ("netapp plugin: handle_volume_perf_data: "
1199 "na_elem_child (\"instances\") failed "
1200 "for host %s.", hostname);
1204 iter_instances = na_child_iterator (elem_instances);
1205 for (elem_instance = na_iterator_next(&iter_instances);
1206 elem_instance != NULL;
1207 elem_instance = na_iterator_next(&iter_instances))
1211 data_volume_perf_t perf_data;
1212 data_volume_perf_t *v;
1214 na_elem_t *elem_counters;
1215 na_elem_iter_t iter_counters;
1216 na_elem_t *elem_counter;
1218 memset (&perf_data, 0, sizeof (perf_data));
1219 perf_data.timestamp = timestamp;
1221 name = na_child_get_string (elem_instance, "name");
1225 /* get_volume_perf may return NULL if this volume is to be ignored. */
1226 v = get_volume_perf (cvp, name);
1230 elem_counters = na_elem_child (elem_instance, "counters");
1231 if (elem_counters == NULL)
1234 iter_counters = na_child_iterator (elem_counters);
1235 for (elem_counter = na_iterator_next(&iter_counters);
1236 elem_counter != NULL;
1237 elem_counter = na_iterator_next(&iter_counters))
1242 name = na_child_get_string (elem_counter, "name");
1246 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1247 if (value == UINT64_MAX)
1250 if (!strcmp(name, "read_data")) {
1251 perf_data.read_bytes = value;
1252 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1253 } else if (!strcmp(name, "write_data")) {
1254 perf_data.write_bytes = value;
1255 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1256 } else if (!strcmp(name, "read_ops")) {
1257 perf_data.read_ops = value;
1258 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1259 } else if (!strcmp(name, "write_ops")) {
1260 perf_data.write_ops = value;
1261 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1262 } else if (!strcmp(name, "read_latency")) {
1263 perf_data.read_latency = value;
1264 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1265 } else if (!strcmp(name, "write_latency")) {
1266 perf_data.write_latency = value;
1267 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1269 } /* for (elem_counter) */
1271 submit_volume_perf_data (hostname, v, &perf_data, interval);
1272 } /* for (volume) */
1275 } /* }}} int cna_handle_volume_perf_data */
1277 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1284 if (cd->query != NULL)
1287 cd->query = na_elem_new ("perf-object-get-instances");
1288 if (cd->query == NULL)
1290 ERROR ("netapp plugin: na_elem_new failed.");
1293 na_child_add_string (cd->query, "objectname", "volume");
1295 e = na_elem_new("counters");
1298 na_elem_free (cd->query);
1300 ERROR ("netapp plugin: na_elem_new failed.");
1303 na_child_add_string(e, "counter", "read_ops");
1304 na_child_add_string(e, "counter", "write_ops");
1305 na_child_add_string(e, "counter", "read_data");
1306 na_child_add_string(e, "counter", "write_data");
1307 na_child_add_string(e, "counter", "read_latency");
1308 na_child_add_string(e, "counter", "write_latency");
1309 na_child_add(cd->query, e);
1312 } /* }}} int cna_setup_volume_perf */
1314 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1323 /* If the user did not configure volume performance statistics, return
1324 * without doing anything. */
1325 if (host->cfg_volume_perf == NULL)
1329 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1332 status = cna_setup_volume_perf (host->cfg_volume_perf);
1335 assert (host->cfg_volume_perf->query != NULL);
1337 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1338 if (na_results_status (data) != NA_OK)
1340 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed for host %s: %s",
1341 host->name, na_results_reason (data));
1342 na_elem_free (data);
1346 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data, host->interval);
1349 host->cfg_volume_perf->interval.last_read = now;
1351 na_elem_free (data);
1353 } /* }}} int cna_query_volume_perf */
1355 /* Data corresponding to <VolumeUsage /> */
1356 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1357 cfg_volume_usage_t *cfg_volume, int interval)
1359 data_volume_usage_t *v;
1361 for (v = cfg_volume->volumes; v != NULL; v = v->next)
1363 char plugin_instance[DATA_MAX_NAME_LEN];
1365 uint64_t norm_used = v->norm_used;
1366 uint64_t norm_free = v->norm_free;
1367 uint64_t sis_saved = v->sis_saved;
1368 uint64_t snap_reserve_used = 0;
1369 uint64_t snap_reserve_free = v->snap_reserved;
1370 uint64_t snap_norm_used = v->snap_used;
1372 ssnprintf (plugin_instance, sizeof (plugin_instance),
1373 "volume-%s", v->name);
1375 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD)) {
1376 if (v->snap_reserved > v->snap_used) {
1377 snap_reserve_free = v->snap_reserved - v->snap_used;
1378 snap_reserve_used = v->snap_used;
1381 snap_reserve_free = 0;
1382 snap_reserve_used = v->snap_reserved;
1383 snap_norm_used = v->snap_used - v->snap_reserved;
1387 /* The space used by snapshots but not reserved for them is included in
1388 * both, norm_used and snap_norm_used. If possible, subtract this here. */
1389 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED))
1391 if (norm_used >= snap_norm_used)
1392 norm_used -= snap_norm_used;
1395 ERROR ("netapp plugin: (norm_used = %"PRIu64") < (snap_norm_used = "
1396 "%"PRIu64") for host %s. Invalidating both.",
1397 norm_used, snap_norm_used, hostname);
1398 v->flags &= ~(HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED);
1402 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1403 submit_double (hostname, /* plugin instance = */ plugin_instance,
1404 "df_complex", "free",
1405 (double) norm_free, /* timestamp = */ 0, interval);
1407 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1408 submit_double (hostname, /* plugin instance = */ plugin_instance,
1409 "df_complex", "sis_saved",
1410 (double) sis_saved, /* timestamp = */ 0, interval);
1412 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1413 submit_double (hostname, /* plugin instance = */ plugin_instance,
1414 "df_complex", "used",
1415 (double) norm_used, /* timestamp = */ 0, interval);
1417 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1418 submit_double (hostname, /* plugin instance = */ plugin_instance,
1419 "df_complex", "snap_reserved",
1420 (double) snap_reserve_free, /* timestamp = */ 0, interval);
1422 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
1423 submit_double (hostname, /* plugin instance = */ plugin_instance,
1424 "df_complex", "snap_reserve_used",
1425 (double) snap_reserve_used, /* timestamp = */ 0, interval);
1427 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1428 submit_double (hostname, /* plugin instance = */ plugin_instance,
1429 "df_complex", "snap_normal_used",
1430 (double) snap_norm_used, /* timestamp = */ 0, interval);
1432 /* Clear all the HAVE_* flags */
1433 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1434 } /* for (v = cfg_volume->volumes) */
1437 } /* }}} int cna_submit_volume_usage_data */
1439 /* Switch the state of a volume between online and offline and send out a
1441 static int cna_change_volume_status (const char *hostname, /* {{{ */
1442 data_volume_usage_t *v)
1446 memset (&n, 0, sizeof (&n));
1447 n.time = time (NULL);
1448 sstrncpy (n.host, hostname, sizeof (n.host));
1449 sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
1450 sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance));
1452 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
1453 n.severity = NOTIF_OKAY;
1454 ssnprintf (n.message, sizeof (n.message),
1455 "Volume %s is now online.", v->name);
1456 v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
1458 n.severity = NOTIF_WARNING;
1459 ssnprintf (n.message, sizeof (n.message),
1460 "Volume %s is now offline.", v->name);
1461 v->flags |= IS_VOLUME_USAGE_OFFLINE;
1464 return (plugin_dispatch_notification (&n));
1465 } /* }}} int cna_change_volume_status */
1467 static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
1468 data_volume_usage_t *v)
1470 uint64_t snap_used = 0, value;
1471 na_elem_t *data, *elem_snap, *elem_snapshots;
1472 na_elem_iter_t iter_snap;
1474 data = na_server_invoke_elem(host->srv, v->snap_query);
1475 if (na_results_status(data) != NA_OK)
1477 if (na_results_errno(data) == EVOLUMEOFFLINE) {
1478 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
1479 cna_change_volume_status (host->name, v);
1481 ERROR ("netapp plugin: cna_handle_volume_snap_usage: na_server_invoke_elem for "
1482 "volume \"%s\" on host %s failed with error %d: %s", v->name,
1483 host->name, na_results_errno(data), na_results_reason(data));
1489 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0)
1490 cna_change_volume_status (host->name, v);
1492 elem_snapshots = na_elem_child (data, "snapshots");
1493 if (elem_snapshots == NULL)
1495 ERROR ("netapp plugin: cna_handle_volume_snap_usage: "
1496 "na_elem_child (\"snapshots\") failed "
1497 "for host %s.", host->name);
1502 iter_snap = na_child_iterator (elem_snapshots);
1503 for (elem_snap = na_iterator_next (&iter_snap);
1505 elem_snap = na_iterator_next (&iter_snap))
1507 value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
1508 /* "cumulative-total" is the total size of the oldest snapshot plus all
1509 * newer ones in blocks (1KB). We therefore are looking for the highest
1510 * number of all snapshots - that's the size required for the snapshots. */
1511 if (value > snap_used)
1514 na_elem_free (data);
1515 /* snap_used is in 1024 byte blocks */
1516 v->snap_used = snap_used * 1024;
1517 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1518 } /* }}} void cna_handle_volume_snap_usage */
1520 static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
1521 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1523 na_elem_t *elem_volume;
1524 na_elem_t *elem_volumes;
1525 na_elem_iter_t iter_volume;
1527 elem_volumes = na_elem_child (data, "volumes");
1528 if (elem_volumes == NULL)
1530 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1531 "na_elem_child (\"volumes\") failed "
1532 "for host %s.", host->name);
1536 iter_volume = na_child_iterator (elem_volumes);
1537 for (elem_volume = na_iterator_next (&iter_volume);
1538 elem_volume != NULL;
1539 elem_volume = na_iterator_next (&iter_volume))
1541 const char *volume_name, *state;
1543 data_volume_usage_t *v;
1547 const char *sis_state;
1548 uint64_t sis_saved_reported;
1550 volume_name = na_child_get_string (elem_volume, "name");
1551 if (volume_name == NULL)
1554 state = na_child_get_string (elem_volume, "state");
1555 if ((state == NULL) || (strcmp(state, "online") != 0))
1558 /* get_volume_usage may return NULL if the volume is to be ignored. */
1559 v = get_volume_usage (cfg_volume, volume_name);
1563 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1564 cna_handle_volume_snap_usage(host, v);
1566 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1569 /* 2^4 exa-bytes? This will take a while ;) */
1570 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1571 if (value != UINT64_MAX) {
1572 v->norm_free = value;
1573 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1576 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1577 if (value != UINT64_MAX) {
1578 v->norm_used = value;
1579 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1582 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1583 if (value != UINT64_MAX) {
1584 /* 1 block == 1024 bytes as per API docs */
1585 v->snap_reserved = 1024 * value;
1586 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1589 sis = na_elem_child(elem_volume, "sis");
1593 sis_state = na_child_get_string(sis, "state");
1594 if (sis_state == NULL)
1597 /* If SIS is not enabled, there's nothing left to do for this volume. */
1598 if (strcmp ("enabled", sis_state) != 0)
1601 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1602 if (sis_saved_reported == UINT64_MAX)
1605 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1606 if ((sis_saved_reported >> 32) != 0) {
1607 /* In case they ever fix this bug. */
1608 v->sis_saved = sis_saved_reported;
1609 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1610 } else { /* really hacky work-around code. {{{ */
1611 uint64_t sis_saved_percent;
1612 uint64_t sis_saved_guess;
1613 uint64_t overflow_guess;
1614 uint64_t guess1, guess2, guess3;
1616 /* Check if we have v->norm_used. Without it, we cannot calculate
1617 * sis_saved_guess. */
1618 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1621 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1622 if (sis_saved_percent > 100)
1625 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1626 * will hopefully be fixed in later versions. To work around the bug, try
1627 * to figure out how often the 32bit integer wrapped around by using the
1628 * "percentage-saved" value. Because the percentage is in the range
1629 * [0-100], this should work as long as the saved space does not exceed
1631 /* percentage-saved = size-saved / (size-saved + size-used) */
1632 if (sis_saved_percent < 100)
1633 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1635 sis_saved_guess = v->norm_used;
1637 overflow_guess = sis_saved_guess >> 32;
1638 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1639 guess2 = (overflow_guess << 32) + sis_saved_reported;
1640 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1642 if (sis_saved_guess < guess2) {
1643 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1644 v->sis_saved = guess1;
1646 v->sis_saved = guess2;
1648 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1649 v->sis_saved = guess2;
1651 v->sis_saved = guess3;
1653 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1654 } /* }}} end of 32-bit workaround */
1655 } /* for (elem_volume) */
1657 return (cna_submit_volume_usage_data (host->name, cfg_volume, host->interval));
1658 } /* }}} int cna_handle_volume_usage_data */
1660 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1665 if (cvu->query != NULL)
1668 cvu->query = na_elem_new ("volume-list-info");
1669 if (cvu->query == NULL)
1671 ERROR ("netapp plugin: na_elem_new failed.");
1676 } /* }}} int cna_setup_volume_usage */
1678 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1687 /* If the user did not configure volume_usage statistics, return without
1688 * doing anything. */
1689 if (host->cfg_volume_usage == NULL)
1693 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1696 status = cna_setup_volume_usage (host->cfg_volume_usage);
1699 assert (host->cfg_volume_usage->query != NULL);
1701 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1702 if (na_results_status (data) != NA_OK)
1704 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed for host %s: %s",
1705 host->name, na_results_reason (data));
1706 na_elem_free (data);
1710 status = cna_handle_volume_usage_data (host, host->cfg_volume_usage, data);
1713 host->cfg_volume_usage->interval.last_read = now;
1715 na_elem_free (data);
1717 } /* }}} int cna_query_volume_usage */
1719 /* Data corresponding to <System /> */
1720 static int cna_handle_system_data (const char *hostname, /* {{{ */
1721 cfg_system_t *cfg_system, na_elem_t *data, int interval)
1723 na_elem_t *instances;
1725 na_elem_iter_t counter_iter;
1727 counter_t disk_read = 0, disk_written = 0;
1728 counter_t net_recv = 0, net_sent = 0;
1729 counter_t cpu_busy = 0, cpu_total = 0;
1730 uint32_t counter_flags = 0;
1732 const char *instance;
1735 timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
1737 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1738 if (instances == NULL)
1740 ERROR ("netapp plugin: cna_handle_system_data: "
1741 "na_elem_child (\"instances\") failed "
1742 "for host %s.", hostname);
1746 instance = na_child_get_string (instances, "name");
1747 if (instance == NULL)
1749 ERROR ("netapp plugin: cna_handle_system_data: "
1750 "na_child_get_string (\"name\") failed "
1751 "for host %s.", hostname);
1755 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
1756 for (counter = na_iterator_next (&counter_iter);
1758 counter = na_iterator_next (&counter_iter))
1763 name = na_child_get_string(counter, "name");
1767 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1768 if (value == UINT64_MAX)
1771 if (!strcmp(name, "disk_data_read")) {
1772 disk_read = (counter_t) (value * 1024);
1773 counter_flags |= 0x01;
1774 } else if (!strcmp(name, "disk_data_written")) {
1775 disk_written = (counter_t) (value * 1024);
1776 counter_flags |= 0x02;
1777 } else if (!strcmp(name, "net_data_recv")) {
1778 net_recv = (counter_t) (value * 1024);
1779 counter_flags |= 0x04;
1780 } else if (!strcmp(name, "net_data_sent")) {
1781 net_sent = (counter_t) (value * 1024);
1782 counter_flags |= 0x08;
1783 } else if (!strcmp(name, "cpu_busy")) {
1784 cpu_busy = (counter_t) value;
1785 counter_flags |= 0x10;
1786 } else if (!strcmp(name, "cpu_elapsed_time")) {
1787 cpu_total = (counter_t) value;
1788 counter_flags |= 0x20;
1789 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1790 && (value > 0) && (strlen(name) > 4)
1791 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1792 submit_counter (hostname, instance, "disk_ops_complex", name,
1793 (counter_t) value, timestamp, interval);
1795 } /* for (counter) */
1797 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1798 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
1799 submit_two_counters (hostname, instance, "disk_octets", NULL,
1800 disk_read, disk_written, timestamp, interval);
1802 if ((cfg_system->flags & CFG_SYSTEM_NET)
1803 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
1804 submit_two_counters (hostname, instance, "if_octets", NULL,
1805 net_recv, net_sent, timestamp, interval);
1807 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1808 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
1810 submit_counter (hostname, instance, "cpu", "system",
1811 cpu_busy, timestamp, interval);
1812 submit_counter (hostname, instance, "cpu", "idle",
1813 cpu_total - cpu_busy, timestamp, interval);
1817 } /* }}} int cna_handle_system_data */
1819 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
1824 if (cs->query != NULL)
1827 cs->query = na_elem_new ("perf-object-get-instances");
1828 if (cs->query == NULL)
1830 ERROR ("netapp plugin: na_elem_new failed.");
1833 na_child_add_string (cs->query, "objectname", "system");
1836 } /* }}} int cna_setup_system */
1838 static int cna_query_system (host_config_t *host) /* {{{ */
1847 /* If system statistics were not configured, return without doing anything. */
1848 if (host->cfg_system == NULL)
1852 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
1855 status = cna_setup_system (host->cfg_system);
1858 assert (host->cfg_system->query != NULL);
1860 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
1861 if (na_results_status (data) != NA_OK)
1863 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed for host %s: %s",
1864 host->name, na_results_reason (data));
1865 na_elem_free (data);
1869 status = cna_handle_system_data (host->name, host->cfg_system, data, host->interval);
1872 host->cfg_system->interval.last_read = now;
1874 na_elem_free (data);
1876 } /* }}} int cna_query_system */
1879 * Configuration handling
1881 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1882 * is false. On error, the flag-field is not changed. */
1883 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1884 uint32_t *flags, uint32_t flag)
1886 if ((ci == NULL) || (flags == NULL))
1889 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1891 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1896 if (ci->values[0].value.boolean)
1902 } /* }}} int cna_config_bool_to_flag */
1904 /* Handling of the "Interval" option which is allowed in every block. */
1905 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1906 cna_interval_t *out_interval)
1910 if ((ci == NULL) || (out_interval == NULL))
1913 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1915 WARNING ("netapp plugin: The `Interval' option needs exactly one numeric argument.");
1919 tmp = (time_t) (ci->values[0].value.number + .5);
1922 WARNING ("netapp plugin: The `Interval' option needs a positive integer argument.");
1926 out_interval->interval = tmp;
1927 out_interval->last_read = 0;
1930 } /* }}} int cna_config_get_interval */
1932 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1933 * <VolumePerf /> block. */
1934 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
1935 const oconfig_item_t *ci)
1940 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1942 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1947 name = ci->values[0].value.string;
1949 if (strcasecmp ("GetIO", ci->key) == 0)
1950 il = cvp->il_octets;
1951 else if (strcasecmp ("GetOps", ci->key) == 0)
1952 il = cvp->il_operations;
1953 else if (strcasecmp ("GetLatency", ci->key) == 0)
1954 il = cvp->il_latency;
1958 ignorelist_add (il, name);
1959 } /* }}} void cna_config_volume_perf_option */
1961 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
1962 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
1963 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
1964 const oconfig_item_t *ci)
1968 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1970 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1975 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
1976 il = cvp->il_octets;
1977 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
1978 il = cvp->il_operations;
1979 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
1980 il = cvp->il_latency;
1984 if (ci->values[0].value.boolean)
1985 ignorelist_set_invert (il, /* invert = */ 0);
1987 ignorelist_set_invert (il, /* invert = */ 1);
1988 } /* }}} void cna_config_volume_perf_default */
1990 /* Corresponds to a <Disks /> block */
1995 * IgnoreSelectedIO false
1999 * IgnoreSelectedOps false
2003 * IgnoreSelectedLatency false
2006 /* Corresponds to a <VolumePerf /> block */
2007 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
2008 const oconfig_item_t *ci)
2010 cfg_volume_perf_t *cfg_volume_perf;
2013 if ((host == NULL) || (ci == NULL))
2016 if (host->cfg_volume_perf == NULL)
2018 cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
2019 if (cfg_volume_perf == NULL)
2021 memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
2023 /* Set default flags */
2024 cfg_volume_perf->query = NULL;
2025 cfg_volume_perf->volumes = NULL;
2027 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
2028 if (cfg_volume_perf->il_octets == NULL)
2030 sfree (cfg_volume_perf);
2034 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
2035 if (cfg_volume_perf->il_operations == NULL)
2037 ignorelist_free (cfg_volume_perf->il_octets);
2038 sfree (cfg_volume_perf);
2042 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
2043 if (cfg_volume_perf->il_latency == NULL)
2045 ignorelist_free (cfg_volume_perf->il_octets);
2046 ignorelist_free (cfg_volume_perf->il_operations);
2047 sfree (cfg_volume_perf);
2051 host->cfg_volume_perf = cfg_volume_perf;
2053 cfg_volume_perf = host->cfg_volume_perf;
2055 for (i = 0; i < ci->children_num; ++i) {
2056 oconfig_item_t *item = ci->children + i;
2058 /* if (!item || !item->key || !*item->key) continue; */
2059 if (strcasecmp(item->key, "Interval") == 0)
2060 cna_config_get_interval (item, &cfg_volume_perf->interval);
2061 else if (!strcasecmp(item->key, "GetIO"))
2062 cna_config_volume_perf_option (cfg_volume_perf, item);
2063 else if (!strcasecmp(item->key, "GetOps"))
2064 cna_config_volume_perf_option (cfg_volume_perf, item);
2065 else if (!strcasecmp(item->key, "GetLatency"))
2066 cna_config_volume_perf_option (cfg_volume_perf, item);
2067 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
2068 cna_config_volume_perf_default (cfg_volume_perf, item);
2069 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
2070 cna_config_volume_perf_default (cfg_volume_perf, item);
2071 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2072 cna_config_volume_perf_default (cfg_volume_perf, item);
2074 WARNING ("netapp plugin: The option %s is not allowed within "
2075 "`VolumePerf' blocks.", item->key);
2079 } /* }}} int cna_config_volume_performance */
2081 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2082 * <VolumeUsage /> block. */
2083 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
2084 const oconfig_item_t *ci)
2089 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2091 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2096 name = ci->values[0].value.string;
2098 if (strcasecmp ("GetCapacity", ci->key) == 0)
2099 il = cvu->il_capacity;
2100 else if (strcasecmp ("GetSnapshot", ci->key) == 0)
2101 il = cvu->il_snapshot;
2105 ignorelist_add (il, name);
2106 } /* }}} void cna_config_volume_usage_option */
2108 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2109 * options within a <VolumeUsage /> block. */
2110 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
2111 const oconfig_item_t *ci)
2115 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2117 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2122 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2123 il = cvu->il_capacity;
2124 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2125 il = cvu->il_snapshot;
2129 if (ci->values[0].value.boolean)
2130 ignorelist_set_invert (il, /* invert = */ 0);
2132 ignorelist_set_invert (il, /* invert = */ 1);
2133 } /* }}} void cna_config_volume_usage_default */
2135 /* Corresponds to a <Disks /> block */
2136 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2137 cfg_disk_t *cfg_disk;
2140 if ((host == NULL) || (ci == NULL))
2143 if (host->cfg_disk == NULL)
2145 cfg_disk = malloc (sizeof (*cfg_disk));
2146 if (cfg_disk == NULL)
2148 memset (cfg_disk, 0, sizeof (*cfg_disk));
2150 /* Set default flags */
2151 cfg_disk->flags = CFG_DISK_ALL;
2152 cfg_disk->query = NULL;
2153 cfg_disk->disks = NULL;
2155 host->cfg_disk = cfg_disk;
2157 cfg_disk = host->cfg_disk;
2159 for (i = 0; i < ci->children_num; ++i) {
2160 oconfig_item_t *item = ci->children + i;
2162 /* if (!item || !item->key || !*item->key) continue; */
2163 if (strcasecmp(item->key, "Interval") == 0)
2164 cna_config_get_interval (item, &cfg_disk->interval);
2165 else if (strcasecmp(item->key, "GetBusy") == 0)
2166 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2169 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2171 NOTICE ("netapp plugin: All disk related values have been disabled. "
2172 "Collection of per-disk data will be disabled entirely.");
2173 free_cfg_disk (host->cfg_disk);
2174 host->cfg_disk = NULL;
2178 } /* }}} int cna_config_disk */
2180 /* Corresponds to a <WAFL /> block */
2181 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2183 cfg_wafl_t *cfg_wafl;
2186 if ((host == NULL) || (ci == NULL))
2189 if (host->cfg_wafl == NULL)
2191 cfg_wafl = malloc (sizeof (*cfg_wafl));
2192 if (cfg_wafl == NULL)
2194 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
2196 /* Set default flags */
2197 cfg_wafl->flags = CFG_WAFL_ALL;
2199 host->cfg_wafl = cfg_wafl;
2201 cfg_wafl = host->cfg_wafl;
2203 for (i = 0; i < ci->children_num; ++i) {
2204 oconfig_item_t *item = ci->children + i;
2206 if (strcasecmp(item->key, "Interval") == 0)
2207 cna_config_get_interval (item, &cfg_wafl->interval);
2208 else if (!strcasecmp(item->key, "GetNameCache"))
2209 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2210 else if (!strcasecmp(item->key, "GetDirCache"))
2211 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2212 else if (!strcasecmp(item->key, "GetBufferCache"))
2213 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2214 else if (!strcasecmp(item->key, "GetInodeCache"))
2215 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2217 WARNING ("netapp plugin: The %s config option is not allowed within "
2218 "`WAFL' blocks.", item->key);
2221 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2223 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2224 "Collection of WAFL data will be disabled entirely.");
2225 free_cfg_wafl (host->cfg_wafl);
2226 host->cfg_wafl = NULL;
2230 } /* }}} int cna_config_wafl */
2234 * GetCapacity "vol0"
2235 * GetCapacity "vol1"
2236 * GetCapacity "vol2"
2237 * GetCapacity "vol3"
2238 * GetCapacity "vol4"
2239 * IgnoreSelectedCapacity false
2241 * GetSnapshot "vol0"
2242 * GetSnapshot "vol3"
2243 * GetSnapshot "vol4"
2244 * GetSnapshot "vol7"
2245 * IgnoreSelectedSnapshot false
2248 /* Corresponds to a <VolumeUsage /> block */
2249 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2250 const oconfig_item_t *ci)
2252 cfg_volume_usage_t *cfg_volume_usage;
2255 if ((host == NULL) || (ci == NULL))
2258 if (host->cfg_volume_usage == NULL)
2260 cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
2261 if (cfg_volume_usage == NULL)
2263 memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
2265 /* Set default flags */
2266 cfg_volume_usage->query = NULL;
2267 cfg_volume_usage->volumes = NULL;
2269 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2270 if (cfg_volume_usage->il_capacity == NULL)
2272 sfree (cfg_volume_usage);
2276 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2277 if (cfg_volume_usage->il_snapshot == NULL)
2279 ignorelist_free (cfg_volume_usage->il_capacity);
2280 sfree (cfg_volume_usage);
2284 host->cfg_volume_usage = cfg_volume_usage;
2286 cfg_volume_usage = host->cfg_volume_usage;
2288 for (i = 0; i < ci->children_num; ++i) {
2289 oconfig_item_t *item = ci->children + i;
2291 /* if (!item || !item->key || !*item->key) continue; */
2292 if (strcasecmp(item->key, "Interval") == 0)
2293 cna_config_get_interval (item, &cfg_volume_usage->interval);
2294 else if (!strcasecmp(item->key, "GetCapacity"))
2295 cna_config_volume_usage_option (cfg_volume_usage, item);
2296 else if (!strcasecmp(item->key, "GetSnapshot"))
2297 cna_config_volume_usage_option (cfg_volume_usage, item);
2298 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2299 cna_config_volume_usage_default (cfg_volume_usage, item);
2300 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2301 cna_config_volume_usage_default (cfg_volume_usage, item);
2303 WARNING ("netapp plugin: The option %s is not allowed within "
2304 "`VolumeUsage' blocks.", item->key);
2308 } /* }}} int cna_config_volume_usage */
2310 /* Corresponds to a <System /> block */
2311 static int cna_config_system (host_config_t *host, /* {{{ */
2314 cfg_system_t *cfg_system;
2317 if ((host == NULL) || (ci == NULL))
2320 if (host->cfg_system == NULL)
2322 cfg_system = malloc (sizeof (*cfg_system));
2323 if (cfg_system == NULL)
2325 memset (cfg_system, 0, sizeof (*cfg_system));
2327 /* Set default flags */
2328 cfg_system->flags = CFG_SYSTEM_ALL;
2329 cfg_system->query = NULL;
2331 host->cfg_system = cfg_system;
2333 cfg_system = host->cfg_system;
2335 for (i = 0; i < ci->children_num; ++i) {
2336 oconfig_item_t *item = ci->children + i;
2338 if (strcasecmp(item->key, "Interval") == 0) {
2339 cna_config_get_interval (item, &cfg_system->interval);
2340 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2341 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2342 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2343 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2344 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2345 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2346 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2347 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2349 WARNING ("netapp plugin: The %s config option is not allowed within "
2350 "`System' blocks.", item->key);
2354 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2356 NOTICE ("netapp plugin: All system related values have been disabled. "
2357 "Collection of system data will be disabled entirely.");
2358 free_cfg_system (host->cfg_system);
2359 host->cfg_system = NULL;
2363 } /* }}} int cna_config_system */
2365 /* Corresponds to a <Host /> block. */
2366 static host_config_t *cna_config_host (const oconfig_item_t *ci) /* {{{ */
2368 oconfig_item_t *item;
2369 host_config_t *host;
2373 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2374 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
2378 host = malloc(sizeof(*host));
2379 memset (host, 0, sizeof (*host));
2381 host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2383 host->username = NULL;
2384 host->password = NULL;
2386 host->cfg_wafl = NULL;
2387 host->cfg_disk = NULL;
2388 host->cfg_volume_perf = NULL;
2389 host->cfg_volume_usage = NULL;
2390 host->cfg_system = NULL;
2392 status = cf_util_get_string (ci, &host->name);
2399 for (i = 0; i < ci->children_num; ++i) {
2400 item = ci->children + i;
2404 if (!strcasecmp(item->key, "Address")) {
2405 status = cf_util_get_string (item, &host->host);
2406 } else if (!strcasecmp(item->key, "Port")) {
2409 tmp = cf_util_get_port_number (item);
2412 } else if (!strcasecmp(item->key, "Protocol")) {
2413 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"))) {
2414 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2417 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2418 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2419 } else if (!strcasecmp(item->key, "User")) {
2420 status = cf_util_get_string (item, &host->username);
2421 } else if (!strcasecmp(item->key, "Password")) {
2422 status = cf_util_get_string (item, &host->password);
2423 } else if (!strcasecmp(item->key, "Interval")) {
2424 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_NUMBER || item->values[0].value.number != (int) item->values[0].value.number || item->values[0].value.number < 2) {
2425 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
2428 host->interval = item->values[0].value.number;
2429 } else if (!strcasecmp(item->key, "WAFL")) {
2430 cna_config_wafl(host, item);
2431 } else if (!strcasecmp(item->key, "Disks")) {
2432 cna_config_disk(host, item);
2433 } else if (!strcasecmp(item->key, "VolumePerf")) {
2434 cna_config_volume_performance(host, item);
2435 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2436 cna_config_volume_usage(host, item);
2437 } else if (!strcasecmp(item->key, "System")) {
2438 cna_config_system(host, item);
2440 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
2441 item->key, ci->values[0].value.string);
2448 if (host->host == NULL)
2449 host->host = strdup (host->name);
2451 if (host->host == NULL)
2454 if (host->port <= 0)
2455 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2457 if ((host->username == NULL) || (host->password == NULL)) {
2458 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2459 "Ignoring host block.", host->name);
2465 free_host_config (host);
2470 } /* }}} host_config_t *cna_config_host */
2473 * Callbacks registered with the daemon
2475 * Pretty standard stuff here.
2477 static int cna_init_host (host_config_t *host) /* {{{ */
2482 if (host->srv != NULL)
2485 /* Request version 1.1 of the ONTAP API */
2486 host->srv = na_server_open(host->host,
2487 /* major version = */ 1, /* minor version = */ 1);
2488 if (host->srv == NULL) {
2489 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
2493 na_server_set_transport_type(host->srv, host->protocol,
2494 /* transportarg = */ NULL);
2495 na_server_set_port(host->srv, host->port);
2496 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
2497 na_server_adminuser(host->srv, host->username, host->password);
2498 na_server_set_timeout(host->srv, 5 /* seconds */);
2501 } /* }}} int cna_init_host */
2503 static int cna_init (void) /* {{{ */
2507 memset (err, 0, sizeof (err));
2508 if (!na_startup(err, sizeof(err))) {
2509 err[sizeof (err) - 1] = 0;
2510 ERROR("netapp plugin: Error initializing netapp API: %s", err);
2515 } /* }}} cna_init */
2517 static int cna_read (user_data_t *ud) { /* {{{ */
2518 host_config_t *host;
2521 if ((ud == NULL) || (ud->data == NULL))
2526 status = cna_init_host (host);
2530 cna_query_wafl (host);
2531 cna_query_disk (host);
2532 cna_query_volume_perf (host);
2533 cna_query_volume_usage (host);
2534 cna_query_system (host);
2537 } /* }}} int cna_read */
2539 static int cna_config (oconfig_item_t *ci) { /* {{{ */
2541 oconfig_item_t *item;
2543 for (i = 0; i < ci->children_num; ++i) {
2544 item = ci->children + i;
2546 if (strcasecmp(item->key, "Host") == 0)
2548 host_config_t *host;
2550 struct timespec interval;
2553 host = cna_config_host (item);
2557 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name);
2559 memset (&interval, 0, sizeof (interval));
2560 interval.tv_sec = host->interval;
2562 memset (&ud, 0, sizeof (ud));
2564 ud.free_func = (void (*) (void *)) free_host_config;
2566 plugin_register_complex_read (/* group = */ NULL, cb_name,
2567 /* callback = */ cna_read,
2568 /* interval = */ (host->interval > 0) ? &interval : NULL,
2569 /* user data = */ &ud);
2572 else /* if (item->key != "Host") */
2574 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
2578 } /* }}} int cna_config */
2580 static int cna_shutdown (void) /* {{{ */
2582 /* Clean up system resources and stuff. */
2586 } /* }}} int cna_shutdown */
2588 void module_register(void) {
2589 plugin_register_complex_config("netapp", cna_config);
2590 plugin_register_init("netapp", cna_init);
2591 plugin_register_shutdown("netapp", cna_shutdown);
2594 /* vim: set sw=2 ts=2 noet fdm=marker : */