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>
33 #define HAS_ALL_FLAGS(has,needs) (((has) & (needs)) == (needs))
35 typedef struct host_config_s host_config_t;
36 typedef void service_handler_t(host_config_t *host, na_elem_t *result, void *data);
43 typedef struct cna_interval_s cna_interval_t;
45 /*! Data types for WAFL statistics {{{
47 * \brief Persistent data for WAFL performance counters. (a.k.a. cache performance)
49 * The cache counters use old counter values to calculate a hit ratio for each
50 * counter. The "cfg_wafl_t" struct therefore contains old counter values along
51 * with flags, which are set if the counter is valid.
53 * The function "cna_handle_wafl_data" will fill a new structure of this kind
54 * with new values, then pass both, new and old data, to "submit_wafl_data".
55 * That function calculates the hit ratios, submits the calculated values and
56 * updates the old counter values for the next iteration.
58 #define CFG_WAFL_NAME_CACHE 0x0001
59 #define CFG_WAFL_DIR_CACHE 0x0002
60 #define CFG_WAFL_BUF_CACHE 0x0004
61 #define CFG_WAFL_INODE_CACHE 0x0008
62 #define CFG_WAFL_ALL 0x000F
63 #define HAVE_WAFL_NAME_CACHE_HIT 0x0100
64 #define HAVE_WAFL_NAME_CACHE_MISS 0x0200
65 #define HAVE_WAFL_NAME_CACHE (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
66 #define HAVE_WAFL_FIND_DIR_HIT 0x0400
67 #define HAVE_WAFL_FIND_DIR_MISS 0x0800
68 #define HAVE_WAFL_FIND_DIR (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
69 #define HAVE_WAFL_BUF_HASH_HIT 0x1000
70 #define HAVE_WAFL_BUF_HASH_MISS 0x2000
71 #define HAVE_WAFL_BUF_HASH (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
72 #define HAVE_WAFL_INODE_CACHE_HIT 0x4000
73 #define HAVE_WAFL_INODE_CACHE_MISS 0x8000
74 #define HAVE_WAFL_INODE_CACHE (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
75 #define HAVE_WAFL_ALL 0xff00
78 cna_interval_t interval;
82 uint64_t name_cache_hit;
83 uint64_t name_cache_miss;
84 uint64_t find_dir_hit;
85 uint64_t find_dir_miss;
86 uint64_t buf_hash_hit;
87 uint64_t buf_hash_miss;
88 uint64_t inode_cache_hit;
89 uint64_t inode_cache_miss;
93 /*! Data types for disk statistics {{{
95 * \brief A disk in the NetApp.
97 * A disk doesn't have any more information than its name at the moment.
98 * The name includes the "disk_" prefix.
100 #define HAVE_DISK_BUSY 0x10
101 #define HAVE_DISK_BASE 0x20
102 #define HAVE_DISK_ALL 0x30
103 typedef struct disk_s {
108 uint64_t base_for_disk_busy;
109 double disk_busy_percent;
113 #define CFG_DISK_BUSIEST 0x01
114 #define CFG_DISK_ALL 0x01
117 cna_interval_t interval;
123 /*! Data types for volume performance statistics {{{
125 * \brief Persistent data for volume performance data.
127 * The code below uses the difference of the operations and latency counters to
128 * calculate an average per-operation latency. For this, old counters need to
129 * be stored in the "data_volume_perf_t" structure. The byte-counters are just
130 * kept for completeness sake. The "flags" member indicates if each counter is
133 * The "cna_handle_volume_perf_data" function will fill a new struct of this
134 * type and pass both, old and new data, to "submit_volume_perf_data". In that
135 * function, the per-operation latency is calculated and dispatched, then the
136 * old counters are updated.
138 #define CFG_VOLUME_PERF_INIT 0x0001
139 #define CFG_VOLUME_PERF_IO 0x0002
140 #define CFG_VOLUME_PERF_OPS 0x0003
141 #define CFG_VOLUME_PERF_LATENCY 0x0008
142 #define CFG_VOLUME_PERF_ALL 0x000F
143 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
144 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
145 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
146 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
147 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
148 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
149 #define HAVE_VOLUME_PERF_ALL 0x03F0
150 struct data_volume_perf_s;
151 typedef struct data_volume_perf_s data_volume_perf_t;
152 struct data_volume_perf_s {
158 uint64_t write_bytes;
161 uint64_t read_latency;
162 uint64_t write_latency;
164 data_volume_perf_t *next;
168 cna_interval_t interval;
171 ignorelist_t *il_octets;
172 ignorelist_t *il_operations;
173 ignorelist_t *il_latency;
175 data_volume_perf_t *volumes;
177 /* }}} data_volume_perf_t */
179 /*! Data types for volume usage statistics {{{
181 * \brief Configuration struct for volume usage data (free / used).
183 #define CFG_VOLUME_USAGE_DF 0x0002
184 #define CFG_VOLUME_USAGE_SNAP 0x0004
185 #define CFG_VOLUME_USAGE_ALL 0x0006
186 #define HAVE_VOLUME_USAGE_NORM_FREE 0x0010
187 #define HAVE_VOLUME_USAGE_NORM_USED 0x0020
188 #define HAVE_VOLUME_USAGE_SNAP_RSVD 0x0040
189 #define HAVE_VOLUME_USAGE_SNAP_USED 0x0080
190 #define HAVE_VOLUME_USAGE_SIS_SAVED 0x0100
191 #define HAVE_VOLUME_USAGE_ALL 0x01f0
192 struct data_volume_usage_s;
193 typedef struct data_volume_usage_s data_volume_usage_t;
194 struct data_volume_usage_s {
200 uint64_t snap_reserved;
204 data_volume_usage_t *next;
208 cna_interval_t interval;
211 ignorelist_t *il_capacity;
212 ignorelist_t *il_snapshot;
214 data_volume_usage_t *volumes;
215 } cfg_volume_usage_t;
216 /* }}} cfg_volume_usage_t */
218 /*! Data types for system statistics {{{
220 * \brief Persistent data for system performance counters
222 #define CFG_SYSTEM_CPU 0x01
223 #define CFG_SYSTEM_NET 0x02
224 #define CFG_SYSTEM_OPS 0x04
225 #define CFG_SYSTEM_DISK 0x08
226 #define CFG_SYSTEM_ALL 0x0F
229 cna_interval_t interval;
232 /* }}} cfg_system_t */
234 typedef struct service_config_s {
236 service_handler_t *handler;
241 struct service_config_s *next;
243 #define SERVICE_INIT {0, 0, 1, 1, 0, 0, 0}
246 * \brief Struct representing a volume.
248 * A volume currently has a name and two sets of values:
250 * - Performance data, such as bytes read/written, number of operations
251 * performed and average time per operation.
253 * - Usage data, i. e. amount of used and free space in the volume.
255 typedef struct volume_s {
257 data_volume_perf_t perf_data;
258 struct volume_s *next;
261 struct host_config_s {
263 na_server_transport_t protocol;
271 cfg_service_t *services;
272 cfg_wafl_t *cfg_wafl;
273 cfg_disk_t *cfg_disk;
274 cfg_volume_perf_t *cfg_volume_perf;
275 cfg_volume_usage_t *cfg_volume_usage;
276 cfg_system_t *cfg_system;
279 struct host_config_s *next;
281 #define HOST_INIT { NULL, NA_SERVER_TRANSPORT_HTTPS, NULL, 0, NULL, NULL, 0, \
282 NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
285 static host_config_t *global_host_config;
290 * Used to free the various structures above.
292 static void free_volume (volume_t *volume) /* {{{ */
301 sfree (volume->name);
305 } /* }}} void free_volume */
307 static void free_disk (disk_t *disk) /* {{{ */
320 } /* }}} void free_disk */
322 static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
327 if (cw->query != NULL)
328 na_elem_free (cw->query);
331 } /* }}} void free_cfg_wafl */
333 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
335 if (cfg_disk == NULL)
338 if (cfg_disk->query != NULL)
339 na_elem_free (cfg_disk->query);
341 free_disk (cfg_disk->disks);
343 } /* }}} void free_cfg_disk */
345 static void free_cfg_volume_perf (cfg_volume_perf_t *cvp) /* {{{ */
347 data_volume_perf_t *data;
352 /* Free the ignorelists */
353 ignorelist_free (cvp->il_octets);
354 ignorelist_free (cvp->il_operations);
355 ignorelist_free (cvp->il_latency);
357 /* Free the linked list of volumes */
361 data_volume_perf_t *next = data->next;
367 if (cvp->query != NULL)
368 na_elem_free (cvp->query);
371 } /* }}} void free_cfg_volume_perf */
373 static void free_cfg_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
375 data_volume_usage_t *data;
380 /* Free the ignorelists */
381 ignorelist_free (cvu->il_capacity);
382 ignorelist_free (cvu->il_snapshot);
384 /* Free the linked list of volumes */
388 data_volume_usage_t *next = data->next;
394 if (cvu->query != NULL)
395 na_elem_free (cvu->query);
398 } /* }}} void free_cfg_volume_usage */
400 static void free_cfg_system (cfg_system_t *cs) /* {{{ */
405 if (cs->query != NULL)
406 na_elem_free (cs->query);
409 } /* }}} void free_cfg_system */
411 static void free_cfg_service (cfg_service_t *service) /* {{{ */
418 next = service->next;
420 /* FIXME: Free service->data? */
421 na_elem_free(service->query);
425 free_cfg_service (next);
426 } /* }}} void free_cfg_service */
428 static void free_host_config (host_config_t *hc) /* {{{ */
439 sfree (hc->username);
440 sfree (hc->password);
442 free_cfg_service (hc->services);
443 free_cfg_disk (hc->cfg_disk);
444 free_cfg_wafl (hc->cfg_wafl);
445 free_cfg_volume_perf (hc->cfg_volume_perf);
446 free_cfg_volume_usage (hc->cfg_volume_usage);
447 free_cfg_system (hc->cfg_system);
448 free_volume (hc->volumes);
452 free_host_config (next);
453 } /* }}} void free_host_config */
456 * Auxiliary functions
458 * Used to look up volumes and disks or to handle flags.
460 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
464 if ((cd == NULL) || (name == NULL))
467 for (d = cd->disks; d != NULL; d = d->next) {
468 if (strcmp(d->name, name) == 0)
472 d = malloc(sizeof(*d));
475 memset (d, 0, sizeof (*d));
478 d->name = strdup(name);
479 if (d->name == NULL) {
488 } /* }}} disk_t *get_disk */
490 static data_volume_usage_t *get_volume_usage (cfg_volume_usage_t *cvu, /* {{{ */
493 data_volume_usage_t *last;
494 data_volume_usage_t *new;
496 int ignore_capacity = 0;
497 int ignore_snapshot = 0;
499 if ((cvu == NULL) || (name == NULL))
505 if (strcmp (last->name, name) == 0)
508 if (last->next == NULL)
514 /* Check the ignorelists. If *both* tell us to ignore a volume, return NULL. */
515 ignore_capacity = ignorelist_match (cvu->il_capacity, name);
516 ignore_snapshot = ignorelist_match (cvu->il_snapshot, name);
517 if ((ignore_capacity != 0) && (ignore_snapshot != 0))
520 /* Not found: allocate. */
521 new = malloc (sizeof (*new));
524 memset (new, 0, sizeof (*new));
527 new->name = strdup (name);
528 if (new->name == NULL)
534 if (ignore_capacity == 0)
535 new->flags |= CFG_VOLUME_USAGE_DF;
536 if (ignore_snapshot == 0)
537 new->flags |= CFG_VOLUME_USAGE_SNAP;
539 /* Add to end of list. */
546 } /* }}} data_volume_usage_t *get_volume_usage */
548 static data_volume_perf_t *get_volume_perf (cfg_volume_perf_t *cvp, /* {{{ */
551 data_volume_perf_t *last;
552 data_volume_perf_t *new;
554 int ignore_octets = 0;
555 int ignore_operations = 0;
556 int ignore_latency = 0;
558 if ((cvp == NULL) || (name == NULL))
564 if (strcmp (last->name, name) == 0)
567 if (last->next == NULL)
573 /* Check the ignorelists. If *all three* tell us to ignore a volume, return
575 ignore_octets = ignorelist_match (cvp->il_octets, name);
576 ignore_operations = ignorelist_match (cvp->il_operations, name);
577 ignore_latency = ignorelist_match (cvp->il_latency, name);
578 if ((ignore_octets != 0) || (ignore_operations != 0)
579 || (ignore_latency != 0))
582 /* Not found: allocate. */
583 new = malloc (sizeof (*new));
586 memset (new, 0, sizeof (*new));
589 new->name = strdup (name);
590 if (new->name == NULL)
596 if (ignore_octets == 0)
597 new->flags |= CFG_VOLUME_PERF_IO;
598 if (ignore_operations == 0)
599 new->flags |= CFG_VOLUME_PERF_OPS;
600 if (ignore_latency == 0)
601 new->flags |= CFG_VOLUME_PERF_LATENCY;
603 /* Add to end of list. */
610 } /* }}} data_volume_perf_t *get_volume_perf */
613 * Various submit functions.
615 * They all eventually call "submit_values" which creates a value_list_t and
616 * dispatches it to the daemon.
618 static int submit_values (const char *host, /* {{{ */
619 const char *plugin_inst,
620 const char *type, const char *type_inst,
621 value_t *values, int values_len,
624 value_list_t vl = VALUE_LIST_INIT;
627 vl.values_len = values_len;
633 sstrncpy (vl.host, host, sizeof (vl.host));
635 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
636 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
637 if (plugin_inst != NULL)
638 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
639 sstrncpy (vl.type, type, sizeof (vl.type));
640 if (type_inst != NULL)
641 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
643 return (plugin_dispatch_values (&vl));
644 } /* }}} int submit_uint64 */
646 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
647 const char *type, const char *type_inst, counter_t val0, counter_t val1,
652 values[0].counter = val0;
653 values[1].counter = val1;
655 return (submit_values (host, plugin_inst, type, type_inst,
656 values, 2, timestamp));
657 } /* }}} int submit_two_counters */
659 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
660 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
666 return (submit_values (host, plugin_inst, type, type_inst,
668 } /* }}} int submit_counter */
670 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
671 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
676 values[0].gauge = val0;
677 values[1].gauge = val1;
679 return (submit_values (host, plugin_inst, type, type_inst,
680 values, 2, timestamp));
681 } /* }}} int submit_two_gauge */
683 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
684 const char *type, const char *type_inst, double d, time_t timestamp)
688 v.gauge = (gauge_t) d;
690 return (submit_values (host, plugin_inst, type, type_inst,
692 } /* }}} int submit_uint64 */
694 /* Calculate hit ratio from old and new counters and submit the resulting
695 * percentage. Used by "submit_wafl_data". */
696 static int submit_cache_ratio (const char *host, /* {{{ */
697 const char *plugin_inst,
698 const char *type_inst,
707 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
711 hits = new_hits - old_hits;
712 misses = new_misses - old_misses;
714 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
719 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
721 } /* }}} int submit_cache_ratio */
723 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
724 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
725 cfg_wafl_t *old_data, const cfg_wafl_t *new_data)
727 /* Submit requested counters */
728 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
729 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
730 submit_cache_ratio (hostname, instance, "name_cache_hit",
731 new_data->name_cache_hit, new_data->name_cache_miss,
732 old_data->name_cache_hit, old_data->name_cache_miss,
733 new_data->timestamp);
735 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
736 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
737 submit_cache_ratio (hostname, instance, "find_dir_hit",
738 new_data->find_dir_hit, new_data->find_dir_miss,
739 old_data->find_dir_hit, old_data->find_dir_miss,
740 new_data->timestamp);
742 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
743 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
744 submit_cache_ratio (hostname, instance, "buf_hash_hit",
745 new_data->buf_hash_hit, new_data->buf_hash_miss,
746 old_data->buf_hash_hit, old_data->buf_hash_miss,
747 new_data->timestamp);
749 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
750 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
751 submit_cache_ratio (hostname, instance, "inode_cache_hit",
752 new_data->inode_cache_hit, new_data->inode_cache_miss,
753 old_data->inode_cache_hit, old_data->inode_cache_miss,
754 new_data->timestamp);
756 /* Clear old HAVE_* flags */
757 old_data->flags &= ~HAVE_WAFL_ALL;
759 /* Copy all counters */
760 old_data->timestamp = new_data->timestamp;
761 old_data->name_cache_hit = new_data->name_cache_hit;
762 old_data->name_cache_miss = new_data->name_cache_miss;
763 old_data->find_dir_hit = new_data->find_dir_hit;
764 old_data->find_dir_miss = new_data->find_dir_miss;
765 old_data->buf_hash_hit = new_data->buf_hash_hit;
766 old_data->buf_hash_miss = new_data->buf_hash_miss;
767 old_data->inode_cache_hit = new_data->inode_cache_hit;
768 old_data->inode_cache_miss = new_data->inode_cache_miss;
770 /* Copy HAVE_* flags */
771 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
774 } /* }}} int submit_wafl_data */
776 /* Submits volume performance data to the daemon, taking care to honor and
777 * update flags appropriately. */
778 static int submit_volume_perf_data (const char *hostname, /* {{{ */
779 data_volume_perf_t *old_data,
780 const data_volume_perf_t *new_data)
782 /* Check for and submit disk-octet values */
783 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
784 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
786 submit_two_counters (hostname, old_data->name, "disk_octets", /* type instance = */ NULL,
787 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
790 /* Check for and submit disk-operations values */
791 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
792 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
794 submit_two_counters (hostname, old_data->name, "disk_ops", /* type instance = */ NULL,
795 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
798 /* Check for, calculate and submit disk-latency values */
799 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
800 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
801 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
802 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
803 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
805 gauge_t latency_per_op_read;
806 gauge_t latency_per_op_write;
808 latency_per_op_read = NAN;
809 latency_per_op_write = NAN;
811 /* Check if a counter wrapped around. */
812 if ((new_data->read_ops > old_data->read_ops)
813 && (new_data->read_latency > old_data->read_latency))
815 uint64_t diff_ops_read;
816 uint64_t diff_latency_read;
818 diff_ops_read = new_data->read_ops - old_data->read_ops;
819 diff_latency_read = new_data->read_latency - old_data->read_latency;
821 if (diff_ops_read > 0)
822 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
825 if ((new_data->write_ops > old_data->write_ops)
826 && (new_data->write_latency > old_data->write_latency))
828 uint64_t diff_ops_write;
829 uint64_t diff_latency_write;
831 diff_ops_write = new_data->write_ops - old_data->write_ops;
832 diff_latency_write = new_data->write_latency - old_data->write_latency;
834 if (diff_ops_write > 0)
835 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
838 submit_two_gauge (hostname, old_data->name, "disk_latency", /* type instance = */ NULL,
839 latency_per_op_read, latency_per_op_write, new_data->timestamp);
842 /* Clear all HAVE_* flags. */
843 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
845 /* Copy all counters */
846 old_data->timestamp = new_data->timestamp;
847 old_data->read_bytes = new_data->read_bytes;
848 old_data->write_bytes = new_data->write_bytes;
849 old_data->read_ops = new_data->read_ops;
850 old_data->write_ops = new_data->write_ops;
851 old_data->read_latency = new_data->read_latency;
852 old_data->write_latency = new_data->write_latency;
854 /* Copy the HAVE_* flags */
855 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
858 } /* }}} int submit_volume_perf_data */
863 * These functions are called with appropriate data returned by the libnetapp
864 * interface which is parsed and submitted with the above functions.
866 /* Data corresponding to <WAFL /> */
867 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
870 cfg_wafl_t perf_data;
871 const char *plugin_inst;
873 na_elem_t *instances;
875 na_elem_iter_t counter_iter;
877 memset (&perf_data, 0, sizeof (perf_data));
879 perf_data.timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
881 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
882 if (instances == NULL)
884 ERROR ("netapp plugin: cna_handle_wafl_data: "
885 "na_elem_child (\"instances\") failed.");
889 plugin_inst = na_child_get_string(instances, "name");
890 if (plugin_inst == NULL)
892 ERROR ("netapp plugin: cna_handle_wafl_data: "
893 "na_child_get_string (\"name\") failed.");
897 /* Iterate over all counters */
898 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
899 for (counter = na_iterator_next (&counter_iter);
901 counter = na_iterator_next (&counter_iter))
906 name = na_child_get_string(counter, "name");
910 value = na_child_get_uint64(counter, "value", UINT64_MAX);
911 if (value == UINT64_MAX)
914 if (!strcmp(name, "name_cache_hit")) {
915 perf_data.name_cache_hit = value;
916 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
917 } else if (!strcmp(name, "name_cache_miss")) {
918 perf_data.name_cache_miss = value;
919 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
920 } else if (!strcmp(name, "find_dir_hit")) {
921 perf_data.find_dir_hit = value;
922 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
923 } else if (!strcmp(name, "find_dir_miss")) {
924 perf_data.find_dir_miss = value;
925 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
926 } else if (!strcmp(name, "buf_hash_hit")) {
927 perf_data.buf_hash_hit = value;
928 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
929 } else if (!strcmp(name, "buf_hash_miss")) {
930 perf_data.buf_hash_miss = value;
931 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
932 } else if (!strcmp(name, "inode_cache_hit")) {
933 perf_data.inode_cache_hit = value;
934 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
935 } else if (!strcmp(name, "inode_cache_miss")) {
936 perf_data.inode_cache_miss = value;
937 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
939 DEBUG("netapp plugin: cna_handle_wafl_data: "
940 "Found unexpected child: %s", name);
944 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data));
945 } /* }}} void cna_handle_wafl_data */
947 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
954 if (cw->query != NULL)
957 cw->query = na_elem_new("perf-object-get-instances");
958 if (cw->query == NULL)
960 ERROR ("netapp plugin: na_elem_new failed.");
963 na_child_add_string (cw->query, "objectname", "wafl");
965 e = na_elem_new("counters");
968 na_elem_free (cw->query);
970 ERROR ("netapp plugin: na_elem_new failed.");
973 na_child_add_string(e, "foo", "name_cache_hit");
974 na_child_add_string(e, "foo", "name_cache_miss");
975 na_child_add_string(e, "foo", "find_dir_hit");
976 na_child_add_string(e, "foo", "find_dir_miss");
977 na_child_add_string(e, "foo", "buf_hash_hit");
978 na_child_add_string(e, "foo", "buf_hash_miss");
979 na_child_add_string(e, "foo", "inode_cache_hit");
980 na_child_add_string(e, "foo", "inode_cache_miss");
982 na_child_add(cw->query, e);
985 } /* }}} int cna_setup_wafl */
987 static int cna_query_wafl (host_config_t *host) /* {{{ */
996 /* If WAFL was not configured, return without doing anything. */
997 if (host->cfg_wafl == NULL)
1001 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
1004 status = cna_setup_wafl (host->cfg_wafl);
1007 assert (host->cfg_wafl->query != NULL);
1009 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
1010 if (na_results_status (data) != NA_OK)
1012 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed: %s",
1013 na_results_reason (data));
1014 na_elem_free (data);
1018 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data);
1021 host->cfg_wafl->interval.last_read = now;
1023 na_elem_free (data);
1025 } /* }}} int cna_query_wafl */
1027 /* Data corresponding to <Disks /> */
1028 static int cna_handle_disk_data (const char *hostname, /* {{{ */
1029 cfg_disk_t *cfg_disk, na_elem_t *data)
1032 na_elem_t *instances;
1033 na_elem_t *instance;
1034 na_elem_iter_t instance_iter;
1035 disk_t *worst_disk = NULL;
1037 if ((cfg_disk == NULL) || (data == NULL))
1040 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
1042 instances = na_elem_child (data, "instances");
1043 if (instances == NULL)
1045 ERROR ("netapp plugin: cna_handle_disk_data: "
1046 "na_elem_child (\"instances\") failed.");
1050 /* Iterate over all children */
1051 instance_iter = na_child_iterator (instances);
1052 for (instance = na_iterator_next (&instance_iter);
1054 instance = na_iterator_next(&instance_iter))
1059 na_elem_iter_t counter_iterator;
1062 memset (&new_data, 0, sizeof (new_data));
1063 new_data.timestamp = timestamp;
1064 new_data.disk_busy_percent = NAN;
1066 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1067 if (old_data == NULL)
1070 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1071 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1072 for (counter = na_iterator_next(&counter_iterator);
1074 counter = na_iterator_next(&counter_iterator))
1079 name = na_child_get_string(counter, "name");
1083 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1084 if (value == UINT64_MAX)
1087 if (strcmp(name, "disk_busy") == 0)
1089 new_data.disk_busy = value;
1090 new_data.flags |= HAVE_DISK_BUSY;
1092 else if (strcmp(name, "base_for_disk_busy") == 0)
1094 new_data.base_for_disk_busy = value;
1095 new_data.flags |= HAVE_DISK_BASE;
1099 DEBUG ("netapp plugin: cna_handle_disk_data: "
1100 "Counter not handled: %s = %"PRIu64,
1105 /* If all required counters are available and did not just wrap around,
1106 * calculate the busy percentage. Otherwise, the value is initialized to
1107 * NAN at the top of the for-loop. */
1108 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1109 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1110 && (new_data.disk_busy >= old_data->disk_busy)
1111 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1116 busy_diff = new_data.disk_busy - old_data->disk_busy;
1117 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1119 new_data.disk_busy_percent = 100.0
1120 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1123 /* Clear HAVE_* flags */
1124 old_data->flags &= ~HAVE_DISK_ALL;
1127 old_data->timestamp = new_data.timestamp;
1128 old_data->disk_busy = new_data.disk_busy;
1129 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1130 old_data->disk_busy_percent = new_data.disk_busy_percent;
1133 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1135 if ((worst_disk == NULL)
1136 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1137 worst_disk = old_data;
1138 } /* for (all disks) */
1140 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1141 submit_double (hostname, "system", "percent", "disk_busy",
1142 worst_disk->disk_busy_percent, timestamp);
1145 } /* }}} int cna_handle_disk_data */
1147 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1154 if (cd->query != NULL)
1157 cd->query = na_elem_new ("perf-object-get-instances");
1158 if (cd->query == NULL)
1160 ERROR ("netapp plugin: na_elem_new failed.");
1163 na_child_add_string (cd->query, "objectname", "disk");
1165 e = na_elem_new("counters");
1168 na_elem_free (cd->query);
1170 ERROR ("netapp plugin: na_elem_new failed.");
1173 na_child_add_string(e, "foo", "disk_busy");
1174 na_child_add_string(e, "foo", "base_for_disk_busy");
1175 na_child_add(cd->query, e);
1178 } /* }}} int cna_setup_disk */
1180 static int cna_query_disk (host_config_t *host) /* {{{ */
1189 /* If the user did not configure disk statistics, return without doing
1191 if (host->cfg_disk == NULL)
1195 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1198 status = cna_setup_disk (host->cfg_disk);
1201 assert (host->cfg_disk->query != NULL);
1203 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1204 if (na_results_status (data) != NA_OK)
1206 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed: %s",
1207 na_results_reason (data));
1208 na_elem_free (data);
1212 status = cna_handle_disk_data (host->name, host->cfg_disk, data);
1215 host->cfg_disk->interval.last_read = now;
1217 na_elem_free (data);
1219 } /* }}} int cna_query_disk */
1221 /* Data corresponding to <VolumePerf /> */
1222 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1223 cfg_volume_perf_t *cvp, na_elem_t *data)
1226 na_elem_t *elem_instances;
1227 na_elem_iter_t iter_instances;
1228 na_elem_t *elem_instance;
1230 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
1232 elem_instances = na_elem_child(data, "instances");
1233 if (elem_instances == NULL)
1235 ERROR ("netapp plugin: handle_volume_perf_data: "
1236 "na_elem_child (\"instances\") failed.");
1240 iter_instances = na_child_iterator (elem_instances);
1241 for (elem_instance = na_iterator_next(&iter_instances);
1242 elem_instance != NULL;
1243 elem_instance = na_iterator_next(&iter_instances))
1247 data_volume_perf_t perf_data;
1248 data_volume_perf_t *v;
1250 na_elem_t *elem_counters;
1251 na_elem_iter_t iter_counters;
1252 na_elem_t *elem_counter;
1254 memset (&perf_data, 0, sizeof (perf_data));
1255 perf_data.timestamp = timestamp;
1257 name = na_child_get_string (elem_instance, "name");
1261 /* get_volume_perf may return NULL if this volume is to be ignored. */
1262 v = get_volume_perf (cvp, perf_data.name);
1266 elem_counters = na_elem_child (elem_instance, "counters");
1267 if (elem_counters == NULL)
1270 iter_counters = na_child_iterator (elem_counters);
1271 for (elem_counter = na_iterator_next(&iter_counters);
1272 elem_counter != NULL;
1273 elem_counter = na_iterator_next(&iter_counters))
1278 name = na_child_get_string (elem_counter, "name");
1282 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1283 if (value == UINT64_MAX)
1286 if (!strcmp(name, "read_data")) {
1287 perf_data.read_bytes = value;
1288 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1289 } else if (!strcmp(name, "write_data")) {
1290 perf_data.write_bytes = value;
1291 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1292 } else if (!strcmp(name, "read_ops")) {
1293 perf_data.read_ops = value;
1294 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1295 } else if (!strcmp(name, "write_ops")) {
1296 perf_data.write_ops = value;
1297 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1298 } else if (!strcmp(name, "read_latency")) {
1299 perf_data.read_latency = value;
1300 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1301 } else if (!strcmp(name, "write_latency")) {
1302 perf_data.write_latency = value;
1303 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1305 } /* for (elem_counter) */
1307 submit_volume_perf_data (hostname, v, &perf_data);
1308 } /* for (volume) */
1311 } /* }}} int cna_handle_volume_perf_data */
1313 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1320 if (cd->query != NULL)
1323 cd->query = na_elem_new ("perf-object-get-instances");
1324 if (cd->query == NULL)
1326 ERROR ("netapp plugin: na_elem_new failed.");
1329 na_child_add_string (cd->query, "objectname", "volume");
1331 e = na_elem_new("counters");
1334 na_elem_free (cd->query);
1336 ERROR ("netapp plugin: na_elem_new failed.");
1339 /* "foo" means: This string has to be here but the content doesn't matter. */
1340 na_child_add_string(e, "foo", "read_ops");
1341 na_child_add_string(e, "foo", "write_ops");
1342 na_child_add_string(e, "foo", "read_data");
1343 na_child_add_string(e, "foo", "write_data");
1344 na_child_add_string(e, "foo", "read_latency");
1345 na_child_add_string(e, "foo", "write_latency");
1346 na_child_add(cd->query, e);
1349 } /* }}} int cna_setup_volume_perf */
1351 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1360 /* If the user did not configure volume performance statistics, return
1361 * without doing anything. */
1362 if (host->cfg_volume_perf == NULL)
1366 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1369 status = cna_setup_volume_perf (host->cfg_volume_perf);
1372 assert (host->cfg_volume_perf->query != NULL);
1374 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1375 if (na_results_status (data) != NA_OK)
1377 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed: %s",
1378 na_results_reason (data));
1379 na_elem_free (data);
1383 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data);
1386 host->cfg_volume_perf->interval.last_read = now;
1388 na_elem_free (data);
1390 } /* }}} int cna_query_volume_perf */
1392 /* Data corresponding to <VolumeUsage /> */
1393 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1394 cfg_volume_usage_t *cfg_volume)
1396 data_volume_usage_t *v;
1398 for (v = cfg_volume->volumes; v != NULL; v = v->next)
1400 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1401 submit_double (hostname, /* plugin instance = */ v->name,
1402 "df_complex", "free",
1403 (double) v->norm_free, /* timestamp = */ 0);
1405 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1406 submit_double (hostname, /* plugin instance = */ v->name,
1407 "df_complex", "used",
1408 (double) v->norm_used, /* timestamp = */ 0);
1410 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1411 submit_double (hostname, /* plugin instance = */ v->name,
1412 "df_complex", "snap_reserved",
1413 (double) v->snap_reserved, /* timestamp = */ 0);
1415 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1416 submit_double (hostname, /* plugin instance = */ v->name,
1417 "df_complex", "snap_used",
1418 (double) v->snap_used, /* timestamp = */ 0);
1420 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1421 submit_double (hostname, /* plugin instance = */ v->name,
1422 "df_complex", "sis_saved",
1423 (double) v->sis_saved, /* timestamp = */ 0);
1425 /* Clear all the HAVE_* flags */
1426 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1427 } /* for (v = cfg_volume->volumes) */
1430 } /* }}} int cna_submit_volume_usage_data */
1432 static int cna_handle_volume_usage_data (const char *hostname, /* {{{ */
1433 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1435 na_elem_t *elem_volume;
1436 na_elem_t *elem_volumes;
1437 na_elem_iter_t iter_volume;
1439 elem_volumes = na_elem_child (data, "volumes");
1440 if (elem_volumes == NULL)
1442 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1443 "na_elem_child (\"volumes\") failed.");
1447 iter_volume = na_child_iterator (elem_volumes);
1448 for (elem_volume = na_iterator_next (&iter_volume);
1449 elem_volume != NULL;
1450 elem_volume = na_iterator_next (&iter_volume))
1452 const char *volume_name;
1454 data_volume_usage_t *v;
1458 const char *sis_state;
1459 uint64_t sis_saved_reported;
1461 volume_name = na_child_get_string (elem_volume, "name");
1462 if (volume_name == NULL)
1465 /* get_volume_usage may return NULL if the volume is to be ignored. */
1466 v = get_volume_usage (cfg_volume, volume_name);
1470 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1473 /* 2^4 exa-bytes? This will take a while ;) */
1474 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1475 if (value != UINT64_MAX) {
1476 v->norm_free = value;
1477 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1480 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1481 if (value != UINT64_MAX) {
1482 v->norm_used = value;
1483 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1486 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1487 if (value != UINT64_MAX) {
1488 /* 1 block == 1024 bytes as per API docs */
1489 v->norm_used = 1024 * value;
1490 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1493 sis = na_elem_child(elem_volume, "sis");
1497 sis_state = na_child_get_string(sis, "state");
1498 if (sis_state == NULL)
1501 /* If SIS is not enabled, set the HAVE_VOLUME_USAGE_SIS_SAVED flag and set
1502 * sis_saved to UINT64_MAX to signal this condition to the submit function. */
1503 if (strcmp ("enabled", sis_state) != 0) {
1504 v->sis_saved = UINT64_MAX;
1505 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1509 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1510 if (sis_saved_reported == UINT64_MAX)
1513 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1514 if ((sis_saved_reported >> 32) != 0) {
1515 /* In case they ever fix this bug. */
1516 v->sis_saved = sis_saved_reported;
1517 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1518 } else { /* really hacky work-around code. {{{ */
1519 uint64_t sis_saved_percent;
1520 uint64_t sis_saved_guess;
1521 uint64_t overflow_guess;
1522 uint64_t guess1, guess2, guess3;
1524 /* Check if we have v->norm_used. Without it, we cannot calculate
1525 * sis_saved_guess. */
1526 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1529 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1530 if (sis_saved_percent > 100)
1533 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1534 * will hopefully be fixed in later versions. To work around the bug, try
1535 * to figure out how often the 32bit integer wrapped around by using the
1536 * "percentage-saved" value. Because the percentage is in the range
1537 * [0-100], this should work as long as the saved space does not exceed
1539 /* percentage-saved = size-saved / (size-saved + size-used) */
1540 if (sis_saved_percent < 100)
1541 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1543 sis_saved_guess = v->norm_used;
1545 overflow_guess = sis_saved_guess >> 32;
1546 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1547 guess2 = (overflow_guess << 32) + sis_saved_reported;
1548 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1550 if (sis_saved_guess < guess2) {
1551 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1552 v->sis_saved = guess1;
1554 v->sis_saved = guess2;
1556 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1557 v->sis_saved = guess2;
1559 v->sis_saved = guess3;
1561 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1562 } /* }}} end of 32-bit workaround */
1563 } /* for (elem_volume) */
1565 return (cna_submit_volume_usage_data (hostname, cfg_volume));
1566 } /* }}} int cna_handle_volume_usage_data */
1568 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1573 if (cvu->query != NULL)
1576 cvu->query = na_elem_new ("volume-list-info");
1577 if (cvu->query == NULL)
1579 ERROR ("netapp plugin: na_elem_new failed.");
1583 /* TODO: cvu->snap_query = na_elem_new("snapshot-list-info"); */
1586 } /* }}} int cna_setup_volume_usage */
1588 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1597 /* If the user did not configure volume_usage statistics, return without
1598 * doing anything. */
1599 if (host->cfg_volume_usage == NULL)
1603 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1606 status = cna_setup_volume_usage (host->cfg_volume_usage);
1609 assert (host->cfg_volume_usage->query != NULL);
1611 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1612 if (na_results_status (data) != NA_OK)
1614 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed: %s",
1615 na_results_reason (data));
1616 na_elem_free (data);
1620 status = cna_handle_volume_usage_data (host->name, host->cfg_volume_usage, data);
1623 host->cfg_volume_usage->interval.last_read = now;
1625 na_elem_free (data);
1627 } /* }}} int cna_query_volume_usage */
1629 /* Data corresponding to <System /> */
1630 static int cna_handle_system_data (const char *hostname, /* {{{ */
1631 cfg_system_t *cfg_system, na_elem_t *data)
1633 na_elem_t *instances;
1635 na_elem_iter_t counter_iter;
1637 counter_t disk_read = 0, disk_written = 0;
1638 counter_t net_recv = 0, net_sent = 0;
1639 counter_t cpu_busy = 0, cpu_total = 0;
1640 uint32_t counter_flags = 0;
1642 const char *instance;
1645 timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
1647 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1648 if (instances == NULL)
1650 ERROR ("netapp plugin: cna_handle_system_data: "
1651 "na_elem_child (\"instances\") failed.");
1655 instance = na_child_get_string (instances, "name");
1656 if (instance == NULL)
1658 ERROR ("netapp plugin: cna_handle_system_data: "
1659 "na_child_get_string (\"name\") failed.");
1663 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
1664 for (counter = na_iterator_next (&counter_iter);
1666 counter = na_iterator_next (&counter_iter))
1671 name = na_child_get_string(counter, "name");
1675 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1676 if (value == UINT64_MAX)
1679 if (!strcmp(name, "disk_data_read")) {
1680 disk_read = (counter_t) (value * 1024);
1681 counter_flags |= 0x01;
1682 } else if (!strcmp(name, "disk_data_written")) {
1683 disk_written = (counter_t) (value * 1024);
1684 counter_flags |= 0x02;
1685 } else if (!strcmp(name, "net_data_recv")) {
1686 net_recv = (counter_t) (value * 1024);
1687 counter_flags |= 0x04;
1688 } else if (!strcmp(name, "net_data_sent")) {
1689 net_sent = (counter_t) (value * 1024);
1690 counter_flags |= 0x08;
1691 } else if (!strcmp(name, "cpu_busy")) {
1692 cpu_busy = (counter_t) value;
1693 counter_flags |= 0x10;
1694 } else if (!strcmp(name, "cpu_elapsed_time")) {
1695 cpu_total = (counter_t) value;
1696 counter_flags |= 0x20;
1697 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1698 && (value > 0) && (strlen(name) > 4)
1699 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1700 submit_counter (hostname, instance, "disk_ops_complex", name,
1701 (counter_t) value, timestamp);
1703 } /* for (counter) */
1705 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1706 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
1707 submit_two_counters (hostname, instance, "disk_octets", NULL,
1708 disk_read, disk_written, timestamp);
1710 if ((cfg_system->flags & CFG_SYSTEM_NET)
1711 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
1712 submit_two_counters (hostname, instance, "if_octets", NULL,
1713 net_recv, net_sent, timestamp);
1715 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1716 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
1718 submit_counter (hostname, instance, "cpu", "system",
1719 cpu_busy, timestamp);
1720 submit_counter (hostname, instance, "cpu", "idle",
1721 cpu_total - cpu_busy, timestamp);
1725 } /* }}} int cna_handle_system_data */
1727 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
1732 if (cs->query != NULL)
1735 cs->query = na_elem_new ("perf-object-get-instances");
1736 if (cs->query == NULL)
1738 ERROR ("netapp plugin: na_elem_new failed.");
1741 na_child_add_string (cs->query, "objectname", "system");
1744 } /* }}} int cna_setup_system */
1746 static int cna_query_system (host_config_t *host) /* {{{ */
1755 /* If system statistics were not configured, return without doing anything. */
1756 if (host->cfg_system == NULL)
1760 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
1763 status = cna_setup_system (host->cfg_system);
1766 assert (host->cfg_system->query != NULL);
1768 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
1769 if (na_results_status (data) != NA_OK)
1771 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed: %s",
1772 na_results_reason (data));
1773 na_elem_free (data);
1777 status = cna_handle_system_data (host->name, host->cfg_system, data);
1780 host->cfg_system->interval.last_read = now;
1782 na_elem_free (data);
1784 } /* }}} int cna_query_system */
1787 * Configuration handling
1789 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1790 * is false. On error, the flag-field is not changed. */
1791 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1792 uint32_t *flags, uint32_t flag)
1794 if ((ci == NULL) || (flags == NULL))
1797 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1799 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1804 if (ci->values[0].value.boolean)
1810 } /* }}} int cna_config_bool_to_flag */
1812 /* Handling of the "Interval" option which is allowed in every block. */
1813 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1814 cna_interval_t *out_interval)
1818 if ((ci == NULL) || (out_interval == NULL))
1821 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1823 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1827 tmp = (time_t) (ci->values[0].value.number + .5);
1830 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1834 out_interval->interval = tmp;
1835 out_interval->last_read = 0;
1838 } /* }}} int cna_config_get_interval */
1840 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1841 * <VolumePerf /> block. */
1842 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
1843 const oconfig_item_t *ci)
1848 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1850 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1855 name = ci->values[0].value.string;
1857 if (strcasecmp ("GetIO", ci->key) == 0)
1858 il = cvp->il_octets;
1859 else if (strcasecmp ("GetOps", ci->key) == 0)
1860 il = cvp->il_operations;
1861 else if (strcasecmp ("GetLatency", ci->key) == 0)
1862 il = cvp->il_latency;
1866 ignorelist_add (il, name);
1867 } /* }}} void cna_config_volume_perf_option */
1869 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
1870 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
1871 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
1872 const oconfig_item_t *ci)
1876 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1878 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1883 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
1884 il = cvp->il_octets;
1885 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
1886 il = cvp->il_operations;
1887 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
1888 il = cvp->il_latency;
1892 if (ci->values[0].value.boolean)
1893 ignorelist_set_invert (il, /* invert = */ 0);
1895 ignorelist_set_invert (il, /* invert = */ 1);
1896 } /* }}} void cna_config_volume_perf_default */
1898 /* Corresponds to a <Disks /> block */
1903 * IgnoreSelectedIO false
1907 * IgnoreSelectedOps false
1911 * IgnoreSelectedLatency false
1914 /* Corresponds to a <VolumePerf /> block */
1915 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
1916 const oconfig_item_t *ci)
1918 cfg_volume_perf_t *cfg_volume_perf;
1921 if ((host == NULL) || (ci == NULL))
1924 if (host->cfg_volume_perf == NULL)
1926 cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
1927 if (cfg_volume_perf == NULL)
1929 memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
1931 /* Set default flags */
1932 cfg_volume_perf->query = NULL;
1933 cfg_volume_perf->volumes = NULL;
1935 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
1936 if (cfg_volume_perf->il_octets == NULL)
1938 sfree (cfg_volume_perf);
1942 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
1943 if (cfg_volume_perf->il_operations == NULL)
1945 ignorelist_free (cfg_volume_perf->il_octets);
1946 sfree (cfg_volume_perf);
1950 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
1951 if (cfg_volume_perf->il_latency == NULL)
1953 ignorelist_free (cfg_volume_perf->il_octets);
1954 ignorelist_free (cfg_volume_perf->il_operations);
1955 sfree (cfg_volume_perf);
1959 host->cfg_volume_perf = cfg_volume_perf;
1961 cfg_volume_perf = host->cfg_volume_perf;
1963 for (i = 0; i < ci->children_num; ++i) {
1964 oconfig_item_t *item = ci->children + i;
1966 /* if (!item || !item->key || !*item->key) continue; */
1967 if (strcasecmp(item->key, "Interval") == 0)
1968 cna_config_get_interval (item, &cfg_volume_perf->interval);
1969 else if (!strcasecmp(item->key, "GetIO"))
1970 cna_config_volume_perf_option (cfg_volume_perf, item);
1971 else if (!strcasecmp(item->key, "GetOps"))
1972 cna_config_volume_perf_option (cfg_volume_perf, item);
1973 else if (!strcasecmp(item->key, "GetLatency"))
1974 cna_config_volume_perf_option (cfg_volume_perf, item);
1975 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
1976 cna_config_volume_perf_default (cfg_volume_perf, item);
1977 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
1978 cna_config_volume_perf_default (cfg_volume_perf, item);
1979 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
1980 cna_config_volume_perf_default (cfg_volume_perf, item);
1982 WARNING ("netapp plugin: The option %s is not allowed within "
1983 "`VolumePerf' blocks.", item->key);
1987 } /* }}} int cna_config_volume_performance */
1989 /* Handling of the "Capacity" and "Snapshot" options within a <VolumeUsage />
1991 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
1992 const oconfig_item_t *ci)
1997 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1999 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2004 name = ci->values[0].value.string;
2006 if (strcasecmp ("Capacity", ci->key) == 0)
2007 il = cvu->il_capacity;
2008 else if (strcasecmp ("Snapshot", ci->key) == 0)
2009 il = cvu->il_snapshot;
2013 ignorelist_add (il, name);
2014 } /* }}} void cna_config_volume_usage_option */
2016 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2017 * options within a <VolumeUsage /> block. */
2018 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
2019 const oconfig_item_t *ci)
2023 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2025 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2030 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2031 il = cvu->il_capacity;
2032 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2033 il = cvu->il_snapshot;
2037 if (ci->values[0].value.boolean)
2038 ignorelist_set_invert (il, /* invert = */ 0);
2040 ignorelist_set_invert (il, /* invert = */ 1);
2041 } /* }}} void cna_config_volume_usage_default */
2043 /* Corresponds to a <Disks /> block */
2044 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2045 cfg_disk_t *cfg_disk;
2048 if ((host == NULL) || (ci == NULL))
2051 if (host->cfg_disk == NULL)
2053 cfg_disk = malloc (sizeof (*cfg_disk));
2054 if (cfg_disk == NULL)
2056 memset (cfg_disk, 0, sizeof (*cfg_disk));
2058 /* Set default flags */
2059 cfg_disk->flags = CFG_DISK_ALL;
2060 cfg_disk->query = NULL;
2061 cfg_disk->disks = NULL;
2063 host->cfg_disk = cfg_disk;
2065 cfg_disk = host->cfg_disk;
2067 for (i = 0; i < ci->children_num; ++i) {
2068 oconfig_item_t *item = ci->children + i;
2070 /* if (!item || !item->key || !*item->key) continue; */
2071 if (strcasecmp(item->key, "Interval") == 0)
2072 cna_config_get_interval (item, &cfg_disk->interval);
2073 else if (strcasecmp(item->key, "GetBusy") == 0)
2074 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2077 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2079 NOTICE ("netapp plugin: All disk related values have been disabled. "
2080 "Collection of per-disk data will be disabled entirely.");
2081 free_cfg_disk (host->cfg_disk);
2082 host->cfg_disk = NULL;
2086 } /* }}} int cna_config_disk */
2088 /* Corresponds to a <WAFL /> block */
2089 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2091 cfg_wafl_t *cfg_wafl;
2094 if ((host == NULL) || (ci == NULL))
2097 if (host->cfg_wafl == NULL)
2099 cfg_wafl = malloc (sizeof (*cfg_wafl));
2100 if (cfg_wafl == NULL)
2102 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
2104 /* Set default flags */
2105 cfg_wafl->flags = CFG_WAFL_ALL;
2107 host->cfg_wafl = cfg_wafl;
2109 cfg_wafl = host->cfg_wafl;
2111 for (i = 0; i < ci->children_num; ++i) {
2112 oconfig_item_t *item = ci->children + i;
2114 if (strcasecmp(item->key, "Interval") == 0)
2115 cna_config_get_interval (item, &cfg_wafl->interval);
2116 else if (!strcasecmp(item->key, "GetNameCache"))
2117 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2118 else if (!strcasecmp(item->key, "GetDirCache"))
2119 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2120 else if (!strcasecmp(item->key, "GetBufferCache"))
2121 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2122 else if (!strcasecmp(item->key, "GetInodeCache"))
2123 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2125 WARNING ("netapp plugin: The %s config option is not allowed within "
2126 "`WAFL' blocks.", item->key);
2129 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2131 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2132 "Collection of WAFL data will be disabled entirely.");
2133 free_cfg_wafl (host->cfg_wafl);
2134 host->cfg_wafl = NULL;
2138 } /* }}} int cna_config_wafl */
2147 * IgnoreSelectedCapacity false
2153 * IgnoreSelectedSnapshot false
2156 /* Corresponds to a <VolumeUsage /> block */
2157 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2158 const oconfig_item_t *ci)
2160 cfg_volume_usage_t *cfg_volume_usage;
2163 if ((host == NULL) || (ci == NULL))
2166 if (host->cfg_volume_usage == NULL)
2168 cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
2169 if (cfg_volume_usage == NULL)
2171 memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
2173 /* Set default flags */
2174 cfg_volume_usage->query = NULL;
2175 cfg_volume_usage->volumes = NULL;
2177 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2178 if (cfg_volume_usage->il_capacity == NULL)
2180 sfree (cfg_volume_usage);
2184 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2185 if (cfg_volume_usage->il_snapshot == NULL)
2187 ignorelist_free (cfg_volume_usage->il_capacity);
2188 sfree (cfg_volume_usage);
2192 host->cfg_volume_usage = cfg_volume_usage;
2194 cfg_volume_usage = host->cfg_volume_usage;
2196 for (i = 0; i < ci->children_num; ++i) {
2197 oconfig_item_t *item = ci->children + i;
2199 /* if (!item || !item->key || !*item->key) continue; */
2200 if (strcasecmp(item->key, "Interval") == 0)
2201 cna_config_get_interval (item, &cfg_volume_usage->interval);
2202 else if (!strcasecmp(item->key, "Capacity"))
2203 cna_config_volume_usage_option (cfg_volume_usage, item);
2204 else if (!strcasecmp(item->key, "Snapshot"))
2205 cna_config_volume_usage_option (cfg_volume_usage, item);
2206 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2207 cna_config_volume_usage_default (cfg_volume_usage, item);
2208 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2209 cna_config_volume_usage_default (cfg_volume_usage, item);
2211 WARNING ("netapp plugin: The option %s is not allowed within "
2212 "`VolumeUsage' blocks.", item->key);
2216 } /* }}} int cna_config_volume_usage */
2218 /* Corresponds to a <System /> block */
2219 static int cna_config_system (host_config_t *host, /* {{{ */
2220 oconfig_item_t *ci, const cfg_service_t *default_service)
2222 cfg_system_t *cfg_system;
2225 if ((host == NULL) || (ci == NULL))
2228 if (host->cfg_system == NULL)
2230 cfg_system = malloc (sizeof (*cfg_system));
2231 if (cfg_system == NULL)
2233 memset (cfg_system, 0, sizeof (*cfg_system));
2235 /* Set default flags */
2236 cfg_system->flags = CFG_SYSTEM_ALL;
2237 cfg_system->query = NULL;
2239 host->cfg_system = cfg_system;
2241 cfg_system = host->cfg_system;
2243 for (i = 0; i < ci->children_num; ++i) {
2244 oconfig_item_t *item = ci->children + i;
2246 if (strcasecmp(item->key, "Interval") == 0) {
2247 cna_config_get_interval (item, &cfg_system->interval);
2248 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2249 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2250 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2251 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2252 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2253 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2254 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2255 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2257 WARNING ("netapp plugin: The %s config option is not allowed within "
2258 "`System' blocks.", item->key);
2262 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2264 NOTICE ("netapp plugin: All system related values have been disabled. "
2265 "Collection of system data will be disabled entirely.");
2266 free_cfg_system (host->cfg_system);
2267 host->cfg_system = NULL;
2271 } /* }}} int cna_config_system */
2273 /* Corresponds to a <Host /> block. */
2274 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
2275 const host_config_t *default_host, const cfg_service_t *def_def_service)
2277 oconfig_item_t *item;
2278 host_config_t *host;
2279 cfg_service_t default_service = *def_def_service;
2283 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2284 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
2288 host = malloc(sizeof(*host));
2289 memcpy (host, default_host, sizeof (*host));
2291 status = cf_util_get_string (ci, &host->name);
2298 for (i = 0; i < ci->children_num; ++i) {
2299 item = ci->children + i;
2303 if (!strcasecmp(item->key, "Address")) {
2304 status = cf_util_get_string (item, &host->host);
2305 } else if (!strcasecmp(item->key, "Port")) {
2308 tmp = cf_util_get_port_number (item);
2311 } else if (!strcasecmp(item->key, "Protocol")) {
2312 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"))) {
2313 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2316 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2317 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2318 } else if (!strcasecmp(item->key, "User")) {
2319 status = cf_util_get_string (item, &host->username);
2320 } else if (!strcasecmp(item->key, "Password")) {
2321 status = cf_util_get_string (item, &host->password);
2322 } else if (!strcasecmp(item->key, "Interval")) {
2323 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) {
2324 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
2327 host->interval = item->values[0].value.number;
2328 } else if (!strcasecmp(item->key, "WAFL")) {
2329 cna_config_wafl(host, item);
2330 } else if (!strcasecmp(item->key, "Disks")) {
2331 cna_config_disk(host, item);
2332 } else if (!strcasecmp(item->key, "VolumePerf")) {
2333 cna_config_volume_performance(host, item);
2334 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2335 cna_config_volume_usage(host, item);
2336 } else if (!strcasecmp(item->key, "System")) {
2337 cna_config_system(host, item, &default_service);
2339 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
2340 item->key, ci->values[0].value.string);
2347 if (host->host == NULL)
2348 host->host = strdup (host->name);
2350 if (host->host == NULL)
2353 if (host->port <= 0)
2354 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2356 if ((host->username == NULL) || (host->password == NULL)) {
2357 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2358 "Ignoring host block.", host->name);
2364 free_host_config (host);
2369 } /* }}} host_config_t *cna_config_host */
2372 * Callbacks registered with the daemon
2374 * Pretty standard stuff here.
2376 static int cna_init(void) { /* {{{ */
2378 host_config_t *host;
2380 if (!global_host_config) {
2381 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
2385 memset (err, 0, sizeof (err));
2386 if (!na_startup(err, sizeof(err))) {
2387 err[sizeof (err) - 1] = 0;
2388 ERROR("netapp plugin: Error initializing netapp API: %s", err);
2392 for (host = global_host_config; host; host = host->next) {
2393 /* Request version 1.1 of the ONTAP API */
2394 host->srv = na_server_open(host->host,
2395 /* major version = */ 1, /* minor version = */ 1);
2396 if (host->srv == NULL) {
2397 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
2401 if (host->interval < interval_g)
2402 host->interval = interval_g;
2404 na_server_set_transport_type(host->srv, host->protocol,
2405 /* transportarg = */ NULL);
2406 na_server_set_port(host->srv, host->port);
2407 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
2408 na_server_adminuser(host->srv, host->username, host->password);
2409 na_server_set_timeout(host->srv, 5 /* seconds */);
2412 } /* }}} int cna_init */
2414 static int cna_config (oconfig_item_t *ci) { /* {{{ */
2416 oconfig_item_t *item;
2417 host_config_t default_host = HOST_INIT;
2418 cfg_service_t default_service = SERVICE_INIT;
2420 for (i = 0; i < ci->children_num; ++i) {
2421 item = ci->children + i;
2423 if (!strcasecmp(item->key, "Host")) {
2424 host_config_t *host;
2427 host = cna_config_host(item, &default_host, &default_service);
2431 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
2433 if (strcasecmp (host->name, tmp->name) == 0)
2434 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
2435 "This is probably a bad idea.",
2438 if (tmp->next == NULL)
2444 global_host_config = host;
2448 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
2452 } /* }}} int cna_config */
2454 static int cna_read (void) { /* {{{ */
2456 host_config_t *host;
2457 cfg_service_t *service;
2459 for (host = global_host_config; host; host = host->next) {
2460 for (service = host->services; service; service = service->next) {
2461 if (--service->skip_countdown > 0) continue;
2462 service->skip_countdown = service->multiplier;
2463 out = na_server_invoke_elem(host->srv, service->query);
2464 if (na_results_status(out) != NA_OK) {
2465 int netapp_errno = na_results_errno(out);
2466 ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
2468 if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
2469 /* Network problems. Just give up on all other services on this host. */
2474 service->handler(host, out, service->data);
2476 } /* for (host->services) */
2478 cna_query_wafl (host);
2479 cna_query_disk (host);
2480 cna_query_volume_perf (host);
2481 cna_query_volume_usage (host);
2482 cna_query_system (host);
2485 } /* }}} int cna_read */
2487 void module_register(void) {
2488 plugin_register_complex_config("netapp", cna_config);
2489 plugin_register_init("netapp", cna_init);
2490 plugin_register_read("netapp", cna_read);
2493 /* vim: set sw=2 ts=2 noet fdm=marker : */