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);
390 na_server_close (hc->srv);
392 free_host_config (next);
393 } /* }}} void free_host_config */
396 * Auxiliary functions
398 * Used to look up volumes and disks or to handle flags.
400 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
404 if ((cd == NULL) || (name == NULL))
407 for (d = cd->disks; d != NULL; d = d->next) {
408 if (strcmp(d->name, name) == 0)
412 d = malloc(sizeof(*d));
415 memset (d, 0, sizeof (*d));
418 d->name = strdup(name);
419 if (d->name == NULL) {
428 } /* }}} disk_t *get_disk */
430 static data_volume_usage_t *get_volume_usage (cfg_volume_usage_t *cvu, /* {{{ */
433 data_volume_usage_t *last;
434 data_volume_usage_t *new;
436 int ignore_capacity = 0;
437 int ignore_snapshot = 0;
439 if ((cvu == NULL) || (name == NULL))
445 if (strcmp (last->name, name) == 0)
448 if (last->next == NULL)
454 /* Check the ignorelists. If *both* tell us to ignore a volume, return NULL. */
455 ignore_capacity = ignorelist_match (cvu->il_capacity, name);
456 ignore_snapshot = ignorelist_match (cvu->il_snapshot, name);
457 if ((ignore_capacity != 0) && (ignore_snapshot != 0))
460 /* Not found: allocate. */
461 new = malloc (sizeof (*new));
464 memset (new, 0, sizeof (*new));
467 new->name = strdup (name);
468 if (new->name == NULL)
474 if (ignore_capacity == 0)
475 new->flags |= CFG_VOLUME_USAGE_DF;
476 if (ignore_snapshot == 0)
477 new->flags |= CFG_VOLUME_USAGE_SNAP;
479 /* Add to end of list. */
486 } /* }}} data_volume_usage_t *get_volume_usage */
488 static data_volume_perf_t *get_volume_perf (cfg_volume_perf_t *cvp, /* {{{ */
491 data_volume_perf_t *last;
492 data_volume_perf_t *new;
494 int ignore_octets = 0;
495 int ignore_operations = 0;
496 int ignore_latency = 0;
498 if ((cvp == NULL) || (name == NULL))
504 if (strcmp (last->name, name) == 0)
507 if (last->next == NULL)
513 /* Check the ignorelists. If *all three* tell us to ignore a volume, return
515 ignore_octets = ignorelist_match (cvp->il_octets, name);
516 ignore_operations = ignorelist_match (cvp->il_operations, name);
517 ignore_latency = ignorelist_match (cvp->il_latency, name);
518 if ((ignore_octets != 0) || (ignore_operations != 0)
519 || (ignore_latency != 0))
522 /* Not found: allocate. */
523 new = malloc (sizeof (*new));
526 memset (new, 0, sizeof (*new));
529 new->name = strdup (name);
530 if (new->name == NULL)
536 if (ignore_octets == 0)
537 new->flags |= CFG_VOLUME_PERF_IO;
538 if (ignore_operations == 0)
539 new->flags |= CFG_VOLUME_PERF_OPS;
540 if (ignore_latency == 0)
541 new->flags |= CFG_VOLUME_PERF_LATENCY;
543 /* Add to end of list. */
550 } /* }}} data_volume_perf_t *get_volume_perf */
553 * Various submit functions.
555 * They all eventually call "submit_values" which creates a value_list_t and
556 * dispatches it to the daemon.
558 static int submit_values (const char *host, /* {{{ */
559 const char *plugin_inst,
560 const char *type, const char *type_inst,
561 value_t *values, int values_len,
564 value_list_t vl = VALUE_LIST_INIT;
567 vl.values_len = values_len;
573 sstrncpy (vl.host, host, sizeof (vl.host));
575 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
576 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
577 if (plugin_inst != NULL)
578 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
579 sstrncpy (vl.type, type, sizeof (vl.type));
580 if (type_inst != NULL)
581 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
583 return (plugin_dispatch_values (&vl));
584 } /* }}} int submit_uint64 */
586 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
587 const char *type, const char *type_inst, counter_t val0, counter_t val1,
592 values[0].counter = val0;
593 values[1].counter = val1;
595 return (submit_values (host, plugin_inst, type, type_inst,
596 values, 2, timestamp));
597 } /* }}} int submit_two_counters */
599 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
600 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
606 return (submit_values (host, plugin_inst, type, type_inst,
608 } /* }}} int submit_counter */
610 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
611 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
616 values[0].gauge = val0;
617 values[1].gauge = val1;
619 return (submit_values (host, plugin_inst, type, type_inst,
620 values, 2, timestamp));
621 } /* }}} int submit_two_gauge */
623 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
624 const char *type, const char *type_inst, double d, time_t timestamp)
628 v.gauge = (gauge_t) d;
630 return (submit_values (host, plugin_inst, type, type_inst,
632 } /* }}} int submit_uint64 */
634 /* Calculate hit ratio from old and new counters and submit the resulting
635 * percentage. Used by "submit_wafl_data". */
636 static int submit_cache_ratio (const char *host, /* {{{ */
637 const char *plugin_inst,
638 const char *type_inst,
647 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
651 hits = new_hits - old_hits;
652 misses = new_misses - old_misses;
654 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
659 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
661 } /* }}} int submit_cache_ratio */
663 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
664 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
665 cfg_wafl_t *old_data, const cfg_wafl_t *new_data)
667 /* Submit requested counters */
668 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
669 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
670 submit_cache_ratio (hostname, instance, "name_cache_hit",
671 new_data->name_cache_hit, new_data->name_cache_miss,
672 old_data->name_cache_hit, old_data->name_cache_miss,
673 new_data->timestamp);
675 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
676 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
677 submit_cache_ratio (hostname, instance, "find_dir_hit",
678 new_data->find_dir_hit, new_data->find_dir_miss,
679 old_data->find_dir_hit, old_data->find_dir_miss,
680 new_data->timestamp);
682 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
683 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
684 submit_cache_ratio (hostname, instance, "buf_hash_hit",
685 new_data->buf_hash_hit, new_data->buf_hash_miss,
686 old_data->buf_hash_hit, old_data->buf_hash_miss,
687 new_data->timestamp);
689 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
690 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
691 submit_cache_ratio (hostname, instance, "inode_cache_hit",
692 new_data->inode_cache_hit, new_data->inode_cache_miss,
693 old_data->inode_cache_hit, old_data->inode_cache_miss,
694 new_data->timestamp);
696 /* Clear old HAVE_* flags */
697 old_data->flags &= ~HAVE_WAFL_ALL;
699 /* Copy all counters */
700 old_data->timestamp = new_data->timestamp;
701 old_data->name_cache_hit = new_data->name_cache_hit;
702 old_data->name_cache_miss = new_data->name_cache_miss;
703 old_data->find_dir_hit = new_data->find_dir_hit;
704 old_data->find_dir_miss = new_data->find_dir_miss;
705 old_data->buf_hash_hit = new_data->buf_hash_hit;
706 old_data->buf_hash_miss = new_data->buf_hash_miss;
707 old_data->inode_cache_hit = new_data->inode_cache_hit;
708 old_data->inode_cache_miss = new_data->inode_cache_miss;
710 /* Copy HAVE_* flags */
711 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
714 } /* }}} int submit_wafl_data */
716 /* Submits volume performance data to the daemon, taking care to honor and
717 * update flags appropriately. */
718 static int submit_volume_perf_data (const char *hostname, /* {{{ */
719 data_volume_perf_t *old_data,
720 const data_volume_perf_t *new_data)
722 /* Check for and submit disk-octet values */
723 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
724 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
726 submit_two_counters (hostname, old_data->name, "disk_octets", /* type instance = */ NULL,
727 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
730 /* Check for and submit disk-operations values */
731 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
732 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
734 submit_two_counters (hostname, old_data->name, "disk_ops", /* type instance = */ NULL,
735 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
738 /* Check for, calculate and submit disk-latency values */
739 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
740 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
741 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
742 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
743 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
745 gauge_t latency_per_op_read;
746 gauge_t latency_per_op_write;
748 latency_per_op_read = NAN;
749 latency_per_op_write = NAN;
751 /* Check if a counter wrapped around. */
752 if ((new_data->read_ops > old_data->read_ops)
753 && (new_data->read_latency > old_data->read_latency))
755 uint64_t diff_ops_read;
756 uint64_t diff_latency_read;
758 diff_ops_read = new_data->read_ops - old_data->read_ops;
759 diff_latency_read = new_data->read_latency - old_data->read_latency;
761 if (diff_ops_read > 0)
762 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
765 if ((new_data->write_ops > old_data->write_ops)
766 && (new_data->write_latency > old_data->write_latency))
768 uint64_t diff_ops_write;
769 uint64_t diff_latency_write;
771 diff_ops_write = new_data->write_ops - old_data->write_ops;
772 diff_latency_write = new_data->write_latency - old_data->write_latency;
774 if (diff_ops_write > 0)
775 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
778 submit_two_gauge (hostname, old_data->name, "disk_latency", /* type instance = */ NULL,
779 latency_per_op_read, latency_per_op_write, new_data->timestamp);
782 /* Clear all HAVE_* flags. */
783 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
785 /* Copy all counters */
786 old_data->timestamp = new_data->timestamp;
787 old_data->read_bytes = new_data->read_bytes;
788 old_data->write_bytes = new_data->write_bytes;
789 old_data->read_ops = new_data->read_ops;
790 old_data->write_ops = new_data->write_ops;
791 old_data->read_latency = new_data->read_latency;
792 old_data->write_latency = new_data->write_latency;
794 /* Copy the HAVE_* flags */
795 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
798 } /* }}} int submit_volume_perf_data */
803 * These functions are called with appropriate data returned by the libnetapp
804 * interface which is parsed and submitted with the above functions.
806 /* Data corresponding to <WAFL /> */
807 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
810 cfg_wafl_t perf_data;
811 const char *plugin_inst;
813 na_elem_t *instances;
815 na_elem_iter_t counter_iter;
817 memset (&perf_data, 0, sizeof (perf_data));
819 perf_data.timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
821 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
822 if (instances == NULL)
824 ERROR ("netapp plugin: cna_handle_wafl_data: "
825 "na_elem_child (\"instances\") failed.");
829 plugin_inst = na_child_get_string(instances, "name");
830 if (plugin_inst == NULL)
832 ERROR ("netapp plugin: cna_handle_wafl_data: "
833 "na_child_get_string (\"name\") failed.");
837 /* Iterate over all counters */
838 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
839 for (counter = na_iterator_next (&counter_iter);
841 counter = na_iterator_next (&counter_iter))
846 name = na_child_get_string(counter, "name");
850 value = na_child_get_uint64(counter, "value", UINT64_MAX);
851 if (value == UINT64_MAX)
854 if (!strcmp(name, "name_cache_hit")) {
855 perf_data.name_cache_hit = value;
856 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
857 } else if (!strcmp(name, "name_cache_miss")) {
858 perf_data.name_cache_miss = value;
859 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
860 } else if (!strcmp(name, "find_dir_hit")) {
861 perf_data.find_dir_hit = value;
862 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
863 } else if (!strcmp(name, "find_dir_miss")) {
864 perf_data.find_dir_miss = value;
865 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
866 } else if (!strcmp(name, "buf_hash_hit")) {
867 perf_data.buf_hash_hit = value;
868 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
869 } else if (!strcmp(name, "buf_hash_miss")) {
870 perf_data.buf_hash_miss = value;
871 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
872 } else if (!strcmp(name, "inode_cache_hit")) {
873 perf_data.inode_cache_hit = value;
874 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
875 } else if (!strcmp(name, "inode_cache_miss")) {
876 perf_data.inode_cache_miss = value;
877 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
879 DEBUG("netapp plugin: cna_handle_wafl_data: "
880 "Found unexpected child: %s", name);
884 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data));
885 } /* }}} void cna_handle_wafl_data */
887 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
894 if (cw->query != NULL)
897 cw->query = na_elem_new("perf-object-get-instances");
898 if (cw->query == NULL)
900 ERROR ("netapp plugin: na_elem_new failed.");
903 na_child_add_string (cw->query, "objectname", "wafl");
905 e = na_elem_new("counters");
908 na_elem_free (cw->query);
910 ERROR ("netapp plugin: na_elem_new failed.");
913 na_child_add_string(e, "foo", "name_cache_hit");
914 na_child_add_string(e, "foo", "name_cache_miss");
915 na_child_add_string(e, "foo", "find_dir_hit");
916 na_child_add_string(e, "foo", "find_dir_miss");
917 na_child_add_string(e, "foo", "buf_hash_hit");
918 na_child_add_string(e, "foo", "buf_hash_miss");
919 na_child_add_string(e, "foo", "inode_cache_hit");
920 na_child_add_string(e, "foo", "inode_cache_miss");
922 na_child_add(cw->query, e);
925 } /* }}} int cna_setup_wafl */
927 static int cna_query_wafl (host_config_t *host) /* {{{ */
936 /* If WAFL was not configured, return without doing anything. */
937 if (host->cfg_wafl == NULL)
941 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
944 status = cna_setup_wafl (host->cfg_wafl);
947 assert (host->cfg_wafl->query != NULL);
949 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
950 if (na_results_status (data) != NA_OK)
952 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed: %s",
953 na_results_reason (data));
958 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data);
961 host->cfg_wafl->interval.last_read = now;
965 } /* }}} int cna_query_wafl */
967 /* Data corresponding to <Disks /> */
968 static int cna_handle_disk_data (const char *hostname, /* {{{ */
969 cfg_disk_t *cfg_disk, na_elem_t *data)
972 na_elem_t *instances;
974 na_elem_iter_t instance_iter;
975 disk_t *worst_disk = NULL;
977 if ((cfg_disk == NULL) || (data == NULL))
980 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
982 instances = na_elem_child (data, "instances");
983 if (instances == NULL)
985 ERROR ("netapp plugin: cna_handle_disk_data: "
986 "na_elem_child (\"instances\") failed.");
990 /* Iterate over all children */
991 instance_iter = na_child_iterator (instances);
992 for (instance = na_iterator_next (&instance_iter);
994 instance = na_iterator_next(&instance_iter))
999 na_elem_iter_t counter_iterator;
1002 memset (&new_data, 0, sizeof (new_data));
1003 new_data.timestamp = timestamp;
1004 new_data.disk_busy_percent = NAN;
1006 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1007 if (old_data == NULL)
1010 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1011 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1012 for (counter = na_iterator_next(&counter_iterator);
1014 counter = na_iterator_next(&counter_iterator))
1019 name = na_child_get_string(counter, "name");
1023 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1024 if (value == UINT64_MAX)
1027 if (strcmp(name, "disk_busy") == 0)
1029 new_data.disk_busy = value;
1030 new_data.flags |= HAVE_DISK_BUSY;
1032 else if (strcmp(name, "base_for_disk_busy") == 0)
1034 new_data.base_for_disk_busy = value;
1035 new_data.flags |= HAVE_DISK_BASE;
1039 DEBUG ("netapp plugin: cna_handle_disk_data: "
1040 "Counter not handled: %s = %"PRIu64,
1045 /* If all required counters are available and did not just wrap around,
1046 * calculate the busy percentage. Otherwise, the value is initialized to
1047 * NAN at the top of the for-loop. */
1048 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1049 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1050 && (new_data.disk_busy >= old_data->disk_busy)
1051 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1056 busy_diff = new_data.disk_busy - old_data->disk_busy;
1057 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1059 new_data.disk_busy_percent = 100.0
1060 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1063 /* Clear HAVE_* flags */
1064 old_data->flags &= ~HAVE_DISK_ALL;
1067 old_data->timestamp = new_data.timestamp;
1068 old_data->disk_busy = new_data.disk_busy;
1069 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1070 old_data->disk_busy_percent = new_data.disk_busy_percent;
1073 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1075 if ((worst_disk == NULL)
1076 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1077 worst_disk = old_data;
1078 } /* for (all disks) */
1080 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1081 submit_double (hostname, "system", "percent", "disk_busy",
1082 worst_disk->disk_busy_percent, timestamp);
1085 } /* }}} int cna_handle_disk_data */
1087 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1094 if (cd->query != NULL)
1097 cd->query = na_elem_new ("perf-object-get-instances");
1098 if (cd->query == NULL)
1100 ERROR ("netapp plugin: na_elem_new failed.");
1103 na_child_add_string (cd->query, "objectname", "disk");
1105 e = na_elem_new("counters");
1108 na_elem_free (cd->query);
1110 ERROR ("netapp plugin: na_elem_new failed.");
1113 na_child_add_string(e, "foo", "disk_busy");
1114 na_child_add_string(e, "foo", "base_for_disk_busy");
1115 na_child_add(cd->query, e);
1118 } /* }}} int cna_setup_disk */
1120 static int cna_query_disk (host_config_t *host) /* {{{ */
1129 /* If the user did not configure disk statistics, return without doing
1131 if (host->cfg_disk == NULL)
1135 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1138 status = cna_setup_disk (host->cfg_disk);
1141 assert (host->cfg_disk->query != NULL);
1143 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1144 if (na_results_status (data) != NA_OK)
1146 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed: %s",
1147 na_results_reason (data));
1148 na_elem_free (data);
1152 status = cna_handle_disk_data (host->name, host->cfg_disk, data);
1155 host->cfg_disk->interval.last_read = now;
1157 na_elem_free (data);
1159 } /* }}} int cna_query_disk */
1161 /* Data corresponding to <VolumePerf /> */
1162 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1163 cfg_volume_perf_t *cvp, na_elem_t *data)
1166 na_elem_t *elem_instances;
1167 na_elem_iter_t iter_instances;
1168 na_elem_t *elem_instance;
1170 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
1172 elem_instances = na_elem_child(data, "instances");
1173 if (elem_instances == NULL)
1175 ERROR ("netapp plugin: handle_volume_perf_data: "
1176 "na_elem_child (\"instances\") failed.");
1180 iter_instances = na_child_iterator (elem_instances);
1181 for (elem_instance = na_iterator_next(&iter_instances);
1182 elem_instance != NULL;
1183 elem_instance = na_iterator_next(&iter_instances))
1187 data_volume_perf_t perf_data;
1188 data_volume_perf_t *v;
1190 na_elem_t *elem_counters;
1191 na_elem_iter_t iter_counters;
1192 na_elem_t *elem_counter;
1194 memset (&perf_data, 0, sizeof (perf_data));
1195 perf_data.timestamp = timestamp;
1197 name = na_child_get_string (elem_instance, "name");
1201 /* get_volume_perf may return NULL if this volume is to be ignored. */
1202 v = get_volume_perf (cvp, perf_data.name);
1206 elem_counters = na_elem_child (elem_instance, "counters");
1207 if (elem_counters == NULL)
1210 iter_counters = na_child_iterator (elem_counters);
1211 for (elem_counter = na_iterator_next(&iter_counters);
1212 elem_counter != NULL;
1213 elem_counter = na_iterator_next(&iter_counters))
1218 name = na_child_get_string (elem_counter, "name");
1222 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1223 if (value == UINT64_MAX)
1226 if (!strcmp(name, "read_data")) {
1227 perf_data.read_bytes = value;
1228 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1229 } else if (!strcmp(name, "write_data")) {
1230 perf_data.write_bytes = value;
1231 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1232 } else if (!strcmp(name, "read_ops")) {
1233 perf_data.read_ops = value;
1234 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1235 } else if (!strcmp(name, "write_ops")) {
1236 perf_data.write_ops = value;
1237 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1238 } else if (!strcmp(name, "read_latency")) {
1239 perf_data.read_latency = value;
1240 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1241 } else if (!strcmp(name, "write_latency")) {
1242 perf_data.write_latency = value;
1243 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1245 } /* for (elem_counter) */
1247 submit_volume_perf_data (hostname, v, &perf_data);
1248 } /* for (volume) */
1251 } /* }}} int cna_handle_volume_perf_data */
1253 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1260 if (cd->query != NULL)
1263 cd->query = na_elem_new ("perf-object-get-instances");
1264 if (cd->query == NULL)
1266 ERROR ("netapp plugin: na_elem_new failed.");
1269 na_child_add_string (cd->query, "objectname", "volume");
1271 e = na_elem_new("counters");
1274 na_elem_free (cd->query);
1276 ERROR ("netapp plugin: na_elem_new failed.");
1279 /* "foo" means: This string has to be here but the content doesn't matter. */
1280 na_child_add_string(e, "foo", "read_ops");
1281 na_child_add_string(e, "foo", "write_ops");
1282 na_child_add_string(e, "foo", "read_data");
1283 na_child_add_string(e, "foo", "write_data");
1284 na_child_add_string(e, "foo", "read_latency");
1285 na_child_add_string(e, "foo", "write_latency");
1286 na_child_add(cd->query, e);
1289 } /* }}} int cna_setup_volume_perf */
1291 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1300 /* If the user did not configure volume performance statistics, return
1301 * without doing anything. */
1302 if (host->cfg_volume_perf == NULL)
1306 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1309 status = cna_setup_volume_perf (host->cfg_volume_perf);
1312 assert (host->cfg_volume_perf->query != NULL);
1314 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1315 if (na_results_status (data) != NA_OK)
1317 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed: %s",
1318 na_results_reason (data));
1319 na_elem_free (data);
1323 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data);
1326 host->cfg_volume_perf->interval.last_read = now;
1328 na_elem_free (data);
1330 } /* }}} int cna_query_volume_perf */
1332 /* Data corresponding to <VolumeUsage /> */
1333 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1334 cfg_volume_usage_t *cfg_volume)
1336 data_volume_usage_t *v;
1338 for (v = cfg_volume->volumes; v != NULL; v = v->next)
1340 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1341 submit_double (hostname, /* plugin instance = */ v->name,
1342 "df_complex", "free",
1343 (double) v->norm_free, /* timestamp = */ 0);
1345 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1346 submit_double (hostname, /* plugin instance = */ v->name,
1347 "df_complex", "used",
1348 (double) v->norm_used, /* timestamp = */ 0);
1350 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1351 submit_double (hostname, /* plugin instance = */ v->name,
1352 "df_complex", "snap_reserved",
1353 (double) v->snap_reserved, /* timestamp = */ 0);
1355 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1356 submit_double (hostname, /* plugin instance = */ v->name,
1357 "df_complex", "snap_used",
1358 (double) v->snap_used, /* timestamp = */ 0);
1360 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1361 submit_double (hostname, /* plugin instance = */ v->name,
1362 "df_complex", "sis_saved",
1363 (double) v->sis_saved, /* timestamp = */ 0);
1365 /* Clear all the HAVE_* flags */
1366 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1367 } /* for (v = cfg_volume->volumes) */
1370 } /* }}} int cna_submit_volume_usage_data */
1372 static int cna_handle_volume_usage_data (const char *hostname, /* {{{ */
1373 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1375 na_elem_t *elem_volume;
1376 na_elem_t *elem_volumes;
1377 na_elem_iter_t iter_volume;
1379 elem_volumes = na_elem_child (data, "volumes");
1380 if (elem_volumes == NULL)
1382 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1383 "na_elem_child (\"volumes\") failed.");
1387 iter_volume = na_child_iterator (elem_volumes);
1388 for (elem_volume = na_iterator_next (&iter_volume);
1389 elem_volume != NULL;
1390 elem_volume = na_iterator_next (&iter_volume))
1392 const char *volume_name;
1394 data_volume_usage_t *v;
1398 const char *sis_state;
1399 uint64_t sis_saved_reported;
1401 volume_name = na_child_get_string (elem_volume, "name");
1402 if (volume_name == NULL)
1405 /* get_volume_usage may return NULL if the volume is to be ignored. */
1406 v = get_volume_usage (cfg_volume, volume_name);
1410 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1413 /* 2^4 exa-bytes? This will take a while ;) */
1414 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1415 if (value != UINT64_MAX) {
1416 v->norm_free = value;
1417 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1420 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1421 if (value != UINT64_MAX) {
1422 v->norm_used = value;
1423 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1426 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1427 if (value != UINT64_MAX) {
1428 /* 1 block == 1024 bytes as per API docs */
1429 v->norm_used = 1024 * value;
1430 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1433 sis = na_elem_child(elem_volume, "sis");
1437 sis_state = na_child_get_string(sis, "state");
1438 if (sis_state == NULL)
1441 /* If SIS is not enabled, set the HAVE_VOLUME_USAGE_SIS_SAVED flag and set
1442 * sis_saved to UINT64_MAX to signal this condition to the submit function. */
1443 if (strcmp ("enabled", sis_state) != 0) {
1444 v->sis_saved = UINT64_MAX;
1445 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1449 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1450 if (sis_saved_reported == UINT64_MAX)
1453 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1454 if ((sis_saved_reported >> 32) != 0) {
1455 /* In case they ever fix this bug. */
1456 v->sis_saved = sis_saved_reported;
1457 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1458 } else { /* really hacky work-around code. {{{ */
1459 uint64_t sis_saved_percent;
1460 uint64_t sis_saved_guess;
1461 uint64_t overflow_guess;
1462 uint64_t guess1, guess2, guess3;
1464 /* Check if we have v->norm_used. Without it, we cannot calculate
1465 * sis_saved_guess. */
1466 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1469 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1470 if (sis_saved_percent > 100)
1473 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1474 * will hopefully be fixed in later versions. To work around the bug, try
1475 * to figure out how often the 32bit integer wrapped around by using the
1476 * "percentage-saved" value. Because the percentage is in the range
1477 * [0-100], this should work as long as the saved space does not exceed
1479 /* percentage-saved = size-saved / (size-saved + size-used) */
1480 if (sis_saved_percent < 100)
1481 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1483 sis_saved_guess = v->norm_used;
1485 overflow_guess = sis_saved_guess >> 32;
1486 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1487 guess2 = (overflow_guess << 32) + sis_saved_reported;
1488 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1490 if (sis_saved_guess < guess2) {
1491 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1492 v->sis_saved = guess1;
1494 v->sis_saved = guess2;
1496 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1497 v->sis_saved = guess2;
1499 v->sis_saved = guess3;
1501 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1502 } /* }}} end of 32-bit workaround */
1503 } /* for (elem_volume) */
1505 return (cna_submit_volume_usage_data (hostname, cfg_volume));
1506 } /* }}} int cna_handle_volume_usage_data */
1508 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1513 if (cvu->query != NULL)
1516 cvu->query = na_elem_new ("volume-list-info");
1517 if (cvu->query == NULL)
1519 ERROR ("netapp plugin: na_elem_new failed.");
1523 /* TODO: cvu->snap_query = na_elem_new("snapshot-list-info"); */
1526 } /* }}} int cna_setup_volume_usage */
1528 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1537 /* If the user did not configure volume_usage statistics, return without
1538 * doing anything. */
1539 if (host->cfg_volume_usage == NULL)
1543 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1546 status = cna_setup_volume_usage (host->cfg_volume_usage);
1549 assert (host->cfg_volume_usage->query != NULL);
1551 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1552 if (na_results_status (data) != NA_OK)
1554 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed: %s",
1555 na_results_reason (data));
1556 na_elem_free (data);
1560 status = cna_handle_volume_usage_data (host->name, host->cfg_volume_usage, data);
1563 host->cfg_volume_usage->interval.last_read = now;
1565 na_elem_free (data);
1567 } /* }}} int cna_query_volume_usage */
1569 /* Data corresponding to <System /> */
1570 static int cna_handle_system_data (const char *hostname, /* {{{ */
1571 cfg_system_t *cfg_system, na_elem_t *data)
1573 na_elem_t *instances;
1575 na_elem_iter_t counter_iter;
1577 counter_t disk_read = 0, disk_written = 0;
1578 counter_t net_recv = 0, net_sent = 0;
1579 counter_t cpu_busy = 0, cpu_total = 0;
1580 uint32_t counter_flags = 0;
1582 const char *instance;
1585 timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
1587 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1588 if (instances == NULL)
1590 ERROR ("netapp plugin: cna_handle_system_data: "
1591 "na_elem_child (\"instances\") failed.");
1595 instance = na_child_get_string (instances, "name");
1596 if (instance == NULL)
1598 ERROR ("netapp plugin: cna_handle_system_data: "
1599 "na_child_get_string (\"name\") failed.");
1603 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
1604 for (counter = na_iterator_next (&counter_iter);
1606 counter = na_iterator_next (&counter_iter))
1611 name = na_child_get_string(counter, "name");
1615 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1616 if (value == UINT64_MAX)
1619 if (!strcmp(name, "disk_data_read")) {
1620 disk_read = (counter_t) (value * 1024);
1621 counter_flags |= 0x01;
1622 } else if (!strcmp(name, "disk_data_written")) {
1623 disk_written = (counter_t) (value * 1024);
1624 counter_flags |= 0x02;
1625 } else if (!strcmp(name, "net_data_recv")) {
1626 net_recv = (counter_t) (value * 1024);
1627 counter_flags |= 0x04;
1628 } else if (!strcmp(name, "net_data_sent")) {
1629 net_sent = (counter_t) (value * 1024);
1630 counter_flags |= 0x08;
1631 } else if (!strcmp(name, "cpu_busy")) {
1632 cpu_busy = (counter_t) value;
1633 counter_flags |= 0x10;
1634 } else if (!strcmp(name, "cpu_elapsed_time")) {
1635 cpu_total = (counter_t) value;
1636 counter_flags |= 0x20;
1637 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1638 && (value > 0) && (strlen(name) > 4)
1639 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1640 submit_counter (hostname, instance, "disk_ops_complex", name,
1641 (counter_t) value, timestamp);
1643 } /* for (counter) */
1645 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1646 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
1647 submit_two_counters (hostname, instance, "disk_octets", NULL,
1648 disk_read, disk_written, timestamp);
1650 if ((cfg_system->flags & CFG_SYSTEM_NET)
1651 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
1652 submit_two_counters (hostname, instance, "if_octets", NULL,
1653 net_recv, net_sent, timestamp);
1655 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1656 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
1658 submit_counter (hostname, instance, "cpu", "system",
1659 cpu_busy, timestamp);
1660 submit_counter (hostname, instance, "cpu", "idle",
1661 cpu_total - cpu_busy, timestamp);
1665 } /* }}} int cna_handle_system_data */
1667 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
1672 if (cs->query != NULL)
1675 cs->query = na_elem_new ("perf-object-get-instances");
1676 if (cs->query == NULL)
1678 ERROR ("netapp plugin: na_elem_new failed.");
1681 na_child_add_string (cs->query, "objectname", "system");
1684 } /* }}} int cna_setup_system */
1686 static int cna_query_system (host_config_t *host) /* {{{ */
1695 /* If system statistics were not configured, return without doing anything. */
1696 if (host->cfg_system == NULL)
1700 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
1703 status = cna_setup_system (host->cfg_system);
1706 assert (host->cfg_system->query != NULL);
1708 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
1709 if (na_results_status (data) != NA_OK)
1711 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed: %s",
1712 na_results_reason (data));
1713 na_elem_free (data);
1717 status = cna_handle_system_data (host->name, host->cfg_system, data);
1720 host->cfg_system->interval.last_read = now;
1722 na_elem_free (data);
1724 } /* }}} int cna_query_system */
1727 * Configuration handling
1729 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1730 * is false. On error, the flag-field is not changed. */
1731 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1732 uint32_t *flags, uint32_t flag)
1734 if ((ci == NULL) || (flags == NULL))
1737 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1739 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1744 if (ci->values[0].value.boolean)
1750 } /* }}} int cna_config_bool_to_flag */
1752 /* Handling of the "Interval" option which is allowed in every block. */
1753 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1754 cna_interval_t *out_interval)
1758 if ((ci == NULL) || (out_interval == NULL))
1761 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1763 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1767 tmp = (time_t) (ci->values[0].value.number + .5);
1770 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1774 out_interval->interval = tmp;
1775 out_interval->last_read = 0;
1778 } /* }}} int cna_config_get_interval */
1780 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1781 * <VolumePerf /> block. */
1782 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
1783 const oconfig_item_t *ci)
1788 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1790 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1795 name = ci->values[0].value.string;
1797 if (strcasecmp ("GetIO", ci->key) == 0)
1798 il = cvp->il_octets;
1799 else if (strcasecmp ("GetOps", ci->key) == 0)
1800 il = cvp->il_operations;
1801 else if (strcasecmp ("GetLatency", ci->key) == 0)
1802 il = cvp->il_latency;
1806 ignorelist_add (il, name);
1807 } /* }}} void cna_config_volume_perf_option */
1809 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
1810 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
1811 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
1812 const oconfig_item_t *ci)
1816 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1818 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1823 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
1824 il = cvp->il_octets;
1825 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
1826 il = cvp->il_operations;
1827 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
1828 il = cvp->il_latency;
1832 if (ci->values[0].value.boolean)
1833 ignorelist_set_invert (il, /* invert = */ 0);
1835 ignorelist_set_invert (il, /* invert = */ 1);
1836 } /* }}} void cna_config_volume_perf_default */
1838 /* Corresponds to a <Disks /> block */
1843 * IgnoreSelectedIO false
1847 * IgnoreSelectedOps false
1851 * IgnoreSelectedLatency false
1854 /* Corresponds to a <VolumePerf /> block */
1855 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
1856 const oconfig_item_t *ci)
1858 cfg_volume_perf_t *cfg_volume_perf;
1861 if ((host == NULL) || (ci == NULL))
1864 if (host->cfg_volume_perf == NULL)
1866 cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
1867 if (cfg_volume_perf == NULL)
1869 memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
1871 /* Set default flags */
1872 cfg_volume_perf->query = NULL;
1873 cfg_volume_perf->volumes = NULL;
1875 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
1876 if (cfg_volume_perf->il_octets == NULL)
1878 sfree (cfg_volume_perf);
1882 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
1883 if (cfg_volume_perf->il_operations == NULL)
1885 ignorelist_free (cfg_volume_perf->il_octets);
1886 sfree (cfg_volume_perf);
1890 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
1891 if (cfg_volume_perf->il_latency == NULL)
1893 ignorelist_free (cfg_volume_perf->il_octets);
1894 ignorelist_free (cfg_volume_perf->il_operations);
1895 sfree (cfg_volume_perf);
1899 host->cfg_volume_perf = cfg_volume_perf;
1901 cfg_volume_perf = host->cfg_volume_perf;
1903 for (i = 0; i < ci->children_num; ++i) {
1904 oconfig_item_t *item = ci->children + i;
1906 /* if (!item || !item->key || !*item->key) continue; */
1907 if (strcasecmp(item->key, "Interval") == 0)
1908 cna_config_get_interval (item, &cfg_volume_perf->interval);
1909 else if (!strcasecmp(item->key, "GetIO"))
1910 cna_config_volume_perf_option (cfg_volume_perf, item);
1911 else if (!strcasecmp(item->key, "GetOps"))
1912 cna_config_volume_perf_option (cfg_volume_perf, item);
1913 else if (!strcasecmp(item->key, "GetLatency"))
1914 cna_config_volume_perf_option (cfg_volume_perf, item);
1915 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
1916 cna_config_volume_perf_default (cfg_volume_perf, item);
1917 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
1918 cna_config_volume_perf_default (cfg_volume_perf, item);
1919 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
1920 cna_config_volume_perf_default (cfg_volume_perf, item);
1922 WARNING ("netapp plugin: The option %s is not allowed within "
1923 "`VolumePerf' blocks.", item->key);
1927 } /* }}} int cna_config_volume_performance */
1929 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
1930 * <VolumeUsage /> block. */
1931 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
1932 const oconfig_item_t *ci)
1937 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1939 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1944 name = ci->values[0].value.string;
1946 if (strcasecmp ("GetCapacity", ci->key) == 0)
1947 il = cvu->il_capacity;
1948 else if (strcasecmp ("GetSnapshot", ci->key) == 0)
1949 il = cvu->il_snapshot;
1953 ignorelist_add (il, name);
1954 } /* }}} void cna_config_volume_usage_option */
1956 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
1957 * options within a <VolumeUsage /> block. */
1958 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
1959 const oconfig_item_t *ci)
1963 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1965 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1970 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
1971 il = cvu->il_capacity;
1972 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
1973 il = cvu->il_snapshot;
1977 if (ci->values[0].value.boolean)
1978 ignorelist_set_invert (il, /* invert = */ 0);
1980 ignorelist_set_invert (il, /* invert = */ 1);
1981 } /* }}} void cna_config_volume_usage_default */
1983 /* Corresponds to a <Disks /> block */
1984 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1985 cfg_disk_t *cfg_disk;
1988 if ((host == NULL) || (ci == NULL))
1991 if (host->cfg_disk == NULL)
1993 cfg_disk = malloc (sizeof (*cfg_disk));
1994 if (cfg_disk == NULL)
1996 memset (cfg_disk, 0, sizeof (*cfg_disk));
1998 /* Set default flags */
1999 cfg_disk->flags = CFG_DISK_ALL;
2000 cfg_disk->query = NULL;
2001 cfg_disk->disks = NULL;
2003 host->cfg_disk = cfg_disk;
2005 cfg_disk = host->cfg_disk;
2007 for (i = 0; i < ci->children_num; ++i) {
2008 oconfig_item_t *item = ci->children + i;
2010 /* if (!item || !item->key || !*item->key) continue; */
2011 if (strcasecmp(item->key, "Interval") == 0)
2012 cna_config_get_interval (item, &cfg_disk->interval);
2013 else if (strcasecmp(item->key, "GetBusy") == 0)
2014 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2017 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2019 NOTICE ("netapp plugin: All disk related values have been disabled. "
2020 "Collection of per-disk data will be disabled entirely.");
2021 free_cfg_disk (host->cfg_disk);
2022 host->cfg_disk = NULL;
2026 } /* }}} int cna_config_disk */
2028 /* Corresponds to a <WAFL /> block */
2029 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2031 cfg_wafl_t *cfg_wafl;
2034 if ((host == NULL) || (ci == NULL))
2037 if (host->cfg_wafl == NULL)
2039 cfg_wafl = malloc (sizeof (*cfg_wafl));
2040 if (cfg_wafl == NULL)
2042 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
2044 /* Set default flags */
2045 cfg_wafl->flags = CFG_WAFL_ALL;
2047 host->cfg_wafl = cfg_wafl;
2049 cfg_wafl = host->cfg_wafl;
2051 for (i = 0; i < ci->children_num; ++i) {
2052 oconfig_item_t *item = ci->children + i;
2054 if (strcasecmp(item->key, "Interval") == 0)
2055 cna_config_get_interval (item, &cfg_wafl->interval);
2056 else if (!strcasecmp(item->key, "GetNameCache"))
2057 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2058 else if (!strcasecmp(item->key, "GetDirCache"))
2059 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2060 else if (!strcasecmp(item->key, "GetBufferCache"))
2061 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2062 else if (!strcasecmp(item->key, "GetInodeCache"))
2063 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2065 WARNING ("netapp plugin: The %s config option is not allowed within "
2066 "`WAFL' blocks.", item->key);
2069 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2071 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2072 "Collection of WAFL data will be disabled entirely.");
2073 free_cfg_wafl (host->cfg_wafl);
2074 host->cfg_wafl = NULL;
2078 } /* }}} int cna_config_wafl */
2082 * GetCapacity "vol0"
2083 * GetCapacity "vol1"
2084 * GetCapacity "vol2"
2085 * GetCapacity "vol3"
2086 * GetCapacity "vol4"
2087 * IgnoreSelectedCapacity false
2089 * GetSnapshot "vol0"
2090 * GetSnapshot "vol3"
2091 * GetSnapshot "vol4"
2092 * GetSnapshot "vol7"
2093 * IgnoreSelectedSnapshot false
2096 /* Corresponds to a <VolumeUsage /> block */
2097 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2098 const oconfig_item_t *ci)
2100 cfg_volume_usage_t *cfg_volume_usage;
2103 if ((host == NULL) || (ci == NULL))
2106 if (host->cfg_volume_usage == NULL)
2108 cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
2109 if (cfg_volume_usage == NULL)
2111 memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
2113 /* Set default flags */
2114 cfg_volume_usage->query = NULL;
2115 cfg_volume_usage->volumes = NULL;
2117 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2118 if (cfg_volume_usage->il_capacity == NULL)
2120 sfree (cfg_volume_usage);
2124 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2125 if (cfg_volume_usage->il_snapshot == NULL)
2127 ignorelist_free (cfg_volume_usage->il_capacity);
2128 sfree (cfg_volume_usage);
2132 host->cfg_volume_usage = cfg_volume_usage;
2134 cfg_volume_usage = host->cfg_volume_usage;
2136 for (i = 0; i < ci->children_num; ++i) {
2137 oconfig_item_t *item = ci->children + i;
2139 /* if (!item || !item->key || !*item->key) continue; */
2140 if (strcasecmp(item->key, "Interval") == 0)
2141 cna_config_get_interval (item, &cfg_volume_usage->interval);
2142 else if (!strcasecmp(item->key, "GetCapacity"))
2143 cna_config_volume_usage_option (cfg_volume_usage, item);
2144 else if (!strcasecmp(item->key, "GetSnapshot"))
2145 cna_config_volume_usage_option (cfg_volume_usage, item);
2146 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2147 cna_config_volume_usage_default (cfg_volume_usage, item);
2148 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2149 cna_config_volume_usage_default (cfg_volume_usage, item);
2151 WARNING ("netapp plugin: The option %s is not allowed within "
2152 "`VolumeUsage' blocks.", item->key);
2156 } /* }}} int cna_config_volume_usage */
2158 /* Corresponds to a <System /> block */
2159 static int cna_config_system (host_config_t *host, /* {{{ */
2162 cfg_system_t *cfg_system;
2165 if ((host == NULL) || (ci == NULL))
2168 if (host->cfg_system == NULL)
2170 cfg_system = malloc (sizeof (*cfg_system));
2171 if (cfg_system == NULL)
2173 memset (cfg_system, 0, sizeof (*cfg_system));
2175 /* Set default flags */
2176 cfg_system->flags = CFG_SYSTEM_ALL;
2177 cfg_system->query = NULL;
2179 host->cfg_system = cfg_system;
2181 cfg_system = host->cfg_system;
2183 for (i = 0; i < ci->children_num; ++i) {
2184 oconfig_item_t *item = ci->children + i;
2186 if (strcasecmp(item->key, "Interval") == 0) {
2187 cna_config_get_interval (item, &cfg_system->interval);
2188 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2189 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2190 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2191 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2192 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2193 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2194 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2195 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2197 WARNING ("netapp plugin: The %s config option is not allowed within "
2198 "`System' blocks.", item->key);
2202 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2204 NOTICE ("netapp plugin: All system related values have been disabled. "
2205 "Collection of system data will be disabled entirely.");
2206 free_cfg_system (host->cfg_system);
2207 host->cfg_system = NULL;
2211 } /* }}} int cna_config_system */
2213 /* Corresponds to a <Host /> block. */
2214 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
2215 const host_config_t *default_host)
2217 oconfig_item_t *item;
2218 host_config_t *host;
2222 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2223 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
2227 host = malloc(sizeof(*host));
2228 memcpy (host, default_host, sizeof (*host));
2230 status = cf_util_get_string (ci, &host->name);
2237 for (i = 0; i < ci->children_num; ++i) {
2238 item = ci->children + i;
2242 if (!strcasecmp(item->key, "Address")) {
2243 status = cf_util_get_string (item, &host->host);
2244 } else if (!strcasecmp(item->key, "Port")) {
2247 tmp = cf_util_get_port_number (item);
2250 } else if (!strcasecmp(item->key, "Protocol")) {
2251 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"))) {
2252 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2255 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2256 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2257 } else if (!strcasecmp(item->key, "User")) {
2258 status = cf_util_get_string (item, &host->username);
2259 } else if (!strcasecmp(item->key, "Password")) {
2260 status = cf_util_get_string (item, &host->password);
2261 } else if (!strcasecmp(item->key, "Interval")) {
2262 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) {
2263 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
2266 host->interval = item->values[0].value.number;
2267 } else if (!strcasecmp(item->key, "WAFL")) {
2268 cna_config_wafl(host, item);
2269 } else if (!strcasecmp(item->key, "Disks")) {
2270 cna_config_disk(host, item);
2271 } else if (!strcasecmp(item->key, "VolumePerf")) {
2272 cna_config_volume_performance(host, item);
2273 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2274 cna_config_volume_usage(host, item);
2275 } else if (!strcasecmp(item->key, "System")) {
2276 cna_config_system(host, item);
2278 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
2279 item->key, ci->values[0].value.string);
2286 if (host->host == NULL)
2287 host->host = strdup (host->name);
2289 if (host->host == NULL)
2292 if (host->port <= 0)
2293 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2295 if ((host->username == NULL) || (host->password == NULL)) {
2296 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2297 "Ignoring host block.", host->name);
2303 free_host_config (host);
2308 } /* }}} host_config_t *cna_config_host */
2311 * Callbacks registered with the daemon
2313 * Pretty standard stuff here.
2315 static int cna_init(void) { /* {{{ */
2317 host_config_t *host;
2319 if (!global_host_config) {
2320 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
2324 memset (err, 0, sizeof (err));
2325 if (!na_startup(err, sizeof(err))) {
2326 err[sizeof (err) - 1] = 0;
2327 ERROR("netapp plugin: Error initializing netapp API: %s", err);
2331 for (host = global_host_config; host; host = host->next) {
2332 /* Request version 1.1 of the ONTAP API */
2333 host->srv = na_server_open(host->host,
2334 /* major version = */ 1, /* minor version = */ 1);
2335 if (host->srv == NULL) {
2336 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
2340 if (host->interval < interval_g)
2341 host->interval = interval_g;
2343 na_server_set_transport_type(host->srv, host->protocol,
2344 /* transportarg = */ NULL);
2345 na_server_set_port(host->srv, host->port);
2346 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
2347 na_server_adminuser(host->srv, host->username, host->password);
2348 na_server_set_timeout(host->srv, 5 /* seconds */);
2351 } /* }}} int cna_init */
2353 static int cna_config (oconfig_item_t *ci) { /* {{{ */
2355 oconfig_item_t *item;
2356 host_config_t default_host = HOST_INIT;
2358 for (i = 0; i < ci->children_num; ++i) {
2359 item = ci->children + i;
2361 if (!strcasecmp(item->key, "Host")) {
2362 host_config_t *host;
2365 host = cna_config_host(item, &default_host);
2369 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
2371 if (strcasecmp (host->name, tmp->name) == 0)
2372 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
2373 "This is probably a bad idea.",
2376 if (tmp->next == NULL)
2382 global_host_config = host;
2386 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
2390 } /* }}} int cna_config */
2392 static int cna_read (void) { /* {{{ */
2393 host_config_t *host;
2395 for (host = global_host_config; host; host = host->next) {
2396 cna_query_wafl (host);
2397 cna_query_disk (host);
2398 cna_query_volume_perf (host);
2399 cna_query_volume_usage (host);
2400 cna_query_system (host);
2403 } /* }}} int cna_read */
2405 void module_register(void) {
2406 plugin_register_complex_config("netapp", cna_config);
2407 plugin_register_init("netapp", cna_init);
2408 plugin_register_read("netapp", cna_read);
2411 /* vim: set sw=2 ts=2 noet fdm=marker : */