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 struct host_config_s {
236 na_server_transport_t protocol;
244 cfg_wafl_t *cfg_wafl;
245 cfg_disk_t *cfg_disk;
246 cfg_volume_perf_t *cfg_volume_perf;
247 cfg_volume_usage_t *cfg_volume_usage;
248 cfg_system_t *cfg_system;
250 struct host_config_s *next;
252 #define HOST_INIT { NULL, NA_SERVER_TRANSPORT_HTTPS, NULL, 0, NULL, NULL, 0, \
253 NULL, NULL, NULL, NULL, NULL, NULL, \
256 static host_config_t *global_host_config;
261 * Used to free the various structures above.
263 static void free_disk (disk_t *disk) /* {{{ */
276 } /* }}} void free_disk */
278 static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
283 if (cw->query != NULL)
284 na_elem_free (cw->query);
287 } /* }}} void free_cfg_wafl */
289 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
291 if (cfg_disk == NULL)
294 if (cfg_disk->query != NULL)
295 na_elem_free (cfg_disk->query);
297 free_disk (cfg_disk->disks);
299 } /* }}} void free_cfg_disk */
301 static void free_cfg_volume_perf (cfg_volume_perf_t *cvp) /* {{{ */
303 data_volume_perf_t *data;
308 /* Free the ignorelists */
309 ignorelist_free (cvp->il_octets);
310 ignorelist_free (cvp->il_operations);
311 ignorelist_free (cvp->il_latency);
313 /* Free the linked list of volumes */
317 data_volume_perf_t *next = data->next;
323 if (cvp->query != NULL)
324 na_elem_free (cvp->query);
327 } /* }}} void free_cfg_volume_perf */
329 static void free_cfg_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
331 data_volume_usage_t *data;
336 /* Free the ignorelists */
337 ignorelist_free (cvu->il_capacity);
338 ignorelist_free (cvu->il_snapshot);
340 /* Free the linked list of volumes */
344 data_volume_usage_t *next = data->next;
350 if (cvu->query != NULL)
351 na_elem_free (cvu->query);
354 } /* }}} void free_cfg_volume_usage */
356 static void free_cfg_system (cfg_system_t *cs) /* {{{ */
361 if (cs->query != NULL)
362 na_elem_free (cs->query);
365 } /* }}} void free_cfg_system */
367 static void free_host_config (host_config_t *hc) /* {{{ */
378 sfree (hc->username);
379 sfree (hc->password);
381 free_cfg_disk (hc->cfg_disk);
382 free_cfg_wafl (hc->cfg_wafl);
383 free_cfg_volume_perf (hc->cfg_volume_perf);
384 free_cfg_volume_usage (hc->cfg_volume_usage);
385 free_cfg_system (hc->cfg_system);
389 free_host_config (next);
390 } /* }}} void free_host_config */
393 * Auxiliary functions
395 * Used to look up volumes and disks or to handle flags.
397 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
401 if ((cd == NULL) || (name == NULL))
404 for (d = cd->disks; d != NULL; d = d->next) {
405 if (strcmp(d->name, name) == 0)
409 d = malloc(sizeof(*d));
412 memset (d, 0, sizeof (*d));
415 d->name = strdup(name);
416 if (d->name == NULL) {
425 } /* }}} disk_t *get_disk */
427 static data_volume_usage_t *get_volume_usage (cfg_volume_usage_t *cvu, /* {{{ */
430 data_volume_usage_t *last;
431 data_volume_usage_t *new;
433 int ignore_capacity = 0;
434 int ignore_snapshot = 0;
436 if ((cvu == NULL) || (name == NULL))
442 if (strcmp (last->name, name) == 0)
445 if (last->next == NULL)
451 /* Check the ignorelists. If *both* tell us to ignore a volume, return NULL. */
452 ignore_capacity = ignorelist_match (cvu->il_capacity, name);
453 ignore_snapshot = ignorelist_match (cvu->il_snapshot, name);
454 if ((ignore_capacity != 0) && (ignore_snapshot != 0))
457 /* Not found: allocate. */
458 new = malloc (sizeof (*new));
461 memset (new, 0, sizeof (*new));
464 new->name = strdup (name);
465 if (new->name == NULL)
471 if (ignore_capacity == 0)
472 new->flags |= CFG_VOLUME_USAGE_DF;
473 if (ignore_snapshot == 0)
474 new->flags |= CFG_VOLUME_USAGE_SNAP;
476 /* Add to end of list. */
483 } /* }}} data_volume_usage_t *get_volume_usage */
485 static data_volume_perf_t *get_volume_perf (cfg_volume_perf_t *cvp, /* {{{ */
488 data_volume_perf_t *last;
489 data_volume_perf_t *new;
491 int ignore_octets = 0;
492 int ignore_operations = 0;
493 int ignore_latency = 0;
495 if ((cvp == NULL) || (name == NULL))
501 if (strcmp (last->name, name) == 0)
504 if (last->next == NULL)
510 /* Check the ignorelists. If *all three* tell us to ignore a volume, return
512 ignore_octets = ignorelist_match (cvp->il_octets, name);
513 ignore_operations = ignorelist_match (cvp->il_operations, name);
514 ignore_latency = ignorelist_match (cvp->il_latency, name);
515 if ((ignore_octets != 0) || (ignore_operations != 0)
516 || (ignore_latency != 0))
519 /* Not found: allocate. */
520 new = malloc (sizeof (*new));
523 memset (new, 0, sizeof (*new));
526 new->name = strdup (name);
527 if (new->name == NULL)
533 if (ignore_octets == 0)
534 new->flags |= CFG_VOLUME_PERF_IO;
535 if (ignore_operations == 0)
536 new->flags |= CFG_VOLUME_PERF_OPS;
537 if (ignore_latency == 0)
538 new->flags |= CFG_VOLUME_PERF_LATENCY;
540 /* Add to end of list. */
547 } /* }}} data_volume_perf_t *get_volume_perf */
550 * Various submit functions.
552 * They all eventually call "submit_values" which creates a value_list_t and
553 * dispatches it to the daemon.
555 static int submit_values (const char *host, /* {{{ */
556 const char *plugin_inst,
557 const char *type, const char *type_inst,
558 value_t *values, int values_len,
561 value_list_t vl = VALUE_LIST_INIT;
564 vl.values_len = values_len;
570 sstrncpy (vl.host, host, sizeof (vl.host));
572 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
573 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
574 if (plugin_inst != NULL)
575 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
576 sstrncpy (vl.type, type, sizeof (vl.type));
577 if (type_inst != NULL)
578 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
580 return (plugin_dispatch_values (&vl));
581 } /* }}} int submit_uint64 */
583 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
584 const char *type, const char *type_inst, counter_t val0, counter_t val1,
589 values[0].counter = val0;
590 values[1].counter = val1;
592 return (submit_values (host, plugin_inst, type, type_inst,
593 values, 2, timestamp));
594 } /* }}} int submit_two_counters */
596 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
597 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
603 return (submit_values (host, plugin_inst, type, type_inst,
605 } /* }}} int submit_counter */
607 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
608 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
613 values[0].gauge = val0;
614 values[1].gauge = val1;
616 return (submit_values (host, plugin_inst, type, type_inst,
617 values, 2, timestamp));
618 } /* }}} int submit_two_gauge */
620 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
621 const char *type, const char *type_inst, double d, time_t timestamp)
625 v.gauge = (gauge_t) d;
627 return (submit_values (host, plugin_inst, type, type_inst,
629 } /* }}} int submit_uint64 */
631 /* Calculate hit ratio from old and new counters and submit the resulting
632 * percentage. Used by "submit_wafl_data". */
633 static int submit_cache_ratio (const char *host, /* {{{ */
634 const char *plugin_inst,
635 const char *type_inst,
644 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
648 hits = new_hits - old_hits;
649 misses = new_misses - old_misses;
651 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
656 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
658 } /* }}} int submit_cache_ratio */
660 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
661 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
662 cfg_wafl_t *old_data, const cfg_wafl_t *new_data)
664 /* Submit requested counters */
665 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
666 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
667 submit_cache_ratio (hostname, instance, "name_cache_hit",
668 new_data->name_cache_hit, new_data->name_cache_miss,
669 old_data->name_cache_hit, old_data->name_cache_miss,
670 new_data->timestamp);
672 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
673 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
674 submit_cache_ratio (hostname, instance, "find_dir_hit",
675 new_data->find_dir_hit, new_data->find_dir_miss,
676 old_data->find_dir_hit, old_data->find_dir_miss,
677 new_data->timestamp);
679 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
680 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
681 submit_cache_ratio (hostname, instance, "buf_hash_hit",
682 new_data->buf_hash_hit, new_data->buf_hash_miss,
683 old_data->buf_hash_hit, old_data->buf_hash_miss,
684 new_data->timestamp);
686 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
687 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
688 submit_cache_ratio (hostname, instance, "inode_cache_hit",
689 new_data->inode_cache_hit, new_data->inode_cache_miss,
690 old_data->inode_cache_hit, old_data->inode_cache_miss,
691 new_data->timestamp);
693 /* Clear old HAVE_* flags */
694 old_data->flags &= ~HAVE_WAFL_ALL;
696 /* Copy all counters */
697 old_data->timestamp = new_data->timestamp;
698 old_data->name_cache_hit = new_data->name_cache_hit;
699 old_data->name_cache_miss = new_data->name_cache_miss;
700 old_data->find_dir_hit = new_data->find_dir_hit;
701 old_data->find_dir_miss = new_data->find_dir_miss;
702 old_data->buf_hash_hit = new_data->buf_hash_hit;
703 old_data->buf_hash_miss = new_data->buf_hash_miss;
704 old_data->inode_cache_hit = new_data->inode_cache_hit;
705 old_data->inode_cache_miss = new_data->inode_cache_miss;
707 /* Copy HAVE_* flags */
708 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
711 } /* }}} int submit_wafl_data */
713 /* Submits volume performance data to the daemon, taking care to honor and
714 * update flags appropriately. */
715 static int submit_volume_perf_data (const char *hostname, /* {{{ */
716 data_volume_perf_t *old_data,
717 const data_volume_perf_t *new_data)
719 /* Check for and submit disk-octet values */
720 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
721 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
723 submit_two_counters (hostname, old_data->name, "disk_octets", /* type instance = */ NULL,
724 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
727 /* Check for and submit disk-operations values */
728 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
729 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
731 submit_two_counters (hostname, old_data->name, "disk_ops", /* type instance = */ NULL,
732 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
735 /* Check for, calculate and submit disk-latency values */
736 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
737 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
738 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
739 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
740 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
742 gauge_t latency_per_op_read;
743 gauge_t latency_per_op_write;
745 latency_per_op_read = NAN;
746 latency_per_op_write = NAN;
748 /* Check if a counter wrapped around. */
749 if ((new_data->read_ops > old_data->read_ops)
750 && (new_data->read_latency > old_data->read_latency))
752 uint64_t diff_ops_read;
753 uint64_t diff_latency_read;
755 diff_ops_read = new_data->read_ops - old_data->read_ops;
756 diff_latency_read = new_data->read_latency - old_data->read_latency;
758 if (diff_ops_read > 0)
759 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
762 if ((new_data->write_ops > old_data->write_ops)
763 && (new_data->write_latency > old_data->write_latency))
765 uint64_t diff_ops_write;
766 uint64_t diff_latency_write;
768 diff_ops_write = new_data->write_ops - old_data->write_ops;
769 diff_latency_write = new_data->write_latency - old_data->write_latency;
771 if (diff_ops_write > 0)
772 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
775 submit_two_gauge (hostname, old_data->name, "disk_latency", /* type instance = */ NULL,
776 latency_per_op_read, latency_per_op_write, new_data->timestamp);
779 /* Clear all HAVE_* flags. */
780 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
782 /* Copy all counters */
783 old_data->timestamp = new_data->timestamp;
784 old_data->read_bytes = new_data->read_bytes;
785 old_data->write_bytes = new_data->write_bytes;
786 old_data->read_ops = new_data->read_ops;
787 old_data->write_ops = new_data->write_ops;
788 old_data->read_latency = new_data->read_latency;
789 old_data->write_latency = new_data->write_latency;
791 /* Copy the HAVE_* flags */
792 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
795 } /* }}} int submit_volume_perf_data */
800 * These functions are called with appropriate data returned by the libnetapp
801 * interface which is parsed and submitted with the above functions.
803 /* Data corresponding to <WAFL /> */
804 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
807 cfg_wafl_t perf_data;
808 const char *plugin_inst;
810 na_elem_t *instances;
812 na_elem_iter_t counter_iter;
814 memset (&perf_data, 0, sizeof (perf_data));
816 perf_data.timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
818 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
819 if (instances == NULL)
821 ERROR ("netapp plugin: cna_handle_wafl_data: "
822 "na_elem_child (\"instances\") failed.");
826 plugin_inst = na_child_get_string(instances, "name");
827 if (plugin_inst == NULL)
829 ERROR ("netapp plugin: cna_handle_wafl_data: "
830 "na_child_get_string (\"name\") failed.");
834 /* Iterate over all counters */
835 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
836 for (counter = na_iterator_next (&counter_iter);
838 counter = na_iterator_next (&counter_iter))
843 name = na_child_get_string(counter, "name");
847 value = na_child_get_uint64(counter, "value", UINT64_MAX);
848 if (value == UINT64_MAX)
851 if (!strcmp(name, "name_cache_hit")) {
852 perf_data.name_cache_hit = value;
853 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
854 } else if (!strcmp(name, "name_cache_miss")) {
855 perf_data.name_cache_miss = value;
856 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
857 } else if (!strcmp(name, "find_dir_hit")) {
858 perf_data.find_dir_hit = value;
859 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
860 } else if (!strcmp(name, "find_dir_miss")) {
861 perf_data.find_dir_miss = value;
862 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
863 } else if (!strcmp(name, "buf_hash_hit")) {
864 perf_data.buf_hash_hit = value;
865 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
866 } else if (!strcmp(name, "buf_hash_miss")) {
867 perf_data.buf_hash_miss = value;
868 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
869 } else if (!strcmp(name, "inode_cache_hit")) {
870 perf_data.inode_cache_hit = value;
871 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
872 } else if (!strcmp(name, "inode_cache_miss")) {
873 perf_data.inode_cache_miss = value;
874 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
876 DEBUG("netapp plugin: cna_handle_wafl_data: "
877 "Found unexpected child: %s", name);
881 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data));
882 } /* }}} void cna_handle_wafl_data */
884 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
891 if (cw->query != NULL)
894 cw->query = na_elem_new("perf-object-get-instances");
895 if (cw->query == NULL)
897 ERROR ("netapp plugin: na_elem_new failed.");
900 na_child_add_string (cw->query, "objectname", "wafl");
902 e = na_elem_new("counters");
905 na_elem_free (cw->query);
907 ERROR ("netapp plugin: na_elem_new failed.");
910 na_child_add_string(e, "foo", "name_cache_hit");
911 na_child_add_string(e, "foo", "name_cache_miss");
912 na_child_add_string(e, "foo", "find_dir_hit");
913 na_child_add_string(e, "foo", "find_dir_miss");
914 na_child_add_string(e, "foo", "buf_hash_hit");
915 na_child_add_string(e, "foo", "buf_hash_miss");
916 na_child_add_string(e, "foo", "inode_cache_hit");
917 na_child_add_string(e, "foo", "inode_cache_miss");
919 na_child_add(cw->query, e);
922 } /* }}} int cna_setup_wafl */
924 static int cna_query_wafl (host_config_t *host) /* {{{ */
933 /* If WAFL was not configured, return without doing anything. */
934 if (host->cfg_wafl == NULL)
938 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
941 status = cna_setup_wafl (host->cfg_wafl);
944 assert (host->cfg_wafl->query != NULL);
946 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
947 if (na_results_status (data) != NA_OK)
949 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed: %s",
950 na_results_reason (data));
955 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data);
958 host->cfg_wafl->interval.last_read = now;
962 } /* }}} int cna_query_wafl */
964 /* Data corresponding to <Disks /> */
965 static int cna_handle_disk_data (const char *hostname, /* {{{ */
966 cfg_disk_t *cfg_disk, na_elem_t *data)
969 na_elem_t *instances;
971 na_elem_iter_t instance_iter;
972 disk_t *worst_disk = NULL;
974 if ((cfg_disk == NULL) || (data == NULL))
977 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
979 instances = na_elem_child (data, "instances");
980 if (instances == NULL)
982 ERROR ("netapp plugin: cna_handle_disk_data: "
983 "na_elem_child (\"instances\") failed.");
987 /* Iterate over all children */
988 instance_iter = na_child_iterator (instances);
989 for (instance = na_iterator_next (&instance_iter);
991 instance = na_iterator_next(&instance_iter))
996 na_elem_iter_t counter_iterator;
999 memset (&new_data, 0, sizeof (new_data));
1000 new_data.timestamp = timestamp;
1001 new_data.disk_busy_percent = NAN;
1003 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1004 if (old_data == NULL)
1007 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1008 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1009 for (counter = na_iterator_next(&counter_iterator);
1011 counter = na_iterator_next(&counter_iterator))
1016 name = na_child_get_string(counter, "name");
1020 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1021 if (value == UINT64_MAX)
1024 if (strcmp(name, "disk_busy") == 0)
1026 new_data.disk_busy = value;
1027 new_data.flags |= HAVE_DISK_BUSY;
1029 else if (strcmp(name, "base_for_disk_busy") == 0)
1031 new_data.base_for_disk_busy = value;
1032 new_data.flags |= HAVE_DISK_BASE;
1036 DEBUG ("netapp plugin: cna_handle_disk_data: "
1037 "Counter not handled: %s = %"PRIu64,
1042 /* If all required counters are available and did not just wrap around,
1043 * calculate the busy percentage. Otherwise, the value is initialized to
1044 * NAN at the top of the for-loop. */
1045 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1046 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1047 && (new_data.disk_busy >= old_data->disk_busy)
1048 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1053 busy_diff = new_data.disk_busy - old_data->disk_busy;
1054 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1056 new_data.disk_busy_percent = 100.0
1057 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1060 /* Clear HAVE_* flags */
1061 old_data->flags &= ~HAVE_DISK_ALL;
1064 old_data->timestamp = new_data.timestamp;
1065 old_data->disk_busy = new_data.disk_busy;
1066 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1067 old_data->disk_busy_percent = new_data.disk_busy_percent;
1070 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1072 if ((worst_disk == NULL)
1073 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1074 worst_disk = old_data;
1075 } /* for (all disks) */
1077 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1078 submit_double (hostname, "system", "percent", "disk_busy",
1079 worst_disk->disk_busy_percent, timestamp);
1082 } /* }}} int cna_handle_disk_data */
1084 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1091 if (cd->query != NULL)
1094 cd->query = na_elem_new ("perf-object-get-instances");
1095 if (cd->query == NULL)
1097 ERROR ("netapp plugin: na_elem_new failed.");
1100 na_child_add_string (cd->query, "objectname", "disk");
1102 e = na_elem_new("counters");
1105 na_elem_free (cd->query);
1107 ERROR ("netapp plugin: na_elem_new failed.");
1110 na_child_add_string(e, "foo", "disk_busy");
1111 na_child_add_string(e, "foo", "base_for_disk_busy");
1112 na_child_add(cd->query, e);
1115 } /* }}} int cna_setup_disk */
1117 static int cna_query_disk (host_config_t *host) /* {{{ */
1126 /* If the user did not configure disk statistics, return without doing
1128 if (host->cfg_disk == NULL)
1132 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1135 status = cna_setup_disk (host->cfg_disk);
1138 assert (host->cfg_disk->query != NULL);
1140 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1141 if (na_results_status (data) != NA_OK)
1143 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed: %s",
1144 na_results_reason (data));
1145 na_elem_free (data);
1149 status = cna_handle_disk_data (host->name, host->cfg_disk, data);
1152 host->cfg_disk->interval.last_read = now;
1154 na_elem_free (data);
1156 } /* }}} int cna_query_disk */
1158 /* Data corresponding to <VolumePerf /> */
1159 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1160 cfg_volume_perf_t *cvp, na_elem_t *data)
1163 na_elem_t *elem_instances;
1164 na_elem_iter_t iter_instances;
1165 na_elem_t *elem_instance;
1167 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
1169 elem_instances = na_elem_child(data, "instances");
1170 if (elem_instances == NULL)
1172 ERROR ("netapp plugin: handle_volume_perf_data: "
1173 "na_elem_child (\"instances\") failed.");
1177 iter_instances = na_child_iterator (elem_instances);
1178 for (elem_instance = na_iterator_next(&iter_instances);
1179 elem_instance != NULL;
1180 elem_instance = na_iterator_next(&iter_instances))
1184 data_volume_perf_t perf_data;
1185 data_volume_perf_t *v;
1187 na_elem_t *elem_counters;
1188 na_elem_iter_t iter_counters;
1189 na_elem_t *elem_counter;
1191 memset (&perf_data, 0, sizeof (perf_data));
1192 perf_data.timestamp = timestamp;
1194 name = na_child_get_string (elem_instance, "name");
1198 /* get_volume_perf may return NULL if this volume is to be ignored. */
1199 v = get_volume_perf (cvp, perf_data.name);
1203 elem_counters = na_elem_child (elem_instance, "counters");
1204 if (elem_counters == NULL)
1207 iter_counters = na_child_iterator (elem_counters);
1208 for (elem_counter = na_iterator_next(&iter_counters);
1209 elem_counter != NULL;
1210 elem_counter = na_iterator_next(&iter_counters))
1215 name = na_child_get_string (elem_counter, "name");
1219 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1220 if (value == UINT64_MAX)
1223 if (!strcmp(name, "read_data")) {
1224 perf_data.read_bytes = value;
1225 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1226 } else if (!strcmp(name, "write_data")) {
1227 perf_data.write_bytes = value;
1228 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1229 } else if (!strcmp(name, "read_ops")) {
1230 perf_data.read_ops = value;
1231 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1232 } else if (!strcmp(name, "write_ops")) {
1233 perf_data.write_ops = value;
1234 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1235 } else if (!strcmp(name, "read_latency")) {
1236 perf_data.read_latency = value;
1237 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1238 } else if (!strcmp(name, "write_latency")) {
1239 perf_data.write_latency = value;
1240 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1242 } /* for (elem_counter) */
1244 submit_volume_perf_data (hostname, v, &perf_data);
1245 } /* for (volume) */
1248 } /* }}} int cna_handle_volume_perf_data */
1250 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1257 if (cd->query != NULL)
1260 cd->query = na_elem_new ("perf-object-get-instances");
1261 if (cd->query == NULL)
1263 ERROR ("netapp plugin: na_elem_new failed.");
1266 na_child_add_string (cd->query, "objectname", "volume");
1268 e = na_elem_new("counters");
1271 na_elem_free (cd->query);
1273 ERROR ("netapp plugin: na_elem_new failed.");
1276 /* "foo" means: This string has to be here but the content doesn't matter. */
1277 na_child_add_string(e, "foo", "read_ops");
1278 na_child_add_string(e, "foo", "write_ops");
1279 na_child_add_string(e, "foo", "read_data");
1280 na_child_add_string(e, "foo", "write_data");
1281 na_child_add_string(e, "foo", "read_latency");
1282 na_child_add_string(e, "foo", "write_latency");
1283 na_child_add(cd->query, e);
1286 } /* }}} int cna_setup_volume_perf */
1288 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1297 /* If the user did not configure volume performance statistics, return
1298 * without doing anything. */
1299 if (host->cfg_volume_perf == NULL)
1303 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1306 status = cna_setup_volume_perf (host->cfg_volume_perf);
1309 assert (host->cfg_volume_perf->query != NULL);
1311 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1312 if (na_results_status (data) != NA_OK)
1314 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed: %s",
1315 na_results_reason (data));
1316 na_elem_free (data);
1320 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data);
1323 host->cfg_volume_perf->interval.last_read = now;
1325 na_elem_free (data);
1327 } /* }}} int cna_query_volume_perf */
1329 /* Data corresponding to <VolumeUsage /> */
1330 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1331 cfg_volume_usage_t *cfg_volume)
1333 data_volume_usage_t *v;
1335 for (v = cfg_volume->volumes; v != NULL; v = v->next)
1337 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1338 submit_double (hostname, /* plugin instance = */ v->name,
1339 "df_complex", "free",
1340 (double) v->norm_free, /* timestamp = */ 0);
1342 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1343 submit_double (hostname, /* plugin instance = */ v->name,
1344 "df_complex", "used",
1345 (double) v->norm_used, /* timestamp = */ 0);
1347 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1348 submit_double (hostname, /* plugin instance = */ v->name,
1349 "df_complex", "snap_reserved",
1350 (double) v->snap_reserved, /* timestamp = */ 0);
1352 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1353 submit_double (hostname, /* plugin instance = */ v->name,
1354 "df_complex", "snap_used",
1355 (double) v->snap_used, /* timestamp = */ 0);
1357 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1358 submit_double (hostname, /* plugin instance = */ v->name,
1359 "df_complex", "sis_saved",
1360 (double) v->sis_saved, /* timestamp = */ 0);
1362 /* Clear all the HAVE_* flags */
1363 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1364 } /* for (v = cfg_volume->volumes) */
1367 } /* }}} int cna_submit_volume_usage_data */
1369 static int cna_handle_volume_usage_data (const char *hostname, /* {{{ */
1370 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1372 na_elem_t *elem_volume;
1373 na_elem_t *elem_volumes;
1374 na_elem_iter_t iter_volume;
1376 elem_volumes = na_elem_child (data, "volumes");
1377 if (elem_volumes == NULL)
1379 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1380 "na_elem_child (\"volumes\") failed.");
1384 iter_volume = na_child_iterator (elem_volumes);
1385 for (elem_volume = na_iterator_next (&iter_volume);
1386 elem_volume != NULL;
1387 elem_volume = na_iterator_next (&iter_volume))
1389 const char *volume_name;
1391 data_volume_usage_t *v;
1395 const char *sis_state;
1396 uint64_t sis_saved_reported;
1398 volume_name = na_child_get_string (elem_volume, "name");
1399 if (volume_name == NULL)
1402 /* get_volume_usage may return NULL if the volume is to be ignored. */
1403 v = get_volume_usage (cfg_volume, volume_name);
1407 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1410 /* 2^4 exa-bytes? This will take a while ;) */
1411 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1412 if (value != UINT64_MAX) {
1413 v->norm_free = value;
1414 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1417 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1418 if (value != UINT64_MAX) {
1419 v->norm_used = value;
1420 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1423 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1424 if (value != UINT64_MAX) {
1425 /* 1 block == 1024 bytes as per API docs */
1426 v->norm_used = 1024 * value;
1427 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1430 sis = na_elem_child(elem_volume, "sis");
1434 sis_state = na_child_get_string(sis, "state");
1435 if (sis_state == NULL)
1438 /* If SIS is not enabled, set the HAVE_VOLUME_USAGE_SIS_SAVED flag and set
1439 * sis_saved to UINT64_MAX to signal this condition to the submit function. */
1440 if (strcmp ("enabled", sis_state) != 0) {
1441 v->sis_saved = UINT64_MAX;
1442 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1446 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1447 if (sis_saved_reported == UINT64_MAX)
1450 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1451 if ((sis_saved_reported >> 32) != 0) {
1452 /* In case they ever fix this bug. */
1453 v->sis_saved = sis_saved_reported;
1454 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1455 } else { /* really hacky work-around code. {{{ */
1456 uint64_t sis_saved_percent;
1457 uint64_t sis_saved_guess;
1458 uint64_t overflow_guess;
1459 uint64_t guess1, guess2, guess3;
1461 /* Check if we have v->norm_used. Without it, we cannot calculate
1462 * sis_saved_guess. */
1463 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1466 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1467 if (sis_saved_percent > 100)
1470 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1471 * will hopefully be fixed in later versions. To work around the bug, try
1472 * to figure out how often the 32bit integer wrapped around by using the
1473 * "percentage-saved" value. Because the percentage is in the range
1474 * [0-100], this should work as long as the saved space does not exceed
1476 /* percentage-saved = size-saved / (size-saved + size-used) */
1477 if (sis_saved_percent < 100)
1478 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1480 sis_saved_guess = v->norm_used;
1482 overflow_guess = sis_saved_guess >> 32;
1483 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1484 guess2 = (overflow_guess << 32) + sis_saved_reported;
1485 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1487 if (sis_saved_guess < guess2) {
1488 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1489 v->sis_saved = guess1;
1491 v->sis_saved = guess2;
1493 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1494 v->sis_saved = guess2;
1496 v->sis_saved = guess3;
1498 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1499 } /* }}} end of 32-bit workaround */
1500 } /* for (elem_volume) */
1502 return (cna_submit_volume_usage_data (hostname, cfg_volume));
1503 } /* }}} int cna_handle_volume_usage_data */
1505 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1510 if (cvu->query != NULL)
1513 cvu->query = na_elem_new ("volume-list-info");
1514 if (cvu->query == NULL)
1516 ERROR ("netapp plugin: na_elem_new failed.");
1520 /* TODO: cvu->snap_query = na_elem_new("snapshot-list-info"); */
1523 } /* }}} int cna_setup_volume_usage */
1525 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1534 /* If the user did not configure volume_usage statistics, return without
1535 * doing anything. */
1536 if (host->cfg_volume_usage == NULL)
1540 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1543 status = cna_setup_volume_usage (host->cfg_volume_usage);
1546 assert (host->cfg_volume_usage->query != NULL);
1548 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1549 if (na_results_status (data) != NA_OK)
1551 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed: %s",
1552 na_results_reason (data));
1553 na_elem_free (data);
1557 status = cna_handle_volume_usage_data (host->name, host->cfg_volume_usage, data);
1560 host->cfg_volume_usage->interval.last_read = now;
1562 na_elem_free (data);
1564 } /* }}} int cna_query_volume_usage */
1566 /* Data corresponding to <System /> */
1567 static int cna_handle_system_data (const char *hostname, /* {{{ */
1568 cfg_system_t *cfg_system, na_elem_t *data)
1570 na_elem_t *instances;
1572 na_elem_iter_t counter_iter;
1574 counter_t disk_read = 0, disk_written = 0;
1575 counter_t net_recv = 0, net_sent = 0;
1576 counter_t cpu_busy = 0, cpu_total = 0;
1577 uint32_t counter_flags = 0;
1579 const char *instance;
1582 timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
1584 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1585 if (instances == NULL)
1587 ERROR ("netapp plugin: cna_handle_system_data: "
1588 "na_elem_child (\"instances\") failed.");
1592 instance = na_child_get_string (instances, "name");
1593 if (instance == NULL)
1595 ERROR ("netapp plugin: cna_handle_system_data: "
1596 "na_child_get_string (\"name\") failed.");
1600 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
1601 for (counter = na_iterator_next (&counter_iter);
1603 counter = na_iterator_next (&counter_iter))
1608 name = na_child_get_string(counter, "name");
1612 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1613 if (value == UINT64_MAX)
1616 if (!strcmp(name, "disk_data_read")) {
1617 disk_read = (counter_t) (value * 1024);
1618 counter_flags |= 0x01;
1619 } else if (!strcmp(name, "disk_data_written")) {
1620 disk_written = (counter_t) (value * 1024);
1621 counter_flags |= 0x02;
1622 } else if (!strcmp(name, "net_data_recv")) {
1623 net_recv = (counter_t) (value * 1024);
1624 counter_flags |= 0x04;
1625 } else if (!strcmp(name, "net_data_sent")) {
1626 net_sent = (counter_t) (value * 1024);
1627 counter_flags |= 0x08;
1628 } else if (!strcmp(name, "cpu_busy")) {
1629 cpu_busy = (counter_t) value;
1630 counter_flags |= 0x10;
1631 } else if (!strcmp(name, "cpu_elapsed_time")) {
1632 cpu_total = (counter_t) value;
1633 counter_flags |= 0x20;
1634 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1635 && (value > 0) && (strlen(name) > 4)
1636 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1637 submit_counter (hostname, instance, "disk_ops_complex", name,
1638 (counter_t) value, timestamp);
1640 } /* for (counter) */
1642 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1643 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
1644 submit_two_counters (hostname, instance, "disk_octets", NULL,
1645 disk_read, disk_written, timestamp);
1647 if ((cfg_system->flags & CFG_SYSTEM_NET)
1648 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
1649 submit_two_counters (hostname, instance, "if_octets", NULL,
1650 net_recv, net_sent, timestamp);
1652 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1653 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
1655 submit_counter (hostname, instance, "cpu", "system",
1656 cpu_busy, timestamp);
1657 submit_counter (hostname, instance, "cpu", "idle",
1658 cpu_total - cpu_busy, timestamp);
1662 } /* }}} int cna_handle_system_data */
1664 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
1669 if (cs->query != NULL)
1672 cs->query = na_elem_new ("perf-object-get-instances");
1673 if (cs->query == NULL)
1675 ERROR ("netapp plugin: na_elem_new failed.");
1678 na_child_add_string (cs->query, "objectname", "system");
1681 } /* }}} int cna_setup_system */
1683 static int cna_query_system (host_config_t *host) /* {{{ */
1692 /* If system statistics were not configured, return without doing anything. */
1693 if (host->cfg_system == NULL)
1697 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
1700 status = cna_setup_system (host->cfg_system);
1703 assert (host->cfg_system->query != NULL);
1705 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
1706 if (na_results_status (data) != NA_OK)
1708 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed: %s",
1709 na_results_reason (data));
1710 na_elem_free (data);
1714 status = cna_handle_system_data (host->name, host->cfg_system, data);
1717 host->cfg_system->interval.last_read = now;
1719 na_elem_free (data);
1721 } /* }}} int cna_query_system */
1724 * Configuration handling
1726 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1727 * is false. On error, the flag-field is not changed. */
1728 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1729 uint32_t *flags, uint32_t flag)
1731 if ((ci == NULL) || (flags == NULL))
1734 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1736 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1741 if (ci->values[0].value.boolean)
1747 } /* }}} int cna_config_bool_to_flag */
1749 /* Handling of the "Interval" option which is allowed in every block. */
1750 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1751 cna_interval_t *out_interval)
1755 if ((ci == NULL) || (out_interval == NULL))
1758 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1760 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1764 tmp = (time_t) (ci->values[0].value.number + .5);
1767 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1771 out_interval->interval = tmp;
1772 out_interval->last_read = 0;
1775 } /* }}} int cna_config_get_interval */
1777 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1778 * <VolumePerf /> block. */
1779 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
1780 const oconfig_item_t *ci)
1785 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1787 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1792 name = ci->values[0].value.string;
1794 if (strcasecmp ("GetIO", ci->key) == 0)
1795 il = cvp->il_octets;
1796 else if (strcasecmp ("GetOps", ci->key) == 0)
1797 il = cvp->il_operations;
1798 else if (strcasecmp ("GetLatency", ci->key) == 0)
1799 il = cvp->il_latency;
1803 ignorelist_add (il, name);
1804 } /* }}} void cna_config_volume_perf_option */
1806 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
1807 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
1808 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
1809 const oconfig_item_t *ci)
1813 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1815 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1820 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
1821 il = cvp->il_octets;
1822 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
1823 il = cvp->il_operations;
1824 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
1825 il = cvp->il_latency;
1829 if (ci->values[0].value.boolean)
1830 ignorelist_set_invert (il, /* invert = */ 0);
1832 ignorelist_set_invert (il, /* invert = */ 1);
1833 } /* }}} void cna_config_volume_perf_default */
1835 /* Corresponds to a <Disks /> block */
1840 * IgnoreSelectedIO false
1844 * IgnoreSelectedOps false
1848 * IgnoreSelectedLatency false
1851 /* Corresponds to a <VolumePerf /> block */
1852 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
1853 const oconfig_item_t *ci)
1855 cfg_volume_perf_t *cfg_volume_perf;
1858 if ((host == NULL) || (ci == NULL))
1861 if (host->cfg_volume_perf == NULL)
1863 cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
1864 if (cfg_volume_perf == NULL)
1866 memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
1868 /* Set default flags */
1869 cfg_volume_perf->query = NULL;
1870 cfg_volume_perf->volumes = NULL;
1872 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
1873 if (cfg_volume_perf->il_octets == NULL)
1875 sfree (cfg_volume_perf);
1879 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
1880 if (cfg_volume_perf->il_operations == NULL)
1882 ignorelist_free (cfg_volume_perf->il_octets);
1883 sfree (cfg_volume_perf);
1887 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
1888 if (cfg_volume_perf->il_latency == NULL)
1890 ignorelist_free (cfg_volume_perf->il_octets);
1891 ignorelist_free (cfg_volume_perf->il_operations);
1892 sfree (cfg_volume_perf);
1896 host->cfg_volume_perf = cfg_volume_perf;
1898 cfg_volume_perf = host->cfg_volume_perf;
1900 for (i = 0; i < ci->children_num; ++i) {
1901 oconfig_item_t *item = ci->children + i;
1903 /* if (!item || !item->key || !*item->key) continue; */
1904 if (strcasecmp(item->key, "Interval") == 0)
1905 cna_config_get_interval (item, &cfg_volume_perf->interval);
1906 else if (!strcasecmp(item->key, "GetIO"))
1907 cna_config_volume_perf_option (cfg_volume_perf, item);
1908 else if (!strcasecmp(item->key, "GetOps"))
1909 cna_config_volume_perf_option (cfg_volume_perf, item);
1910 else if (!strcasecmp(item->key, "GetLatency"))
1911 cna_config_volume_perf_option (cfg_volume_perf, item);
1912 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
1913 cna_config_volume_perf_default (cfg_volume_perf, item);
1914 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
1915 cna_config_volume_perf_default (cfg_volume_perf, item);
1916 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
1917 cna_config_volume_perf_default (cfg_volume_perf, item);
1919 WARNING ("netapp plugin: The option %s is not allowed within "
1920 "`VolumePerf' blocks.", item->key);
1924 } /* }}} int cna_config_volume_performance */
1926 /* Handling of the "Capacity" and "Snapshot" options within a <VolumeUsage />
1928 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
1929 const oconfig_item_t *ci)
1934 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1936 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1941 name = ci->values[0].value.string;
1943 if (strcasecmp ("Capacity", ci->key) == 0)
1944 il = cvu->il_capacity;
1945 else if (strcasecmp ("Snapshot", ci->key) == 0)
1946 il = cvu->il_snapshot;
1950 ignorelist_add (il, name);
1951 } /* }}} void cna_config_volume_usage_option */
1953 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
1954 * options within a <VolumeUsage /> block. */
1955 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
1956 const oconfig_item_t *ci)
1960 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1962 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1967 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
1968 il = cvu->il_capacity;
1969 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
1970 il = cvu->il_snapshot;
1974 if (ci->values[0].value.boolean)
1975 ignorelist_set_invert (il, /* invert = */ 0);
1977 ignorelist_set_invert (il, /* invert = */ 1);
1978 } /* }}} void cna_config_volume_usage_default */
1980 /* Corresponds to a <Disks /> block */
1981 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1982 cfg_disk_t *cfg_disk;
1985 if ((host == NULL) || (ci == NULL))
1988 if (host->cfg_disk == NULL)
1990 cfg_disk = malloc (sizeof (*cfg_disk));
1991 if (cfg_disk == NULL)
1993 memset (cfg_disk, 0, sizeof (*cfg_disk));
1995 /* Set default flags */
1996 cfg_disk->flags = CFG_DISK_ALL;
1997 cfg_disk->query = NULL;
1998 cfg_disk->disks = NULL;
2000 host->cfg_disk = cfg_disk;
2002 cfg_disk = host->cfg_disk;
2004 for (i = 0; i < ci->children_num; ++i) {
2005 oconfig_item_t *item = ci->children + i;
2007 /* if (!item || !item->key || !*item->key) continue; */
2008 if (strcasecmp(item->key, "Interval") == 0)
2009 cna_config_get_interval (item, &cfg_disk->interval);
2010 else if (strcasecmp(item->key, "GetBusy") == 0)
2011 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2014 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2016 NOTICE ("netapp plugin: All disk related values have been disabled. "
2017 "Collection of per-disk data will be disabled entirely.");
2018 free_cfg_disk (host->cfg_disk);
2019 host->cfg_disk = NULL;
2023 } /* }}} int cna_config_disk */
2025 /* Corresponds to a <WAFL /> block */
2026 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2028 cfg_wafl_t *cfg_wafl;
2031 if ((host == NULL) || (ci == NULL))
2034 if (host->cfg_wafl == NULL)
2036 cfg_wafl = malloc (sizeof (*cfg_wafl));
2037 if (cfg_wafl == NULL)
2039 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
2041 /* Set default flags */
2042 cfg_wafl->flags = CFG_WAFL_ALL;
2044 host->cfg_wafl = cfg_wafl;
2046 cfg_wafl = host->cfg_wafl;
2048 for (i = 0; i < ci->children_num; ++i) {
2049 oconfig_item_t *item = ci->children + i;
2051 if (strcasecmp(item->key, "Interval") == 0)
2052 cna_config_get_interval (item, &cfg_wafl->interval);
2053 else if (!strcasecmp(item->key, "GetNameCache"))
2054 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2055 else if (!strcasecmp(item->key, "GetDirCache"))
2056 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2057 else if (!strcasecmp(item->key, "GetBufferCache"))
2058 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2059 else if (!strcasecmp(item->key, "GetInodeCache"))
2060 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2062 WARNING ("netapp plugin: The %s config option is not allowed within "
2063 "`WAFL' blocks.", item->key);
2066 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2068 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2069 "Collection of WAFL data will be disabled entirely.");
2070 free_cfg_wafl (host->cfg_wafl);
2071 host->cfg_wafl = NULL;
2075 } /* }}} int cna_config_wafl */
2084 * IgnoreSelectedCapacity false
2090 * IgnoreSelectedSnapshot false
2093 /* Corresponds to a <VolumeUsage /> block */
2094 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2095 const oconfig_item_t *ci)
2097 cfg_volume_usage_t *cfg_volume_usage;
2100 if ((host == NULL) || (ci == NULL))
2103 if (host->cfg_volume_usage == NULL)
2105 cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
2106 if (cfg_volume_usage == NULL)
2108 memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
2110 /* Set default flags */
2111 cfg_volume_usage->query = NULL;
2112 cfg_volume_usage->volumes = NULL;
2114 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2115 if (cfg_volume_usage->il_capacity == NULL)
2117 sfree (cfg_volume_usage);
2121 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2122 if (cfg_volume_usage->il_snapshot == NULL)
2124 ignorelist_free (cfg_volume_usage->il_capacity);
2125 sfree (cfg_volume_usage);
2129 host->cfg_volume_usage = cfg_volume_usage;
2131 cfg_volume_usage = host->cfg_volume_usage;
2133 for (i = 0; i < ci->children_num; ++i) {
2134 oconfig_item_t *item = ci->children + i;
2136 /* if (!item || !item->key || !*item->key) continue; */
2137 if (strcasecmp(item->key, "Interval") == 0)
2138 cna_config_get_interval (item, &cfg_volume_usage->interval);
2139 else if (!strcasecmp(item->key, "Capacity"))
2140 cna_config_volume_usage_option (cfg_volume_usage, item);
2141 else if (!strcasecmp(item->key, "Snapshot"))
2142 cna_config_volume_usage_option (cfg_volume_usage, item);
2143 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2144 cna_config_volume_usage_default (cfg_volume_usage, item);
2145 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2146 cna_config_volume_usage_default (cfg_volume_usage, item);
2148 WARNING ("netapp plugin: The option %s is not allowed within "
2149 "`VolumeUsage' blocks.", item->key);
2153 } /* }}} int cna_config_volume_usage */
2155 /* Corresponds to a <System /> block */
2156 static int cna_config_system (host_config_t *host, /* {{{ */
2159 cfg_system_t *cfg_system;
2162 if ((host == NULL) || (ci == NULL))
2165 if (host->cfg_system == NULL)
2167 cfg_system = malloc (sizeof (*cfg_system));
2168 if (cfg_system == NULL)
2170 memset (cfg_system, 0, sizeof (*cfg_system));
2172 /* Set default flags */
2173 cfg_system->flags = CFG_SYSTEM_ALL;
2174 cfg_system->query = NULL;
2176 host->cfg_system = cfg_system;
2178 cfg_system = host->cfg_system;
2180 for (i = 0; i < ci->children_num; ++i) {
2181 oconfig_item_t *item = ci->children + i;
2183 if (strcasecmp(item->key, "Interval") == 0) {
2184 cna_config_get_interval (item, &cfg_system->interval);
2185 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2186 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2187 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2188 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2189 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2190 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2191 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2192 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2194 WARNING ("netapp plugin: The %s config option is not allowed within "
2195 "`System' blocks.", item->key);
2199 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2201 NOTICE ("netapp plugin: All system related values have been disabled. "
2202 "Collection of system data will be disabled entirely.");
2203 free_cfg_system (host->cfg_system);
2204 host->cfg_system = NULL;
2208 } /* }}} int cna_config_system */
2210 /* Corresponds to a <Host /> block. */
2211 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
2212 const host_config_t *default_host)
2214 oconfig_item_t *item;
2215 host_config_t *host;
2219 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2220 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
2224 host = malloc(sizeof(*host));
2225 memcpy (host, default_host, sizeof (*host));
2227 status = cf_util_get_string (ci, &host->name);
2234 for (i = 0; i < ci->children_num; ++i) {
2235 item = ci->children + i;
2239 if (!strcasecmp(item->key, "Address")) {
2240 status = cf_util_get_string (item, &host->host);
2241 } else if (!strcasecmp(item->key, "Port")) {
2244 tmp = cf_util_get_port_number (item);
2247 } else if (!strcasecmp(item->key, "Protocol")) {
2248 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"))) {
2249 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2252 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2253 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2254 } else if (!strcasecmp(item->key, "User")) {
2255 status = cf_util_get_string (item, &host->username);
2256 } else if (!strcasecmp(item->key, "Password")) {
2257 status = cf_util_get_string (item, &host->password);
2258 } else if (!strcasecmp(item->key, "Interval")) {
2259 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) {
2260 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
2263 host->interval = item->values[0].value.number;
2264 } else if (!strcasecmp(item->key, "WAFL")) {
2265 cna_config_wafl(host, item);
2266 } else if (!strcasecmp(item->key, "Disks")) {
2267 cna_config_disk(host, item);
2268 } else if (!strcasecmp(item->key, "VolumePerf")) {
2269 cna_config_volume_performance(host, item);
2270 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2271 cna_config_volume_usage(host, item);
2272 } else if (!strcasecmp(item->key, "System")) {
2273 cna_config_system(host, item);
2275 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
2276 item->key, ci->values[0].value.string);
2283 if (host->host == NULL)
2284 host->host = strdup (host->name);
2286 if (host->host == NULL)
2289 if (host->port <= 0)
2290 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2292 if ((host->username == NULL) || (host->password == NULL)) {
2293 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2294 "Ignoring host block.", host->name);
2300 free_host_config (host);
2305 } /* }}} host_config_t *cna_config_host */
2308 * Callbacks registered with the daemon
2310 * Pretty standard stuff here.
2312 static int cna_init(void) { /* {{{ */
2314 host_config_t *host;
2316 if (!global_host_config) {
2317 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
2321 memset (err, 0, sizeof (err));
2322 if (!na_startup(err, sizeof(err))) {
2323 err[sizeof (err) - 1] = 0;
2324 ERROR("netapp plugin: Error initializing netapp API: %s", err);
2328 for (host = global_host_config; host; host = host->next) {
2329 /* Request version 1.1 of the ONTAP API */
2330 host->srv = na_server_open(host->host,
2331 /* major version = */ 1, /* minor version = */ 1);
2332 if (host->srv == NULL) {
2333 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
2337 if (host->interval < interval_g)
2338 host->interval = interval_g;
2340 na_server_set_transport_type(host->srv, host->protocol,
2341 /* transportarg = */ NULL);
2342 na_server_set_port(host->srv, host->port);
2343 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
2344 na_server_adminuser(host->srv, host->username, host->password);
2345 na_server_set_timeout(host->srv, 5 /* seconds */);
2348 } /* }}} int cna_init */
2350 static int cna_config (oconfig_item_t *ci) { /* {{{ */
2352 oconfig_item_t *item;
2353 host_config_t default_host = HOST_INIT;
2355 for (i = 0; i < ci->children_num; ++i) {
2356 item = ci->children + i;
2358 if (!strcasecmp(item->key, "Host")) {
2359 host_config_t *host;
2362 host = cna_config_host(item, &default_host);
2366 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
2368 if (strcasecmp (host->name, tmp->name) == 0)
2369 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
2370 "This is probably a bad idea.",
2373 if (tmp->next == NULL)
2379 global_host_config = host;
2383 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
2387 } /* }}} int cna_config */
2389 static int cna_read (void) { /* {{{ */
2390 host_config_t *host;
2392 for (host = global_host_config; host; host = host->next) {
2393 cna_query_wafl (host);
2394 cna_query_disk (host);
2395 cna_query_volume_perf (host);
2396 cna_query_volume_usage (host);
2397 cna_query_system (host);
2400 } /* }}} int cna_read */
2402 void module_register(void) {
2403 plugin_register_complex_config("netapp", cna_config);
2404 plugin_register_init("netapp", cna_init);
2405 plugin_register_read("netapp", cna_read);
2408 /* vim: set sw=2 ts=2 noet fdm=marker : */