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>
30 #include <netapp_api.h>
32 #define HAS_ALL_FLAGS(has,needs) (((has) & (needs)) == (needs))
34 typedef struct host_config_s host_config_t;
35 typedef void service_handler_t(host_config_t *host, na_elem_t *result, void *data);
42 typedef struct cna_interval_s cna_interval_t;
45 * \brief Persistent data for system performance counters
47 #define CFG_SYSTEM_CPU 0x01
48 #define CFG_SYSTEM_NET 0x02
49 #define CFG_SYSTEM_OPS 0x04
50 #define CFG_SYSTEM_DISK 0x08
51 #define CFG_SYSTEM_ALL 0x0F
54 cna_interval_t interval;
59 * \brief Persistent data for WAFL performance counters. (a.k.a. cache performance)
61 * The cache counters use old counter values to calculate a hit ratio for each
62 * counter. The "cfg_wafl_t" struct therefore contains old counter values along
63 * with flags, which are set if the counter is valid.
65 * The function "cna_handle_wafl_data" will fill a new structure of this kind
66 * with new values, then pass both, new and old data, to "submit_wafl_data".
67 * That function calculates the hit ratios, submits the calculated values and
68 * updates the old counter values for the next iteration.
70 #define CFG_WAFL_NAME_CACHE 0x0001
71 #define CFG_WAFL_DIR_CACHE 0x0002
72 #define CFG_WAFL_BUF_CACHE 0x0004
73 #define CFG_WAFL_INODE_CACHE 0x0008
74 #define CFG_WAFL_ALL 0x000F
75 #define HAVE_WAFL_NAME_CACHE_HIT 0x0100
76 #define HAVE_WAFL_NAME_CACHE_MISS 0x0200
77 #define HAVE_WAFL_NAME_CACHE (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
78 #define HAVE_WAFL_FIND_DIR_HIT 0x0400
79 #define HAVE_WAFL_FIND_DIR_MISS 0x0800
80 #define HAVE_WAFL_FIND_DIR (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
81 #define HAVE_WAFL_BUF_HASH_HIT 0x1000
82 #define HAVE_WAFL_BUF_HASH_MISS 0x2000
83 #define HAVE_WAFL_BUF_HASH (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
84 #define HAVE_WAFL_INODE_CACHE_HIT 0x4000
85 #define HAVE_WAFL_INODE_CACHE_MISS 0x8000
86 #define HAVE_WAFL_INODE_CACHE (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
87 #define HAVE_WAFL_ALL 0xff00
90 cna_interval_t interval;
94 uint64_t name_cache_hit;
95 uint64_t name_cache_miss;
96 uint64_t find_dir_hit;
97 uint64_t find_dir_miss;
98 uint64_t buf_hash_hit;
99 uint64_t buf_hash_miss;
100 uint64_t inode_cache_hit;
101 uint64_t inode_cache_miss;
105 * \brief Persistent data for volume performance data.
107 * The code below uses the difference of the operations and latency counters to
108 * calculate an average per-operation latency. For this, old counters need to
109 * be stored in the "data_volume_perf_t" structure. The byte-counters are just
110 * kept for completeness sake. The "flags" member indicates if each counter is
113 * The "query_volume_perf_data" function will fill a new struct of this type
114 * and pass both, old and new data, to "submit_volume_perf_data". In that
115 * function, the per-operation latency is calculated and dispatched, then the
116 * old counters are updated.
118 #define CFG_VOLUME_PERF_INIT 0x0001
119 #define CFG_VOLUME_PERF_IO 0x0002
120 #define CFG_VOLUME_PERF_OPS 0x0003
121 #define CFG_VOLUME_PERF_LATENCY 0x0008
122 #define CFG_VOLUME_PERF_ALL 0x000F
123 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
124 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
125 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
126 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
127 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
128 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
129 #define HAVE_VOLUME_PERF_ALL 0x03F0
138 uint64_t write_bytes;
141 uint64_t read_latency;
142 uint64_t write_latency;
143 } data_volume_perf_t;
146 * \brief Configuration struct for volume usage data (free / used).
148 #define CFG_VOLUME_USAGE_INIT 0x0001
149 #define CFG_VOLUME_USAGE_DF 0x0002
150 #define CFG_VOLUME_USAGE_SNAP 0x0004
151 #define HAVE_VOLUME_USAGE_SNAP 0x0008
155 } cfg_volume_usage_t;
157 typedef struct service_config_s {
159 service_handler_t *handler;
164 struct service_config_s *next;
166 #define SERVICE_INIT {0, 0, 1, 1, 0, 0, 0}
169 * \brief Struct representing a volume.
171 * A volume currently has a name and two sets of values:
173 * - Performance data, such as bytes read/written, number of operations
174 * performed and average time per operation.
176 * - Usage data, i. e. amount of used and free space in the volume.
178 typedef struct volume_s {
180 data_volume_perf_t perf_data;
181 cfg_volume_usage_t cfg_volume_usage;
182 struct volume_s *next;
186 * \brief A disk in the NetApp.
188 * A disk doesn't have any more information than its name at the moment.
189 * The name includes the "disk_" prefix.
191 #define HAVE_DISK_BUSY 0x10
192 #define HAVE_DISK_BASE 0x20
193 #define HAVE_DISK_ALL 0x30
194 typedef struct disk_s {
199 uint64_t base_for_disk_busy;
200 double disk_busy_percent;
204 #define CFG_DISK_BUSIEST 0x01
205 #define CFG_DISK_ALL 0x01
208 cna_interval_t interval;
213 struct host_config_s {
215 na_server_transport_t protocol;
223 cfg_service_t *services;
224 cfg_disk_t *cfg_disk;
225 cfg_wafl_t *cfg_wafl;
226 cfg_system_t *cfg_system;
229 struct host_config_s *next;
231 #define HOST_INIT { NULL, NA_SERVER_TRANSPORT_HTTPS, NULL, 0, NULL, NULL, 0, \
232 NULL, NULL, NULL, NULL, \
235 static host_config_t *global_host_config;
240 * Used to free the various structures above.
242 static void free_volume (volume_t *volume) /* {{{ */
251 sfree (volume->name);
255 } /* }}} void free_volume */
257 static void free_disk (disk_t *disk) /* {{{ */
270 } /* }}} void free_disk */
272 static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
277 if (cw->query != NULL)
278 na_elem_free (cw->query);
281 } /* }}} void free_cfg_wafl */
283 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
285 if (cfg_disk == NULL)
288 if (cfg_disk->query != NULL)
289 na_elem_free (cfg_disk->query);
291 free_disk (cfg_disk->disks);
293 } /* }}} void free_cfg_disk */
295 static void free_cfg_system (cfg_system_t *cs) /* {{{ */
300 if (cs->query != NULL)
301 na_elem_free (cs->query);
304 } /* }}} void free_cfg_system */
306 static void free_cfg_service (cfg_service_t *service) /* {{{ */
313 next = service->next;
315 /* FIXME: Free service->data? */
316 na_elem_free(service->query);
320 free_cfg_service (next);
321 } /* }}} void free_cfg_service */
323 static void free_host_config (host_config_t *hc) /* {{{ */
334 sfree (hc->username);
335 sfree (hc->password);
337 free_cfg_service (hc->services);
338 free_cfg_disk (hc->cfg_disk);
339 free_cfg_wafl (hc->cfg_wafl);
340 free_cfg_system (hc->cfg_system);
341 free_volume (hc->volumes);
345 free_host_config (next);
346 } /* }}} void free_host_config */
349 * Auxiliary functions
351 * Used to look up volumes and disks or to handle flags.
353 static volume_t *get_volume (host_config_t *host, const char *name, /* {{{ */
354 uint32_t vol_usage_flags, uint32_t vol_perf_flags)
361 /* Make sure the default flags include the init-bit. */
362 if (vol_usage_flags != 0)
363 vol_usage_flags |= CFG_VOLUME_USAGE_INIT;
364 if (vol_perf_flags != 0)
365 vol_perf_flags |= CFG_VOLUME_PERF_INIT;
367 for (v = host->volumes; v; v = v->next) {
368 if (strcmp(v->name, name) != 0)
371 /* Check if the flags have been initialized. */
372 if (((v->cfg_volume_usage.flags & CFG_VOLUME_USAGE_INIT) == 0)
373 && (vol_usage_flags != 0))
374 v->cfg_volume_usage.flags = vol_usage_flags;
375 if (((v->perf_data.flags & CFG_VOLUME_PERF_INIT) == 0)
376 && (vol_perf_flags != 0))
377 v->perf_data.flags = vol_perf_flags;
382 DEBUG ("netapp plugin: Allocating new entry for volume %s.", name);
383 v = malloc(sizeof(*v));
386 memset (v, 0, sizeof (*v));
388 v->cfg_volume_usage.flags = vol_usage_flags;
389 v->perf_data.flags = vol_perf_flags;
391 v->name = strdup(name);
392 if (v->name == NULL) {
397 v->next = host->volumes;
401 } /* }}} volume_t *get_volume */
403 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
407 if ((cd == NULL) || (name == NULL))
410 for (d = cd->disks; d != NULL; d = d->next) {
411 if (strcmp(d->name, name) == 0)
415 d = malloc(sizeof(*d));
418 memset (d, 0, sizeof (*d));
421 d->name = strdup(name);
422 if (d->name == NULL) {
431 } /* }}} disk_t *get_disk */
433 static void host_set_all_perf_data_flags(const host_config_t *host, /* {{{ */
434 uint32_t flag, _Bool set)
438 for (v = host->volumes; v; v = v->next) {
440 v->perf_data.flags |= flag;
442 v->perf_data.flags &= ~flag;
444 } /* }}} void host_set_all_perf_data_flags */
446 static void host_set_all_cfg_volume_usage_flags(const host_config_t *host, /* {{{ */
447 uint32_t flag, _Bool set) {
450 for (v = host->volumes; v; v = v->next) {
452 v->cfg_volume_usage.flags |= flag;
454 v->cfg_volume_usage.flags &= ~flag;
456 } /* }}} void host_set_all_cfg_volume_usage_flags */
459 * Various submit functions.
461 * They all eventually call "submit_values" which creates a value_list_t and
462 * dispatches it to the daemon.
464 static int submit_values (const char *host, /* {{{ */
465 const char *plugin_inst,
466 const char *type, const char *type_inst,
467 value_t *values, int values_len,
470 value_list_t vl = VALUE_LIST_INIT;
473 vl.values_len = values_len;
479 sstrncpy (vl.host, host, sizeof (vl.host));
481 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
482 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
483 if (plugin_inst != NULL)
484 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
485 sstrncpy (vl.type, type, sizeof (vl.type));
486 if (type_inst != NULL)
487 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
489 return (plugin_dispatch_values (&vl));
490 } /* }}} int submit_uint64 */
492 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
493 const char *type, const char *type_inst, counter_t val0, counter_t val1,
498 values[0].counter = val0;
499 values[1].counter = val1;
501 return (submit_values (host, plugin_inst, type, type_inst,
502 values, 2, timestamp));
503 } /* }}} int submit_two_counters */
505 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
506 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
512 return (submit_values (host, plugin_inst, type, type_inst,
514 } /* }}} int submit_counter */
516 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
517 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
522 values[0].gauge = val0;
523 values[1].gauge = val1;
525 return (submit_values (host, plugin_inst, type, type_inst,
526 values, 2, timestamp));
527 } /* }}} int submit_two_gauge */
529 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
530 const char *type, const char *type_inst, double d, time_t timestamp)
534 v.gauge = (gauge_t) d;
536 return (submit_values (host, plugin_inst, type, type_inst,
538 } /* }}} int submit_uint64 */
540 /* Calculate hit ratio from old and new counters and submit the resulting
541 * percentage. Used by "submit_wafl_data". */
542 static int submit_cache_ratio (const char *host, /* {{{ */
543 const char *plugin_inst,
544 const char *type_inst,
553 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
557 hits = new_hits - old_hits;
558 misses = new_misses - old_misses;
560 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
565 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
567 } /* }}} int submit_cache_ratio */
569 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
570 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
571 cfg_wafl_t *old_data, const cfg_wafl_t *new_data)
573 /* Submit requested counters */
574 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
575 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
576 submit_cache_ratio (hostname, instance, "name_cache_hit",
577 new_data->name_cache_hit, new_data->name_cache_miss,
578 old_data->name_cache_hit, old_data->name_cache_miss,
579 new_data->timestamp);
581 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
582 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
583 submit_cache_ratio (hostname, instance, "find_dir_hit",
584 new_data->find_dir_hit, new_data->find_dir_miss,
585 old_data->find_dir_hit, old_data->find_dir_miss,
586 new_data->timestamp);
588 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
589 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
590 submit_cache_ratio (hostname, instance, "buf_hash_hit",
591 new_data->buf_hash_hit, new_data->buf_hash_miss,
592 old_data->buf_hash_hit, old_data->buf_hash_miss,
593 new_data->timestamp);
595 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
596 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
597 submit_cache_ratio (hostname, instance, "inode_cache_hit",
598 new_data->inode_cache_hit, new_data->inode_cache_miss,
599 old_data->inode_cache_hit, old_data->inode_cache_miss,
600 new_data->timestamp);
602 /* Clear old HAVE_* flags */
603 old_data->flags &= ~HAVE_WAFL_ALL;
605 /* Copy all counters */
606 old_data->timestamp = new_data->timestamp;
607 old_data->name_cache_hit = new_data->name_cache_hit;
608 old_data->name_cache_miss = new_data->name_cache_miss;
609 old_data->find_dir_hit = new_data->find_dir_hit;
610 old_data->find_dir_miss = new_data->find_dir_miss;
611 old_data->buf_hash_hit = new_data->buf_hash_hit;
612 old_data->buf_hash_miss = new_data->buf_hash_miss;
613 old_data->inode_cache_hit = new_data->inode_cache_hit;
614 old_data->inode_cache_miss = new_data->inode_cache_miss;
616 /* Copy HAVE_* flags */
617 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
620 } /* }}} int submit_wafl_data */
622 /* Submits volume performance data to the daemon, taking care to honor and
623 * update flags appropriately. */
624 static int submit_volume_perf_data (const host_config_t *host, /* {{{ */
626 const data_volume_perf_t *new_data)
628 /* Check for and submit disk-octet values */
629 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_IO)
630 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
632 submit_two_counters (host->name, volume->name, "disk_octets", /* type instance = */ NULL,
633 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
636 /* Check for and submit disk-operations values */
637 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_OPS)
638 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
640 submit_two_counters (host->name, volume->name, "disk_ops", /* type instance = */ NULL,
641 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
644 /* Check for, calculate and submit disk-latency values */
645 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_LATENCY
646 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
647 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
648 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
649 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
651 gauge_t latency_per_op_read;
652 gauge_t latency_per_op_write;
654 latency_per_op_read = NAN;
655 latency_per_op_write = NAN;
657 /* Check if a counter wrapped around. */
658 if ((new_data->read_ops > volume->perf_data.read_ops)
659 && (new_data->read_latency > volume->perf_data.read_latency))
661 uint64_t diff_ops_read;
662 uint64_t diff_latency_read;
664 diff_ops_read = new_data->read_ops - volume->perf_data.read_ops;
665 diff_latency_read = new_data->read_latency - volume->perf_data.read_latency;
667 if (diff_ops_read > 0)
668 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
671 if ((new_data->write_ops > volume->perf_data.write_ops)
672 && (new_data->write_latency > volume->perf_data.write_latency))
674 uint64_t diff_ops_write;
675 uint64_t diff_latency_write;
677 diff_ops_write = new_data->write_ops - volume->perf_data.write_ops;
678 diff_latency_write = new_data->write_latency - volume->perf_data.write_latency;
680 if (diff_ops_write > 0)
681 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
684 submit_two_gauge (host->name, volume->name, "disk_latency", /* type instance = */ NULL,
685 latency_per_op_read, latency_per_op_write, new_data->timestamp);
688 /* Clear all HAVE_* flags. */
689 volume->perf_data.flags &= ~HAVE_VOLUME_PERF_ALL;
691 /* Copy all counters */
692 volume->perf_data.timestamp = new_data->timestamp;
693 volume->perf_data.read_bytes = new_data->read_bytes;
694 volume->perf_data.write_bytes = new_data->write_bytes;
695 volume->perf_data.read_ops = new_data->read_ops;
696 volume->perf_data.write_ops = new_data->write_ops;
697 volume->perf_data.read_latency = new_data->read_latency;
698 volume->perf_data.write_latency = new_data->write_latency;
700 /* Copy the HAVE_* flags */
701 volume->perf_data.flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
704 } /* }}} int submit_volume_perf_data */
709 * These functions are called with appropriate data returned by the libnetapp
710 * interface which is parsed and submitted with the above functions.
712 /* Data corresponding to <WAFL /> */
713 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
716 cfg_wafl_t perf_data;
717 const char *plugin_inst;
719 na_elem_t *instances;
721 na_elem_iter_t counter_iter;
723 memset (&perf_data, 0, sizeof (perf_data));
725 perf_data.timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
727 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
728 if (instances == NULL)
730 ERROR ("netapp plugin: cna_handle_wafl_data: "
731 "na_elem_child (\"instances\") failed.");
735 plugin_inst = na_child_get_string(instances, "name");
736 if (plugin_inst == NULL)
738 ERROR ("netapp plugin: cna_handle_wafl_data: "
739 "na_child_get_string (\"name\") failed.");
743 /* Iterate over all counters */
744 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
745 for (counter = na_iterator_next (&counter_iter);
747 counter = na_iterator_next (&counter_iter))
752 name = na_child_get_string(counter, "name");
756 value = na_child_get_uint64(counter, "value", UINT64_MAX);
757 if (value == UINT64_MAX)
760 if (!strcmp(name, "name_cache_hit")) {
761 perf_data.name_cache_hit = value;
762 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
763 } else if (!strcmp(name, "name_cache_miss")) {
764 perf_data.name_cache_miss = value;
765 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
766 } else if (!strcmp(name, "find_dir_hit")) {
767 perf_data.find_dir_hit = value;
768 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
769 } else if (!strcmp(name, "find_dir_miss")) {
770 perf_data.find_dir_miss = value;
771 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
772 } else if (!strcmp(name, "buf_hash_hit")) {
773 perf_data.buf_hash_hit = value;
774 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
775 } else if (!strcmp(name, "buf_hash_miss")) {
776 perf_data.buf_hash_miss = value;
777 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
778 } else if (!strcmp(name, "inode_cache_hit")) {
779 perf_data.inode_cache_hit = value;
780 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
781 } else if (!strcmp(name, "inode_cache_miss")) {
782 perf_data.inode_cache_miss = value;
783 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
785 DEBUG("netapp plugin: cna_handle_wafl_data: "
786 "Found unexpected child: %s", name);
790 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data));
791 } /* }}} void cna_handle_wafl_data */
793 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
800 if (cw->query != NULL)
803 cw->query = na_elem_new("perf-object-get-instances");
804 if (cw->query == NULL)
806 ERROR ("netapp plugin: na_elem_new failed.");
809 na_child_add_string (cw->query, "objectname", "wafl");
811 e = na_elem_new("counters");
814 na_elem_free (cw->query);
816 ERROR ("netapp plugin: na_elem_new failed.");
819 na_child_add_string(e, "foo", "name_cache_hit");
820 na_child_add_string(e, "foo", "name_cache_miss");
821 na_child_add_string(e, "foo", "find_dir_hit");
822 na_child_add_string(e, "foo", "find_dir_miss");
823 na_child_add_string(e, "foo", "buf_hash_hit");
824 na_child_add_string(e, "foo", "buf_hash_miss");
825 na_child_add_string(e, "foo", "inode_cache_hit");
826 na_child_add_string(e, "foo", "inode_cache_miss");
828 na_child_add(cw->query, e);
831 } /* }}} int cna_setup_wafl */
833 static int cna_query_wafl (host_config_t *host) /* {{{ */
842 /* If WAFL was not configured, return without doing anything. */
843 if (host->cfg_wafl == NULL)
847 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
850 status = cna_setup_wafl (host->cfg_wafl);
853 assert (host->cfg_wafl->query != NULL);
855 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
856 if (na_results_status (data) != NA_OK)
858 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed: %s",
859 na_results_reason (data));
864 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data);
867 host->cfg_wafl->interval.last_read = now;
871 } /* }}} int cna_query_wafl */
873 /* Data corresponding to <Disks /> */
874 static int cna_handle_disk_data (const char *hostname, /* {{{ */
875 cfg_disk_t *cfg_disk, na_elem_t *data)
878 na_elem_t *instances;
880 na_elem_iter_t instance_iter;
881 disk_t *worst_disk = NULL;
883 if ((cfg_disk == NULL) || (data == NULL))
886 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
888 instances = na_elem_child (data, "instances");
889 if (instances == NULL)
891 ERROR ("netapp plugin: cna_handle_disk_data: "
892 "na_elem_child (\"instances\") failed.");
896 /* Iterate over all children */
897 instance_iter = na_child_iterator (instances);
898 for (instance = na_iterator_next (&instance_iter);
900 instance = na_iterator_next(&instance_iter))
905 na_elem_iter_t counter_iterator;
908 memset (&new_data, 0, sizeof (new_data));
909 new_data.timestamp = timestamp;
910 new_data.disk_busy_percent = NAN;
912 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
913 if (old_data == NULL)
916 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
917 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
918 for (counter = na_iterator_next(&counter_iterator);
920 counter = na_iterator_next(&counter_iterator))
925 name = na_child_get_string(counter, "name");
929 value = na_child_get_uint64(counter, "value", UINT64_MAX);
930 if (value == UINT64_MAX)
933 if (strcmp(name, "disk_busy") == 0)
935 new_data.disk_busy = value;
936 new_data.flags |= HAVE_DISK_BUSY;
938 else if (strcmp(name, "base_for_disk_busy") == 0)
940 new_data.base_for_disk_busy = value;
941 new_data.flags |= HAVE_DISK_BASE;
945 DEBUG ("netapp plugin: cna_handle_disk_data: "
946 "Counter not handled: %s = %"PRIu64,
951 /* If all required counters are available and did not just wrap around,
952 * calculate the busy percentage. Otherwise, the value is initialized to
953 * NAN at the top of the for-loop. */
954 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
955 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
956 && (new_data.disk_busy >= old_data->disk_busy)
957 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
962 busy_diff = new_data.disk_busy - old_data->disk_busy;
963 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
965 new_data.disk_busy_percent = 100.0
966 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
969 /* Clear HAVE_* flags */
970 old_data->flags &= ~HAVE_DISK_ALL;
973 old_data->timestamp = new_data.timestamp;
974 old_data->disk_busy = new_data.disk_busy;
975 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
976 old_data->disk_busy_percent = new_data.disk_busy_percent;
979 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
981 if ((worst_disk == NULL)
982 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
983 worst_disk = old_data;
984 } /* for (all disks) */
986 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
987 submit_double (hostname, "system", "percent", "disk_busy",
988 worst_disk->disk_busy_percent, timestamp);
991 } /* }}} int cna_handle_disk_data */
993 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1000 if (cd->query != NULL)
1003 cd->query = na_elem_new ("perf-object-get-instances");
1004 if (cd->query == NULL)
1006 ERROR ("netapp plugin: na_elem_new failed.");
1009 na_child_add_string (cd->query, "objectname", "disk");
1011 e = na_elem_new("counters");
1014 na_elem_free (cd->query);
1016 ERROR ("netapp plugin: na_elem_new failed.");
1019 na_child_add_string(e, "foo", "disk_busy");
1020 na_child_add_string(e, "foo", "base_for_disk_busy");
1021 na_child_add(cd->query, e);
1024 } /* }}} int cna_setup_disk */
1026 static int cna_query_disk (host_config_t *host) /* {{{ */
1035 /* If the user did not configure disk statistics, return without doing
1037 if (host->cfg_disk == NULL)
1041 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1044 status = cna_setup_disk (host->cfg_disk);
1047 assert (host->cfg_disk->query != NULL);
1049 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1050 if (na_results_status (data) != NA_OK)
1052 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed: %s",
1053 na_results_reason (data));
1054 na_elem_free (data);
1058 status = cna_handle_disk_data (host->name, host->cfg_disk, data);
1061 host->cfg_disk->interval.last_read = now;
1063 na_elem_free (data);
1065 } /* }}} int cna_query_disk */
1067 /* Data corresponding to <GetVolumeData /> */
1068 static void collect_volume_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
1071 cfg_volume_usage_t *cfg_volume_data = data;
1073 out = na_elem_child(out, "volumes");
1074 na_elem_iter_t inst_iter = na_child_iterator(out);
1075 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
1076 uint64_t size_free = 0, size_used = 0, snap_reserved = 0;
1079 const char *sis_state;
1080 uint64_t sis_saved_reported;
1083 volume = get_volume(host, na_child_get_string(inst, "name"),
1084 cfg_volume_data->flags, /* perf_flags = */ 0);
1088 if (!(volume->cfg_volume_usage.flags & CFG_VOLUME_USAGE_DF))
1091 /* 2^4 exa-bytes? This will take a while ;) */
1092 size_free = na_child_get_uint64(inst, "size-available", UINT64_MAX);
1093 if (size_free != UINT64_MAX)
1094 submit_double (host->name, volume->name, "df_complex", "free",
1095 (double) size_free, /* time = */ 0);
1097 size_used = na_child_get_uint64(inst, "size-used", UINT64_MAX);
1098 if (size_used != UINT64_MAX) {
1099 if ((volume->cfg_volume_usage.flags & HAVE_VOLUME_USAGE_SNAP)
1100 && (size_used >= volume->cfg_volume_usage.snap_used))
1101 size_used -= volume->cfg_volume_usage.snap_used;
1102 submit_double (host->name, volume->name, "df_complex", "used",
1103 (double) size_used, /* time = */ 0);
1106 snap_reserved = na_child_get_uint64(inst, "snapshot-blocks-reserved", UINT64_MAX);
1107 if (!(volume->cfg_volume_usage.flags & HAVE_VOLUME_USAGE_SNAP) && (snap_reserved != UINT64_MAX))
1108 /* If we have snap usage data this value has already been submitted. */
1109 /* 1 block == 1024 bytes as per API docs */
1110 submit_double (host->name, volume->name, "df_complex", "snap_reserved",
1111 (double) (1024 * snap_reserved), /* time = */ 0);
1113 sis = na_elem_child(inst, "sis");
1117 sis_state = na_child_get_string(sis, "state");
1118 if ((sis_state == NULL)
1119 || (strcmp ("enabled", sis_state) != 0))
1122 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1123 if (sis_saved_reported == UINT64_MAX)
1126 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1127 if ((sis_saved_reported >> 32) != 0) {
1128 /* In case they ever fix this bug. */
1129 sis_saved = sis_saved_reported;
1131 uint64_t sis_saved_percent;
1132 uint64_t sis_saved_guess;
1133 uint64_t overflow_guess;
1134 uint64_t guess1, guess2, guess3;
1136 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1137 if (sis_saved_percent > 100)
1140 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1141 * will hopefully be fixed in later versions. To work around the bug, try
1142 * to figure out how often the 32bit integer wrapped around by using the
1143 * "percentage-saved" value. Because the percentage is in the range
1144 * [0-100], this should work as long as the saved space does not exceed
1146 /* percentage-saved = size-saved / (size-saved + size-used) */
1147 if (sis_saved_percent < 100)
1148 sis_saved_guess = size_used * sis_saved_percent / (100 - sis_saved_percent);
1150 sis_saved_guess = size_used;
1152 overflow_guess = sis_saved_guess >> 32;
1153 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1154 guess2 = (overflow_guess << 32) + sis_saved_reported;
1155 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1157 if (sis_saved_guess < guess2) {
1158 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1163 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1168 } /* end of 32-bit workaround */
1170 submit_double (host->name, volume->name, "df_complex", "sis_saved",
1171 (double) sis_saved, /* time = */ 0);
1173 } /* }}} void collect_volume_data */
1175 /* Data corresponding to <GetVolumePerfData /> */
1176 static void query_volume_perf_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
1177 cfg_volume_perf_t *cfg_volume_perf = data;
1179 na_elem_t *counter, *inst;
1181 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
1183 out = na_elem_child(out, "instances");
1184 na_elem_iter_t inst_iter = na_child_iterator(out);
1185 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
1186 data_volume_perf_t perf_data;
1189 memset (&perf_data, 0, sizeof (perf_data));
1190 perf_data.timestamp = timestamp;
1192 volume = get_volume(host, na_child_get_string(inst, "name"),
1193 /* data_flags = */ 0, cfg_volume_perf->flags);
1197 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
1198 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
1202 name = na_child_get_string(counter, "name");
1206 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1207 if (value == UINT64_MAX)
1210 if (!strcmp(name, "read_data")) {
1211 perf_data.read_bytes = value;
1212 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1213 } else if (!strcmp(name, "write_data")) {
1214 perf_data.write_bytes = value;
1215 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1216 } else if (!strcmp(name, "read_ops")) {
1217 perf_data.read_ops = value;
1218 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1219 } else if (!strcmp(name, "write_ops")) {
1220 perf_data.write_ops = value;
1221 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1222 } else if (!strcmp(name, "read_latency")) {
1223 perf_data.read_latency = value;
1224 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1225 } else if (!strcmp(name, "write_latency")) {
1226 perf_data.write_latency = value;
1227 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1231 submit_volume_perf_data (host, volume, &perf_data);
1232 } /* for (volume) */
1233 } /* }}} void query_volume_perf_data */
1235 /* Data corresponding to <System /> */
1236 static int cna_handle_system_data (const char *hostname, /* {{{ */
1237 cfg_system_t *cfg_system, na_elem_t *data)
1239 na_elem_t *instances;
1241 na_elem_iter_t counter_iter;
1243 counter_t disk_read = 0, disk_written = 0;
1244 counter_t net_recv = 0, net_sent = 0;
1245 counter_t cpu_busy = 0, cpu_total = 0;
1246 uint32_t counter_flags = 0;
1248 const char *instance;
1251 timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
1253 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1254 if (instances == NULL)
1256 ERROR ("netapp plugin: cna_handle_system_data: "
1257 "na_elem_child (\"instances\") failed.");
1261 instance = na_child_get_string (instances, "name");
1262 if (instance == NULL)
1264 ERROR ("netapp plugin: cna_handle_system_data: "
1265 "na_child_get_string (\"name\") failed.");
1269 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
1270 for (counter = na_iterator_next (&counter_iter);
1272 counter = na_iterator_next (&counter_iter))
1277 name = na_child_get_string(counter, "name");
1281 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1282 if (value == UINT64_MAX)
1285 if (!strcmp(name, "disk_data_read")) {
1286 disk_read = (counter_t) (value * 1024);
1287 counter_flags |= 0x01;
1288 } else if (!strcmp(name, "disk_data_written")) {
1289 disk_written = (counter_t) (value * 1024);
1290 counter_flags |= 0x02;
1291 } else if (!strcmp(name, "net_data_recv")) {
1292 net_recv = (counter_t) (value * 1024);
1293 counter_flags |= 0x04;
1294 } else if (!strcmp(name, "net_data_sent")) {
1295 net_sent = (counter_t) (value * 1024);
1296 counter_flags |= 0x08;
1297 } else if (!strcmp(name, "cpu_busy")) {
1298 cpu_busy = (counter_t) value;
1299 counter_flags |= 0x10;
1300 } else if (!strcmp(name, "cpu_elapsed_time")) {
1301 cpu_total = (counter_t) value;
1302 counter_flags |= 0x20;
1303 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1304 && (value > 0) && (strlen(name) > 4)
1305 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1306 submit_counter (hostname, instance, "disk_ops_complex", name,
1307 (counter_t) value, timestamp);
1309 } /* for (counter) */
1311 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1312 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
1313 submit_two_counters (hostname, instance, "disk_octets", NULL,
1314 disk_read, disk_written, timestamp);
1316 if ((cfg_system->flags & CFG_SYSTEM_NET)
1317 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
1318 submit_two_counters (hostname, instance, "if_octets", NULL,
1319 net_recv, net_sent, timestamp);
1321 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1322 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
1324 submit_counter (hostname, instance, "cpu", "system",
1325 cpu_busy, timestamp);
1326 submit_counter (hostname, instance, "cpu", "idle",
1327 cpu_total - cpu_busy, timestamp);
1331 } /* }}} int cna_handle_system_data */
1333 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
1338 if (cs->query != NULL)
1341 cs->query = na_elem_new ("perf-object-get-instances");
1342 if (cs->query == NULL)
1344 ERROR ("netapp plugin: na_elem_new failed.");
1347 na_child_add_string (cs->query, "objectname", "system");
1350 } /* }}} int cna_setup_system */
1352 static int cna_query_system (host_config_t *host) /* {{{ */
1361 /* If system statistics were not configured, return without doing anything. */
1362 if (host->cfg_system == NULL)
1366 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
1369 status = cna_setup_system (host->cfg_system);
1372 assert (host->cfg_system->query != NULL);
1374 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
1375 if (na_results_status (data) != NA_OK)
1377 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed: %s",
1378 na_results_reason (data));
1379 na_elem_free (data);
1383 status = cna_handle_system_data (host->name, host->cfg_system, data);
1386 host->cfg_system->interval.last_read = now;
1388 na_elem_free (data);
1390 } /* }}} int cna_query_system */
1393 * Configuration handling
1395 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1396 * is false. On error, the flag-field is not changed. */
1397 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1398 uint32_t *flags, uint32_t flag)
1400 if ((ci == NULL) || (flags == NULL))
1403 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1405 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1410 if (ci->values[0].value.boolean)
1416 } /* }}} int cna_config_bool_to_flag */
1418 /* Handling of the "Multiplier" option which is allowed in every block. */
1419 static int cna_config_get_multiplier (const oconfig_item_t *ci, /* {{{ */
1420 cfg_service_t *service)
1424 if ((ci == NULL) || (service == NULL))
1427 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1429 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1433 tmp = (int) (ci->values[0].value.number + .5);
1436 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1440 service->multiplier = tmp;
1441 service->skip_countdown = tmp;
1444 } /* }}} int cna_config_get_multiplier */
1446 /* Handling of the "Interval" option which is allowed in every block. */
1447 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1448 cna_interval_t *out_interval)
1452 if ((ci == NULL) || (out_interval == NULL))
1455 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1457 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1461 tmp = (time_t) (ci->values[0].value.number + .5);
1464 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1468 out_interval->interval = tmp;
1469 out_interval->last_read = 0;
1472 } /* }}} int cna_config_get_interval */
1474 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1475 * <GetVolumePerfData /> block. */
1476 static void cna_config_volume_performance_option (host_config_t *host, /* {{{ */
1477 cfg_volume_perf_t *perf_volume, const oconfig_item_t *item,
1482 for (i = 0; i < item->values_num; ++i) {
1487 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1488 WARNING("netapp plugin: Ignoring non-string argument in "
1489 "\"GetVolumePerfData\" block for host %s", host->name);
1493 name = item->values[i].value.string;
1494 if (name[0] == '+') {
1497 } else if (name[0] == '-') {
1504 perf_volume->flags |= flag;
1505 else /* if (!set) */
1506 perf_volume->flags &= ~flag;
1508 host_set_all_perf_data_flags(host, flag, set);
1512 v = get_volume (host, name, /* data_flags = */ 0, perf_volume->flags);
1517 v->perf_data.flags |= flag;
1518 else /* if (!set) */
1519 v->perf_data.flags &= ~flag;
1520 } /* for (i = 0 .. item->values_num) */
1521 } /* }}} void cna_config_volume_performance_option */
1523 /* Corresponds to a <GetVolumePerfData /> block */
1524 static void cna_config_volume_performance(host_config_t *host, const oconfig_item_t *ci) { /* {{{ */
1525 int i, had_io = 0, had_ops = 0, had_latency = 0;
1526 cfg_service_t *service;
1527 cfg_volume_perf_t *perf_volume;
1529 service = malloc(sizeof(*service));
1531 service->handler = query_volume_perf_data;
1532 perf_volume = service->data = malloc(sizeof(*perf_volume));
1533 perf_volume->flags = CFG_VOLUME_PERF_INIT;
1534 service->next = host->services;
1535 host->services = service;
1536 for (i = 0; i < ci->children_num; ++i) {
1537 oconfig_item_t *item = ci->children + i;
1539 /* if (!item || !item->key || !*item->key) continue; */
1540 if (!strcasecmp(item->key, "Multiplier")) {
1541 cna_config_get_multiplier (item, service);
1542 } else if (!strcasecmp(item->key, "GetIO")) {
1544 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_IO);
1545 } else if (!strcasecmp(item->key, "GetOps")) {
1547 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_OPS);
1548 } else if (!strcasecmp(item->key, "GetLatency")) {
1550 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_LATENCY);
1554 perf_volume->flags |= CFG_VOLUME_PERF_IO;
1555 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_IO, /* set = */ true);
1558 perf_volume->flags |= CFG_VOLUME_PERF_OPS;
1559 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_OPS, /* set = */ true);
1562 perf_volume->flags |= CFG_VOLUME_PERF_LATENCY;
1563 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_LATENCY, /* set = */ true);
1565 } /* }}} void cna_config_volume_performance */
1567 /* Handling of the "GetDiskUtil" option within a <GetVolumeData /> block. */
1568 static void cna_config_volume_usage_option (host_config_t *host, /* {{{ */
1569 cfg_volume_usage_t *cfg_volume_data, const oconfig_item_t *item, uint32_t flag)
1573 for (i = 0; i < item->values_num; ++i) {
1578 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1579 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolData\""
1580 "block for host %s", host->name);
1584 name = item->values[i].value.string;
1585 if (name[0] == '+') {
1588 } else if (name[0] == '-') {
1595 cfg_volume_data->flags |= flag;
1596 else /* if (!set) */
1597 cfg_volume_data->flags &= ~flag;
1599 host_set_all_cfg_volume_usage_flags(host, flag, set);
1603 v = get_volume(host, name, cfg_volume_data->flags, /* perf_flags = */ 0);
1607 if (!v->cfg_volume_usage.flags)
1608 v->cfg_volume_usage.flags = cfg_volume_data->flags;
1611 v->cfg_volume_usage.flags |= flag;
1612 else /* if (!set) */
1613 v->cfg_volume_usage.flags &= ~flag;
1615 } /* }}} void cna_config_volume_usage_option */
1617 /* Corresponds to a <GetVolumeData /> block */
1618 static void cna_config_volume_usage(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1620 cfg_service_t *service;
1621 cfg_volume_usage_t *cfg_volume_data;
1623 service = malloc(sizeof(*service));
1625 service->handler = collect_volume_data;
1626 cfg_volume_data = service->data = malloc(sizeof(*cfg_volume_data));
1627 cfg_volume_data->flags = CFG_VOLUME_USAGE_INIT;
1628 service->next = host->services;
1629 host->services = service;
1630 for (i = 0; i < ci->children_num; ++i) {
1631 oconfig_item_t *item = ci->children + i;
1633 /* if (!item || !item->key || !*item->key) continue; */
1634 if (!strcasecmp(item->key, "Multiplier")) {
1635 cna_config_get_multiplier (item, service);
1636 } else if (!strcasecmp(item->key, "GetDiskUtil")) {
1638 cna_config_volume_usage_option(host, cfg_volume_data, item, CFG_VOLUME_USAGE_DF);
1639 } else if (!strcasecmp(item->key, "GetSnapUtil")) {
1641 cna_config_volume_usage_option(host, cfg_volume_data, item, CFG_VOLUME_USAGE_SNAP);
1645 cfg_volume_data->flags |= CFG_VOLUME_USAGE_DF;
1646 host_set_all_cfg_volume_usage_flags(host, CFG_VOLUME_USAGE_DF, /* set = */ true);
1648 if (cfg_volume_data->flags & CFG_VOLUME_USAGE_SNAP) {
1649 WARNING("netapp plugin: The \"GetSnapUtil\" option does not support the \"+\" wildcard.");
1651 } /* }}} void cna_config_volume_usage */
1653 /* Corresponds to a <Disks /> block */
1654 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1655 cfg_disk_t *cfg_disk;
1658 if ((host == NULL) || (ci == NULL))
1661 if (host->cfg_disk == NULL)
1663 cfg_disk = malloc (sizeof (*cfg_disk));
1664 if (cfg_disk == NULL)
1666 memset (cfg_disk, 0, sizeof (*cfg_disk));
1668 /* Set default flags */
1669 cfg_disk->flags = CFG_DISK_ALL;
1670 cfg_disk->query = NULL;
1671 cfg_disk->disks = NULL;
1673 host->cfg_disk = cfg_disk;
1675 cfg_disk = host->cfg_disk;
1677 for (i = 0; i < ci->children_num; ++i) {
1678 oconfig_item_t *item = ci->children + i;
1680 /* if (!item || !item->key || !*item->key) continue; */
1681 if (strcasecmp(item->key, "Interval") == 0)
1682 cna_config_get_interval (item, &cfg_disk->interval);
1683 else if (strcasecmp(item->key, "GetBusy") == 0)
1684 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
1687 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
1689 NOTICE ("netapp plugin: All disk related values have been disabled. "
1690 "Collection of per-disk data will be disabled entirely.");
1691 free_cfg_disk (host->cfg_disk);
1692 host->cfg_disk = NULL;
1696 } /* }}} int cna_config_disk */
1698 /* Corresponds to a <WAFL /> block */
1699 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
1701 cfg_wafl_t *cfg_wafl;
1704 if ((host == NULL) || (ci == NULL))
1707 if (host->cfg_wafl == NULL)
1709 cfg_wafl = malloc (sizeof (*cfg_wafl));
1710 if (cfg_wafl == NULL)
1712 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
1714 /* Set default flags */
1715 cfg_wafl->flags = CFG_WAFL_ALL;
1717 host->cfg_wafl = cfg_wafl;
1719 cfg_wafl = host->cfg_wafl;
1721 for (i = 0; i < ci->children_num; ++i) {
1722 oconfig_item_t *item = ci->children + i;
1724 if (strcasecmp(item->key, "Interval") == 0)
1725 cna_config_get_interval (item, &cfg_wafl->interval);
1726 else if (!strcasecmp(item->key, "GetNameCache"))
1727 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
1728 else if (!strcasecmp(item->key, "GetDirCache"))
1729 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
1730 else if (!strcasecmp(item->key, "GetBufferCache"))
1731 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
1732 else if (!strcasecmp(item->key, "GetInodeCache"))
1733 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
1735 WARNING ("netapp plugin: The %s config option is not allowed within "
1736 "`WAFL' blocks.", item->key);
1739 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
1741 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
1742 "Collection of WAFL data will be disabled entirely.");
1743 free_cfg_wafl (host->cfg_wafl);
1744 host->cfg_wafl = NULL;
1748 } /* }}} int cna_config_wafl */
1750 /* Corresponds to a <System /> block */
1751 static int cna_config_system (host_config_t *host, /* {{{ */
1752 oconfig_item_t *ci, const cfg_service_t *default_service)
1754 cfg_system_t *cfg_system;
1757 if ((host == NULL) || (ci == NULL))
1760 if (host->cfg_system == NULL)
1762 cfg_system = malloc (sizeof (*cfg_system));
1763 if (cfg_system == NULL)
1765 memset (cfg_system, 0, sizeof (*cfg_system));
1767 /* Set default flags */
1768 cfg_system->flags = CFG_SYSTEM_ALL;
1769 cfg_system->query = NULL;
1771 host->cfg_system = cfg_system;
1773 cfg_system = host->cfg_system;
1775 for (i = 0; i < ci->children_num; ++i) {
1776 oconfig_item_t *item = ci->children + i;
1778 if (strcasecmp(item->key, "Interval") == 0) {
1779 cna_config_get_interval (item, &cfg_system->interval);
1780 } else if (!strcasecmp(item->key, "GetCPULoad")) {
1781 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
1782 } else if (!strcasecmp(item->key, "GetInterfaces")) {
1783 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
1784 } else if (!strcasecmp(item->key, "GetDiskOps")) {
1785 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
1786 } else if (!strcasecmp(item->key, "GetDiskIO")) {
1787 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
1789 WARNING ("netapp plugin: The %s config option is not allowed within "
1790 "`System' blocks.", item->key);
1794 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
1796 NOTICE ("netapp plugin: All system related values have been disabled. "
1797 "Collection of system data will be disabled entirely.");
1798 free_cfg_system (host->cfg_system);
1799 host->cfg_system = NULL;
1803 } /* }}} int cna_config_system */
1805 /* Corresponds to a <Host /> block. */
1806 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
1807 const host_config_t *default_host, const cfg_service_t *def_def_service)
1809 oconfig_item_t *item;
1810 host_config_t *host;
1811 cfg_service_t default_service = *def_def_service;
1815 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1816 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
1820 host = malloc(sizeof(*host));
1821 memcpy (host, default_host, sizeof (*host));
1823 status = cf_util_get_string (ci, &host->name);
1830 for (i = 0; i < ci->children_num; ++i) {
1831 item = ci->children + i;
1835 if (!strcasecmp(item->key, "Address")) {
1836 status = cf_util_get_string (item, &host->host);
1837 } else if (!strcasecmp(item->key, "Port")) {
1840 tmp = cf_util_get_port_number (item);
1843 } else if (!strcasecmp(item->key, "Protocol")) {
1844 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"))) {
1845 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
1848 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
1849 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
1850 } else if (!strcasecmp(item->key, "User")) {
1851 status = cf_util_get_string (item, &host->username);
1852 } else if (!strcasecmp(item->key, "Password")) {
1853 status = cf_util_get_string (item, &host->password);
1854 } else if (!strcasecmp(item->key, "Interval")) {
1855 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) {
1856 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
1859 host->interval = item->values[0].value.number;
1860 } else if (!strcasecmp(item->key, "GetVolumePerfData")) {
1861 cna_config_volume_performance(host, item);
1862 } else if (!strcasecmp(item->key, "System")) {
1863 cna_config_system(host, item, &default_service);
1864 } else if (!strcasecmp(item->key, "WAFL")) {
1865 cna_config_wafl(host, item);
1866 } else if (!strcasecmp(item->key, "Disks")) {
1867 cna_config_disk(host, item);
1868 } else if (!strcasecmp(item->key, "GetVolumeData")) {
1869 cna_config_volume_usage(host, item);
1871 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
1872 item->key, ci->values[0].value.string);
1879 if (host->host == NULL)
1880 host->host = strdup (host->name);
1882 if (host->host == NULL)
1885 if (host->port <= 0)
1886 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
1888 if ((host->username == NULL) || (host->password == NULL)) {
1889 WARNING("netapp plugin: Please supply login information for host \"%s\". "
1890 "Ignoring host block.", host->name);
1896 free_host_config (host);
1901 } /* }}} host_config_t *cna_config_host */
1904 * Callbacks registered with the daemon
1906 * Pretty standard stuff here.
1908 static int cna_init(void) { /* {{{ */
1911 host_config_t *host;
1912 cfg_service_t *service;
1914 if (!global_host_config) {
1915 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
1919 memset (err, 0, sizeof (err));
1920 if (!na_startup(err, sizeof(err))) {
1921 err[sizeof (err) - 1] = 0;
1922 ERROR("netapp plugin: Error initializing netapp API: %s", err);
1926 for (host = global_host_config; host; host = host->next) {
1927 /* Request version 1.1 of the ONTAP API */
1928 host->srv = na_server_open(host->host,
1929 /* major version = */ 1, /* minor version = */ 1);
1930 if (host->srv == NULL) {
1931 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
1935 if (host->interval < interval_g)
1936 host->interval = interval_g;
1938 na_server_set_transport_type(host->srv, host->protocol,
1939 /* transportarg = */ NULL);
1940 na_server_set_port(host->srv, host->port);
1941 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
1942 na_server_adminuser(host->srv, host->username, host->password);
1943 na_server_set_timeout(host->srv, 5 /* seconds */);
1945 for (service = host->services; service; service = service->next) {
1946 service->interval = host->interval * service->multiplier;
1948 if (service->handler == query_volume_perf_data) {
1949 service->query = na_elem_new("perf-object-get-instances");
1950 na_child_add_string(service->query, "objectname", "volume");
1951 e = na_elem_new("counters");
1952 /* "foo" means: This string has to be here but
1953 the content doesn't matter. */
1954 na_child_add_string(e, "foo", "read_ops");
1955 na_child_add_string(e, "foo", "write_ops");
1956 na_child_add_string(e, "foo", "read_data");
1957 na_child_add_string(e, "foo", "write_data");
1958 na_child_add_string(e, "foo", "read_latency");
1959 na_child_add_string(e, "foo", "write_latency");
1960 na_child_add(service->query, e);
1961 } else if (service->handler == collect_volume_data) {
1962 service->query = na_elem_new("volume-list-info");
1963 /* na_child_add_string(service->query, "objectname", "volume"); */
1964 /* } else if (service->handler == collect_snapshot_data) { */
1965 /* service->query = na_elem_new("snapshot-list-info"); */
1967 } /* for (host->services) */
1970 } /* }}} int cna_init */
1972 static int cna_config (oconfig_item_t *ci) { /* {{{ */
1974 oconfig_item_t *item;
1975 host_config_t default_host = HOST_INIT;
1976 cfg_service_t default_service = SERVICE_INIT;
1978 for (i = 0; i < ci->children_num; ++i) {
1979 item = ci->children + i;
1981 if (!strcasecmp(item->key, "Host")) {
1982 host_config_t *host;
1985 host = cna_config_host(item, &default_host, &default_service);
1989 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
1991 if (strcasecmp (host->name, tmp->name) == 0)
1992 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
1993 "This is probably a bad idea.",
1996 if (tmp->next == NULL)
2002 global_host_config = host;
2006 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
2010 } /* }}} int cna_config */
2012 static int cna_read(void) { /* {{{ */
2014 host_config_t *host;
2015 cfg_service_t *service;
2017 for (host = global_host_config; host; host = host->next) {
2018 for (service = host->services; service; service = service->next) {
2019 if (--service->skip_countdown > 0) continue;
2020 service->skip_countdown = service->multiplier;
2021 out = na_server_invoke_elem(host->srv, service->query);
2022 if (na_results_status(out) != NA_OK) {
2023 int netapp_errno = na_results_errno(out);
2024 ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
2026 if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
2027 /* Network problems. Just give up on all other services on this host. */
2032 service->handler(host, out, service->data);
2034 } /* for (host->services) */
2036 cna_query_wafl (host);
2037 cna_query_disk (host);
2038 cna_query_system (host);
2041 } /* }}} int cna_read */
2043 void module_register(void) {
2044 plugin_register_complex_config("netapp", cna_config);
2045 plugin_register_init("netapp", cna_init);
2046 plugin_register_read("netapp", cna_read);
2049 /* vim: set sw=2 ts=2 noet fdm=marker : */