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 */
235 * \brief Struct representing a volume.
237 * A volume currently has a name and two sets of values:
239 * - Performance data, such as bytes read/written, number of operations
240 * performed and average time per operation.
242 * - Usage data, i. e. amount of used and free space in the volume.
244 typedef struct volume_s {
246 data_volume_perf_t perf_data;
247 struct volume_s *next;
250 struct host_config_s {
252 na_server_transport_t protocol;
260 cfg_wafl_t *cfg_wafl;
261 cfg_disk_t *cfg_disk;
262 cfg_volume_perf_t *cfg_volume_perf;
263 cfg_volume_usage_t *cfg_volume_usage;
264 cfg_system_t *cfg_system;
267 struct host_config_s *next;
269 #define HOST_INIT { NULL, NA_SERVER_TRANSPORT_HTTPS, NULL, 0, NULL, NULL, 0, \
270 NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
273 static host_config_t *global_host_config;
278 * Used to free the various structures above.
280 static void free_volume (volume_t *volume) /* {{{ */
289 sfree (volume->name);
293 } /* }}} void free_volume */
295 static void free_disk (disk_t *disk) /* {{{ */
308 } /* }}} void free_disk */
310 static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
315 if (cw->query != NULL)
316 na_elem_free (cw->query);
319 } /* }}} void free_cfg_wafl */
321 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
323 if (cfg_disk == NULL)
326 if (cfg_disk->query != NULL)
327 na_elem_free (cfg_disk->query);
329 free_disk (cfg_disk->disks);
331 } /* }}} void free_cfg_disk */
333 static void free_cfg_volume_perf (cfg_volume_perf_t *cvp) /* {{{ */
335 data_volume_perf_t *data;
340 /* Free the ignorelists */
341 ignorelist_free (cvp->il_octets);
342 ignorelist_free (cvp->il_operations);
343 ignorelist_free (cvp->il_latency);
345 /* Free the linked list of volumes */
349 data_volume_perf_t *next = data->next;
355 if (cvp->query != NULL)
356 na_elem_free (cvp->query);
359 } /* }}} void free_cfg_volume_perf */
361 static void free_cfg_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
363 data_volume_usage_t *data;
368 /* Free the ignorelists */
369 ignorelist_free (cvu->il_capacity);
370 ignorelist_free (cvu->il_snapshot);
372 /* Free the linked list of volumes */
376 data_volume_usage_t *next = data->next;
382 if (cvu->query != NULL)
383 na_elem_free (cvu->query);
386 } /* }}} void free_cfg_volume_usage */
388 static void free_cfg_system (cfg_system_t *cs) /* {{{ */
393 if (cs->query != NULL)
394 na_elem_free (cs->query);
397 } /* }}} void free_cfg_system */
399 static void free_host_config (host_config_t *hc) /* {{{ */
410 sfree (hc->username);
411 sfree (hc->password);
413 free_cfg_disk (hc->cfg_disk);
414 free_cfg_wafl (hc->cfg_wafl);
415 free_cfg_volume_perf (hc->cfg_volume_perf);
416 free_cfg_volume_usage (hc->cfg_volume_usage);
417 free_cfg_system (hc->cfg_system);
418 free_volume (hc->volumes);
422 free_host_config (next);
423 } /* }}} void free_host_config */
426 * Auxiliary functions
428 * Used to look up volumes and disks or to handle flags.
430 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
434 if ((cd == NULL) || (name == NULL))
437 for (d = cd->disks; d != NULL; d = d->next) {
438 if (strcmp(d->name, name) == 0)
442 d = malloc(sizeof(*d));
445 memset (d, 0, sizeof (*d));
448 d->name = strdup(name);
449 if (d->name == NULL) {
458 } /* }}} disk_t *get_disk */
460 static data_volume_usage_t *get_volume_usage (cfg_volume_usage_t *cvu, /* {{{ */
463 data_volume_usage_t *last;
464 data_volume_usage_t *new;
466 int ignore_capacity = 0;
467 int ignore_snapshot = 0;
469 if ((cvu == NULL) || (name == NULL))
475 if (strcmp (last->name, name) == 0)
478 if (last->next == NULL)
484 /* Check the ignorelists. If *both* tell us to ignore a volume, return NULL. */
485 ignore_capacity = ignorelist_match (cvu->il_capacity, name);
486 ignore_snapshot = ignorelist_match (cvu->il_snapshot, name);
487 if ((ignore_capacity != 0) && (ignore_snapshot != 0))
490 /* Not found: allocate. */
491 new = malloc (sizeof (*new));
494 memset (new, 0, sizeof (*new));
497 new->name = strdup (name);
498 if (new->name == NULL)
504 if (ignore_capacity == 0)
505 new->flags |= CFG_VOLUME_USAGE_DF;
506 if (ignore_snapshot == 0)
507 new->flags |= CFG_VOLUME_USAGE_SNAP;
509 /* Add to end of list. */
516 } /* }}} data_volume_usage_t *get_volume_usage */
518 static data_volume_perf_t *get_volume_perf (cfg_volume_perf_t *cvp, /* {{{ */
521 data_volume_perf_t *last;
522 data_volume_perf_t *new;
524 int ignore_octets = 0;
525 int ignore_operations = 0;
526 int ignore_latency = 0;
528 if ((cvp == NULL) || (name == NULL))
534 if (strcmp (last->name, name) == 0)
537 if (last->next == NULL)
543 /* Check the ignorelists. If *all three* tell us to ignore a volume, return
545 ignore_octets = ignorelist_match (cvp->il_octets, name);
546 ignore_operations = ignorelist_match (cvp->il_operations, name);
547 ignore_latency = ignorelist_match (cvp->il_latency, name);
548 if ((ignore_octets != 0) || (ignore_operations != 0)
549 || (ignore_latency != 0))
552 /* Not found: allocate. */
553 new = malloc (sizeof (*new));
556 memset (new, 0, sizeof (*new));
559 new->name = strdup (name);
560 if (new->name == NULL)
566 if (ignore_octets == 0)
567 new->flags |= CFG_VOLUME_PERF_IO;
568 if (ignore_operations == 0)
569 new->flags |= CFG_VOLUME_PERF_OPS;
570 if (ignore_latency == 0)
571 new->flags |= CFG_VOLUME_PERF_LATENCY;
573 /* Add to end of list. */
580 } /* }}} data_volume_perf_t *get_volume_perf */
583 * Various submit functions.
585 * They all eventually call "submit_values" which creates a value_list_t and
586 * dispatches it to the daemon.
588 static int submit_values (const char *host, /* {{{ */
589 const char *plugin_inst,
590 const char *type, const char *type_inst,
591 value_t *values, int values_len,
594 value_list_t vl = VALUE_LIST_INIT;
597 vl.values_len = values_len;
603 sstrncpy (vl.host, host, sizeof (vl.host));
605 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
606 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
607 if (plugin_inst != NULL)
608 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
609 sstrncpy (vl.type, type, sizeof (vl.type));
610 if (type_inst != NULL)
611 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
613 return (plugin_dispatch_values (&vl));
614 } /* }}} int submit_uint64 */
616 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
617 const char *type, const char *type_inst, counter_t val0, counter_t val1,
622 values[0].counter = val0;
623 values[1].counter = val1;
625 return (submit_values (host, plugin_inst, type, type_inst,
626 values, 2, timestamp));
627 } /* }}} int submit_two_counters */
629 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
630 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
636 return (submit_values (host, plugin_inst, type, type_inst,
638 } /* }}} int submit_counter */
640 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
641 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
646 values[0].gauge = val0;
647 values[1].gauge = val1;
649 return (submit_values (host, plugin_inst, type, type_inst,
650 values, 2, timestamp));
651 } /* }}} int submit_two_gauge */
653 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
654 const char *type, const char *type_inst, double d, time_t timestamp)
658 v.gauge = (gauge_t) d;
660 return (submit_values (host, plugin_inst, type, type_inst,
662 } /* }}} int submit_uint64 */
664 /* Calculate hit ratio from old and new counters and submit the resulting
665 * percentage. Used by "submit_wafl_data". */
666 static int submit_cache_ratio (const char *host, /* {{{ */
667 const char *plugin_inst,
668 const char *type_inst,
677 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
681 hits = new_hits - old_hits;
682 misses = new_misses - old_misses;
684 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
689 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
691 } /* }}} int submit_cache_ratio */
693 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
694 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
695 cfg_wafl_t *old_data, const cfg_wafl_t *new_data)
697 /* Submit requested counters */
698 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
699 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
700 submit_cache_ratio (hostname, instance, "name_cache_hit",
701 new_data->name_cache_hit, new_data->name_cache_miss,
702 old_data->name_cache_hit, old_data->name_cache_miss,
703 new_data->timestamp);
705 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
706 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
707 submit_cache_ratio (hostname, instance, "find_dir_hit",
708 new_data->find_dir_hit, new_data->find_dir_miss,
709 old_data->find_dir_hit, old_data->find_dir_miss,
710 new_data->timestamp);
712 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
713 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
714 submit_cache_ratio (hostname, instance, "buf_hash_hit",
715 new_data->buf_hash_hit, new_data->buf_hash_miss,
716 old_data->buf_hash_hit, old_data->buf_hash_miss,
717 new_data->timestamp);
719 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
720 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
721 submit_cache_ratio (hostname, instance, "inode_cache_hit",
722 new_data->inode_cache_hit, new_data->inode_cache_miss,
723 old_data->inode_cache_hit, old_data->inode_cache_miss,
724 new_data->timestamp);
726 /* Clear old HAVE_* flags */
727 old_data->flags &= ~HAVE_WAFL_ALL;
729 /* Copy all counters */
730 old_data->timestamp = new_data->timestamp;
731 old_data->name_cache_hit = new_data->name_cache_hit;
732 old_data->name_cache_miss = new_data->name_cache_miss;
733 old_data->find_dir_hit = new_data->find_dir_hit;
734 old_data->find_dir_miss = new_data->find_dir_miss;
735 old_data->buf_hash_hit = new_data->buf_hash_hit;
736 old_data->buf_hash_miss = new_data->buf_hash_miss;
737 old_data->inode_cache_hit = new_data->inode_cache_hit;
738 old_data->inode_cache_miss = new_data->inode_cache_miss;
740 /* Copy HAVE_* flags */
741 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
744 } /* }}} int submit_wafl_data */
746 /* Submits volume performance data to the daemon, taking care to honor and
747 * update flags appropriately. */
748 static int submit_volume_perf_data (const char *hostname, /* {{{ */
749 data_volume_perf_t *old_data,
750 const data_volume_perf_t *new_data)
752 /* Check for and submit disk-octet values */
753 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
754 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
756 submit_two_counters (hostname, old_data->name, "disk_octets", /* type instance = */ NULL,
757 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
760 /* Check for and submit disk-operations values */
761 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
762 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
764 submit_two_counters (hostname, old_data->name, "disk_ops", /* type instance = */ NULL,
765 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
768 /* Check for, calculate and submit disk-latency values */
769 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
770 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
771 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
772 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
773 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
775 gauge_t latency_per_op_read;
776 gauge_t latency_per_op_write;
778 latency_per_op_read = NAN;
779 latency_per_op_write = NAN;
781 /* Check if a counter wrapped around. */
782 if ((new_data->read_ops > old_data->read_ops)
783 && (new_data->read_latency > old_data->read_latency))
785 uint64_t diff_ops_read;
786 uint64_t diff_latency_read;
788 diff_ops_read = new_data->read_ops - old_data->read_ops;
789 diff_latency_read = new_data->read_latency - old_data->read_latency;
791 if (diff_ops_read > 0)
792 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
795 if ((new_data->write_ops > old_data->write_ops)
796 && (new_data->write_latency > old_data->write_latency))
798 uint64_t diff_ops_write;
799 uint64_t diff_latency_write;
801 diff_ops_write = new_data->write_ops - old_data->write_ops;
802 diff_latency_write = new_data->write_latency - old_data->write_latency;
804 if (diff_ops_write > 0)
805 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
808 submit_two_gauge (hostname, old_data->name, "disk_latency", /* type instance = */ NULL,
809 latency_per_op_read, latency_per_op_write, new_data->timestamp);
812 /* Clear all HAVE_* flags. */
813 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
815 /* Copy all counters */
816 old_data->timestamp = new_data->timestamp;
817 old_data->read_bytes = new_data->read_bytes;
818 old_data->write_bytes = new_data->write_bytes;
819 old_data->read_ops = new_data->read_ops;
820 old_data->write_ops = new_data->write_ops;
821 old_data->read_latency = new_data->read_latency;
822 old_data->write_latency = new_data->write_latency;
824 /* Copy the HAVE_* flags */
825 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
828 } /* }}} int submit_volume_perf_data */
833 * These functions are called with appropriate data returned by the libnetapp
834 * interface which is parsed and submitted with the above functions.
836 /* Data corresponding to <WAFL /> */
837 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
840 cfg_wafl_t perf_data;
841 const char *plugin_inst;
843 na_elem_t *instances;
845 na_elem_iter_t counter_iter;
847 memset (&perf_data, 0, sizeof (perf_data));
849 perf_data.timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
851 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
852 if (instances == NULL)
854 ERROR ("netapp plugin: cna_handle_wafl_data: "
855 "na_elem_child (\"instances\") failed.");
859 plugin_inst = na_child_get_string(instances, "name");
860 if (plugin_inst == NULL)
862 ERROR ("netapp plugin: cna_handle_wafl_data: "
863 "na_child_get_string (\"name\") failed.");
867 /* Iterate over all counters */
868 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
869 for (counter = na_iterator_next (&counter_iter);
871 counter = na_iterator_next (&counter_iter))
876 name = na_child_get_string(counter, "name");
880 value = na_child_get_uint64(counter, "value", UINT64_MAX);
881 if (value == UINT64_MAX)
884 if (!strcmp(name, "name_cache_hit")) {
885 perf_data.name_cache_hit = value;
886 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
887 } else if (!strcmp(name, "name_cache_miss")) {
888 perf_data.name_cache_miss = value;
889 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
890 } else if (!strcmp(name, "find_dir_hit")) {
891 perf_data.find_dir_hit = value;
892 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
893 } else if (!strcmp(name, "find_dir_miss")) {
894 perf_data.find_dir_miss = value;
895 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
896 } else if (!strcmp(name, "buf_hash_hit")) {
897 perf_data.buf_hash_hit = value;
898 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
899 } else if (!strcmp(name, "buf_hash_miss")) {
900 perf_data.buf_hash_miss = value;
901 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
902 } else if (!strcmp(name, "inode_cache_hit")) {
903 perf_data.inode_cache_hit = value;
904 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
905 } else if (!strcmp(name, "inode_cache_miss")) {
906 perf_data.inode_cache_miss = value;
907 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
909 DEBUG("netapp plugin: cna_handle_wafl_data: "
910 "Found unexpected child: %s", name);
914 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data));
915 } /* }}} void cna_handle_wafl_data */
917 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
924 if (cw->query != NULL)
927 cw->query = na_elem_new("perf-object-get-instances");
928 if (cw->query == NULL)
930 ERROR ("netapp plugin: na_elem_new failed.");
933 na_child_add_string (cw->query, "objectname", "wafl");
935 e = na_elem_new("counters");
938 na_elem_free (cw->query);
940 ERROR ("netapp plugin: na_elem_new failed.");
943 na_child_add_string(e, "foo", "name_cache_hit");
944 na_child_add_string(e, "foo", "name_cache_miss");
945 na_child_add_string(e, "foo", "find_dir_hit");
946 na_child_add_string(e, "foo", "find_dir_miss");
947 na_child_add_string(e, "foo", "buf_hash_hit");
948 na_child_add_string(e, "foo", "buf_hash_miss");
949 na_child_add_string(e, "foo", "inode_cache_hit");
950 na_child_add_string(e, "foo", "inode_cache_miss");
952 na_child_add(cw->query, e);
955 } /* }}} int cna_setup_wafl */
957 static int cna_query_wafl (host_config_t *host) /* {{{ */
966 /* If WAFL was not configured, return without doing anything. */
967 if (host->cfg_wafl == NULL)
971 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
974 status = cna_setup_wafl (host->cfg_wafl);
977 assert (host->cfg_wafl->query != NULL);
979 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
980 if (na_results_status (data) != NA_OK)
982 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed: %s",
983 na_results_reason (data));
988 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data);
991 host->cfg_wafl->interval.last_read = now;
995 } /* }}} int cna_query_wafl */
997 /* Data corresponding to <Disks /> */
998 static int cna_handle_disk_data (const char *hostname, /* {{{ */
999 cfg_disk_t *cfg_disk, na_elem_t *data)
1002 na_elem_t *instances;
1003 na_elem_t *instance;
1004 na_elem_iter_t instance_iter;
1005 disk_t *worst_disk = NULL;
1007 if ((cfg_disk == NULL) || (data == NULL))
1010 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
1012 instances = na_elem_child (data, "instances");
1013 if (instances == NULL)
1015 ERROR ("netapp plugin: cna_handle_disk_data: "
1016 "na_elem_child (\"instances\") failed.");
1020 /* Iterate over all children */
1021 instance_iter = na_child_iterator (instances);
1022 for (instance = na_iterator_next (&instance_iter);
1024 instance = na_iterator_next(&instance_iter))
1029 na_elem_iter_t counter_iterator;
1032 memset (&new_data, 0, sizeof (new_data));
1033 new_data.timestamp = timestamp;
1034 new_data.disk_busy_percent = NAN;
1036 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1037 if (old_data == NULL)
1040 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1041 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1042 for (counter = na_iterator_next(&counter_iterator);
1044 counter = na_iterator_next(&counter_iterator))
1049 name = na_child_get_string(counter, "name");
1053 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1054 if (value == UINT64_MAX)
1057 if (strcmp(name, "disk_busy") == 0)
1059 new_data.disk_busy = value;
1060 new_data.flags |= HAVE_DISK_BUSY;
1062 else if (strcmp(name, "base_for_disk_busy") == 0)
1064 new_data.base_for_disk_busy = value;
1065 new_data.flags |= HAVE_DISK_BASE;
1069 DEBUG ("netapp plugin: cna_handle_disk_data: "
1070 "Counter not handled: %s = %"PRIu64,
1075 /* If all required counters are available and did not just wrap around,
1076 * calculate the busy percentage. Otherwise, the value is initialized to
1077 * NAN at the top of the for-loop. */
1078 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1079 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1080 && (new_data.disk_busy >= old_data->disk_busy)
1081 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1086 busy_diff = new_data.disk_busy - old_data->disk_busy;
1087 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1089 new_data.disk_busy_percent = 100.0
1090 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1093 /* Clear HAVE_* flags */
1094 old_data->flags &= ~HAVE_DISK_ALL;
1097 old_data->timestamp = new_data.timestamp;
1098 old_data->disk_busy = new_data.disk_busy;
1099 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1100 old_data->disk_busy_percent = new_data.disk_busy_percent;
1103 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1105 if ((worst_disk == NULL)
1106 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1107 worst_disk = old_data;
1108 } /* for (all disks) */
1110 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1111 submit_double (hostname, "system", "percent", "disk_busy",
1112 worst_disk->disk_busy_percent, timestamp);
1115 } /* }}} int cna_handle_disk_data */
1117 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1124 if (cd->query != NULL)
1127 cd->query = na_elem_new ("perf-object-get-instances");
1128 if (cd->query == NULL)
1130 ERROR ("netapp plugin: na_elem_new failed.");
1133 na_child_add_string (cd->query, "objectname", "disk");
1135 e = na_elem_new("counters");
1138 na_elem_free (cd->query);
1140 ERROR ("netapp plugin: na_elem_new failed.");
1143 na_child_add_string(e, "foo", "disk_busy");
1144 na_child_add_string(e, "foo", "base_for_disk_busy");
1145 na_child_add(cd->query, e);
1148 } /* }}} int cna_setup_disk */
1150 static int cna_query_disk (host_config_t *host) /* {{{ */
1159 /* If the user did not configure disk statistics, return without doing
1161 if (host->cfg_disk == NULL)
1165 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1168 status = cna_setup_disk (host->cfg_disk);
1171 assert (host->cfg_disk->query != NULL);
1173 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1174 if (na_results_status (data) != NA_OK)
1176 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed: %s",
1177 na_results_reason (data));
1178 na_elem_free (data);
1182 status = cna_handle_disk_data (host->name, host->cfg_disk, data);
1185 host->cfg_disk->interval.last_read = now;
1187 na_elem_free (data);
1189 } /* }}} int cna_query_disk */
1191 /* Data corresponding to <VolumePerf /> */
1192 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1193 cfg_volume_perf_t *cvp, na_elem_t *data)
1196 na_elem_t *elem_instances;
1197 na_elem_iter_t iter_instances;
1198 na_elem_t *elem_instance;
1200 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
1202 elem_instances = na_elem_child(data, "instances");
1203 if (elem_instances == NULL)
1205 ERROR ("netapp plugin: handle_volume_perf_data: "
1206 "na_elem_child (\"instances\") failed.");
1210 iter_instances = na_child_iterator (elem_instances);
1211 for (elem_instance = na_iterator_next(&iter_instances);
1212 elem_instance != NULL;
1213 elem_instance = na_iterator_next(&iter_instances))
1217 data_volume_perf_t perf_data;
1218 data_volume_perf_t *v;
1220 na_elem_t *elem_counters;
1221 na_elem_iter_t iter_counters;
1222 na_elem_t *elem_counter;
1224 memset (&perf_data, 0, sizeof (perf_data));
1225 perf_data.timestamp = timestamp;
1227 name = na_child_get_string (elem_instance, "name");
1231 /* get_volume_perf may return NULL if this volume is to be ignored. */
1232 v = get_volume_perf (cvp, perf_data.name);
1236 elem_counters = na_elem_child (elem_instance, "counters");
1237 if (elem_counters == NULL)
1240 iter_counters = na_child_iterator (elem_counters);
1241 for (elem_counter = na_iterator_next(&iter_counters);
1242 elem_counter != NULL;
1243 elem_counter = na_iterator_next(&iter_counters))
1248 name = na_child_get_string (elem_counter, "name");
1252 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1253 if (value == UINT64_MAX)
1256 if (!strcmp(name, "read_data")) {
1257 perf_data.read_bytes = value;
1258 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1259 } else if (!strcmp(name, "write_data")) {
1260 perf_data.write_bytes = value;
1261 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1262 } else if (!strcmp(name, "read_ops")) {
1263 perf_data.read_ops = value;
1264 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1265 } else if (!strcmp(name, "write_ops")) {
1266 perf_data.write_ops = value;
1267 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1268 } else if (!strcmp(name, "read_latency")) {
1269 perf_data.read_latency = value;
1270 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1271 } else if (!strcmp(name, "write_latency")) {
1272 perf_data.write_latency = value;
1273 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1275 } /* for (elem_counter) */
1277 submit_volume_perf_data (hostname, v, &perf_data);
1278 } /* for (volume) */
1281 } /* }}} int cna_handle_volume_perf_data */
1283 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1290 if (cd->query != NULL)
1293 cd->query = na_elem_new ("perf-object-get-instances");
1294 if (cd->query == NULL)
1296 ERROR ("netapp plugin: na_elem_new failed.");
1299 na_child_add_string (cd->query, "objectname", "volume");
1301 e = na_elem_new("counters");
1304 na_elem_free (cd->query);
1306 ERROR ("netapp plugin: na_elem_new failed.");
1309 /* "foo" means: This string has to be here but the content doesn't matter. */
1310 na_child_add_string(e, "foo", "read_ops");
1311 na_child_add_string(e, "foo", "write_ops");
1312 na_child_add_string(e, "foo", "read_data");
1313 na_child_add_string(e, "foo", "write_data");
1314 na_child_add_string(e, "foo", "read_latency");
1315 na_child_add_string(e, "foo", "write_latency");
1316 na_child_add(cd->query, e);
1319 } /* }}} int cna_setup_volume_perf */
1321 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1330 /* If the user did not configure volume performance statistics, return
1331 * without doing anything. */
1332 if (host->cfg_volume_perf == NULL)
1336 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1339 status = cna_setup_volume_perf (host->cfg_volume_perf);
1342 assert (host->cfg_volume_perf->query != NULL);
1344 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1345 if (na_results_status (data) != NA_OK)
1347 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed: %s",
1348 na_results_reason (data));
1349 na_elem_free (data);
1353 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data);
1356 host->cfg_volume_perf->interval.last_read = now;
1358 na_elem_free (data);
1360 } /* }}} int cna_query_volume_perf */
1362 /* Data corresponding to <VolumeUsage /> */
1363 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1364 cfg_volume_usage_t *cfg_volume)
1366 data_volume_usage_t *v;
1368 for (v = cfg_volume->volumes; v != NULL; v = v->next)
1370 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1371 submit_double (hostname, /* plugin instance = */ v->name,
1372 "df_complex", "free",
1373 (double) v->norm_free, /* timestamp = */ 0);
1375 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1376 submit_double (hostname, /* plugin instance = */ v->name,
1377 "df_complex", "used",
1378 (double) v->norm_used, /* timestamp = */ 0);
1380 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1381 submit_double (hostname, /* plugin instance = */ v->name,
1382 "df_complex", "snap_reserved",
1383 (double) v->snap_reserved, /* timestamp = */ 0);
1385 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1386 submit_double (hostname, /* plugin instance = */ v->name,
1387 "df_complex", "snap_used",
1388 (double) v->snap_used, /* timestamp = */ 0);
1390 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1391 submit_double (hostname, /* plugin instance = */ v->name,
1392 "df_complex", "sis_saved",
1393 (double) v->sis_saved, /* timestamp = */ 0);
1395 /* Clear all the HAVE_* flags */
1396 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1397 } /* for (v = cfg_volume->volumes) */
1400 } /* }}} int cna_submit_volume_usage_data */
1402 static int cna_handle_volume_usage_data (const char *hostname, /* {{{ */
1403 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1405 na_elem_t *elem_volume;
1406 na_elem_t *elem_volumes;
1407 na_elem_iter_t iter_volume;
1409 elem_volumes = na_elem_child (data, "volumes");
1410 if (elem_volumes == NULL)
1412 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1413 "na_elem_child (\"volumes\") failed.");
1417 iter_volume = na_child_iterator (elem_volumes);
1418 for (elem_volume = na_iterator_next (&iter_volume);
1419 elem_volume != NULL;
1420 elem_volume = na_iterator_next (&iter_volume))
1422 const char *volume_name;
1424 data_volume_usage_t *v;
1428 const char *sis_state;
1429 uint64_t sis_saved_reported;
1431 volume_name = na_child_get_string (elem_volume, "name");
1432 if (volume_name == NULL)
1435 /* get_volume_usage may return NULL if the volume is to be ignored. */
1436 v = get_volume_usage (cfg_volume, volume_name);
1440 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1443 /* 2^4 exa-bytes? This will take a while ;) */
1444 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1445 if (value != UINT64_MAX) {
1446 v->norm_free = value;
1447 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1450 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1451 if (value != UINT64_MAX) {
1452 v->norm_used = value;
1453 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1456 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1457 if (value != UINT64_MAX) {
1458 /* 1 block == 1024 bytes as per API docs */
1459 v->norm_used = 1024 * value;
1460 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1463 sis = na_elem_child(elem_volume, "sis");
1467 sis_state = na_child_get_string(sis, "state");
1468 if (sis_state == NULL)
1471 /* If SIS is not enabled, set the HAVE_VOLUME_USAGE_SIS_SAVED flag and set
1472 * sis_saved to UINT64_MAX to signal this condition to the submit function. */
1473 if (strcmp ("enabled", sis_state) != 0) {
1474 v->sis_saved = UINT64_MAX;
1475 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1479 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1480 if (sis_saved_reported == UINT64_MAX)
1483 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1484 if ((sis_saved_reported >> 32) != 0) {
1485 /* In case they ever fix this bug. */
1486 v->sis_saved = sis_saved_reported;
1487 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1488 } else { /* really hacky work-around code. {{{ */
1489 uint64_t sis_saved_percent;
1490 uint64_t sis_saved_guess;
1491 uint64_t overflow_guess;
1492 uint64_t guess1, guess2, guess3;
1494 /* Check if we have v->norm_used. Without it, we cannot calculate
1495 * sis_saved_guess. */
1496 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1499 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1500 if (sis_saved_percent > 100)
1503 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1504 * will hopefully be fixed in later versions. To work around the bug, try
1505 * to figure out how often the 32bit integer wrapped around by using the
1506 * "percentage-saved" value. Because the percentage is in the range
1507 * [0-100], this should work as long as the saved space does not exceed
1509 /* percentage-saved = size-saved / (size-saved + size-used) */
1510 if (sis_saved_percent < 100)
1511 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1513 sis_saved_guess = v->norm_used;
1515 overflow_guess = sis_saved_guess >> 32;
1516 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1517 guess2 = (overflow_guess << 32) + sis_saved_reported;
1518 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1520 if (sis_saved_guess < guess2) {
1521 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1522 v->sis_saved = guess1;
1524 v->sis_saved = guess2;
1526 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1527 v->sis_saved = guess2;
1529 v->sis_saved = guess3;
1531 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1532 } /* }}} end of 32-bit workaround */
1533 } /* for (elem_volume) */
1535 return (cna_submit_volume_usage_data (hostname, cfg_volume));
1536 } /* }}} int cna_handle_volume_usage_data */
1538 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1543 if (cvu->query != NULL)
1546 cvu->query = na_elem_new ("volume-list-info");
1547 if (cvu->query == NULL)
1549 ERROR ("netapp plugin: na_elem_new failed.");
1553 /* TODO: cvu->snap_query = na_elem_new("snapshot-list-info"); */
1556 } /* }}} int cna_setup_volume_usage */
1558 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1567 /* If the user did not configure volume_usage statistics, return without
1568 * doing anything. */
1569 if (host->cfg_volume_usage == NULL)
1573 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1576 status = cna_setup_volume_usage (host->cfg_volume_usage);
1579 assert (host->cfg_volume_usage->query != NULL);
1581 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1582 if (na_results_status (data) != NA_OK)
1584 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed: %s",
1585 na_results_reason (data));
1586 na_elem_free (data);
1590 status = cna_handle_volume_usage_data (host->name, host->cfg_volume_usage, data);
1593 host->cfg_volume_usage->interval.last_read = now;
1595 na_elem_free (data);
1597 } /* }}} int cna_query_volume_usage */
1599 /* Data corresponding to <System /> */
1600 static int cna_handle_system_data (const char *hostname, /* {{{ */
1601 cfg_system_t *cfg_system, na_elem_t *data)
1603 na_elem_t *instances;
1605 na_elem_iter_t counter_iter;
1607 counter_t disk_read = 0, disk_written = 0;
1608 counter_t net_recv = 0, net_sent = 0;
1609 counter_t cpu_busy = 0, cpu_total = 0;
1610 uint32_t counter_flags = 0;
1612 const char *instance;
1615 timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
1617 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1618 if (instances == NULL)
1620 ERROR ("netapp plugin: cna_handle_system_data: "
1621 "na_elem_child (\"instances\") failed.");
1625 instance = na_child_get_string (instances, "name");
1626 if (instance == NULL)
1628 ERROR ("netapp plugin: cna_handle_system_data: "
1629 "na_child_get_string (\"name\") failed.");
1633 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
1634 for (counter = na_iterator_next (&counter_iter);
1636 counter = na_iterator_next (&counter_iter))
1641 name = na_child_get_string(counter, "name");
1645 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1646 if (value == UINT64_MAX)
1649 if (!strcmp(name, "disk_data_read")) {
1650 disk_read = (counter_t) (value * 1024);
1651 counter_flags |= 0x01;
1652 } else if (!strcmp(name, "disk_data_written")) {
1653 disk_written = (counter_t) (value * 1024);
1654 counter_flags |= 0x02;
1655 } else if (!strcmp(name, "net_data_recv")) {
1656 net_recv = (counter_t) (value * 1024);
1657 counter_flags |= 0x04;
1658 } else if (!strcmp(name, "net_data_sent")) {
1659 net_sent = (counter_t) (value * 1024);
1660 counter_flags |= 0x08;
1661 } else if (!strcmp(name, "cpu_busy")) {
1662 cpu_busy = (counter_t) value;
1663 counter_flags |= 0x10;
1664 } else if (!strcmp(name, "cpu_elapsed_time")) {
1665 cpu_total = (counter_t) value;
1666 counter_flags |= 0x20;
1667 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1668 && (value > 0) && (strlen(name) > 4)
1669 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1670 submit_counter (hostname, instance, "disk_ops_complex", name,
1671 (counter_t) value, timestamp);
1673 } /* for (counter) */
1675 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1676 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
1677 submit_two_counters (hostname, instance, "disk_octets", NULL,
1678 disk_read, disk_written, timestamp);
1680 if ((cfg_system->flags & CFG_SYSTEM_NET)
1681 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
1682 submit_two_counters (hostname, instance, "if_octets", NULL,
1683 net_recv, net_sent, timestamp);
1685 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1686 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
1688 submit_counter (hostname, instance, "cpu", "system",
1689 cpu_busy, timestamp);
1690 submit_counter (hostname, instance, "cpu", "idle",
1691 cpu_total - cpu_busy, timestamp);
1695 } /* }}} int cna_handle_system_data */
1697 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
1702 if (cs->query != NULL)
1705 cs->query = na_elem_new ("perf-object-get-instances");
1706 if (cs->query == NULL)
1708 ERROR ("netapp plugin: na_elem_new failed.");
1711 na_child_add_string (cs->query, "objectname", "system");
1714 } /* }}} int cna_setup_system */
1716 static int cna_query_system (host_config_t *host) /* {{{ */
1725 /* If system statistics were not configured, return without doing anything. */
1726 if (host->cfg_system == NULL)
1730 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
1733 status = cna_setup_system (host->cfg_system);
1736 assert (host->cfg_system->query != NULL);
1738 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
1739 if (na_results_status (data) != NA_OK)
1741 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed: %s",
1742 na_results_reason (data));
1743 na_elem_free (data);
1747 status = cna_handle_system_data (host->name, host->cfg_system, data);
1750 host->cfg_system->interval.last_read = now;
1752 na_elem_free (data);
1754 } /* }}} int cna_query_system */
1757 * Configuration handling
1759 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1760 * is false. On error, the flag-field is not changed. */
1761 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1762 uint32_t *flags, uint32_t flag)
1764 if ((ci == NULL) || (flags == NULL))
1767 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1769 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1774 if (ci->values[0].value.boolean)
1780 } /* }}} int cna_config_bool_to_flag */
1782 /* Handling of the "Interval" option which is allowed in every block. */
1783 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1784 cna_interval_t *out_interval)
1788 if ((ci == NULL) || (out_interval == NULL))
1791 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1793 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1797 tmp = (time_t) (ci->values[0].value.number + .5);
1800 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1804 out_interval->interval = tmp;
1805 out_interval->last_read = 0;
1808 } /* }}} int cna_config_get_interval */
1810 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1811 * <VolumePerf /> block. */
1812 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
1813 const oconfig_item_t *ci)
1818 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1820 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1825 name = ci->values[0].value.string;
1827 if (strcasecmp ("GetIO", ci->key) == 0)
1828 il = cvp->il_octets;
1829 else if (strcasecmp ("GetOps", ci->key) == 0)
1830 il = cvp->il_operations;
1831 else if (strcasecmp ("GetLatency", ci->key) == 0)
1832 il = cvp->il_latency;
1836 ignorelist_add (il, name);
1837 } /* }}} void cna_config_volume_perf_option */
1839 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
1840 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
1841 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
1842 const oconfig_item_t *ci)
1846 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1848 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1853 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
1854 il = cvp->il_octets;
1855 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
1856 il = cvp->il_operations;
1857 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
1858 il = cvp->il_latency;
1862 if (ci->values[0].value.boolean)
1863 ignorelist_set_invert (il, /* invert = */ 0);
1865 ignorelist_set_invert (il, /* invert = */ 1);
1866 } /* }}} void cna_config_volume_perf_default */
1868 /* Corresponds to a <Disks /> block */
1873 * IgnoreSelectedIO false
1877 * IgnoreSelectedOps false
1881 * IgnoreSelectedLatency false
1884 /* Corresponds to a <VolumePerf /> block */
1885 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
1886 const oconfig_item_t *ci)
1888 cfg_volume_perf_t *cfg_volume_perf;
1891 if ((host == NULL) || (ci == NULL))
1894 if (host->cfg_volume_perf == NULL)
1896 cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
1897 if (cfg_volume_perf == NULL)
1899 memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
1901 /* Set default flags */
1902 cfg_volume_perf->query = NULL;
1903 cfg_volume_perf->volumes = NULL;
1905 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
1906 if (cfg_volume_perf->il_octets == NULL)
1908 sfree (cfg_volume_perf);
1912 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
1913 if (cfg_volume_perf->il_operations == NULL)
1915 ignorelist_free (cfg_volume_perf->il_octets);
1916 sfree (cfg_volume_perf);
1920 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
1921 if (cfg_volume_perf->il_latency == NULL)
1923 ignorelist_free (cfg_volume_perf->il_octets);
1924 ignorelist_free (cfg_volume_perf->il_operations);
1925 sfree (cfg_volume_perf);
1929 host->cfg_volume_perf = cfg_volume_perf;
1931 cfg_volume_perf = host->cfg_volume_perf;
1933 for (i = 0; i < ci->children_num; ++i) {
1934 oconfig_item_t *item = ci->children + i;
1936 /* if (!item || !item->key || !*item->key) continue; */
1937 if (strcasecmp(item->key, "Interval") == 0)
1938 cna_config_get_interval (item, &cfg_volume_perf->interval);
1939 else if (!strcasecmp(item->key, "GetIO"))
1940 cna_config_volume_perf_option (cfg_volume_perf, item);
1941 else if (!strcasecmp(item->key, "GetOps"))
1942 cna_config_volume_perf_option (cfg_volume_perf, item);
1943 else if (!strcasecmp(item->key, "GetLatency"))
1944 cna_config_volume_perf_option (cfg_volume_perf, item);
1945 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
1946 cna_config_volume_perf_default (cfg_volume_perf, item);
1947 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
1948 cna_config_volume_perf_default (cfg_volume_perf, item);
1949 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
1950 cna_config_volume_perf_default (cfg_volume_perf, item);
1952 WARNING ("netapp plugin: The option %s is not allowed within "
1953 "`VolumePerf' blocks.", item->key);
1957 } /* }}} int cna_config_volume_performance */
1959 /* Handling of the "Capacity" and "Snapshot" options within a <VolumeUsage />
1961 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
1962 const oconfig_item_t *ci)
1967 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1969 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1974 name = ci->values[0].value.string;
1976 if (strcasecmp ("Capacity", ci->key) == 0)
1977 il = cvu->il_capacity;
1978 else if (strcasecmp ("Snapshot", ci->key) == 0)
1979 il = cvu->il_snapshot;
1983 ignorelist_add (il, name);
1984 } /* }}} void cna_config_volume_usage_option */
1986 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
1987 * options within a <VolumeUsage /> block. */
1988 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
1989 const oconfig_item_t *ci)
1993 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1995 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2000 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2001 il = cvu->il_capacity;
2002 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2003 il = cvu->il_snapshot;
2007 if (ci->values[0].value.boolean)
2008 ignorelist_set_invert (il, /* invert = */ 0);
2010 ignorelist_set_invert (il, /* invert = */ 1);
2011 } /* }}} void cna_config_volume_usage_default */
2013 /* Corresponds to a <Disks /> block */
2014 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2015 cfg_disk_t *cfg_disk;
2018 if ((host == NULL) || (ci == NULL))
2021 if (host->cfg_disk == NULL)
2023 cfg_disk = malloc (sizeof (*cfg_disk));
2024 if (cfg_disk == NULL)
2026 memset (cfg_disk, 0, sizeof (*cfg_disk));
2028 /* Set default flags */
2029 cfg_disk->flags = CFG_DISK_ALL;
2030 cfg_disk->query = NULL;
2031 cfg_disk->disks = NULL;
2033 host->cfg_disk = cfg_disk;
2035 cfg_disk = host->cfg_disk;
2037 for (i = 0; i < ci->children_num; ++i) {
2038 oconfig_item_t *item = ci->children + i;
2040 /* if (!item || !item->key || !*item->key) continue; */
2041 if (strcasecmp(item->key, "Interval") == 0)
2042 cna_config_get_interval (item, &cfg_disk->interval);
2043 else if (strcasecmp(item->key, "GetBusy") == 0)
2044 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2047 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2049 NOTICE ("netapp plugin: All disk related values have been disabled. "
2050 "Collection of per-disk data will be disabled entirely.");
2051 free_cfg_disk (host->cfg_disk);
2052 host->cfg_disk = NULL;
2056 } /* }}} int cna_config_disk */
2058 /* Corresponds to a <WAFL /> block */
2059 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2061 cfg_wafl_t *cfg_wafl;
2064 if ((host == NULL) || (ci == NULL))
2067 if (host->cfg_wafl == NULL)
2069 cfg_wafl = malloc (sizeof (*cfg_wafl));
2070 if (cfg_wafl == NULL)
2072 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
2074 /* Set default flags */
2075 cfg_wafl->flags = CFG_WAFL_ALL;
2077 host->cfg_wafl = cfg_wafl;
2079 cfg_wafl = host->cfg_wafl;
2081 for (i = 0; i < ci->children_num; ++i) {
2082 oconfig_item_t *item = ci->children + i;
2084 if (strcasecmp(item->key, "Interval") == 0)
2085 cna_config_get_interval (item, &cfg_wafl->interval);
2086 else if (!strcasecmp(item->key, "GetNameCache"))
2087 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2088 else if (!strcasecmp(item->key, "GetDirCache"))
2089 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2090 else if (!strcasecmp(item->key, "GetBufferCache"))
2091 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2092 else if (!strcasecmp(item->key, "GetInodeCache"))
2093 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2095 WARNING ("netapp plugin: The %s config option is not allowed within "
2096 "`WAFL' blocks.", item->key);
2099 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2101 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2102 "Collection of WAFL data will be disabled entirely.");
2103 free_cfg_wafl (host->cfg_wafl);
2104 host->cfg_wafl = NULL;
2108 } /* }}} int cna_config_wafl */
2117 * IgnoreSelectedCapacity false
2123 * IgnoreSelectedSnapshot false
2126 /* Corresponds to a <VolumeUsage /> block */
2127 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2128 const oconfig_item_t *ci)
2130 cfg_volume_usage_t *cfg_volume_usage;
2133 if ((host == NULL) || (ci == NULL))
2136 if (host->cfg_volume_usage == NULL)
2138 cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
2139 if (cfg_volume_usage == NULL)
2141 memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
2143 /* Set default flags */
2144 cfg_volume_usage->query = NULL;
2145 cfg_volume_usage->volumes = NULL;
2147 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2148 if (cfg_volume_usage->il_capacity == NULL)
2150 sfree (cfg_volume_usage);
2154 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2155 if (cfg_volume_usage->il_snapshot == NULL)
2157 ignorelist_free (cfg_volume_usage->il_capacity);
2158 sfree (cfg_volume_usage);
2162 host->cfg_volume_usage = cfg_volume_usage;
2164 cfg_volume_usage = host->cfg_volume_usage;
2166 for (i = 0; i < ci->children_num; ++i) {
2167 oconfig_item_t *item = ci->children + i;
2169 /* if (!item || !item->key || !*item->key) continue; */
2170 if (strcasecmp(item->key, "Interval") == 0)
2171 cna_config_get_interval (item, &cfg_volume_usage->interval);
2172 else if (!strcasecmp(item->key, "Capacity"))
2173 cna_config_volume_usage_option (cfg_volume_usage, item);
2174 else if (!strcasecmp(item->key, "Snapshot"))
2175 cna_config_volume_usage_option (cfg_volume_usage, item);
2176 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2177 cna_config_volume_usage_default (cfg_volume_usage, item);
2178 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2179 cna_config_volume_usage_default (cfg_volume_usage, item);
2181 WARNING ("netapp plugin: The option %s is not allowed within "
2182 "`VolumeUsage' blocks.", item->key);
2186 } /* }}} int cna_config_volume_usage */
2188 /* Corresponds to a <System /> block */
2189 static int cna_config_system (host_config_t *host, /* {{{ */
2192 cfg_system_t *cfg_system;
2195 if ((host == NULL) || (ci == NULL))
2198 if (host->cfg_system == NULL)
2200 cfg_system = malloc (sizeof (*cfg_system));
2201 if (cfg_system == NULL)
2203 memset (cfg_system, 0, sizeof (*cfg_system));
2205 /* Set default flags */
2206 cfg_system->flags = CFG_SYSTEM_ALL;
2207 cfg_system->query = NULL;
2209 host->cfg_system = cfg_system;
2211 cfg_system = host->cfg_system;
2213 for (i = 0; i < ci->children_num; ++i) {
2214 oconfig_item_t *item = ci->children + i;
2216 if (strcasecmp(item->key, "Interval") == 0) {
2217 cna_config_get_interval (item, &cfg_system->interval);
2218 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2219 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2220 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2221 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2222 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2223 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2224 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2225 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2227 WARNING ("netapp plugin: The %s config option is not allowed within "
2228 "`System' blocks.", item->key);
2232 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2234 NOTICE ("netapp plugin: All system related values have been disabled. "
2235 "Collection of system data will be disabled entirely.");
2236 free_cfg_system (host->cfg_system);
2237 host->cfg_system = NULL;
2241 } /* }}} int cna_config_system */
2243 /* Corresponds to a <Host /> block. */
2244 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
2245 const host_config_t *default_host)
2247 oconfig_item_t *item;
2248 host_config_t *host;
2252 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2253 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
2257 host = malloc(sizeof(*host));
2258 memcpy (host, default_host, sizeof (*host));
2260 status = cf_util_get_string (ci, &host->name);
2267 for (i = 0; i < ci->children_num; ++i) {
2268 item = ci->children + i;
2272 if (!strcasecmp(item->key, "Address")) {
2273 status = cf_util_get_string (item, &host->host);
2274 } else if (!strcasecmp(item->key, "Port")) {
2277 tmp = cf_util_get_port_number (item);
2280 } else if (!strcasecmp(item->key, "Protocol")) {
2281 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"))) {
2282 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2285 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2286 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2287 } else if (!strcasecmp(item->key, "User")) {
2288 status = cf_util_get_string (item, &host->username);
2289 } else if (!strcasecmp(item->key, "Password")) {
2290 status = cf_util_get_string (item, &host->password);
2291 } else if (!strcasecmp(item->key, "Interval")) {
2292 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) {
2293 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
2296 host->interval = item->values[0].value.number;
2297 } else if (!strcasecmp(item->key, "WAFL")) {
2298 cna_config_wafl(host, item);
2299 } else if (!strcasecmp(item->key, "Disks")) {
2300 cna_config_disk(host, item);
2301 } else if (!strcasecmp(item->key, "VolumePerf")) {
2302 cna_config_volume_performance(host, item);
2303 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2304 cna_config_volume_usage(host, item);
2305 } else if (!strcasecmp(item->key, "System")) {
2306 cna_config_system(host, item);
2308 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
2309 item->key, ci->values[0].value.string);
2316 if (host->host == NULL)
2317 host->host = strdup (host->name);
2319 if (host->host == NULL)
2322 if (host->port <= 0)
2323 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2325 if ((host->username == NULL) || (host->password == NULL)) {
2326 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2327 "Ignoring host block.", host->name);
2333 free_host_config (host);
2338 } /* }}} host_config_t *cna_config_host */
2341 * Callbacks registered with the daemon
2343 * Pretty standard stuff here.
2345 static int cna_init(void) { /* {{{ */
2347 host_config_t *host;
2349 if (!global_host_config) {
2350 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
2354 memset (err, 0, sizeof (err));
2355 if (!na_startup(err, sizeof(err))) {
2356 err[sizeof (err) - 1] = 0;
2357 ERROR("netapp plugin: Error initializing netapp API: %s", err);
2361 for (host = global_host_config; host; host = host->next) {
2362 /* Request version 1.1 of the ONTAP API */
2363 host->srv = na_server_open(host->host,
2364 /* major version = */ 1, /* minor version = */ 1);
2365 if (host->srv == NULL) {
2366 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
2370 if (host->interval < interval_g)
2371 host->interval = interval_g;
2373 na_server_set_transport_type(host->srv, host->protocol,
2374 /* transportarg = */ NULL);
2375 na_server_set_port(host->srv, host->port);
2376 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
2377 na_server_adminuser(host->srv, host->username, host->password);
2378 na_server_set_timeout(host->srv, 5 /* seconds */);
2381 } /* }}} int cna_init */
2383 static int cna_config (oconfig_item_t *ci) { /* {{{ */
2385 oconfig_item_t *item;
2386 host_config_t default_host = HOST_INIT;
2388 for (i = 0; i < ci->children_num; ++i) {
2389 item = ci->children + i;
2391 if (!strcasecmp(item->key, "Host")) {
2392 host_config_t *host;
2395 host = cna_config_host(item, &default_host);
2399 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
2401 if (strcasecmp (host->name, tmp->name) == 0)
2402 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
2403 "This is probably a bad idea.",
2406 if (tmp->next == NULL)
2412 global_host_config = host;
2416 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
2420 } /* }}} int cna_config */
2422 static int cna_read (void) { /* {{{ */
2423 host_config_t *host;
2425 for (host = global_host_config; host; host = host->next) {
2426 cna_query_wafl (host);
2427 cna_query_disk (host);
2428 cna_query_volume_perf (host);
2429 cna_query_volume_usage (host);
2430 cna_query_system (host);
2433 } /* }}} int cna_read */
2435 void module_register(void) {
2436 plugin_register_complex_config("netapp", cna_config);
2437 plugin_register_init("netapp", cna_init);
2438 plugin_register_read("netapp", cna_read);
2441 /* vim: set sw=2 ts=2 noet fdm=marker : */