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", "used",
832 (double) size_used, /* time = */ 0);
834 size_used = na_child_get_uint64(inst, "size-used", UINT64_MAX);
835 if (size_free != UINT64_MAX)
836 submit_double (host->name, volume->name, "df_complex", "free",
837 (double) size_free, /* time = */ 0);
839 snap_reserved = na_child_get_uint64(inst, "snapshot-blocks-reserved", UINT64_MAX);
840 if (snap_reserved != UINT64_MAX)
841 /* 1 block == 1024 bytes as per API docs */
842 submit_double (host->name, volume->name, "df_complex", "snap_reserved",
843 (double) (1024 * snap_reserved), /* time = */ 0);
845 sis = na_elem_child(inst, "sis");
849 sis_state = na_child_get_string(sis, "state");
850 if ((sis_state == NULL)
851 || (strcmp ("enabled", sis_state) != 0))
854 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
855 if (sis_saved_reported == UINT64_MAX)
858 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
859 if ((sis_saved_reported >> 32) != 0) {
860 /* In case they ever fix this bug. */
861 sis_saved = sis_saved_reported;
863 uint64_t sis_saved_percent;
864 uint64_t sis_saved_guess;
865 uint64_t overflow_guess;
866 uint64_t guess1, guess2, guess3;
868 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
869 if (sis_saved_percent > 100)
872 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
873 * will hopefully be fixed in later versions. To work around the bug, try
874 * to figure out how often the 32bit integer wrapped around by using the
875 * "percentage-saved" value. Because the percentage is in the range
876 * [0-100], this should work as long as the saved space does not exceed
878 /* percentage-saved = size-saved / (size-saved + size-used) */
879 if (sis_saved_percent < 100)
880 sis_saved_guess = size_used * sis_saved_percent / (100 - sis_saved_percent);
882 sis_saved_guess = size_used;
884 overflow_guess = sis_saved_guess >> 32;
885 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
886 guess2 = (overflow_guess << 32) + sis_saved_reported;
887 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
889 if (sis_saved_guess < guess2) {
890 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
895 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
900 } /* end of 32-bit workaround */
902 submit_double (host->name, volume->name, "df_complex", "sis_saved",
903 (double) sis_saved, /* time = */ 0);
905 } /* }}} void collect_volume_data */
907 /* Data corresponding to <GetVolumePerfData /> */
908 static void query_volume_perf_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
909 cfg_volume_perf_t *cfg_volume_perf = data;
911 na_elem_t *counter, *inst;
913 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
915 out = na_elem_child(out, "instances");
916 na_elem_iter_t inst_iter = na_child_iterator(out);
917 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
918 data_volume_perf_t perf_data;
921 memset (&perf_data, 0, sizeof (perf_data));
922 perf_data.timestamp = timestamp;
924 volume = get_volume(host, na_child_get_string(inst, "name"),
925 /* data_flags = */ 0, cfg_volume_perf->flags);
929 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
930 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
934 name = na_child_get_string(counter, "name");
938 value = na_child_get_uint64(counter, "value", UINT64_MAX);
939 if (value == UINT64_MAX)
942 if (!strcmp(name, "read_data")) {
943 perf_data.read_bytes = value;
944 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
945 } else if (!strcmp(name, "write_data")) {
946 perf_data.write_bytes = value;
947 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
948 } else if (!strcmp(name, "read_ops")) {
949 perf_data.read_ops = value;
950 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
951 } else if (!strcmp(name, "write_ops")) {
952 perf_data.write_ops = value;
953 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
954 } else if (!strcmp(name, "read_latency")) {
955 perf_data.read_latency = value;
956 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
957 } else if (!strcmp(name, "write_latency")) {
958 perf_data.write_latency = value;
959 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
963 submit_volume_perf_data (host, volume, &perf_data);
965 } /* }}} void query_volume_perf_data */
967 /* Data corresponding to <GetSystemPerfData /> */
968 static void collect_perf_system_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
969 counter_t disk_read = 0, disk_written = 0;
970 counter_t net_recv = 0, net_sent = 0;
971 counter_t cpu_busy = 0, cpu_total = 0;
972 unsigned int counter_flags = 0;
974 cfg_system_t *cfg_system = data;
975 const char *instance;
979 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
980 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
981 instance = na_child_get_string(out, "name");
983 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
984 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
988 name = na_child_get_string(counter, "name");
992 value = na_child_get_uint64(counter, "value", UINT64_MAX);
993 if (value == UINT64_MAX)
996 if (!strcmp(name, "disk_data_read")) {
997 disk_read = (counter_t) (value * 1024);
998 counter_flags |= 0x01;
999 } else if (!strcmp(name, "disk_data_written")) {
1000 disk_written = (counter_t) (value * 1024);
1001 counter_flags |= 0x02;
1002 } else if (!strcmp(name, "net_data_recv")) {
1003 net_recv = (counter_t) (value * 1024);
1004 counter_flags |= 0x04;
1005 } else if (!strcmp(name, "net_data_sent")) {
1006 net_sent = (counter_t) (value * 1024);
1007 counter_flags |= 0x08;
1008 } else if (!strcmp(name, "cpu_busy")) {
1009 cpu_busy = (counter_t) value;
1010 counter_flags |= 0x10;
1011 } else if (!strcmp(name, "cpu_elapsed_time")) {
1012 cpu_total = (counter_t) value;
1013 counter_flags |= 0x20;
1014 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1015 && (value > 0) && (strlen(name) > 4)
1016 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1017 submit_counter (host->name, instance, "disk_ops_complex", name,
1018 (counter_t) value, timestamp);
1020 } /* for (counter) */
1022 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1023 && ((counter_flags & 0x03) == 0x03))
1024 submit_two_counters (host->name, instance, "disk_octets", NULL,
1025 disk_read, disk_written, timestamp);
1027 if ((cfg_system->flags & CFG_SYSTEM_NET)
1028 && ((counter_flags & 0x0c) == 0x0c))
1029 submit_two_counters (host->name, instance, "if_octets", NULL,
1030 net_recv, net_sent, timestamp);
1032 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1033 && ((counter_flags & 0x30) == 0x30)) {
1034 submit_counter (host->name, instance, "cpu", "system",
1035 cpu_busy, timestamp);
1036 submit_counter (host->name, instance, "cpu", "idle",
1037 cpu_total - cpu_busy, timestamp);
1039 } /* }}} void collect_perf_system_data */
1042 * Configuration handling
1044 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1045 * is false. On error, the flag-field is not changed. */
1046 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1047 uint32_t *flags, uint32_t flag)
1049 if ((ci == NULL) || (flags == NULL))
1052 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1054 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1059 if (ci->values[0].value.boolean)
1065 } /* }}} int cna_config_bool_to_flag */
1067 /* Handling of the "Multiplier" option which is allowed in every block. */
1068 static int cna_config_get_multiplier (const oconfig_item_t *ci, /* {{{ */
1069 cfg_service_t *service)
1073 if ((ci == NULL) || (service == NULL))
1076 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1078 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1082 tmp = (int) (ci->values[0].value.number + .5);
1085 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1089 service->multiplier = tmp;
1090 service->skip_countdown = tmp;
1093 } /* }}} int cna_config_get_multiplier */
1095 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1096 * <GetVolumePerfData /> block. */
1097 static void cna_config_volume_performance_option (host_config_t *host, /* {{{ */
1098 cfg_volume_perf_t *perf_volume, const oconfig_item_t *item,
1103 for (i = 0; i < item->values_num; ++i) {
1108 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1109 WARNING("netapp plugin: Ignoring non-string argument in "
1110 "\"GetVolumePerfData\" block for host %s", host->name);
1114 name = item->values[i].value.string;
1115 if (name[0] == '+') {
1118 } else if (name[0] == '-') {
1125 perf_volume->flags |= flag;
1126 else /* if (!set) */
1127 perf_volume->flags &= ~flag;
1129 host_set_all_perf_data_flags(host, flag, set);
1133 v = get_volume (host, name, /* data_flags = */ 0, perf_volume->flags);
1138 v->perf_data.flags |= flag;
1139 else /* if (!set) */
1140 v->perf_data.flags &= ~flag;
1141 } /* for (i = 0 .. item->values_num) */
1142 } /* }}} void cna_config_volume_performance_option */
1144 /* Corresponds to a <GetDiskPerfData /> block */
1145 static void cna_config_volume_performance(host_config_t *host, const oconfig_item_t *ci) { /* {{{ */
1146 int i, had_io = 0, had_ops = 0, had_latency = 0;
1147 cfg_service_t *service;
1148 cfg_volume_perf_t *perf_volume;
1150 service = malloc(sizeof(*service));
1152 service->handler = query_volume_perf_data;
1153 perf_volume = service->data = malloc(sizeof(*perf_volume));
1154 perf_volume->flags = CFG_VOLUME_PERF_INIT;
1155 service->next = host->services;
1156 host->services = service;
1157 for (i = 0; i < ci->children_num; ++i) {
1158 oconfig_item_t *item = ci->children + i;
1160 /* if (!item || !item->key || !*item->key) continue; */
1161 if (!strcasecmp(item->key, "Multiplier")) {
1162 cna_config_get_multiplier (item, service);
1163 } else if (!strcasecmp(item->key, "GetIO")) {
1165 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_IO);
1166 } else if (!strcasecmp(item->key, "GetOps")) {
1168 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_OPS);
1169 } else if (!strcasecmp(item->key, "GetLatency")) {
1171 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_LATENCY);
1175 perf_volume->flags |= CFG_VOLUME_PERF_IO;
1176 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_IO, /* set = */ true);
1179 perf_volume->flags |= CFG_VOLUME_PERF_OPS;
1180 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_OPS, /* set = */ true);
1183 perf_volume->flags |= CFG_VOLUME_PERF_LATENCY;
1184 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_LATENCY, /* set = */ true);
1186 } /* }}} void cna_config_volume_performance */
1188 /* Handling of the "GetDiskUtil" option within a <GetVolumeData /> block. */
1189 static void cna_config_volume_usage_option (host_config_t *host, /* {{{ */
1190 cfg_volume_usage_t *cfg_volume_data, const oconfig_item_t *item, uint32_t flag)
1194 for (i = 0; i < item->values_num; ++i) {
1199 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1200 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolData\""
1201 "block for host %s", host->name);
1205 name = item->values[i].value.string;
1206 if (name[0] == '+') {
1209 } else if (name[0] == '-') {
1216 cfg_volume_data->flags |= flag;
1217 else /* if (!set) */
1218 cfg_volume_data->flags &= ~flag;
1220 host_set_all_cfg_volume_usage_flags(host, flag, set);
1224 v = get_volume(host, name, cfg_volume_data->flags, /* perf_flags = */ 0);
1228 if (!v->cfg_volume_usage.flags)
1229 v->cfg_volume_usage.flags = cfg_volume_data->flags;
1232 v->cfg_volume_usage.flags |= flag;
1233 else /* if (!set) */
1234 v->cfg_volume_usage.flags &= ~flag;
1236 } /* }}} void cna_config_volume_usage_option */
1238 /* Corresponds to a <GetVolumeData /> block */
1239 static void cna_config_volume_usage(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1241 cfg_service_t *service;
1242 cfg_volume_usage_t *cfg_volume_data;
1244 service = malloc(sizeof(*service));
1246 service->handler = collect_volume_data;
1247 cfg_volume_data = service->data = malloc(sizeof(*cfg_volume_data));
1248 cfg_volume_data->flags = CFG_VOLUME_USAGE_INIT;
1249 service->next = host->services;
1250 host->services = service;
1251 for (i = 0; i < ci->children_num; ++i) {
1252 oconfig_item_t *item = ci->children + i;
1254 /* if (!item || !item->key || !*item->key) continue; */
1255 if (!strcasecmp(item->key, "Multiplier")) {
1256 cna_config_get_multiplier (item, service);
1257 } else if (!strcasecmp(item->key, "GetDiskUtil")) {
1259 cna_config_volume_usage_option(host, cfg_volume_data, item, CFG_VOLUME_USAGE_DF);
1260 } else if (!strcasecmp(item->key, "GetSnapUtil")) {
1262 cna_config_volume_usage_option(host, cfg_volume_data, item, CFG_VOLUME_USAGE_SNAP);
1266 cfg_volume_data->flags |= CFG_VOLUME_USAGE_DF;
1267 host_set_all_cfg_volume_usage_flags(host, CFG_VOLUME_USAGE_DF, /* set = */ true);
1269 if (cfg_volume_data->flags & CFG_VOLUME_USAGE_SNAP) {
1270 WARNING("netapp plugin: The \"GetSnapUtil\" option does not support the \"+\" wildcard.");
1272 } /* }}} void cna_config_volume_usage */
1274 /* Corresponds to a <GetDiskPerfData /> block */
1275 static void cna_config_disk(host_config_t *temp, oconfig_item_t *ci) { /* {{{ */
1277 cfg_service_t *service;
1278 cfg_disk_t *cfg_disk;
1280 service = malloc(sizeof(*service));
1282 service->handler = query_submit_disk_data;
1283 cfg_disk = service->data = malloc(sizeof(*cfg_disk));
1284 cfg_disk->flags = CFG_DISK_ALL;
1285 service->next = temp->services;
1286 temp->services = service;
1287 for (i = 0; i < ci->children_num; ++i) {
1288 oconfig_item_t *item = ci->children + i;
1290 /* if (!item || !item->key || !*item->key) continue; */
1291 if (!strcasecmp(item->key, "Multiplier")) {
1292 cna_config_get_multiplier (item, service);
1293 } else if (!strcasecmp(item->key, "GetBusy")) {
1294 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_SYSTEM_CPU);
1297 } /* }}} void cna_config_disk */
1299 /* Corresponds to a <GetWaflPerfData /> block */
1300 static void cna_config_wafl(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1302 cfg_service_t *service;
1303 data_wafl_t *perf_wafl;
1305 service = malloc(sizeof(*service));
1306 if (service == NULL)
1308 memset (service, 0, sizeof (*service));
1311 service->handler = query_wafl_data;
1312 perf_wafl = service->data = malloc(sizeof(*perf_wafl));
1313 perf_wafl->flags = CFG_WAFL_ALL;
1315 for (i = 0; i < ci->children_num; ++i) {
1316 oconfig_item_t *item = ci->children + i;
1318 if (!strcasecmp(item->key, "Multiplier")) {
1319 cna_config_get_multiplier (item, service);
1320 } else if (!strcasecmp(item->key, "GetNameCache")) {
1321 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_NAME_CACHE);
1322 } else if (!strcasecmp(item->key, "GetDirCache")) {
1323 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_DIR_CACHE);
1324 } else if (!strcasecmp(item->key, "GetBufCache")) {
1325 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_BUF_CACHE);
1326 } else if (!strcasecmp(item->key, "GetInodeCache")) {
1327 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_INODE_CACHE);
1329 WARNING ("netapp plugin: The %s config option is not allowed within "
1330 "`GetWaflPerfData' blocks.", item->key);
1334 service->next = host->services;
1335 host->services = service;
1336 } /* }}} void cna_config_wafl */
1338 /* Corresponds to a <GetSystemPerfData /> block */
1339 static int cna_config_system (host_config_t *host, /* {{{ */
1340 oconfig_item_t *ci, const cfg_service_t *default_service)
1343 cfg_service_t *service;
1344 cfg_system_t *cfg_system;
1346 service = malloc(sizeof(*service));
1347 if (service == NULL)
1349 memset (service, 0, sizeof (*service));
1350 *service = *default_service;
1351 service->handler = collect_perf_system_data;
1353 cfg_system = malloc(sizeof(*cfg_system));
1354 if (cfg_system == NULL) {
1358 memset (cfg_system, 0, sizeof (*cfg_system));
1359 cfg_system->flags = CFG_SYSTEM_ALL;
1360 service->data = cfg_system;
1362 for (i = 0; i < ci->children_num; ++i) {
1363 oconfig_item_t *item = ci->children + i;
1365 if (!strcasecmp(item->key, "Multiplier")) {
1366 cna_config_get_multiplier (item, service);
1367 } else if (!strcasecmp(item->key, "GetCPULoad")) {
1368 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
1369 } else if (!strcasecmp(item->key, "GetInterfaces")) {
1370 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
1371 } else if (!strcasecmp(item->key, "GetDiskOps")) {
1372 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
1373 } else if (!strcasecmp(item->key, "GetDiskIO")) {
1374 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
1376 WARNING ("netapp plugin: The %s config option is not allowed within "
1377 "`GetSystemPerfData' blocks.", item->key);
1381 service->next = host->services;
1382 host->services = service;
1385 } /* }}} int cna_config_system */
1387 /* Corresponds to a <Host /> block. */
1388 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
1389 const host_config_t *default_host, const cfg_service_t *def_def_service)
1391 oconfig_item_t *item;
1392 host_config_t *host, *hc;
1393 cfg_service_t default_service = *def_def_service;
1397 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1398 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
1402 host = malloc(sizeof(*host));
1403 memcpy (host, default_host, sizeof (*host));
1405 status = cf_util_get_string (ci, &host->name);
1412 for (i = 0; i < ci->children_num; ++i) {
1413 item = ci->children + i;
1417 if (!strcasecmp(item->key, "Address")) {
1418 status = cf_util_get_string (item, &host->host);
1419 } else if (!strcasecmp(item->key, "Port")) {
1422 tmp = cf_util_get_port_number (item);
1425 } else if (!strcasecmp(item->key, "Protocol")) {
1426 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"))) {
1427 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
1430 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
1431 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
1432 } else if (!strcasecmp(item->key, "User")) {
1433 status = cf_util_get_string (item, &host->username);
1434 } else if (!strcasecmp(item->key, "Password")) {
1435 status = cf_util_get_string (item, &host->password);
1436 } else if (!strcasecmp(item->key, "Interval")) {
1437 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) {
1438 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
1441 host->interval = item->values[0].value.number;
1442 } else if (!strcasecmp(item->key, "GetVolumePerfData")) {
1443 cna_config_volume_performance(host, item);
1444 } else if (!strcasecmp(item->key, "GetSystemPerfData")) {
1445 cna_config_system(host, item, &default_service);
1446 } else if (!strcasecmp(item->key, "GetWaflPerfData")) {
1447 cna_config_wafl(host, item);
1448 } else if (!strcasecmp(item->key, "GetDiskPerfData")) {
1449 cna_config_disk(host, item);
1450 } else if (!strcasecmp(item->key, "GetVolumeData")) {
1451 cna_config_volume_usage(host, item);
1453 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
1454 item->key, ci->values[0].value.string);
1461 if (host->host == NULL)
1462 host->host = strdup (host->name);
1464 if (host->host == NULL)
1467 if (host->port <= 0)
1468 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
1470 if ((host->username == NULL) || (host->password == NULL)) {
1471 WARNING("netapp plugin: Please supply login information for host \"%s\". "
1472 "Ignoring host block.", host->name);
1478 free_host_config (host);
1483 } /* }}} host_config_t *cna_config_host */
1486 * Callbacks registered with the daemon
1488 * Pretty standard stuff here.
1490 static int cna_init(void) { /* {{{ */
1493 host_config_t *host;
1494 cfg_service_t *service;
1496 if (!global_host_config) {
1497 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
1501 if (!na_startup(err, sizeof(err))) {
1502 ERROR("netapp plugin: Error initializing netapp API: %s", err);
1506 for (host = global_host_config; host; host = host->next) {
1507 host->srv = na_server_open(host->host, 1, 1);
1508 na_server_set_transport_type(host->srv, host->protocol, 0);
1509 na_server_set_port(host->srv, host->port);
1510 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
1511 na_server_adminuser(host->srv, host->username, host->password);
1512 na_server_set_timeout(host->srv, 5);
1513 for (service = host->services; service; service = service->next) {
1514 service->interval = host->interval * service->multiplier;
1515 if (service->handler == collect_perf_system_data) {
1516 service->query = na_elem_new("perf-object-get-instances");
1517 na_child_add_string(service->query, "objectname", "system");
1518 } else if (service->handler == query_volume_perf_data) {
1519 service->query = na_elem_new("perf-object-get-instances");
1520 na_child_add_string(service->query, "objectname", "volume");
1521 /* e = na_elem_new("instances");
1522 na_child_add_string(e, "foo", "system");
1523 na_child_add(root, e);*/
1524 e = na_elem_new("counters");
1525 /* "foo" means: This string has to be here but
1526 the content doesn't matter. */
1527 na_child_add_string(e, "foo", "read_ops");
1528 na_child_add_string(e, "foo", "write_ops");
1529 na_child_add_string(e, "foo", "read_data");
1530 na_child_add_string(e, "foo", "write_data");
1531 na_child_add_string(e, "foo", "read_latency");
1532 na_child_add_string(e, "foo", "write_latency");
1533 na_child_add(service->query, e);
1534 } else if (service->handler == query_wafl_data) {
1535 service->query = na_elem_new("perf-object-get-instances");
1536 na_child_add_string(service->query, "objectname", "wafl");
1537 /* e = na_elem_new("instances");
1538 na_child_add_string(e, "foo", "system");
1539 na_child_add(root, e);*/
1540 e = na_elem_new("counters");
1541 na_child_add_string(e, "foo", "name_cache_hit");
1542 na_child_add_string(e, "foo", "name_cache_miss");
1543 na_child_add_string(e, "foo", "find_dir_hit");
1544 na_child_add_string(e, "foo", "find_dir_miss");
1545 na_child_add_string(e, "foo", "buf_hash_hit");
1546 na_child_add_string(e, "foo", "buf_hash_miss");
1547 na_child_add_string(e, "foo", "inode_cache_hit");
1548 na_child_add_string(e, "foo", "inode_cache_miss");
1549 /* na_child_add_string(e, "foo", "inode_eject_time"); */
1550 /* na_child_add_string(e, "foo", "buf_eject_time"); */
1551 na_child_add(service->query, e);
1552 } else if (service->handler == query_submit_disk_data) {
1553 service->query = na_elem_new("perf-object-get-instances");
1554 na_child_add_string(service->query, "objectname", "disk");
1555 e = na_elem_new("counters");
1556 na_child_add_string(e, "foo", "disk_busy");
1557 na_child_add_string(e, "foo", "base_for_disk_busy");
1558 na_child_add(service->query, e);
1559 } else if (service->handler == collect_volume_data) {
1560 service->query = na_elem_new("volume-list-info");
1561 /* na_child_add_string(service->query, "objectname", "volume"); */
1562 /* } else if (service->handler == collect_snapshot_data) { */
1563 /* service->query = na_elem_new("snapshot-list-info"); */
1568 } /* }}} int cna_init */
1570 static int cna_config (oconfig_item_t *ci) { /* {{{ */
1572 oconfig_item_t *item;
1573 host_config_t default_host = HOST_INIT;
1574 cfg_service_t default_service = SERVICE_INIT;
1576 for (i = 0; i < ci->children_num; ++i) {
1577 item = ci->children + i;
1579 if (!strcasecmp(item->key, "Host")) {
1580 host_config_t *host;
1583 host = cna_config_host(item, &default_host, &default_service);
1587 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
1589 if (strcasecmp (host->name, tmp->name) == 0)
1590 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
1591 "This is probably a bad idea.",
1594 if (tmp->next == NULL)
1600 global_host_config = host;
1604 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
1608 } /* }}} int cna_config */
1610 static int cna_read(void) { /* {{{ */
1612 host_config_t *host;
1613 cfg_service_t *service;
1615 for (host = global_host_config; host; host = host->next) {
1616 for (service = host->services; service; service = service->next) {
1617 if (--service->skip_countdown > 0) continue;
1618 service->skip_countdown = service->multiplier;
1619 out = na_server_invoke_elem(host->srv, service->query);
1620 if (na_results_status(out) != NA_OK) {
1621 int netapp_errno = na_results_errno(out);
1622 ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
1624 if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
1625 /* Network problems. Just give up on all other services on this host. */
1630 service->handler(host, out, service->data);
1635 } /* }}} int cna_read */
1637 void module_register(void) {
1638 plugin_register_complex_config("netapp", cna_config);
1639 plugin_register_init("netapp", cna_init);
1640 plugin_register_read("netapp", cna_read);
1643 /* vim: set sw=2 ts=2 noet fdm=marker : */