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 if (value > snap_used)
1445 na_elem_free (data);
1446 /* snap_used is the total size of the oldest snapshot plus all
1447 * newer ones in blocks (1KB). */
1448 v->snap_used = snap_used * 1024;
1449 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1452 static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
1453 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1455 na_elem_t *elem_volume;
1456 na_elem_t *elem_volumes;
1457 na_elem_iter_t iter_volume;
1459 elem_volumes = na_elem_child (data, "volumes");
1460 if (elem_volumes == NULL)
1462 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1463 "na_elem_child (\"volumes\") failed.");
1467 iter_volume = na_child_iterator (elem_volumes);
1468 for (elem_volume = na_iterator_next (&iter_volume);
1469 elem_volume != NULL;
1470 elem_volume = na_iterator_next (&iter_volume))
1472 const char *volume_name, *state;
1474 data_volume_usage_t *v;
1478 const char *sis_state;
1479 uint64_t sis_saved_reported;
1481 volume_name = na_child_get_string (elem_volume, "name");
1482 if (volume_name == NULL)
1485 state = na_child_get_string (elem_volume, "state");
1486 if ((state == NULL) || (strcmp(state, "online") != 0))
1489 /* get_volume_usage may return NULL if the volume is to be ignored. */
1490 v = get_volume_usage (cfg_volume, volume_name);
1494 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1495 cna_handle_volume_snap_usage(host, v);
1497 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1500 /* 2^4 exa-bytes? This will take a while ;) */
1501 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1502 if (value != UINT64_MAX) {
1503 v->norm_free = value;
1504 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1507 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1508 if (value != UINT64_MAX) {
1509 v->norm_used = value;
1510 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1513 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1514 if (value != UINT64_MAX) {
1515 /* 1 block == 1024 bytes as per API docs */
1516 v->snap_reserved = 1024 * value;
1517 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1520 sis = na_elem_child(elem_volume, "sis");
1524 sis_state = na_child_get_string(sis, "state");
1525 if (sis_state == NULL)
1528 /* If SIS is not enabled, there's nothing left to do for this volume. */
1529 if (strcmp ("enabled", sis_state) != 0)
1532 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1533 if (sis_saved_reported == UINT64_MAX)
1536 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1537 if ((sis_saved_reported >> 32) != 0) {
1538 /* In case they ever fix this bug. */
1539 v->sis_saved = sis_saved_reported;
1540 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1541 } else { /* really hacky work-around code. {{{ */
1542 uint64_t sis_saved_percent;
1543 uint64_t sis_saved_guess;
1544 uint64_t overflow_guess;
1545 uint64_t guess1, guess2, guess3;
1547 /* Check if we have v->norm_used. Without it, we cannot calculate
1548 * sis_saved_guess. */
1549 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1552 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1553 if (sis_saved_percent > 100)
1556 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1557 * will hopefully be fixed in later versions. To work around the bug, try
1558 * to figure out how often the 32bit integer wrapped around by using the
1559 * "percentage-saved" value. Because the percentage is in the range
1560 * [0-100], this should work as long as the saved space does not exceed
1562 /* percentage-saved = size-saved / (size-saved + size-used) */
1563 if (sis_saved_percent < 100)
1564 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1566 sis_saved_guess = v->norm_used;
1568 overflow_guess = sis_saved_guess >> 32;
1569 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1570 guess2 = (overflow_guess << 32) + sis_saved_reported;
1571 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1573 if (sis_saved_guess < guess2) {
1574 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1575 v->sis_saved = guess1;
1577 v->sis_saved = guess2;
1579 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1580 v->sis_saved = guess2;
1582 v->sis_saved = guess3;
1584 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1585 } /* }}} end of 32-bit workaround */
1586 } /* for (elem_volume) */
1588 return (cna_submit_volume_usage_data (host->name, cfg_volume));
1589 } /* }}} int cna_handle_volume_usage_data */
1591 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1596 if (cvu->query != NULL)
1599 cvu->query = na_elem_new ("volume-list-info");
1600 if (cvu->query == NULL)
1602 ERROR ("netapp plugin: na_elem_new failed.");
1607 } /* }}} int cna_setup_volume_usage */
1609 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1618 /* If the user did not configure volume_usage statistics, return without
1619 * doing anything. */
1620 if (host->cfg_volume_usage == NULL)
1624 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1627 status = cna_setup_volume_usage (host->cfg_volume_usage);
1630 assert (host->cfg_volume_usage->query != NULL);
1632 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1633 if (na_results_status (data) != NA_OK)
1635 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed: %s",
1636 na_results_reason (data));
1637 na_elem_free (data);
1641 status = cna_handle_volume_usage_data (host, host->cfg_volume_usage, data);
1644 host->cfg_volume_usage->interval.last_read = now;
1646 na_elem_free (data);
1648 } /* }}} int cna_query_volume_usage */
1650 /* Data corresponding to <System /> */
1651 static int cna_handle_system_data (const char *hostname, /* {{{ */
1652 cfg_system_t *cfg_system, na_elem_t *data)
1654 na_elem_t *instances;
1656 na_elem_iter_t counter_iter;
1658 counter_t disk_read = 0, disk_written = 0;
1659 counter_t net_recv = 0, net_sent = 0;
1660 counter_t cpu_busy = 0, cpu_total = 0;
1661 uint32_t counter_flags = 0;
1663 const char *instance;
1666 timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
1668 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1669 if (instances == NULL)
1671 ERROR ("netapp plugin: cna_handle_system_data: "
1672 "na_elem_child (\"instances\") failed.");
1676 instance = na_child_get_string (instances, "name");
1677 if (instance == NULL)
1679 ERROR ("netapp plugin: cna_handle_system_data: "
1680 "na_child_get_string (\"name\") failed.");
1684 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
1685 for (counter = na_iterator_next (&counter_iter);
1687 counter = na_iterator_next (&counter_iter))
1692 name = na_child_get_string(counter, "name");
1696 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1697 if (value == UINT64_MAX)
1700 if (!strcmp(name, "disk_data_read")) {
1701 disk_read = (counter_t) (value * 1024);
1702 counter_flags |= 0x01;
1703 } else if (!strcmp(name, "disk_data_written")) {
1704 disk_written = (counter_t) (value * 1024);
1705 counter_flags |= 0x02;
1706 } else if (!strcmp(name, "net_data_recv")) {
1707 net_recv = (counter_t) (value * 1024);
1708 counter_flags |= 0x04;
1709 } else if (!strcmp(name, "net_data_sent")) {
1710 net_sent = (counter_t) (value * 1024);
1711 counter_flags |= 0x08;
1712 } else if (!strcmp(name, "cpu_busy")) {
1713 cpu_busy = (counter_t) value;
1714 counter_flags |= 0x10;
1715 } else if (!strcmp(name, "cpu_elapsed_time")) {
1716 cpu_total = (counter_t) value;
1717 counter_flags |= 0x20;
1718 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1719 && (value > 0) && (strlen(name) > 4)
1720 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1721 submit_counter (hostname, instance, "disk_ops_complex", name,
1722 (counter_t) value, timestamp);
1724 } /* for (counter) */
1726 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1727 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
1728 submit_two_counters (hostname, instance, "disk_octets", NULL,
1729 disk_read, disk_written, timestamp);
1731 if ((cfg_system->flags & CFG_SYSTEM_NET)
1732 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
1733 submit_two_counters (hostname, instance, "if_octets", NULL,
1734 net_recv, net_sent, timestamp);
1736 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1737 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
1739 submit_counter (hostname, instance, "cpu", "system",
1740 cpu_busy, timestamp);
1741 submit_counter (hostname, instance, "cpu", "idle",
1742 cpu_total - cpu_busy, timestamp);
1746 } /* }}} int cna_handle_system_data */
1748 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
1753 if (cs->query != NULL)
1756 cs->query = na_elem_new ("perf-object-get-instances");
1757 if (cs->query == NULL)
1759 ERROR ("netapp plugin: na_elem_new failed.");
1762 na_child_add_string (cs->query, "objectname", "system");
1765 } /* }}} int cna_setup_system */
1767 static int cna_query_system (host_config_t *host) /* {{{ */
1776 /* If system statistics were not configured, return without doing anything. */
1777 if (host->cfg_system == NULL)
1781 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
1784 status = cna_setup_system (host->cfg_system);
1787 assert (host->cfg_system->query != NULL);
1789 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
1790 if (na_results_status (data) != NA_OK)
1792 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed: %s",
1793 na_results_reason (data));
1794 na_elem_free (data);
1798 status = cna_handle_system_data (host->name, host->cfg_system, data);
1801 host->cfg_system->interval.last_read = now;
1803 na_elem_free (data);
1805 } /* }}} int cna_query_system */
1808 * Configuration handling
1810 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1811 * is false. On error, the flag-field is not changed. */
1812 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1813 uint32_t *flags, uint32_t flag)
1815 if ((ci == NULL) || (flags == NULL))
1818 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1820 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1825 if (ci->values[0].value.boolean)
1831 } /* }}} int cna_config_bool_to_flag */
1833 /* Handling of the "Interval" option which is allowed in every block. */
1834 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1835 cna_interval_t *out_interval)
1839 if ((ci == NULL) || (out_interval == NULL))
1842 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1844 WARNING ("netapp plugin: The `Interval' option needs exactly one numeric argument.");
1848 tmp = (time_t) (ci->values[0].value.number + .5);
1851 WARNING ("netapp plugin: The `Interval' option needs a positive integer argument.");
1855 out_interval->interval = tmp;
1856 out_interval->last_read = 0;
1859 } /* }}} int cna_config_get_interval */
1861 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1862 * <VolumePerf /> block. */
1863 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
1864 const oconfig_item_t *ci)
1869 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1871 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1876 name = ci->values[0].value.string;
1878 if (strcasecmp ("GetIO", ci->key) == 0)
1879 il = cvp->il_octets;
1880 else if (strcasecmp ("GetOps", ci->key) == 0)
1881 il = cvp->il_operations;
1882 else if (strcasecmp ("GetLatency", ci->key) == 0)
1883 il = cvp->il_latency;
1887 ignorelist_add (il, name);
1888 } /* }}} void cna_config_volume_perf_option */
1890 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
1891 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
1892 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
1893 const oconfig_item_t *ci)
1897 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1899 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1904 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
1905 il = cvp->il_octets;
1906 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
1907 il = cvp->il_operations;
1908 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
1909 il = cvp->il_latency;
1913 if (ci->values[0].value.boolean)
1914 ignorelist_set_invert (il, /* invert = */ 0);
1916 ignorelist_set_invert (il, /* invert = */ 1);
1917 } /* }}} void cna_config_volume_perf_default */
1919 /* Corresponds to a <Disks /> block */
1924 * IgnoreSelectedIO false
1928 * IgnoreSelectedOps false
1932 * IgnoreSelectedLatency false
1935 /* Corresponds to a <VolumePerf /> block */
1936 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
1937 const oconfig_item_t *ci)
1939 cfg_volume_perf_t *cfg_volume_perf;
1942 if ((host == NULL) || (ci == NULL))
1945 if (host->cfg_volume_perf == NULL)
1947 cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
1948 if (cfg_volume_perf == NULL)
1950 memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
1952 /* Set default flags */
1953 cfg_volume_perf->query = NULL;
1954 cfg_volume_perf->volumes = NULL;
1956 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
1957 if (cfg_volume_perf->il_octets == NULL)
1959 sfree (cfg_volume_perf);
1963 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
1964 if (cfg_volume_perf->il_operations == NULL)
1966 ignorelist_free (cfg_volume_perf->il_octets);
1967 sfree (cfg_volume_perf);
1971 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
1972 if (cfg_volume_perf->il_latency == NULL)
1974 ignorelist_free (cfg_volume_perf->il_octets);
1975 ignorelist_free (cfg_volume_perf->il_operations);
1976 sfree (cfg_volume_perf);
1980 host->cfg_volume_perf = cfg_volume_perf;
1982 cfg_volume_perf = host->cfg_volume_perf;
1984 for (i = 0; i < ci->children_num; ++i) {
1985 oconfig_item_t *item = ci->children + i;
1987 /* if (!item || !item->key || !*item->key) continue; */
1988 if (strcasecmp(item->key, "Interval") == 0)
1989 cna_config_get_interval (item, &cfg_volume_perf->interval);
1990 else if (!strcasecmp(item->key, "GetIO"))
1991 cna_config_volume_perf_option (cfg_volume_perf, item);
1992 else if (!strcasecmp(item->key, "GetOps"))
1993 cna_config_volume_perf_option (cfg_volume_perf, item);
1994 else if (!strcasecmp(item->key, "GetLatency"))
1995 cna_config_volume_perf_option (cfg_volume_perf, item);
1996 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
1997 cna_config_volume_perf_default (cfg_volume_perf, item);
1998 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
1999 cna_config_volume_perf_default (cfg_volume_perf, item);
2000 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2001 cna_config_volume_perf_default (cfg_volume_perf, item);
2003 WARNING ("netapp plugin: The option %s is not allowed within "
2004 "`VolumePerf' blocks.", item->key);
2008 } /* }}} int cna_config_volume_performance */
2010 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2011 * <VolumeUsage /> block. */
2012 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
2013 const oconfig_item_t *ci)
2018 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2020 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2025 name = ci->values[0].value.string;
2027 if (strcasecmp ("GetCapacity", ci->key) == 0)
2028 il = cvu->il_capacity;
2029 else if (strcasecmp ("GetSnapshot", ci->key) == 0)
2030 il = cvu->il_snapshot;
2034 ignorelist_add (il, name);
2035 } /* }}} void cna_config_volume_usage_option */
2037 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2038 * options within a <VolumeUsage /> block. */
2039 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
2040 const oconfig_item_t *ci)
2044 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2046 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2051 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2052 il = cvu->il_capacity;
2053 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2054 il = cvu->il_snapshot;
2058 if (ci->values[0].value.boolean)
2059 ignorelist_set_invert (il, /* invert = */ 0);
2061 ignorelist_set_invert (il, /* invert = */ 1);
2062 } /* }}} void cna_config_volume_usage_default */
2064 /* Corresponds to a <Disks /> block */
2065 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2066 cfg_disk_t *cfg_disk;
2069 if ((host == NULL) || (ci == NULL))
2072 if (host->cfg_disk == NULL)
2074 cfg_disk = malloc (sizeof (*cfg_disk));
2075 if (cfg_disk == NULL)
2077 memset (cfg_disk, 0, sizeof (*cfg_disk));
2079 /* Set default flags */
2080 cfg_disk->flags = CFG_DISK_ALL;
2081 cfg_disk->query = NULL;
2082 cfg_disk->disks = NULL;
2084 host->cfg_disk = cfg_disk;
2086 cfg_disk = host->cfg_disk;
2088 for (i = 0; i < ci->children_num; ++i) {
2089 oconfig_item_t *item = ci->children + i;
2091 /* if (!item || !item->key || !*item->key) continue; */
2092 if (strcasecmp(item->key, "Interval") == 0)
2093 cna_config_get_interval (item, &cfg_disk->interval);
2094 else if (strcasecmp(item->key, "GetBusy") == 0)
2095 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2098 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2100 NOTICE ("netapp plugin: All disk related values have been disabled. "
2101 "Collection of per-disk data will be disabled entirely.");
2102 free_cfg_disk (host->cfg_disk);
2103 host->cfg_disk = NULL;
2107 } /* }}} int cna_config_disk */
2109 /* Corresponds to a <WAFL /> block */
2110 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2112 cfg_wafl_t *cfg_wafl;
2115 if ((host == NULL) || (ci == NULL))
2118 if (host->cfg_wafl == NULL)
2120 cfg_wafl = malloc (sizeof (*cfg_wafl));
2121 if (cfg_wafl == NULL)
2123 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
2125 /* Set default flags */
2126 cfg_wafl->flags = CFG_WAFL_ALL;
2128 host->cfg_wafl = cfg_wafl;
2130 cfg_wafl = host->cfg_wafl;
2132 for (i = 0; i < ci->children_num; ++i) {
2133 oconfig_item_t *item = ci->children + i;
2135 if (strcasecmp(item->key, "Interval") == 0)
2136 cna_config_get_interval (item, &cfg_wafl->interval);
2137 else if (!strcasecmp(item->key, "GetNameCache"))
2138 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2139 else if (!strcasecmp(item->key, "GetDirCache"))
2140 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2141 else if (!strcasecmp(item->key, "GetBufferCache"))
2142 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2143 else if (!strcasecmp(item->key, "GetInodeCache"))
2144 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2146 WARNING ("netapp plugin: The %s config option is not allowed within "
2147 "`WAFL' blocks.", item->key);
2150 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2152 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2153 "Collection of WAFL data will be disabled entirely.");
2154 free_cfg_wafl (host->cfg_wafl);
2155 host->cfg_wafl = NULL;
2159 } /* }}} int cna_config_wafl */
2163 * GetCapacity "vol0"
2164 * GetCapacity "vol1"
2165 * GetCapacity "vol2"
2166 * GetCapacity "vol3"
2167 * GetCapacity "vol4"
2168 * IgnoreSelectedCapacity false
2170 * GetSnapshot "vol0"
2171 * GetSnapshot "vol3"
2172 * GetSnapshot "vol4"
2173 * GetSnapshot "vol7"
2174 * IgnoreSelectedSnapshot false
2177 /* Corresponds to a <VolumeUsage /> block */
2178 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2179 const oconfig_item_t *ci)
2181 cfg_volume_usage_t *cfg_volume_usage;
2184 if ((host == NULL) || (ci == NULL))
2187 if (host->cfg_volume_usage == NULL)
2189 cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
2190 if (cfg_volume_usage == NULL)
2192 memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
2194 /* Set default flags */
2195 cfg_volume_usage->query = NULL;
2196 cfg_volume_usage->volumes = NULL;
2198 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2199 if (cfg_volume_usage->il_capacity == NULL)
2201 sfree (cfg_volume_usage);
2205 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2206 if (cfg_volume_usage->il_snapshot == NULL)
2208 ignorelist_free (cfg_volume_usage->il_capacity);
2209 sfree (cfg_volume_usage);
2213 host->cfg_volume_usage = cfg_volume_usage;
2215 cfg_volume_usage = host->cfg_volume_usage;
2217 for (i = 0; i < ci->children_num; ++i) {
2218 oconfig_item_t *item = ci->children + i;
2220 /* if (!item || !item->key || !*item->key) continue; */
2221 if (strcasecmp(item->key, "Interval") == 0)
2222 cna_config_get_interval (item, &cfg_volume_usage->interval);
2223 else if (!strcasecmp(item->key, "GetCapacity"))
2224 cna_config_volume_usage_option (cfg_volume_usage, item);
2225 else if (!strcasecmp(item->key, "GetSnapshot"))
2226 cna_config_volume_usage_option (cfg_volume_usage, item);
2227 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2228 cna_config_volume_usage_default (cfg_volume_usage, item);
2229 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2230 cna_config_volume_usage_default (cfg_volume_usage, item);
2232 WARNING ("netapp plugin: The option %s is not allowed within "
2233 "`VolumeUsage' blocks.", item->key);
2237 } /* }}} int cna_config_volume_usage */
2239 /* Corresponds to a <System /> block */
2240 static int cna_config_system (host_config_t *host, /* {{{ */
2243 cfg_system_t *cfg_system;
2246 if ((host == NULL) || (ci == NULL))
2249 if (host->cfg_system == NULL)
2251 cfg_system = malloc (sizeof (*cfg_system));
2252 if (cfg_system == NULL)
2254 memset (cfg_system, 0, sizeof (*cfg_system));
2256 /* Set default flags */
2257 cfg_system->flags = CFG_SYSTEM_ALL;
2258 cfg_system->query = NULL;
2260 host->cfg_system = cfg_system;
2262 cfg_system = host->cfg_system;
2264 for (i = 0; i < ci->children_num; ++i) {
2265 oconfig_item_t *item = ci->children + i;
2267 if (strcasecmp(item->key, "Interval") == 0) {
2268 cna_config_get_interval (item, &cfg_system->interval);
2269 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2270 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2271 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2272 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2273 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2274 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2275 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2276 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2278 WARNING ("netapp plugin: The %s config option is not allowed within "
2279 "`System' blocks.", item->key);
2283 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2285 NOTICE ("netapp plugin: All system related values have been disabled. "
2286 "Collection of system data will be disabled entirely.");
2287 free_cfg_system (host->cfg_system);
2288 host->cfg_system = NULL;
2292 } /* }}} int cna_config_system */
2294 /* Corresponds to a <Host /> block. */
2295 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
2296 const host_config_t *default_host)
2298 oconfig_item_t *item;
2299 host_config_t *host;
2303 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2304 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
2308 host = malloc(sizeof(*host));
2309 memcpy (host, default_host, sizeof (*host));
2311 status = cf_util_get_string (ci, &host->name);
2318 for (i = 0; i < ci->children_num; ++i) {
2319 item = ci->children + i;
2323 if (!strcasecmp(item->key, "Address")) {
2324 status = cf_util_get_string (item, &host->host);
2325 } else if (!strcasecmp(item->key, "Port")) {
2328 tmp = cf_util_get_port_number (item);
2331 } else if (!strcasecmp(item->key, "Protocol")) {
2332 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"))) {
2333 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2336 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2337 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2338 } else if (!strcasecmp(item->key, "User")) {
2339 status = cf_util_get_string (item, &host->username);
2340 } else if (!strcasecmp(item->key, "Password")) {
2341 status = cf_util_get_string (item, &host->password);
2342 } else if (!strcasecmp(item->key, "Interval")) {
2343 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) {
2344 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
2347 host->interval = item->values[0].value.number;
2348 } else if (!strcasecmp(item->key, "WAFL")) {
2349 cna_config_wafl(host, item);
2350 } else if (!strcasecmp(item->key, "Disks")) {
2351 cna_config_disk(host, item);
2352 } else if (!strcasecmp(item->key, "VolumePerf")) {
2353 cna_config_volume_performance(host, item);
2354 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2355 cna_config_volume_usage(host, item);
2356 } else if (!strcasecmp(item->key, "System")) {
2357 cna_config_system(host, item);
2359 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
2360 item->key, ci->values[0].value.string);
2367 if (host->host == NULL)
2368 host->host = strdup (host->name);
2370 if (host->host == NULL)
2373 if (host->port <= 0)
2374 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2376 if ((host->username == NULL) || (host->password == NULL)) {
2377 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2378 "Ignoring host block.", host->name);
2384 free_host_config (host);
2389 } /* }}} host_config_t *cna_config_host */
2392 * Callbacks registered with the daemon
2394 * Pretty standard stuff here.
2396 static int cna_init(void) { /* {{{ */
2398 host_config_t *host;
2400 if (!global_host_config) {
2401 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
2405 memset (err, 0, sizeof (err));
2406 if (!na_startup(err, sizeof(err))) {
2407 err[sizeof (err) - 1] = 0;
2408 ERROR("netapp plugin: Error initializing netapp API: %s", err);
2412 for (host = global_host_config; host; host = host->next) {
2413 /* Request version 1.1 of the ONTAP API */
2414 host->srv = na_server_open(host->host,
2415 /* major version = */ 1, /* minor version = */ 1);
2416 if (host->srv == NULL) {
2417 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
2421 if (host->interval < interval_g)
2422 host->interval = interval_g;
2424 na_server_set_transport_type(host->srv, host->protocol,
2425 /* transportarg = */ NULL);
2426 na_server_set_port(host->srv, host->port);
2427 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
2428 na_server_adminuser(host->srv, host->username, host->password);
2429 na_server_set_timeout(host->srv, 5 /* seconds */);
2432 } /* }}} int cna_init */
2434 static int cna_config (oconfig_item_t *ci) { /* {{{ */
2436 oconfig_item_t *item;
2437 host_config_t default_host = HOST_INIT;
2439 for (i = 0; i < ci->children_num; ++i) {
2440 item = ci->children + i;
2442 if (!strcasecmp(item->key, "Host")) {
2443 host_config_t *host;
2446 host = cna_config_host(item, &default_host);
2450 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
2452 if (strcasecmp (host->name, tmp->name) == 0)
2453 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
2454 "This is probably a bad idea.",
2457 if (tmp->next == NULL)
2463 global_host_config = host;
2467 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
2471 } /* }}} int cna_config */
2473 static int cna_read (void) { /* {{{ */
2474 host_config_t *host;
2476 for (host = global_host_config; host; host = host->next) {
2477 cna_query_wafl (host);
2478 cna_query_disk (host);
2479 cna_query_volume_perf (host);
2480 cna_query_volume_usage (host);
2481 cna_query_system (host);
2484 } /* }}} int cna_read */
2486 static int cna_shutdown (void) /* {{{ */
2488 free_host_config (global_host_config);
2489 global_host_config = NULL;
2492 } /* }}} int cna_shutdown */
2494 void module_register(void) {
2495 plugin_register_complex_config("netapp", cna_config);
2496 plugin_register_init("netapp", cna_init);
2497 plugin_register_read("netapp", cna_read);
2498 plugin_register_shutdown("netapp", cna_shutdown);
2501 /* vim: set sw=2 ts=2 noet fdm=marker : */