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 typedef struct host_config_s host_config_t;
33 typedef void service_handler_t(host_config_t *host, na_elem_t *result, void *data);
35 #define PERF_SYSTEM_CPU 0x01
36 #define PERF_SYSTEM_NET 0x02
37 #define PERF_SYSTEM_OPS 0x04
38 #define PERF_SYSTEM_DISK 0x08
39 #define PERF_SYSTEM_ALL 0x0F
42 * \brief Persistent data for system performence counters
47 uint64_t last_cpu_busy;
48 uint64_t last_cpu_total;
52 * \brief Persistent data for WAFL performence counters. (a.k.a. cache performence)
55 #define PERF_WAFL_NAME_CACHE 0x01
56 #define PERF_WAFL_DIR_CACHE 0x02
57 #define PERF_WAFL_BUF_CACHE 0x04
58 #define PERF_WAFL_INODE_CACHE 0x08
59 #define PERF_WAFL_ALL 0x0F
63 uint64_t last_name_cache_hit;
64 uint64_t last_name_cache_miss;
65 uint64_t last_find_dir_hit;
66 uint64_t last_find_dir_miss;
67 uint64_t last_buf_hash_hit;
68 uint64_t last_buf_hash_miss;
69 uint64_t last_inode_cache_hit;
70 uint64_t last_inode_cache_miss;
73 #define PERF_VOLUME_INIT 0x01
74 #define PERF_VOLUME_IO 0x02
75 #define PERF_VOLUME_OPS 0x03
76 #define PERF_VOLUME_LATENCY 0x08
77 #define PERF_VOLUME_ALL 0x0F
87 #define PERF_DISK_BUSIEST 0x01
88 #define PERF_DISK_ALL 0x01
96 time_t last_timestamp;
97 uint64_t last_read_latency;
98 uint64_t last_write_latency;
99 uint64_t last_read_ops;
100 uint64_t last_write_ops;
101 } per_volume_perf_data_t;
103 #define VOLUME_INIT 0x01
104 #define VOLUME_DF 0x02
105 #define VOLUME_SNAP 0x04
113 double last_disk_busy_percent;
114 uint64_t last_disk_busy;
115 uint64_t last_base_for_disk_busy;
116 } per_disk_perf_data_t;
118 typedef struct service_config_s {
120 service_handler_t *handler;
125 struct service_config_s *next;
128 #define SERVICE_INIT {0, 0, 1, 1, 0, 0, 0}
130 typedef struct volume_s {
132 per_volume_perf_data_t perf_data;
133 per_volume_data_t volume_data;
134 struct volume_s *next;
138 * \brief A disk in the netapp.
140 * A disk doesn't have any more information than its name atm.
141 * The name includes the "disk_" prefix.
144 typedef struct disk_s {
146 per_disk_perf_data_t perf_data;
150 #define DISK_INIT {0, {0, 0, 0, 0}, 0}
152 struct host_config_s {
155 na_server_transport_t protocol;
161 service_config_t *services;
164 struct host_config_s *next;
167 #define HOST_INIT {0, 0, NA_SERVER_TRANSPORT_HTTPS, 0, 0, 0, 0, 10, 0, 0, 0}
169 static host_config_t *host_config;
171 static volume_t *get_volume (host_config_t *host, const char *name) /* {{{ */
178 for (v = host->volumes; v; v = v->next) {
179 if (strcmp(v->name, name) == 0)
183 v = malloc(sizeof(*v));
186 memset (v, 0, sizeof (*v));
188 v->name = strdup(name);
189 if (v->name == NULL) {
194 v->next = host->volumes;
198 } /* }}} volume_t *get_volume */
200 static disk_t *get_disk(host_config_t *host, const char *name) /* {{{ */
202 disk_t *v, init = DISK_INIT;
207 for (v = host->disks; v; v = v->next) {
208 if (strcmp(v->name, name) == 0)
211 v = malloc(sizeof(*v));
216 v->name = strdup(name);
217 if (v->name == NULL) {
222 v->next = host->disks;
226 } /* }}} disk_t *get_disk */
228 static int submit_values (const char *host, /* {{{ */
229 const char *plugin_inst,
230 const char *type, const char *type_inst,
231 value_t *values, int values_len,
234 value_list_t vl = VALUE_LIST_INIT;
237 vl.values_len = values_len;
243 sstrncpy (vl.host, host, sizeof (vl.host));
245 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
246 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
247 if (plugin_inst != NULL)
248 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
249 sstrncpy (vl.type, type, sizeof (vl.type));
250 if (type_inst != NULL)
251 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
253 return (plugin_dispatch_values (&vl));
254 } /* }}} int submit_uint64 */
256 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
257 const char *type, const char *type_inst, counter_t val0, counter_t val1,
262 values[0].counter = val0;
263 values[1].counter = val1;
265 return (submit_values (host, plugin_inst, type, type_inst,
266 values, 2, timestamp));
267 } /* }}} int submit_two_counters */
269 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
270 const char *type, const char *type_inst, double d, time_t timestamp)
274 v.gauge = (gauge_t) d;
276 return (submit_values (host, plugin_inst, type, type_inst,
278 } /* }}} int submit_uint64 */
280 static int submit_cache_ratio (const char *host, /* {{{ */
281 const char *plugin_inst,
282 const char *type_inst,
286 uint64_t *old_misses,
291 if ((new_hits >= (*old_hits)) && (new_misses >= (*old_misses))) {
295 hits = new_hits - (*old_hits);
296 misses = new_misses - (*old_misses);
298 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
303 *old_hits = new_hits;
304 *old_misses = new_misses;
306 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
308 } /* }}} int submit_cache_ratio */
310 static void collect_perf_wafl_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
311 perf_wafl_data_t *wafl = data;
312 uint64_t name_cache_hit = 0, name_cache_miss = 0;
313 uint64_t find_dir_hit = 0, find_dir_miss = 0;
314 uint64_t buf_hash_hit = 0, buf_hash_miss = 0;
315 uint64_t inode_cache_hit = 0, inode_cache_miss = 0;
316 const char *plugin_inst;
320 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
321 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
322 plugin_inst = na_child_get_string(out, "name");
324 /* Iterate over all counters */
325 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
326 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
329 name = na_child_get_string(counter, "name");
330 if (!strcmp(name, "name_cache_hit"))
331 name_cache_hit = na_child_get_uint64(counter, "value", UINT64_MAX);
332 else if (!strcmp(name, "name_cache_miss"))
333 name_cache_miss = na_child_get_uint64(counter, "value", UINT64_MAX);
334 else if (!strcmp(name, "find_dir_hit"))
335 find_dir_hit = na_child_get_uint64(counter, "value", UINT64_MAX);
336 else if (!strcmp(name, "find_dir_miss"))
337 find_dir_miss = na_child_get_uint64(counter, "value", UINT64_MAX);
338 else if (!strcmp(name, "buf_hash_hit"))
339 buf_hash_hit = na_child_get_uint64(counter, "value", UINT64_MAX);
340 else if (!strcmp(name, "buf_hash_miss"))
341 buf_hash_miss = na_child_get_uint64(counter, "value", UINT64_MAX);
342 else if (!strcmp(name, "inode_cache_hit"))
343 inode_cache_hit = na_child_get_uint64(counter, "value", UINT64_MAX);
344 else if (!strcmp(name, "inode_cache_miss"))
345 inode_cache_miss = na_child_get_uint64(counter, "value", UINT64_MAX);
347 INFO ("netapp plugin: Found unexpected child: %s", name);
350 /* Submit requested counters */
351 if ((wafl->flags & PERF_WAFL_NAME_CACHE)
352 && (name_cache_hit != UINT64_MAX) && (name_cache_miss != UINT64_MAX))
353 submit_cache_ratio (host->name, plugin_inst, "name_cache_hit",
354 name_cache_hit, name_cache_miss,
355 &wafl->last_name_cache_hit, &wafl->last_name_cache_miss,
358 if ((wafl->flags & PERF_WAFL_DIR_CACHE)
359 && (find_dir_hit != UINT64_MAX) && (find_dir_miss != UINT64_MAX))
360 submit_cache_ratio (host->name, plugin_inst, "find_dir_hit",
361 find_dir_hit, find_dir_miss,
362 &wafl->last_find_dir_hit, &wafl->last_find_dir_miss,
365 if ((wafl->flags & PERF_WAFL_BUF_CACHE)
366 && (buf_hash_hit != UINT64_MAX) && (buf_hash_miss != UINT64_MAX))
367 submit_cache_ratio (host->name, plugin_inst, "buf_hash_hit",
368 buf_hash_hit, buf_hash_miss,
369 &wafl->last_buf_hash_hit, &wafl->last_buf_hash_miss,
372 if ((wafl->flags & PERF_WAFL_INODE_CACHE)
373 && (inode_cache_hit != UINT64_MAX) && (inode_cache_miss != UINT64_MAX))
374 submit_cache_ratio (host->name, plugin_inst, "inode_cache_hit",
375 inode_cache_hit, inode_cache_miss,
376 &wafl->last_inode_cache_hit, &wafl->last_inode_cache_miss,
378 } /* }}} void collect_perf_wafl_data */
380 static void collect_perf_disk_data(host_config_t *host, na_elem_t *out, void *data) {
381 perf_disk_data_t *perf = data;
384 na_elem_t *counter, *inst;
385 disk_t *disk, *worst_disk = 0;
387 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
388 out = na_elem_child(out, "instances");
390 /* Iterate over all children */
391 na_elem_iter_t inst_iter = na_child_iterator(out);
392 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
393 uint64_t disk_busy = 0;
394 uint64_t base_for_disk_busy = 0;
396 disk = get_disk(host, na_child_get_string(inst, "name"));
400 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
401 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
402 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
403 name = na_child_get_string(counter, "name");
407 if (strcmp(name, "disk_busy") == 0)
408 disk_busy = na_child_get_uint64(counter, "value", UINT64_MAX);
409 else if (strcmp(name, "base_for_disk_busy") == 0)
410 base_for_disk_busy = na_child_get_uint64(counter, "value", UINT64_MAX);
413 if ((disk_busy == UINT64_MAX) || (base_for_disk_busy == UINT64_MAX))
415 disk->perf_data.last_disk_busy = 0;
416 disk->perf_data.last_base_for_disk_busy = 0;
420 disk->perf_data.last_update = timestamp;
421 if ((disk_busy >= disk->perf_data.last_disk_busy)
422 && (base_for_disk_busy >= disk->perf_data.last_base_for_disk_busy))
424 uint64_t disk_busy_diff;
427 disk_busy_diff = disk_busy - disk->perf_data.last_disk_busy;
428 base_diff = base_for_disk_busy - disk->perf_data.last_base_for_disk_busy;
431 disk->perf_data.last_disk_busy_percent = NAN;
433 disk->perf_data.last_disk_busy_percent = 100.0
434 * ((gauge_t) disk_busy_diff) / ((gauge_t) base_diff);
438 disk->perf_data.last_disk_busy_percent = NAN;
441 disk->perf_data.last_disk_busy = disk_busy;
442 disk->perf_data.last_base_for_disk_busy = base_for_disk_busy;
444 if ((worst_disk == NULL)
445 || (worst_disk->perf_data.last_disk_busy_percent < disk->perf_data.last_disk_busy_percent))
449 if ((perf->flags & PERF_DISK_BUSIEST) && (worst_disk != NULL))
450 submit_double (host->name, "system", "percent", "disk_busy",
451 worst_disk->perf_data.last_disk_busy_percent, timestamp);
452 } /* void collect_perf_disk_data */
454 static void collect_volume_data(host_config_t *host, na_elem_t *out, void *data) {
455 na_elem_t *inst, *sis;
457 volume_data_t *volume_data = data;
459 value_list_t vl = VALUE_LIST_INIT;
461 out = na_elem_child(out, "volumes");
462 na_elem_iter_t inst_iter = na_child_iterator(out);
463 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
464 uint64_t size_free = 0, size_used = 0, snap_reserved = 0, sis_saved = 0;
465 volume = get_volume(host, na_child_get_string(inst, "name"));
466 if (!(volume->volume_data.flags & VOLUME_INIT)) volume->volume_data.flags = volume_data->flags;
467 if (!(volume->volume_data.flags & VOLUME_DF)) continue;
468 size_free = na_child_get_uint64(inst, "size-available", 0);
469 size_used = na_child_get_uint64(inst, "size-used", 0);
470 snap_reserved = na_child_get_uint64(inst, "snapshot-blocks-reserved", 0) * 1024;
475 vl.interval = interval_g;
476 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
477 sstrncpy(vl.host, host->name, sizeof(vl.host));
478 sstrncpy(vl.plugin_instance, volume->name, sizeof(vl.plugin_instance));
479 sstrncpy(vl.type, "df_complex", sizeof(vl.type));
481 values[0].gauge = size_used;
482 sstrncpy(vl.type_instance, "used", sizeof(vl.type_instance));
483 DEBUG("%s/netapp-%s/df_complex-used: %"PRIu64, host->name, volume->name, size_used);
484 plugin_dispatch_values (&vl);
486 values[0].gauge = size_free;
487 sstrncpy(vl.type_instance, "free", sizeof(vl.type_instance));
488 DEBUG("%s/netapp-%s/df_complex-free: %"PRIu64, host->name, volume->name, size_free);
489 plugin_dispatch_values (&vl);
492 values[0].gauge = snap_reserved;
493 sstrncpy(vl.type_instance, "snap_reserved", sizeof(vl.type_instance));
494 DEBUG("%s/netapp-%s/df_complex-snap_reserved: %"PRIu64, host->name, volume->name, snap_reserved);
495 plugin_dispatch_values (&vl);
498 sis = na_elem_child(inst, "sis");
499 if (sis && !strcmp(na_child_get_string(sis, "state"), "enabled")) {
500 uint64_t sis_saved_reported = na_child_get_uint64(sis, "size-saved", 0), sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", 0);
501 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
502 if (sis_saved_reported >> 32) {
503 /* In case they ever fix this bug. */
504 sis_saved = sis_saved_reported;
506 uint64_t real_saved = sis_saved_percent * size_used / (100 - sis_saved_percent);
507 uint64_t overflow_guess = real_saved >> 32;
508 uint64_t guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
509 uint64_t guess2 = (overflow_guess << 32) + sis_saved_reported;
510 uint64_t guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
512 if (real_saved < guess2) {
513 if (real_saved - guess1 < guess2 - real_saved) sis_saved = guess1;
514 else sis_saved = guess2;
516 if (real_saved - guess2 < guess3 - real_saved) sis_saved = guess2;
517 else sis_saved = guess3;
520 values[0].gauge = sis_saved;
521 sstrncpy(vl.type_instance, "sis_saved", sizeof(vl.type_instance));
522 DEBUG("%s/netapp-%s/df_complex-sis_saved: %"PRIu64, host->name, volume->name, sis_saved);
523 plugin_dispatch_values (&vl);
528 static void collect_perf_volume_data(host_config_t *host, na_elem_t *out, void *data) {
529 perf_volume_data_t *perf = data;
532 na_elem_t *counter, *inst;
535 value_list_t vl = VALUE_LIST_INIT;
537 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
538 out = na_elem_child(out, "instances");
539 na_elem_iter_t inst_iter = na_child_iterator(out);
540 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
541 uint64_t read_data = 0, write_data = 0, read_ops = 0, write_ops = 0, read_latency = 0, write_latency = 0;
543 volume = get_volume(host, na_child_get_string(inst, "name"));
544 if (!volume->perf_data.flags) {
545 volume->perf_data.flags = perf->flags;
546 volume->perf_data.last_read_latency = volume->perf_data.last_read_ops = 0;
547 volume->perf_data.last_write_latency = volume->perf_data.last_write_ops = 0;
549 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
550 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
551 name = na_child_get_string(counter, "name");
552 if (!strcmp(name, "read_ops")) {
553 read_ops = na_child_get_uint64(counter, "value", 0);
554 } else if (!strcmp(name, "write_ops")) {
555 write_ops = na_child_get_uint64(counter, "value", 0);
556 } else if (!strcmp(name, "read_data")) {
557 read_data = na_child_get_uint64(counter, "value", 0);
558 } else if (!strcmp(name, "write_data")) {
559 write_data = na_child_get_uint64(counter, "value", 0);
560 } else if (!strcmp(name, "read_latency")) {
561 read_latency = na_child_get_uint64(counter, "value", 0);
562 } else if (!strcmp(name, "write_latency")) {
563 write_latency = na_child_get_uint64(counter, "value", 0);
566 if (read_ops && write_ops) {
567 values[0].counter = read_ops;
568 values[1].counter = write_ops;
572 vl.interval = interval_g;
573 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
574 sstrncpy(vl.host, host->name, sizeof(vl.host));
575 sstrncpy(vl.plugin_instance, volume->name, sizeof(vl.plugin_instance));
576 sstrncpy(vl.type, "disk_ops", sizeof(vl.type));
577 vl.type_instance[0] = 0;
578 if (volume->perf_data.flags & PERF_VOLUME_OPS) {
579 /* We might need the data even if it wasn't configured to calculate
580 the latency. Therefore we just skip the dispatch. */
581 DEBUG("%s/netapp-%s/disk_ops: %"PRIu64" %"PRIu64, host->name, volume->name, read_ops, write_ops);
582 plugin_dispatch_values(&vl);
584 if ((volume->perf_data.flags & PERF_VOLUME_LATENCY) && read_latency && write_latency) {
586 if (read_ops - volume->perf_data.last_read_ops) values[0].gauge = (read_latency - volume->perf_data.last_read_latency) * (timestamp - volume->perf_data.last_timestamp) / (read_ops - volume->perf_data.last_read_ops);
588 if (write_ops - volume->perf_data.last_write_ops) values[1].gauge = (write_latency - volume->perf_data.last_write_latency) * (timestamp - volume->perf_data.last_timestamp) / (write_ops - volume->perf_data.last_write_ops);
592 vl.interval = interval_g;
593 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
594 sstrncpy(vl.host, host->name, sizeof(vl.host));
595 sstrncpy(vl.plugin_instance, volume->name, sizeof(vl.plugin_instance));
596 sstrncpy(vl.type, "disk_latency", sizeof(vl.type));
597 vl.type_instance[0] = 0;
598 if (volume->perf_data.last_read_ops && volume->perf_data.last_write_ops) {
599 DEBUG("%s/netapp-%s/disk_latency: ro: %"PRIu64" lro: %"PRIu64" "
600 "rl: %"PRIu64" lrl: %"PRIu64" "
602 host->name, volume->name,
603 read_ops, volume->perf_data.last_read_ops,
604 read_latency, volume->perf_data.last_read_latency,
605 values[0].counter, values[1].counter);
606 plugin_dispatch_values(&vl);
608 volume->perf_data.last_timestamp = timestamp;
609 volume->perf_data.last_read_latency = read_latency;
610 volume->perf_data.last_read_ops = read_ops;
611 volume->perf_data.last_write_latency = write_latency;
612 volume->perf_data.last_write_ops = write_ops;
615 if ((volume->perf_data.flags & PERF_VOLUME_IO) && read_data && write_data) {
616 values[0].counter = read_data;
617 values[1].counter = write_data;
621 vl.interval = interval_g;
622 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
623 sstrncpy(vl.host, host->name, sizeof(vl.host));
624 sstrncpy(vl.plugin_instance, volume->name, sizeof(vl.plugin_instance));
625 sstrncpy(vl.type, "disk_octets", sizeof(vl.type));
626 vl.type_instance[0] = 0;
627 DEBUG("%s/netapp-%s/disk_octets: %"PRIu64" %"PRIu64, host->name, volume->name, read_data, write_data);
628 plugin_dispatch_values (&vl);
633 static void collect_perf_system_data(host_config_t *host, na_elem_t *out, void *data) {
634 uint64_t disk_read = 0, disk_written = 0, net_recv = 0, net_sent = 0, cpu_busy = 0, cpu_total = 0;
635 perf_system_data_t *perf = data;
636 const char *instance, *name;
640 value_list_t vl = VALUE_LIST_INIT;
642 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
643 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
644 instance = na_child_get_string(out, "name");
646 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
647 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
648 name = na_child_get_string(counter, "name");
649 if (!strcmp(name, "disk_data_read")) {
650 disk_read = na_child_get_uint64(counter, "value", 0) * 1024;
651 } else if (!strcmp(name, "disk_data_written")) {
652 disk_written = na_child_get_uint64(counter, "value", 0) * 1024;
653 } else if (!strcmp(name, "net_data_recv")) {
654 net_recv = na_child_get_uint64(counter, "value", 0) * 1024;
655 } else if (!strcmp(name, "net_data_sent")) {
656 net_sent = na_child_get_uint64(counter, "value", 0) * 1024;
657 } else if (!strcmp(name, "cpu_busy")) {
658 cpu_busy = na_child_get_uint64(counter, "value", 0);
659 } else if (!strcmp(name, "cpu_elapsed_time")) {
660 cpu_total = na_child_get_uint64(counter, "value", 0);
661 } else if ((perf->flags & PERF_SYSTEM_OPS) && strlen(name) > 4 && !strcmp(name + strlen(name) - 4, "_ops")) {
662 values[0].counter = na_child_get_uint64(counter, "value", 0);
663 if (!values[0].counter) continue;
667 vl.interval = interval_g;
668 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
669 sstrncpy(vl.host, host->name, sizeof(vl.host));
670 sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
671 sstrncpy(vl.type, "disk_ops_complex", sizeof(vl.type));
672 sstrncpy(vl.type_instance, name, sizeof(vl.plugin_instance));
673 DEBUG("%s/netapp-%s/disk_ops_complex-%s: %llu",
674 host->name, instance, name, values[0].counter);
675 plugin_dispatch_values (&vl);
678 if ((perf->flags & PERF_SYSTEM_DISK) && disk_read && disk_written) {
679 values[0].counter = disk_read;
680 values[1].counter = disk_written;
684 vl.interval = interval_g;
685 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
686 sstrncpy(vl.host, host->name, sizeof(vl.host));
687 sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
688 sstrncpy(vl.type, "disk_octets", sizeof(vl.type));
689 vl.type_instance[0] = 0;
690 DEBUG("%s/netapp-%s/disk_octets: %"PRIu64" %"PRIu64, host->name, instance, disk_read, disk_written);
691 plugin_dispatch_values (&vl);
693 if ((perf->flags & PERF_SYSTEM_NET) && net_recv && net_sent) {
694 values[0].counter = net_recv;
695 values[1].counter = net_sent;
699 vl.interval = interval_g;
700 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
701 sstrncpy(vl.host, host->name, sizeof(vl.host));
702 sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
703 sstrncpy(vl.type, "if_octets", sizeof(vl.type));
704 vl.type_instance[0] = 0;
705 DEBUG("%s/netapp-%s/if_octects: %"PRIu64" %"PRIu64, host->name, instance, net_recv, net_sent);
706 plugin_dispatch_values (&vl);
708 if ((perf->flags & PERF_SYSTEM_CPU) && cpu_busy && cpu_total) {
709 /* values[0].gauge = (double) (cpu_busy - perf->last_cpu_busy) / (cpu_total - perf->last_cpu_total) * 100; */
710 values[0].counter = cpu_busy / 10000;
714 vl.interval = interval_g;
715 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
716 sstrncpy(vl.host, host->name, sizeof(vl.host));
717 sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
718 sstrncpy(vl.type, "cpu", sizeof(vl.type));
719 sstrncpy(vl.type_instance, "system", sizeof(vl.plugin_instance));
720 /* if (perf->last_cpu_busy && perf->last_cpu_total) printf("CPU: busy: %lf - idle: %lf\n", values[0].gauge, 100.0 - values[0].gauge); */
721 /* if (perf->last_cpu_busy && perf->last_cpu_total) plugin_dispatch_values ("cpu", &vl); */
722 DEBUG("%s/netapp-%s/cpu: busy: %"PRIu64" - idle: %"PRIu64, host->name, instance, cpu_busy / 10000, cpu_total / 10000);
723 plugin_dispatch_values (&vl);
725 /* values[0].gauge = 100.0 - (double) (cpu_busy - perf->last_cpu_busy) / (cpu_total - perf->last_cpu_total) * 100; */
726 values[0].counter = (cpu_total - cpu_busy) / 10000;
730 vl.interval = interval_g;
731 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
732 sstrncpy(vl.host, host->name, sizeof(vl.host));
733 sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
734 sstrncpy(vl.type, "cpu", sizeof(vl.type));
735 sstrncpy(vl.type_instance, "idle", sizeof(vl.plugin_instance));
736 /* if (perf->last_cpu_busy && perf->last_cpu_total) plugin_dispatch_values ("cpu", &vl); */
737 plugin_dispatch_values (&vl);
739 perf->last_cpu_busy = cpu_busy;
740 perf->last_cpu_total = cpu_total;
748 service_config_t *service;
751 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
755 if (!na_startup(err, sizeof(err))) {
756 ERROR("netapp plugin: Error initializing netapp API: %s", err);
760 for (host = host_config; host; host = host->next) {
761 host->srv = na_server_open(host->host, 1, 1);
762 na_server_set_transport_type(host->srv, host->protocol, 0);
763 na_server_set_port(host->srv, host->port);
764 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
765 na_server_adminuser(host->srv, host->username, host->password);
766 na_server_set_timeout(host->srv, 5);
767 for (service = host->services; service; service = service->next) {
768 service->interval = host->interval * service->multiplier;
769 if (service->handler == collect_perf_system_data) {
770 service->query = na_elem_new("perf-object-get-instances");
771 na_child_add_string(service->query, "objectname", "system");
772 } else if (service->handler == collect_perf_volume_data) {
773 service->query = na_elem_new("perf-object-get-instances");
774 na_child_add_string(service->query, "objectname", "volume");
775 /* e = na_elem_new("instances");
776 na_child_add_string(e, "foo", "system");
777 na_child_add(root, e);*/
778 e = na_elem_new("counters");
779 na_child_add_string(e, "foo", "read_ops");
780 na_child_add_string(e, "foo", "write_ops");
781 na_child_add_string(e, "foo", "read_data");
782 na_child_add_string(e, "foo", "write_data");
783 na_child_add_string(e, "foo", "read_latency");
784 na_child_add_string(e, "foo", "write_latency");
785 na_child_add(service->query, e);
786 } else if (service->handler == collect_perf_wafl_data) {
787 service->query = na_elem_new("perf-object-get-instances");
788 na_child_add_string(service->query, "objectname", "wafl");
789 /* e = na_elem_new("instances");
790 na_child_add_string(e, "foo", "system");
791 na_child_add(root, e);*/
792 e = na_elem_new("counters");
793 na_child_add_string(e, "foo", "name_cache_hit");
794 na_child_add_string(e, "foo", "name_cache_miss");
795 na_child_add_string(e, "foo", "find_dir_hit");
796 na_child_add_string(e, "foo", "find_dir_miss");
797 na_child_add_string(e, "foo", "buf_hash_hit");
798 na_child_add_string(e, "foo", "buf_hash_miss");
799 na_child_add_string(e, "foo", "inode_cache_hit");
800 na_child_add_string(e, "foo", "inode_cache_miss");
801 /* na_child_add_string(e, "foo", "inode_eject_time"); */
802 /* na_child_add_string(e, "foo", "buf_eject_time"); */
803 na_child_add(service->query, e);
804 } else if (service->handler == collect_perf_disk_data) {
805 service->query = na_elem_new("perf-object-get-instances");
806 na_child_add_string(service->query, "objectname", "disk");
807 e = na_elem_new("counters");
808 na_child_add_string(e, "foo", "disk_busy");
809 na_child_add_string(e, "foo", "base_for_disk_busy");
810 na_child_add(service->query, e);
811 } else if (service->handler == collect_volume_data) {
812 service->query = na_elem_new("volume-list-info");
813 /* na_child_add_string(service->query, "objectname", "volume"); */
814 /* } else if (service->handler == collect_snapshot_data) { */
815 /* service->query = na_elem_new("snapshot-list-info"); */
822 static void set_global_perf_vol_flag(const host_config_t *host, uint32_t flag, int value) {
825 for (v = host->volumes; v; v = v->next) {
826 v->perf_data.flags &= ~flag;
827 if (value) v->perf_data.flags |= flag;
831 static void set_global_vol_flag(const host_config_t *host, uint32_t flag, int value) {
834 for (v = host->volumes; v; v = v->next) {
835 v->volume_data.flags &= ~flag;
836 if (value) v->volume_data.flags |= flag;
840 static void process_perf_volume_flag(host_config_t *host, perf_volume_data_t *perf_volume, const oconfig_item_t *item, uint32_t flag) {
843 for (n = 0; n < item->values_num; ++n) {
845 const char *name = item->values[n].value.string;
847 if (item->values[n].type != OCONFIG_TYPE_STRING) {
848 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolPerfData\" block for host %s", host->name);
851 if (name[0] == '+') {
853 } else if (name[0] == '-') {
858 perf_volume->flags &= ~flag;
859 if (!minus) perf_volume->flags |= flag;
860 set_global_perf_vol_flag(host, flag, !minus);
863 v = get_volume(host, name);
864 if (!v->perf_data.flags) {
865 v->perf_data.flags = perf_volume->flags;
866 v->perf_data.last_read_latency = v->perf_data.last_read_ops = 0;
867 v->perf_data.last_write_latency = v->perf_data.last_write_ops = 0;
869 v->perf_data.flags &= ~flag;
870 if (!minus) v->perf_data.flags |= flag;
874 static void process_volume_flag(host_config_t *host, volume_data_t *volume_data, const oconfig_item_t *item, uint32_t flag) {
877 for (n = 0; n < item->values_num; ++n) {
879 const char *name = item->values[n].value.string;
881 if (item->values[n].type != OCONFIG_TYPE_STRING) {
882 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolData\" block for host %s", host->name);
885 if (name[0] == '+') {
887 } else if (name[0] == '-') {
892 volume_data->flags &= ~flag;
893 if (!minus) volume_data->flags |= flag;
894 set_global_vol_flag(host, flag, !minus);
897 v = get_volume(host, name);
898 if (!v->volume_data.flags) v->volume_data.flags = volume_data->flags;
899 v->volume_data.flags &= ~flag;
900 if (!minus) v->volume_data.flags |= flag;
904 static void build_perf_vol_config(host_config_t *host, const oconfig_item_t *ci) {
905 int i, had_io = 0, had_ops = 0, had_latency = 0;
906 service_config_t *service;
907 perf_volume_data_t *perf_volume;
909 service = malloc(sizeof(*service));
911 service->handler = collect_perf_volume_data;
912 perf_volume = service->data = malloc(sizeof(*perf_volume));
913 perf_volume->flags = PERF_VOLUME_INIT;
914 service->next = host->services;
915 host->services = service;
916 for (i = 0; i < ci->children_num; ++i) {
917 oconfig_item_t *item = ci->children + i;
919 /* if (!item || !item->key || !*item->key) continue; */
920 if (!strcasecmp(item->key, "Multiplier")) {
921 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) {
922 WARNING("netapp plugin: \"Multiplier\" of host %s service GetVolPerfData needs exactly one positive integer argument.", host->name);
925 service->skip_countdown = service->multiplier = item->values[0].value.number;
926 } else if (!strcasecmp(item->key, "GetIO")) {
928 process_perf_volume_flag(host, perf_volume, item, PERF_VOLUME_IO);
929 } else if (!strcasecmp(item->key, "GetOps")) {
931 process_perf_volume_flag(host, perf_volume, item, PERF_VOLUME_OPS);
932 } else if (!strcasecmp(item->key, "GetLatency")) {
934 process_perf_volume_flag(host, perf_volume, item, PERF_VOLUME_LATENCY);
938 perf_volume->flags |= PERF_VOLUME_IO;
939 set_global_perf_vol_flag(host, PERF_VOLUME_IO, 1);
942 perf_volume->flags |= PERF_VOLUME_OPS;
943 set_global_perf_vol_flag(host, PERF_VOLUME_OPS, 1);
946 perf_volume->flags |= PERF_VOLUME_LATENCY;
947 set_global_perf_vol_flag(host, PERF_VOLUME_LATENCY, 1);
951 static void build_volume_config(host_config_t *host, oconfig_item_t *ci) {
953 service_config_t *service;
954 volume_data_t *volume_data;
956 service = malloc(sizeof(*service));
958 service->handler = collect_volume_data;
959 volume_data = service->data = malloc(sizeof(*volume_data));
960 volume_data->flags = VOLUME_INIT;
961 service->next = host->services;
962 host->services = service;
963 for (i = 0; i < ci->children_num; ++i) {
964 oconfig_item_t *item = ci->children + i;
966 /* if (!item || !item->key || !*item->key) continue; */
967 if (!strcasecmp(item->key, "Multiplier")) {
968 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) {
969 WARNING("netapp plugin: \"Multiplier\" of host %s service GetVolPerfData needs exactly one positive integer argument.", host->name);
972 service->skip_countdown = service->multiplier = item->values[0].value.number;
973 } else if (!strcasecmp(item->key, "GetDiskUtil")) {
975 process_volume_flag(host, volume_data, item, VOLUME_DF);
979 volume_data->flags |= VOLUME_DF;
980 set_global_vol_flag(host, VOLUME_DF, 1);
982 /* service = malloc(sizeof(*service));
984 service->handler = collect_snapshot_data;
985 service->data = volume_data;
986 service->next = temp->services;
987 temp->services = service;*/
990 static void build_perf_disk_config(host_config_t *temp, oconfig_item_t *ci) {
992 service_config_t *service;
993 perf_disk_data_t *perf_disk;
995 service = malloc(sizeof(*service));
997 service->handler = collect_perf_disk_data;
998 perf_disk = service->data = malloc(sizeof(*perf_disk));
999 perf_disk->flags = PERF_DISK_ALL;
1000 service->next = temp->services;
1001 temp->services = service;
1002 for (i = 0; i < ci->children_num; ++i) {
1003 oconfig_item_t *item = ci->children + i;
1005 /* if (!item || !item->key || !*item->key) continue; */
1006 if (!strcasecmp(item->key, "Multiplier")) {
1007 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) {
1008 WARNING("netapp plugin: \"Multiplier\" of host %s service GetWaflPerfData needs exactly one positive integer argument.", ci->values[0].value.string);
1011 service->skip_countdown = service->multiplier = item->values[0].value.number;
1012 } else if (!strcasecmp(item->key, "GetBusy")) {
1013 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
1014 WARNING("netapp plugin: \"GetBusy\" of host %s service GetDiskPerfData needs exactly one bool argument.", ci->values[0].value.string);
1017 perf_disk->flags = (perf_disk->flags & ~PERF_SYSTEM_CPU) | (item->values[0].value.boolean ? PERF_DISK_BUSIEST : 0);
1022 static void build_perf_wafl_config(host_config_t *temp, oconfig_item_t *ci) {
1024 service_config_t *service;
1025 perf_wafl_data_t *perf_wafl;
1027 service = malloc(sizeof(*service));
1029 service->handler = collect_perf_wafl_data;
1030 perf_wafl = service->data = malloc(sizeof(*perf_wafl));
1031 perf_wafl->flags = PERF_WAFL_ALL;
1032 perf_wafl->last_name_cache_hit = 0;
1033 perf_wafl->last_name_cache_miss = 0;
1034 perf_wafl->last_find_dir_hit = 0;
1035 perf_wafl->last_find_dir_miss = 0;
1036 perf_wafl->last_buf_hash_hit = 0;
1037 perf_wafl->last_buf_hash_miss = 0;
1038 perf_wafl->last_inode_cache_hit = 0;
1039 perf_wafl->last_inode_cache_miss = 0;
1040 service->next = temp->services;
1041 temp->services = service;
1042 for (i = 0; i < ci->children_num; ++i) {
1043 oconfig_item_t *item = ci->children + i;
1045 /* if (!item || !item->key || !*item->key) continue; */
1046 if (!strcasecmp(item->key, "Multiplier")) {
1047 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) {
1048 WARNING("netapp plugin: \"Multiplier\" of host %s service GetWaflPerfData needs exactly one positive integer argument.", ci->values[0].value.string);
1051 service->skip_countdown = service->multiplier = item->values[0].value.number;
1052 } else if (!strcasecmp(item->key, "GetNameCache")) {
1053 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
1054 WARNING("netapp plugin: \"GetNameCache\" of host %s service GetWaflPerfData needs exactly one bool argument.", ci->values[0].value.string);
1057 perf_wafl->flags = (perf_wafl->flags & ~PERF_WAFL_NAME_CACHE) | (item->values[0].value.boolean ? PERF_WAFL_NAME_CACHE : 0);
1058 } else if (!strcasecmp(item->key, "GetDirCache")) {
1059 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
1060 WARNING("netapp plugin: \"GetDirChache\" of host %s service GetWaflPerfData needs exactly one bool argument.", ci->values[0].value.string);
1063 perf_wafl->flags = (perf_wafl->flags & ~PERF_WAFL_DIR_CACHE) | (item->values[0].value.boolean ? PERF_WAFL_DIR_CACHE : 0);
1064 } else if (!strcasecmp(item->key, "GetBufCache")) {
1065 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
1066 WARNING("netapp plugin: \"GetBufCache\" of host %s service GetWaflPerfData needs exactly one bool argument.", ci->values[0].value.string);
1069 perf_wafl->flags = (perf_wafl->flags & ~PERF_WAFL_BUF_CACHE) | (item->values[0].value.boolean ? PERF_WAFL_BUF_CACHE : 0);
1070 } else if (!strcasecmp(item->key, "GetInodeCache")) {
1071 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
1072 WARNING("netapp plugin: \"GetInodeCache\" of host %s service GetWaflPerfData needs exactly one bool argument.", ci->values[0].value.string);
1075 perf_wafl->flags = (perf_wafl->flags & ~PERF_WAFL_INODE_CACHE) | (item->values[0].value.boolean ? PERF_WAFL_INODE_CACHE : 0);
1080 static void build_perf_sys_config(host_config_t *temp, oconfig_item_t *ci, const service_config_t *default_service) {
1082 service_config_t *service;
1083 perf_system_data_t *perf_system;
1085 service = malloc(sizeof(*service));
1086 *service = *default_service;
1087 service->handler = collect_perf_system_data;
1088 perf_system = service->data = malloc(sizeof(*perf_system));
1089 perf_system->flags = PERF_SYSTEM_ALL;
1090 perf_system->last_cpu_busy = 0;
1091 perf_system->last_cpu_total = 0;
1092 service->next = temp->services;
1093 temp->services = service;
1094 for (i = 0; i < ci->children_num; ++i) {
1095 oconfig_item_t *item = ci->children + i;
1097 /* if (!item || !item->key || !*item->key) continue; */
1098 if (!strcasecmp(item->key, "Multiplier")) {
1099 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) {
1100 WARNING("netapp plugin: \"Multiplier\" of host %s service GetSystemPerfData needs exactly one positive integer argument.", ci->values[0].value.string);
1103 service->skip_countdown = service->multiplier = item->values[0].value.number;
1104 } else if (!strcasecmp(item->key, "GetCPULoad")) {
1105 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
1106 WARNING("netapp plugin: \"GetCPULoad\" of host %s service GetSystemPerfData needs exactly one bool argument.", ci->values[0].value.string);
1109 perf_system->flags = (perf_system->flags & ~PERF_SYSTEM_CPU) | (item->values[0].value.boolean ? PERF_SYSTEM_CPU : 0);
1110 } else if (!strcasecmp(item->key, "GetInterfaces")) {
1111 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
1112 WARNING("netapp plugin: \"GetInterfaces\" of host %s service GetSystemPerfData needs exactly one bool argument.", ci->values[0].value.string);
1115 perf_system->flags = (perf_system->flags & ~PERF_SYSTEM_NET) | (item->values[0].value.boolean ? PERF_SYSTEM_NET : 0);
1116 } else if (!strcasecmp(item->key, "GetDiskOps")) {
1117 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
1118 WARNING("netapp plugin: \"GetDiskOps\" of host %s service GetSystemPerfData needs exactly one bool argument.", ci->values[0].value.string);
1121 perf_system->flags = (perf_system->flags & ~PERF_SYSTEM_OPS) | (item->values[0].value.boolean ? PERF_SYSTEM_OPS : 0);
1122 } else if (!strcasecmp(item->key, "GetDiskIO")) {
1123 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
1124 WARNING("netapp plugin: \"GetDiskIO\" of host %s service GetSystemPerfData needs exactly one bool argument.", ci->values[0].value.string);
1127 perf_system->flags = (perf_system->flags & ~PERF_SYSTEM_DISK) | (item->values[0].value.boolean ? PERF_SYSTEM_DISK : 0);
1132 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) {
1134 oconfig_item_t *item;
1135 host_config_t *host, *hc, temp = *default_host;
1136 service_config_t default_service = *def_def_service;
1138 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1139 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
1143 temp.name = ci->values[0].value.string;
1144 for (i = 0; i < ci->children_num; ++i) {
1145 item = ci->children + i;
1147 /* if (!item || !item->key || !*item->key) continue; */
1148 if (!strcasecmp(item->key, "Address")) {
1149 if ((item->values_num != 1) || (item->values[0].type != OCONFIG_TYPE_STRING)) {
1150 WARNING("netapp plugin: \"Name\" needs exactly one string argument. Ignoring host block \"%s\".", ci->values[0].value.string);
1153 temp.host = item->values[0].value.string;
1154 } else if (!strcasecmp(item->key, "Port")) {
1155 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)) {
1156 WARNING("netapp plugin: \"Port\" needs exactly one integer argument in the range of 1-65535. Ignoring host block \"%s\".", ci->values[0].value.string);
1159 temp.port = item->values[0].value.number;
1160 } else if (!strcasecmp(item->key, "Protocol")) {
1161 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"))) {
1162 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
1165 if (!strcasecmp(item->values[0].value.string, "http")) temp.protocol = NA_SERVER_TRANSPORT_HTTP;
1166 else temp.protocol = NA_SERVER_TRANSPORT_HTTPS;
1167 } else if (!strcasecmp(item->key, "Login")) {
1168 if ((item->values_num != 2) || (item->values[0].type != OCONFIG_TYPE_STRING) || (item->values[1].type != OCONFIG_TYPE_STRING)) {
1169 WARNING("netapp plugin: \"Login\" needs exactly two string arguments, username and password. Ignoring host block \"%s\".", ci->values[0].value.string);
1172 temp.username = item->values[0].value.string;
1173 temp.password = item->values[1].value.string;
1174 } else if (!strcasecmp(item->key, "Interval")) {
1175 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) {
1176 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
1179 temp.interval = item->values[0].value.number;
1180 } else if (!strcasecmp(item->key, "GetVolumePerfData")) {
1181 build_perf_vol_config(&temp, item);
1182 } else if (!strcasecmp(item->key, "GetSystemPerfData")) {
1183 build_perf_sys_config(&temp, item, &default_service);
1184 /* if ((item->values_num != 1) || (item->values[0].type != OCONFIG_TYPE_STRING)) {
1185 WARNING("netapp plugin: \"Collect\" needs exactly one string argument. Ignoring collect block for \"%s\".", ci->values[0].value.string);
1188 build_collect_config(&temp, item);*/
1189 } else if (!strcasecmp(item->key, "GetWaflPerfData")) {
1190 build_perf_wafl_config(&temp, item);
1191 } else if (!strcasecmp(item->key, "GetDiskPerfData")) {
1192 build_perf_disk_config(&temp, item);
1193 } else if (!strcasecmp(item->key, "GetVolumeData")) {
1194 build_volume_config(&temp, item);
1196 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".", item->key, ci->values[0].value.string);
1200 if (!temp.host) temp.host = temp.name;
1201 if (!temp.port) temp.port = temp.protocol == NA_SERVER_TRANSPORT_HTTP ? 80 : 443;
1202 if (!temp.username) {
1203 WARNING("netapp plugin: Please supply login information for host \"%s\". Ignoring host block.", temp.name);
1206 for (hc = host_config; hc; hc = hc->next) {
1207 if (!strcasecmp(hc->name, temp.name)) WARNING("netapp plugin: Duplicate definition of host \"%s\". This is probably a bad idea.", hc->name);
1209 host = malloc(sizeof(*host));
1211 host->name = strdup(temp.name);
1212 host->protocol = temp.protocol;
1213 host->host = strdup(temp.host);
1214 host->username = strdup(temp.username);
1215 host->password = strdup(temp.password);
1216 host->next = host_config;
1221 static int build_config (oconfig_item_t *ci) {
1223 oconfig_item_t *item;
1224 host_config_t default_host = HOST_INIT;
1225 service_config_t default_service = SERVICE_INIT;
1227 for (i = 0; i < ci->children_num; ++i) {
1228 item = ci->children + i;
1230 /* if (!item || !item->key || !*item->key) continue; */
1231 if (!strcasecmp(item->key, "Host")) {
1232 build_host_config(item, &default_host, &default_service);
1234 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
1240 static int netapp_read() {
1242 host_config_t *host;
1243 service_config_t *service;
1245 for (host = host_config; host; host = host->next) {
1246 for (service = host->services; service; service = service->next) {
1247 if (--service->skip_countdown > 0) continue;
1248 service->skip_countdown = service->multiplier;
1249 out = na_server_invoke_elem(host->srv, service->query);
1250 if (na_results_status(out) != NA_OK) {
1251 int netapp_errno = na_results_errno(out);
1252 ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
1254 if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
1255 /* Network problems. Just give up on all other services on this host. */
1260 service->handler(host, out, service->data);
1267 void module_register() {
1268 plugin_register_complex_config("netapp", build_config);
1269 plugin_register_init("netapp", config_init);
1270 plugin_register_read("netapp", netapp_read);
1273 /* vim: set sw=2 ts=2 noet fdm=marker : */