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;
256 #define HOST_INIT { NULL, NA_SERVER_TRANSPORT_HTTPS, NULL, 0, NULL, NULL, 0, \
257 NULL, NULL, NULL, NULL, NULL, NULL, \
260 static host_config_t *global_host_config;
265 * Used to free the various structures above.
267 static void free_disk (disk_t *disk) /* {{{ */
280 } /* }}} void free_disk */
282 static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
287 if (cw->query != NULL)
288 na_elem_free (cw->query);
291 } /* }}} void free_cfg_wafl */
293 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
295 if (cfg_disk == NULL)
298 if (cfg_disk->query != NULL)
299 na_elem_free (cfg_disk->query);
301 free_disk (cfg_disk->disks);
303 } /* }}} void free_cfg_disk */
305 static void free_cfg_volume_perf (cfg_volume_perf_t *cvp) /* {{{ */
307 data_volume_perf_t *data;
312 /* Free the ignorelists */
313 ignorelist_free (cvp->il_octets);
314 ignorelist_free (cvp->il_operations);
315 ignorelist_free (cvp->il_latency);
317 /* Free the linked list of volumes */
321 data_volume_perf_t *next = data->next;
327 if (cvp->query != NULL)
328 na_elem_free (cvp->query);
331 } /* }}} void free_cfg_volume_perf */
333 static void free_cfg_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
335 data_volume_usage_t *data;
340 /* Free the ignorelists */
341 ignorelist_free (cvu->il_capacity);
342 ignorelist_free (cvu->il_snapshot);
344 /* Free the linked list of volumes */
348 data_volume_usage_t *next = data->next;
350 if (data->snap_query != NULL)
351 na_elem_free(data->snap_query);
356 if (cvu->query != NULL)
357 na_elem_free (cvu->query);
360 } /* }}} void free_cfg_volume_usage */
362 static void free_cfg_system (cfg_system_t *cs) /* {{{ */
367 if (cs->query != NULL)
368 na_elem_free (cs->query);
371 } /* }}} void free_cfg_system */
373 static void free_host_config (host_config_t *hc) /* {{{ */
384 sfree (hc->username);
385 sfree (hc->password);
387 free_cfg_disk (hc->cfg_disk);
388 free_cfg_wafl (hc->cfg_wafl);
389 free_cfg_volume_perf (hc->cfg_volume_perf);
390 free_cfg_volume_usage (hc->cfg_volume_usage);
391 free_cfg_system (hc->cfg_system);
394 na_server_close (hc->srv);
398 free_host_config (next);
399 } /* }}} void free_host_config */
402 * Auxiliary functions
404 * Used to look up volumes and disks or to handle flags.
406 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
410 if ((cd == NULL) || (name == NULL))
413 for (d = cd->disks; d != NULL; d = d->next) {
414 if (strcmp(d->name, name) == 0)
418 d = malloc(sizeof(*d));
421 memset (d, 0, sizeof (*d));
424 d->name = strdup(name);
425 if (d->name == NULL) {
434 } /* }}} disk_t *get_disk */
436 static data_volume_usage_t *get_volume_usage (cfg_volume_usage_t *cvu, /* {{{ */
439 data_volume_usage_t *last;
440 data_volume_usage_t *new;
442 int ignore_capacity = 0;
443 int ignore_snapshot = 0;
445 if ((cvu == NULL) || (name == NULL))
451 if (strcmp (last->name, name) == 0)
454 if (last->next == NULL)
460 /* Check the ignorelists. If *both* tell us to ignore a volume, return NULL. */
461 ignore_capacity = ignorelist_match (cvu->il_capacity, name);
462 ignore_snapshot = ignorelist_match (cvu->il_snapshot, name);
463 if ((ignore_capacity != 0) && (ignore_snapshot != 0))
466 /* Not found: allocate. */
467 new = malloc (sizeof (*new));
470 memset (new, 0, sizeof (*new));
473 new->name = strdup (name);
474 if (new->name == NULL)
480 if (ignore_capacity == 0)
481 new->flags |= CFG_VOLUME_USAGE_DF;
482 if (ignore_snapshot == 0) {
483 new->flags |= CFG_VOLUME_USAGE_SNAP;
484 new->snap_query = na_elem_new ("snapshot-list-info");
485 na_child_add_string(new->snap_query, "target-type", "volume");
486 na_child_add_string(new->snap_query, "target-name", name);
488 new->snap_query = NULL;
491 /* Add to end of list. */
498 } /* }}} data_volume_usage_t *get_volume_usage */
500 static data_volume_perf_t *get_volume_perf (cfg_volume_perf_t *cvp, /* {{{ */
503 data_volume_perf_t *last;
504 data_volume_perf_t *new;
506 int ignore_octets = 0;
507 int ignore_operations = 0;
508 int ignore_latency = 0;
510 if ((cvp == NULL) || (name == NULL))
516 if (strcmp (last->name, name) == 0)
519 if (last->next == NULL)
525 /* Check the ignorelists. If *all three* tell us to ignore a volume, return
527 ignore_octets = ignorelist_match (cvp->il_octets, name);
528 ignore_operations = ignorelist_match (cvp->il_operations, name);
529 ignore_latency = ignorelist_match (cvp->il_latency, name);
530 if ((ignore_octets != 0) || (ignore_operations != 0)
531 || (ignore_latency != 0))
534 /* Not found: allocate. */
535 new = malloc (sizeof (*new));
538 memset (new, 0, sizeof (*new));
541 new->name = strdup (name);
542 if (new->name == NULL)
548 if (ignore_octets == 0)
549 new->flags |= CFG_VOLUME_PERF_IO;
550 if (ignore_operations == 0)
551 new->flags |= CFG_VOLUME_PERF_OPS;
552 if (ignore_latency == 0)
553 new->flags |= CFG_VOLUME_PERF_LATENCY;
555 /* Add to end of list. */
562 } /* }}} data_volume_perf_t *get_volume_perf */
565 * Various submit functions.
567 * They all eventually call "submit_values" which creates a value_list_t and
568 * dispatches it to the daemon.
570 static int submit_values (const char *host, /* {{{ */
571 const char *plugin_inst,
572 const char *type, const char *type_inst,
573 value_t *values, int values_len,
576 value_list_t vl = VALUE_LIST_INIT;
579 vl.values_len = values_len;
585 sstrncpy (vl.host, host, sizeof (vl.host));
587 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
588 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
589 if (plugin_inst != NULL)
590 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
591 sstrncpy (vl.type, type, sizeof (vl.type));
592 if (type_inst != NULL)
593 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
595 return (plugin_dispatch_values (&vl));
596 } /* }}} int submit_uint64 */
598 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
599 const char *type, const char *type_inst, counter_t val0, counter_t val1,
604 values[0].counter = val0;
605 values[1].counter = val1;
607 return (submit_values (host, plugin_inst, type, type_inst,
608 values, 2, timestamp));
609 } /* }}} int submit_two_counters */
611 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
612 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
618 return (submit_values (host, plugin_inst, type, type_inst,
620 } /* }}} int submit_counter */
622 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
623 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
628 values[0].gauge = val0;
629 values[1].gauge = val1;
631 return (submit_values (host, plugin_inst, type, type_inst,
632 values, 2, timestamp));
633 } /* }}} int submit_two_gauge */
635 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
636 const char *type, const char *type_inst, double d, time_t timestamp)
640 v.gauge = (gauge_t) d;
642 return (submit_values (host, plugin_inst, type, type_inst,
644 } /* }}} int submit_uint64 */
646 /* Calculate hit ratio from old and new counters and submit the resulting
647 * percentage. Used by "submit_wafl_data". */
648 static int submit_cache_ratio (const char *host, /* {{{ */
649 const char *plugin_inst,
650 const char *type_inst,
659 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
663 hits = new_hits - old_hits;
664 misses = new_misses - old_misses;
666 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
671 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
673 } /* }}} int submit_cache_ratio */
675 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
676 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
677 cfg_wafl_t *old_data, const cfg_wafl_t *new_data)
679 /* Submit requested counters */
680 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
681 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
682 submit_cache_ratio (hostname, instance, "name_cache_hit",
683 new_data->name_cache_hit, new_data->name_cache_miss,
684 old_data->name_cache_hit, old_data->name_cache_miss,
685 new_data->timestamp);
687 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
688 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
689 submit_cache_ratio (hostname, instance, "find_dir_hit",
690 new_data->find_dir_hit, new_data->find_dir_miss,
691 old_data->find_dir_hit, old_data->find_dir_miss,
692 new_data->timestamp);
694 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
695 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
696 submit_cache_ratio (hostname, instance, "buf_hash_hit",
697 new_data->buf_hash_hit, new_data->buf_hash_miss,
698 old_data->buf_hash_hit, old_data->buf_hash_miss,
699 new_data->timestamp);
701 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
702 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
703 submit_cache_ratio (hostname, instance, "inode_cache_hit",
704 new_data->inode_cache_hit, new_data->inode_cache_miss,
705 old_data->inode_cache_hit, old_data->inode_cache_miss,
706 new_data->timestamp);
708 /* Clear old HAVE_* flags */
709 old_data->flags &= ~HAVE_WAFL_ALL;
711 /* Copy all counters */
712 old_data->timestamp = new_data->timestamp;
713 old_data->name_cache_hit = new_data->name_cache_hit;
714 old_data->name_cache_miss = new_data->name_cache_miss;
715 old_data->find_dir_hit = new_data->find_dir_hit;
716 old_data->find_dir_miss = new_data->find_dir_miss;
717 old_data->buf_hash_hit = new_data->buf_hash_hit;
718 old_data->buf_hash_miss = new_data->buf_hash_miss;
719 old_data->inode_cache_hit = new_data->inode_cache_hit;
720 old_data->inode_cache_miss = new_data->inode_cache_miss;
722 /* Copy HAVE_* flags */
723 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
726 } /* }}} int submit_wafl_data */
728 /* Submits volume performance data to the daemon, taking care to honor and
729 * update flags appropriately. */
730 static int submit_volume_perf_data (const char *hostname, /* {{{ */
731 data_volume_perf_t *old_data,
732 const data_volume_perf_t *new_data)
734 char plugin_instance[DATA_MAX_NAME_LEN];
736 if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
739 ssnprintf (plugin_instance, sizeof (plugin_instance),
740 "volume-%s", old_data->name);
742 /* Check for and submit disk-octet values */
743 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
744 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
746 submit_two_counters (hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
747 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
750 /* Check for and submit disk-operations values */
751 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
752 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
754 submit_two_counters (hostname, plugin_instance, "disk_ops", /* type instance = */ NULL,
755 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
758 /* Check for, calculate and submit disk-latency values */
759 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
760 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
761 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
762 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
763 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
765 gauge_t latency_per_op_read;
766 gauge_t latency_per_op_write;
768 latency_per_op_read = NAN;
769 latency_per_op_write = NAN;
771 /* Check if a counter wrapped around. */
772 if ((new_data->read_ops > old_data->read_ops)
773 && (new_data->read_latency > old_data->read_latency))
775 uint64_t diff_ops_read;
776 uint64_t diff_latency_read;
778 diff_ops_read = new_data->read_ops - old_data->read_ops;
779 diff_latency_read = new_data->read_latency - old_data->read_latency;
781 if (diff_ops_read > 0)
782 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
785 if ((new_data->write_ops > old_data->write_ops)
786 && (new_data->write_latency > old_data->write_latency))
788 uint64_t diff_ops_write;
789 uint64_t diff_latency_write;
791 diff_ops_write = new_data->write_ops - old_data->write_ops;
792 diff_latency_write = new_data->write_latency - old_data->write_latency;
794 if (diff_ops_write > 0)
795 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
798 submit_two_gauge (hostname, plugin_instance, "disk_latency", /* type instance = */ NULL,
799 latency_per_op_read, latency_per_op_write, new_data->timestamp);
802 /* Clear all HAVE_* flags. */
803 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
805 /* Copy all counters */
806 old_data->timestamp = new_data->timestamp;
807 old_data->read_bytes = new_data->read_bytes;
808 old_data->write_bytes = new_data->write_bytes;
809 old_data->read_ops = new_data->read_ops;
810 old_data->write_ops = new_data->write_ops;
811 old_data->read_latency = new_data->read_latency;
812 old_data->write_latency = new_data->write_latency;
814 /* Copy the HAVE_* flags */
815 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
818 } /* }}} int submit_volume_perf_data */
823 * These functions are called with appropriate data returned by the libnetapp
824 * interface which is parsed and submitted with the above functions.
826 /* Data corresponding to <WAFL /> */
827 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
830 cfg_wafl_t perf_data;
831 const char *plugin_inst;
833 na_elem_t *instances;
835 na_elem_iter_t counter_iter;
837 memset (&perf_data, 0, sizeof (perf_data));
839 perf_data.timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
841 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
842 if (instances == NULL)
844 ERROR ("netapp plugin: cna_handle_wafl_data: "
845 "na_elem_child (\"instances\") failed.");
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.");
857 /* Iterate over all counters */
858 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
859 for (counter = na_iterator_next (&counter_iter);
861 counter = na_iterator_next (&counter_iter))
866 name = na_child_get_string(counter, "name");
870 value = na_child_get_uint64(counter, "value", UINT64_MAX);
871 if (value == UINT64_MAX)
874 if (!strcmp(name, "name_cache_hit")) {
875 perf_data.name_cache_hit = value;
876 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
877 } else if (!strcmp(name, "name_cache_miss")) {
878 perf_data.name_cache_miss = value;
879 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
880 } else if (!strcmp(name, "find_dir_hit")) {
881 perf_data.find_dir_hit = value;
882 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
883 } else if (!strcmp(name, "find_dir_miss")) {
884 perf_data.find_dir_miss = value;
885 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
886 } else if (!strcmp(name, "buf_hash_hit")) {
887 perf_data.buf_hash_hit = value;
888 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
889 } else if (!strcmp(name, "buf_hash_miss")) {
890 perf_data.buf_hash_miss = value;
891 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
892 } else if (!strcmp(name, "inode_cache_hit")) {
893 perf_data.inode_cache_hit = value;
894 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
895 } else if (!strcmp(name, "inode_cache_miss")) {
896 perf_data.inode_cache_miss = value;
897 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
899 DEBUG("netapp plugin: cna_handle_wafl_data: "
900 "Found unexpected child: %s", name);
904 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data));
905 } /* }}} void cna_handle_wafl_data */
907 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
914 if (cw->query != NULL)
917 cw->query = na_elem_new("perf-object-get-instances");
918 if (cw->query == NULL)
920 ERROR ("netapp plugin: na_elem_new failed.");
923 na_child_add_string (cw->query, "objectname", "wafl");
925 e = na_elem_new("counters");
928 na_elem_free (cw->query);
930 ERROR ("netapp plugin: na_elem_new failed.");
933 na_child_add_string(e, "foo", "name_cache_hit");
934 na_child_add_string(e, "foo", "name_cache_miss");
935 na_child_add_string(e, "foo", "find_dir_hit");
936 na_child_add_string(e, "foo", "find_dir_miss");
937 na_child_add_string(e, "foo", "buf_hash_hit");
938 na_child_add_string(e, "foo", "buf_hash_miss");
939 na_child_add_string(e, "foo", "inode_cache_hit");
940 na_child_add_string(e, "foo", "inode_cache_miss");
942 na_child_add(cw->query, e);
945 } /* }}} int cna_setup_wafl */
947 static int cna_query_wafl (host_config_t *host) /* {{{ */
956 /* If WAFL was not configured, return without doing anything. */
957 if (host->cfg_wafl == NULL)
961 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
964 status = cna_setup_wafl (host->cfg_wafl);
967 assert (host->cfg_wafl->query != NULL);
969 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
970 if (na_results_status (data) != NA_OK)
972 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed: %s",
973 na_results_reason (data));
978 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data);
981 host->cfg_wafl->interval.last_read = now;
985 } /* }}} int cna_query_wafl */
987 /* Data corresponding to <Disks /> */
988 static int cna_handle_disk_data (const char *hostname, /* {{{ */
989 cfg_disk_t *cfg_disk, na_elem_t *data)
992 na_elem_t *instances;
994 na_elem_iter_t instance_iter;
995 disk_t *worst_disk = NULL;
997 if ((cfg_disk == NULL) || (data == NULL))
1000 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
1002 instances = na_elem_child (data, "instances");
1003 if (instances == NULL)
1005 ERROR ("netapp plugin: cna_handle_disk_data: "
1006 "na_elem_child (\"instances\") failed.");
1010 /* Iterate over all children */
1011 instance_iter = na_child_iterator (instances);
1012 for (instance = na_iterator_next (&instance_iter);
1014 instance = na_iterator_next(&instance_iter))
1019 na_elem_iter_t counter_iterator;
1022 memset (&new_data, 0, sizeof (new_data));
1023 new_data.timestamp = timestamp;
1024 new_data.disk_busy_percent = NAN;
1026 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1027 if (old_data == NULL)
1030 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1031 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1032 for (counter = na_iterator_next(&counter_iterator);
1034 counter = na_iterator_next(&counter_iterator))
1039 name = na_child_get_string(counter, "name");
1043 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1044 if (value == UINT64_MAX)
1047 if (strcmp(name, "disk_busy") == 0)
1049 new_data.disk_busy = value;
1050 new_data.flags |= HAVE_DISK_BUSY;
1052 else if (strcmp(name, "base_for_disk_busy") == 0)
1054 new_data.base_for_disk_busy = value;
1055 new_data.flags |= HAVE_DISK_BASE;
1059 DEBUG ("netapp plugin: cna_handle_disk_data: "
1060 "Counter not handled: %s = %"PRIu64,
1065 /* If all required counters are available and did not just wrap around,
1066 * calculate the busy percentage. Otherwise, the value is initialized to
1067 * NAN at the top of the for-loop. */
1068 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1069 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1070 && (new_data.disk_busy >= old_data->disk_busy)
1071 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1076 busy_diff = new_data.disk_busy - old_data->disk_busy;
1077 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1079 new_data.disk_busy_percent = 100.0
1080 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1083 /* Clear HAVE_* flags */
1084 old_data->flags &= ~HAVE_DISK_ALL;
1087 old_data->timestamp = new_data.timestamp;
1088 old_data->disk_busy = new_data.disk_busy;
1089 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1090 old_data->disk_busy_percent = new_data.disk_busy_percent;
1093 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1095 if ((worst_disk == NULL)
1096 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1097 worst_disk = old_data;
1098 } /* for (all disks) */
1100 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1101 submit_double (hostname, "system", "percent", "disk_busy",
1102 worst_disk->disk_busy_percent, timestamp);
1105 } /* }}} int cna_handle_disk_data */
1107 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1114 if (cd->query != NULL)
1117 cd->query = na_elem_new ("perf-object-get-instances");
1118 if (cd->query == NULL)
1120 ERROR ("netapp plugin: na_elem_new failed.");
1123 na_child_add_string (cd->query, "objectname", "disk");
1125 e = na_elem_new("counters");
1128 na_elem_free (cd->query);
1130 ERROR ("netapp plugin: na_elem_new failed.");
1133 na_child_add_string(e, "foo", "disk_busy");
1134 na_child_add_string(e, "foo", "base_for_disk_busy");
1135 na_child_add(cd->query, e);
1138 } /* }}} int cna_setup_disk */
1140 static int cna_query_disk (host_config_t *host) /* {{{ */
1149 /* If the user did not configure disk statistics, return without doing
1151 if (host->cfg_disk == NULL)
1155 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1158 status = cna_setup_disk (host->cfg_disk);
1161 assert (host->cfg_disk->query != NULL);
1163 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1164 if (na_results_status (data) != NA_OK)
1166 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed: %s",
1167 na_results_reason (data));
1168 na_elem_free (data);
1172 status = cna_handle_disk_data (host->name, host->cfg_disk, data);
1175 host->cfg_disk->interval.last_read = now;
1177 na_elem_free (data);
1179 } /* }}} int cna_query_disk */
1181 /* Data corresponding to <VolumePerf /> */
1182 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1183 cfg_volume_perf_t *cvp, na_elem_t *data)
1186 na_elem_t *elem_instances;
1187 na_elem_iter_t iter_instances;
1188 na_elem_t *elem_instance;
1190 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
1192 elem_instances = na_elem_child(data, "instances");
1193 if (elem_instances == NULL)
1195 ERROR ("netapp plugin: handle_volume_perf_data: "
1196 "na_elem_child (\"instances\") failed.");
1200 iter_instances = na_child_iterator (elem_instances);
1201 for (elem_instance = na_iterator_next(&iter_instances);
1202 elem_instance != NULL;
1203 elem_instance = na_iterator_next(&iter_instances))
1207 data_volume_perf_t perf_data;
1208 data_volume_perf_t *v;
1210 na_elem_t *elem_counters;
1211 na_elem_iter_t iter_counters;
1212 na_elem_t *elem_counter;
1214 memset (&perf_data, 0, sizeof (perf_data));
1215 perf_data.timestamp = timestamp;
1217 name = na_child_get_string (elem_instance, "name");
1221 /* get_volume_perf may return NULL if this volume is to be ignored. */
1222 v = get_volume_perf (cvp, name);
1226 elem_counters = na_elem_child (elem_instance, "counters");
1227 if (elem_counters == NULL)
1230 iter_counters = na_child_iterator (elem_counters);
1231 for (elem_counter = na_iterator_next(&iter_counters);
1232 elem_counter != NULL;
1233 elem_counter = na_iterator_next(&iter_counters))
1238 name = na_child_get_string (elem_counter, "name");
1242 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1243 if (value == UINT64_MAX)
1246 if (!strcmp(name, "read_data")) {
1247 perf_data.read_bytes = value;
1248 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1249 } else if (!strcmp(name, "write_data")) {
1250 perf_data.write_bytes = value;
1251 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1252 } else if (!strcmp(name, "read_ops")) {
1253 perf_data.read_ops = value;
1254 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1255 } else if (!strcmp(name, "write_ops")) {
1256 perf_data.write_ops = value;
1257 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1258 } else if (!strcmp(name, "read_latency")) {
1259 perf_data.read_latency = value;
1260 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1261 } else if (!strcmp(name, "write_latency")) {
1262 perf_data.write_latency = value;
1263 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1265 } /* for (elem_counter) */
1267 submit_volume_perf_data (hostname, v, &perf_data);
1268 } /* for (volume) */
1271 } /* }}} int cna_handle_volume_perf_data */
1273 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1280 if (cd->query != NULL)
1283 cd->query = na_elem_new ("perf-object-get-instances");
1284 if (cd->query == NULL)
1286 ERROR ("netapp plugin: na_elem_new failed.");
1289 na_child_add_string (cd->query, "objectname", "volume");
1291 e = na_elem_new("counters");
1294 na_elem_free (cd->query);
1296 ERROR ("netapp plugin: na_elem_new failed.");
1299 /* "foo" means: This string has to be here but the content doesn't matter. */
1300 na_child_add_string(e, "foo", "read_ops");
1301 na_child_add_string(e, "foo", "write_ops");
1302 na_child_add_string(e, "foo", "read_data");
1303 na_child_add_string(e, "foo", "write_data");
1304 na_child_add_string(e, "foo", "read_latency");
1305 na_child_add_string(e, "foo", "write_latency");
1306 na_child_add(cd->query, e);
1309 } /* }}} int cna_setup_volume_perf */
1311 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1320 /* If the user did not configure volume performance statistics, return
1321 * without doing anything. */
1322 if (host->cfg_volume_perf == NULL)
1326 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1329 status = cna_setup_volume_perf (host->cfg_volume_perf);
1332 assert (host->cfg_volume_perf->query != NULL);
1334 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1335 if (na_results_status (data) != NA_OK)
1337 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed: %s",
1338 na_results_reason (data));
1339 na_elem_free (data);
1343 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data);
1346 host->cfg_volume_perf->interval.last_read = now;
1348 na_elem_free (data);
1350 } /* }}} int cna_query_volume_perf */
1352 /* Data corresponding to <VolumeUsage /> */
1353 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1354 cfg_volume_usage_t *cfg_volume)
1356 data_volume_usage_t *v;
1358 for (v = cfg_volume->volumes; v != NULL; v = v->next)
1360 char plugin_instance[DATA_MAX_NAME_LEN];
1362 uint64_t norm_used = v->norm_used;
1363 uint64_t norm_free = v->norm_free;
1364 uint64_t sis_saved = v->sis_saved;
1365 uint64_t snap_reserve_used = 0;
1366 uint64_t snap_reserve_free = v->snap_reserved;
1367 uint64_t snap_norm_used = v->snap_used;
1369 ssnprintf (plugin_instance, sizeof (plugin_instance),
1370 "volume-%s", v->name);
1372 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD)) {
1373 if (v->snap_reserved > v->snap_used) {
1374 snap_reserve_free = v->snap_reserved - v->snap_used;
1375 snap_reserve_used = v->snap_used;
1378 snap_reserve_free = 0;
1379 snap_reserve_used = v->snap_reserved;
1380 snap_norm_used = v->snap_used - v->snap_reserved;
1381 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED)
1382 && (norm_used >= snap_norm_used))
1383 norm_used -= snap_norm_used;
1387 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1388 submit_double (hostname, /* plugin instance = */ plugin_instance,
1389 "df_complex", "free",
1390 (double) norm_free, /* timestamp = */ 0);
1392 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1393 submit_double (hostname, /* plugin instance = */ plugin_instance,
1394 "df_complex", "sis_saved",
1395 (double) sis_saved, /* timestamp = */ 0);
1397 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1398 submit_double (hostname, /* plugin instance = */ plugin_instance,
1399 "df_complex", "used",
1400 (double) norm_used, /* timestamp = */ 0);
1402 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1403 submit_double (hostname, /* plugin instance = */ plugin_instance,
1404 "df_complex", "snap_reserved",
1405 (double) snap_reserve_free, /* timestamp = */ 0);
1407 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
1408 submit_double (hostname, /* plugin instance = */ plugin_instance,
1409 "df_complex", "snap_reserve_used",
1410 (double) snap_reserve_used, /* timestamp = */ 0);
1412 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1413 submit_double (hostname, /* plugin instance = */ plugin_instance,
1414 "df_complex", "snap_normal_used",
1415 (double) snap_norm_used, /* timestamp = */ 0);
1417 /* Clear all the HAVE_* flags */
1418 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1419 } /* for (v = cfg_volume->volumes) */
1422 } /* }}} int cna_submit_volume_usage_data */
1424 /* Switch the state of a volume between online and offline and send out a
1426 static int cna_change_volume_status (const char *hostname, /* {{{ */
1427 data_volume_usage_t *v)
1431 memset (&n, 0, sizeof (&n));
1432 n.time = time (NULL);
1433 sstrncpy (n.host, hostname, sizeof (n.host));
1434 sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
1435 sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance));
1437 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
1438 n.severity = NOTIF_OKAY;
1439 ssnprintf (n.message, sizeof (n.message),
1440 "Volume %s is now online.", v->name);
1441 v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
1443 n.severity = NOTIF_WARNING;
1444 ssnprintf (n.message, sizeof (n.message),
1445 "Volume %s is now offline.", v->name);
1446 v->flags |= IS_VOLUME_USAGE_OFFLINE;
1449 return (plugin_dispatch_notification (&n));
1450 } /* }}} int cna_change_volume_status */
1452 static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
1453 data_volume_usage_t *v)
1455 uint64_t snap_used = 0, value;
1456 na_elem_t *data, *elem_snap, *elem_snapshots;
1457 na_elem_iter_t iter_snap;
1459 data = na_server_invoke_elem(host->srv, v->snap_query);
1460 if (na_results_status(data) != NA_OK)
1462 if (na_results_errno(data) == EVOLUMEOFFLINE) {
1463 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
1464 cna_change_volume_status (host->name, v);
1466 ERROR ("netapp plugin: cna_handle_volume_snap_usage: na_server_invoke_elem for "
1467 "volume \"%s\" failed with error %d: %s", v->name,
1468 na_results_errno(data), na_results_reason(data));
1474 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0)
1475 cna_change_volume_status (host->name, v);
1477 elem_snapshots = na_elem_child (data, "snapshots");
1478 if (elem_snapshots == NULL)
1480 ERROR ("netapp plugin: cna_handle_volume_snap_usage: "
1481 "na_elem_child (\"snapshots\") failed.");
1486 iter_snap = na_child_iterator (elem_snapshots);
1487 for (elem_snap = na_iterator_next (&iter_snap);
1489 elem_snap = na_iterator_next (&iter_snap))
1491 value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
1492 /* "cumulative-total" is the total size of the oldest snapshot plus all
1493 * newer ones in blocks (1KB). We therefore are looking for the highest
1494 * number of all snapshots - that's the size required for the snapshots. */
1495 if (value > snap_used)
1498 na_elem_free (data);
1499 /* snap_used is in 1024 byte blocks */
1500 v->snap_used = snap_used * 1024;
1501 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1502 } /* }}} void cna_handle_volume_snap_usage */
1504 static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
1505 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1507 na_elem_t *elem_volume;
1508 na_elem_t *elem_volumes;
1509 na_elem_iter_t iter_volume;
1511 elem_volumes = na_elem_child (data, "volumes");
1512 if (elem_volumes == NULL)
1514 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1515 "na_elem_child (\"volumes\") failed.");
1519 iter_volume = na_child_iterator (elem_volumes);
1520 for (elem_volume = na_iterator_next (&iter_volume);
1521 elem_volume != NULL;
1522 elem_volume = na_iterator_next (&iter_volume))
1524 const char *volume_name, *state;
1526 data_volume_usage_t *v;
1530 const char *sis_state;
1531 uint64_t sis_saved_reported;
1533 volume_name = na_child_get_string (elem_volume, "name");
1534 if (volume_name == NULL)
1537 state = na_child_get_string (elem_volume, "state");
1538 if ((state == NULL) || (strcmp(state, "online") != 0))
1541 /* get_volume_usage may return NULL if the volume is to be ignored. */
1542 v = get_volume_usage (cfg_volume, volume_name);
1546 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1547 cna_handle_volume_snap_usage(host, v);
1549 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1552 /* 2^4 exa-bytes? This will take a while ;) */
1553 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1554 if (value != UINT64_MAX) {
1555 v->norm_free = value;
1556 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1559 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1560 if (value != UINT64_MAX) {
1561 v->norm_used = value;
1562 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1565 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1566 if (value != UINT64_MAX) {
1567 /* 1 block == 1024 bytes as per API docs */
1568 v->snap_reserved = 1024 * value;
1569 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1572 sis = na_elem_child(elem_volume, "sis");
1576 sis_state = na_child_get_string(sis, "state");
1577 if (sis_state == NULL)
1580 /* If SIS is not enabled, there's nothing left to do for this volume. */
1581 if (strcmp ("enabled", sis_state) != 0)
1584 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1585 if (sis_saved_reported == UINT64_MAX)
1588 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1589 if ((sis_saved_reported >> 32) != 0) {
1590 /* In case they ever fix this bug. */
1591 v->sis_saved = sis_saved_reported;
1592 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1593 } else { /* really hacky work-around code. {{{ */
1594 uint64_t sis_saved_percent;
1595 uint64_t sis_saved_guess;
1596 uint64_t overflow_guess;
1597 uint64_t guess1, guess2, guess3;
1599 /* Check if we have v->norm_used. Without it, we cannot calculate
1600 * sis_saved_guess. */
1601 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1604 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1605 if (sis_saved_percent > 100)
1608 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1609 * will hopefully be fixed in later versions. To work around the bug, try
1610 * to figure out how often the 32bit integer wrapped around by using the
1611 * "percentage-saved" value. Because the percentage is in the range
1612 * [0-100], this should work as long as the saved space does not exceed
1614 /* percentage-saved = size-saved / (size-saved + size-used) */
1615 if (sis_saved_percent < 100)
1616 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1618 sis_saved_guess = v->norm_used;
1620 overflow_guess = sis_saved_guess >> 32;
1621 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1622 guess2 = (overflow_guess << 32) + sis_saved_reported;
1623 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1625 if (sis_saved_guess < guess2) {
1626 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1627 v->sis_saved = guess1;
1629 v->sis_saved = guess2;
1631 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1632 v->sis_saved = guess2;
1634 v->sis_saved = guess3;
1636 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1637 } /* }}} end of 32-bit workaround */
1638 } /* for (elem_volume) */
1640 return (cna_submit_volume_usage_data (host->name, cfg_volume));
1641 } /* }}} int cna_handle_volume_usage_data */
1643 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1648 if (cvu->query != NULL)
1651 cvu->query = na_elem_new ("volume-list-info");
1652 if (cvu->query == NULL)
1654 ERROR ("netapp plugin: na_elem_new failed.");
1659 } /* }}} int cna_setup_volume_usage */
1661 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1670 /* If the user did not configure volume_usage statistics, return without
1671 * doing anything. */
1672 if (host->cfg_volume_usage == NULL)
1676 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1679 status = cna_setup_volume_usage (host->cfg_volume_usage);
1682 assert (host->cfg_volume_usage->query != NULL);
1684 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1685 if (na_results_status (data) != NA_OK)
1687 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed: %s",
1688 na_results_reason (data));
1689 na_elem_free (data);
1693 status = cna_handle_volume_usage_data (host, host->cfg_volume_usage, data);
1696 host->cfg_volume_usage->interval.last_read = now;
1698 na_elem_free (data);
1700 } /* }}} int cna_query_volume_usage */
1702 /* Data corresponding to <System /> */
1703 static int cna_handle_system_data (const char *hostname, /* {{{ */
1704 cfg_system_t *cfg_system, na_elem_t *data)
1706 na_elem_t *instances;
1708 na_elem_iter_t counter_iter;
1710 counter_t disk_read = 0, disk_written = 0;
1711 counter_t net_recv = 0, net_sent = 0;
1712 counter_t cpu_busy = 0, cpu_total = 0;
1713 uint32_t counter_flags = 0;
1715 const char *instance;
1718 timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
1720 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1721 if (instances == NULL)
1723 ERROR ("netapp plugin: cna_handle_system_data: "
1724 "na_elem_child (\"instances\") failed.");
1728 instance = na_child_get_string (instances, "name");
1729 if (instance == NULL)
1731 ERROR ("netapp plugin: cna_handle_system_data: "
1732 "na_child_get_string (\"name\") failed.");
1736 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
1737 for (counter = na_iterator_next (&counter_iter);
1739 counter = na_iterator_next (&counter_iter))
1744 name = na_child_get_string(counter, "name");
1748 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1749 if (value == UINT64_MAX)
1752 if (!strcmp(name, "disk_data_read")) {
1753 disk_read = (counter_t) (value * 1024);
1754 counter_flags |= 0x01;
1755 } else if (!strcmp(name, "disk_data_written")) {
1756 disk_written = (counter_t) (value * 1024);
1757 counter_flags |= 0x02;
1758 } else if (!strcmp(name, "net_data_recv")) {
1759 net_recv = (counter_t) (value * 1024);
1760 counter_flags |= 0x04;
1761 } else if (!strcmp(name, "net_data_sent")) {
1762 net_sent = (counter_t) (value * 1024);
1763 counter_flags |= 0x08;
1764 } else if (!strcmp(name, "cpu_busy")) {
1765 cpu_busy = (counter_t) value;
1766 counter_flags |= 0x10;
1767 } else if (!strcmp(name, "cpu_elapsed_time")) {
1768 cpu_total = (counter_t) value;
1769 counter_flags |= 0x20;
1770 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1771 && (value > 0) && (strlen(name) > 4)
1772 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1773 submit_counter (hostname, instance, "disk_ops_complex", name,
1774 (counter_t) value, timestamp);
1776 } /* for (counter) */
1778 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1779 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
1780 submit_two_counters (hostname, instance, "disk_octets", NULL,
1781 disk_read, disk_written, timestamp);
1783 if ((cfg_system->flags & CFG_SYSTEM_NET)
1784 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
1785 submit_two_counters (hostname, instance, "if_octets", NULL,
1786 net_recv, net_sent, timestamp);
1788 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1789 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
1791 submit_counter (hostname, instance, "cpu", "system",
1792 cpu_busy, timestamp);
1793 submit_counter (hostname, instance, "cpu", "idle",
1794 cpu_total - cpu_busy, timestamp);
1798 } /* }}} int cna_handle_system_data */
1800 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
1805 if (cs->query != NULL)
1808 cs->query = na_elem_new ("perf-object-get-instances");
1809 if (cs->query == NULL)
1811 ERROR ("netapp plugin: na_elem_new failed.");
1814 na_child_add_string (cs->query, "objectname", "system");
1817 } /* }}} int cna_setup_system */
1819 static int cna_query_system (host_config_t *host) /* {{{ */
1828 /* If system statistics were not configured, return without doing anything. */
1829 if (host->cfg_system == NULL)
1833 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
1836 status = cna_setup_system (host->cfg_system);
1839 assert (host->cfg_system->query != NULL);
1841 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
1842 if (na_results_status (data) != NA_OK)
1844 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed: %s",
1845 na_results_reason (data));
1846 na_elem_free (data);
1850 status = cna_handle_system_data (host->name, host->cfg_system, data);
1853 host->cfg_system->interval.last_read = now;
1855 na_elem_free (data);
1857 } /* }}} int cna_query_system */
1860 * Configuration handling
1862 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1863 * is false. On error, the flag-field is not changed. */
1864 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1865 uint32_t *flags, uint32_t flag)
1867 if ((ci == NULL) || (flags == NULL))
1870 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1872 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1877 if (ci->values[0].value.boolean)
1883 } /* }}} int cna_config_bool_to_flag */
1885 /* Handling of the "Interval" option which is allowed in every block. */
1886 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1887 cna_interval_t *out_interval)
1891 if ((ci == NULL) || (out_interval == NULL))
1894 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1896 WARNING ("netapp plugin: The `Interval' option needs exactly one numeric argument.");
1900 tmp = (time_t) (ci->values[0].value.number + .5);
1903 WARNING ("netapp plugin: The `Interval' option needs a positive integer argument.");
1907 out_interval->interval = tmp;
1908 out_interval->last_read = 0;
1911 } /* }}} int cna_config_get_interval */
1913 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1914 * <VolumePerf /> block. */
1915 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
1916 const oconfig_item_t *ci)
1921 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1923 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1928 name = ci->values[0].value.string;
1930 if (strcasecmp ("GetIO", ci->key) == 0)
1931 il = cvp->il_octets;
1932 else if (strcasecmp ("GetOps", ci->key) == 0)
1933 il = cvp->il_operations;
1934 else if (strcasecmp ("GetLatency", ci->key) == 0)
1935 il = cvp->il_latency;
1939 ignorelist_add (il, name);
1940 } /* }}} void cna_config_volume_perf_option */
1942 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
1943 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
1944 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
1945 const oconfig_item_t *ci)
1949 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1951 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1956 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
1957 il = cvp->il_octets;
1958 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
1959 il = cvp->il_operations;
1960 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
1961 il = cvp->il_latency;
1965 if (ci->values[0].value.boolean)
1966 ignorelist_set_invert (il, /* invert = */ 0);
1968 ignorelist_set_invert (il, /* invert = */ 1);
1969 } /* }}} void cna_config_volume_perf_default */
1971 /* Corresponds to a <Disks /> block */
1976 * IgnoreSelectedIO false
1980 * IgnoreSelectedOps false
1984 * IgnoreSelectedLatency false
1987 /* Corresponds to a <VolumePerf /> block */
1988 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
1989 const oconfig_item_t *ci)
1991 cfg_volume_perf_t *cfg_volume_perf;
1994 if ((host == NULL) || (ci == NULL))
1997 if (host->cfg_volume_perf == NULL)
1999 cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
2000 if (cfg_volume_perf == NULL)
2002 memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
2004 /* Set default flags */
2005 cfg_volume_perf->query = NULL;
2006 cfg_volume_perf->volumes = NULL;
2008 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
2009 if (cfg_volume_perf->il_octets == NULL)
2011 sfree (cfg_volume_perf);
2015 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
2016 if (cfg_volume_perf->il_operations == NULL)
2018 ignorelist_free (cfg_volume_perf->il_octets);
2019 sfree (cfg_volume_perf);
2023 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
2024 if (cfg_volume_perf->il_latency == NULL)
2026 ignorelist_free (cfg_volume_perf->il_octets);
2027 ignorelist_free (cfg_volume_perf->il_operations);
2028 sfree (cfg_volume_perf);
2032 host->cfg_volume_perf = cfg_volume_perf;
2034 cfg_volume_perf = host->cfg_volume_perf;
2036 for (i = 0; i < ci->children_num; ++i) {
2037 oconfig_item_t *item = ci->children + i;
2039 /* if (!item || !item->key || !*item->key) continue; */
2040 if (strcasecmp(item->key, "Interval") == 0)
2041 cna_config_get_interval (item, &cfg_volume_perf->interval);
2042 else if (!strcasecmp(item->key, "GetIO"))
2043 cna_config_volume_perf_option (cfg_volume_perf, item);
2044 else if (!strcasecmp(item->key, "GetOps"))
2045 cna_config_volume_perf_option (cfg_volume_perf, item);
2046 else if (!strcasecmp(item->key, "GetLatency"))
2047 cna_config_volume_perf_option (cfg_volume_perf, item);
2048 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
2049 cna_config_volume_perf_default (cfg_volume_perf, item);
2050 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
2051 cna_config_volume_perf_default (cfg_volume_perf, item);
2052 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2053 cna_config_volume_perf_default (cfg_volume_perf, item);
2055 WARNING ("netapp plugin: The option %s is not allowed within "
2056 "`VolumePerf' blocks.", item->key);
2060 } /* }}} int cna_config_volume_performance */
2062 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2063 * <VolumeUsage /> block. */
2064 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
2065 const oconfig_item_t *ci)
2070 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2072 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2077 name = ci->values[0].value.string;
2079 if (strcasecmp ("GetCapacity", ci->key) == 0)
2080 il = cvu->il_capacity;
2081 else if (strcasecmp ("GetSnapshot", ci->key) == 0)
2082 il = cvu->il_snapshot;
2086 ignorelist_add (il, name);
2087 } /* }}} void cna_config_volume_usage_option */
2089 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2090 * options within a <VolumeUsage /> block. */
2091 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
2092 const oconfig_item_t *ci)
2096 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2098 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2103 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2104 il = cvu->il_capacity;
2105 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2106 il = cvu->il_snapshot;
2110 if (ci->values[0].value.boolean)
2111 ignorelist_set_invert (il, /* invert = */ 0);
2113 ignorelist_set_invert (il, /* invert = */ 1);
2114 } /* }}} void cna_config_volume_usage_default */
2116 /* Corresponds to a <Disks /> block */
2117 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2118 cfg_disk_t *cfg_disk;
2121 if ((host == NULL) || (ci == NULL))
2124 if (host->cfg_disk == NULL)
2126 cfg_disk = malloc (sizeof (*cfg_disk));
2127 if (cfg_disk == NULL)
2129 memset (cfg_disk, 0, sizeof (*cfg_disk));
2131 /* Set default flags */
2132 cfg_disk->flags = CFG_DISK_ALL;
2133 cfg_disk->query = NULL;
2134 cfg_disk->disks = NULL;
2136 host->cfg_disk = cfg_disk;
2138 cfg_disk = host->cfg_disk;
2140 for (i = 0; i < ci->children_num; ++i) {
2141 oconfig_item_t *item = ci->children + i;
2143 /* if (!item || !item->key || !*item->key) continue; */
2144 if (strcasecmp(item->key, "Interval") == 0)
2145 cna_config_get_interval (item, &cfg_disk->interval);
2146 else if (strcasecmp(item->key, "GetBusy") == 0)
2147 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2150 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2152 NOTICE ("netapp plugin: All disk related values have been disabled. "
2153 "Collection of per-disk data will be disabled entirely.");
2154 free_cfg_disk (host->cfg_disk);
2155 host->cfg_disk = NULL;
2159 } /* }}} int cna_config_disk */
2161 /* Corresponds to a <WAFL /> block */
2162 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2164 cfg_wafl_t *cfg_wafl;
2167 if ((host == NULL) || (ci == NULL))
2170 if (host->cfg_wafl == NULL)
2172 cfg_wafl = malloc (sizeof (*cfg_wafl));
2173 if (cfg_wafl == NULL)
2175 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
2177 /* Set default flags */
2178 cfg_wafl->flags = CFG_WAFL_ALL;
2180 host->cfg_wafl = cfg_wafl;
2182 cfg_wafl = host->cfg_wafl;
2184 for (i = 0; i < ci->children_num; ++i) {
2185 oconfig_item_t *item = ci->children + i;
2187 if (strcasecmp(item->key, "Interval") == 0)
2188 cna_config_get_interval (item, &cfg_wafl->interval);
2189 else if (!strcasecmp(item->key, "GetNameCache"))
2190 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2191 else if (!strcasecmp(item->key, "GetDirCache"))
2192 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2193 else if (!strcasecmp(item->key, "GetBufferCache"))
2194 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2195 else if (!strcasecmp(item->key, "GetInodeCache"))
2196 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2198 WARNING ("netapp plugin: The %s config option is not allowed within "
2199 "`WAFL' blocks.", item->key);
2202 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2204 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2205 "Collection of WAFL data will be disabled entirely.");
2206 free_cfg_wafl (host->cfg_wafl);
2207 host->cfg_wafl = NULL;
2211 } /* }}} int cna_config_wafl */
2215 * GetCapacity "vol0"
2216 * GetCapacity "vol1"
2217 * GetCapacity "vol2"
2218 * GetCapacity "vol3"
2219 * GetCapacity "vol4"
2220 * IgnoreSelectedCapacity false
2222 * GetSnapshot "vol0"
2223 * GetSnapshot "vol3"
2224 * GetSnapshot "vol4"
2225 * GetSnapshot "vol7"
2226 * IgnoreSelectedSnapshot false
2229 /* Corresponds to a <VolumeUsage /> block */
2230 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2231 const oconfig_item_t *ci)
2233 cfg_volume_usage_t *cfg_volume_usage;
2236 if ((host == NULL) || (ci == NULL))
2239 if (host->cfg_volume_usage == NULL)
2241 cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
2242 if (cfg_volume_usage == NULL)
2244 memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
2246 /* Set default flags */
2247 cfg_volume_usage->query = NULL;
2248 cfg_volume_usage->volumes = NULL;
2250 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2251 if (cfg_volume_usage->il_capacity == NULL)
2253 sfree (cfg_volume_usage);
2257 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2258 if (cfg_volume_usage->il_snapshot == NULL)
2260 ignorelist_free (cfg_volume_usage->il_capacity);
2261 sfree (cfg_volume_usage);
2265 host->cfg_volume_usage = cfg_volume_usage;
2267 cfg_volume_usage = host->cfg_volume_usage;
2269 for (i = 0; i < ci->children_num; ++i) {
2270 oconfig_item_t *item = ci->children + i;
2272 /* if (!item || !item->key || !*item->key) continue; */
2273 if (strcasecmp(item->key, "Interval") == 0)
2274 cna_config_get_interval (item, &cfg_volume_usage->interval);
2275 else if (!strcasecmp(item->key, "GetCapacity"))
2276 cna_config_volume_usage_option (cfg_volume_usage, item);
2277 else if (!strcasecmp(item->key, "GetSnapshot"))
2278 cna_config_volume_usage_option (cfg_volume_usage, item);
2279 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2280 cna_config_volume_usage_default (cfg_volume_usage, item);
2281 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2282 cna_config_volume_usage_default (cfg_volume_usage, item);
2284 WARNING ("netapp plugin: The option %s is not allowed within "
2285 "`VolumeUsage' blocks.", item->key);
2289 } /* }}} int cna_config_volume_usage */
2291 /* Corresponds to a <System /> block */
2292 static int cna_config_system (host_config_t *host, /* {{{ */
2295 cfg_system_t *cfg_system;
2298 if ((host == NULL) || (ci == NULL))
2301 if (host->cfg_system == NULL)
2303 cfg_system = malloc (sizeof (*cfg_system));
2304 if (cfg_system == NULL)
2306 memset (cfg_system, 0, sizeof (*cfg_system));
2308 /* Set default flags */
2309 cfg_system->flags = CFG_SYSTEM_ALL;
2310 cfg_system->query = NULL;
2312 host->cfg_system = cfg_system;
2314 cfg_system = host->cfg_system;
2316 for (i = 0; i < ci->children_num; ++i) {
2317 oconfig_item_t *item = ci->children + i;
2319 if (strcasecmp(item->key, "Interval") == 0) {
2320 cna_config_get_interval (item, &cfg_system->interval);
2321 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2322 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2323 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2324 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2325 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2326 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2327 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2328 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2330 WARNING ("netapp plugin: The %s config option is not allowed within "
2331 "`System' blocks.", item->key);
2335 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2337 NOTICE ("netapp plugin: All system related values have been disabled. "
2338 "Collection of system data will be disabled entirely.");
2339 free_cfg_system (host->cfg_system);
2340 host->cfg_system = NULL;
2344 } /* }}} int cna_config_system */
2346 /* Corresponds to a <Host /> block. */
2347 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
2348 const host_config_t *default_host)
2350 oconfig_item_t *item;
2351 host_config_t *host;
2355 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2356 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
2360 host = malloc(sizeof(*host));
2361 memcpy (host, default_host, sizeof (*host));
2363 status = cf_util_get_string (ci, &host->name);
2370 for (i = 0; i < ci->children_num; ++i) {
2371 item = ci->children + i;
2375 if (!strcasecmp(item->key, "Address")) {
2376 status = cf_util_get_string (item, &host->host);
2377 } else if (!strcasecmp(item->key, "Port")) {
2380 tmp = cf_util_get_port_number (item);
2383 } else if (!strcasecmp(item->key, "Protocol")) {
2384 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"))) {
2385 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2388 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2389 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2390 } else if (!strcasecmp(item->key, "User")) {
2391 status = cf_util_get_string (item, &host->username);
2392 } else if (!strcasecmp(item->key, "Password")) {
2393 status = cf_util_get_string (item, &host->password);
2394 } else if (!strcasecmp(item->key, "Interval")) {
2395 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) {
2396 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
2399 host->interval = item->values[0].value.number;
2400 } else if (!strcasecmp(item->key, "WAFL")) {
2401 cna_config_wafl(host, item);
2402 } else if (!strcasecmp(item->key, "Disks")) {
2403 cna_config_disk(host, item);
2404 } else if (!strcasecmp(item->key, "VolumePerf")) {
2405 cna_config_volume_performance(host, item);
2406 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2407 cna_config_volume_usage(host, item);
2408 } else if (!strcasecmp(item->key, "System")) {
2409 cna_config_system(host, item);
2411 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
2412 item->key, ci->values[0].value.string);
2419 if (host->host == NULL)
2420 host->host = strdup (host->name);
2422 if (host->host == NULL)
2425 if (host->port <= 0)
2426 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2428 if ((host->username == NULL) || (host->password == NULL)) {
2429 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2430 "Ignoring host block.", host->name);
2436 free_host_config (host);
2441 } /* }}} host_config_t *cna_config_host */
2444 * Callbacks registered with the daemon
2446 * Pretty standard stuff here.
2448 static int cna_init(void) { /* {{{ */
2450 host_config_t *host;
2452 if (!global_host_config) {
2453 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
2457 memset (err, 0, sizeof (err));
2458 if (!na_startup(err, sizeof(err))) {
2459 err[sizeof (err) - 1] = 0;
2460 ERROR("netapp plugin: Error initializing netapp API: %s", err);
2464 for (host = global_host_config; host; host = host->next) {
2465 /* Request version 1.1 of the ONTAP API */
2466 host->srv = na_server_open(host->host,
2467 /* major version = */ 1, /* minor version = */ 1);
2468 if (host->srv == NULL) {
2469 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
2473 if (host->interval < interval_g)
2474 host->interval = interval_g;
2476 na_server_set_transport_type(host->srv, host->protocol,
2477 /* transportarg = */ NULL);
2478 na_server_set_port(host->srv, host->port);
2479 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
2480 na_server_adminuser(host->srv, host->username, host->password);
2481 na_server_set_timeout(host->srv, 5 /* seconds */);
2484 } /* }}} int cna_init */
2486 static int cna_config (oconfig_item_t *ci) { /* {{{ */
2488 oconfig_item_t *item;
2489 host_config_t default_host = HOST_INIT;
2491 for (i = 0; i < ci->children_num; ++i) {
2492 item = ci->children + i;
2494 if (!strcasecmp(item->key, "Host")) {
2495 host_config_t *host;
2498 host = cna_config_host(item, &default_host);
2502 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
2504 if (strcasecmp (host->name, tmp->name) == 0)
2505 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
2506 "This is probably a bad idea.",
2509 if (tmp->next == NULL)
2515 global_host_config = host;
2519 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
2523 } /* }}} int cna_config */
2525 static int cna_read (void) { /* {{{ */
2526 host_config_t *host;
2528 for (host = global_host_config; host; host = host->next) {
2529 cna_query_wafl (host);
2530 cna_query_disk (host);
2531 cna_query_volume_perf (host);
2532 cna_query_volume_usage (host);
2533 cna_query_system (host);
2536 } /* }}} int cna_read */
2538 static int cna_shutdown (void) /* {{{ */
2540 free_host_config (global_host_config);
2541 global_host_config = NULL;
2544 } /* }}} int cna_shutdown */
2546 void module_register(void) {
2547 plugin_register_complex_config("netapp", cna_config);
2548 plugin_register_init("netapp", cna_init);
2549 plugin_register_read("netapp", cna_read);
2550 plugin_register_shutdown("netapp", cna_shutdown);
2553 /* vim: set sw=2 ts=2 noet fdm=marker : */