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
50 * \brief Persistent data for WAFL performence counters. (a.k.a. cache performence)
53 #define PERF_WAFL_NAME_CACHE 0x01
54 #define PERF_WAFL_DIR_CACHE 0x02
55 #define PERF_WAFL_BUF_CACHE 0x04
56 #define PERF_WAFL_INODE_CACHE 0x08
57 #define PERF_WAFL_ALL 0x0F
61 uint64_t last_name_cache_hit;
62 uint64_t last_name_cache_miss;
63 uint64_t last_find_dir_hit;
64 uint64_t last_find_dir_miss;
65 uint64_t last_buf_hash_hit;
66 uint64_t last_buf_hash_miss;
67 uint64_t last_inode_cache_hit;
68 uint64_t last_inode_cache_miss;
71 #define PERF_VOLUME_INIT 0x01
72 #define PERF_VOLUME_IO 0x02
73 #define PERF_VOLUME_OPS 0x03
74 #define PERF_VOLUME_LATENCY 0x08
75 #define PERF_VOLUME_ALL 0x0F
85 #define PERF_DISK_BUSIEST 0x01
86 #define PERF_DISK_ALL 0x01
94 time_t last_timestamp;
95 uint64_t last_read_latency;
96 uint64_t last_write_latency;
97 uint64_t last_read_ops;
98 uint64_t last_write_ops;
99 } per_volume_perf_data_t;
101 #define VOLUME_INIT 0x01
102 #define VOLUME_DF 0x02
103 #define VOLUME_SNAP 0x04
111 double last_disk_busy_percent;
112 uint64_t last_disk_busy;
113 uint64_t last_base_for_disk_busy;
114 } per_disk_perf_data_t;
116 typedef struct service_config_s {
118 service_handler_t *handler;
123 struct service_config_s *next;
126 #define SERVICE_INIT {0, 0, 1, 1, 0, 0, 0}
128 typedef struct volume_s {
130 per_volume_perf_data_t perf_data;
131 per_volume_data_t volume_data;
132 struct volume_s *next;
136 * \brief A disk in the netapp.
138 * A disk doesn't have any more information than its name atm.
139 * The name includes the "disk_" prefix.
142 typedef struct disk_s {
144 per_disk_perf_data_t perf_data;
148 #define DISK_INIT {0, {0, 0, 0, 0}, 0}
150 struct host_config_s {
153 na_server_transport_t protocol;
159 service_config_t *services;
162 struct host_config_s *next;
165 #define HOST_INIT {0, 0, NA_SERVER_TRANSPORT_HTTPS, 0, 0, 0, 0, 10, 0, 0, 0}
167 static host_config_t *host_config;
169 static volume_t *get_volume (host_config_t *host, const char *name) /* {{{ */
176 for (v = host->volumes; v; v = v->next) {
177 if (strcmp(v->name, name) == 0)
181 v = malloc(sizeof(*v));
184 memset (v, 0, sizeof (*v));
186 v->name = strdup(name);
187 if (v->name == NULL) {
192 v->next = host->volumes;
196 } /* }}} volume_t *get_volume */
198 static disk_t *get_disk(host_config_t *host, const char *name) /* {{{ */
200 disk_t *v, init = DISK_INIT;
205 for (v = host->disks; v; v = v->next) {
206 if (strcmp(v->name, name) == 0)
209 v = malloc(sizeof(*v));
214 v->name = strdup(name);
215 if (v->name == NULL) {
220 v->next = host->disks;
224 } /* }}} disk_t *get_disk */
226 static int submit_values (const char *host, /* {{{ */
227 const char *plugin_inst,
228 const char *type, const char *type_inst,
229 value_t *values, int values_len,
232 value_list_t vl = VALUE_LIST_INIT;
235 vl.values_len = values_len;
241 sstrncpy (vl.host, host, sizeof (vl.host));
243 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
244 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
245 if (plugin_inst != NULL)
246 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
247 sstrncpy (vl.type, type, sizeof (vl.type));
248 if (type_inst != NULL)
249 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
251 return (plugin_dispatch_values (&vl));
252 } /* }}} int submit_uint64 */
254 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
255 const char *type, const char *type_inst, counter_t val0, counter_t val1,
260 values[0].counter = val0;
261 values[1].counter = val1;
263 return (submit_values (host, plugin_inst, type, type_inst,
264 values, 2, timestamp));
265 } /* }}} int submit_two_counters */
267 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
268 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
274 return (submit_values (host, plugin_inst, type, type_inst,
276 } /* }}} int submit_counter */
278 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
279 const char *type, const char *type_inst, double d, time_t timestamp)
283 v.gauge = (gauge_t) d;
285 return (submit_values (host, plugin_inst, type, type_inst,
287 } /* }}} int submit_uint64 */
289 static int submit_cache_ratio (const char *host, /* {{{ */
290 const char *plugin_inst,
291 const char *type_inst,
295 uint64_t *old_misses,
300 if ((new_hits >= (*old_hits)) && (new_misses >= (*old_misses))) {
304 hits = new_hits - (*old_hits);
305 misses = new_misses - (*old_misses);
307 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
312 *old_hits = new_hits;
313 *old_misses = new_misses;
315 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
317 } /* }}} int submit_cache_ratio */
319 static void collect_perf_wafl_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
320 perf_wafl_data_t *wafl = data;
321 uint64_t name_cache_hit = 0, name_cache_miss = 0;
322 uint64_t find_dir_hit = 0, find_dir_miss = 0;
323 uint64_t buf_hash_hit = 0, buf_hash_miss = 0;
324 uint64_t inode_cache_hit = 0, inode_cache_miss = 0;
325 const char *plugin_inst;
329 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
330 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
331 plugin_inst = na_child_get_string(out, "name");
333 /* Iterate over all counters */
334 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
335 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
338 name = na_child_get_string(counter, "name");
339 if (!strcmp(name, "name_cache_hit"))
340 name_cache_hit = na_child_get_uint64(counter, "value", UINT64_MAX);
341 else if (!strcmp(name, "name_cache_miss"))
342 name_cache_miss = na_child_get_uint64(counter, "value", UINT64_MAX);
343 else if (!strcmp(name, "find_dir_hit"))
344 find_dir_hit = na_child_get_uint64(counter, "value", UINT64_MAX);
345 else if (!strcmp(name, "find_dir_miss"))
346 find_dir_miss = na_child_get_uint64(counter, "value", UINT64_MAX);
347 else if (!strcmp(name, "buf_hash_hit"))
348 buf_hash_hit = na_child_get_uint64(counter, "value", UINT64_MAX);
349 else if (!strcmp(name, "buf_hash_miss"))
350 buf_hash_miss = na_child_get_uint64(counter, "value", UINT64_MAX);
351 else if (!strcmp(name, "inode_cache_hit"))
352 inode_cache_hit = na_child_get_uint64(counter, "value", UINT64_MAX);
353 else if (!strcmp(name, "inode_cache_miss"))
354 inode_cache_miss = na_child_get_uint64(counter, "value", UINT64_MAX);
356 DEBUG("netapp plugin: Found unexpected child: %s", name);
359 /* Submit requested counters */
360 if ((wafl->flags & PERF_WAFL_NAME_CACHE)
361 && (name_cache_hit != UINT64_MAX) && (name_cache_miss != UINT64_MAX))
362 submit_cache_ratio (host->name, plugin_inst, "name_cache_hit",
363 name_cache_hit, name_cache_miss,
364 &wafl->last_name_cache_hit, &wafl->last_name_cache_miss,
367 if ((wafl->flags & PERF_WAFL_DIR_CACHE)
368 && (find_dir_hit != UINT64_MAX) && (find_dir_miss != UINT64_MAX))
369 submit_cache_ratio (host->name, plugin_inst, "find_dir_hit",
370 find_dir_hit, find_dir_miss,
371 &wafl->last_find_dir_hit, &wafl->last_find_dir_miss,
374 if ((wafl->flags & PERF_WAFL_BUF_CACHE)
375 && (buf_hash_hit != UINT64_MAX) && (buf_hash_miss != UINT64_MAX))
376 submit_cache_ratio (host->name, plugin_inst, "buf_hash_hit",
377 buf_hash_hit, buf_hash_miss,
378 &wafl->last_buf_hash_hit, &wafl->last_buf_hash_miss,
381 if ((wafl->flags & PERF_WAFL_INODE_CACHE)
382 && (inode_cache_hit != UINT64_MAX) && (inode_cache_miss != UINT64_MAX))
383 submit_cache_ratio (host->name, plugin_inst, "inode_cache_hit",
384 inode_cache_hit, inode_cache_miss,
385 &wafl->last_inode_cache_hit, &wafl->last_inode_cache_miss,
387 } /* }}} void collect_perf_wafl_data */
389 static void collect_perf_disk_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
390 perf_disk_data_t *perf = data;
393 na_elem_t *counter, *inst;
394 disk_t *disk, *worst_disk = 0;
396 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
397 out = na_elem_child(out, "instances");
399 /* Iterate over all children */
400 na_elem_iter_t inst_iter = na_child_iterator(out);
401 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
402 uint64_t disk_busy = 0;
403 uint64_t base_for_disk_busy = 0;
405 disk = get_disk(host, na_child_get_string(inst, "name"));
409 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
410 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
411 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
412 name = na_child_get_string(counter, "name");
416 if (strcmp(name, "disk_busy") == 0)
417 disk_busy = na_child_get_uint64(counter, "value", UINT64_MAX);
418 else if (strcmp(name, "base_for_disk_busy") == 0)
419 base_for_disk_busy = na_child_get_uint64(counter, "value", UINT64_MAX);
422 if ((disk_busy == UINT64_MAX) || (base_for_disk_busy == UINT64_MAX))
424 disk->perf_data.last_disk_busy = 0;
425 disk->perf_data.last_base_for_disk_busy = 0;
429 disk->perf_data.last_update = timestamp;
430 if ((disk_busy >= disk->perf_data.last_disk_busy)
431 && (base_for_disk_busy >= disk->perf_data.last_base_for_disk_busy))
433 uint64_t disk_busy_diff;
436 disk_busy_diff = disk_busy - disk->perf_data.last_disk_busy;
437 base_diff = base_for_disk_busy - disk->perf_data.last_base_for_disk_busy;
440 disk->perf_data.last_disk_busy_percent = NAN;
442 disk->perf_data.last_disk_busy_percent = 100.0
443 * ((gauge_t) disk_busy_diff) / ((gauge_t) base_diff);
447 disk->perf_data.last_disk_busy_percent = NAN;
450 disk->perf_data.last_disk_busy = disk_busy;
451 disk->perf_data.last_base_for_disk_busy = base_for_disk_busy;
453 if ((worst_disk == NULL)
454 || (worst_disk->perf_data.last_disk_busy_percent < disk->perf_data.last_disk_busy_percent))
458 if ((perf->flags & PERF_DISK_BUSIEST) && (worst_disk != NULL))
459 submit_double (host->name, "system", "percent", "disk_busy",
460 worst_disk->perf_data.last_disk_busy_percent, timestamp);
461 } /* }}} void collect_perf_disk_data */
463 static void collect_volume_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
466 volume_data_t *volume_data = data;
468 out = na_elem_child(out, "volumes");
469 na_elem_iter_t inst_iter = na_child_iterator(out);
470 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
471 uint64_t size_free = 0, size_used = 0, snap_reserved = 0;
474 const char *sis_state;
475 uint64_t sis_saved_reported;
478 volume = get_volume(host, na_child_get_string(inst, "name"));
482 if (!(volume->volume_data.flags & VOLUME_INIT))
483 volume->volume_data.flags = volume_data->flags;
485 if (!(volume->volume_data.flags & VOLUME_DF))
488 /* 2^4 exa-bytes? This will take a while ;) */
489 size_free = na_child_get_uint64(inst, "size-available", UINT64_MAX);
490 if (size_free != UINT64_MAX)
491 submit_double (host->name, volume->name, "df_complex", "used",
492 (double) size_used, /* time = */ 0);
494 size_used = na_child_get_uint64(inst, "size-used", UINT64_MAX);
495 if (size_free != UINT64_MAX)
496 submit_double (host->name, volume->name, "df_complex", "free",
497 (double) size_free, /* time = */ 0);
499 snap_reserved = na_child_get_uint64(inst, "snapshot-blocks-reserved", UINT64_MAX);
500 if (snap_reserved != UINT64_MAX)
501 /* 1 block == 1024 bytes as per API docs */
502 submit_double (host->name, volume->name, "df_complex", "snap_reserved",
503 (double) (1024 * snap_reserved), /* time = */ 0);
505 sis = na_elem_child(inst, "sis");
509 sis_state = na_child_get_string(sis, "state");
510 if ((sis_state == NULL)
511 || (strcmp ("enabled", sis_state) != 0))
514 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
515 if (sis_saved_reported == UINT64_MAX)
518 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
519 if ((sis_saved_reported >> 32) != 0) {
520 /* In case they ever fix this bug. */
521 sis_saved = sis_saved_reported;
523 uint64_t sis_saved_percent;
524 uint64_t sis_saved_guess;
525 uint64_t overflow_guess;
526 uint64_t guess1, guess2, guess3;
528 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
529 if (sis_saved_percent > 100)
532 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
533 * will hopefully be fixed in later versions. To work around the bug, try
534 * to figure out how often the 32bit integer wrapped around by using the
535 * "percentage-saved" value. Because the percentage is in the range
536 * [0-100], this should work as long as the saved space does not exceed
538 /* percentage-saved = size-saved / (size-saved + size-used) */
539 if (sis_saved_percent < 100)
540 sis_saved_guess = size_used * sis_saved_percent / (100 - sis_saved_percent);
542 sis_saved_guess = size_used;
544 overflow_guess = sis_saved_guess >> 32;
545 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
546 guess2 = (overflow_guess << 32) + sis_saved_reported;
547 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
549 if (sis_saved_guess < guess2) {
550 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
555 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
560 } /* end of 32-bit workaround */
562 submit_double (host->name, volume->name, "df_complex", "sis_saved",
563 (double) sis_saved, /* time = */ 0);
565 } /* }}} void collect_volume_data */
567 static void collect_perf_volume_data(host_config_t *host, na_elem_t *out, void *data) {
568 perf_volume_data_t *perf = data;
571 na_elem_t *counter, *inst;
574 value_list_t vl = VALUE_LIST_INIT;
576 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
577 out = na_elem_child(out, "instances");
578 na_elem_iter_t inst_iter = na_child_iterator(out);
579 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
580 uint64_t read_data = 0, write_data = 0, read_ops = 0, write_ops = 0, read_latency = 0, write_latency = 0;
582 volume = get_volume(host, na_child_get_string(inst, "name"));
583 if (!volume->perf_data.flags) {
584 volume->perf_data.flags = perf->flags;
585 volume->perf_data.last_read_latency = volume->perf_data.last_read_ops = 0;
586 volume->perf_data.last_write_latency = volume->perf_data.last_write_ops = 0;
588 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
589 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
590 name = na_child_get_string(counter, "name");
591 if (!strcmp(name, "read_ops")) {
592 read_ops = na_child_get_uint64(counter, "value", 0);
593 } else if (!strcmp(name, "write_ops")) {
594 write_ops = na_child_get_uint64(counter, "value", 0);
595 } else if (!strcmp(name, "read_data")) {
596 read_data = na_child_get_uint64(counter, "value", 0);
597 } else if (!strcmp(name, "write_data")) {
598 write_data = na_child_get_uint64(counter, "value", 0);
599 } else if (!strcmp(name, "read_latency")) {
600 read_latency = na_child_get_uint64(counter, "value", 0);
601 } else if (!strcmp(name, "write_latency")) {
602 write_latency = na_child_get_uint64(counter, "value", 0);
605 if (read_ops && write_ops) {
606 values[0].counter = read_ops;
607 values[1].counter = write_ops;
611 vl.interval = interval_g;
612 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
613 sstrncpy(vl.host, host->name, sizeof(vl.host));
614 sstrncpy(vl.plugin_instance, volume->name, sizeof(vl.plugin_instance));
615 sstrncpy(vl.type, "disk_ops", sizeof(vl.type));
616 vl.type_instance[0] = 0;
617 if (volume->perf_data.flags & PERF_VOLUME_OPS) {
618 /* We might need the data even if it wasn't configured to calculate
619 the latency. Therefore we just skip the dispatch. */
620 DEBUG("%s/netapp-%s/disk_ops: %"PRIu64" %"PRIu64, host->name, volume->name, read_ops, write_ops);
621 plugin_dispatch_values(&vl);
623 if ((volume->perf_data.flags & PERF_VOLUME_LATENCY) && read_latency && write_latency) {
625 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);
627 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);
631 vl.interval = interval_g;
632 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
633 sstrncpy(vl.host, host->name, sizeof(vl.host));
634 sstrncpy(vl.plugin_instance, volume->name, sizeof(vl.plugin_instance));
635 sstrncpy(vl.type, "disk_latency", sizeof(vl.type));
636 vl.type_instance[0] = 0;
637 if (volume->perf_data.last_read_ops && volume->perf_data.last_write_ops) {
638 DEBUG("%s/netapp-%s/disk_latency: ro: %"PRIu64" lro: %"PRIu64" "
639 "rl: %"PRIu64" lrl: %"PRIu64" "
641 host->name, volume->name,
642 read_ops, volume->perf_data.last_read_ops,
643 read_latency, volume->perf_data.last_read_latency,
644 values[0].counter, values[1].counter);
645 plugin_dispatch_values(&vl);
647 volume->perf_data.last_timestamp = timestamp;
648 volume->perf_data.last_read_latency = read_latency;
649 volume->perf_data.last_read_ops = read_ops;
650 volume->perf_data.last_write_latency = write_latency;
651 volume->perf_data.last_write_ops = write_ops;
654 if ((volume->perf_data.flags & PERF_VOLUME_IO) && read_data && write_data) {
655 values[0].counter = read_data;
656 values[1].counter = write_data;
660 vl.interval = interval_g;
661 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
662 sstrncpy(vl.host, host->name, sizeof(vl.host));
663 sstrncpy(vl.plugin_instance, volume->name, sizeof(vl.plugin_instance));
664 sstrncpy(vl.type, "disk_octets", sizeof(vl.type));
665 vl.type_instance[0] = 0;
666 DEBUG("%s/netapp-%s/disk_octets: %"PRIu64" %"PRIu64, host->name, volume->name, read_data, write_data);
667 plugin_dispatch_values (&vl);
672 static void collect_perf_system_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
673 counter_t disk_read = 0, disk_written = 0;
674 counter_t net_recv = 0, net_sent = 0;
675 counter_t cpu_busy = 0, cpu_total = 0;
676 unsigned int counter_flags = 0;
678 perf_system_data_t *perf = data;
679 const char *instance;
683 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
684 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
685 instance = na_child_get_string(out, "name");
687 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
688 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
692 name = na_child_get_string(counter, "name");
696 value = na_child_get_uint64(counter, "value", UINT64_MAX);
697 if (value == UINT64_MAX)
700 if (!strcmp(name, "disk_data_read")) {
701 disk_read = (counter_t) (value * 1024);
702 counter_flags |= 0x01;
703 } else if (!strcmp(name, "disk_data_written")) {
704 disk_written = (counter_t) (value * 1024);
705 counter_flags |= 0x02;
706 } else if (!strcmp(name, "net_data_recv")) {
707 net_recv = (counter_t) (value * 1024);
708 counter_flags |= 0x04;
709 } else if (!strcmp(name, "net_data_sent")) {
710 net_sent = (counter_t) (value * 1024);
711 counter_flags |= 0x08;
712 } else if (!strcmp(name, "cpu_busy")) {
713 cpu_busy = (counter_t) value;
714 counter_flags |= 0x10;
715 } else if (!strcmp(name, "cpu_elapsed_time")) {
716 cpu_total = (counter_t) value;
717 counter_flags |= 0x20;
718 } else if ((perf->flags & PERF_SYSTEM_OPS)
719 && (strlen(name) > 4)
720 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
721 submit_counter (host->name, instance, "disk_ops_complex", name,
722 (counter_t) value, timestamp);
724 } /* for (counter) */
726 if ((perf->flags & PERF_SYSTEM_DISK)
727 && ((counter_flags & 0x03) == 0x03))
728 submit_two_counters (host->name, instance, "disk_octets", NULL,
729 disk_read, disk_written, timestamp);
731 if ((perf->flags & PERF_SYSTEM_NET)
732 && ((counter_flags & 0x0c) == 0x0c))
733 submit_two_counters (host->name, instance, "if_octets", NULL,
734 net_recv, net_sent, timestamp);
736 if ((perf->flags & PERF_SYSTEM_CPU)
737 && ((counter_flags & 0x30) == 0x30)) {
738 submit_counter (host->name, instance, "cpu", "system",
739 cpu_busy, timestamp);
740 submit_counter (host->name, instance, "cpu", "idle",
741 cpu_total - cpu_busy, timestamp);
743 } /* }}} void collect_perf_system_data */
745 static int config_init(void) { /* {{{ */
749 service_config_t *service;
752 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
756 if (!na_startup(err, sizeof(err))) {
757 ERROR("netapp plugin: Error initializing netapp API: %s", err);
761 for (host = host_config; host; host = host->next) {
762 host->srv = na_server_open(host->host, 1, 1);
763 na_server_set_transport_type(host->srv, host->protocol, 0);
764 na_server_set_port(host->srv, host->port);
765 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
766 na_server_adminuser(host->srv, host->username, host->password);
767 na_server_set_timeout(host->srv, 5);
768 for (service = host->services; service; service = service->next) {
769 service->interval = host->interval * service->multiplier;
770 if (service->handler == collect_perf_system_data) {
771 service->query = na_elem_new("perf-object-get-instances");
772 na_child_add_string(service->query, "objectname", "system");
773 } else if (service->handler == collect_perf_volume_data) {
774 service->query = na_elem_new("perf-object-get-instances");
775 na_child_add_string(service->query, "objectname", "volume");
776 /* e = na_elem_new("instances");
777 na_child_add_string(e, "foo", "system");
778 na_child_add(root, e);*/
779 e = na_elem_new("counters");
780 na_child_add_string(e, "foo", "read_ops");
781 na_child_add_string(e, "foo", "write_ops");
782 na_child_add_string(e, "foo", "read_data");
783 na_child_add_string(e, "foo", "write_data");
784 na_child_add_string(e, "foo", "read_latency");
785 na_child_add_string(e, "foo", "write_latency");
786 na_child_add(service->query, e);
787 } else if (service->handler == collect_perf_wafl_data) {
788 service->query = na_elem_new("perf-object-get-instances");
789 na_child_add_string(service->query, "objectname", "wafl");
790 /* e = na_elem_new("instances");
791 na_child_add_string(e, "foo", "system");
792 na_child_add(root, e);*/
793 e = na_elem_new("counters");
794 na_child_add_string(e, "foo", "name_cache_hit");
795 na_child_add_string(e, "foo", "name_cache_miss");
796 na_child_add_string(e, "foo", "find_dir_hit");
797 na_child_add_string(e, "foo", "find_dir_miss");
798 na_child_add_string(e, "foo", "buf_hash_hit");
799 na_child_add_string(e, "foo", "buf_hash_miss");
800 na_child_add_string(e, "foo", "inode_cache_hit");
801 na_child_add_string(e, "foo", "inode_cache_miss");
802 /* na_child_add_string(e, "foo", "inode_eject_time"); */
803 /* na_child_add_string(e, "foo", "buf_eject_time"); */
804 na_child_add(service->query, e);
805 } else if (service->handler == collect_perf_disk_data) {
806 service->query = na_elem_new("perf-object-get-instances");
807 na_child_add_string(service->query, "objectname", "disk");
808 e = na_elem_new("counters");
809 na_child_add_string(e, "foo", "disk_busy");
810 na_child_add_string(e, "foo", "base_for_disk_busy");
811 na_child_add(service->query, e);
812 } else if (service->handler == collect_volume_data) {
813 service->query = na_elem_new("volume-list-info");
814 /* na_child_add_string(service->query, "objectname", "volume"); */
815 /* } else if (service->handler == collect_snapshot_data) { */
816 /* service->query = na_elem_new("snapshot-list-info"); */
821 } /* }}} int config_init */
823 static int config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
824 uint32_t *flags, uint32_t flag)
826 if ((ci == NULL) || (flags == NULL))
829 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
831 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
836 if (ci->values[0].value.boolean)
842 } /* }}} int config_bool_to_flag */
844 static int config_get_multiplier (const oconfig_item_t *ci, /* {{{ */
845 service_config_t *service)
849 if ((ci == NULL) || (service == NULL))
852 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
854 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
858 tmp = (int) (ci->values[0].value.number + .5);
861 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
865 service->multiplier = tmp;
866 service->skip_countdown = tmp;
869 } /* }}} int config_get_multiplier */
871 static void set_global_perf_vol_flag(const host_config_t *host, /* {{{ */
872 uint32_t flag, _Bool set)
876 for (v = host->volumes; v; v = v->next) {
878 v->perf_data.flags |= flag;
880 v->perf_data.flags &= ~flag;
882 } /* }}} void set_global_perf_vol_flag */
884 static void set_global_vol_flag(const host_config_t *host, /* {{{ */
885 uint32_t flag, _Bool set) {
888 for (v = host->volumes; v; v = v->next) {
890 v->volume_data.flags |= flag;
892 v->volume_data.flags &= ~flag;
894 } /* }}} void set_global_vol_flag */
896 static void process_perf_volume_flag (host_config_t *host, /* {{{ */
897 perf_volume_data_t *perf_volume, const oconfig_item_t *item,
902 for (i = 0; i < item->values_num; ++i) {
907 if (item->values[i].type != OCONFIG_TYPE_STRING) {
908 WARNING("netapp plugin: Ignoring non-string argument in "
909 "\"GetVolPerfData\" block for host %s", host->name);
913 name = item->values[i].value.string;
914 if (name[0] == '+') {
917 } else if (name[0] == '-') {
924 perf_volume->flags |= flag;
926 perf_volume->flags &= ~flag;
928 set_global_perf_vol_flag(host, flag, set);
932 v = get_volume (host, name);
936 if (!v->perf_data.flags) {
937 v->perf_data.flags = perf_volume->flags;
941 v->perf_data.flags |= flag;
943 v->perf_data.flags &= ~flag;
944 } /* for (i = 0 .. item->values_num) */
945 } /* }}} void process_perf_volume_flag */
947 static void process_volume_flag (host_config_t *host, /* {{{ */
948 volume_data_t *volume_data, const oconfig_item_t *item, uint32_t flag)
952 for (i = 0; i < item->values_num; ++i) {
957 if (item->values[i].type != OCONFIG_TYPE_STRING) {
958 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolData\""
959 "block for host %s", host->name);
963 name = item->values[i].value.string;
964 if (name[0] == '+') {
967 } else if (name[0] == '-') {
974 volume_data->flags |= flag;
976 volume_data->flags &= ~flag;
978 set_global_vol_flag(host, flag, set);
982 v = get_volume(host, name);
986 if (!v->volume_data.flags)
987 v->volume_data.flags = volume_data->flags;
990 v->volume_data.flags |= flag;
992 v->volume_data.flags &= ~flag;
994 } /* }}} void process_volume_flag */
996 static void build_perf_vol_config(host_config_t *host, const oconfig_item_t *ci) {
997 int i, had_io = 0, had_ops = 0, had_latency = 0;
998 service_config_t *service;
999 perf_volume_data_t *perf_volume;
1001 service = malloc(sizeof(*service));
1003 service->handler = collect_perf_volume_data;
1004 perf_volume = service->data = malloc(sizeof(*perf_volume));
1005 perf_volume->flags = PERF_VOLUME_INIT;
1006 service->next = host->services;
1007 host->services = service;
1008 for (i = 0; i < ci->children_num; ++i) {
1009 oconfig_item_t *item = ci->children + i;
1011 /* if (!item || !item->key || !*item->key) continue; */
1012 if (!strcasecmp(item->key, "Multiplier")) {
1013 config_get_multiplier (item, service);
1014 } else if (!strcasecmp(item->key, "GetIO")) {
1016 process_perf_volume_flag(host, perf_volume, item, PERF_VOLUME_IO);
1017 } else if (!strcasecmp(item->key, "GetOps")) {
1019 process_perf_volume_flag(host, perf_volume, item, PERF_VOLUME_OPS);
1020 } else if (!strcasecmp(item->key, "GetLatency")) {
1022 process_perf_volume_flag(host, perf_volume, item, PERF_VOLUME_LATENCY);
1026 perf_volume->flags |= PERF_VOLUME_IO;
1027 set_global_perf_vol_flag(host, PERF_VOLUME_IO, /* set = */ true);
1030 perf_volume->flags |= PERF_VOLUME_OPS;
1031 set_global_perf_vol_flag(host, PERF_VOLUME_OPS, /* set = */ true);
1034 perf_volume->flags |= PERF_VOLUME_LATENCY;
1035 set_global_perf_vol_flag(host, PERF_VOLUME_LATENCY, /* set = */ true);
1039 static void build_volume_config(host_config_t *host, oconfig_item_t *ci) {
1041 service_config_t *service;
1042 volume_data_t *volume_data;
1044 service = malloc(sizeof(*service));
1046 service->handler = collect_volume_data;
1047 volume_data = service->data = malloc(sizeof(*volume_data));
1048 volume_data->flags = VOLUME_INIT;
1049 service->next = host->services;
1050 host->services = service;
1051 for (i = 0; i < ci->children_num; ++i) {
1052 oconfig_item_t *item = ci->children + i;
1054 /* if (!item || !item->key || !*item->key) continue; */
1055 if (!strcasecmp(item->key, "Multiplier")) {
1056 config_get_multiplier (item, service);
1057 } else if (!strcasecmp(item->key, "GetDiskUtil")) {
1059 process_volume_flag(host, volume_data, item, VOLUME_DF);
1063 volume_data->flags |= VOLUME_DF;
1064 set_global_vol_flag(host, VOLUME_DF, /* set = */ true);
1066 /* service = malloc(sizeof(*service));
1068 service->handler = collect_snapshot_data;
1069 service->data = volume_data;
1070 service->next = temp->services;
1071 temp->services = service;*/
1074 static void build_perf_disk_config(host_config_t *temp, oconfig_item_t *ci) {
1076 service_config_t *service;
1077 perf_disk_data_t *perf_disk;
1079 service = malloc(sizeof(*service));
1081 service->handler = collect_perf_disk_data;
1082 perf_disk = service->data = malloc(sizeof(*perf_disk));
1083 perf_disk->flags = PERF_DISK_ALL;
1084 service->next = temp->services;
1085 temp->services = service;
1086 for (i = 0; i < ci->children_num; ++i) {
1087 oconfig_item_t *item = ci->children + i;
1089 /* if (!item || !item->key || !*item->key) continue; */
1090 if (!strcasecmp(item->key, "Multiplier")) {
1091 config_get_multiplier (item, service);
1092 } else if (!strcasecmp(item->key, "GetBusy")) {
1093 config_bool_to_flag (item, &perf_disk->flags, PERF_SYSTEM_CPU);
1098 static void build_perf_wafl_config(host_config_t *temp, oconfig_item_t *ci) {
1100 service_config_t *service;
1101 perf_wafl_data_t *perf_wafl;
1103 service = malloc(sizeof(*service));
1105 service->handler = collect_perf_wafl_data;
1106 perf_wafl = service->data = malloc(sizeof(*perf_wafl));
1107 perf_wafl->flags = PERF_WAFL_ALL;
1108 perf_wafl->last_name_cache_hit = 0;
1109 perf_wafl->last_name_cache_miss = 0;
1110 perf_wafl->last_find_dir_hit = 0;
1111 perf_wafl->last_find_dir_miss = 0;
1112 perf_wafl->last_buf_hash_hit = 0;
1113 perf_wafl->last_buf_hash_miss = 0;
1114 perf_wafl->last_inode_cache_hit = 0;
1115 perf_wafl->last_inode_cache_miss = 0;
1116 service->next = temp->services;
1117 temp->services = service;
1118 for (i = 0; i < ci->children_num; ++i) {
1119 oconfig_item_t *item = ci->children + i;
1121 /* if (!item || !item->key || !*item->key) continue; */
1122 if (!strcasecmp(item->key, "Multiplier")) {
1123 config_get_multiplier (item, service);
1124 } else if (!strcasecmp(item->key, "GetNameCache")) {
1125 config_bool_to_flag (item, &perf_wafl->flags, PERF_WAFL_NAME_CACHE);
1126 } else if (!strcasecmp(item->key, "GetDirCache")) {
1127 config_bool_to_flag (item, &perf_wafl->flags, PERF_WAFL_DIR_CACHE);
1128 } else if (!strcasecmp(item->key, "GetBufCache")) {
1129 config_bool_to_flag (item, &perf_wafl->flags, PERF_WAFL_BUF_CACHE);
1130 } else if (!strcasecmp(item->key, "GetInodeCache")) {
1131 config_bool_to_flag (item, &perf_wafl->flags, PERF_WAFL_INODE_CACHE);
1133 WARNING ("netapp plugin: The %s config option is not allowed within "
1134 "`GetWaflPerfData' blocks.", item->key);
1139 static int build_perf_sys_config (host_config_t *host, /* {{{ */
1140 oconfig_item_t *ci, const service_config_t *default_service)
1143 service_config_t *service;
1144 perf_system_data_t *perf_system;
1146 service = malloc(sizeof(*service));
1147 if (service == NULL)
1149 memset (service, 0, sizeof (*service));
1150 *service = *default_service;
1151 service->handler = collect_perf_system_data;
1153 perf_system = malloc(sizeof(*perf_system));
1154 if (perf_system == NULL) {
1158 memset (perf_system, 0, sizeof (*perf_system));
1159 perf_system->flags = PERF_SYSTEM_ALL;
1160 service->data = perf_system;
1162 for (i = 0; i < ci->children_num; ++i) {
1163 oconfig_item_t *item = ci->children + i;
1165 if (!strcasecmp(item->key, "Multiplier")) {
1166 config_get_multiplier (item, service);
1167 } else if (!strcasecmp(item->key, "GetCPULoad")) {
1168 config_bool_to_flag (item, &perf_system->flags, PERF_SYSTEM_CPU);
1169 } else if (!strcasecmp(item->key, "GetInterfaces")) {
1170 config_bool_to_flag (item, &perf_system->flags, PERF_SYSTEM_NET);
1171 } else if (!strcasecmp(item->key, "GetDiskOps")) {
1172 config_bool_to_flag (item, &perf_system->flags, PERF_SYSTEM_OPS);
1173 } else if (!strcasecmp(item->key, "GetDiskIO")) {
1174 config_bool_to_flag (item, &perf_system->flags, PERF_SYSTEM_DISK);
1176 WARNING ("netapp plugin: The %s config option is not allowed within "
1177 "`GetSystemPerfData' blocks.", item->key);
1181 service->next = host->services;
1182 host->services = service;
1185 } /* }}} int build_perf_sys_config */
1187 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) {
1189 oconfig_item_t *item;
1190 host_config_t *host, *hc, temp = *default_host;
1191 service_config_t default_service = *def_def_service;
1193 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1194 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
1198 temp.name = ci->values[0].value.string;
1199 for (i = 0; i < ci->children_num; ++i) {
1200 item = ci->children + i;
1202 /* if (!item || !item->key || !*item->key) continue; */
1203 if (!strcasecmp(item->key, "Address")) {
1204 if ((item->values_num != 1) || (item->values[0].type != OCONFIG_TYPE_STRING)) {
1205 WARNING("netapp plugin: \"Name\" needs exactly one string argument. Ignoring host block \"%s\".", ci->values[0].value.string);
1208 temp.host = item->values[0].value.string;
1209 } else if (!strcasecmp(item->key, "Port")) {
1210 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)) {
1211 WARNING("netapp plugin: \"Port\" needs exactly one integer argument in the range of 1-65535. Ignoring host block \"%s\".", ci->values[0].value.string);
1214 temp.port = item->values[0].value.number;
1215 } else if (!strcasecmp(item->key, "Protocol")) {
1216 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"))) {
1217 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
1220 if (!strcasecmp(item->values[0].value.string, "http")) temp.protocol = NA_SERVER_TRANSPORT_HTTP;
1221 else temp.protocol = NA_SERVER_TRANSPORT_HTTPS;
1222 } else if (!strcasecmp(item->key, "Login")) {
1223 if ((item->values_num != 2) || (item->values[0].type != OCONFIG_TYPE_STRING) || (item->values[1].type != OCONFIG_TYPE_STRING)) {
1224 WARNING("netapp plugin: \"Login\" needs exactly two string arguments, username and password. Ignoring host block \"%s\".", ci->values[0].value.string);
1227 temp.username = item->values[0].value.string;
1228 temp.password = item->values[1].value.string;
1229 } else if (!strcasecmp(item->key, "Interval")) {
1230 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) {
1231 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
1234 temp.interval = item->values[0].value.number;
1235 } else if (!strcasecmp(item->key, "GetVolumePerfData")) {
1236 build_perf_vol_config(&temp, item);
1237 } else if (!strcasecmp(item->key, "GetSystemPerfData")) {
1238 build_perf_sys_config(&temp, item, &default_service);
1239 /* if ((item->values_num != 1) || (item->values[0].type != OCONFIG_TYPE_STRING)) {
1240 WARNING("netapp plugin: \"Collect\" needs exactly one string argument. Ignoring collect block for \"%s\".", ci->values[0].value.string);
1243 build_collect_config(&temp, item);*/
1244 } else if (!strcasecmp(item->key, "GetWaflPerfData")) {
1245 build_perf_wafl_config(&temp, item);
1246 } else if (!strcasecmp(item->key, "GetDiskPerfData")) {
1247 build_perf_disk_config(&temp, item);
1248 } else if (!strcasecmp(item->key, "GetVolumeData")) {
1249 build_volume_config(&temp, item);
1251 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".", item->key, ci->values[0].value.string);
1255 if (!temp.host) temp.host = temp.name;
1256 if (!temp.port) temp.port = temp.protocol == NA_SERVER_TRANSPORT_HTTP ? 80 : 443;
1257 if (!temp.username) {
1258 WARNING("netapp plugin: Please supply login information for host \"%s\". Ignoring host block.", temp.name);
1261 for (hc = host_config; hc; hc = hc->next) {
1262 if (!strcasecmp(hc->name, temp.name)) WARNING("netapp plugin: Duplicate definition of host \"%s\". This is probably a bad idea.", hc->name);
1264 host = malloc(sizeof(*host));
1266 host->name = strdup(temp.name);
1267 host->protocol = temp.protocol;
1268 host->host = strdup(temp.host);
1269 host->username = strdup(temp.username);
1270 host->password = strdup(temp.password);
1271 host->next = host_config;
1276 static int build_config (oconfig_item_t *ci) {
1278 oconfig_item_t *item;
1279 host_config_t default_host = HOST_INIT;
1280 service_config_t default_service = SERVICE_INIT;
1282 for (i = 0; i < ci->children_num; ++i) {
1283 item = ci->children + i;
1285 /* if (!item || !item->key || !*item->key) continue; */
1286 if (!strcasecmp(item->key, "Host")) {
1287 build_host_config(item, &default_host, &default_service);
1289 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
1295 static int netapp_read() {
1297 host_config_t *host;
1298 service_config_t *service;
1300 for (host = host_config; host; host = host->next) {
1301 for (service = host->services; service; service = service->next) {
1302 if (--service->skip_countdown > 0) continue;
1303 service->skip_countdown = service->multiplier;
1304 out = na_server_invoke_elem(host->srv, service->query);
1305 if (na_results_status(out) != NA_OK) {
1306 int netapp_errno = na_results_errno(out);
1307 ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
1309 if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
1310 /* Network problems. Just give up on all other services on this host. */
1315 service->handler(host, out, service->data);
1322 void module_register() {
1323 plugin_register_complex_config("netapp", build_config);
1324 plugin_register_init("netapp", config_init);
1325 plugin_register_read("netapp", netapp_read);
1328 /* vim: set sw=2 ts=2 noet fdm=marker : */