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 <sven.trenkel at noris.net>
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);
37 #define PERF_SYSTEM_CPU 0x01
38 #define PERF_SYSTEM_NET 0x02
39 #define PERF_SYSTEM_OPS 0x04
40 #define PERF_SYSTEM_DISK 0x08
41 #define PERF_SYSTEM_ALL 0x0F
44 * \brief Persistent data for system performence counters
52 * \brief Persistent data for WAFL performence counters. (a.k.a. cache performence)
55 #define CFG_WAFL_NAME_CACHE 0x01
56 #define CFG_WAFL_DIR_CACHE 0x02
57 #define CFG_WAFL_BUF_CACHE 0x04
58 #define CFG_WAFL_INODE_CACHE 0x08
59 #define CFG_WAFL_ALL 0x0F
61 #define HAVE_WAFL_NAME_CACHE_HIT 0x0100
62 #define HAVE_WAFL_NAME_CACHE_MISS 0x0200
63 #define HAVE_WAFL_NAME_CACHE (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
64 #define HAVE_WAFL_FIND_DIR_HIT 0x0400
65 #define HAVE_WAFL_FIND_DIR_MISS 0x0800
66 #define HAVE_WAFL_FIND_DIR (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
67 #define HAVE_WAFL_BUF_HASH_HIT 0x1000
68 #define HAVE_WAFL_BUF_HASH_MISS 0x2000
69 #define HAVE_WAFL_BUF_HASH (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
70 #define HAVE_WAFL_INODE_CACHE_HIT 0x4000
71 #define HAVE_WAFL_INODE_CACHE_MISS 0x8000
72 #define HAVE_WAFL_INODE_CACHE (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
73 #define HAVE_WAFL_ALL 0xff00
78 uint64_t name_cache_hit;
79 uint64_t name_cache_miss;
80 uint64_t find_dir_hit;
81 uint64_t find_dir_miss;
82 uint64_t buf_hash_hit;
83 uint64_t buf_hash_miss;
84 uint64_t inode_cache_hit;
85 uint64_t inode_cache_miss;
88 #define CFG_VOLUME_PERF_INIT 0x0001
89 #define CFG_VOLUME_PERF_IO 0x0002
90 #define CFG_VOLUME_PERF_OPS 0x0003
91 #define CFG_VOLUME_PERF_LATENCY 0x0008
92 #define CFG_VOLUME_PERF_ALL 0x000F
102 #define PERF_DISK_BUSIEST 0x01
103 #define PERF_DISK_ALL 0x01
109 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
110 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
111 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
112 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
113 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
114 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
115 #define HAVE_VOLUME_PERF_ALL 0x03F0
120 uint64_t write_bytes;
123 uint64_t read_latency;
124 uint64_t write_latency;
125 } per_volume_perf_data_t;
127 #define VOLUME_INIT 0x01
128 #define VOLUME_DF 0x02
129 #define VOLUME_SNAP 0x04
137 double last_disk_busy_percent;
138 uint64_t last_disk_busy;
139 uint64_t last_base_for_disk_busy;
140 } per_disk_perf_data_t;
142 typedef struct service_config_s {
144 service_handler_t *handler;
149 struct service_config_s *next;
152 #define SERVICE_INIT {0, 0, 1, 1, 0, 0, 0}
154 typedef struct volume_s {
156 per_volume_perf_data_t perf_data;
157 per_volume_data_t volume_data;
158 struct volume_s *next;
162 * \brief A disk in the netapp.
164 * A disk doesn't have any more information than its name atm.
165 * The name includes the "disk_" prefix.
168 typedef struct disk_s {
170 per_disk_perf_data_t perf_data;
174 #define DISK_INIT {0, {0, 0, 0, 0}, 0}
176 struct host_config_s {
179 na_server_transport_t protocol;
185 service_config_t *services;
188 struct host_config_s *next;
191 #define HOST_INIT {0, 0, NA_SERVER_TRANSPORT_HTTPS, 0, 0, 0, 0, 10, 0, 0, 0}
193 static host_config_t *host_config;
195 static volume_t *get_volume (host_config_t *host, const char *name, /* {{{ */
196 uint32_t vol_data_flags, uint32_t vol_perf_flags)
203 /* Make sure the default flags include the init-bit. */
204 if (vol_data_flags != 0)
205 vol_data_flags |= VOLUME_INIT;
206 if (vol_perf_flags != 0)
207 vol_perf_flags |= CFG_VOLUME_PERF_INIT;
209 for (v = host->volumes; v; v = v->next) {
210 if (strcmp(v->name, name) != 0)
213 /* Check if the flags have been initialized. */
214 if (((v->volume_data.flags & VOLUME_INIT) == 0)
215 && (vol_data_flags != 0))
216 v->volume_data.flags = vol_data_flags;
217 if (((v->perf_data.flags & CFG_VOLUME_PERF_INIT) == 0)
218 && (vol_perf_flags != 0))
219 v->perf_data.flags = vol_perf_flags;
224 DEBUG ("netapp plugin: Allocating new entry for volume %s.", name);
225 v = malloc(sizeof(*v));
228 memset (v, 0, sizeof (*v));
230 v->volume_data.flags = vol_data_flags;
231 v->perf_data.flags = vol_perf_flags;
233 v->name = strdup(name);
234 if (v->name == NULL) {
239 v->next = host->volumes;
243 } /* }}} volume_t *get_volume */
245 static disk_t *get_disk(host_config_t *host, const char *name) /* {{{ */
247 disk_t *v, init = DISK_INIT;
252 for (v = host->disks; v; v = v->next) {
253 if (strcmp(v->name, name) == 0)
256 v = malloc(sizeof(*v));
261 v->name = strdup(name);
262 if (v->name == NULL) {
267 v->next = host->disks;
271 } /* }}} disk_t *get_disk */
273 static int submit_values (const char *host, /* {{{ */
274 const char *plugin_inst,
275 const char *type, const char *type_inst,
276 value_t *values, int values_len,
279 value_list_t vl = VALUE_LIST_INIT;
282 vl.values_len = values_len;
288 sstrncpy (vl.host, host, sizeof (vl.host));
290 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
291 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
292 if (plugin_inst != NULL)
293 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
294 sstrncpy (vl.type, type, sizeof (vl.type));
295 if (type_inst != NULL)
296 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
298 return (plugin_dispatch_values (&vl));
299 } /* }}} int submit_uint64 */
301 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
302 const char *type, const char *type_inst, counter_t val0, counter_t val1,
307 values[0].counter = val0;
308 values[1].counter = val1;
310 return (submit_values (host, plugin_inst, type, type_inst,
311 values, 2, timestamp));
312 } /* }}} int submit_two_counters */
314 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
315 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
321 return (submit_values (host, plugin_inst, type, type_inst,
323 } /* }}} int submit_counter */
325 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
326 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
331 values[0].gauge = val0;
332 values[1].gauge = val1;
334 return (submit_values (host, plugin_inst, type, type_inst,
335 values, 2, timestamp));
336 } /* }}} int submit_two_gauge */
338 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
339 const char *type, const char *type_inst, double d, time_t timestamp)
343 v.gauge = (gauge_t) d;
345 return (submit_values (host, plugin_inst, type, type_inst,
347 } /* }}} int submit_uint64 */
349 static int submit_cache_ratio (const char *host, /* {{{ */
350 const char *plugin_inst,
351 const char *type_inst,
360 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
364 hits = new_hits - old_hits;
365 misses = new_misses - old_misses;
367 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
372 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
374 } /* }}} int submit_cache_ratio */
376 static int submit_wafl_data (const host_config_t *host, const char *instance, /* {{{ */
377 perf_wafl_data_t *old_data, const perf_wafl_data_t *new_data)
379 /* Submit requested counters */
380 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
381 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
382 submit_cache_ratio (host->name, instance, "name_cache_hit",
383 new_data->name_cache_hit, new_data->name_cache_miss,
384 old_data->name_cache_hit, old_data->name_cache_miss,
385 new_data->timestamp);
387 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
388 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
389 submit_cache_ratio (host->name, instance, "find_dir_hit",
390 new_data->find_dir_hit, new_data->find_dir_miss,
391 old_data->find_dir_hit, old_data->find_dir_miss,
392 new_data->timestamp);
394 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
395 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
396 submit_cache_ratio (host->name, instance, "buf_hash_hit",
397 new_data->buf_hash_hit, new_data->buf_hash_miss,
398 old_data->buf_hash_hit, old_data->buf_hash_miss,
399 new_data->timestamp);
401 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
402 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
403 submit_cache_ratio (host->name, instance, "inode_cache_hit",
404 new_data->inode_cache_hit, new_data->inode_cache_miss,
405 old_data->inode_cache_hit, old_data->inode_cache_miss,
406 new_data->timestamp);
408 /* Clear old HAVE_* flags */
409 old_data->flags &= ~HAVE_WAFL_ALL;
411 /* Copy all counters */
412 old_data->timestamp = new_data->timestamp;
413 old_data->name_cache_hit = new_data->name_cache_hit;
414 old_data->name_cache_miss = new_data->name_cache_miss;
415 old_data->find_dir_hit = new_data->find_dir_hit;
416 old_data->find_dir_miss = new_data->find_dir_miss;
417 old_data->buf_hash_hit = new_data->buf_hash_hit;
418 old_data->buf_hash_miss = new_data->buf_hash_miss;
419 old_data->inode_cache_hit = new_data->inode_cache_hit;
420 old_data->inode_cache_miss = new_data->inode_cache_miss;
422 /* Copy HAVE_* flags */
423 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
426 } /* }}} int submit_wafl_data */
428 static int submit_volume_perf_data (const host_config_t *host, /* {{{ */
430 const per_volume_perf_data_t *new_data)
432 /* Check for and submit disk-octet values */
433 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_IO)
434 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
436 submit_two_counters (host->name, volume->name, "disk_octets", /* type instance = */ NULL,
437 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
440 /* Check for and submit disk-operations values */
441 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_OPS)
442 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
444 submit_two_counters (host->name, volume->name, "disk_ops", /* type instance = */ NULL,
445 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
448 /* Check for, calculate and submit disk-latency values */
449 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_LATENCY
450 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
451 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
452 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
453 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
455 gauge_t latency_per_op_read;
456 gauge_t latency_per_op_write;
458 latency_per_op_read = NAN;
459 latency_per_op_write = NAN;
461 /* Check if a counter wrapped around. */
462 if ((new_data->read_ops > volume->perf_data.read_ops)
463 && (new_data->read_latency > volume->perf_data.read_latency))
465 uint64_t diff_ops_read;
466 uint64_t diff_latency_read;
468 diff_ops_read = new_data->read_ops - volume->perf_data.read_ops;
469 diff_latency_read = new_data->read_latency - volume->perf_data.read_latency;
471 if (diff_ops_read > 0)
472 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
475 if ((new_data->write_ops > volume->perf_data.write_ops)
476 && (new_data->write_latency > volume->perf_data.write_latency))
478 uint64_t diff_ops_write;
479 uint64_t diff_latency_write;
481 diff_ops_write = new_data->write_ops - volume->perf_data.write_ops;
482 diff_latency_write = new_data->write_latency - volume->perf_data.write_latency;
484 if (diff_ops_write > 0)
485 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
488 submit_two_gauge (host->name, volume->name, "disk_latency", /* type instance = */ NULL,
489 latency_per_op_read, latency_per_op_write, new_data->timestamp);
492 /* Clear all HAVE_* flags. */
493 volume->perf_data.flags &= ~HAVE_VOLUME_PERF_ALL;
495 /* Copy all counters */
496 volume->perf_data.timestamp = new_data->timestamp;
497 volume->perf_data.read_bytes = new_data->read_bytes;
498 volume->perf_data.write_bytes = new_data->write_bytes;
499 volume->perf_data.read_ops = new_data->read_ops;
500 volume->perf_data.write_ops = new_data->write_ops;
501 volume->perf_data.read_latency = new_data->read_latency;
502 volume->perf_data.write_latency = new_data->write_latency;
504 /* Copy the HAVE_* flags */
505 volume->perf_data.flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
508 } /* }}} int submit_volume_perf_data */
510 static void query_wafl_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
511 perf_wafl_data_t *wafl = data;
512 perf_wafl_data_t perf_data;
513 const char *plugin_inst;
516 memset (&perf_data, 0, sizeof (perf_data));
518 perf_data.timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
520 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
521 plugin_inst = na_child_get_string(out, "name");
523 /* Iterate over all counters */
524 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
525 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
529 name = na_child_get_string(counter, "name");
533 value = na_child_get_uint64(counter, "value", UINT64_MAX);
534 if (value == UINT64_MAX)
537 if (!strcmp(name, "name_cache_hit")) {
538 perf_data.name_cache_hit = value;
539 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
540 } else if (!strcmp(name, "name_cache_miss")) {
541 perf_data.name_cache_miss = value;
542 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
543 } else if (!strcmp(name, "find_dir_hit")) {
544 perf_data.find_dir_hit = value;
545 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
546 } else if (!strcmp(name, "find_dir_miss")) {
547 perf_data.find_dir_miss = value;
548 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
549 } else if (!strcmp(name, "buf_hash_hit")) {
550 perf_data.buf_hash_hit = value;
551 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
552 } else if (!strcmp(name, "buf_hash_miss")) {
553 perf_data.buf_hash_miss = value;
554 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
555 } else if (!strcmp(name, "inode_cache_hit")) {
556 perf_data.inode_cache_hit = value;
557 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
558 } else if (!strcmp(name, "inode_cache_miss")) {
559 perf_data.inode_cache_miss = value;
560 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
562 DEBUG("netapp plugin: Found unexpected child: %s", name);
566 submit_wafl_data (host, plugin_inst, wafl, &perf_data);
567 } /* }}} void query_wafl_data */
569 static void collect_perf_disk_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
570 perf_disk_data_t *perf = data;
573 na_elem_t *counter, *inst;
574 disk_t *disk, *worst_disk = 0;
576 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
577 out = na_elem_child(out, "instances");
579 /* Iterate over all children */
580 na_elem_iter_t inst_iter = na_child_iterator(out);
581 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
582 uint64_t disk_busy = 0;
583 uint64_t base_for_disk_busy = 0;
585 disk = get_disk(host, na_child_get_string(inst, "name"));
589 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
590 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
591 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
592 name = na_child_get_string(counter, "name");
596 if (strcmp(name, "disk_busy") == 0)
597 disk_busy = na_child_get_uint64(counter, "value", UINT64_MAX);
598 else if (strcmp(name, "base_for_disk_busy") == 0)
599 base_for_disk_busy = na_child_get_uint64(counter, "value", UINT64_MAX);
602 if ((disk_busy == UINT64_MAX) || (base_for_disk_busy == UINT64_MAX))
604 disk->perf_data.last_disk_busy = 0;
605 disk->perf_data.last_base_for_disk_busy = 0;
609 disk->perf_data.last_update = timestamp;
610 if ((disk_busy >= disk->perf_data.last_disk_busy)
611 && (base_for_disk_busy >= disk->perf_data.last_base_for_disk_busy))
613 uint64_t disk_busy_diff;
616 disk_busy_diff = disk_busy - disk->perf_data.last_disk_busy;
617 base_diff = base_for_disk_busy - disk->perf_data.last_base_for_disk_busy;
620 disk->perf_data.last_disk_busy_percent = NAN;
622 disk->perf_data.last_disk_busy_percent = 100.0
623 * ((gauge_t) disk_busy_diff) / ((gauge_t) base_diff);
627 disk->perf_data.last_disk_busy_percent = NAN;
630 disk->perf_data.last_disk_busy = disk_busy;
631 disk->perf_data.last_base_for_disk_busy = base_for_disk_busy;
633 if ((worst_disk == NULL)
634 || (worst_disk->perf_data.last_disk_busy_percent < disk->perf_data.last_disk_busy_percent))
638 if ((perf->flags & PERF_DISK_BUSIEST) && (worst_disk != NULL))
639 submit_double (host->name, "system", "percent", "disk_busy",
640 worst_disk->perf_data.last_disk_busy_percent, timestamp);
641 } /* }}} void collect_perf_disk_data */
643 static void collect_volume_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
646 cfg_volume_data_t *cfg_volume_data = data;
648 out = na_elem_child(out, "volumes");
649 na_elem_iter_t inst_iter = na_child_iterator(out);
650 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
651 uint64_t size_free = 0, size_used = 0, snap_reserved = 0;
654 const char *sis_state;
655 uint64_t sis_saved_reported;
658 volume = get_volume(host, na_child_get_string(inst, "name"),
659 cfg_volume_data->flags, /* perf_flags = */ 0);
663 if (!(volume->volume_data.flags & VOLUME_DF))
666 /* 2^4 exa-bytes? This will take a while ;) */
667 size_free = na_child_get_uint64(inst, "size-available", UINT64_MAX);
668 if (size_free != UINT64_MAX)
669 submit_double (host->name, volume->name, "df_complex", "used",
670 (double) size_used, /* time = */ 0);
672 size_used = na_child_get_uint64(inst, "size-used", UINT64_MAX);
673 if (size_free != UINT64_MAX)
674 submit_double (host->name, volume->name, "df_complex", "free",
675 (double) size_free, /* time = */ 0);
677 snap_reserved = na_child_get_uint64(inst, "snapshot-blocks-reserved", UINT64_MAX);
678 if (snap_reserved != UINT64_MAX)
679 /* 1 block == 1024 bytes as per API docs */
680 submit_double (host->name, volume->name, "df_complex", "snap_reserved",
681 (double) (1024 * snap_reserved), /* time = */ 0);
683 sis = na_elem_child(inst, "sis");
687 sis_state = na_child_get_string(sis, "state");
688 if ((sis_state == NULL)
689 || (strcmp ("enabled", sis_state) != 0))
692 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
693 if (sis_saved_reported == UINT64_MAX)
696 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
697 if ((sis_saved_reported >> 32) != 0) {
698 /* In case they ever fix this bug. */
699 sis_saved = sis_saved_reported;
701 uint64_t sis_saved_percent;
702 uint64_t sis_saved_guess;
703 uint64_t overflow_guess;
704 uint64_t guess1, guess2, guess3;
706 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
707 if (sis_saved_percent > 100)
710 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
711 * will hopefully be fixed in later versions. To work around the bug, try
712 * to figure out how often the 32bit integer wrapped around by using the
713 * "percentage-saved" value. Because the percentage is in the range
714 * [0-100], this should work as long as the saved space does not exceed
716 /* percentage-saved = size-saved / (size-saved + size-used) */
717 if (sis_saved_percent < 100)
718 sis_saved_guess = size_used * sis_saved_percent / (100 - sis_saved_percent);
720 sis_saved_guess = size_used;
722 overflow_guess = sis_saved_guess >> 32;
723 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
724 guess2 = (overflow_guess << 32) + sis_saved_reported;
725 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
727 if (sis_saved_guess < guess2) {
728 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
733 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
738 } /* end of 32-bit workaround */
740 submit_double (host->name, volume->name, "df_complex", "sis_saved",
741 (double) sis_saved, /* time = */ 0);
743 } /* }}} void collect_volume_data */
745 static void query_volume_perf_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
746 cfg_volume_perf_t *perf = data;
748 na_elem_t *counter, *inst;
750 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
752 out = na_elem_child(out, "instances");
753 na_elem_iter_t inst_iter = na_child_iterator(out);
754 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
755 per_volume_perf_data_t perf_data;
758 memset (&perf_data, 0, sizeof (perf_data));
759 perf_data.timestamp = timestamp;
761 volume = get_volume(host, na_child_get_string(inst, "name"),
762 /* data_flags = */ 0, perf->flags);
766 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
767 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
771 name = na_child_get_string(counter, "name");
775 value = na_child_get_uint64(counter, "value", UINT64_MAX);
776 if (value == UINT64_MAX)
779 if (!strcmp(name, "read_data")) {
780 perf_data.read_bytes = value;
781 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
782 } else if (!strcmp(name, "write_data")) {
783 perf_data.write_bytes = value;
784 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
785 } else if (!strcmp(name, "read_ops")) {
786 perf_data.read_ops = value;
787 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
788 } else if (!strcmp(name, "write_ops")) {
789 perf_data.write_ops = value;
790 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
791 } else if (!strcmp(name, "read_latency")) {
792 perf_data.read_latency = value;
793 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
794 } else if (!strcmp(name, "write_latency")) {
795 perf_data.write_latency = value;
796 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
800 submit_volume_perf_data (host, volume, &perf_data);
802 } /* }}} void query_volume_perf_data */
804 static void collect_perf_system_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
805 counter_t disk_read = 0, disk_written = 0;
806 counter_t net_recv = 0, net_sent = 0;
807 counter_t cpu_busy = 0, cpu_total = 0;
808 unsigned int counter_flags = 0;
810 perf_system_data_t *perf = data;
811 const char *instance;
815 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
816 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
817 instance = na_child_get_string(out, "name");
819 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
820 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
824 name = na_child_get_string(counter, "name");
828 value = na_child_get_uint64(counter, "value", UINT64_MAX);
829 if (value == UINT64_MAX)
832 if (!strcmp(name, "disk_data_read")) {
833 disk_read = (counter_t) (value * 1024);
834 counter_flags |= 0x01;
835 } else if (!strcmp(name, "disk_data_written")) {
836 disk_written = (counter_t) (value * 1024);
837 counter_flags |= 0x02;
838 } else if (!strcmp(name, "net_data_recv")) {
839 net_recv = (counter_t) (value * 1024);
840 counter_flags |= 0x04;
841 } else if (!strcmp(name, "net_data_sent")) {
842 net_sent = (counter_t) (value * 1024);
843 counter_flags |= 0x08;
844 } else if (!strcmp(name, "cpu_busy")) {
845 cpu_busy = (counter_t) value;
846 counter_flags |= 0x10;
847 } else if (!strcmp(name, "cpu_elapsed_time")) {
848 cpu_total = (counter_t) value;
849 counter_flags |= 0x20;
850 } else if ((perf->flags & PERF_SYSTEM_OPS)
851 && (strlen(name) > 4)
852 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
853 submit_counter (host->name, instance, "disk_ops_complex", name,
854 (counter_t) value, timestamp);
856 } /* for (counter) */
858 if ((perf->flags & PERF_SYSTEM_DISK)
859 && ((counter_flags & 0x03) == 0x03))
860 submit_two_counters (host->name, instance, "disk_octets", NULL,
861 disk_read, disk_written, timestamp);
863 if ((perf->flags & PERF_SYSTEM_NET)
864 && ((counter_flags & 0x0c) == 0x0c))
865 submit_two_counters (host->name, instance, "if_octets", NULL,
866 net_recv, net_sent, timestamp);
868 if ((perf->flags & PERF_SYSTEM_CPU)
869 && ((counter_flags & 0x30) == 0x30)) {
870 submit_counter (host->name, instance, "cpu", "system",
871 cpu_busy, timestamp);
872 submit_counter (host->name, instance, "cpu", "idle",
873 cpu_total - cpu_busy, timestamp);
875 } /* }}} void collect_perf_system_data */
877 static int config_init(void) { /* {{{ */
881 service_config_t *service;
884 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
888 if (!na_startup(err, sizeof(err))) {
889 ERROR("netapp plugin: Error initializing netapp API: %s", err);
893 for (host = host_config; host; host = host->next) {
894 host->srv = na_server_open(host->host, 1, 1);
895 na_server_set_transport_type(host->srv, host->protocol, 0);
896 na_server_set_port(host->srv, host->port);
897 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
898 na_server_adminuser(host->srv, host->username, host->password);
899 na_server_set_timeout(host->srv, 5);
900 for (service = host->services; service; service = service->next) {
901 service->interval = host->interval * service->multiplier;
902 if (service->handler == collect_perf_system_data) {
903 service->query = na_elem_new("perf-object-get-instances");
904 na_child_add_string(service->query, "objectname", "system");
905 } else if (service->handler == query_volume_perf_data) {
906 service->query = na_elem_new("perf-object-get-instances");
907 na_child_add_string(service->query, "objectname", "volume");
908 /* e = na_elem_new("instances");
909 na_child_add_string(e, "foo", "system");
910 na_child_add(root, e);*/
911 e = na_elem_new("counters");
912 na_child_add_string(e, "foo", "read_ops");
913 na_child_add_string(e, "foo", "write_ops");
914 na_child_add_string(e, "foo", "read_data");
915 na_child_add_string(e, "foo", "write_data");
916 na_child_add_string(e, "foo", "read_latency");
917 na_child_add_string(e, "foo", "write_latency");
918 na_child_add(service->query, e);
919 } else if (service->handler == query_wafl_data) {
920 service->query = na_elem_new("perf-object-get-instances");
921 na_child_add_string(service->query, "objectname", "wafl");
922 /* e = na_elem_new("instances");
923 na_child_add_string(e, "foo", "system");
924 na_child_add(root, e);*/
925 e = na_elem_new("counters");
926 na_child_add_string(e, "foo", "name_cache_hit");
927 na_child_add_string(e, "foo", "name_cache_miss");
928 na_child_add_string(e, "foo", "find_dir_hit");
929 na_child_add_string(e, "foo", "find_dir_miss");
930 na_child_add_string(e, "foo", "buf_hash_hit");
931 na_child_add_string(e, "foo", "buf_hash_miss");
932 na_child_add_string(e, "foo", "inode_cache_hit");
933 na_child_add_string(e, "foo", "inode_cache_miss");
934 /* na_child_add_string(e, "foo", "inode_eject_time"); */
935 /* na_child_add_string(e, "foo", "buf_eject_time"); */
936 na_child_add(service->query, e);
937 } else if (service->handler == collect_perf_disk_data) {
938 service->query = na_elem_new("perf-object-get-instances");
939 na_child_add_string(service->query, "objectname", "disk");
940 e = na_elem_new("counters");
941 na_child_add_string(e, "foo", "disk_busy");
942 na_child_add_string(e, "foo", "base_for_disk_busy");
943 na_child_add(service->query, e);
944 } else if (service->handler == collect_volume_data) {
945 service->query = na_elem_new("volume-list-info");
946 /* na_child_add_string(service->query, "objectname", "volume"); */
947 /* } else if (service->handler == collect_snapshot_data) { */
948 /* service->query = na_elem_new("snapshot-list-info"); */
953 } /* }}} int config_init */
955 static int config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
956 uint32_t *flags, uint32_t flag)
958 if ((ci == NULL) || (flags == NULL))
961 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
963 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
968 if (ci->values[0].value.boolean)
974 } /* }}} int config_bool_to_flag */
976 static int config_get_multiplier (const oconfig_item_t *ci, /* {{{ */
977 service_config_t *service)
981 if ((ci == NULL) || (service == NULL))
984 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
986 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
990 tmp = (int) (ci->values[0].value.number + .5);
993 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
997 service->multiplier = tmp;
998 service->skip_countdown = tmp;
1001 } /* }}} int config_get_multiplier */
1003 static void set_global_perf_vol_flag(const host_config_t *host, /* {{{ */
1004 uint32_t flag, _Bool set)
1008 for (v = host->volumes; v; v = v->next) {
1010 v->perf_data.flags |= flag;
1011 else /* if (!set) */
1012 v->perf_data.flags &= ~flag;
1014 } /* }}} void set_global_perf_vol_flag */
1016 static void set_global_vol_flag(const host_config_t *host, /* {{{ */
1017 uint32_t flag, _Bool set) {
1020 for (v = host->volumes; v; v = v->next) {
1022 v->volume_data.flags |= flag;
1023 else /* if (!set) */
1024 v->volume_data.flags &= ~flag;
1026 } /* }}} void set_global_vol_flag */
1028 static void process_perf_volume_flag (host_config_t *host, /* {{{ */
1029 cfg_volume_perf_t *perf_volume, const oconfig_item_t *item,
1034 for (i = 0; i < item->values_num; ++i) {
1039 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1040 WARNING("netapp plugin: Ignoring non-string argument in "
1041 "\"GetVolumePerfData\" block for host %s", host->name);
1045 name = item->values[i].value.string;
1046 if (name[0] == '+') {
1049 } else if (name[0] == '-') {
1056 perf_volume->flags |= flag;
1057 else /* if (!set) */
1058 perf_volume->flags &= ~flag;
1060 set_global_perf_vol_flag(host, flag, set);
1064 v = get_volume (host, name, /* data_flags = */ 0, perf_volume->flags);
1069 v->perf_data.flags |= flag;
1070 else /* if (!set) */
1071 v->perf_data.flags &= ~flag;
1072 } /* for (i = 0 .. item->values_num) */
1073 } /* }}} void process_perf_volume_flag */
1075 static void process_volume_flag (host_config_t *host, /* {{{ */
1076 cfg_volume_data_t *cfg_volume_data, const oconfig_item_t *item, uint32_t flag)
1080 for (i = 0; i < item->values_num; ++i) {
1085 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1086 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolData\""
1087 "block for host %s", host->name);
1091 name = item->values[i].value.string;
1092 if (name[0] == '+') {
1095 } else if (name[0] == '-') {
1102 cfg_volume_data->flags |= flag;
1103 else /* if (!set) */
1104 cfg_volume_data->flags &= ~flag;
1106 set_global_vol_flag(host, flag, set);
1110 v = get_volume(host, name, cfg_volume_data->flags, /* perf_flags = */ 0);
1114 if (!v->volume_data.flags)
1115 v->volume_data.flags = cfg_volume_data->flags;
1118 v->volume_data.flags |= flag;
1119 else /* if (!set) */
1120 v->volume_data.flags &= ~flag;
1122 } /* }}} void process_volume_flag */
1124 static void build_perf_vol_config(host_config_t *host, const oconfig_item_t *ci) {
1125 int i, had_io = 0, had_ops = 0, had_latency = 0;
1126 service_config_t *service;
1127 cfg_volume_perf_t *perf_volume;
1129 service = malloc(sizeof(*service));
1131 service->handler = query_volume_perf_data;
1132 perf_volume = service->data = malloc(sizeof(*perf_volume));
1133 perf_volume->flags = CFG_VOLUME_PERF_INIT;
1134 service->next = host->services;
1135 host->services = service;
1136 for (i = 0; i < ci->children_num; ++i) {
1137 oconfig_item_t *item = ci->children + i;
1139 /* if (!item || !item->key || !*item->key) continue; */
1140 if (!strcasecmp(item->key, "Multiplier")) {
1141 config_get_multiplier (item, service);
1142 } else if (!strcasecmp(item->key, "GetIO")) {
1144 process_perf_volume_flag(host, perf_volume, item, CFG_VOLUME_PERF_IO);
1145 } else if (!strcasecmp(item->key, "GetOps")) {
1147 process_perf_volume_flag(host, perf_volume, item, CFG_VOLUME_PERF_OPS);
1148 } else if (!strcasecmp(item->key, "GetLatency")) {
1150 process_perf_volume_flag(host, perf_volume, item, CFG_VOLUME_PERF_LATENCY);
1154 perf_volume->flags |= CFG_VOLUME_PERF_IO;
1155 set_global_perf_vol_flag(host, CFG_VOLUME_PERF_IO, /* set = */ true);
1158 perf_volume->flags |= CFG_VOLUME_PERF_OPS;
1159 set_global_perf_vol_flag(host, CFG_VOLUME_PERF_OPS, /* set = */ true);
1162 perf_volume->flags |= CFG_VOLUME_PERF_LATENCY;
1163 set_global_perf_vol_flag(host, CFG_VOLUME_PERF_LATENCY, /* set = */ true);
1167 static void build_volume_config(host_config_t *host, oconfig_item_t *ci) {
1169 service_config_t *service;
1170 cfg_volume_data_t *cfg_volume_data;
1172 service = malloc(sizeof(*service));
1174 service->handler = collect_volume_data;
1175 cfg_volume_data = service->data = malloc(sizeof(*cfg_volume_data));
1176 cfg_volume_data->flags = VOLUME_INIT;
1177 service->next = host->services;
1178 host->services = service;
1179 for (i = 0; i < ci->children_num; ++i) {
1180 oconfig_item_t *item = ci->children + i;
1182 /* if (!item || !item->key || !*item->key) continue; */
1183 if (!strcasecmp(item->key, "Multiplier")) {
1184 config_get_multiplier (item, service);
1185 } else if (!strcasecmp(item->key, "GetDiskUtil")) {
1187 process_volume_flag(host, cfg_volume_data, item, VOLUME_DF);
1191 cfg_volume_data->flags |= VOLUME_DF;
1192 set_global_vol_flag(host, VOLUME_DF, /* set = */ true);
1196 static void build_perf_disk_config(host_config_t *temp, oconfig_item_t *ci) {
1198 service_config_t *service;
1199 perf_disk_data_t *perf_disk;
1201 service = malloc(sizeof(*service));
1203 service->handler = collect_perf_disk_data;
1204 perf_disk = service->data = malloc(sizeof(*perf_disk));
1205 perf_disk->flags = PERF_DISK_ALL;
1206 service->next = temp->services;
1207 temp->services = service;
1208 for (i = 0; i < ci->children_num; ++i) {
1209 oconfig_item_t *item = ci->children + i;
1211 /* if (!item || !item->key || !*item->key) continue; */
1212 if (!strcasecmp(item->key, "Multiplier")) {
1213 config_get_multiplier (item, service);
1214 } else if (!strcasecmp(item->key, "GetBusy")) {
1215 config_bool_to_flag (item, &perf_disk->flags, PERF_SYSTEM_CPU);
1220 static void build_perf_wafl_config(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1222 service_config_t *service;
1223 perf_wafl_data_t *perf_wafl;
1225 service = malloc(sizeof(*service));
1226 if (service == NULL)
1228 memset (service, 0, sizeof (*service));
1231 service->handler = query_wafl_data;
1232 perf_wafl = service->data = malloc(sizeof(*perf_wafl));
1233 perf_wafl->flags = CFG_WAFL_ALL;
1235 for (i = 0; i < ci->children_num; ++i) {
1236 oconfig_item_t *item = ci->children + i;
1238 if (!strcasecmp(item->key, "Multiplier")) {
1239 config_get_multiplier (item, service);
1240 } else if (!strcasecmp(item->key, "GetNameCache")) {
1241 config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_NAME_CACHE);
1242 } else if (!strcasecmp(item->key, "GetDirCache")) {
1243 config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_DIR_CACHE);
1244 } else if (!strcasecmp(item->key, "GetBufCache")) {
1245 config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_BUF_CACHE);
1246 } else if (!strcasecmp(item->key, "GetInodeCache")) {
1247 config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_INODE_CACHE);
1249 WARNING ("netapp plugin: The %s config option is not allowed within "
1250 "`GetWaflPerfData' blocks.", item->key);
1254 service->next = host->services;
1255 host->services = service;
1256 } /* }}} void build_perf_wafl_config */
1258 static int build_perf_sys_config (host_config_t *host, /* {{{ */
1259 oconfig_item_t *ci, const service_config_t *default_service)
1262 service_config_t *service;
1263 perf_system_data_t *perf_system;
1265 service = malloc(sizeof(*service));
1266 if (service == NULL)
1268 memset (service, 0, sizeof (*service));
1269 *service = *default_service;
1270 service->handler = collect_perf_system_data;
1272 perf_system = malloc(sizeof(*perf_system));
1273 if (perf_system == NULL) {
1277 memset (perf_system, 0, sizeof (*perf_system));
1278 perf_system->flags = PERF_SYSTEM_ALL;
1279 service->data = perf_system;
1281 for (i = 0; i < ci->children_num; ++i) {
1282 oconfig_item_t *item = ci->children + i;
1284 if (!strcasecmp(item->key, "Multiplier")) {
1285 config_get_multiplier (item, service);
1286 } else if (!strcasecmp(item->key, "GetCPULoad")) {
1287 config_bool_to_flag (item, &perf_system->flags, PERF_SYSTEM_CPU);
1288 } else if (!strcasecmp(item->key, "GetInterfaces")) {
1289 config_bool_to_flag (item, &perf_system->flags, PERF_SYSTEM_NET);
1290 } else if (!strcasecmp(item->key, "GetDiskOps")) {
1291 config_bool_to_flag (item, &perf_system->flags, PERF_SYSTEM_OPS);
1292 } else if (!strcasecmp(item->key, "GetDiskIO")) {
1293 config_bool_to_flag (item, &perf_system->flags, PERF_SYSTEM_DISK);
1295 WARNING ("netapp plugin: The %s config option is not allowed within "
1296 "`GetSystemPerfData' blocks.", item->key);
1300 service->next = host->services;
1301 host->services = service;
1304 } /* }}} int build_perf_sys_config */
1306 static host_config_t *build_host_config(const oconfig_item_t *ci, const host_config_t *default_host, const service_config_t *def_def_service) {
1308 oconfig_item_t *item;
1309 host_config_t *host, *hc, temp = *default_host;
1310 service_config_t default_service = *def_def_service;
1312 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1313 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
1317 temp.name = ci->values[0].value.string;
1318 for (i = 0; i < ci->children_num; ++i) {
1319 item = ci->children + i;
1321 /* if (!item || !item->key || !*item->key) continue; */
1322 if (!strcasecmp(item->key, "Address")) {
1323 if ((item->values_num != 1) || (item->values[0].type != OCONFIG_TYPE_STRING)) {
1324 WARNING("netapp plugin: \"Name\" needs exactly one string argument. Ignoring host block \"%s\".", ci->values[0].value.string);
1327 temp.host = item->values[0].value.string;
1328 } else if (!strcasecmp(item->key, "Port")) {
1329 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 < 1) || (item->values[0].value.number > 65535)) {
1330 WARNING("netapp plugin: \"Port\" needs exactly one integer argument in the range of 1-65535. Ignoring host block \"%s\".", ci->values[0].value.string);
1333 temp.port = item->values[0].value.number;
1334 } else if (!strcasecmp(item->key, "Protocol")) {
1335 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"))) {
1336 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
1339 if (!strcasecmp(item->values[0].value.string, "http")) temp.protocol = NA_SERVER_TRANSPORT_HTTP;
1340 else temp.protocol = NA_SERVER_TRANSPORT_HTTPS;
1341 } else if (!strcasecmp(item->key, "Login")) {
1342 if ((item->values_num != 2) || (item->values[0].type != OCONFIG_TYPE_STRING) || (item->values[1].type != OCONFIG_TYPE_STRING)) {
1343 WARNING("netapp plugin: \"Login\" needs exactly two string arguments, username and password. Ignoring host block \"%s\".", ci->values[0].value.string);
1346 temp.username = item->values[0].value.string;
1347 temp.password = item->values[1].value.string;
1348 } else if (!strcasecmp(item->key, "Interval")) {
1349 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) {
1350 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
1353 temp.interval = item->values[0].value.number;
1354 } else if (!strcasecmp(item->key, "GetVolumePerfData")) {
1355 build_perf_vol_config(&temp, item);
1356 } else if (!strcasecmp(item->key, "GetSystemPerfData")) {
1357 build_perf_sys_config(&temp, item, &default_service);
1358 } else if (!strcasecmp(item->key, "GetWaflPerfData")) {
1359 build_perf_wafl_config(&temp, item);
1360 } else if (!strcasecmp(item->key, "GetDiskPerfData")) {
1361 build_perf_disk_config(&temp, item);
1362 } else if (!strcasecmp(item->key, "GetVolumeData")) {
1363 build_volume_config(&temp, item);
1365 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
1366 item->key, ci->values[0].value.string);
1370 if (!temp.host) temp.host = temp.name;
1371 if (!temp.port) temp.port = temp.protocol == NA_SERVER_TRANSPORT_HTTP ? 80 : 443;
1372 if (!temp.username) {
1373 WARNING("netapp plugin: Please supply login information for host \"%s\". Ignoring host block.", temp.name);
1376 for (hc = host_config; hc; hc = hc->next) {
1377 if (!strcasecmp(hc->name, temp.name)) WARNING("netapp plugin: Duplicate definition of host \"%s\". This is probably a bad idea.", hc->name);
1379 host = malloc(sizeof(*host));
1381 host->name = strdup(temp.name);
1382 host->protocol = temp.protocol;
1383 host->host = strdup(temp.host);
1384 host->username = strdup(temp.username);
1385 host->password = strdup(temp.password);
1386 host->next = host_config;
1391 static int build_config (oconfig_item_t *ci) {
1393 oconfig_item_t *item;
1394 host_config_t default_host = HOST_INIT;
1395 service_config_t default_service = SERVICE_INIT;
1397 for (i = 0; i < ci->children_num; ++i) {
1398 item = ci->children + i;
1400 /* if (!item || !item->key || !*item->key) continue; */
1401 if (!strcasecmp(item->key, "Host")) {
1402 build_host_config(item, &default_host, &default_service);
1404 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
1410 static int netapp_read() {
1412 host_config_t *host;
1413 service_config_t *service;
1415 for (host = host_config; host; host = host->next) {
1416 for (service = host->services; service; service = service->next) {
1417 if (--service->skip_countdown > 0) continue;
1418 service->skip_countdown = service->multiplier;
1419 out = na_server_invoke_elem(host->srv, service->query);
1420 if (na_results_status(out) != NA_OK) {
1421 int netapp_errno = na_results_errno(out);
1422 ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
1424 if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
1425 /* Network problems. Just give up on all other services on this host. */
1430 service->handler(host, out, service->data);
1437 void module_register() {
1438 plugin_register_complex_config("netapp", build_config);
1439 plugin_register_init("netapp", config_init);
1440 plugin_register_read("netapp", netapp_read);
1443 /* vim: set sw=2 ts=2 noet fdm=marker : */