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 void set_global_perf_vol_flag(const host_config_t *host, /* {{{ */
845 uint32_t flag, _Bool set)
849 for (v = host->volumes; v; v = v->next) {
851 v->perf_data.flags |= flag;
853 v->perf_data.flags &= ~flag;
855 } /* }}} void set_global_perf_vol_flag */
857 static void set_global_vol_flag(const host_config_t *host, /* {{{ */
858 uint32_t flag, _Bool set) {
861 for (v = host->volumes; v; v = v->next) {
863 v->volume_data.flags |= flag;
865 v->volume_data.flags &= ~flag;
867 } /* }}} void set_global_vol_flag */
869 static void process_perf_volume_flag (host_config_t *host, /* {{{ */
870 perf_volume_data_t *perf_volume, const oconfig_item_t *item,
875 for (i = 0; i < item->values_num; ++i) {
880 if (item->values[i].type != OCONFIG_TYPE_STRING) {
881 WARNING("netapp plugin: Ignoring non-string argument in "
882 "\"GetVolPerfData\" block for host %s", host->name);
886 name = item->values[i].value.string;
887 if (name[0] == '+') {
890 } else if (name[0] == '-') {
897 perf_volume->flags |= flag;
899 perf_volume->flags &= ~flag;
901 set_global_perf_vol_flag(host, flag, set);
905 v = get_volume (host, name);
909 if (!v->perf_data.flags) {
910 v->perf_data.flags = perf_volume->flags;
914 v->perf_data.flags |= flag;
916 v->perf_data.flags &= ~flag;
917 } /* for (i = 0 .. item->values_num) */
918 } /* }}} void process_perf_volume_flag */
920 static void process_volume_flag (host_config_t *host, /* {{{ */
921 volume_data_t *volume_data, const oconfig_item_t *item, uint32_t flag)
925 for (i = 0; i < item->values_num; ++i) {
930 if (item->values[i].type != OCONFIG_TYPE_STRING) {
931 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolData\""
932 "block for host %s", host->name);
936 name = item->values[i].value.string;
937 if (name[0] == '+') {
940 } else if (name[0] == '-') {
947 volume_data->flags |= flag;
949 volume_data->flags &= ~flag;
951 set_global_vol_flag(host, flag, set);
955 v = get_volume(host, name);
959 if (!v->volume_data.flags)
960 v->volume_data.flags = volume_data->flags;
963 v->volume_data.flags |= flag;
965 v->volume_data.flags &= ~flag;
967 } /* }}} void process_volume_flag */
969 static void build_perf_vol_config(host_config_t *host, const oconfig_item_t *ci) {
970 int i, had_io = 0, had_ops = 0, had_latency = 0;
971 service_config_t *service;
972 perf_volume_data_t *perf_volume;
974 service = malloc(sizeof(*service));
976 service->handler = collect_perf_volume_data;
977 perf_volume = service->data = malloc(sizeof(*perf_volume));
978 perf_volume->flags = PERF_VOLUME_INIT;
979 service->next = host->services;
980 host->services = service;
981 for (i = 0; i < ci->children_num; ++i) {
982 oconfig_item_t *item = ci->children + i;
984 /* if (!item || !item->key || !*item->key) continue; */
985 if (!strcasecmp(item->key, "Multiplier")) {
986 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) {
987 WARNING("netapp plugin: \"Multiplier\" of host %s service GetVolPerfData needs exactly one positive integer argument.", host->name);
990 service->skip_countdown = service->multiplier = item->values[0].value.number;
991 } else if (!strcasecmp(item->key, "GetIO")) {
993 process_perf_volume_flag(host, perf_volume, item, PERF_VOLUME_IO);
994 } else if (!strcasecmp(item->key, "GetOps")) {
996 process_perf_volume_flag(host, perf_volume, item, PERF_VOLUME_OPS);
997 } else if (!strcasecmp(item->key, "GetLatency")) {
999 process_perf_volume_flag(host, perf_volume, item, PERF_VOLUME_LATENCY);
1003 perf_volume->flags |= PERF_VOLUME_IO;
1004 set_global_perf_vol_flag(host, PERF_VOLUME_IO, /* set = */ true);
1007 perf_volume->flags |= PERF_VOLUME_OPS;
1008 set_global_perf_vol_flag(host, PERF_VOLUME_OPS, /* set = */ true);
1011 perf_volume->flags |= PERF_VOLUME_LATENCY;
1012 set_global_perf_vol_flag(host, PERF_VOLUME_LATENCY, /* set = */ true);
1016 static void build_volume_config(host_config_t *host, oconfig_item_t *ci) {
1018 service_config_t *service;
1019 volume_data_t *volume_data;
1021 service = malloc(sizeof(*service));
1023 service->handler = collect_volume_data;
1024 volume_data = service->data = malloc(sizeof(*volume_data));
1025 volume_data->flags = VOLUME_INIT;
1026 service->next = host->services;
1027 host->services = service;
1028 for (i = 0; i < ci->children_num; ++i) {
1029 oconfig_item_t *item = ci->children + i;
1031 /* if (!item || !item->key || !*item->key) continue; */
1032 if (!strcasecmp(item->key, "Multiplier")) {
1033 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) {
1034 WARNING("netapp plugin: \"Multiplier\" of host %s service GetVolPerfData needs exactly one positive integer argument.", host->name);
1037 service->skip_countdown = service->multiplier = item->values[0].value.number;
1038 } else if (!strcasecmp(item->key, "GetDiskUtil")) {
1040 process_volume_flag(host, volume_data, item, VOLUME_DF);
1044 volume_data->flags |= VOLUME_DF;
1045 set_global_vol_flag(host, VOLUME_DF, /* set = */ true);
1047 /* service = malloc(sizeof(*service));
1049 service->handler = collect_snapshot_data;
1050 service->data = volume_data;
1051 service->next = temp->services;
1052 temp->services = service;*/
1055 static void build_perf_disk_config(host_config_t *temp, oconfig_item_t *ci) {
1057 service_config_t *service;
1058 perf_disk_data_t *perf_disk;
1060 service = malloc(sizeof(*service));
1062 service->handler = collect_perf_disk_data;
1063 perf_disk = service->data = malloc(sizeof(*perf_disk));
1064 perf_disk->flags = PERF_DISK_ALL;
1065 service->next = temp->services;
1066 temp->services = service;
1067 for (i = 0; i < ci->children_num; ++i) {
1068 oconfig_item_t *item = ci->children + i;
1070 /* if (!item || !item->key || !*item->key) continue; */
1071 if (!strcasecmp(item->key, "Multiplier")) {
1072 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) {
1073 WARNING("netapp plugin: \"Multiplier\" of host %s service GetWaflPerfData needs exactly one positive integer argument.", ci->values[0].value.string);
1076 service->skip_countdown = service->multiplier = item->values[0].value.number;
1077 } else if (!strcasecmp(item->key, "GetBusy")) {
1078 config_bool_to_flag (item, &perf_disk->flags, PERF_SYSTEM_CPU);
1083 static void build_perf_wafl_config(host_config_t *temp, oconfig_item_t *ci) {
1085 service_config_t *service;
1086 perf_wafl_data_t *perf_wafl;
1088 service = malloc(sizeof(*service));
1090 service->handler = collect_perf_wafl_data;
1091 perf_wafl = service->data = malloc(sizeof(*perf_wafl));
1092 perf_wafl->flags = PERF_WAFL_ALL;
1093 perf_wafl->last_name_cache_hit = 0;
1094 perf_wafl->last_name_cache_miss = 0;
1095 perf_wafl->last_find_dir_hit = 0;
1096 perf_wafl->last_find_dir_miss = 0;
1097 perf_wafl->last_buf_hash_hit = 0;
1098 perf_wafl->last_buf_hash_miss = 0;
1099 perf_wafl->last_inode_cache_hit = 0;
1100 perf_wafl->last_inode_cache_miss = 0;
1101 service->next = temp->services;
1102 temp->services = service;
1103 for (i = 0; i < ci->children_num; ++i) {
1104 oconfig_item_t *item = ci->children + i;
1106 /* if (!item || !item->key || !*item->key) continue; */
1107 if (!strcasecmp(item->key, "Multiplier")) {
1108 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) {
1109 WARNING("netapp plugin: \"Multiplier\" of host %s service GetWaflPerfData needs exactly one positive integer argument.", ci->values[0].value.string);
1112 service->skip_countdown = service->multiplier = item->values[0].value.number;
1113 } else if (!strcasecmp(item->key, "GetNameCache")) {
1114 config_bool_to_flag (item, &perf_wafl->flags, PERF_WAFL_NAME_CACHE);
1115 } else if (!strcasecmp(item->key, "GetDirCache")) {
1116 config_bool_to_flag (item, &perf_wafl->flags, PERF_WAFL_DIR_CACHE);
1117 } else if (!strcasecmp(item->key, "GetBufCache")) {
1118 config_bool_to_flag (item, &perf_wafl->flags, PERF_WAFL_BUF_CACHE);
1119 } else if (!strcasecmp(item->key, "GetInodeCache")) {
1120 config_bool_to_flag (item, &perf_wafl->flags, PERF_WAFL_INODE_CACHE);
1122 WARNING ("netapp plugin: The %s config option is not allowed within "
1123 "`GetWaflPerfData' blocks.", item->key);
1128 static int build_perf_sys_config (host_config_t *host, /* {{{ */
1129 oconfig_item_t *ci, const service_config_t *default_service)
1132 service_config_t *service;
1133 perf_system_data_t *perf_system;
1135 service = malloc(sizeof(*service));
1136 if (service == NULL)
1138 memset (service, 0, sizeof (*service));
1139 *service = *default_service;
1140 service->handler = collect_perf_system_data;
1142 perf_system = malloc(sizeof(*perf_system));
1143 if (perf_system == NULL) {
1147 memset (perf_system, 0, sizeof (*perf_system));
1148 perf_system->flags = PERF_SYSTEM_ALL;
1149 service->data = perf_system;
1151 for (i = 0; i < ci->children_num; ++i) {
1152 oconfig_item_t *item = ci->children + i;
1154 if (!strcasecmp(item->key, "Multiplier")) {
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) {
1156 WARNING("netapp plugin: \"Multiplier\" of host %s service GetSystemPerfData needs exactly one positive integer argument.", ci->values[0].value.string);
1159 service->skip_countdown = service->multiplier = item->values[0].value.number;
1160 } else if (!strcasecmp(item->key, "GetCPULoad")) {
1161 config_bool_to_flag (item, &perf_system->flags, PERF_SYSTEM_CPU);
1162 } else if (!strcasecmp(item->key, "GetInterfaces")) {
1163 config_bool_to_flag (item, &perf_system->flags, PERF_SYSTEM_NET);
1164 } else if (!strcasecmp(item->key, "GetDiskOps")) {
1165 config_bool_to_flag (item, &perf_system->flags, PERF_SYSTEM_OPS);
1166 } else if (!strcasecmp(item->key, "GetDiskIO")) {
1167 config_bool_to_flag (item, &perf_system->flags, PERF_SYSTEM_DISK);
1169 WARNING ("netapp plugin: The %s config option is not allowed within "
1170 "`GetSystemPerfData' blocks.", item->key);
1174 service->next = host->services;
1175 host->services = service;
1178 } /* }}} int build_perf_sys_config */
1180 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) {
1182 oconfig_item_t *item;
1183 host_config_t *host, *hc, temp = *default_host;
1184 service_config_t default_service = *def_def_service;
1186 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1187 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
1191 temp.name = ci->values[0].value.string;
1192 for (i = 0; i < ci->children_num; ++i) {
1193 item = ci->children + i;
1195 /* if (!item || !item->key || !*item->key) continue; */
1196 if (!strcasecmp(item->key, "Address")) {
1197 if ((item->values_num != 1) || (item->values[0].type != OCONFIG_TYPE_STRING)) {
1198 WARNING("netapp plugin: \"Name\" needs exactly one string argument. Ignoring host block \"%s\".", ci->values[0].value.string);
1201 temp.host = item->values[0].value.string;
1202 } else if (!strcasecmp(item->key, "Port")) {
1203 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)) {
1204 WARNING("netapp plugin: \"Port\" needs exactly one integer argument in the range of 1-65535. Ignoring host block \"%s\".", ci->values[0].value.string);
1207 temp.port = item->values[0].value.number;
1208 } else if (!strcasecmp(item->key, "Protocol")) {
1209 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"))) {
1210 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
1213 if (!strcasecmp(item->values[0].value.string, "http")) temp.protocol = NA_SERVER_TRANSPORT_HTTP;
1214 else temp.protocol = NA_SERVER_TRANSPORT_HTTPS;
1215 } else if (!strcasecmp(item->key, "Login")) {
1216 if ((item->values_num != 2) || (item->values[0].type != OCONFIG_TYPE_STRING) || (item->values[1].type != OCONFIG_TYPE_STRING)) {
1217 WARNING("netapp plugin: \"Login\" needs exactly two string arguments, username and password. Ignoring host block \"%s\".", ci->values[0].value.string);
1220 temp.username = item->values[0].value.string;
1221 temp.password = item->values[1].value.string;
1222 } else if (!strcasecmp(item->key, "Interval")) {
1223 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) {
1224 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
1227 temp.interval = item->values[0].value.number;
1228 } else if (!strcasecmp(item->key, "GetVolumePerfData")) {
1229 build_perf_vol_config(&temp, item);
1230 } else if (!strcasecmp(item->key, "GetSystemPerfData")) {
1231 build_perf_sys_config(&temp, item, &default_service);
1232 /* if ((item->values_num != 1) || (item->values[0].type != OCONFIG_TYPE_STRING)) {
1233 WARNING("netapp plugin: \"Collect\" needs exactly one string argument. Ignoring collect block for \"%s\".", ci->values[0].value.string);
1236 build_collect_config(&temp, item);*/
1237 } else if (!strcasecmp(item->key, "GetWaflPerfData")) {
1238 build_perf_wafl_config(&temp, item);
1239 } else if (!strcasecmp(item->key, "GetDiskPerfData")) {
1240 build_perf_disk_config(&temp, item);
1241 } else if (!strcasecmp(item->key, "GetVolumeData")) {
1242 build_volume_config(&temp, item);
1244 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".", item->key, ci->values[0].value.string);
1248 if (!temp.host) temp.host = temp.name;
1249 if (!temp.port) temp.port = temp.protocol == NA_SERVER_TRANSPORT_HTTP ? 80 : 443;
1250 if (!temp.username) {
1251 WARNING("netapp plugin: Please supply login information for host \"%s\". Ignoring host block.", temp.name);
1254 for (hc = host_config; hc; hc = hc->next) {
1255 if (!strcasecmp(hc->name, temp.name)) WARNING("netapp plugin: Duplicate definition of host \"%s\". This is probably a bad idea.", hc->name);
1257 host = malloc(sizeof(*host));
1259 host->name = strdup(temp.name);
1260 host->protocol = temp.protocol;
1261 host->host = strdup(temp.host);
1262 host->username = strdup(temp.username);
1263 host->password = strdup(temp.password);
1264 host->next = host_config;
1269 static int build_config (oconfig_item_t *ci) {
1271 oconfig_item_t *item;
1272 host_config_t default_host = HOST_INIT;
1273 service_config_t default_service = SERVICE_INIT;
1275 for (i = 0; i < ci->children_num; ++i) {
1276 item = ci->children + i;
1278 /* if (!item || !item->key || !*item->key) continue; */
1279 if (!strcasecmp(item->key, "Host")) {
1280 build_host_config(item, &default_host, &default_service);
1282 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
1288 static int netapp_read() {
1290 host_config_t *host;
1291 service_config_t *service;
1293 for (host = host_config; host; host = host->next) {
1294 for (service = host->services; service; service = service->next) {
1295 if (--service->skip_countdown > 0) continue;
1296 service->skip_countdown = service->multiplier;
1297 out = na_server_invoke_elem(host->srv, service->query);
1298 if (na_results_status(out) != NA_OK) {
1299 int netapp_errno = na_results_errno(out);
1300 ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
1302 if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
1303 /* Network problems. Just give up on all other services on this host. */
1308 service->handler(host, out, service->data);
1315 void module_register() {
1316 plugin_register_complex_config("netapp", build_config);
1317 plugin_register_init("netapp", config_init);
1318 plugin_register_read("netapp", netapp_read);
1321 /* vim: set sw=2 ts=2 noet fdm=marker : */