2 * collectd - src/netapp.c
3 * Copyright (C) 2009 Sven Trenkel
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Sven Trenkel <sven.trenkel at noris.net>
30 #include <netapp_api.h>
32 #define HAS_ALL_FLAGS(has,needs) (((has) & (needs)) == (needs))
34 typedef struct host_config_s host_config_t;
35 typedef void service_handler_t(host_config_t *host, na_elem_t *result, void *data);
38 * \brief Persistent data for system performance counters
40 #define CFG_SYSTEM_CPU 0x01
41 #define CFG_SYSTEM_NET 0x02
42 #define CFG_SYSTEM_OPS 0x04
43 #define CFG_SYSTEM_DISK 0x08
44 #define CFG_SYSTEM_ALL 0x0F
50 * \brief Persistent data for WAFL performance counters. (a.k.a. cache performance)
52 * The cache counters use old counter values to calculate a hit ratio for each
53 * counter. The "data_wafl_t" struct therefore contains old counter values
54 * along with flags, which are set if the counter is valid.
56 * The function "query_wafl_data" will fill a new structure of this kind with
57 * new values, then pass both, new and old data, to "submit_wafl_data". That
58 * function calculates the hit ratios, submits the calculated values and
59 * updates the old counter values for the next iteration.
61 #define CFG_WAFL_NAME_CACHE 0x0001
62 #define CFG_WAFL_DIR_CACHE 0x0002
63 #define CFG_WAFL_BUF_CACHE 0x0004
64 #define CFG_WAFL_INODE_CACHE 0x0008
65 #define CFG_WAFL_ALL 0x000F
66 #define HAVE_WAFL_NAME_CACHE_HIT 0x0100
67 #define HAVE_WAFL_NAME_CACHE_MISS 0x0200
68 #define HAVE_WAFL_NAME_CACHE (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
69 #define HAVE_WAFL_FIND_DIR_HIT 0x0400
70 #define HAVE_WAFL_FIND_DIR_MISS 0x0800
71 #define HAVE_WAFL_FIND_DIR (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
72 #define HAVE_WAFL_BUF_HASH_HIT 0x1000
73 #define HAVE_WAFL_BUF_HASH_MISS 0x2000
74 #define HAVE_WAFL_BUF_HASH (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
75 #define HAVE_WAFL_INODE_CACHE_HIT 0x4000
76 #define HAVE_WAFL_INODE_CACHE_MISS 0x8000
77 #define HAVE_WAFL_INODE_CACHE (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
78 #define HAVE_WAFL_ALL 0xff00
82 uint64_t name_cache_hit;
83 uint64_t name_cache_miss;
84 uint64_t find_dir_hit;
85 uint64_t find_dir_miss;
86 uint64_t buf_hash_hit;
87 uint64_t buf_hash_miss;
88 uint64_t inode_cache_hit;
89 uint64_t inode_cache_miss;
93 * \brief Persistent data for volume performance data.
95 * The code below uses the difference of the operations and latency counters to
96 * calculate an average per-operation latency. For this, old counters need to
97 * be stored in the "data_volume_perf_t" structure. The byte-counters are just
98 * kept for completeness sake. The "flags" member indicates if each counter is
101 * The "query_volume_perf_data" function will fill a new struct of this type
102 * and pass both, old and new data, to "submit_volume_perf_data". In that
103 * function, the per-operation latency is calculated and dispatched, then the
104 * old counters are updated.
106 #define CFG_VOLUME_PERF_INIT 0x0001
107 #define CFG_VOLUME_PERF_IO 0x0002
108 #define CFG_VOLUME_PERF_OPS 0x0003
109 #define CFG_VOLUME_PERF_LATENCY 0x0008
110 #define CFG_VOLUME_PERF_ALL 0x000F
111 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
112 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
113 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
114 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
115 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
116 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
117 #define HAVE_VOLUME_PERF_ALL 0x03F0
126 uint64_t write_bytes;
129 uint64_t read_latency;
130 uint64_t write_latency;
131 } data_volume_perf_t;
134 * \brief Configuration struct for volume usage data (free / used).
136 #define CFG_VOLUME_USAGE_INIT 0x0001
137 #define CFG_VOLUME_USAGE_DF 0x0002
138 #define CFG_VOLUME_USAGE_SNAP 0x0004
139 #define HAVE_VOLUME_USAGE_SNAP 0x0008
143 } cfg_volume_usage_t;
145 typedef struct service_config_s {
147 service_handler_t *handler;
152 struct service_config_s *next;
154 #define SERVICE_INIT {0, 0, 1, 1, 0, 0, 0}
157 * \brief Struct representing a volume.
159 * A volume currently has a name and two sets of values:
161 * - Performance data, such as bytes read/written, number of operations
162 * performed and average time per operation.
164 * - Usage data, i. e. amount of used and free space in the volume.
166 typedef struct volume_s {
168 data_volume_perf_t perf_data;
169 cfg_volume_usage_t cfg_volume_usage;
170 struct volume_s *next;
173 #define CFG_DISK_BUSIEST 0x01
174 #define CFG_DISK_ALL 0x01
175 #define HAVE_DISK_BUSY 0x10
176 #define HAVE_DISK_BASE 0x20
177 #define HAVE_DISK_ALL 0x30
183 * \brief A disk in the NetApp.
185 * A disk doesn't have any more information than its name at the moment.
186 * The name includes the "disk_" prefix.
188 typedef struct disk_s {
193 uint64_t base_for_disk_busy;
194 double disk_busy_percent;
198 struct host_config_s {
201 na_server_transport_t protocol;
207 cfg_service_t *services;
210 struct host_config_s *next;
212 #define HOST_INIT {NULL, NULL, NA_SERVER_TRANSPORT_HTTPS, NULL, 0, NULL, NULL, 10, NULL, NULL, NULL, NULL}
214 static host_config_t *global_host_config;
219 * Used to free the various structures above.
221 static void free_volume (volume_t *volume) /* {{{ */
227 sfree (volume->name);
231 } /* }}} void free_volume */
233 static void free_disk (disk_t *disk) /* {{{ */
243 } /* }}} void free_disk */
245 static void free_cfg_service (cfg_service_t *service) /* {{{ */
252 next = service->next;
254 /* FIXME: Free service->data? */
255 na_elem_free(service->query);
259 free_cfg_service (next);
260 } /* }}} void free_cfg_service */
262 static void free_host_config (host_config_t *hc) /* {{{ */
273 sfree (hc->username);
274 sfree (hc->password);
276 free_cfg_service (hc->services);
277 free_disk (hc->disks);
278 free_volume (hc->volumes);
282 free_host_config (next);
283 } /* }}} void free_host_config */
286 * Auxiliary functions
288 * Used to look up volumes and disks or to handle flags.
290 static volume_t *get_volume (host_config_t *host, const char *name, /* {{{ */
291 uint32_t vol_usage_flags, uint32_t vol_perf_flags)
298 /* Make sure the default flags include the init-bit. */
299 if (vol_usage_flags != 0)
300 vol_usage_flags |= CFG_VOLUME_USAGE_INIT;
301 if (vol_perf_flags != 0)
302 vol_perf_flags |= CFG_VOLUME_PERF_INIT;
304 for (v = host->volumes; v; v = v->next) {
305 if (strcmp(v->name, name) != 0)
308 /* Check if the flags have been initialized. */
309 if (((v->cfg_volume_usage.flags & CFG_VOLUME_USAGE_INIT) == 0)
310 && (vol_usage_flags != 0))
311 v->cfg_volume_usage.flags = vol_usage_flags;
312 if (((v->perf_data.flags & CFG_VOLUME_PERF_INIT) == 0)
313 && (vol_perf_flags != 0))
314 v->perf_data.flags = vol_perf_flags;
319 DEBUG ("netapp plugin: Allocating new entry for volume %s.", name);
320 v = malloc(sizeof(*v));
323 memset (v, 0, sizeof (*v));
325 v->cfg_volume_usage.flags = vol_usage_flags;
326 v->perf_data.flags = vol_perf_flags;
328 v->name = strdup(name);
329 if (v->name == NULL) {
334 v->next = host->volumes;
338 } /* }}} volume_t *get_volume */
340 static disk_t *get_disk(host_config_t *host, const char *name) /* {{{ */
347 for (v = host->disks; v; v = v->next) {
348 if (strcmp(v->name, name) == 0)
351 v = malloc(sizeof(*v));
354 memset (v, 0, sizeof (*v));
357 v->name = strdup(name);
358 if (v->name == NULL) {
363 v->next = host->disks;
367 } /* }}} disk_t *get_disk */
369 static void host_set_all_perf_data_flags(const host_config_t *host, /* {{{ */
370 uint32_t flag, _Bool set)
374 for (v = host->volumes; v; v = v->next) {
376 v->perf_data.flags |= flag;
378 v->perf_data.flags &= ~flag;
380 } /* }}} void host_set_all_perf_data_flags */
382 static void host_set_all_cfg_volume_usage_flags(const host_config_t *host, /* {{{ */
383 uint32_t flag, _Bool set) {
386 for (v = host->volumes; v; v = v->next) {
388 v->cfg_volume_usage.flags |= flag;
390 v->cfg_volume_usage.flags &= ~flag;
392 } /* }}} void host_set_all_cfg_volume_usage_flags */
395 * Various submit functions.
397 * They all eventually call "submit_values" which creates a value_list_t and
398 * dispatches it to the daemon.
400 static int submit_values (const char *host, /* {{{ */
401 const char *plugin_inst,
402 const char *type, const char *type_inst,
403 value_t *values, int values_len,
406 value_list_t vl = VALUE_LIST_INIT;
409 vl.values_len = values_len;
415 sstrncpy (vl.host, host, sizeof (vl.host));
417 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
418 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
419 if (plugin_inst != NULL)
420 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
421 sstrncpy (vl.type, type, sizeof (vl.type));
422 if (type_inst != NULL)
423 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
425 return (plugin_dispatch_values (&vl));
426 } /* }}} int submit_uint64 */
428 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
429 const char *type, const char *type_inst, counter_t val0, counter_t val1,
434 values[0].counter = val0;
435 values[1].counter = val1;
437 return (submit_values (host, plugin_inst, type, type_inst,
438 values, 2, timestamp));
439 } /* }}} int submit_two_counters */
441 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
442 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
448 return (submit_values (host, plugin_inst, type, type_inst,
450 } /* }}} int submit_counter */
452 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
453 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
458 values[0].gauge = val0;
459 values[1].gauge = val1;
461 return (submit_values (host, plugin_inst, type, type_inst,
462 values, 2, timestamp));
463 } /* }}} int submit_two_gauge */
465 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
466 const char *type, const char *type_inst, double d, time_t timestamp)
470 v.gauge = (gauge_t) d;
472 return (submit_values (host, plugin_inst, type, type_inst,
474 } /* }}} int submit_uint64 */
476 /* Calculate hit ratio from old and new counters and submit the resulting
477 * percentage. Used by "submit_wafl_data". */
478 static int submit_cache_ratio (const char *host, /* {{{ */
479 const char *plugin_inst,
480 const char *type_inst,
489 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
493 hits = new_hits - old_hits;
494 misses = new_misses - old_misses;
496 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
501 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
503 } /* }}} int submit_cache_ratio */
505 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
506 static int submit_wafl_data (const host_config_t *host, const char *instance, /* {{{ */
507 data_wafl_t *old_data, const data_wafl_t *new_data)
509 /* Submit requested counters */
510 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
511 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
512 submit_cache_ratio (host->name, instance, "name_cache_hit",
513 new_data->name_cache_hit, new_data->name_cache_miss,
514 old_data->name_cache_hit, old_data->name_cache_miss,
515 new_data->timestamp);
517 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
518 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
519 submit_cache_ratio (host->name, instance, "find_dir_hit",
520 new_data->find_dir_hit, new_data->find_dir_miss,
521 old_data->find_dir_hit, old_data->find_dir_miss,
522 new_data->timestamp);
524 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
525 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
526 submit_cache_ratio (host->name, instance, "buf_hash_hit",
527 new_data->buf_hash_hit, new_data->buf_hash_miss,
528 old_data->buf_hash_hit, old_data->buf_hash_miss,
529 new_data->timestamp);
531 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
532 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
533 submit_cache_ratio (host->name, instance, "inode_cache_hit",
534 new_data->inode_cache_hit, new_data->inode_cache_miss,
535 old_data->inode_cache_hit, old_data->inode_cache_miss,
536 new_data->timestamp);
538 /* Clear old HAVE_* flags */
539 old_data->flags &= ~HAVE_WAFL_ALL;
541 /* Copy all counters */
542 old_data->timestamp = new_data->timestamp;
543 old_data->name_cache_hit = new_data->name_cache_hit;
544 old_data->name_cache_miss = new_data->name_cache_miss;
545 old_data->find_dir_hit = new_data->find_dir_hit;
546 old_data->find_dir_miss = new_data->find_dir_miss;
547 old_data->buf_hash_hit = new_data->buf_hash_hit;
548 old_data->buf_hash_miss = new_data->buf_hash_miss;
549 old_data->inode_cache_hit = new_data->inode_cache_hit;
550 old_data->inode_cache_miss = new_data->inode_cache_miss;
552 /* Copy HAVE_* flags */
553 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
556 } /* }}} int submit_wafl_data */
558 /* Submits volume performance data to the daemon, taking care to honor and
559 * update flags appropriately. */
560 static int submit_volume_perf_data (const host_config_t *host, /* {{{ */
562 const data_volume_perf_t *new_data)
564 /* Check for and submit disk-octet values */
565 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_IO)
566 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
568 submit_two_counters (host->name, volume->name, "disk_octets", /* type instance = */ NULL,
569 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
572 /* Check for and submit disk-operations values */
573 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_OPS)
574 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
576 submit_two_counters (host->name, volume->name, "disk_ops", /* type instance = */ NULL,
577 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
580 /* Check for, calculate and submit disk-latency values */
581 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_LATENCY
582 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
583 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
584 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
585 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
587 gauge_t latency_per_op_read;
588 gauge_t latency_per_op_write;
590 latency_per_op_read = NAN;
591 latency_per_op_write = NAN;
593 /* Check if a counter wrapped around. */
594 if ((new_data->read_ops > volume->perf_data.read_ops)
595 && (new_data->read_latency > volume->perf_data.read_latency))
597 uint64_t diff_ops_read;
598 uint64_t diff_latency_read;
600 diff_ops_read = new_data->read_ops - volume->perf_data.read_ops;
601 diff_latency_read = new_data->read_latency - volume->perf_data.read_latency;
603 if (diff_ops_read > 0)
604 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
607 if ((new_data->write_ops > volume->perf_data.write_ops)
608 && (new_data->write_latency > volume->perf_data.write_latency))
610 uint64_t diff_ops_write;
611 uint64_t diff_latency_write;
613 diff_ops_write = new_data->write_ops - volume->perf_data.write_ops;
614 diff_latency_write = new_data->write_latency - volume->perf_data.write_latency;
616 if (diff_ops_write > 0)
617 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
620 submit_two_gauge (host->name, volume->name, "disk_latency", /* type instance = */ NULL,
621 latency_per_op_read, latency_per_op_write, new_data->timestamp);
624 /* Clear all HAVE_* flags. */
625 volume->perf_data.flags &= ~HAVE_VOLUME_PERF_ALL;
627 /* Copy all counters */
628 volume->perf_data.timestamp = new_data->timestamp;
629 volume->perf_data.read_bytes = new_data->read_bytes;
630 volume->perf_data.write_bytes = new_data->write_bytes;
631 volume->perf_data.read_ops = new_data->read_ops;
632 volume->perf_data.write_ops = new_data->write_ops;
633 volume->perf_data.read_latency = new_data->read_latency;
634 volume->perf_data.write_latency = new_data->write_latency;
636 /* Copy the HAVE_* flags */
637 volume->perf_data.flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
640 } /* }}} int submit_volume_perf_data */
645 * These functions are called with appropriate data returned by the libnetapp
646 * interface which is parsed and submitted with the above functions.
648 /* Data corresponding to <GetWaflPerfData /> */
649 static void query_wafl_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
650 data_wafl_t *wafl = data;
651 data_wafl_t perf_data;
652 const char *plugin_inst;
655 memset (&perf_data, 0, sizeof (perf_data));
657 perf_data.timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
659 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
663 plugin_inst = na_child_get_string(out, "name");
664 if (plugin_inst == NULL)
667 /* Iterate over all counters */
668 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
669 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
673 name = na_child_get_string(counter, "name");
677 value = na_child_get_uint64(counter, "value", UINT64_MAX);
678 if (value == UINT64_MAX)
681 if (!strcmp(name, "name_cache_hit")) {
682 perf_data.name_cache_hit = value;
683 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
684 } else if (!strcmp(name, "name_cache_miss")) {
685 perf_data.name_cache_miss = value;
686 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
687 } else if (!strcmp(name, "find_dir_hit")) {
688 perf_data.find_dir_hit = value;
689 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
690 } else if (!strcmp(name, "find_dir_miss")) {
691 perf_data.find_dir_miss = value;
692 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
693 } else if (!strcmp(name, "buf_hash_hit")) {
694 perf_data.buf_hash_hit = value;
695 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
696 } else if (!strcmp(name, "buf_hash_miss")) {
697 perf_data.buf_hash_miss = value;
698 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
699 } else if (!strcmp(name, "inode_cache_hit")) {
700 perf_data.inode_cache_hit = value;
701 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
702 } else if (!strcmp(name, "inode_cache_miss")) {
703 perf_data.inode_cache_miss = value;
704 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
706 DEBUG("netapp plugin: query_wafl_data: Found unexpected child: %s",
711 submit_wafl_data (host, plugin_inst, wafl, &perf_data);
712 } /* }}} void query_wafl_data */
714 /* Data corresponding to <GetDiskPerfData /> */
715 static void query_submit_disk_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
716 cfg_disk_t *cfg_disk = data;
718 na_elem_t *counter, *inst;
719 disk_t *worst_disk = 0;
721 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
722 out = na_elem_child(out, "instances");
724 /* Iterate over all children */
725 na_elem_iter_t inst_iter = na_child_iterator(out);
726 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
730 memset (&new_data, 0, sizeof (new_data));
731 new_data.timestamp = timestamp;
732 new_data.disk_busy_percent = NAN;
734 old_data = get_disk(host, na_child_get_string(inst, "name"));
735 if (old_data == NULL)
738 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
739 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
740 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
744 name = na_child_get_string(counter, "name");
748 value = na_child_get_uint64(counter, "value", UINT64_MAX);
749 if (value == UINT64_MAX)
752 if (strcmp(name, "disk_busy") == 0)
754 new_data.disk_busy = value;
755 new_data.flags |= HAVE_DISK_BUSY;
757 else if (strcmp(name, "base_for_disk_busy") == 0)
759 new_data.base_for_disk_busy = value;
760 new_data.flags |= HAVE_DISK_BASE;
764 /* If all required counters are available and did not just wrap around,
765 * calculate the busy percentage. Otherwise, the value is initialized to
766 * NAN at the top of the for-loop. */
767 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
768 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
769 && (new_data.disk_busy >= old_data->disk_busy)
770 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
775 busy_diff = new_data.disk_busy - old_data->disk_busy;
776 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
778 new_data.disk_busy_percent = 100.0
779 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
782 /* Clear HAVE_* flags */
783 old_data->flags &= ~HAVE_DISK_ALL;
786 old_data->timestamp = new_data.timestamp;
787 old_data->disk_busy = new_data.disk_busy;
788 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
789 old_data->disk_busy_percent = new_data.disk_busy_percent;
792 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
794 if ((worst_disk == NULL)
795 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
796 worst_disk = old_data;
797 } /* for (all disks) */
799 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
800 submit_double (host->name, "system", "percent", "disk_busy",
801 worst_disk->disk_busy_percent, timestamp);
802 } /* }}} void query_submit_disk_data */
804 /* Data corresponding to <GetVolumeData /> */
805 static void collect_volume_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
808 cfg_volume_usage_t *cfg_volume_data = data;
810 out = na_elem_child(out, "volumes");
811 na_elem_iter_t inst_iter = na_child_iterator(out);
812 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
813 uint64_t size_free = 0, size_used = 0, snap_reserved = 0;
816 const char *sis_state;
817 uint64_t sis_saved_reported;
820 volume = get_volume(host, na_child_get_string(inst, "name"),
821 cfg_volume_data->flags, /* perf_flags = */ 0);
825 if (!(volume->cfg_volume_usage.flags & CFG_VOLUME_USAGE_DF))
828 /* 2^4 exa-bytes? This will take a while ;) */
829 size_free = na_child_get_uint64(inst, "size-available", UINT64_MAX);
830 if (size_free != UINT64_MAX)
831 submit_double (host->name, volume->name, "df_complex", "free",
832 (double) size_free, /* time = */ 0);
834 size_used = na_child_get_uint64(inst, "size-used", UINT64_MAX);
835 if (size_used != UINT64_MAX) {
836 if ((volume->cfg_volume_usage.flags & HAVE_VOLUME_USAGE_SNAP)
837 && (size_used >= volume->cfg_volume_usage.snap_used))
838 size_used -= volume->cfg_volume_usage.snap_used;
839 submit_double (host->name, volume->name, "df_complex", "used",
840 (double) size_used, /* time = */ 0);
843 snap_reserved = na_child_get_uint64(inst, "snapshot-blocks-reserved", UINT64_MAX);
844 if (!(volume->cfg_volume_usage.flags & HAVE_VOLUME_USAGE_SNAP) && (snap_reserved != UINT64_MAX))
845 /* If we have snap usage data this value has already been submitted. */
846 /* 1 block == 1024 bytes as per API docs */
847 submit_double (host->name, volume->name, "df_complex", "snap_reserved",
848 (double) (1024 * snap_reserved), /* time = */ 0);
850 sis = na_elem_child(inst, "sis");
854 sis_state = na_child_get_string(sis, "state");
855 if ((sis_state == NULL)
856 || (strcmp ("enabled", sis_state) != 0))
859 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
860 if (sis_saved_reported == UINT64_MAX)
863 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
864 if ((sis_saved_reported >> 32) != 0) {
865 /* In case they ever fix this bug. */
866 sis_saved = sis_saved_reported;
868 uint64_t sis_saved_percent;
869 uint64_t sis_saved_guess;
870 uint64_t overflow_guess;
871 uint64_t guess1, guess2, guess3;
873 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
874 if (sis_saved_percent > 100)
877 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
878 * will hopefully be fixed in later versions. To work around the bug, try
879 * to figure out how often the 32bit integer wrapped around by using the
880 * "percentage-saved" value. Because the percentage is in the range
881 * [0-100], this should work as long as the saved space does not exceed
883 /* percentage-saved = size-saved / (size-saved + size-used) */
884 if (sis_saved_percent < 100)
885 sis_saved_guess = size_used * sis_saved_percent / (100 - sis_saved_percent);
887 sis_saved_guess = size_used;
889 overflow_guess = sis_saved_guess >> 32;
890 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
891 guess2 = (overflow_guess << 32) + sis_saved_reported;
892 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
894 if (sis_saved_guess < guess2) {
895 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
900 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
905 } /* end of 32-bit workaround */
907 submit_double (host->name, volume->name, "df_complex", "sis_saved",
908 (double) sis_saved, /* time = */ 0);
910 } /* }}} void collect_volume_data */
912 /* Data corresponding to <GetVolumePerfData /> */
913 static void query_volume_perf_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
914 cfg_volume_perf_t *cfg_volume_perf = data;
916 na_elem_t *counter, *inst;
918 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
920 out = na_elem_child(out, "instances");
921 na_elem_iter_t inst_iter = na_child_iterator(out);
922 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
923 data_volume_perf_t perf_data;
926 memset (&perf_data, 0, sizeof (perf_data));
927 perf_data.timestamp = timestamp;
929 volume = get_volume(host, na_child_get_string(inst, "name"),
930 /* data_flags = */ 0, cfg_volume_perf->flags);
934 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
935 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
939 name = na_child_get_string(counter, "name");
943 value = na_child_get_uint64(counter, "value", UINT64_MAX);
944 if (value == UINT64_MAX)
947 if (!strcmp(name, "read_data")) {
948 perf_data.read_bytes = value;
949 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
950 } else if (!strcmp(name, "write_data")) {
951 perf_data.write_bytes = value;
952 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
953 } else if (!strcmp(name, "read_ops")) {
954 perf_data.read_ops = value;
955 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
956 } else if (!strcmp(name, "write_ops")) {
957 perf_data.write_ops = value;
958 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
959 } else if (!strcmp(name, "read_latency")) {
960 perf_data.read_latency = value;
961 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
962 } else if (!strcmp(name, "write_latency")) {
963 perf_data.write_latency = value;
964 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
968 submit_volume_perf_data (host, volume, &perf_data);
970 } /* }}} void query_volume_perf_data */
972 /* Data corresponding to <GetSystemPerfData /> */
973 static void collect_perf_system_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
974 counter_t disk_read = 0, disk_written = 0;
975 counter_t net_recv = 0, net_sent = 0;
976 counter_t cpu_busy = 0, cpu_total = 0;
977 unsigned int counter_flags = 0;
979 cfg_system_t *cfg_system = data;
980 const char *instance;
984 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
985 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
986 instance = na_child_get_string(out, "name");
988 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
989 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
993 name = na_child_get_string(counter, "name");
997 value = na_child_get_uint64(counter, "value", UINT64_MAX);
998 if (value == UINT64_MAX)
1001 if (!strcmp(name, "disk_data_read")) {
1002 disk_read = (counter_t) (value * 1024);
1003 counter_flags |= 0x01;
1004 } else if (!strcmp(name, "disk_data_written")) {
1005 disk_written = (counter_t) (value * 1024);
1006 counter_flags |= 0x02;
1007 } else if (!strcmp(name, "net_data_recv")) {
1008 net_recv = (counter_t) (value * 1024);
1009 counter_flags |= 0x04;
1010 } else if (!strcmp(name, "net_data_sent")) {
1011 net_sent = (counter_t) (value * 1024);
1012 counter_flags |= 0x08;
1013 } else if (!strcmp(name, "cpu_busy")) {
1014 cpu_busy = (counter_t) value;
1015 counter_flags |= 0x10;
1016 } else if (!strcmp(name, "cpu_elapsed_time")) {
1017 cpu_total = (counter_t) value;
1018 counter_flags |= 0x20;
1019 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1020 && (value > 0) && (strlen(name) > 4)
1021 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1022 submit_counter (host->name, instance, "disk_ops_complex", name,
1023 (counter_t) value, timestamp);
1025 } /* for (counter) */
1027 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1028 && ((counter_flags & 0x03) == 0x03))
1029 submit_two_counters (host->name, instance, "disk_octets", NULL,
1030 disk_read, disk_written, timestamp);
1032 if ((cfg_system->flags & CFG_SYSTEM_NET)
1033 && ((counter_flags & 0x0c) == 0x0c))
1034 submit_two_counters (host->name, instance, "if_octets", NULL,
1035 net_recv, net_sent, timestamp);
1037 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1038 && ((counter_flags & 0x30) == 0x30)) {
1039 submit_counter (host->name, instance, "cpu", "system",
1040 cpu_busy, timestamp);
1041 submit_counter (host->name, instance, "cpu", "idle",
1042 cpu_total - cpu_busy, timestamp);
1044 } /* }}} void collect_perf_system_data */
1047 * Configuration handling
1049 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1050 * is false. On error, the flag-field is not changed. */
1051 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1052 uint32_t *flags, uint32_t flag)
1054 if ((ci == NULL) || (flags == NULL))
1057 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1059 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1064 if (ci->values[0].value.boolean)
1070 } /* }}} int cna_config_bool_to_flag */
1072 /* Handling of the "Multiplier" option which is allowed in every block. */
1073 static int cna_config_get_multiplier (const oconfig_item_t *ci, /* {{{ */
1074 cfg_service_t *service)
1078 if ((ci == NULL) || (service == NULL))
1081 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1083 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1087 tmp = (int) (ci->values[0].value.number + .5);
1090 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1094 service->multiplier = tmp;
1095 service->skip_countdown = tmp;
1098 } /* }}} int cna_config_get_multiplier */
1100 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1101 * <GetVolumePerfData /> block. */
1102 static void cna_config_volume_performance_option (host_config_t *host, /* {{{ */
1103 cfg_volume_perf_t *perf_volume, const oconfig_item_t *item,
1108 for (i = 0; i < item->values_num; ++i) {
1113 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1114 WARNING("netapp plugin: Ignoring non-string argument in "
1115 "\"GetVolumePerfData\" block for host %s", host->name);
1119 name = item->values[i].value.string;
1120 if (name[0] == '+') {
1123 } else if (name[0] == '-') {
1130 perf_volume->flags |= flag;
1131 else /* if (!set) */
1132 perf_volume->flags &= ~flag;
1134 host_set_all_perf_data_flags(host, flag, set);
1138 v = get_volume (host, name, /* data_flags = */ 0, perf_volume->flags);
1143 v->perf_data.flags |= flag;
1144 else /* if (!set) */
1145 v->perf_data.flags &= ~flag;
1146 } /* for (i = 0 .. item->values_num) */
1147 } /* }}} void cna_config_volume_performance_option */
1149 /* Corresponds to a <GetDiskPerfData /> block */
1150 static void cna_config_volume_performance(host_config_t *host, const oconfig_item_t *ci) { /* {{{ */
1151 int i, had_io = 0, had_ops = 0, had_latency = 0;
1152 cfg_service_t *service;
1153 cfg_volume_perf_t *perf_volume;
1155 service = malloc(sizeof(*service));
1157 service->handler = query_volume_perf_data;
1158 perf_volume = service->data = malloc(sizeof(*perf_volume));
1159 perf_volume->flags = CFG_VOLUME_PERF_INIT;
1160 service->next = host->services;
1161 host->services = service;
1162 for (i = 0; i < ci->children_num; ++i) {
1163 oconfig_item_t *item = ci->children + i;
1165 /* if (!item || !item->key || !*item->key) continue; */
1166 if (!strcasecmp(item->key, "Multiplier")) {
1167 cna_config_get_multiplier (item, service);
1168 } else if (!strcasecmp(item->key, "GetIO")) {
1170 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_IO);
1171 } else if (!strcasecmp(item->key, "GetOps")) {
1173 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_OPS);
1174 } else if (!strcasecmp(item->key, "GetLatency")) {
1176 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_LATENCY);
1180 perf_volume->flags |= CFG_VOLUME_PERF_IO;
1181 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_IO, /* set = */ true);
1184 perf_volume->flags |= CFG_VOLUME_PERF_OPS;
1185 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_OPS, /* set = */ true);
1188 perf_volume->flags |= CFG_VOLUME_PERF_LATENCY;
1189 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_LATENCY, /* set = */ true);
1191 } /* }}} void cna_config_volume_performance */
1193 /* Handling of the "GetDiskUtil" option within a <GetVolumeData /> block. */
1194 static void cna_config_volume_usage_option (host_config_t *host, /* {{{ */
1195 cfg_volume_usage_t *cfg_volume_data, const oconfig_item_t *item, uint32_t flag)
1199 for (i = 0; i < item->values_num; ++i) {
1204 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1205 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolData\""
1206 "block for host %s", host->name);
1210 name = item->values[i].value.string;
1211 if (name[0] == '+') {
1214 } else if (name[0] == '-') {
1221 cfg_volume_data->flags |= flag;
1222 else /* if (!set) */
1223 cfg_volume_data->flags &= ~flag;
1225 host_set_all_cfg_volume_usage_flags(host, flag, set);
1229 v = get_volume(host, name, cfg_volume_data->flags, /* perf_flags = */ 0);
1233 if (!v->cfg_volume_usage.flags)
1234 v->cfg_volume_usage.flags = cfg_volume_data->flags;
1237 v->cfg_volume_usage.flags |= flag;
1238 else /* if (!set) */
1239 v->cfg_volume_usage.flags &= ~flag;
1241 } /* }}} void cna_config_volume_usage_option */
1243 /* Corresponds to a <GetVolumeData /> block */
1244 static void cna_config_volume_usage(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1246 cfg_service_t *service;
1247 cfg_volume_usage_t *cfg_volume_data;
1249 service = malloc(sizeof(*service));
1251 service->handler = collect_volume_data;
1252 cfg_volume_data = service->data = malloc(sizeof(*cfg_volume_data));
1253 cfg_volume_data->flags = CFG_VOLUME_USAGE_INIT;
1254 service->next = host->services;
1255 host->services = service;
1256 for (i = 0; i < ci->children_num; ++i) {
1257 oconfig_item_t *item = ci->children + i;
1259 /* if (!item || !item->key || !*item->key) continue; */
1260 if (!strcasecmp(item->key, "Multiplier")) {
1261 cna_config_get_multiplier (item, service);
1262 } else if (!strcasecmp(item->key, "GetDiskUtil")) {
1264 cna_config_volume_usage_option(host, cfg_volume_data, item, CFG_VOLUME_USAGE_DF);
1265 } else if (!strcasecmp(item->key, "GetSnapUtil")) {
1267 cna_config_volume_usage_option(host, cfg_volume_data, item, CFG_VOLUME_USAGE_SNAP);
1271 cfg_volume_data->flags |= CFG_VOLUME_USAGE_DF;
1272 host_set_all_cfg_volume_usage_flags(host, CFG_VOLUME_USAGE_DF, /* set = */ true);
1274 if (cfg_volume_data->flags & CFG_VOLUME_USAGE_SNAP) {
1275 WARNING("netapp plugin: The \"GetSnapUtil\" option does not support the \"+\" wildcard.");
1277 } /* }}} void cna_config_volume_usage */
1279 /* Corresponds to a <GetDiskPerfData /> block */
1280 static void cna_config_disk(host_config_t *temp, oconfig_item_t *ci) { /* {{{ */
1282 cfg_service_t *service;
1283 cfg_disk_t *cfg_disk;
1285 service = malloc(sizeof(*service));
1287 service->handler = query_submit_disk_data;
1288 cfg_disk = service->data = malloc(sizeof(*cfg_disk));
1289 cfg_disk->flags = CFG_DISK_ALL;
1290 service->next = temp->services;
1291 temp->services = service;
1292 for (i = 0; i < ci->children_num; ++i) {
1293 oconfig_item_t *item = ci->children + i;
1295 /* if (!item || !item->key || !*item->key) continue; */
1296 if (!strcasecmp(item->key, "Multiplier")) {
1297 cna_config_get_multiplier (item, service);
1298 } else if (!strcasecmp(item->key, "GetBusy")) {
1299 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_SYSTEM_CPU);
1302 } /* }}} void cna_config_disk */
1304 /* Corresponds to a <GetWaflPerfData /> block */
1305 static void cna_config_wafl(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1307 cfg_service_t *service;
1308 data_wafl_t *perf_wafl;
1310 service = malloc(sizeof(*service));
1311 if (service == NULL)
1313 memset (service, 0, sizeof (*service));
1316 service->handler = query_wafl_data;
1317 perf_wafl = service->data = malloc(sizeof(*perf_wafl));
1318 perf_wafl->flags = CFG_WAFL_ALL;
1320 for (i = 0; i < ci->children_num; ++i) {
1321 oconfig_item_t *item = ci->children + i;
1323 if (!strcasecmp(item->key, "Multiplier")) {
1324 cna_config_get_multiplier (item, service);
1325 } else if (!strcasecmp(item->key, "GetNameCache")) {
1326 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_NAME_CACHE);
1327 } else if (!strcasecmp(item->key, "GetDirCache")) {
1328 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_DIR_CACHE);
1329 } else if (!strcasecmp(item->key, "GetBufCache")) {
1330 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_BUF_CACHE);
1331 } else if (!strcasecmp(item->key, "GetInodeCache")) {
1332 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_INODE_CACHE);
1334 WARNING ("netapp plugin: The %s config option is not allowed within "
1335 "`GetWaflPerfData' blocks.", item->key);
1339 service->next = host->services;
1340 host->services = service;
1341 } /* }}} void cna_config_wafl */
1343 /* Corresponds to a <GetSystemPerfData /> block */
1344 static int cna_config_system (host_config_t *host, /* {{{ */
1345 oconfig_item_t *ci, const cfg_service_t *default_service)
1348 cfg_service_t *service;
1349 cfg_system_t *cfg_system;
1351 service = malloc(sizeof(*service));
1352 if (service == NULL)
1354 memset (service, 0, sizeof (*service));
1355 *service = *default_service;
1356 service->handler = collect_perf_system_data;
1358 cfg_system = malloc(sizeof(*cfg_system));
1359 if (cfg_system == NULL) {
1363 memset (cfg_system, 0, sizeof (*cfg_system));
1364 cfg_system->flags = CFG_SYSTEM_ALL;
1365 service->data = cfg_system;
1367 for (i = 0; i < ci->children_num; ++i) {
1368 oconfig_item_t *item = ci->children + i;
1370 if (!strcasecmp(item->key, "Multiplier")) {
1371 cna_config_get_multiplier (item, service);
1372 } else if (!strcasecmp(item->key, "GetCPULoad")) {
1373 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
1374 } else if (!strcasecmp(item->key, "GetInterfaces")) {
1375 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
1376 } else if (!strcasecmp(item->key, "GetDiskOps")) {
1377 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
1378 } else if (!strcasecmp(item->key, "GetDiskIO")) {
1379 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
1381 WARNING ("netapp plugin: The %s config option is not allowed within "
1382 "`GetSystemPerfData' blocks.", item->key);
1386 service->next = host->services;
1387 host->services = service;
1390 } /* }}} int cna_config_system */
1392 /* Corresponds to a <Host /> block. */
1393 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
1394 const host_config_t *default_host, const cfg_service_t *def_def_service)
1396 oconfig_item_t *item;
1397 host_config_t *host;
1398 cfg_service_t default_service = *def_def_service;
1402 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1403 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
1407 host = malloc(sizeof(*host));
1408 memcpy (host, default_host, sizeof (*host));
1410 status = cf_util_get_string (ci, &host->name);
1417 for (i = 0; i < ci->children_num; ++i) {
1418 item = ci->children + i;
1422 if (!strcasecmp(item->key, "Address")) {
1423 status = cf_util_get_string (item, &host->host);
1424 } else if (!strcasecmp(item->key, "Port")) {
1427 tmp = cf_util_get_port_number (item);
1430 } else if (!strcasecmp(item->key, "Protocol")) {
1431 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"))) {
1432 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
1435 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
1436 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
1437 } else if (!strcasecmp(item->key, "User")) {
1438 status = cf_util_get_string (item, &host->username);
1439 } else if (!strcasecmp(item->key, "Password")) {
1440 status = cf_util_get_string (item, &host->password);
1441 } else if (!strcasecmp(item->key, "Interval")) {
1442 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) {
1443 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
1446 host->interval = item->values[0].value.number;
1447 } else if (!strcasecmp(item->key, "GetVolumePerfData")) {
1448 cna_config_volume_performance(host, item);
1449 } else if (!strcasecmp(item->key, "GetSystemPerfData")) {
1450 cna_config_system(host, item, &default_service);
1451 } else if (!strcasecmp(item->key, "GetWaflPerfData")) {
1452 cna_config_wafl(host, item);
1453 } else if (!strcasecmp(item->key, "GetDiskPerfData")) {
1454 cna_config_disk(host, item);
1455 } else if (!strcasecmp(item->key, "GetVolumeData")) {
1456 cna_config_volume_usage(host, item);
1458 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
1459 item->key, ci->values[0].value.string);
1466 if (host->host == NULL)
1467 host->host = strdup (host->name);
1469 if (host->host == NULL)
1472 if (host->port <= 0)
1473 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
1475 if ((host->username == NULL) || (host->password == NULL)) {
1476 WARNING("netapp plugin: Please supply login information for host \"%s\". "
1477 "Ignoring host block.", host->name);
1483 free_host_config (host);
1488 } /* }}} host_config_t *cna_config_host */
1491 * Callbacks registered with the daemon
1493 * Pretty standard stuff here.
1495 static int cna_init(void) { /* {{{ */
1498 host_config_t *host;
1499 cfg_service_t *service;
1501 if (!global_host_config) {
1502 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
1506 if (!na_startup(err, sizeof(err))) {
1507 ERROR("netapp plugin: Error initializing netapp API: %s", err);
1511 for (host = global_host_config; host; host = host->next) {
1512 host->srv = na_server_open(host->host, 1, 1);
1513 na_server_set_transport_type(host->srv, host->protocol, 0);
1514 na_server_set_port(host->srv, host->port);
1515 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
1516 na_server_adminuser(host->srv, host->username, host->password);
1517 na_server_set_timeout(host->srv, 5);
1518 for (service = host->services; service; service = service->next) {
1519 service->interval = host->interval * service->multiplier;
1520 if (service->handler == collect_perf_system_data) {
1521 service->query = na_elem_new("perf-object-get-instances");
1522 na_child_add_string(service->query, "objectname", "system");
1523 } else if (service->handler == query_volume_perf_data) {
1524 service->query = na_elem_new("perf-object-get-instances");
1525 na_child_add_string(service->query, "objectname", "volume");
1526 /* e = na_elem_new("instances");
1527 na_child_add_string(e, "foo", "system");
1528 na_child_add(root, e);*/
1529 e = na_elem_new("counters");
1530 /* "foo" means: This string has to be here but
1531 the content doesn't matter. */
1532 na_child_add_string(e, "foo", "read_ops");
1533 na_child_add_string(e, "foo", "write_ops");
1534 na_child_add_string(e, "foo", "read_data");
1535 na_child_add_string(e, "foo", "write_data");
1536 na_child_add_string(e, "foo", "read_latency");
1537 na_child_add_string(e, "foo", "write_latency");
1538 na_child_add(service->query, e);
1539 } else if (service->handler == query_wafl_data) {
1540 service->query = na_elem_new("perf-object-get-instances");
1541 na_child_add_string(service->query, "objectname", "wafl");
1542 /* e = na_elem_new("instances");
1543 na_child_add_string(e, "foo", "system");
1544 na_child_add(root, e);*/
1545 e = na_elem_new("counters");
1546 na_child_add_string(e, "foo", "name_cache_hit");
1547 na_child_add_string(e, "foo", "name_cache_miss");
1548 na_child_add_string(e, "foo", "find_dir_hit");
1549 na_child_add_string(e, "foo", "find_dir_miss");
1550 na_child_add_string(e, "foo", "buf_hash_hit");
1551 na_child_add_string(e, "foo", "buf_hash_miss");
1552 na_child_add_string(e, "foo", "inode_cache_hit");
1553 na_child_add_string(e, "foo", "inode_cache_miss");
1554 /* na_child_add_string(e, "foo", "inode_eject_time"); */
1555 /* na_child_add_string(e, "foo", "buf_eject_time"); */
1556 na_child_add(service->query, e);
1557 } else if (service->handler == query_submit_disk_data) {
1558 service->query = na_elem_new("perf-object-get-instances");
1559 na_child_add_string(service->query, "objectname", "disk");
1560 e = na_elem_new("counters");
1561 na_child_add_string(e, "foo", "disk_busy");
1562 na_child_add_string(e, "foo", "base_for_disk_busy");
1563 na_child_add(service->query, e);
1564 } else if (service->handler == collect_volume_data) {
1565 service->query = na_elem_new("volume-list-info");
1566 /* na_child_add_string(service->query, "objectname", "volume"); */
1567 /* } else if (service->handler == collect_snapshot_data) { */
1568 /* service->query = na_elem_new("snapshot-list-info"); */
1573 } /* }}} int cna_init */
1575 static int cna_config (oconfig_item_t *ci) { /* {{{ */
1577 oconfig_item_t *item;
1578 host_config_t default_host = HOST_INIT;
1579 cfg_service_t default_service = SERVICE_INIT;
1581 for (i = 0; i < ci->children_num; ++i) {
1582 item = ci->children + i;
1584 if (!strcasecmp(item->key, "Host")) {
1585 host_config_t *host;
1588 host = cna_config_host(item, &default_host, &default_service);
1592 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
1594 if (strcasecmp (host->name, tmp->name) == 0)
1595 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
1596 "This is probably a bad idea.",
1599 if (tmp->next == NULL)
1605 global_host_config = host;
1609 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
1613 } /* }}} int cna_config */
1615 static int cna_read(void) { /* {{{ */
1617 host_config_t *host;
1618 cfg_service_t *service;
1620 for (host = global_host_config; host; host = host->next) {
1621 for (service = host->services; service; service = service->next) {
1622 if (--service->skip_countdown > 0) continue;
1623 service->skip_countdown = service->multiplier;
1624 out = na_server_invoke_elem(host->srv, service->query);
1625 if (na_results_status(out) != NA_OK) {
1626 int netapp_errno = na_results_errno(out);
1627 ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
1629 if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
1630 /* Network problems. Just give up on all other services on this host. */
1635 service->handler(host, out, service->data);
1640 } /* }}} int cna_read */
1642 void module_register(void) {
1643 plugin_register_complex_config("netapp", cna_config);
1644 plugin_register_init("netapp", cna_init);
1645 plugin_register_read("netapp", cna_read);
1648 /* vim: set sw=2 ts=2 noet fdm=marker : */