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
57 * \brief Persistent data for WAFL performance counters. (a.k.a. cache performance)
59 * The cache counters use old counter values to calculate a hit ratio for each
60 * counter. The "data_wafl_t" struct therefore contains old counter values
61 * along with flags, which are set if the counter is valid.
63 * The function "query_wafl_data" will fill a new structure of this kind with
64 * new values, then pass both, new and old data, to "submit_wafl_data". That
65 * function calculates the hit ratios, submits the calculated values and
66 * updates the old counter values for the next iteration.
68 #define CFG_WAFL_NAME_CACHE 0x0001
69 #define CFG_WAFL_DIR_CACHE 0x0002
70 #define CFG_WAFL_BUF_CACHE 0x0004
71 #define CFG_WAFL_INODE_CACHE 0x0008
72 #define CFG_WAFL_ALL 0x000F
73 #define HAVE_WAFL_NAME_CACHE_HIT 0x0100
74 #define HAVE_WAFL_NAME_CACHE_MISS 0x0200
75 #define HAVE_WAFL_NAME_CACHE (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
76 #define HAVE_WAFL_FIND_DIR_HIT 0x0400
77 #define HAVE_WAFL_FIND_DIR_MISS 0x0800
78 #define HAVE_WAFL_FIND_DIR (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
79 #define HAVE_WAFL_BUF_HASH_HIT 0x1000
80 #define HAVE_WAFL_BUF_HASH_MISS 0x2000
81 #define HAVE_WAFL_BUF_HASH (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
82 #define HAVE_WAFL_INODE_CACHE_HIT 0x4000
83 #define HAVE_WAFL_INODE_CACHE_MISS 0x8000
84 #define HAVE_WAFL_INODE_CACHE (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
85 #define HAVE_WAFL_ALL 0xff00
89 uint64_t name_cache_hit;
90 uint64_t name_cache_miss;
91 uint64_t find_dir_hit;
92 uint64_t find_dir_miss;
93 uint64_t buf_hash_hit;
94 uint64_t buf_hash_miss;
95 uint64_t inode_cache_hit;
96 uint64_t inode_cache_miss;
100 * \brief Persistent data for volume performance data.
102 * The code below uses the difference of the operations and latency counters to
103 * calculate an average per-operation latency. For this, old counters need to
104 * be stored in the "data_volume_perf_t" structure. The byte-counters are just
105 * kept for completeness sake. The "flags" member indicates if each counter is
108 * The "query_volume_perf_data" function will fill a new struct of this type
109 * and pass both, old and new data, to "submit_volume_perf_data". In that
110 * function, the per-operation latency is calculated and dispatched, then the
111 * old counters are updated.
113 #define CFG_VOLUME_PERF_INIT 0x0001
114 #define CFG_VOLUME_PERF_IO 0x0002
115 #define CFG_VOLUME_PERF_OPS 0x0003
116 #define CFG_VOLUME_PERF_LATENCY 0x0008
117 #define CFG_VOLUME_PERF_ALL 0x000F
118 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
119 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
120 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
121 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
122 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
123 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
124 #define HAVE_VOLUME_PERF_ALL 0x03F0
133 uint64_t write_bytes;
136 uint64_t read_latency;
137 uint64_t write_latency;
138 } data_volume_perf_t;
141 * \brief Configuration struct for volume usage data (free / used).
143 #define VOLUME_INIT 0x01
144 #define VOLUME_DF 0x02
145 #define VOLUME_SNAP 0x04
148 } cfg_volume_usage_t;
150 typedef struct service_config_s {
152 service_handler_t *handler;
157 struct service_config_s *next;
159 #define SERVICE_INIT {0, 0, 1, 1, 0, 0, 0}
162 * \brief Struct representing a volume.
164 * A volume currently has a name and two sets of values:
166 * - Performance data, such as bytes read/written, number of operations
167 * performed and average time per operation.
169 * - Usage data, i. e. amount of used and free space in the volume.
171 typedef struct volume_s {
173 data_volume_perf_t perf_data;
174 cfg_volume_usage_t cfg_volume_usage;
175 struct volume_s *next;
179 * \brief A disk in the NetApp.
181 * A disk doesn't have any more information than its name at the moment.
182 * The name includes the "disk_" prefix.
184 #define HAVE_DISK_BUSY 0x10
185 #define HAVE_DISK_BASE 0x20
186 #define HAVE_DISK_ALL 0x30
187 typedef struct disk_s {
192 uint64_t base_for_disk_busy;
193 double disk_busy_percent;
197 #define CFG_DISK_BUSIEST 0x01
198 #define CFG_DISK_ALL 0x01
201 cna_interval_t interval;
206 struct host_config_s {
208 na_server_transport_t protocol;
216 cfg_service_t *services;
217 cfg_disk_t *cfg_disk;
220 struct host_config_s *next;
222 #define HOST_INIT { NULL, NA_SERVER_TRANSPORT_HTTPS, NULL, 0, NULL, NULL, 0, \
223 NULL, NULL, NULL, NULL, \
226 static host_config_t *global_host_config;
231 * Used to free the various structures above.
233 static void free_volume (volume_t *volume) /* {{{ */
239 sfree (volume->name);
243 } /* }}} void free_volume */
245 static void free_disk (disk_t *disk) /* {{{ */
255 } /* }}} void free_disk */
257 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
259 if (cfg_disk == NULL)
262 free_disk (cfg_disk->disks);
264 } /* }}} void free_cfg_disk */
266 static void free_cfg_service (cfg_service_t *service) /* {{{ */
270 next = service->next;
272 /* FIXME: Free service->data? */
275 free_cfg_service (next);
276 } /* }}} void free_cfg_service */
278 static void free_host_config (host_config_t *hc) /* {{{ */
289 sfree (hc->username);
290 sfree (hc->password);
292 free_cfg_service (hc->services);
293 free_cfg_disk (hc->cfg_disk);
294 free_volume (hc->volumes);
298 free_host_config (next);
299 } /* }}} void free_host_config */
302 * Auxiliary functions
304 * Used to look up volumes and disks or to handle flags.
306 static volume_t *get_volume (host_config_t *host, const char *name, /* {{{ */
307 uint32_t vol_usage_flags, uint32_t vol_perf_flags)
314 /* Make sure the default flags include the init-bit. */
315 if (vol_usage_flags != 0)
316 vol_usage_flags |= VOLUME_INIT;
317 if (vol_perf_flags != 0)
318 vol_perf_flags |= CFG_VOLUME_PERF_INIT;
320 for (v = host->volumes; v; v = v->next) {
321 if (strcmp(v->name, name) != 0)
324 /* Check if the flags have been initialized. */
325 if (((v->cfg_volume_usage.flags & VOLUME_INIT) == 0)
326 && (vol_usage_flags != 0))
327 v->cfg_volume_usage.flags = vol_usage_flags;
328 if (((v->perf_data.flags & CFG_VOLUME_PERF_INIT) == 0)
329 && (vol_perf_flags != 0))
330 v->perf_data.flags = vol_perf_flags;
335 DEBUG ("netapp plugin: Allocating new entry for volume %s.", name);
336 v = malloc(sizeof(*v));
339 memset (v, 0, sizeof (*v));
341 v->cfg_volume_usage.flags = vol_usage_flags;
342 v->perf_data.flags = vol_perf_flags;
344 v->name = strdup(name);
345 if (v->name == NULL) {
350 v->next = host->volumes;
354 } /* }}} volume_t *get_volume */
356 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
360 if ((cd == NULL) || (name == NULL))
363 for (d = cd->disks; d != NULL; d = d->next) {
364 if (strcmp(d->name, name) == 0)
368 d = malloc(sizeof(*d));
371 memset (d, 0, sizeof (*d));
374 d->name = strdup(name);
375 if (d->name == NULL) {
384 } /* }}} disk_t *get_disk */
386 static void host_set_all_perf_data_flags(const host_config_t *host, /* {{{ */
387 uint32_t flag, _Bool set)
391 for (v = host->volumes; v; v = v->next) {
393 v->perf_data.flags |= flag;
395 v->perf_data.flags &= ~flag;
397 } /* }}} void host_set_all_perf_data_flags */
399 static void host_set_all_cfg_volume_usage_flags(const host_config_t *host, /* {{{ */
400 uint32_t flag, _Bool set) {
403 for (v = host->volumes; v; v = v->next) {
405 v->cfg_volume_usage.flags |= flag;
407 v->cfg_volume_usage.flags &= ~flag;
409 } /* }}} void host_set_all_cfg_volume_usage_flags */
412 * Various submit functions.
414 * They all eventually call "submit_values" which creates a value_list_t and
415 * dispatches it to the daemon.
417 static int submit_values (const char *host, /* {{{ */
418 const char *plugin_inst,
419 const char *type, const char *type_inst,
420 value_t *values, int values_len,
423 value_list_t vl = VALUE_LIST_INIT;
426 vl.values_len = values_len;
432 sstrncpy (vl.host, host, sizeof (vl.host));
434 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
435 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
436 if (plugin_inst != NULL)
437 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
438 sstrncpy (vl.type, type, sizeof (vl.type));
439 if (type_inst != NULL)
440 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
442 return (plugin_dispatch_values (&vl));
443 } /* }}} int submit_uint64 */
445 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
446 const char *type, const char *type_inst, counter_t val0, counter_t val1,
451 values[0].counter = val0;
452 values[1].counter = val1;
454 return (submit_values (host, plugin_inst, type, type_inst,
455 values, 2, timestamp));
456 } /* }}} int submit_two_counters */
458 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
459 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
465 return (submit_values (host, plugin_inst, type, type_inst,
467 } /* }}} int submit_counter */
469 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
470 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
475 values[0].gauge = val0;
476 values[1].gauge = val1;
478 return (submit_values (host, plugin_inst, type, type_inst,
479 values, 2, timestamp));
480 } /* }}} int submit_two_gauge */
482 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
483 const char *type, const char *type_inst, double d, time_t timestamp)
487 v.gauge = (gauge_t) d;
489 return (submit_values (host, plugin_inst, type, type_inst,
491 } /* }}} int submit_uint64 */
493 /* Calculate hit ratio from old and new counters and submit the resulting
494 * percentage. Used by "submit_wafl_data". */
495 static int submit_cache_ratio (const char *host, /* {{{ */
496 const char *plugin_inst,
497 const char *type_inst,
506 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
510 hits = new_hits - old_hits;
511 misses = new_misses - old_misses;
513 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
518 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
520 } /* }}} int submit_cache_ratio */
522 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
523 static int submit_wafl_data (const host_config_t *host, const char *instance, /* {{{ */
524 data_wafl_t *old_data, const data_wafl_t *new_data)
526 /* Submit requested counters */
527 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
528 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
529 submit_cache_ratio (host->name, instance, "name_cache_hit",
530 new_data->name_cache_hit, new_data->name_cache_miss,
531 old_data->name_cache_hit, old_data->name_cache_miss,
532 new_data->timestamp);
534 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
535 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
536 submit_cache_ratio (host->name, instance, "find_dir_hit",
537 new_data->find_dir_hit, new_data->find_dir_miss,
538 old_data->find_dir_hit, old_data->find_dir_miss,
539 new_data->timestamp);
541 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
542 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
543 submit_cache_ratio (host->name, instance, "buf_hash_hit",
544 new_data->buf_hash_hit, new_data->buf_hash_miss,
545 old_data->buf_hash_hit, old_data->buf_hash_miss,
546 new_data->timestamp);
548 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
549 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
550 submit_cache_ratio (host->name, instance, "inode_cache_hit",
551 new_data->inode_cache_hit, new_data->inode_cache_miss,
552 old_data->inode_cache_hit, old_data->inode_cache_miss,
553 new_data->timestamp);
555 /* Clear old HAVE_* flags */
556 old_data->flags &= ~HAVE_WAFL_ALL;
558 /* Copy all counters */
559 old_data->timestamp = new_data->timestamp;
560 old_data->name_cache_hit = new_data->name_cache_hit;
561 old_data->name_cache_miss = new_data->name_cache_miss;
562 old_data->find_dir_hit = new_data->find_dir_hit;
563 old_data->find_dir_miss = new_data->find_dir_miss;
564 old_data->buf_hash_hit = new_data->buf_hash_hit;
565 old_data->buf_hash_miss = new_data->buf_hash_miss;
566 old_data->inode_cache_hit = new_data->inode_cache_hit;
567 old_data->inode_cache_miss = new_data->inode_cache_miss;
569 /* Copy HAVE_* flags */
570 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
573 } /* }}} int submit_wafl_data */
575 /* Submits volume performance data to the daemon, taking care to honor and
576 * update flags appropriately. */
577 static int submit_volume_perf_data (const host_config_t *host, /* {{{ */
579 const data_volume_perf_t *new_data)
581 /* Check for and submit disk-octet values */
582 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_IO)
583 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
585 submit_two_counters (host->name, volume->name, "disk_octets", /* type instance = */ NULL,
586 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
589 /* Check for and submit disk-operations values */
590 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_OPS)
591 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
593 submit_two_counters (host->name, volume->name, "disk_ops", /* type instance = */ NULL,
594 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
597 /* Check for, calculate and submit disk-latency values */
598 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_LATENCY
599 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
600 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
601 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
602 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
604 gauge_t latency_per_op_read;
605 gauge_t latency_per_op_write;
607 latency_per_op_read = NAN;
608 latency_per_op_write = NAN;
610 /* Check if a counter wrapped around. */
611 if ((new_data->read_ops > volume->perf_data.read_ops)
612 && (new_data->read_latency > volume->perf_data.read_latency))
614 uint64_t diff_ops_read;
615 uint64_t diff_latency_read;
617 diff_ops_read = new_data->read_ops - volume->perf_data.read_ops;
618 diff_latency_read = new_data->read_latency - volume->perf_data.read_latency;
620 if (diff_ops_read > 0)
621 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
624 if ((new_data->write_ops > volume->perf_data.write_ops)
625 && (new_data->write_latency > volume->perf_data.write_latency))
627 uint64_t diff_ops_write;
628 uint64_t diff_latency_write;
630 diff_ops_write = new_data->write_ops - volume->perf_data.write_ops;
631 diff_latency_write = new_data->write_latency - volume->perf_data.write_latency;
633 if (diff_ops_write > 0)
634 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
637 submit_two_gauge (host->name, volume->name, "disk_latency", /* type instance = */ NULL,
638 latency_per_op_read, latency_per_op_write, new_data->timestamp);
641 /* Clear all HAVE_* flags. */
642 volume->perf_data.flags &= ~HAVE_VOLUME_PERF_ALL;
644 /* Copy all counters */
645 volume->perf_data.timestamp = new_data->timestamp;
646 volume->perf_data.read_bytes = new_data->read_bytes;
647 volume->perf_data.write_bytes = new_data->write_bytes;
648 volume->perf_data.read_ops = new_data->read_ops;
649 volume->perf_data.write_ops = new_data->write_ops;
650 volume->perf_data.read_latency = new_data->read_latency;
651 volume->perf_data.write_latency = new_data->write_latency;
653 /* Copy the HAVE_* flags */
654 volume->perf_data.flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
657 } /* }}} int submit_volume_perf_data */
662 * These functions are called with appropriate data returned by the libnetapp
663 * interface which is parsed and submitted with the above functions.
665 /* Data corresponding to <GetWaflPerfData /> */
666 static void query_wafl_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
667 data_wafl_t *wafl = data;
668 data_wafl_t perf_data;
669 const char *plugin_inst;
672 memset (&perf_data, 0, sizeof (perf_data));
674 perf_data.timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
676 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
680 plugin_inst = na_child_get_string(out, "name");
681 if (plugin_inst == NULL)
684 /* Iterate over all counters */
685 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
686 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
690 name = na_child_get_string(counter, "name");
694 value = na_child_get_uint64(counter, "value", UINT64_MAX);
695 if (value == UINT64_MAX)
698 if (!strcmp(name, "name_cache_hit")) {
699 perf_data.name_cache_hit = value;
700 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
701 } else if (!strcmp(name, "name_cache_miss")) {
702 perf_data.name_cache_miss = value;
703 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
704 } else if (!strcmp(name, "find_dir_hit")) {
705 perf_data.find_dir_hit = value;
706 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
707 } else if (!strcmp(name, "find_dir_miss")) {
708 perf_data.find_dir_miss = value;
709 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
710 } else if (!strcmp(name, "buf_hash_hit")) {
711 perf_data.buf_hash_hit = value;
712 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
713 } else if (!strcmp(name, "buf_hash_miss")) {
714 perf_data.buf_hash_miss = value;
715 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
716 } else if (!strcmp(name, "inode_cache_hit")) {
717 perf_data.inode_cache_hit = value;
718 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
719 } else if (!strcmp(name, "inode_cache_miss")) {
720 perf_data.inode_cache_miss = value;
721 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
723 DEBUG("netapp plugin: query_wafl_data: Found unexpected child: %s",
728 submit_wafl_data (host, plugin_inst, wafl, &perf_data);
729 } /* }}} void query_wafl_data */
731 /* Data corresponding to <Disks /> */
732 static int cna_handle_disk_data (const char *hostname, /* {{{ */
733 cfg_disk_t *cfg_disk, na_elem_t *data)
736 na_elem_t *instances;
738 na_elem_iter_t instance_iter;
739 disk_t *worst_disk = NULL;
741 if ((cfg_disk == NULL) || (data == NULL))
744 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
746 instances = na_elem_child (data, "instances");
747 if (instances == NULL)
749 ERROR ("netapp plugin: cna_handle_disk_data: "
750 "na_elem_child (\"instances\") failed.");
754 /* Iterate over all children */
755 instance_iter = na_child_iterator (instances);
756 for (instance = na_iterator_next (&instance_iter);
758 instance = na_iterator_next(&instance_iter))
763 na_elem_iter_t counter_iterator;
766 memset (&new_data, 0, sizeof (new_data));
767 new_data.timestamp = timestamp;
768 new_data.disk_busy_percent = NAN;
770 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
771 if (old_data == NULL)
774 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
775 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
776 for (counter = na_iterator_next(&counter_iterator);
778 counter = na_iterator_next(&counter_iterator))
783 name = na_child_get_string(counter, "name");
787 value = na_child_get_uint64(counter, "value", UINT64_MAX);
788 if (value == UINT64_MAX)
791 if (strcmp(name, "disk_busy") == 0)
793 new_data.disk_busy = value;
794 new_data.flags |= HAVE_DISK_BUSY;
796 else if (strcmp(name, "base_for_disk_busy") == 0)
798 new_data.base_for_disk_busy = value;
799 new_data.flags |= HAVE_DISK_BASE;
803 DEBUG ("netapp plugin: cna_handle_disk_data: "
804 "Counter not handled: %s = %"PRIu64,
809 /* If all required counters are available and did not just wrap around,
810 * calculate the busy percentage. Otherwise, the value is initialized to
811 * NAN at the top of the for-loop. */
812 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
813 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
814 && (new_data.disk_busy >= old_data->disk_busy)
815 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
820 busy_diff = new_data.disk_busy - old_data->disk_busy;
821 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
823 new_data.disk_busy_percent = 100.0
824 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
827 /* Clear HAVE_* flags */
828 old_data->flags &= ~HAVE_DISK_ALL;
831 old_data->timestamp = new_data.timestamp;
832 old_data->disk_busy = new_data.disk_busy;
833 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
834 old_data->disk_busy_percent = new_data.disk_busy_percent;
837 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
839 if ((worst_disk == NULL)
840 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
841 worst_disk = old_data;
842 } /* for (all disks) */
844 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
845 submit_double (hostname, "system", "percent", "disk_busy",
846 worst_disk->disk_busy_percent, timestamp);
849 } /* }}} int cna_handle_disk_data */
851 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
858 if (cd->query != NULL)
861 cd->query = na_elem_new ("perf-object-get-instances");
862 if (cd->query == NULL)
864 ERROR ("netapp plugin: na_elem_new failed.");
867 na_child_add_string (cd->query, "objectname", "disk");
869 e = na_elem_new("counters");
872 na_elem_free (cd->query);
874 ERROR ("netapp plugin: na_elem_new failed.");
877 na_child_add_string(e, "foo", "disk_busy");
878 na_child_add_string(e, "foo", "base_for_disk_busy");
879 na_child_add(cd->query, e);
882 } /* }}} int cna_setup_disk */
884 static int cna_query_disk (host_config_t *host) /* {{{ */
893 if (host->cfg_disk == NULL)
897 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
900 status = cna_setup_disk (host->cfg_disk);
903 assert (host->cfg_disk->query != NULL);
905 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
906 if (na_results_status (data) != NA_OK)
908 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed: %s",
909 na_results_reason (data));
914 status = cna_handle_disk_data (host->name, host->cfg_disk, data);
917 host->cfg_disk->interval.last_read = now;
921 } /* }}} int cna_query_disk */
923 /* Data corresponding to <GetVolumeData /> */
924 static void collect_volume_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
927 cfg_volume_usage_t *cfg_volume_data = data;
929 out = na_elem_child(out, "volumes");
930 na_elem_iter_t inst_iter = na_child_iterator(out);
931 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
932 uint64_t size_free = 0, size_used = 0, snap_reserved = 0;
935 const char *sis_state;
936 uint64_t sis_saved_reported;
939 volume = get_volume(host, na_child_get_string(inst, "name"),
940 cfg_volume_data->flags, /* perf_flags = */ 0);
944 if (!(volume->cfg_volume_usage.flags & VOLUME_DF))
947 /* 2^4 exa-bytes? This will take a while ;) */
948 size_free = na_child_get_uint64(inst, "size-available", UINT64_MAX);
949 if (size_free != UINT64_MAX)
950 submit_double (host->name, volume->name, "df_complex", "used",
951 (double) size_used, /* time = */ 0);
953 size_used = na_child_get_uint64(inst, "size-used", UINT64_MAX);
954 if (size_free != UINT64_MAX)
955 submit_double (host->name, volume->name, "df_complex", "free",
956 (double) size_free, /* time = */ 0);
958 snap_reserved = na_child_get_uint64(inst, "snapshot-blocks-reserved", UINT64_MAX);
959 if (snap_reserved != UINT64_MAX)
960 /* 1 block == 1024 bytes as per API docs */
961 submit_double (host->name, volume->name, "df_complex", "snap_reserved",
962 (double) (1024 * snap_reserved), /* time = */ 0);
964 sis = na_elem_child(inst, "sis");
968 sis_state = na_child_get_string(sis, "state");
969 if ((sis_state == NULL)
970 || (strcmp ("enabled", sis_state) != 0))
973 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
974 if (sis_saved_reported == UINT64_MAX)
977 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
978 if ((sis_saved_reported >> 32) != 0) {
979 /* In case they ever fix this bug. */
980 sis_saved = sis_saved_reported;
982 uint64_t sis_saved_percent;
983 uint64_t sis_saved_guess;
984 uint64_t overflow_guess;
985 uint64_t guess1, guess2, guess3;
987 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
988 if (sis_saved_percent > 100)
991 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
992 * will hopefully be fixed in later versions. To work around the bug, try
993 * to figure out how often the 32bit integer wrapped around by using the
994 * "percentage-saved" value. Because the percentage is in the range
995 * [0-100], this should work as long as the saved space does not exceed
997 /* percentage-saved = size-saved / (size-saved + size-used) */
998 if (sis_saved_percent < 100)
999 sis_saved_guess = size_used * sis_saved_percent / (100 - sis_saved_percent);
1001 sis_saved_guess = size_used;
1003 overflow_guess = sis_saved_guess >> 32;
1004 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1005 guess2 = (overflow_guess << 32) + sis_saved_reported;
1006 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1008 if (sis_saved_guess < guess2) {
1009 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1014 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1019 } /* end of 32-bit workaround */
1021 submit_double (host->name, volume->name, "df_complex", "sis_saved",
1022 (double) sis_saved, /* time = */ 0);
1024 } /* }}} void collect_volume_data */
1026 /* Data corresponding to <GetVolumePerfData /> */
1027 static void query_volume_perf_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
1028 cfg_volume_perf_t *cfg_volume_perf = data;
1030 na_elem_t *counter, *inst;
1032 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
1034 out = na_elem_child(out, "instances");
1035 na_elem_iter_t inst_iter = na_child_iterator(out);
1036 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
1037 data_volume_perf_t perf_data;
1040 memset (&perf_data, 0, sizeof (perf_data));
1041 perf_data.timestamp = timestamp;
1043 volume = get_volume(host, na_child_get_string(inst, "name"),
1044 /* data_flags = */ 0, cfg_volume_perf->flags);
1048 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
1049 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
1053 name = na_child_get_string(counter, "name");
1057 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1058 if (value == UINT64_MAX)
1061 if (!strcmp(name, "read_data")) {
1062 perf_data.read_bytes = value;
1063 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1064 } else if (!strcmp(name, "write_data")) {
1065 perf_data.write_bytes = value;
1066 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1067 } else if (!strcmp(name, "read_ops")) {
1068 perf_data.read_ops = value;
1069 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1070 } else if (!strcmp(name, "write_ops")) {
1071 perf_data.write_ops = value;
1072 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1073 } else if (!strcmp(name, "read_latency")) {
1074 perf_data.read_latency = value;
1075 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1076 } else if (!strcmp(name, "write_latency")) {
1077 perf_data.write_latency = value;
1078 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1082 submit_volume_perf_data (host, volume, &perf_data);
1083 } /* for (volume) */
1084 } /* }}} void query_volume_perf_data */
1086 /* Data corresponding to <GetSystemPerfData /> */
1087 static void collect_perf_system_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
1088 counter_t disk_read = 0, disk_written = 0;
1089 counter_t net_recv = 0, net_sent = 0;
1090 counter_t cpu_busy = 0, cpu_total = 0;
1091 unsigned int counter_flags = 0;
1093 cfg_system_t *cfg_system = data;
1094 const char *instance;
1098 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
1099 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
1100 instance = na_child_get_string(out, "name");
1102 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
1103 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
1107 name = na_child_get_string(counter, "name");
1111 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1112 if (value == UINT64_MAX)
1115 if (!strcmp(name, "disk_data_read")) {
1116 disk_read = (counter_t) (value * 1024);
1117 counter_flags |= 0x01;
1118 } else if (!strcmp(name, "disk_data_written")) {
1119 disk_written = (counter_t) (value * 1024);
1120 counter_flags |= 0x02;
1121 } else if (!strcmp(name, "net_data_recv")) {
1122 net_recv = (counter_t) (value * 1024);
1123 counter_flags |= 0x04;
1124 } else if (!strcmp(name, "net_data_sent")) {
1125 net_sent = (counter_t) (value * 1024);
1126 counter_flags |= 0x08;
1127 } else if (!strcmp(name, "cpu_busy")) {
1128 cpu_busy = (counter_t) value;
1129 counter_flags |= 0x10;
1130 } else if (!strcmp(name, "cpu_elapsed_time")) {
1131 cpu_total = (counter_t) value;
1132 counter_flags |= 0x20;
1133 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1134 && (strlen(name) > 4)
1135 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1136 submit_counter (host->name, instance, "disk_ops_complex", name,
1137 (counter_t) value, timestamp);
1139 } /* for (counter) */
1141 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1142 && ((counter_flags & 0x03) == 0x03))
1143 submit_two_counters (host->name, instance, "disk_octets", NULL,
1144 disk_read, disk_written, timestamp);
1146 if ((cfg_system->flags & CFG_SYSTEM_NET)
1147 && ((counter_flags & 0x0c) == 0x0c))
1148 submit_two_counters (host->name, instance, "if_octets", NULL,
1149 net_recv, net_sent, timestamp);
1151 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1152 && ((counter_flags & 0x30) == 0x30)) {
1153 submit_counter (host->name, instance, "cpu", "system",
1154 cpu_busy, timestamp);
1155 submit_counter (host->name, instance, "cpu", "idle",
1156 cpu_total - cpu_busy, timestamp);
1158 } /* }}} void collect_perf_system_data */
1161 * Configuration handling
1163 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1164 * is false. On error, the flag-field is not changed. */
1165 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1166 uint32_t *flags, uint32_t flag)
1168 if ((ci == NULL) || (flags == NULL))
1171 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1173 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1178 if (ci->values[0].value.boolean)
1184 } /* }}} int cna_config_bool_to_flag */
1186 /* Handling of the "Multiplier" option which is allowed in every block. */
1187 static int cna_config_get_multiplier (const oconfig_item_t *ci, /* {{{ */
1188 cfg_service_t *service)
1192 if ((ci == NULL) || (service == NULL))
1195 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1197 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1201 tmp = (int) (ci->values[0].value.number + .5);
1204 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1208 service->multiplier = tmp;
1209 service->skip_countdown = tmp;
1212 } /* }}} int cna_config_get_multiplier */
1214 /* Handling of the "Interval" option which is allowed in every block. */
1215 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1216 cna_interval_t *out_interval)
1220 if ((ci == NULL) || (out_interval == NULL))
1223 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1225 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1229 tmp = (time_t) (ci->values[0].value.number + .5);
1232 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1236 out_interval->interval = tmp;
1237 out_interval->last_read = 0;
1240 } /* }}} int cna_config_get_interval */
1242 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1243 * <GetVolumePerfData /> block. */
1244 static void cna_config_volume_performance_option (host_config_t *host, /* {{{ */
1245 cfg_volume_perf_t *perf_volume, const oconfig_item_t *item,
1250 for (i = 0; i < item->values_num; ++i) {
1255 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1256 WARNING("netapp plugin: Ignoring non-string argument in "
1257 "\"GetVolumePerfData\" block for host %s", host->name);
1261 name = item->values[i].value.string;
1262 if (name[0] == '+') {
1265 } else if (name[0] == '-') {
1272 perf_volume->flags |= flag;
1273 else /* if (!set) */
1274 perf_volume->flags &= ~flag;
1276 host_set_all_perf_data_flags(host, flag, set);
1280 v = get_volume (host, name, /* data_flags = */ 0, perf_volume->flags);
1285 v->perf_data.flags |= flag;
1286 else /* if (!set) */
1287 v->perf_data.flags &= ~flag;
1288 } /* for (i = 0 .. item->values_num) */
1289 } /* }}} void cna_config_volume_performance_option */
1291 /* Corresponds to a <GetVolumePerfData /> block */
1292 static void cna_config_volume_performance(host_config_t *host, const oconfig_item_t *ci) { /* {{{ */
1293 int i, had_io = 0, had_ops = 0, had_latency = 0;
1294 cfg_service_t *service;
1295 cfg_volume_perf_t *perf_volume;
1297 service = malloc(sizeof(*service));
1299 service->handler = query_volume_perf_data;
1300 perf_volume = service->data = malloc(sizeof(*perf_volume));
1301 perf_volume->flags = CFG_VOLUME_PERF_INIT;
1302 service->next = host->services;
1303 host->services = service;
1304 for (i = 0; i < ci->children_num; ++i) {
1305 oconfig_item_t *item = ci->children + i;
1307 /* if (!item || !item->key || !*item->key) continue; */
1308 if (!strcasecmp(item->key, "Multiplier")) {
1309 cna_config_get_multiplier (item, service);
1310 } else if (!strcasecmp(item->key, "GetIO")) {
1312 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_IO);
1313 } else if (!strcasecmp(item->key, "GetOps")) {
1315 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_OPS);
1316 } else if (!strcasecmp(item->key, "GetLatency")) {
1318 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_LATENCY);
1322 perf_volume->flags |= CFG_VOLUME_PERF_IO;
1323 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_IO, /* set = */ true);
1326 perf_volume->flags |= CFG_VOLUME_PERF_OPS;
1327 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_OPS, /* set = */ true);
1330 perf_volume->flags |= CFG_VOLUME_PERF_LATENCY;
1331 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_LATENCY, /* set = */ true);
1333 } /* }}} void cna_config_volume_performance */
1335 /* Handling of the "GetDiskUtil" option within a <GetVolumeData /> block. */
1336 static void cna_config_volume_usage_option (host_config_t *host, /* {{{ */
1337 cfg_volume_usage_t *cfg_volume_data, const oconfig_item_t *item, uint32_t flag)
1341 for (i = 0; i < item->values_num; ++i) {
1346 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1347 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolData\""
1348 "block for host %s", host->name);
1352 name = item->values[i].value.string;
1353 if (name[0] == '+') {
1356 } else if (name[0] == '-') {
1363 cfg_volume_data->flags |= flag;
1364 else /* if (!set) */
1365 cfg_volume_data->flags &= ~flag;
1367 host_set_all_cfg_volume_usage_flags(host, flag, set);
1371 v = get_volume(host, name, cfg_volume_data->flags, /* perf_flags = */ 0);
1375 if (!v->cfg_volume_usage.flags)
1376 v->cfg_volume_usage.flags = cfg_volume_data->flags;
1379 v->cfg_volume_usage.flags |= flag;
1380 else /* if (!set) */
1381 v->cfg_volume_usage.flags &= ~flag;
1383 } /* }}} void cna_config_volume_usage_option */
1385 /* Corresponds to a <GetVolumeData /> block */
1386 static void cna_config_volume_usage(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1388 cfg_service_t *service;
1389 cfg_volume_usage_t *cfg_volume_data;
1391 service = malloc(sizeof(*service));
1393 service->handler = collect_volume_data;
1394 cfg_volume_data = service->data = malloc(sizeof(*cfg_volume_data));
1395 cfg_volume_data->flags = VOLUME_INIT;
1396 service->next = host->services;
1397 host->services = service;
1398 for (i = 0; i < ci->children_num; ++i) {
1399 oconfig_item_t *item = ci->children + i;
1401 /* if (!item || !item->key || !*item->key) continue; */
1402 if (!strcasecmp(item->key, "Multiplier")) {
1403 cna_config_get_multiplier (item, service);
1404 } else if (!strcasecmp(item->key, "GetDiskUtil")) {
1406 cna_config_volume_usage_option(host, cfg_volume_data, item, VOLUME_DF);
1410 cfg_volume_data->flags |= VOLUME_DF;
1411 host_set_all_cfg_volume_usage_flags(host, VOLUME_DF, /* set = */ true);
1413 } /* }}} void cna_config_volume_usage */
1415 /* Corresponds to a <Disks /> block */
1416 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1417 cfg_disk_t *cfg_disk;
1420 if ((host == NULL) || (ci == NULL))
1423 if (host->cfg_disk == NULL)
1425 cfg_disk = malloc (sizeof (*cfg_disk));
1426 if (cfg_disk == NULL)
1428 memset (cfg_disk, 0, sizeof (*cfg_disk));
1430 /* Set default flags */
1431 cfg_disk->flags = CFG_DISK_ALL;
1432 cfg_disk->query = NULL;
1433 cfg_disk->disks = NULL;
1435 host->cfg_disk = cfg_disk;
1437 cfg_disk = host->cfg_disk;
1439 for (i = 0; i < ci->children_num; ++i) {
1440 oconfig_item_t *item = ci->children + i;
1442 /* if (!item || !item->key || !*item->key) continue; */
1443 if (strcasecmp(item->key, "Interval") == 0)
1444 cna_config_get_interval (item, &cfg_disk->interval);
1445 else if (strcasecmp(item->key, "GetBusy") == 0)
1446 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
1450 } /* }}} int cna_config_disk */
1452 /* Corresponds to a <GetWaflPerfData /> block */
1453 static void cna_config_wafl(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1455 cfg_service_t *service;
1456 data_wafl_t *perf_wafl;
1458 service = malloc(sizeof(*service));
1459 if (service == NULL)
1461 memset (service, 0, sizeof (*service));
1464 service->handler = query_wafl_data;
1465 perf_wafl = service->data = malloc(sizeof(*perf_wafl));
1466 perf_wafl->flags = CFG_WAFL_ALL;
1468 for (i = 0; i < ci->children_num; ++i) {
1469 oconfig_item_t *item = ci->children + i;
1471 if (!strcasecmp(item->key, "Multiplier")) {
1472 cna_config_get_multiplier (item, service);
1473 } else if (!strcasecmp(item->key, "GetNameCache")) {
1474 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_NAME_CACHE);
1475 } else if (!strcasecmp(item->key, "GetDirCache")) {
1476 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_DIR_CACHE);
1477 } else if (!strcasecmp(item->key, "GetBufCache")) {
1478 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_BUF_CACHE);
1479 } else if (!strcasecmp(item->key, "GetInodeCache")) {
1480 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_INODE_CACHE);
1482 WARNING ("netapp plugin: The %s config option is not allowed within "
1483 "`GetWaflPerfData' blocks.", item->key);
1487 service->next = host->services;
1488 host->services = service;
1489 } /* }}} void cna_config_wafl */
1491 /* Corresponds to a <GetSystemPerfData /> block */
1492 static int cna_config_system (host_config_t *host, /* {{{ */
1493 oconfig_item_t *ci, const cfg_service_t *default_service)
1496 cfg_service_t *service;
1497 cfg_system_t *cfg_system;
1499 service = malloc(sizeof(*service));
1500 if (service == NULL)
1502 memset (service, 0, sizeof (*service));
1503 *service = *default_service;
1504 service->handler = collect_perf_system_data;
1506 cfg_system = malloc(sizeof(*cfg_system));
1507 if (cfg_system == NULL) {
1511 memset (cfg_system, 0, sizeof (*cfg_system));
1512 cfg_system->flags = CFG_SYSTEM_ALL;
1513 service->data = cfg_system;
1515 for (i = 0; i < ci->children_num; ++i) {
1516 oconfig_item_t *item = ci->children + i;
1518 if (!strcasecmp(item->key, "Multiplier")) {
1519 cna_config_get_multiplier (item, service);
1520 } else if (!strcasecmp(item->key, "GetCPULoad")) {
1521 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
1522 } else if (!strcasecmp(item->key, "GetInterfaces")) {
1523 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
1524 } else if (!strcasecmp(item->key, "GetDiskOps")) {
1525 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
1526 } else if (!strcasecmp(item->key, "GetDiskIO")) {
1527 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
1529 WARNING ("netapp plugin: The %s config option is not allowed within "
1530 "`GetSystemPerfData' blocks.", item->key);
1534 service->next = host->services;
1535 host->services = service;
1538 } /* }}} int cna_config_system */
1540 /* Corresponds to a <Host /> block. */
1541 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
1542 const host_config_t *default_host, const cfg_service_t *def_def_service)
1544 oconfig_item_t *item;
1545 host_config_t *host, *hc;
1546 cfg_service_t default_service = *def_def_service;
1550 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1551 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
1555 host = malloc(sizeof(*host));
1556 memcpy (host, default_host, sizeof (*host));
1558 status = cf_util_get_string (ci, &host->name);
1565 for (i = 0; i < ci->children_num; ++i) {
1566 item = ci->children + i;
1570 if (!strcasecmp(item->key, "Address")) {
1571 status = cf_util_get_string (item, &host->host);
1572 } else if (!strcasecmp(item->key, "Port")) {
1575 tmp = cf_util_get_port_number (item);
1578 } else if (!strcasecmp(item->key, "Protocol")) {
1579 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"))) {
1580 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
1583 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
1584 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
1585 } else if (!strcasecmp(item->key, "User")) {
1586 status = cf_util_get_string (item, &host->username);
1587 } else if (!strcasecmp(item->key, "Password")) {
1588 status = cf_util_get_string (item, &host->password);
1589 } else if (!strcasecmp(item->key, "Interval")) {
1590 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) {
1591 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
1594 host->interval = item->values[0].value.number;
1595 } else if (!strcasecmp(item->key, "GetVolumePerfData")) {
1596 cna_config_volume_performance(host, item);
1597 } else if (!strcasecmp(item->key, "GetSystemPerfData")) {
1598 cna_config_system(host, item, &default_service);
1599 } else if (!strcasecmp(item->key, "GetWaflPerfData")) {
1600 cna_config_wafl(host, item);
1601 } else if (!strcasecmp(item->key, "Disks")) {
1602 cna_config_disk(host, item);
1603 } else if (!strcasecmp(item->key, "GetVolumeData")) {
1604 cna_config_volume_usage(host, item);
1606 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
1607 item->key, ci->values[0].value.string);
1614 if (host->host == NULL)
1615 host->host = strdup (host->name);
1617 if (host->host == NULL)
1620 if (host->port <= 0)
1621 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
1623 if ((host->username == NULL) || (host->password == NULL)) {
1624 WARNING("netapp plugin: Please supply login information for host \"%s\". "
1625 "Ignoring host block.", host->name);
1631 free_host_config (host);
1635 for (hc = global_host_config; hc; hc = hc->next) {
1636 if (!strcasecmp(hc->name, host->name)) WARNING("netapp plugin: Duplicate definition of host \"%s\". This is probably a bad idea.", hc->name);
1639 } /* }}} host_config_t *cna_config_host */
1642 * Callbacks registered with the daemon
1644 * Pretty standard stuff here.
1646 static int cna_init(void) { /* {{{ */
1649 host_config_t *host;
1650 cfg_service_t *service;
1652 if (!global_host_config) {
1653 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
1657 memset (err, 0, sizeof (err));
1658 if (!na_startup(err, sizeof(err))) {
1659 err[sizeof (err) - 1] = 0;
1660 ERROR("netapp plugin: Error initializing netapp API: %s", err);
1664 for (host = global_host_config; host; host = host->next) {
1665 /* Request version 1.1 of the ONTAP API */
1666 host->srv = na_server_open(host->host,
1667 /* major version = */ 1, /* minor version = */ 1);
1668 if (host->srv == NULL) {
1669 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
1673 if (host->interval < interval_g)
1674 host->interval = interval_g;
1676 na_server_set_transport_type(host->srv, host->protocol,
1677 /* transportarg = */ NULL);
1678 na_server_set_port(host->srv, host->port);
1679 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
1680 na_server_adminuser(host->srv, host->username, host->password);
1681 na_server_set_timeout(host->srv, 5 /* seconds */);
1683 for (service = host->services; service; service = service->next) {
1684 service->interval = host->interval * service->multiplier;
1686 if (service->handler == collect_perf_system_data) {
1687 service->query = na_elem_new("perf-object-get-instances");
1688 na_child_add_string(service->query, "objectname", "system");
1689 } else if (service->handler == query_volume_perf_data) {
1690 service->query = na_elem_new("perf-object-get-instances");
1691 na_child_add_string(service->query, "objectname", "volume");
1692 e = na_elem_new("counters");
1693 na_child_add_string(e, "foo", "read_ops");
1694 na_child_add_string(e, "foo", "write_ops");
1695 na_child_add_string(e, "foo", "read_data");
1696 na_child_add_string(e, "foo", "write_data");
1697 na_child_add_string(e, "foo", "read_latency");
1698 na_child_add_string(e, "foo", "write_latency");
1699 na_child_add(service->query, e);
1700 } else if (service->handler == query_wafl_data) {
1701 service->query = na_elem_new("perf-object-get-instances");
1702 na_child_add_string(service->query, "objectname", "wafl");
1703 e = na_elem_new("counters");
1704 na_child_add_string(e, "foo", "name_cache_hit");
1705 na_child_add_string(e, "foo", "name_cache_miss");
1706 na_child_add_string(e, "foo", "find_dir_hit");
1707 na_child_add_string(e, "foo", "find_dir_miss");
1708 na_child_add_string(e, "foo", "buf_hash_hit");
1709 na_child_add_string(e, "foo", "buf_hash_miss");
1710 na_child_add_string(e, "foo", "inode_cache_hit");
1711 na_child_add_string(e, "foo", "inode_cache_miss");
1712 /* na_child_add_string(e, "foo", "inode_eject_time"); */
1713 /* na_child_add_string(e, "foo", "buf_eject_time"); */
1714 na_child_add(service->query, e);
1715 } else if (service->handler == collect_volume_data) {
1716 service->query = na_elem_new("volume-list-info");
1717 /* na_child_add_string(service->query, "objectname", "volume"); */
1718 /* } else if (service->handler == collect_snapshot_data) { */
1719 /* service->query = na_elem_new("snapshot-list-info"); */
1721 } /* for (host->services) */
1724 } /* }}} int cna_init */
1726 static int cna_config (oconfig_item_t *ci) { /* {{{ */
1728 oconfig_item_t *item;
1729 host_config_t default_host = HOST_INIT;
1730 cfg_service_t default_service = SERVICE_INIT;
1732 for (i = 0; i < ci->children_num; ++i) {
1733 item = ci->children + i;
1735 /* if (!item || !item->key || !*item->key) continue; */
1736 if (!strcasecmp(item->key, "Host")) {
1737 host_config_t *host;
1740 host = cna_config_host(item, &default_host, &default_service);
1744 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
1746 if (strcasecmp (host->name, tmp->name) == 0)
1747 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
1748 "This is probably a bad idea.",
1751 if (tmp->next == NULL)
1757 global_host_config = host;
1761 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
1765 } /* }}} int cna_config */
1767 static int cna_read(void) { /* {{{ */
1769 host_config_t *host;
1770 cfg_service_t *service;
1772 for (host = global_host_config; host; host = host->next) {
1773 for (service = host->services; service; service = service->next) {
1774 if (--service->skip_countdown > 0) continue;
1775 service->skip_countdown = service->multiplier;
1776 out = na_server_invoke_elem(host->srv, service->query);
1777 if (na_results_status(out) != NA_OK) {
1778 int netapp_errno = na_results_errno(out);
1779 ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
1781 if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
1782 /* Network problems. Just give up on all other services on this host. */
1787 service->handler(host, out, service->data);
1789 } /* for (host->services) */
1791 cna_query_disk (host);
1794 } /* }}} int cna_read */
1796 void module_register(void) {
1797 plugin_register_complex_config("netapp", cna_config);
1798 plugin_register_init("netapp", cna_init);
1799 plugin_register_read("netapp", cna_read);
1802 /* vim: set sw=2 ts=2 noet fdm=marker : */