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 struct data_volume_usage_s;
194 typedef struct data_volume_usage_s data_volume_usage_t;
195 struct data_volume_usage_s {
199 na_elem_t *snap_query;
203 uint64_t snap_reserved;
207 data_volume_usage_t *next;
211 cna_interval_t interval;
214 ignorelist_t *il_capacity;
215 ignorelist_t *il_snapshot;
217 data_volume_usage_t *volumes;
218 } cfg_volume_usage_t;
219 /* }}} cfg_volume_usage_t */
221 /*! Data types for system statistics {{{
223 * \brief Persistent data for system performance counters
225 #define CFG_SYSTEM_CPU 0x01
226 #define CFG_SYSTEM_NET 0x02
227 #define CFG_SYSTEM_OPS 0x04
228 #define CFG_SYSTEM_DISK 0x08
229 #define CFG_SYSTEM_ALL 0x0F
232 cna_interval_t interval;
235 /* }}} cfg_system_t */
237 struct host_config_s {
239 na_server_transport_t protocol;
247 cfg_wafl_t *cfg_wafl;
248 cfg_disk_t *cfg_disk;
249 cfg_volume_perf_t *cfg_volume_perf;
250 cfg_volume_usage_t *cfg_volume_usage;
251 cfg_system_t *cfg_system;
253 struct host_config_s *next;
255 #define HOST_INIT { NULL, NA_SERVER_TRANSPORT_HTTPS, NULL, 0, NULL, NULL, 0, \
256 NULL, NULL, NULL, NULL, NULL, NULL, \
259 static host_config_t *global_host_config;
264 * Used to free the various structures above.
266 static void free_disk (disk_t *disk) /* {{{ */
279 } /* }}} void free_disk */
281 static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
286 if (cw->query != NULL)
287 na_elem_free (cw->query);
290 } /* }}} void free_cfg_wafl */
292 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
294 if (cfg_disk == NULL)
297 if (cfg_disk->query != NULL)
298 na_elem_free (cfg_disk->query);
300 free_disk (cfg_disk->disks);
302 } /* }}} void free_cfg_disk */
304 static void free_cfg_volume_perf (cfg_volume_perf_t *cvp) /* {{{ */
306 data_volume_perf_t *data;
311 /* Free the ignorelists */
312 ignorelist_free (cvp->il_octets);
313 ignorelist_free (cvp->il_operations);
314 ignorelist_free (cvp->il_latency);
316 /* Free the linked list of volumes */
320 data_volume_perf_t *next = data->next;
326 if (cvp->query != NULL)
327 na_elem_free (cvp->query);
330 } /* }}} void free_cfg_volume_perf */
332 static void free_cfg_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
334 data_volume_usage_t *data;
339 /* Free the ignorelists */
340 ignorelist_free (cvu->il_capacity);
341 ignorelist_free (cvu->il_snapshot);
343 /* Free the linked list of volumes */
347 data_volume_usage_t *next = data->next;
349 if (data->snap_query != NULL)
350 na_elem_free(data->snap_query);
355 if (cvu->query != NULL)
356 na_elem_free (cvu->query);
359 } /* }}} void free_cfg_volume_usage */
361 static void free_cfg_system (cfg_system_t *cs) /* {{{ */
366 if (cs->query != NULL)
367 na_elem_free (cs->query);
370 } /* }}} void free_cfg_system */
372 static void free_host_config (host_config_t *hc) /* {{{ */
383 sfree (hc->username);
384 sfree (hc->password);
386 free_cfg_disk (hc->cfg_disk);
387 free_cfg_wafl (hc->cfg_wafl);
388 free_cfg_volume_perf (hc->cfg_volume_perf);
389 free_cfg_volume_usage (hc->cfg_volume_usage);
390 free_cfg_system (hc->cfg_system);
393 na_server_close (hc->srv);
397 free_host_config (next);
398 } /* }}} void free_host_config */
401 * Auxiliary functions
403 * Used to look up volumes and disks or to handle flags.
405 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
409 if ((cd == NULL) || (name == NULL))
412 for (d = cd->disks; d != NULL; d = d->next) {
413 if (strcmp(d->name, name) == 0)
417 d = malloc(sizeof(*d));
420 memset (d, 0, sizeof (*d));
423 d->name = strdup(name);
424 if (d->name == NULL) {
433 } /* }}} disk_t *get_disk */
435 static data_volume_usage_t *get_volume_usage (cfg_volume_usage_t *cvu, /* {{{ */
438 data_volume_usage_t *last;
439 data_volume_usage_t *new;
441 int ignore_capacity = 0;
442 int ignore_snapshot = 0;
444 if ((cvu == NULL) || (name == NULL))
450 if (strcmp (last->name, name) == 0)
453 if (last->next == NULL)
459 /* Check the ignorelists. If *both* tell us to ignore a volume, return NULL. */
460 ignore_capacity = ignorelist_match (cvu->il_capacity, name);
461 ignore_snapshot = ignorelist_match (cvu->il_snapshot, name);
462 if ((ignore_capacity != 0) && (ignore_snapshot != 0))
465 /* Not found: allocate. */
466 new = malloc (sizeof (*new));
469 memset (new, 0, sizeof (*new));
472 new->name = strdup (name);
473 if (new->name == NULL)
479 if (ignore_capacity == 0)
480 new->flags |= CFG_VOLUME_USAGE_DF;
481 if (ignore_snapshot == 0) {
482 new->flags |= CFG_VOLUME_USAGE_SNAP;
483 new->snap_query = na_elem_new ("snapshot-list-info");
484 na_child_add_string(new->snap_query, "target-type", "volume");
485 na_child_add_string(new->snap_query, "target-name", name);
487 new->snap_query = NULL;
490 /* Add to end of list. */
497 } /* }}} data_volume_usage_t *get_volume_usage */
499 static data_volume_perf_t *get_volume_perf (cfg_volume_perf_t *cvp, /* {{{ */
502 data_volume_perf_t *last;
503 data_volume_perf_t *new;
505 int ignore_octets = 0;
506 int ignore_operations = 0;
507 int ignore_latency = 0;
509 if ((cvp == NULL) || (name == NULL))
515 if (strcmp (last->name, name) == 0)
518 if (last->next == NULL)
524 /* Check the ignorelists. If *all three* tell us to ignore a volume, return
526 ignore_octets = ignorelist_match (cvp->il_octets, name);
527 ignore_operations = ignorelist_match (cvp->il_operations, name);
528 ignore_latency = ignorelist_match (cvp->il_latency, name);
529 if ((ignore_octets != 0) || (ignore_operations != 0)
530 || (ignore_latency != 0))
533 /* Not found: allocate. */
534 new = malloc (sizeof (*new));
537 memset (new, 0, sizeof (*new));
540 new->name = strdup (name);
541 if (new->name == NULL)
547 if (ignore_octets == 0)
548 new->flags |= CFG_VOLUME_PERF_IO;
549 if (ignore_operations == 0)
550 new->flags |= CFG_VOLUME_PERF_OPS;
551 if (ignore_latency == 0)
552 new->flags |= CFG_VOLUME_PERF_LATENCY;
554 /* Add to end of list. */
561 } /* }}} data_volume_perf_t *get_volume_perf */
564 * Various submit functions.
566 * They all eventually call "submit_values" which creates a value_list_t and
567 * dispatches it to the daemon.
569 static int submit_values (const char *host, /* {{{ */
570 const char *plugin_inst,
571 const char *type, const char *type_inst,
572 value_t *values, int values_len,
575 value_list_t vl = VALUE_LIST_INIT;
578 vl.values_len = values_len;
584 sstrncpy (vl.host, host, sizeof (vl.host));
586 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
587 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
588 if (plugin_inst != NULL)
589 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
590 sstrncpy (vl.type, type, sizeof (vl.type));
591 if (type_inst != NULL)
592 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
594 return (plugin_dispatch_values (&vl));
595 } /* }}} int submit_uint64 */
597 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
598 const char *type, const char *type_inst, counter_t val0, counter_t val1,
603 values[0].counter = val0;
604 values[1].counter = val1;
606 return (submit_values (host, plugin_inst, type, type_inst,
607 values, 2, timestamp));
608 } /* }}} int submit_two_counters */
610 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
611 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
617 return (submit_values (host, plugin_inst, type, type_inst,
619 } /* }}} int submit_counter */
621 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
622 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
627 values[0].gauge = val0;
628 values[1].gauge = val1;
630 return (submit_values (host, plugin_inst, type, type_inst,
631 values, 2, timestamp));
632 } /* }}} int submit_two_gauge */
634 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
635 const char *type, const char *type_inst, double d, time_t timestamp)
639 v.gauge = (gauge_t) d;
641 return (submit_values (host, plugin_inst, type, type_inst,
643 } /* }}} int submit_uint64 */
645 /* Calculate hit ratio from old and new counters and submit the resulting
646 * percentage. Used by "submit_wafl_data". */
647 static int submit_cache_ratio (const char *host, /* {{{ */
648 const char *plugin_inst,
649 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,
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)
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);
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);
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);
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);
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)
733 /* Check for and submit disk-octet values */
734 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
735 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
737 submit_two_counters (hostname, old_data->name, "disk_octets", /* type instance = */ NULL,
738 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
741 /* Check for and submit disk-operations values */
742 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
743 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
745 submit_two_counters (hostname, old_data->name, "disk_ops", /* type instance = */ NULL,
746 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
749 /* Check for, calculate and submit disk-latency values */
750 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
751 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
752 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
753 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
754 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
756 gauge_t latency_per_op_read;
757 gauge_t latency_per_op_write;
759 latency_per_op_read = NAN;
760 latency_per_op_write = NAN;
762 /* Check if a counter wrapped around. */
763 if ((new_data->read_ops > old_data->read_ops)
764 && (new_data->read_latency > old_data->read_latency))
766 uint64_t diff_ops_read;
767 uint64_t diff_latency_read;
769 diff_ops_read = new_data->read_ops - old_data->read_ops;
770 diff_latency_read = new_data->read_latency - old_data->read_latency;
772 if (diff_ops_read > 0)
773 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
776 if ((new_data->write_ops > old_data->write_ops)
777 && (new_data->write_latency > old_data->write_latency))
779 uint64_t diff_ops_write;
780 uint64_t diff_latency_write;
782 diff_ops_write = new_data->write_ops - old_data->write_ops;
783 diff_latency_write = new_data->write_latency - old_data->write_latency;
785 if (diff_ops_write > 0)
786 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
789 submit_two_gauge (hostname, old_data->name, "disk_latency", /* type instance = */ NULL,
790 latency_per_op_read, latency_per_op_write, new_data->timestamp);
793 /* Clear all HAVE_* flags. */
794 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
796 /* Copy all counters */
797 old_data->timestamp = new_data->timestamp;
798 old_data->read_bytes = new_data->read_bytes;
799 old_data->write_bytes = new_data->write_bytes;
800 old_data->read_ops = new_data->read_ops;
801 old_data->write_ops = new_data->write_ops;
802 old_data->read_latency = new_data->read_latency;
803 old_data->write_latency = new_data->write_latency;
805 /* Copy the HAVE_* flags */
806 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
809 } /* }}} int submit_volume_perf_data */
814 * These functions are called with appropriate data returned by the libnetapp
815 * interface which is parsed and submitted with the above functions.
817 /* Data corresponding to <WAFL /> */
818 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
821 cfg_wafl_t perf_data;
822 const char *plugin_inst;
824 na_elem_t *instances;
826 na_elem_iter_t counter_iter;
828 memset (&perf_data, 0, sizeof (perf_data));
830 perf_data.timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
832 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
833 if (instances == NULL)
835 ERROR ("netapp plugin: cna_handle_wafl_data: "
836 "na_elem_child (\"instances\") failed.");
840 plugin_inst = na_child_get_string(instances, "name");
841 if (plugin_inst == NULL)
843 ERROR ("netapp plugin: cna_handle_wafl_data: "
844 "na_child_get_string (\"name\") failed.");
848 /* Iterate over all counters */
849 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
850 for (counter = na_iterator_next (&counter_iter);
852 counter = na_iterator_next (&counter_iter))
857 name = na_child_get_string(counter, "name");
861 value = na_child_get_uint64(counter, "value", UINT64_MAX);
862 if (value == UINT64_MAX)
865 if (!strcmp(name, "name_cache_hit")) {
866 perf_data.name_cache_hit = value;
867 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
868 } else if (!strcmp(name, "name_cache_miss")) {
869 perf_data.name_cache_miss = value;
870 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
871 } else if (!strcmp(name, "find_dir_hit")) {
872 perf_data.find_dir_hit = value;
873 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
874 } else if (!strcmp(name, "find_dir_miss")) {
875 perf_data.find_dir_miss = value;
876 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
877 } else if (!strcmp(name, "buf_hash_hit")) {
878 perf_data.buf_hash_hit = value;
879 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
880 } else if (!strcmp(name, "buf_hash_miss")) {
881 perf_data.buf_hash_miss = value;
882 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
883 } else if (!strcmp(name, "inode_cache_hit")) {
884 perf_data.inode_cache_hit = value;
885 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
886 } else if (!strcmp(name, "inode_cache_miss")) {
887 perf_data.inode_cache_miss = value;
888 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
890 DEBUG("netapp plugin: cna_handle_wafl_data: "
891 "Found unexpected child: %s", name);
895 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data));
896 } /* }}} void cna_handle_wafl_data */
898 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
905 if (cw->query != NULL)
908 cw->query = na_elem_new("perf-object-get-instances");
909 if (cw->query == NULL)
911 ERROR ("netapp plugin: na_elem_new failed.");
914 na_child_add_string (cw->query, "objectname", "wafl");
916 e = na_elem_new("counters");
919 na_elem_free (cw->query);
921 ERROR ("netapp plugin: na_elem_new failed.");
924 na_child_add_string(e, "foo", "name_cache_hit");
925 na_child_add_string(e, "foo", "name_cache_miss");
926 na_child_add_string(e, "foo", "find_dir_hit");
927 na_child_add_string(e, "foo", "find_dir_miss");
928 na_child_add_string(e, "foo", "buf_hash_hit");
929 na_child_add_string(e, "foo", "buf_hash_miss");
930 na_child_add_string(e, "foo", "inode_cache_hit");
931 na_child_add_string(e, "foo", "inode_cache_miss");
933 na_child_add(cw->query, e);
936 } /* }}} int cna_setup_wafl */
938 static int cna_query_wafl (host_config_t *host) /* {{{ */
947 /* If WAFL was not configured, return without doing anything. */
948 if (host->cfg_wafl == NULL)
952 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
955 status = cna_setup_wafl (host->cfg_wafl);
958 assert (host->cfg_wafl->query != NULL);
960 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
961 if (na_results_status (data) != NA_OK)
963 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed: %s",
964 na_results_reason (data));
969 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data);
972 host->cfg_wafl->interval.last_read = now;
976 } /* }}} int cna_query_wafl */
978 /* Data corresponding to <Disks /> */
979 static int cna_handle_disk_data (const char *hostname, /* {{{ */
980 cfg_disk_t *cfg_disk, na_elem_t *data)
983 na_elem_t *instances;
985 na_elem_iter_t instance_iter;
986 disk_t *worst_disk = NULL;
988 if ((cfg_disk == NULL) || (data == NULL))
991 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
993 instances = na_elem_child (data, "instances");
994 if (instances == NULL)
996 ERROR ("netapp plugin: cna_handle_disk_data: "
997 "na_elem_child (\"instances\") failed.");
1001 /* Iterate over all children */
1002 instance_iter = na_child_iterator (instances);
1003 for (instance = na_iterator_next (&instance_iter);
1005 instance = na_iterator_next(&instance_iter))
1010 na_elem_iter_t counter_iterator;
1013 memset (&new_data, 0, sizeof (new_data));
1014 new_data.timestamp = timestamp;
1015 new_data.disk_busy_percent = NAN;
1017 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1018 if (old_data == NULL)
1021 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1022 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1023 for (counter = na_iterator_next(&counter_iterator);
1025 counter = na_iterator_next(&counter_iterator))
1030 name = na_child_get_string(counter, "name");
1034 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1035 if (value == UINT64_MAX)
1038 if (strcmp(name, "disk_busy") == 0)
1040 new_data.disk_busy = value;
1041 new_data.flags |= HAVE_DISK_BUSY;
1043 else if (strcmp(name, "base_for_disk_busy") == 0)
1045 new_data.base_for_disk_busy = value;
1046 new_data.flags |= HAVE_DISK_BASE;
1050 DEBUG ("netapp plugin: cna_handle_disk_data: "
1051 "Counter not handled: %s = %"PRIu64,
1056 /* If all required counters are available and did not just wrap around,
1057 * calculate the busy percentage. Otherwise, the value is initialized to
1058 * NAN at the top of the for-loop. */
1059 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1060 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1061 && (new_data.disk_busy >= old_data->disk_busy)
1062 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1067 busy_diff = new_data.disk_busy - old_data->disk_busy;
1068 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1070 new_data.disk_busy_percent = 100.0
1071 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1074 /* Clear HAVE_* flags */
1075 old_data->flags &= ~HAVE_DISK_ALL;
1078 old_data->timestamp = new_data.timestamp;
1079 old_data->disk_busy = new_data.disk_busy;
1080 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1081 old_data->disk_busy_percent = new_data.disk_busy_percent;
1084 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1086 if ((worst_disk == NULL)
1087 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1088 worst_disk = old_data;
1089 } /* for (all disks) */
1091 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1092 submit_double (hostname, "system", "percent", "disk_busy",
1093 worst_disk->disk_busy_percent, timestamp);
1096 } /* }}} int cna_handle_disk_data */
1098 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1105 if (cd->query != NULL)
1108 cd->query = na_elem_new ("perf-object-get-instances");
1109 if (cd->query == NULL)
1111 ERROR ("netapp plugin: na_elem_new failed.");
1114 na_child_add_string (cd->query, "objectname", "disk");
1116 e = na_elem_new("counters");
1119 na_elem_free (cd->query);
1121 ERROR ("netapp plugin: na_elem_new failed.");
1124 na_child_add_string(e, "foo", "disk_busy");
1125 na_child_add_string(e, "foo", "base_for_disk_busy");
1126 na_child_add(cd->query, e);
1129 } /* }}} int cna_setup_disk */
1131 static int cna_query_disk (host_config_t *host) /* {{{ */
1140 /* If the user did not configure disk statistics, return without doing
1142 if (host->cfg_disk == NULL)
1146 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1149 status = cna_setup_disk (host->cfg_disk);
1152 assert (host->cfg_disk->query != NULL);
1154 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1155 if (na_results_status (data) != NA_OK)
1157 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed: %s",
1158 na_results_reason (data));
1159 na_elem_free (data);
1163 status = cna_handle_disk_data (host->name, host->cfg_disk, data);
1166 host->cfg_disk->interval.last_read = now;
1168 na_elem_free (data);
1170 } /* }}} int cna_query_disk */
1172 /* Data corresponding to <VolumePerf /> */
1173 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1174 cfg_volume_perf_t *cvp, na_elem_t *data)
1177 na_elem_t *elem_instances;
1178 na_elem_iter_t iter_instances;
1179 na_elem_t *elem_instance;
1181 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
1183 elem_instances = na_elem_child(data, "instances");
1184 if (elem_instances == NULL)
1186 ERROR ("netapp plugin: handle_volume_perf_data: "
1187 "na_elem_child (\"instances\") failed.");
1191 iter_instances = na_child_iterator (elem_instances);
1192 for (elem_instance = na_iterator_next(&iter_instances);
1193 elem_instance != NULL;
1194 elem_instance = na_iterator_next(&iter_instances))
1198 data_volume_perf_t perf_data;
1199 data_volume_perf_t *v;
1201 na_elem_t *elem_counters;
1202 na_elem_iter_t iter_counters;
1203 na_elem_t *elem_counter;
1205 memset (&perf_data, 0, sizeof (perf_data));
1206 perf_data.timestamp = timestamp;
1208 name = na_child_get_string (elem_instance, "name");
1212 /* get_volume_perf may return NULL if this volume is to be ignored. */
1213 v = get_volume_perf (cvp, name);
1217 elem_counters = na_elem_child (elem_instance, "counters");
1218 if (elem_counters == NULL)
1221 iter_counters = na_child_iterator (elem_counters);
1222 for (elem_counter = na_iterator_next(&iter_counters);
1223 elem_counter != NULL;
1224 elem_counter = na_iterator_next(&iter_counters))
1229 name = na_child_get_string (elem_counter, "name");
1233 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1234 if (value == UINT64_MAX)
1237 if (!strcmp(name, "read_data")) {
1238 perf_data.read_bytes = value;
1239 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1240 } else if (!strcmp(name, "write_data")) {
1241 perf_data.write_bytes = value;
1242 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1243 } else if (!strcmp(name, "read_ops")) {
1244 perf_data.read_ops = value;
1245 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1246 } else if (!strcmp(name, "write_ops")) {
1247 perf_data.write_ops = value;
1248 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1249 } else if (!strcmp(name, "read_latency")) {
1250 perf_data.read_latency = value;
1251 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1252 } else if (!strcmp(name, "write_latency")) {
1253 perf_data.write_latency = value;
1254 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1256 } /* for (elem_counter) */
1258 submit_volume_perf_data (hostname, v, &perf_data);
1259 } /* for (volume) */
1262 } /* }}} int cna_handle_volume_perf_data */
1264 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1271 if (cd->query != NULL)
1274 cd->query = na_elem_new ("perf-object-get-instances");
1275 if (cd->query == NULL)
1277 ERROR ("netapp plugin: na_elem_new failed.");
1280 na_child_add_string (cd->query, "objectname", "volume");
1282 e = na_elem_new("counters");
1285 na_elem_free (cd->query);
1287 ERROR ("netapp plugin: na_elem_new failed.");
1290 /* "foo" means: This string has to be here but the content doesn't matter. */
1291 na_child_add_string(e, "foo", "read_ops");
1292 na_child_add_string(e, "foo", "write_ops");
1293 na_child_add_string(e, "foo", "read_data");
1294 na_child_add_string(e, "foo", "write_data");
1295 na_child_add_string(e, "foo", "read_latency");
1296 na_child_add_string(e, "foo", "write_latency");
1297 na_child_add(cd->query, e);
1300 } /* }}} int cna_setup_volume_perf */
1302 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1311 /* If the user did not configure volume performance statistics, return
1312 * without doing anything. */
1313 if (host->cfg_volume_perf == NULL)
1317 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1320 status = cna_setup_volume_perf (host->cfg_volume_perf);
1323 assert (host->cfg_volume_perf->query != NULL);
1325 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1326 if (na_results_status (data) != NA_OK)
1328 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed: %s",
1329 na_results_reason (data));
1330 na_elem_free (data);
1334 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data);
1337 host->cfg_volume_perf->interval.last_read = now;
1339 na_elem_free (data);
1341 } /* }}} int cna_query_volume_perf */
1343 /* Data corresponding to <VolumeUsage /> */
1344 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1345 cfg_volume_usage_t *cfg_volume)
1347 data_volume_usage_t *v;
1349 for (v = cfg_volume->volumes; v != NULL; v = v->next)
1351 uint64_t norm_used = v->norm_used;
1352 uint64_t norm_free = v->norm_free;
1353 uint64_t sis_saved = v->sis_saved;
1354 uint64_t snap_reserve_used = 0;
1355 uint64_t snap_reserve_free = v->snap_reserved;
1356 uint64_t snap_norm_used = v->snap_used;
1358 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD)) {
1359 if (v->snap_reserved > v->snap_used) {
1360 snap_reserve_free = v->snap_reserved - v->snap_used;
1361 snap_reserve_used = v->snap_used;
1364 snap_reserve_free = 0;
1365 snap_reserve_used = v->snap_reserved;
1366 snap_norm_used = v->snap_used - v->snap_reserved;
1367 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED)
1368 && (norm_used >= snap_norm_used))
1369 norm_used -= snap_norm_used;
1373 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1374 submit_double (hostname, /* plugin instance = */ v->name,
1375 "df_complex", "free",
1376 (double) norm_free, /* timestamp = */ 0);
1378 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1379 submit_double (hostname, /* plugin instance = */ v->name,
1380 "df_complex", "sis_saved",
1381 (double) sis_saved, /* timestamp = */ 0);
1383 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1384 submit_double (hostname, /* plugin instance = */ v->name,
1385 "df_complex", "used",
1386 (double) norm_used, /* timestamp = */ 0);
1388 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1389 submit_double (hostname, /* plugin instance = */ v->name,
1390 "df_complex", "snap_reserved",
1391 (double) snap_reserve_free, /* timestamp = */ 0);
1393 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
1394 submit_double (hostname, /* plugin instance = */ v->name,
1395 "df_complex", "snap_reserve_used",
1396 (double) snap_reserve_used, /* timestamp = */ 0);
1398 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1399 submit_double (hostname, /* plugin instance = */ v->name,
1400 "df_complex", "snap_normal_used",
1401 (double) snap_norm_used, /* timestamp = */ 0);
1403 /* Clear all the HAVE_* flags */
1404 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1405 } /* for (v = cfg_volume->volumes) */
1408 } /* }}} int cna_submit_volume_usage_data */
1410 static void cna_handle_volume_snap_usage(const host_config_t *host, data_volume_usage_t *v)
1412 uint64_t snap_used = 0, value;
1413 na_elem_t *data, *elem_snap, *elem_snapshots;
1414 na_elem_iter_t iter_snap;
1416 data = na_server_invoke_elem(host->srv, v->snap_query);
1417 if (na_results_status(data) != NA_OK)
1419 if (na_results_errno(data) != EVOLUMEOFFLINE)
1420 ERROR ("netapp plugin: cna_handle_volume_snap_usage: na_server_invoke_elem for "
1421 "volume \"%s\" failed with error %d: %s", v->name,
1422 na_results_errno(data), na_results_reason(data));
1427 elem_snapshots = na_elem_child (data, "snapshots");
1428 if (elem_snapshots == NULL)
1430 ERROR ("netapp plugin: cna_handle_volume_snap_usage: "
1431 "na_elem_child (\"snapshots\") failed.");
1436 iter_snap = na_child_iterator (elem_snapshots);
1437 for (elem_snap = na_iterator_next (&iter_snap);
1439 elem_snap = na_iterator_next (&iter_snap))
1441 value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
1442 /* "cumulative-total" is the total size of the oldest snapshot plus all
1443 * newer ones in blocks (1KB). We therefore are looking for the highest
1444 * number of all snapshots - that's the size required for the snapshots. */
1445 if (value > snap_used)
1448 na_elem_free (data);
1449 /* snap_used is in 1024 byte blocks */
1450 v->snap_used = snap_used * 1024;
1451 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1452 } /* }}} void cna_handle_volume_snap_usage */
1454 static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
1455 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1457 na_elem_t *elem_volume;
1458 na_elem_t *elem_volumes;
1459 na_elem_iter_t iter_volume;
1461 elem_volumes = na_elem_child (data, "volumes");
1462 if (elem_volumes == NULL)
1464 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1465 "na_elem_child (\"volumes\") failed.");
1469 iter_volume = na_child_iterator (elem_volumes);
1470 for (elem_volume = na_iterator_next (&iter_volume);
1471 elem_volume != NULL;
1472 elem_volume = na_iterator_next (&iter_volume))
1474 const char *volume_name, *state;
1476 data_volume_usage_t *v;
1480 const char *sis_state;
1481 uint64_t sis_saved_reported;
1483 volume_name = na_child_get_string (elem_volume, "name");
1484 if (volume_name == NULL)
1487 state = na_child_get_string (elem_volume, "state");
1488 if ((state == NULL) || (strcmp(state, "online") != 0))
1491 /* get_volume_usage may return NULL if the volume is to be ignored. */
1492 v = get_volume_usage (cfg_volume, volume_name);
1496 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1497 cna_handle_volume_snap_usage(host, v);
1499 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1502 /* 2^4 exa-bytes? This will take a while ;) */
1503 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1504 if (value != UINT64_MAX) {
1505 v->norm_free = value;
1506 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1509 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1510 if (value != UINT64_MAX) {
1511 v->norm_used = value;
1512 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1515 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1516 if (value != UINT64_MAX) {
1517 /* 1 block == 1024 bytes as per API docs */
1518 v->snap_reserved = 1024 * value;
1519 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1522 sis = na_elem_child(elem_volume, "sis");
1526 sis_state = na_child_get_string(sis, "state");
1527 if (sis_state == NULL)
1530 /* If SIS is not enabled, there's nothing left to do for this volume. */
1531 if (strcmp ("enabled", sis_state) != 0)
1534 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1535 if (sis_saved_reported == UINT64_MAX)
1538 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1539 if ((sis_saved_reported >> 32) != 0) {
1540 /* In case they ever fix this bug. */
1541 v->sis_saved = sis_saved_reported;
1542 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1543 } else { /* really hacky work-around code. {{{ */
1544 uint64_t sis_saved_percent;
1545 uint64_t sis_saved_guess;
1546 uint64_t overflow_guess;
1547 uint64_t guess1, guess2, guess3;
1549 /* Check if we have v->norm_used. Without it, we cannot calculate
1550 * sis_saved_guess. */
1551 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1554 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1555 if (sis_saved_percent > 100)
1558 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1559 * will hopefully be fixed in later versions. To work around the bug, try
1560 * to figure out how often the 32bit integer wrapped around by using the
1561 * "percentage-saved" value. Because the percentage is in the range
1562 * [0-100], this should work as long as the saved space does not exceed
1564 /* percentage-saved = size-saved / (size-saved + size-used) */
1565 if (sis_saved_percent < 100)
1566 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1568 sis_saved_guess = v->norm_used;
1570 overflow_guess = sis_saved_guess >> 32;
1571 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1572 guess2 = (overflow_guess << 32) + sis_saved_reported;
1573 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1575 if (sis_saved_guess < guess2) {
1576 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1577 v->sis_saved = guess1;
1579 v->sis_saved = guess2;
1581 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1582 v->sis_saved = guess2;
1584 v->sis_saved = guess3;
1586 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1587 } /* }}} end of 32-bit workaround */
1588 } /* for (elem_volume) */
1590 return (cna_submit_volume_usage_data (host->name, cfg_volume));
1591 } /* }}} int cna_handle_volume_usage_data */
1593 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1598 if (cvu->query != NULL)
1601 cvu->query = na_elem_new ("volume-list-info");
1602 if (cvu->query == NULL)
1604 ERROR ("netapp plugin: na_elem_new failed.");
1609 } /* }}} int cna_setup_volume_usage */
1611 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1620 /* If the user did not configure volume_usage statistics, return without
1621 * doing anything. */
1622 if (host->cfg_volume_usage == NULL)
1626 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1629 status = cna_setup_volume_usage (host->cfg_volume_usage);
1632 assert (host->cfg_volume_usage->query != NULL);
1634 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1635 if (na_results_status (data) != NA_OK)
1637 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed: %s",
1638 na_results_reason (data));
1639 na_elem_free (data);
1643 status = cna_handle_volume_usage_data (host, host->cfg_volume_usage, data);
1646 host->cfg_volume_usage->interval.last_read = now;
1648 na_elem_free (data);
1650 } /* }}} int cna_query_volume_usage */
1652 /* Data corresponding to <System /> */
1653 static int cna_handle_system_data (const char *hostname, /* {{{ */
1654 cfg_system_t *cfg_system, na_elem_t *data)
1656 na_elem_t *instances;
1658 na_elem_iter_t counter_iter;
1660 counter_t disk_read = 0, disk_written = 0;
1661 counter_t net_recv = 0, net_sent = 0;
1662 counter_t cpu_busy = 0, cpu_total = 0;
1663 uint32_t counter_flags = 0;
1665 const char *instance;
1668 timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
1670 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1671 if (instances == NULL)
1673 ERROR ("netapp plugin: cna_handle_system_data: "
1674 "na_elem_child (\"instances\") failed.");
1678 instance = na_child_get_string (instances, "name");
1679 if (instance == NULL)
1681 ERROR ("netapp plugin: cna_handle_system_data: "
1682 "na_child_get_string (\"name\") failed.");
1686 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
1687 for (counter = na_iterator_next (&counter_iter);
1689 counter = na_iterator_next (&counter_iter))
1694 name = na_child_get_string(counter, "name");
1698 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1699 if (value == UINT64_MAX)
1702 if (!strcmp(name, "disk_data_read")) {
1703 disk_read = (counter_t) (value * 1024);
1704 counter_flags |= 0x01;
1705 } else if (!strcmp(name, "disk_data_written")) {
1706 disk_written = (counter_t) (value * 1024);
1707 counter_flags |= 0x02;
1708 } else if (!strcmp(name, "net_data_recv")) {
1709 net_recv = (counter_t) (value * 1024);
1710 counter_flags |= 0x04;
1711 } else if (!strcmp(name, "net_data_sent")) {
1712 net_sent = (counter_t) (value * 1024);
1713 counter_flags |= 0x08;
1714 } else if (!strcmp(name, "cpu_busy")) {
1715 cpu_busy = (counter_t) value;
1716 counter_flags |= 0x10;
1717 } else if (!strcmp(name, "cpu_elapsed_time")) {
1718 cpu_total = (counter_t) value;
1719 counter_flags |= 0x20;
1720 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1721 && (value > 0) && (strlen(name) > 4)
1722 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1723 submit_counter (hostname, instance, "disk_ops_complex", name,
1724 (counter_t) value, timestamp);
1726 } /* for (counter) */
1728 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1729 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
1730 submit_two_counters (hostname, instance, "disk_octets", NULL,
1731 disk_read, disk_written, timestamp);
1733 if ((cfg_system->flags & CFG_SYSTEM_NET)
1734 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
1735 submit_two_counters (hostname, instance, "if_octets", NULL,
1736 net_recv, net_sent, timestamp);
1738 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1739 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
1741 submit_counter (hostname, instance, "cpu", "system",
1742 cpu_busy, timestamp);
1743 submit_counter (hostname, instance, "cpu", "idle",
1744 cpu_total - cpu_busy, timestamp);
1748 } /* }}} int cna_handle_system_data */
1750 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
1755 if (cs->query != NULL)
1758 cs->query = na_elem_new ("perf-object-get-instances");
1759 if (cs->query == NULL)
1761 ERROR ("netapp plugin: na_elem_new failed.");
1764 na_child_add_string (cs->query, "objectname", "system");
1767 } /* }}} int cna_setup_system */
1769 static int cna_query_system (host_config_t *host) /* {{{ */
1778 /* If system statistics were not configured, return without doing anything. */
1779 if (host->cfg_system == NULL)
1783 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
1786 status = cna_setup_system (host->cfg_system);
1789 assert (host->cfg_system->query != NULL);
1791 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
1792 if (na_results_status (data) != NA_OK)
1794 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed: %s",
1795 na_results_reason (data));
1796 na_elem_free (data);
1800 status = cna_handle_system_data (host->name, host->cfg_system, data);
1803 host->cfg_system->interval.last_read = now;
1805 na_elem_free (data);
1807 } /* }}} int cna_query_system */
1810 * Configuration handling
1812 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1813 * is false. On error, the flag-field is not changed. */
1814 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1815 uint32_t *flags, uint32_t flag)
1817 if ((ci == NULL) || (flags == NULL))
1820 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1822 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1827 if (ci->values[0].value.boolean)
1833 } /* }}} int cna_config_bool_to_flag */
1835 /* Handling of the "Interval" option which is allowed in every block. */
1836 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1837 cna_interval_t *out_interval)
1841 if ((ci == NULL) || (out_interval == NULL))
1844 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1846 WARNING ("netapp plugin: The `Interval' option needs exactly one numeric argument.");
1850 tmp = (time_t) (ci->values[0].value.number + .5);
1853 WARNING ("netapp plugin: The `Interval' option needs a positive integer argument.");
1857 out_interval->interval = tmp;
1858 out_interval->last_read = 0;
1861 } /* }}} int cna_config_get_interval */
1863 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1864 * <VolumePerf /> block. */
1865 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
1866 const oconfig_item_t *ci)
1871 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1873 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1878 name = ci->values[0].value.string;
1880 if (strcasecmp ("GetIO", ci->key) == 0)
1881 il = cvp->il_octets;
1882 else if (strcasecmp ("GetOps", ci->key) == 0)
1883 il = cvp->il_operations;
1884 else if (strcasecmp ("GetLatency", ci->key) == 0)
1885 il = cvp->il_latency;
1889 ignorelist_add (il, name);
1890 } /* }}} void cna_config_volume_perf_option */
1892 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
1893 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
1894 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
1895 const oconfig_item_t *ci)
1899 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1901 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1906 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
1907 il = cvp->il_octets;
1908 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
1909 il = cvp->il_operations;
1910 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
1911 il = cvp->il_latency;
1915 if (ci->values[0].value.boolean)
1916 ignorelist_set_invert (il, /* invert = */ 0);
1918 ignorelist_set_invert (il, /* invert = */ 1);
1919 } /* }}} void cna_config_volume_perf_default */
1921 /* Corresponds to a <Disks /> block */
1926 * IgnoreSelectedIO false
1930 * IgnoreSelectedOps false
1934 * IgnoreSelectedLatency false
1937 /* Corresponds to a <VolumePerf /> block */
1938 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
1939 const oconfig_item_t *ci)
1941 cfg_volume_perf_t *cfg_volume_perf;
1944 if ((host == NULL) || (ci == NULL))
1947 if (host->cfg_volume_perf == NULL)
1949 cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
1950 if (cfg_volume_perf == NULL)
1952 memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
1954 /* Set default flags */
1955 cfg_volume_perf->query = NULL;
1956 cfg_volume_perf->volumes = NULL;
1958 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
1959 if (cfg_volume_perf->il_octets == NULL)
1961 sfree (cfg_volume_perf);
1965 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
1966 if (cfg_volume_perf->il_operations == NULL)
1968 ignorelist_free (cfg_volume_perf->il_octets);
1969 sfree (cfg_volume_perf);
1973 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
1974 if (cfg_volume_perf->il_latency == NULL)
1976 ignorelist_free (cfg_volume_perf->il_octets);
1977 ignorelist_free (cfg_volume_perf->il_operations);
1978 sfree (cfg_volume_perf);
1982 host->cfg_volume_perf = cfg_volume_perf;
1984 cfg_volume_perf = host->cfg_volume_perf;
1986 for (i = 0; i < ci->children_num; ++i) {
1987 oconfig_item_t *item = ci->children + i;
1989 /* if (!item || !item->key || !*item->key) continue; */
1990 if (strcasecmp(item->key, "Interval") == 0)
1991 cna_config_get_interval (item, &cfg_volume_perf->interval);
1992 else if (!strcasecmp(item->key, "GetIO"))
1993 cna_config_volume_perf_option (cfg_volume_perf, item);
1994 else if (!strcasecmp(item->key, "GetOps"))
1995 cna_config_volume_perf_option (cfg_volume_perf, item);
1996 else if (!strcasecmp(item->key, "GetLatency"))
1997 cna_config_volume_perf_option (cfg_volume_perf, item);
1998 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
1999 cna_config_volume_perf_default (cfg_volume_perf, item);
2000 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
2001 cna_config_volume_perf_default (cfg_volume_perf, item);
2002 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2003 cna_config_volume_perf_default (cfg_volume_perf, item);
2005 WARNING ("netapp plugin: The option %s is not allowed within "
2006 "`VolumePerf' blocks.", item->key);
2010 } /* }}} int cna_config_volume_performance */
2012 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2013 * <VolumeUsage /> block. */
2014 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
2015 const oconfig_item_t *ci)
2020 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2022 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2027 name = ci->values[0].value.string;
2029 if (strcasecmp ("GetCapacity", ci->key) == 0)
2030 il = cvu->il_capacity;
2031 else if (strcasecmp ("GetSnapshot", ci->key) == 0)
2032 il = cvu->il_snapshot;
2036 ignorelist_add (il, name);
2037 } /* }}} void cna_config_volume_usage_option */
2039 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2040 * options within a <VolumeUsage /> block. */
2041 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
2042 const oconfig_item_t *ci)
2046 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2048 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2053 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2054 il = cvu->il_capacity;
2055 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2056 il = cvu->il_snapshot;
2060 if (ci->values[0].value.boolean)
2061 ignorelist_set_invert (il, /* invert = */ 0);
2063 ignorelist_set_invert (il, /* invert = */ 1);
2064 } /* }}} void cna_config_volume_usage_default */
2066 /* Corresponds to a <Disks /> block */
2067 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2068 cfg_disk_t *cfg_disk;
2071 if ((host == NULL) || (ci == NULL))
2074 if (host->cfg_disk == NULL)
2076 cfg_disk = malloc (sizeof (*cfg_disk));
2077 if (cfg_disk == NULL)
2079 memset (cfg_disk, 0, sizeof (*cfg_disk));
2081 /* Set default flags */
2082 cfg_disk->flags = CFG_DISK_ALL;
2083 cfg_disk->query = NULL;
2084 cfg_disk->disks = NULL;
2086 host->cfg_disk = cfg_disk;
2088 cfg_disk = host->cfg_disk;
2090 for (i = 0; i < ci->children_num; ++i) {
2091 oconfig_item_t *item = ci->children + i;
2093 /* if (!item || !item->key || !*item->key) continue; */
2094 if (strcasecmp(item->key, "Interval") == 0)
2095 cna_config_get_interval (item, &cfg_disk->interval);
2096 else if (strcasecmp(item->key, "GetBusy") == 0)
2097 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2100 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2102 NOTICE ("netapp plugin: All disk related values have been disabled. "
2103 "Collection of per-disk data will be disabled entirely.");
2104 free_cfg_disk (host->cfg_disk);
2105 host->cfg_disk = NULL;
2109 } /* }}} int cna_config_disk */
2111 /* Corresponds to a <WAFL /> block */
2112 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2114 cfg_wafl_t *cfg_wafl;
2117 if ((host == NULL) || (ci == NULL))
2120 if (host->cfg_wafl == NULL)
2122 cfg_wafl = malloc (sizeof (*cfg_wafl));
2123 if (cfg_wafl == NULL)
2125 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
2127 /* Set default flags */
2128 cfg_wafl->flags = CFG_WAFL_ALL;
2130 host->cfg_wafl = cfg_wafl;
2132 cfg_wafl = host->cfg_wafl;
2134 for (i = 0; i < ci->children_num; ++i) {
2135 oconfig_item_t *item = ci->children + i;
2137 if (strcasecmp(item->key, "Interval") == 0)
2138 cna_config_get_interval (item, &cfg_wafl->interval);
2139 else if (!strcasecmp(item->key, "GetNameCache"))
2140 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2141 else if (!strcasecmp(item->key, "GetDirCache"))
2142 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2143 else if (!strcasecmp(item->key, "GetBufferCache"))
2144 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2145 else if (!strcasecmp(item->key, "GetInodeCache"))
2146 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2148 WARNING ("netapp plugin: The %s config option is not allowed within "
2149 "`WAFL' blocks.", item->key);
2152 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2154 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2155 "Collection of WAFL data will be disabled entirely.");
2156 free_cfg_wafl (host->cfg_wafl);
2157 host->cfg_wafl = NULL;
2161 } /* }}} int cna_config_wafl */
2165 * GetCapacity "vol0"
2166 * GetCapacity "vol1"
2167 * GetCapacity "vol2"
2168 * GetCapacity "vol3"
2169 * GetCapacity "vol4"
2170 * IgnoreSelectedCapacity false
2172 * GetSnapshot "vol0"
2173 * GetSnapshot "vol3"
2174 * GetSnapshot "vol4"
2175 * GetSnapshot "vol7"
2176 * IgnoreSelectedSnapshot false
2179 /* Corresponds to a <VolumeUsage /> block */
2180 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2181 const oconfig_item_t *ci)
2183 cfg_volume_usage_t *cfg_volume_usage;
2186 if ((host == NULL) || (ci == NULL))
2189 if (host->cfg_volume_usage == NULL)
2191 cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
2192 if (cfg_volume_usage == NULL)
2194 memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
2196 /* Set default flags */
2197 cfg_volume_usage->query = NULL;
2198 cfg_volume_usage->volumes = NULL;
2200 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2201 if (cfg_volume_usage->il_capacity == NULL)
2203 sfree (cfg_volume_usage);
2207 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2208 if (cfg_volume_usage->il_snapshot == NULL)
2210 ignorelist_free (cfg_volume_usage->il_capacity);
2211 sfree (cfg_volume_usage);
2215 host->cfg_volume_usage = cfg_volume_usage;
2217 cfg_volume_usage = host->cfg_volume_usage;
2219 for (i = 0; i < ci->children_num; ++i) {
2220 oconfig_item_t *item = ci->children + i;
2222 /* if (!item || !item->key || !*item->key) continue; */
2223 if (strcasecmp(item->key, "Interval") == 0)
2224 cna_config_get_interval (item, &cfg_volume_usage->interval);
2225 else if (!strcasecmp(item->key, "GetCapacity"))
2226 cna_config_volume_usage_option (cfg_volume_usage, item);
2227 else if (!strcasecmp(item->key, "GetSnapshot"))
2228 cna_config_volume_usage_option (cfg_volume_usage, item);
2229 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2230 cna_config_volume_usage_default (cfg_volume_usage, item);
2231 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2232 cna_config_volume_usage_default (cfg_volume_usage, item);
2234 WARNING ("netapp plugin: The option %s is not allowed within "
2235 "`VolumeUsage' blocks.", item->key);
2239 } /* }}} int cna_config_volume_usage */
2241 /* Corresponds to a <System /> block */
2242 static int cna_config_system (host_config_t *host, /* {{{ */
2245 cfg_system_t *cfg_system;
2248 if ((host == NULL) || (ci == NULL))
2251 if (host->cfg_system == NULL)
2253 cfg_system = malloc (sizeof (*cfg_system));
2254 if (cfg_system == NULL)
2256 memset (cfg_system, 0, sizeof (*cfg_system));
2258 /* Set default flags */
2259 cfg_system->flags = CFG_SYSTEM_ALL;
2260 cfg_system->query = NULL;
2262 host->cfg_system = cfg_system;
2264 cfg_system = host->cfg_system;
2266 for (i = 0; i < ci->children_num; ++i) {
2267 oconfig_item_t *item = ci->children + i;
2269 if (strcasecmp(item->key, "Interval") == 0) {
2270 cna_config_get_interval (item, &cfg_system->interval);
2271 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2272 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2273 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2274 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2275 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2276 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2277 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2278 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2280 WARNING ("netapp plugin: The %s config option is not allowed within "
2281 "`System' blocks.", item->key);
2285 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2287 NOTICE ("netapp plugin: All system related values have been disabled. "
2288 "Collection of system data will be disabled entirely.");
2289 free_cfg_system (host->cfg_system);
2290 host->cfg_system = NULL;
2294 } /* }}} int cna_config_system */
2296 /* Corresponds to a <Host /> block. */
2297 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
2298 const host_config_t *default_host)
2300 oconfig_item_t *item;
2301 host_config_t *host;
2305 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2306 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
2310 host = malloc(sizeof(*host));
2311 memcpy (host, default_host, sizeof (*host));
2313 status = cf_util_get_string (ci, &host->name);
2320 for (i = 0; i < ci->children_num; ++i) {
2321 item = ci->children + i;
2325 if (!strcasecmp(item->key, "Address")) {
2326 status = cf_util_get_string (item, &host->host);
2327 } else if (!strcasecmp(item->key, "Port")) {
2330 tmp = cf_util_get_port_number (item);
2333 } else if (!strcasecmp(item->key, "Protocol")) {
2334 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"))) {
2335 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2338 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2339 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2340 } else if (!strcasecmp(item->key, "User")) {
2341 status = cf_util_get_string (item, &host->username);
2342 } else if (!strcasecmp(item->key, "Password")) {
2343 status = cf_util_get_string (item, &host->password);
2344 } else if (!strcasecmp(item->key, "Interval")) {
2345 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) {
2346 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
2349 host->interval = item->values[0].value.number;
2350 } else if (!strcasecmp(item->key, "WAFL")) {
2351 cna_config_wafl(host, item);
2352 } else if (!strcasecmp(item->key, "Disks")) {
2353 cna_config_disk(host, item);
2354 } else if (!strcasecmp(item->key, "VolumePerf")) {
2355 cna_config_volume_performance(host, item);
2356 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2357 cna_config_volume_usage(host, item);
2358 } else if (!strcasecmp(item->key, "System")) {
2359 cna_config_system(host, item);
2361 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
2362 item->key, ci->values[0].value.string);
2369 if (host->host == NULL)
2370 host->host = strdup (host->name);
2372 if (host->host == NULL)
2375 if (host->port <= 0)
2376 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2378 if ((host->username == NULL) || (host->password == NULL)) {
2379 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2380 "Ignoring host block.", host->name);
2386 free_host_config (host);
2391 } /* }}} host_config_t *cna_config_host */
2394 * Callbacks registered with the daemon
2396 * Pretty standard stuff here.
2398 static int cna_init(void) { /* {{{ */
2400 host_config_t *host;
2402 if (!global_host_config) {
2403 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
2407 memset (err, 0, sizeof (err));
2408 if (!na_startup(err, sizeof(err))) {
2409 err[sizeof (err) - 1] = 0;
2410 ERROR("netapp plugin: Error initializing netapp API: %s", err);
2414 for (host = global_host_config; host; host = host->next) {
2415 /* Request version 1.1 of the ONTAP API */
2416 host->srv = na_server_open(host->host,
2417 /* major version = */ 1, /* minor version = */ 1);
2418 if (host->srv == NULL) {
2419 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
2423 if (host->interval < interval_g)
2424 host->interval = interval_g;
2426 na_server_set_transport_type(host->srv, host->protocol,
2427 /* transportarg = */ NULL);
2428 na_server_set_port(host->srv, host->port);
2429 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
2430 na_server_adminuser(host->srv, host->username, host->password);
2431 na_server_set_timeout(host->srv, 5 /* seconds */);
2434 } /* }}} int cna_init */
2436 static int cna_config (oconfig_item_t *ci) { /* {{{ */
2438 oconfig_item_t *item;
2439 host_config_t default_host = HOST_INIT;
2441 for (i = 0; i < ci->children_num; ++i) {
2442 item = ci->children + i;
2444 if (!strcasecmp(item->key, "Host")) {
2445 host_config_t *host;
2448 host = cna_config_host(item, &default_host);
2452 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
2454 if (strcasecmp (host->name, tmp->name) == 0)
2455 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
2456 "This is probably a bad idea.",
2459 if (tmp->next == NULL)
2465 global_host_config = host;
2469 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
2473 } /* }}} int cna_config */
2475 static int cna_read (void) { /* {{{ */
2476 host_config_t *host;
2478 for (host = global_host_config; host; host = host->next) {
2479 cna_query_wafl (host);
2480 cna_query_disk (host);
2481 cna_query_volume_perf (host);
2482 cna_query_volume_usage (host);
2483 cna_query_system (host);
2486 } /* }}} int cna_read */
2488 static int cna_shutdown (void) /* {{{ */
2490 free_host_config (global_host_config);
2491 global_host_config = NULL;
2494 } /* }}} int cna_shutdown */
2496 void module_register(void) {
2497 plugin_register_complex_config("netapp", cna_config);
2498 plugin_register_init("netapp", cna_init);
2499 plugin_register_read("netapp", cna_read);
2500 plugin_register_shutdown("netapp", cna_shutdown);
2503 /* vim: set sw=2 ts=2 noet fdm=marker : */