2 * collectd - src/netapp.c
3 * Copyright (C) 2009 Sven Trenkel
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Sven Trenkel <collectd at semidefinite.de>
29 #include "utils_ignorelist.h"
31 #include <netapp_api.h>
32 #include <netapp_errno.h>
34 #define HAS_ALL_FLAGS(has,needs) (((has) & (needs)) == (needs))
36 typedef struct host_config_s host_config_t;
37 typedef void service_handler_t(host_config_t *host, na_elem_t *result, void *data);
44 typedef struct cna_interval_s cna_interval_t;
46 /*! Data types for WAFL statistics {{{
48 * \brief Persistent data for WAFL performance counters. (a.k.a. cache performance)
50 * The cache counters use old counter values to calculate a hit ratio for each
51 * counter. The "cfg_wafl_t" struct therefore contains old counter values along
52 * with flags, which are set if the counter is valid.
54 * The function "cna_handle_wafl_data" will fill a new structure of this kind
55 * with new values, then pass both, new and old data, to "submit_wafl_data".
56 * That function calculates the hit ratios, submits the calculated values and
57 * updates the old counter values for the next iteration.
59 #define CFG_WAFL_NAME_CACHE 0x0001
60 #define CFG_WAFL_DIR_CACHE 0x0002
61 #define CFG_WAFL_BUF_CACHE 0x0004
62 #define CFG_WAFL_INODE_CACHE 0x0008
63 #define CFG_WAFL_ALL 0x000F
64 #define HAVE_WAFL_NAME_CACHE_HIT 0x0100
65 #define HAVE_WAFL_NAME_CACHE_MISS 0x0200
66 #define HAVE_WAFL_NAME_CACHE (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
67 #define HAVE_WAFL_FIND_DIR_HIT 0x0400
68 #define HAVE_WAFL_FIND_DIR_MISS 0x0800
69 #define HAVE_WAFL_FIND_DIR (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
70 #define HAVE_WAFL_BUF_HASH_HIT 0x1000
71 #define HAVE_WAFL_BUF_HASH_MISS 0x2000
72 #define HAVE_WAFL_BUF_HASH (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
73 #define HAVE_WAFL_INODE_CACHE_HIT 0x4000
74 #define HAVE_WAFL_INODE_CACHE_MISS 0x8000
75 #define HAVE_WAFL_INODE_CACHE (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
76 #define HAVE_WAFL_ALL 0xff00
79 cna_interval_t interval;
83 uint64_t name_cache_hit;
84 uint64_t name_cache_miss;
85 uint64_t find_dir_hit;
86 uint64_t find_dir_miss;
87 uint64_t buf_hash_hit;
88 uint64_t buf_hash_miss;
89 uint64_t inode_cache_hit;
90 uint64_t inode_cache_miss;
94 /*! Data types for disk statistics {{{
96 * \brief A disk in the NetApp.
98 * A disk doesn't have any more information than its name at the moment.
99 * The name includes the "disk_" prefix.
101 #define HAVE_DISK_BUSY 0x10
102 #define HAVE_DISK_BASE 0x20
103 #define HAVE_DISK_ALL 0x30
104 typedef struct disk_s {
109 uint64_t base_for_disk_busy;
110 double disk_busy_percent;
114 #define CFG_DISK_BUSIEST 0x01
115 #define CFG_DISK_ALL 0x01
118 cna_interval_t interval;
124 /*! Data types for volume performance statistics {{{
126 * \brief Persistent data for volume performance data.
128 * The code below uses the difference of the operations and latency counters to
129 * calculate an average per-operation latency. For this, old counters need to
130 * be stored in the "data_volume_perf_t" structure. The byte-counters are just
131 * kept for completeness sake. The "flags" member indicates if each counter is
134 * The "cna_handle_volume_perf_data" function will fill a new struct of this
135 * type and pass both, old and new data, to "submit_volume_perf_data". In that
136 * function, the per-operation latency is calculated and dispatched, then the
137 * old counters are updated.
139 #define CFG_VOLUME_PERF_INIT 0x0001
140 #define CFG_VOLUME_PERF_IO 0x0002
141 #define CFG_VOLUME_PERF_OPS 0x0003
142 #define CFG_VOLUME_PERF_LATENCY 0x0008
143 #define CFG_VOLUME_PERF_ALL 0x000F
144 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
145 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
146 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
147 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
148 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
149 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
150 #define HAVE_VOLUME_PERF_ALL 0x03F0
151 struct data_volume_perf_s;
152 typedef struct data_volume_perf_s data_volume_perf_t;
153 struct data_volume_perf_s {
159 uint64_t write_bytes;
162 uint64_t read_latency;
163 uint64_t write_latency;
165 data_volume_perf_t *next;
169 cna_interval_t interval;
172 ignorelist_t *il_octets;
173 ignorelist_t *il_operations;
174 ignorelist_t *il_latency;
176 data_volume_perf_t *volumes;
178 /* }}} data_volume_perf_t */
180 /*! Data types for volume usage statistics {{{
182 * \brief Configuration struct for volume usage data (free / used).
184 #define CFG_VOLUME_USAGE_DF 0x0002
185 #define CFG_VOLUME_USAGE_SNAP 0x0004
186 #define CFG_VOLUME_USAGE_ALL 0x0006
187 #define HAVE_VOLUME_USAGE_NORM_FREE 0x0010
188 #define HAVE_VOLUME_USAGE_NORM_USED 0x0020
189 #define HAVE_VOLUME_USAGE_SNAP_RSVD 0x0040
190 #define HAVE_VOLUME_USAGE_SNAP_USED 0x0080
191 #define HAVE_VOLUME_USAGE_SIS_SAVED 0x0100
192 #define HAVE_VOLUME_USAGE_ALL 0x01f0
193 #define IS_VOLUME_USAGE_OFFLINE 0x0200
194 struct data_volume_usage_s;
195 typedef struct data_volume_usage_s data_volume_usage_t;
196 struct data_volume_usage_s {
200 na_elem_t *snap_query;
204 uint64_t snap_reserved;
208 data_volume_usage_t *next;
212 cna_interval_t interval;
215 ignorelist_t *il_capacity;
216 ignorelist_t *il_snapshot;
218 data_volume_usage_t *volumes;
219 } cfg_volume_usage_t;
220 /* }}} cfg_volume_usage_t */
222 /*! Data types for system statistics {{{
224 * \brief Persistent data for system performance counters
226 #define CFG_SYSTEM_CPU 0x01
227 #define CFG_SYSTEM_NET 0x02
228 #define CFG_SYSTEM_OPS 0x04
229 #define CFG_SYSTEM_DISK 0x08
230 #define CFG_SYSTEM_ALL 0x0F
233 cna_interval_t interval;
236 /* }}} cfg_system_t */
238 struct host_config_s {
240 na_server_transport_t protocol;
248 cfg_wafl_t *cfg_wafl;
249 cfg_disk_t *cfg_disk;
250 cfg_volume_perf_t *cfg_volume_perf;
251 cfg_volume_usage_t *cfg_volume_usage;
252 cfg_system_t *cfg_system;
254 struct host_config_s *next;
260 * Used to free the various structures above.
262 static void free_disk (disk_t *disk) /* {{{ */
275 } /* }}} void free_disk */
277 static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
282 if (cw->query != NULL)
283 na_elem_free (cw->query);
286 } /* }}} void free_cfg_wafl */
288 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
290 if (cfg_disk == NULL)
293 if (cfg_disk->query != NULL)
294 na_elem_free (cfg_disk->query);
296 free_disk (cfg_disk->disks);
298 } /* }}} void free_cfg_disk */
300 static void free_cfg_volume_perf (cfg_volume_perf_t *cvp) /* {{{ */
302 data_volume_perf_t *data;
307 /* Free the ignorelists */
308 ignorelist_free (cvp->il_octets);
309 ignorelist_free (cvp->il_operations);
310 ignorelist_free (cvp->il_latency);
312 /* Free the linked list of volumes */
316 data_volume_perf_t *next = data->next;
322 if (cvp->query != NULL)
323 na_elem_free (cvp->query);
326 } /* }}} void free_cfg_volume_perf */
328 static void free_cfg_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
330 data_volume_usage_t *data;
335 /* Free the ignorelists */
336 ignorelist_free (cvu->il_capacity);
337 ignorelist_free (cvu->il_snapshot);
339 /* Free the linked list of volumes */
343 data_volume_usage_t *next = data->next;
345 if (data->snap_query != NULL)
346 na_elem_free(data->snap_query);
351 if (cvu->query != NULL)
352 na_elem_free (cvu->query);
355 } /* }}} void free_cfg_volume_usage */
357 static void free_cfg_system (cfg_system_t *cs) /* {{{ */
362 if (cs->query != NULL)
363 na_elem_free (cs->query);
366 } /* }}} void free_cfg_system */
368 static void free_host_config (host_config_t *hc) /* {{{ */
379 sfree (hc->username);
380 sfree (hc->password);
382 free_cfg_disk (hc->cfg_disk);
383 free_cfg_wafl (hc->cfg_wafl);
384 free_cfg_volume_perf (hc->cfg_volume_perf);
385 free_cfg_volume_usage (hc->cfg_volume_usage);
386 free_cfg_system (hc->cfg_system);
389 na_server_close (hc->srv);
393 free_host_config (next);
394 } /* }}} void free_host_config */
397 * Auxiliary functions
399 * Used to look up volumes and disks or to handle flags.
401 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
405 if ((cd == NULL) || (name == NULL))
408 for (d = cd->disks; d != NULL; d = d->next) {
409 if (strcmp(d->name, name) == 0)
413 d = malloc(sizeof(*d));
416 memset (d, 0, sizeof (*d));
419 d->name = strdup(name);
420 if (d->name == NULL) {
429 } /* }}} disk_t *get_disk */
431 static data_volume_usage_t *get_volume_usage (cfg_volume_usage_t *cvu, /* {{{ */
434 data_volume_usage_t *last;
435 data_volume_usage_t *new;
437 int ignore_capacity = 0;
438 int ignore_snapshot = 0;
440 if ((cvu == NULL) || (name == NULL))
446 if (strcmp (last->name, name) == 0)
449 if (last->next == NULL)
455 /* Check the ignorelists. If *both* tell us to ignore a volume, return NULL. */
456 ignore_capacity = ignorelist_match (cvu->il_capacity, name);
457 ignore_snapshot = ignorelist_match (cvu->il_snapshot, name);
458 if ((ignore_capacity != 0) && (ignore_snapshot != 0))
461 /* Not found: allocate. */
462 new = malloc (sizeof (*new));
465 memset (new, 0, sizeof (*new));
468 new->name = strdup (name);
469 if (new->name == NULL)
475 if (ignore_capacity == 0)
476 new->flags |= CFG_VOLUME_USAGE_DF;
477 if (ignore_snapshot == 0) {
478 new->flags |= CFG_VOLUME_USAGE_SNAP;
479 new->snap_query = na_elem_new ("snapshot-list-info");
480 na_child_add_string(new->snap_query, "target-type", "volume");
481 na_child_add_string(new->snap_query, "target-name", name);
483 new->snap_query = NULL;
486 /* Add to end of list. */
493 } /* }}} data_volume_usage_t *get_volume_usage */
495 static data_volume_perf_t *get_volume_perf (cfg_volume_perf_t *cvp, /* {{{ */
498 data_volume_perf_t *last;
499 data_volume_perf_t *new;
501 int ignore_octets = 0;
502 int ignore_operations = 0;
503 int ignore_latency = 0;
505 if ((cvp == NULL) || (name == NULL))
511 if (strcmp (last->name, name) == 0)
514 if (last->next == NULL)
520 /* Check the ignorelists. If *all three* tell us to ignore a volume, return
522 ignore_octets = ignorelist_match (cvp->il_octets, name);
523 ignore_operations = ignorelist_match (cvp->il_operations, name);
524 ignore_latency = ignorelist_match (cvp->il_latency, name);
525 if ((ignore_octets != 0) || (ignore_operations != 0)
526 || (ignore_latency != 0))
529 /* Not found: allocate. */
530 new = malloc (sizeof (*new));
533 memset (new, 0, sizeof (*new));
536 new->name = strdup (name);
537 if (new->name == NULL)
543 if (ignore_octets == 0)
544 new->flags |= CFG_VOLUME_PERF_IO;
545 if (ignore_operations == 0)
546 new->flags |= CFG_VOLUME_PERF_OPS;
547 if (ignore_latency == 0)
548 new->flags |= CFG_VOLUME_PERF_LATENCY;
550 /* Add to end of list. */
557 } /* }}} data_volume_perf_t *get_volume_perf */
560 * Various submit functions.
562 * They all eventually call "submit_values" which creates a value_list_t and
563 * dispatches it to the daemon.
565 static int submit_values (const char *host, /* {{{ */
566 const char *plugin_inst,
567 const char *type, const char *type_inst,
568 value_t *values, int values_len,
571 value_list_t vl = VALUE_LIST_INIT;
574 vl.values_len = values_len;
580 sstrncpy (vl.host, host, sizeof (vl.host));
582 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
583 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
584 if (plugin_inst != NULL)
585 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
586 sstrncpy (vl.type, type, sizeof (vl.type));
587 if (type_inst != NULL)
588 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
590 return (plugin_dispatch_values (&vl));
591 } /* }}} int submit_uint64 */
593 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
594 const char *type, const char *type_inst, counter_t val0, counter_t val1,
599 values[0].counter = val0;
600 values[1].counter = val1;
602 return (submit_values (host, plugin_inst, type, type_inst,
603 values, 2, timestamp));
604 } /* }}} int submit_two_counters */
606 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
607 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
613 return (submit_values (host, plugin_inst, type, type_inst,
615 } /* }}} int submit_counter */
617 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
618 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
623 values[0].gauge = val0;
624 values[1].gauge = val1;
626 return (submit_values (host, plugin_inst, type, type_inst,
627 values, 2, timestamp));
628 } /* }}} int submit_two_gauge */
630 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
631 const char *type, const char *type_inst, double d, time_t timestamp)
635 v.gauge = (gauge_t) d;
637 return (submit_values (host, plugin_inst, type, type_inst,
639 } /* }}} int submit_uint64 */
641 /* Calculate hit ratio from old and new counters and submit the resulting
642 * percentage. Used by "submit_wafl_data". */
643 static int submit_cache_ratio (const char *host, /* {{{ */
644 const char *plugin_inst,
645 const char *type_inst,
654 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
658 hits = new_hits - old_hits;
659 misses = new_misses - old_misses;
661 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
666 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
668 } /* }}} int submit_cache_ratio */
670 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
671 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
672 cfg_wafl_t *old_data, const cfg_wafl_t *new_data)
674 /* Submit requested counters */
675 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
676 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
677 submit_cache_ratio (hostname, instance, "name_cache_hit",
678 new_data->name_cache_hit, new_data->name_cache_miss,
679 old_data->name_cache_hit, old_data->name_cache_miss,
680 new_data->timestamp);
682 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
683 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
684 submit_cache_ratio (hostname, instance, "find_dir_hit",
685 new_data->find_dir_hit, new_data->find_dir_miss,
686 old_data->find_dir_hit, old_data->find_dir_miss,
687 new_data->timestamp);
689 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
690 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
691 submit_cache_ratio (hostname, instance, "buf_hash_hit",
692 new_data->buf_hash_hit, new_data->buf_hash_miss,
693 old_data->buf_hash_hit, old_data->buf_hash_miss,
694 new_data->timestamp);
696 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
697 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
698 submit_cache_ratio (hostname, instance, "inode_cache_hit",
699 new_data->inode_cache_hit, new_data->inode_cache_miss,
700 old_data->inode_cache_hit, old_data->inode_cache_miss,
701 new_data->timestamp);
703 /* Clear old HAVE_* flags */
704 old_data->flags &= ~HAVE_WAFL_ALL;
706 /* Copy all counters */
707 old_data->timestamp = new_data->timestamp;
708 old_data->name_cache_hit = new_data->name_cache_hit;
709 old_data->name_cache_miss = new_data->name_cache_miss;
710 old_data->find_dir_hit = new_data->find_dir_hit;
711 old_data->find_dir_miss = new_data->find_dir_miss;
712 old_data->buf_hash_hit = new_data->buf_hash_hit;
713 old_data->buf_hash_miss = new_data->buf_hash_miss;
714 old_data->inode_cache_hit = new_data->inode_cache_hit;
715 old_data->inode_cache_miss = new_data->inode_cache_miss;
717 /* Copy HAVE_* flags */
718 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
721 } /* }}} int submit_wafl_data */
723 /* Submits volume performance data to the daemon, taking care to honor and
724 * update flags appropriately. */
725 static int submit_volume_perf_data (const char *hostname, /* {{{ */
726 data_volume_perf_t *old_data,
727 const data_volume_perf_t *new_data)
729 char plugin_instance[DATA_MAX_NAME_LEN];
731 if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
734 ssnprintf (plugin_instance, sizeof (plugin_instance),
735 "volume-%s", old_data->name);
737 /* Check for and submit disk-octet values */
738 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
739 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
741 submit_two_counters (hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
742 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
745 /* Check for and submit disk-operations values */
746 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
747 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
749 submit_two_counters (hostname, plugin_instance, "disk_ops", /* type instance = */ NULL,
750 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
753 /* Check for, calculate and submit disk-latency values */
754 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
755 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
756 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
757 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
758 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
760 gauge_t latency_per_op_read;
761 gauge_t latency_per_op_write;
763 latency_per_op_read = NAN;
764 latency_per_op_write = NAN;
766 /* Check if a counter wrapped around. */
767 if ((new_data->read_ops > old_data->read_ops)
768 && (new_data->read_latency > old_data->read_latency))
770 uint64_t diff_ops_read;
771 uint64_t diff_latency_read;
773 diff_ops_read = new_data->read_ops - old_data->read_ops;
774 diff_latency_read = new_data->read_latency - old_data->read_latency;
776 if (diff_ops_read > 0)
777 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
780 if ((new_data->write_ops > old_data->write_ops)
781 && (new_data->write_latency > old_data->write_latency))
783 uint64_t diff_ops_write;
784 uint64_t diff_latency_write;
786 diff_ops_write = new_data->write_ops - old_data->write_ops;
787 diff_latency_write = new_data->write_latency - old_data->write_latency;
789 if (diff_ops_write > 0)
790 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
793 submit_two_gauge (hostname, plugin_instance, "disk_latency", /* type instance = */ NULL,
794 latency_per_op_read, latency_per_op_write, new_data->timestamp);
797 /* Clear all HAVE_* flags. */
798 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
800 /* Copy all counters */
801 old_data->timestamp = new_data->timestamp;
802 old_data->read_bytes = new_data->read_bytes;
803 old_data->write_bytes = new_data->write_bytes;
804 old_data->read_ops = new_data->read_ops;
805 old_data->write_ops = new_data->write_ops;
806 old_data->read_latency = new_data->read_latency;
807 old_data->write_latency = new_data->write_latency;
809 /* Copy the HAVE_* flags */
810 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
813 } /* }}} int submit_volume_perf_data */
818 * These functions are called with appropriate data returned by the libnetapp
819 * interface which is parsed and submitted with the above functions.
821 /* Data corresponding to <WAFL /> */
822 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
825 cfg_wafl_t perf_data;
826 const char *plugin_inst;
828 na_elem_t *instances;
830 na_elem_iter_t counter_iter;
832 memset (&perf_data, 0, sizeof (perf_data));
834 perf_data.timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
836 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
837 if (instances == NULL)
839 ERROR ("netapp plugin: cna_handle_wafl_data: "
840 "na_elem_child (\"instances\") failed.");
844 plugin_inst = na_child_get_string(instances, "name");
845 if (plugin_inst == NULL)
847 ERROR ("netapp plugin: cna_handle_wafl_data: "
848 "na_child_get_string (\"name\") failed.");
852 /* Iterate over all counters */
853 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
854 for (counter = na_iterator_next (&counter_iter);
856 counter = na_iterator_next (&counter_iter))
861 name = na_child_get_string(counter, "name");
865 value = na_child_get_uint64(counter, "value", UINT64_MAX);
866 if (value == UINT64_MAX)
869 if (!strcmp(name, "name_cache_hit")) {
870 perf_data.name_cache_hit = value;
871 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
872 } else if (!strcmp(name, "name_cache_miss")) {
873 perf_data.name_cache_miss = value;
874 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
875 } else if (!strcmp(name, "find_dir_hit")) {
876 perf_data.find_dir_hit = value;
877 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
878 } else if (!strcmp(name, "find_dir_miss")) {
879 perf_data.find_dir_miss = value;
880 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
881 } else if (!strcmp(name, "buf_hash_hit")) {
882 perf_data.buf_hash_hit = value;
883 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
884 } else if (!strcmp(name, "buf_hash_miss")) {
885 perf_data.buf_hash_miss = value;
886 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
887 } else if (!strcmp(name, "inode_cache_hit")) {
888 perf_data.inode_cache_hit = value;
889 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
890 } else if (!strcmp(name, "inode_cache_miss")) {
891 perf_data.inode_cache_miss = value;
892 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
894 DEBUG("netapp plugin: cna_handle_wafl_data: "
895 "Found unexpected child: %s", name);
899 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data));
900 } /* }}} void cna_handle_wafl_data */
902 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
909 if (cw->query != NULL)
912 cw->query = na_elem_new("perf-object-get-instances");
913 if (cw->query == NULL)
915 ERROR ("netapp plugin: na_elem_new failed.");
918 na_child_add_string (cw->query, "objectname", "wafl");
920 e = na_elem_new("counters");
923 na_elem_free (cw->query);
925 ERROR ("netapp plugin: na_elem_new failed.");
928 na_child_add_string(e, "counter", "name_cache_hit");
929 na_child_add_string(e, "counter", "name_cache_miss");
930 na_child_add_string(e, "counter", "find_dir_hit");
931 na_child_add_string(e, "counter", "find_dir_miss");
932 na_child_add_string(e, "counter", "buf_hash_hit");
933 na_child_add_string(e, "counter", "buf_hash_miss");
934 na_child_add_string(e, "counter", "inode_cache_hit");
935 na_child_add_string(e, "counter", "inode_cache_miss");
937 na_child_add(cw->query, e);
940 } /* }}} int cna_setup_wafl */
942 static int cna_query_wafl (host_config_t *host) /* {{{ */
951 /* If WAFL was not configured, return without doing anything. */
952 if (host->cfg_wafl == NULL)
956 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
959 status = cna_setup_wafl (host->cfg_wafl);
962 assert (host->cfg_wafl->query != NULL);
964 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
965 if (na_results_status (data) != NA_OK)
967 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed: %s",
968 na_results_reason (data));
973 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data);
976 host->cfg_wafl->interval.last_read = now;
980 } /* }}} int cna_query_wafl */
982 /* Data corresponding to <Disks /> */
983 static int cna_handle_disk_data (const char *hostname, /* {{{ */
984 cfg_disk_t *cfg_disk, na_elem_t *data)
987 na_elem_t *instances;
989 na_elem_iter_t instance_iter;
990 disk_t *worst_disk = NULL;
992 if ((cfg_disk == NULL) || (data == NULL))
995 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
997 instances = na_elem_child (data, "instances");
998 if (instances == NULL)
1000 ERROR ("netapp plugin: cna_handle_disk_data: "
1001 "na_elem_child (\"instances\") failed.");
1005 /* Iterate over all children */
1006 instance_iter = na_child_iterator (instances);
1007 for (instance = na_iterator_next (&instance_iter);
1009 instance = na_iterator_next(&instance_iter))
1014 na_elem_iter_t counter_iterator;
1017 memset (&new_data, 0, sizeof (new_data));
1018 new_data.timestamp = timestamp;
1019 new_data.disk_busy_percent = NAN;
1021 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1022 if (old_data == NULL)
1025 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1026 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1027 for (counter = na_iterator_next(&counter_iterator);
1029 counter = na_iterator_next(&counter_iterator))
1034 name = na_child_get_string(counter, "name");
1038 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1039 if (value == UINT64_MAX)
1042 if (strcmp(name, "disk_busy") == 0)
1044 new_data.disk_busy = value;
1045 new_data.flags |= HAVE_DISK_BUSY;
1047 else if (strcmp(name, "base_for_disk_busy") == 0)
1049 new_data.base_for_disk_busy = value;
1050 new_data.flags |= HAVE_DISK_BASE;
1054 DEBUG ("netapp plugin: cna_handle_disk_data: "
1055 "Counter not handled: %s = %"PRIu64,
1060 /* If all required counters are available and did not just wrap around,
1061 * calculate the busy percentage. Otherwise, the value is initialized to
1062 * NAN at the top of the for-loop. */
1063 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1064 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1065 && (new_data.disk_busy >= old_data->disk_busy)
1066 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1071 busy_diff = new_data.disk_busy - old_data->disk_busy;
1072 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1074 new_data.disk_busy_percent = 100.0
1075 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1078 /* Clear HAVE_* flags */
1079 old_data->flags &= ~HAVE_DISK_ALL;
1082 old_data->timestamp = new_data.timestamp;
1083 old_data->disk_busy = new_data.disk_busy;
1084 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1085 old_data->disk_busy_percent = new_data.disk_busy_percent;
1088 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1090 if ((worst_disk == NULL)
1091 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1092 worst_disk = old_data;
1093 } /* for (all disks) */
1095 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1096 submit_double (hostname, "system", "percent", "disk_busy",
1097 worst_disk->disk_busy_percent, timestamp);
1100 } /* }}} int cna_handle_disk_data */
1102 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1109 if (cd->query != NULL)
1112 cd->query = na_elem_new ("perf-object-get-instances");
1113 if (cd->query == NULL)
1115 ERROR ("netapp plugin: na_elem_new failed.");
1118 na_child_add_string (cd->query, "objectname", "disk");
1120 e = na_elem_new("counters");
1123 na_elem_free (cd->query);
1125 ERROR ("netapp plugin: na_elem_new failed.");
1128 na_child_add_string(e, "counter", "disk_busy");
1129 na_child_add_string(e, "counter", "base_for_disk_busy");
1130 na_child_add(cd->query, e);
1133 } /* }}} int cna_setup_disk */
1135 static int cna_query_disk (host_config_t *host) /* {{{ */
1144 /* If the user did not configure disk statistics, return without doing
1146 if (host->cfg_disk == NULL)
1150 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1153 status = cna_setup_disk (host->cfg_disk);
1156 assert (host->cfg_disk->query != NULL);
1158 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1159 if (na_results_status (data) != NA_OK)
1161 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed: %s",
1162 na_results_reason (data));
1163 na_elem_free (data);
1167 status = cna_handle_disk_data (host->name, host->cfg_disk, data);
1170 host->cfg_disk->interval.last_read = now;
1172 na_elem_free (data);
1174 } /* }}} int cna_query_disk */
1176 /* Data corresponding to <VolumePerf /> */
1177 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1178 cfg_volume_perf_t *cvp, na_elem_t *data)
1181 na_elem_t *elem_instances;
1182 na_elem_iter_t iter_instances;
1183 na_elem_t *elem_instance;
1185 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
1187 elem_instances = na_elem_child(data, "instances");
1188 if (elem_instances == NULL)
1190 ERROR ("netapp plugin: handle_volume_perf_data: "
1191 "na_elem_child (\"instances\") failed.");
1195 iter_instances = na_child_iterator (elem_instances);
1196 for (elem_instance = na_iterator_next(&iter_instances);
1197 elem_instance != NULL;
1198 elem_instance = na_iterator_next(&iter_instances))
1202 data_volume_perf_t perf_data;
1203 data_volume_perf_t *v;
1205 na_elem_t *elem_counters;
1206 na_elem_iter_t iter_counters;
1207 na_elem_t *elem_counter;
1209 memset (&perf_data, 0, sizeof (perf_data));
1210 perf_data.timestamp = timestamp;
1212 name = na_child_get_string (elem_instance, "name");
1216 /* get_volume_perf may return NULL if this volume is to be ignored. */
1217 v = get_volume_perf (cvp, name);
1221 elem_counters = na_elem_child (elem_instance, "counters");
1222 if (elem_counters == NULL)
1225 iter_counters = na_child_iterator (elem_counters);
1226 for (elem_counter = na_iterator_next(&iter_counters);
1227 elem_counter != NULL;
1228 elem_counter = na_iterator_next(&iter_counters))
1233 name = na_child_get_string (elem_counter, "name");
1237 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1238 if (value == UINT64_MAX)
1241 if (!strcmp(name, "read_data")) {
1242 perf_data.read_bytes = value;
1243 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1244 } else if (!strcmp(name, "write_data")) {
1245 perf_data.write_bytes = value;
1246 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1247 } else if (!strcmp(name, "read_ops")) {
1248 perf_data.read_ops = value;
1249 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1250 } else if (!strcmp(name, "write_ops")) {
1251 perf_data.write_ops = value;
1252 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1253 } else if (!strcmp(name, "read_latency")) {
1254 perf_data.read_latency = value;
1255 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1256 } else if (!strcmp(name, "write_latency")) {
1257 perf_data.write_latency = value;
1258 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1260 } /* for (elem_counter) */
1262 submit_volume_perf_data (hostname, v, &perf_data);
1263 } /* for (volume) */
1266 } /* }}} int cna_handle_volume_perf_data */
1268 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1275 if (cd->query != NULL)
1278 cd->query = na_elem_new ("perf-object-get-instances");
1279 if (cd->query == NULL)
1281 ERROR ("netapp plugin: na_elem_new failed.");
1284 na_child_add_string (cd->query, "objectname", "volume");
1286 e = na_elem_new("counters");
1289 na_elem_free (cd->query);
1291 ERROR ("netapp plugin: na_elem_new failed.");
1294 na_child_add_string(e, "counter", "read_ops");
1295 na_child_add_string(e, "counter", "write_ops");
1296 na_child_add_string(e, "counter", "read_data");
1297 na_child_add_string(e, "counter", "write_data");
1298 na_child_add_string(e, "counter", "read_latency");
1299 na_child_add_string(e, "counter", "write_latency");
1300 na_child_add(cd->query, e);
1303 } /* }}} int cna_setup_volume_perf */
1305 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1314 /* If the user did not configure volume performance statistics, return
1315 * without doing anything. */
1316 if (host->cfg_volume_perf == NULL)
1320 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1323 status = cna_setup_volume_perf (host->cfg_volume_perf);
1326 assert (host->cfg_volume_perf->query != NULL);
1328 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1329 if (na_results_status (data) != NA_OK)
1331 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed: %s",
1332 na_results_reason (data));
1333 na_elem_free (data);
1337 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data);
1340 host->cfg_volume_perf->interval.last_read = now;
1342 na_elem_free (data);
1344 } /* }}} int cna_query_volume_perf */
1346 /* Data corresponding to <VolumeUsage /> */
1347 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1348 cfg_volume_usage_t *cfg_volume)
1350 data_volume_usage_t *v;
1352 for (v = cfg_volume->volumes; v != NULL; v = v->next)
1354 char plugin_instance[DATA_MAX_NAME_LEN];
1356 uint64_t norm_used = v->norm_used;
1357 uint64_t norm_free = v->norm_free;
1358 uint64_t sis_saved = v->sis_saved;
1359 uint64_t snap_reserve_used = 0;
1360 uint64_t snap_reserve_free = v->snap_reserved;
1361 uint64_t snap_norm_used = v->snap_used;
1363 ssnprintf (plugin_instance, sizeof (plugin_instance),
1364 "volume-%s", v->name);
1366 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD)) {
1367 if (v->snap_reserved > v->snap_used) {
1368 snap_reserve_free = v->snap_reserved - v->snap_used;
1369 snap_reserve_used = v->snap_used;
1372 snap_reserve_free = 0;
1373 snap_reserve_used = v->snap_reserved;
1374 snap_norm_used = v->snap_used - v->snap_reserved;
1378 /* The space used by snapshots but not reserved for them is included in
1379 * both, norm_used and snap_norm_used. If possible, subtract this here. */
1380 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED))
1382 if (norm_used >= snap_norm_used)
1383 norm_used -= snap_norm_used;
1386 ERROR ("netapp plugin: (norm_used = %"PRIu64") < (snap_norm_used = "
1387 "%"PRIu64"). Invalidating both.",
1388 norm_used, snap_norm_used);
1389 v->flags &= ~(HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED);
1393 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1394 submit_double (hostname, /* plugin instance = */ plugin_instance,
1395 "df_complex", "free",
1396 (double) norm_free, /* timestamp = */ 0);
1398 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1399 submit_double (hostname, /* plugin instance = */ plugin_instance,
1400 "df_complex", "sis_saved",
1401 (double) sis_saved, /* timestamp = */ 0);
1403 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1404 submit_double (hostname, /* plugin instance = */ plugin_instance,
1405 "df_complex", "used",
1406 (double) norm_used, /* timestamp = */ 0);
1408 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1409 submit_double (hostname, /* plugin instance = */ plugin_instance,
1410 "df_complex", "snap_reserved",
1411 (double) snap_reserve_free, /* timestamp = */ 0);
1413 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
1414 submit_double (hostname, /* plugin instance = */ plugin_instance,
1415 "df_complex", "snap_reserve_used",
1416 (double) snap_reserve_used, /* timestamp = */ 0);
1418 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1419 submit_double (hostname, /* plugin instance = */ plugin_instance,
1420 "df_complex", "snap_normal_used",
1421 (double) snap_norm_used, /* timestamp = */ 0);
1423 /* Clear all the HAVE_* flags */
1424 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1425 } /* for (v = cfg_volume->volumes) */
1428 } /* }}} int cna_submit_volume_usage_data */
1430 /* Switch the state of a volume between online and offline and send out a
1432 static int cna_change_volume_status (const char *hostname, /* {{{ */
1433 data_volume_usage_t *v)
1437 memset (&n, 0, sizeof (&n));
1438 n.time = time (NULL);
1439 sstrncpy (n.host, hostname, sizeof (n.host));
1440 sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
1441 sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance));
1443 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
1444 n.severity = NOTIF_OKAY;
1445 ssnprintf (n.message, sizeof (n.message),
1446 "Volume %s is now online.", v->name);
1447 v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
1449 n.severity = NOTIF_WARNING;
1450 ssnprintf (n.message, sizeof (n.message),
1451 "Volume %s is now offline.", v->name);
1452 v->flags |= IS_VOLUME_USAGE_OFFLINE;
1455 return (plugin_dispatch_notification (&n));
1456 } /* }}} int cna_change_volume_status */
1458 static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
1459 data_volume_usage_t *v)
1461 uint64_t snap_used = 0, value;
1462 na_elem_t *data, *elem_snap, *elem_snapshots;
1463 na_elem_iter_t iter_snap;
1465 data = na_server_invoke_elem(host->srv, v->snap_query);
1466 if (na_results_status(data) != NA_OK)
1468 if (na_results_errno(data) == EVOLUMEOFFLINE) {
1469 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
1470 cna_change_volume_status (host->name, v);
1472 ERROR ("netapp plugin: cna_handle_volume_snap_usage: na_server_invoke_elem for "
1473 "volume \"%s\" failed with error %d: %s", v->name,
1474 na_results_errno(data), na_results_reason(data));
1480 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0)
1481 cna_change_volume_status (host->name, v);
1483 elem_snapshots = na_elem_child (data, "snapshots");
1484 if (elem_snapshots == NULL)
1486 ERROR ("netapp plugin: cna_handle_volume_snap_usage: "
1487 "na_elem_child (\"snapshots\") failed.");
1492 iter_snap = na_child_iterator (elem_snapshots);
1493 for (elem_snap = na_iterator_next (&iter_snap);
1495 elem_snap = na_iterator_next (&iter_snap))
1497 value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
1498 /* "cumulative-total" is the total size of the oldest snapshot plus all
1499 * newer ones in blocks (1KB). We therefore are looking for the highest
1500 * number of all snapshots - that's the size required for the snapshots. */
1501 if (value > snap_used)
1504 na_elem_free (data);
1505 /* snap_used is in 1024 byte blocks */
1506 v->snap_used = snap_used * 1024;
1507 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1508 } /* }}} void cna_handle_volume_snap_usage */
1510 static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
1511 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1513 na_elem_t *elem_volume;
1514 na_elem_t *elem_volumes;
1515 na_elem_iter_t iter_volume;
1517 elem_volumes = na_elem_child (data, "volumes");
1518 if (elem_volumes == NULL)
1520 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1521 "na_elem_child (\"volumes\") failed.");
1525 iter_volume = na_child_iterator (elem_volumes);
1526 for (elem_volume = na_iterator_next (&iter_volume);
1527 elem_volume != NULL;
1528 elem_volume = na_iterator_next (&iter_volume))
1530 const char *volume_name, *state;
1532 data_volume_usage_t *v;
1536 const char *sis_state;
1537 uint64_t sis_saved_reported;
1539 volume_name = na_child_get_string (elem_volume, "name");
1540 if (volume_name == NULL)
1543 state = na_child_get_string (elem_volume, "state");
1544 if ((state == NULL) || (strcmp(state, "online") != 0))
1547 /* get_volume_usage may return NULL if the volume is to be ignored. */
1548 v = get_volume_usage (cfg_volume, volume_name);
1552 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1553 cna_handle_volume_snap_usage(host, v);
1555 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1558 /* 2^4 exa-bytes? This will take a while ;) */
1559 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1560 if (value != UINT64_MAX) {
1561 v->norm_free = value;
1562 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1565 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1566 if (value != UINT64_MAX) {
1567 v->norm_used = value;
1568 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1571 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1572 if (value != UINT64_MAX) {
1573 /* 1 block == 1024 bytes as per API docs */
1574 v->snap_reserved = 1024 * value;
1575 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1578 sis = na_elem_child(elem_volume, "sis");
1582 sis_state = na_child_get_string(sis, "state");
1583 if (sis_state == NULL)
1586 /* If SIS is not enabled, there's nothing left to do for this volume. */
1587 if (strcmp ("enabled", sis_state) != 0)
1590 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1591 if (sis_saved_reported == UINT64_MAX)
1594 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1595 if ((sis_saved_reported >> 32) != 0) {
1596 /* In case they ever fix this bug. */
1597 v->sis_saved = sis_saved_reported;
1598 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1599 } else { /* really hacky work-around code. {{{ */
1600 uint64_t sis_saved_percent;
1601 uint64_t sis_saved_guess;
1602 uint64_t overflow_guess;
1603 uint64_t guess1, guess2, guess3;
1605 /* Check if we have v->norm_used. Without it, we cannot calculate
1606 * sis_saved_guess. */
1607 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1610 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1611 if (sis_saved_percent > 100)
1614 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1615 * will hopefully be fixed in later versions. To work around the bug, try
1616 * to figure out how often the 32bit integer wrapped around by using the
1617 * "percentage-saved" value. Because the percentage is in the range
1618 * [0-100], this should work as long as the saved space does not exceed
1620 /* percentage-saved = size-saved / (size-saved + size-used) */
1621 if (sis_saved_percent < 100)
1622 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1624 sis_saved_guess = v->norm_used;
1626 overflow_guess = sis_saved_guess >> 32;
1627 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1628 guess2 = (overflow_guess << 32) + sis_saved_reported;
1629 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1631 if (sis_saved_guess < guess2) {
1632 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1633 v->sis_saved = guess1;
1635 v->sis_saved = guess2;
1637 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1638 v->sis_saved = guess2;
1640 v->sis_saved = guess3;
1642 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1643 } /* }}} end of 32-bit workaround */
1644 } /* for (elem_volume) */
1646 return (cna_submit_volume_usage_data (host->name, cfg_volume));
1647 } /* }}} int cna_handle_volume_usage_data */
1649 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1654 if (cvu->query != NULL)
1657 cvu->query = na_elem_new ("volume-list-info");
1658 if (cvu->query == NULL)
1660 ERROR ("netapp plugin: na_elem_new failed.");
1665 } /* }}} int cna_setup_volume_usage */
1667 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1676 /* If the user did not configure volume_usage statistics, return without
1677 * doing anything. */
1678 if (host->cfg_volume_usage == NULL)
1682 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1685 status = cna_setup_volume_usage (host->cfg_volume_usage);
1688 assert (host->cfg_volume_usage->query != NULL);
1690 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1691 if (na_results_status (data) != NA_OK)
1693 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed: %s",
1694 na_results_reason (data));
1695 na_elem_free (data);
1699 status = cna_handle_volume_usage_data (host, host->cfg_volume_usage, data);
1702 host->cfg_volume_usage->interval.last_read = now;
1704 na_elem_free (data);
1706 } /* }}} int cna_query_volume_usage */
1708 /* Data corresponding to <System /> */
1709 static int cna_handle_system_data (const char *hostname, /* {{{ */
1710 cfg_system_t *cfg_system, na_elem_t *data)
1712 na_elem_t *instances;
1714 na_elem_iter_t counter_iter;
1716 counter_t disk_read = 0, disk_written = 0;
1717 counter_t net_recv = 0, net_sent = 0;
1718 counter_t cpu_busy = 0, cpu_total = 0;
1719 uint32_t counter_flags = 0;
1721 const char *instance;
1724 timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
1726 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1727 if (instances == NULL)
1729 ERROR ("netapp plugin: cna_handle_system_data: "
1730 "na_elem_child (\"instances\") failed.");
1734 instance = na_child_get_string (instances, "name");
1735 if (instance == NULL)
1737 ERROR ("netapp plugin: cna_handle_system_data: "
1738 "na_child_get_string (\"name\") failed.");
1742 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
1743 for (counter = na_iterator_next (&counter_iter);
1745 counter = na_iterator_next (&counter_iter))
1750 name = na_child_get_string(counter, "name");
1754 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1755 if (value == UINT64_MAX)
1758 if (!strcmp(name, "disk_data_read")) {
1759 disk_read = (counter_t) (value * 1024);
1760 counter_flags |= 0x01;
1761 } else if (!strcmp(name, "disk_data_written")) {
1762 disk_written = (counter_t) (value * 1024);
1763 counter_flags |= 0x02;
1764 } else if (!strcmp(name, "net_data_recv")) {
1765 net_recv = (counter_t) (value * 1024);
1766 counter_flags |= 0x04;
1767 } else if (!strcmp(name, "net_data_sent")) {
1768 net_sent = (counter_t) (value * 1024);
1769 counter_flags |= 0x08;
1770 } else if (!strcmp(name, "cpu_busy")) {
1771 cpu_busy = (counter_t) value;
1772 counter_flags |= 0x10;
1773 } else if (!strcmp(name, "cpu_elapsed_time")) {
1774 cpu_total = (counter_t) value;
1775 counter_flags |= 0x20;
1776 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1777 && (value > 0) && (strlen(name) > 4)
1778 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1779 submit_counter (hostname, instance, "disk_ops_complex", name,
1780 (counter_t) value, timestamp);
1782 } /* for (counter) */
1784 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1785 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
1786 submit_two_counters (hostname, instance, "disk_octets", NULL,
1787 disk_read, disk_written, timestamp);
1789 if ((cfg_system->flags & CFG_SYSTEM_NET)
1790 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
1791 submit_two_counters (hostname, instance, "if_octets", NULL,
1792 net_recv, net_sent, timestamp);
1794 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1795 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
1797 submit_counter (hostname, instance, "cpu", "system",
1798 cpu_busy, timestamp);
1799 submit_counter (hostname, instance, "cpu", "idle",
1800 cpu_total - cpu_busy, timestamp);
1804 } /* }}} int cna_handle_system_data */
1806 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
1811 if (cs->query != NULL)
1814 cs->query = na_elem_new ("perf-object-get-instances");
1815 if (cs->query == NULL)
1817 ERROR ("netapp plugin: na_elem_new failed.");
1820 na_child_add_string (cs->query, "objectname", "system");
1823 } /* }}} int cna_setup_system */
1825 static int cna_query_system (host_config_t *host) /* {{{ */
1834 /* If system statistics were not configured, return without doing anything. */
1835 if (host->cfg_system == NULL)
1839 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
1842 status = cna_setup_system (host->cfg_system);
1845 assert (host->cfg_system->query != NULL);
1847 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
1848 if (na_results_status (data) != NA_OK)
1850 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed: %s",
1851 na_results_reason (data));
1852 na_elem_free (data);
1856 status = cna_handle_system_data (host->name, host->cfg_system, data);
1859 host->cfg_system->interval.last_read = now;
1861 na_elem_free (data);
1863 } /* }}} int cna_query_system */
1866 * Configuration handling
1868 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1869 * is false. On error, the flag-field is not changed. */
1870 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1871 uint32_t *flags, uint32_t flag)
1873 if ((ci == NULL) || (flags == NULL))
1876 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1878 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1883 if (ci->values[0].value.boolean)
1889 } /* }}} int cna_config_bool_to_flag */
1891 /* Handling of the "Interval" option which is allowed in every block. */
1892 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1893 cna_interval_t *out_interval)
1897 if ((ci == NULL) || (out_interval == NULL))
1900 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1902 WARNING ("netapp plugin: The `Interval' option needs exactly one numeric argument.");
1906 tmp = (time_t) (ci->values[0].value.number + .5);
1909 WARNING ("netapp plugin: The `Interval' option needs a positive integer argument.");
1913 out_interval->interval = tmp;
1914 out_interval->last_read = 0;
1917 } /* }}} int cna_config_get_interval */
1919 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1920 * <VolumePerf /> block. */
1921 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
1922 const oconfig_item_t *ci)
1927 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1929 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1934 name = ci->values[0].value.string;
1936 if (strcasecmp ("GetIO", ci->key) == 0)
1937 il = cvp->il_octets;
1938 else if (strcasecmp ("GetOps", ci->key) == 0)
1939 il = cvp->il_operations;
1940 else if (strcasecmp ("GetLatency", ci->key) == 0)
1941 il = cvp->il_latency;
1945 ignorelist_add (il, name);
1946 } /* }}} void cna_config_volume_perf_option */
1948 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
1949 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
1950 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
1951 const oconfig_item_t *ci)
1955 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1957 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1962 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
1963 il = cvp->il_octets;
1964 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
1965 il = cvp->il_operations;
1966 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
1967 il = cvp->il_latency;
1971 if (ci->values[0].value.boolean)
1972 ignorelist_set_invert (il, /* invert = */ 0);
1974 ignorelist_set_invert (il, /* invert = */ 1);
1975 } /* }}} void cna_config_volume_perf_default */
1977 /* Corresponds to a <Disks /> block */
1982 * IgnoreSelectedIO false
1986 * IgnoreSelectedOps false
1990 * IgnoreSelectedLatency false
1993 /* Corresponds to a <VolumePerf /> block */
1994 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
1995 const oconfig_item_t *ci)
1997 cfg_volume_perf_t *cfg_volume_perf;
2000 if ((host == NULL) || (ci == NULL))
2003 if (host->cfg_volume_perf == NULL)
2005 cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
2006 if (cfg_volume_perf == NULL)
2008 memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
2010 /* Set default flags */
2011 cfg_volume_perf->query = NULL;
2012 cfg_volume_perf->volumes = NULL;
2014 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
2015 if (cfg_volume_perf->il_octets == NULL)
2017 sfree (cfg_volume_perf);
2021 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
2022 if (cfg_volume_perf->il_operations == NULL)
2024 ignorelist_free (cfg_volume_perf->il_octets);
2025 sfree (cfg_volume_perf);
2029 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
2030 if (cfg_volume_perf->il_latency == NULL)
2032 ignorelist_free (cfg_volume_perf->il_octets);
2033 ignorelist_free (cfg_volume_perf->il_operations);
2034 sfree (cfg_volume_perf);
2038 host->cfg_volume_perf = cfg_volume_perf;
2040 cfg_volume_perf = host->cfg_volume_perf;
2042 for (i = 0; i < ci->children_num; ++i) {
2043 oconfig_item_t *item = ci->children + i;
2045 /* if (!item || !item->key || !*item->key) continue; */
2046 if (strcasecmp(item->key, "Interval") == 0)
2047 cna_config_get_interval (item, &cfg_volume_perf->interval);
2048 else if (!strcasecmp(item->key, "GetIO"))
2049 cna_config_volume_perf_option (cfg_volume_perf, item);
2050 else if (!strcasecmp(item->key, "GetOps"))
2051 cna_config_volume_perf_option (cfg_volume_perf, item);
2052 else if (!strcasecmp(item->key, "GetLatency"))
2053 cna_config_volume_perf_option (cfg_volume_perf, item);
2054 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
2055 cna_config_volume_perf_default (cfg_volume_perf, item);
2056 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
2057 cna_config_volume_perf_default (cfg_volume_perf, item);
2058 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2059 cna_config_volume_perf_default (cfg_volume_perf, item);
2061 WARNING ("netapp plugin: The option %s is not allowed within "
2062 "`VolumePerf' blocks.", item->key);
2066 } /* }}} int cna_config_volume_performance */
2068 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2069 * <VolumeUsage /> block. */
2070 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
2071 const oconfig_item_t *ci)
2076 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2078 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2083 name = ci->values[0].value.string;
2085 if (strcasecmp ("GetCapacity", ci->key) == 0)
2086 il = cvu->il_capacity;
2087 else if (strcasecmp ("GetSnapshot", ci->key) == 0)
2088 il = cvu->il_snapshot;
2092 ignorelist_add (il, name);
2093 } /* }}} void cna_config_volume_usage_option */
2095 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2096 * options within a <VolumeUsage /> block. */
2097 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
2098 const oconfig_item_t *ci)
2102 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2104 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2109 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2110 il = cvu->il_capacity;
2111 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2112 il = cvu->il_snapshot;
2116 if (ci->values[0].value.boolean)
2117 ignorelist_set_invert (il, /* invert = */ 0);
2119 ignorelist_set_invert (il, /* invert = */ 1);
2120 } /* }}} void cna_config_volume_usage_default */
2122 /* Corresponds to a <Disks /> block */
2123 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2124 cfg_disk_t *cfg_disk;
2127 if ((host == NULL) || (ci == NULL))
2130 if (host->cfg_disk == NULL)
2132 cfg_disk = malloc (sizeof (*cfg_disk));
2133 if (cfg_disk == NULL)
2135 memset (cfg_disk, 0, sizeof (*cfg_disk));
2137 /* Set default flags */
2138 cfg_disk->flags = CFG_DISK_ALL;
2139 cfg_disk->query = NULL;
2140 cfg_disk->disks = NULL;
2142 host->cfg_disk = cfg_disk;
2144 cfg_disk = host->cfg_disk;
2146 for (i = 0; i < ci->children_num; ++i) {
2147 oconfig_item_t *item = ci->children + i;
2149 /* if (!item || !item->key || !*item->key) continue; */
2150 if (strcasecmp(item->key, "Interval") == 0)
2151 cna_config_get_interval (item, &cfg_disk->interval);
2152 else if (strcasecmp(item->key, "GetBusy") == 0)
2153 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2156 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2158 NOTICE ("netapp plugin: All disk related values have been disabled. "
2159 "Collection of per-disk data will be disabled entirely.");
2160 free_cfg_disk (host->cfg_disk);
2161 host->cfg_disk = NULL;
2165 } /* }}} int cna_config_disk */
2167 /* Corresponds to a <WAFL /> block */
2168 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2170 cfg_wafl_t *cfg_wafl;
2173 if ((host == NULL) || (ci == NULL))
2176 if (host->cfg_wafl == NULL)
2178 cfg_wafl = malloc (sizeof (*cfg_wafl));
2179 if (cfg_wafl == NULL)
2181 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
2183 /* Set default flags */
2184 cfg_wafl->flags = CFG_WAFL_ALL;
2186 host->cfg_wafl = cfg_wafl;
2188 cfg_wafl = host->cfg_wafl;
2190 for (i = 0; i < ci->children_num; ++i) {
2191 oconfig_item_t *item = ci->children + i;
2193 if (strcasecmp(item->key, "Interval") == 0)
2194 cna_config_get_interval (item, &cfg_wafl->interval);
2195 else if (!strcasecmp(item->key, "GetNameCache"))
2196 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2197 else if (!strcasecmp(item->key, "GetDirCache"))
2198 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2199 else if (!strcasecmp(item->key, "GetBufferCache"))
2200 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2201 else if (!strcasecmp(item->key, "GetInodeCache"))
2202 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2204 WARNING ("netapp plugin: The %s config option is not allowed within "
2205 "`WAFL' blocks.", item->key);
2208 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2210 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2211 "Collection of WAFL data will be disabled entirely.");
2212 free_cfg_wafl (host->cfg_wafl);
2213 host->cfg_wafl = NULL;
2217 } /* }}} int cna_config_wafl */
2221 * GetCapacity "vol0"
2222 * GetCapacity "vol1"
2223 * GetCapacity "vol2"
2224 * GetCapacity "vol3"
2225 * GetCapacity "vol4"
2226 * IgnoreSelectedCapacity false
2228 * GetSnapshot "vol0"
2229 * GetSnapshot "vol3"
2230 * GetSnapshot "vol4"
2231 * GetSnapshot "vol7"
2232 * IgnoreSelectedSnapshot false
2235 /* Corresponds to a <VolumeUsage /> block */
2236 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2237 const oconfig_item_t *ci)
2239 cfg_volume_usage_t *cfg_volume_usage;
2242 if ((host == NULL) || (ci == NULL))
2245 if (host->cfg_volume_usage == NULL)
2247 cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
2248 if (cfg_volume_usage == NULL)
2250 memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
2252 /* Set default flags */
2253 cfg_volume_usage->query = NULL;
2254 cfg_volume_usage->volumes = NULL;
2256 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2257 if (cfg_volume_usage->il_capacity == NULL)
2259 sfree (cfg_volume_usage);
2263 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2264 if (cfg_volume_usage->il_snapshot == NULL)
2266 ignorelist_free (cfg_volume_usage->il_capacity);
2267 sfree (cfg_volume_usage);
2271 host->cfg_volume_usage = cfg_volume_usage;
2273 cfg_volume_usage = host->cfg_volume_usage;
2275 for (i = 0; i < ci->children_num; ++i) {
2276 oconfig_item_t *item = ci->children + i;
2278 /* if (!item || !item->key || !*item->key) continue; */
2279 if (strcasecmp(item->key, "Interval") == 0)
2280 cna_config_get_interval (item, &cfg_volume_usage->interval);
2281 else if (!strcasecmp(item->key, "GetCapacity"))
2282 cna_config_volume_usage_option (cfg_volume_usage, item);
2283 else if (!strcasecmp(item->key, "GetSnapshot"))
2284 cna_config_volume_usage_option (cfg_volume_usage, item);
2285 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2286 cna_config_volume_usage_default (cfg_volume_usage, item);
2287 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2288 cna_config_volume_usage_default (cfg_volume_usage, item);
2290 WARNING ("netapp plugin: The option %s is not allowed within "
2291 "`VolumeUsage' blocks.", item->key);
2295 } /* }}} int cna_config_volume_usage */
2297 /* Corresponds to a <System /> block */
2298 static int cna_config_system (host_config_t *host, /* {{{ */
2301 cfg_system_t *cfg_system;
2304 if ((host == NULL) || (ci == NULL))
2307 if (host->cfg_system == NULL)
2309 cfg_system = malloc (sizeof (*cfg_system));
2310 if (cfg_system == NULL)
2312 memset (cfg_system, 0, sizeof (*cfg_system));
2314 /* Set default flags */
2315 cfg_system->flags = CFG_SYSTEM_ALL;
2316 cfg_system->query = NULL;
2318 host->cfg_system = cfg_system;
2320 cfg_system = host->cfg_system;
2322 for (i = 0; i < ci->children_num; ++i) {
2323 oconfig_item_t *item = ci->children + i;
2325 if (strcasecmp(item->key, "Interval") == 0) {
2326 cna_config_get_interval (item, &cfg_system->interval);
2327 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2328 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2329 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2330 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2331 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2332 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2333 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2334 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2336 WARNING ("netapp plugin: The %s config option is not allowed within "
2337 "`System' blocks.", item->key);
2341 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2343 NOTICE ("netapp plugin: All system related values have been disabled. "
2344 "Collection of system data will be disabled entirely.");
2345 free_cfg_system (host->cfg_system);
2346 host->cfg_system = NULL;
2350 } /* }}} int cna_config_system */
2352 /* Corresponds to a <Host /> block. */
2353 static host_config_t *cna_config_host (const oconfig_item_t *ci) /* {{{ */
2355 oconfig_item_t *item;
2356 host_config_t *host;
2360 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2361 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
2365 host = malloc(sizeof(*host));
2366 memset (host, 0, sizeof (*host));
2368 host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2370 host->username = NULL;
2371 host->password = NULL;
2373 host->cfg_wafl = NULL;
2374 host->cfg_disk = NULL;
2375 host->cfg_volume_perf = NULL;
2376 host->cfg_volume_usage = NULL;
2377 host->cfg_system = NULL;
2379 status = cf_util_get_string (ci, &host->name);
2386 for (i = 0; i < ci->children_num; ++i) {
2387 item = ci->children + i;
2391 if (!strcasecmp(item->key, "Address")) {
2392 status = cf_util_get_string (item, &host->host);
2393 } else if (!strcasecmp(item->key, "Port")) {
2396 tmp = cf_util_get_port_number (item);
2399 } else if (!strcasecmp(item->key, "Protocol")) {
2400 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"))) {
2401 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2404 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2405 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2406 } else if (!strcasecmp(item->key, "User")) {
2407 status = cf_util_get_string (item, &host->username);
2408 } else if (!strcasecmp(item->key, "Password")) {
2409 status = cf_util_get_string (item, &host->password);
2410 } else if (!strcasecmp(item->key, "Interval")) {
2411 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) {
2412 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
2415 host->interval = item->values[0].value.number;
2416 } else if (!strcasecmp(item->key, "WAFL")) {
2417 cna_config_wafl(host, item);
2418 } else if (!strcasecmp(item->key, "Disks")) {
2419 cna_config_disk(host, item);
2420 } else if (!strcasecmp(item->key, "VolumePerf")) {
2421 cna_config_volume_performance(host, item);
2422 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2423 cna_config_volume_usage(host, item);
2424 } else if (!strcasecmp(item->key, "System")) {
2425 cna_config_system(host, item);
2427 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
2428 item->key, ci->values[0].value.string);
2435 if (host->host == NULL)
2436 host->host = strdup (host->name);
2438 if (host->host == NULL)
2441 if (host->port <= 0)
2442 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2444 if ((host->username == NULL) || (host->password == NULL)) {
2445 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2446 "Ignoring host block.", host->name);
2452 free_host_config (host);
2457 } /* }}} host_config_t *cna_config_host */
2460 * Callbacks registered with the daemon
2462 * Pretty standard stuff here.
2464 static int cna_init_host (host_config_t *host) /* {{{ */
2469 if (host->srv != NULL)
2472 /* Request version 1.1 of the ONTAP API */
2473 host->srv = na_server_open(host->host,
2474 /* major version = */ 1, /* minor version = */ 1);
2475 if (host->srv == NULL) {
2476 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
2480 na_server_set_transport_type(host->srv, host->protocol,
2481 /* transportarg = */ NULL);
2482 na_server_set_port(host->srv, host->port);
2483 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
2484 na_server_adminuser(host->srv, host->username, host->password);
2485 na_server_set_timeout(host->srv, 5 /* seconds */);
2488 } /* }}} int cna_init_host */
2490 static int cna_init (void) /* {{{ */
2494 memset (err, 0, sizeof (err));
2495 if (!na_startup(err, sizeof(err))) {
2496 err[sizeof (err) - 1] = 0;
2497 ERROR("netapp plugin: Error initializing netapp API: %s", err);
2502 } /* }}} cna_init */
2504 static int cna_read (user_data_t *ud) { /* {{{ */
2505 host_config_t *host;
2508 if ((ud == NULL) || (ud->data == NULL))
2513 status = cna_init_host (host);
2517 cna_query_wafl (host);
2518 cna_query_disk (host);
2519 cna_query_volume_perf (host);
2520 cna_query_volume_usage (host);
2521 cna_query_system (host);
2524 } /* }}} int cna_read */
2526 static int cna_config (oconfig_item_t *ci) { /* {{{ */
2528 oconfig_item_t *item;
2530 for (i = 0; i < ci->children_num; ++i) {
2531 item = ci->children + i;
2533 if (strcasecmp(item->key, "Host") == 0)
2535 host_config_t *host;
2537 struct timespec interval;
2540 host = cna_config_host (item);
2544 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name);
2546 memset (&interval, 0, sizeof (interval));
2547 interval.tv_sec = host->interval;
2549 memset (&ud, 0, sizeof (ud));
2551 ud.free_func = (void (*) (void *)) free_host_config;
2553 plugin_register_complex_read (cb_name,
2554 /* callback = */ cna_read,
2555 /* interval = */ (host->interval > 0) ? &interval : NULL,
2556 /* user data = */ &ud);
2559 else /* if (item->key != "Host") */
2561 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
2565 } /* }}} int cna_config */
2567 static int cna_shutdown (void) /* {{{ */
2569 /* Clean up system resources and stuff. */
2573 } /* }}} int cna_shutdown */
2575 void module_register(void) {
2576 plugin_register_complex_config("netapp", cna_config);
2577 plugin_register_init("netapp", cna_init);
2578 plugin_register_shutdown("netapp", cna_shutdown);
2581 /* vim: set sw=2 ts=2 noet fdm=marker : */