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 VOLUME_INIT 0x01
137 #define VOLUME_DF 0x02
138 #define VOLUME_SNAP 0x04
141 } cfg_volume_usage_t;
143 typedef struct service_config_s {
145 service_handler_t *handler;
150 struct service_config_s *next;
152 #define SERVICE_INIT {0, 0, 1, 1, 0, 0, 0}
155 * \brief Struct representing a volume.
157 * A volume currently has a name and two sets of values:
159 * - Performance data, such as bytes read/written, number of operations
160 * performed and average time per operation.
162 * - Usage data, i. e. amount of used and free space in the volume.
164 typedef struct volume_s {
166 data_volume_perf_t perf_data;
167 cfg_volume_usage_t cfg_volume_usage;
168 struct volume_s *next;
171 #define CFG_DISK_BUSIEST 0x01
172 #define CFG_DISK_ALL 0x01
173 #define HAVE_DISK_BUSY 0x10
174 #define HAVE_DISK_BASE 0x20
175 #define HAVE_DISK_ALL 0x30
181 * \brief A disk in the NetApp.
183 * A disk doesn't have any more information than its name at the moment.
184 * The name includes the "disk_" prefix.
186 typedef struct disk_s {
191 uint64_t base_for_disk_busy;
192 double disk_busy_percent;
196 struct host_config_s {
199 na_server_transport_t protocol;
205 cfg_service_t *services;
208 struct host_config_s *next;
210 #define HOST_INIT {NULL, NULL, NA_SERVER_TRANSPORT_HTTPS, NULL, 0, NULL, NULL, 10, NULL, NULL, NULL, NULL}
212 static host_config_t *global_host_config;
217 * Used to free the various structures above.
219 static void free_volume (volume_t *volume) /* {{{ */
225 sfree (volume->name);
229 } /* }}} void free_volume */
231 static void free_disk (disk_t *disk) /* {{{ */
241 } /* }}} void free_disk */
243 static void free_cfg_service (cfg_service_t *service) /* {{{ */
247 next = service->next;
249 /* FIXME: Free service->data? */
252 free_cfg_service (next);
253 } /* }}} void free_cfg_service */
255 static void free_host_config (host_config_t *hc) /* {{{ */
266 sfree (hc->username);
267 sfree (hc->password);
269 free_cfg_service (hc->services);
270 free_disk (hc->disks);
271 free_volume (hc->volumes);
275 free_host_config (next);
276 } /* }}} void free_host_config */
279 * Auxiliary functions
281 * Used to look up volumes and disks or to handle flags.
283 static volume_t *get_volume (host_config_t *host, const char *name, /* {{{ */
284 uint32_t vol_usage_flags, uint32_t vol_perf_flags)
291 /* Make sure the default flags include the init-bit. */
292 if (vol_usage_flags != 0)
293 vol_usage_flags |= VOLUME_INIT;
294 if (vol_perf_flags != 0)
295 vol_perf_flags |= CFG_VOLUME_PERF_INIT;
297 for (v = host->volumes; v; v = v->next) {
298 if (strcmp(v->name, name) != 0)
301 /* Check if the flags have been initialized. */
302 if (((v->cfg_volume_usage.flags & VOLUME_INIT) == 0)
303 && (vol_usage_flags != 0))
304 v->cfg_volume_usage.flags = vol_usage_flags;
305 if (((v->perf_data.flags & CFG_VOLUME_PERF_INIT) == 0)
306 && (vol_perf_flags != 0))
307 v->perf_data.flags = vol_perf_flags;
312 DEBUG ("netapp plugin: Allocating new entry for volume %s.", name);
313 v = malloc(sizeof(*v));
316 memset (v, 0, sizeof (*v));
318 v->cfg_volume_usage.flags = vol_usage_flags;
319 v->perf_data.flags = vol_perf_flags;
321 v->name = strdup(name);
322 if (v->name == NULL) {
327 v->next = host->volumes;
331 } /* }}} volume_t *get_volume */
333 static disk_t *get_disk(host_config_t *host, const char *name) /* {{{ */
340 for (v = host->disks; v; v = v->next) {
341 if (strcmp(v->name, name) == 0)
344 v = malloc(sizeof(*v));
347 memset (v, 0, sizeof (*v));
350 v->name = strdup(name);
351 if (v->name == NULL) {
356 v->next = host->disks;
360 } /* }}} disk_t *get_disk */
362 static void host_set_all_perf_data_flags(const host_config_t *host, /* {{{ */
363 uint32_t flag, _Bool set)
367 for (v = host->volumes; v; v = v->next) {
369 v->perf_data.flags |= flag;
371 v->perf_data.flags &= ~flag;
373 } /* }}} void host_set_all_perf_data_flags */
375 static void host_set_all_cfg_volume_usage_flags(const host_config_t *host, /* {{{ */
376 uint32_t flag, _Bool set) {
379 for (v = host->volumes; v; v = v->next) {
381 v->cfg_volume_usage.flags |= flag;
383 v->cfg_volume_usage.flags &= ~flag;
385 } /* }}} void host_set_all_cfg_volume_usage_flags */
388 * Various submit functions.
390 * They all eventually call "submit_values" which creates a value_list_t and
391 * dispatches it to the daemon.
393 static int submit_values (const char *host, /* {{{ */
394 const char *plugin_inst,
395 const char *type, const char *type_inst,
396 value_t *values, int values_len,
399 value_list_t vl = VALUE_LIST_INIT;
402 vl.values_len = values_len;
408 sstrncpy (vl.host, host, sizeof (vl.host));
410 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
411 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
412 if (plugin_inst != NULL)
413 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
414 sstrncpy (vl.type, type, sizeof (vl.type));
415 if (type_inst != NULL)
416 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
418 return (plugin_dispatch_values (&vl));
419 } /* }}} int submit_uint64 */
421 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
422 const char *type, const char *type_inst, counter_t val0, counter_t val1,
427 values[0].counter = val0;
428 values[1].counter = val1;
430 return (submit_values (host, plugin_inst, type, type_inst,
431 values, 2, timestamp));
432 } /* }}} int submit_two_counters */
434 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
435 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
441 return (submit_values (host, plugin_inst, type, type_inst,
443 } /* }}} int submit_counter */
445 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
446 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
451 values[0].gauge = val0;
452 values[1].gauge = val1;
454 return (submit_values (host, plugin_inst, type, type_inst,
455 values, 2, timestamp));
456 } /* }}} int submit_two_gauge */
458 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
459 const char *type, const char *type_inst, double d, time_t timestamp)
463 v.gauge = (gauge_t) d;
465 return (submit_values (host, plugin_inst, type, type_inst,
467 } /* }}} int submit_uint64 */
469 /* Calculate hit ratio from old and new counters and submit the resulting
470 * percentage. Used by "submit_wafl_data". */
471 static int submit_cache_ratio (const char *host, /* {{{ */
472 const char *plugin_inst,
473 const char *type_inst,
482 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
486 hits = new_hits - old_hits;
487 misses = new_misses - old_misses;
489 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
494 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
496 } /* }}} int submit_cache_ratio */
498 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
499 static int submit_wafl_data (const host_config_t *host, const char *instance, /* {{{ */
500 data_wafl_t *old_data, const data_wafl_t *new_data)
502 /* Submit requested counters */
503 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
504 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
505 submit_cache_ratio (host->name, instance, "name_cache_hit",
506 new_data->name_cache_hit, new_data->name_cache_miss,
507 old_data->name_cache_hit, old_data->name_cache_miss,
508 new_data->timestamp);
510 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
511 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
512 submit_cache_ratio (host->name, instance, "find_dir_hit",
513 new_data->find_dir_hit, new_data->find_dir_miss,
514 old_data->find_dir_hit, old_data->find_dir_miss,
515 new_data->timestamp);
517 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
518 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
519 submit_cache_ratio (host->name, instance, "buf_hash_hit",
520 new_data->buf_hash_hit, new_data->buf_hash_miss,
521 old_data->buf_hash_hit, old_data->buf_hash_miss,
522 new_data->timestamp);
524 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
525 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
526 submit_cache_ratio (host->name, instance, "inode_cache_hit",
527 new_data->inode_cache_hit, new_data->inode_cache_miss,
528 old_data->inode_cache_hit, old_data->inode_cache_miss,
529 new_data->timestamp);
531 /* Clear old HAVE_* flags */
532 old_data->flags &= ~HAVE_WAFL_ALL;
534 /* Copy all counters */
535 old_data->timestamp = new_data->timestamp;
536 old_data->name_cache_hit = new_data->name_cache_hit;
537 old_data->name_cache_miss = new_data->name_cache_miss;
538 old_data->find_dir_hit = new_data->find_dir_hit;
539 old_data->find_dir_miss = new_data->find_dir_miss;
540 old_data->buf_hash_hit = new_data->buf_hash_hit;
541 old_data->buf_hash_miss = new_data->buf_hash_miss;
542 old_data->inode_cache_hit = new_data->inode_cache_hit;
543 old_data->inode_cache_miss = new_data->inode_cache_miss;
545 /* Copy HAVE_* flags */
546 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
549 } /* }}} int submit_wafl_data */
551 /* Submits volume performance data to the daemon, taking care to honor and
552 * update flags appropriately. */
553 static int submit_volume_perf_data (const host_config_t *host, /* {{{ */
555 const data_volume_perf_t *new_data)
557 /* Check for and submit disk-octet values */
558 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_IO)
559 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
561 submit_two_counters (host->name, volume->name, "disk_octets", /* type instance = */ NULL,
562 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
565 /* Check for and submit disk-operations values */
566 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_OPS)
567 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
569 submit_two_counters (host->name, volume->name, "disk_ops", /* type instance = */ NULL,
570 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
573 /* Check for, calculate and submit disk-latency values */
574 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_LATENCY
575 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
576 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
577 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
578 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
580 gauge_t latency_per_op_read;
581 gauge_t latency_per_op_write;
583 latency_per_op_read = NAN;
584 latency_per_op_write = NAN;
586 /* Check if a counter wrapped around. */
587 if ((new_data->read_ops > volume->perf_data.read_ops)
588 && (new_data->read_latency > volume->perf_data.read_latency))
590 uint64_t diff_ops_read;
591 uint64_t diff_latency_read;
593 diff_ops_read = new_data->read_ops - volume->perf_data.read_ops;
594 diff_latency_read = new_data->read_latency - volume->perf_data.read_latency;
596 if (diff_ops_read > 0)
597 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
600 if ((new_data->write_ops > volume->perf_data.write_ops)
601 && (new_data->write_latency > volume->perf_data.write_latency))
603 uint64_t diff_ops_write;
604 uint64_t diff_latency_write;
606 diff_ops_write = new_data->write_ops - volume->perf_data.write_ops;
607 diff_latency_write = new_data->write_latency - volume->perf_data.write_latency;
609 if (diff_ops_write > 0)
610 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
613 submit_two_gauge (host->name, volume->name, "disk_latency", /* type instance = */ NULL,
614 latency_per_op_read, latency_per_op_write, new_data->timestamp);
617 /* Clear all HAVE_* flags. */
618 volume->perf_data.flags &= ~HAVE_VOLUME_PERF_ALL;
620 /* Copy all counters */
621 volume->perf_data.timestamp = new_data->timestamp;
622 volume->perf_data.read_bytes = new_data->read_bytes;
623 volume->perf_data.write_bytes = new_data->write_bytes;
624 volume->perf_data.read_ops = new_data->read_ops;
625 volume->perf_data.write_ops = new_data->write_ops;
626 volume->perf_data.read_latency = new_data->read_latency;
627 volume->perf_data.write_latency = new_data->write_latency;
629 /* Copy the HAVE_* flags */
630 volume->perf_data.flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
633 } /* }}} int submit_volume_perf_data */
638 * These functions are called with appropriate data returned by the libnetapp
639 * interface which is parsed and submitted with the above functions.
641 /* Data corresponding to <GetWaflPerfData /> */
642 static void query_wafl_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
643 data_wafl_t *wafl = data;
644 data_wafl_t perf_data;
645 const char *plugin_inst;
648 memset (&perf_data, 0, sizeof (perf_data));
650 perf_data.timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
652 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
656 plugin_inst = na_child_get_string(out, "name");
657 if (plugin_inst == NULL)
660 /* Iterate over all counters */
661 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
662 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
666 name = na_child_get_string(counter, "name");
670 value = na_child_get_uint64(counter, "value", UINT64_MAX);
671 if (value == UINT64_MAX)
674 if (!strcmp(name, "name_cache_hit")) {
675 perf_data.name_cache_hit = value;
676 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
677 } else if (!strcmp(name, "name_cache_miss")) {
678 perf_data.name_cache_miss = value;
679 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
680 } else if (!strcmp(name, "find_dir_hit")) {
681 perf_data.find_dir_hit = value;
682 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
683 } else if (!strcmp(name, "find_dir_miss")) {
684 perf_data.find_dir_miss = value;
685 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
686 } else if (!strcmp(name, "buf_hash_hit")) {
687 perf_data.buf_hash_hit = value;
688 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
689 } else if (!strcmp(name, "buf_hash_miss")) {
690 perf_data.buf_hash_miss = value;
691 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
692 } else if (!strcmp(name, "inode_cache_hit")) {
693 perf_data.inode_cache_hit = value;
694 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
695 } else if (!strcmp(name, "inode_cache_miss")) {
696 perf_data.inode_cache_miss = value;
697 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
699 DEBUG("netapp plugin: query_wafl_data: Found unexpected child: %s",
704 submit_wafl_data (host, plugin_inst, wafl, &perf_data);
705 } /* }}} void query_wafl_data */
707 /* Data corresponding to <GetDiskPerfData /> */
708 static void query_submit_disk_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
709 cfg_disk_t *cfg_disk = data;
711 na_elem_t *counter, *inst;
712 disk_t *worst_disk = 0;
714 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
715 out = na_elem_child(out, "instances");
717 /* Iterate over all children */
718 na_elem_iter_t inst_iter = na_child_iterator(out);
719 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
723 memset (&new_data, 0, sizeof (new_data));
724 new_data.timestamp = timestamp;
725 new_data.disk_busy_percent = NAN;
727 old_data = get_disk(host, na_child_get_string(inst, "name"));
728 if (old_data == NULL)
731 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
732 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
733 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
737 name = na_child_get_string(counter, "name");
741 value = na_child_get_uint64(counter, "value", UINT64_MAX);
742 if (value == UINT64_MAX)
745 if (strcmp(name, "disk_busy") == 0)
747 new_data.disk_busy = value;
748 new_data.flags |= HAVE_DISK_BUSY;
750 else if (strcmp(name, "base_for_disk_busy") == 0)
752 new_data.base_for_disk_busy = value;
753 new_data.flags |= HAVE_DISK_BASE;
757 /* If all required counters are available and did not just wrap around,
758 * calculate the busy percentage. Otherwise, the value is initialized to
759 * NAN at the top of the for-loop. */
760 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
761 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
762 && (new_data.disk_busy >= old_data->disk_busy)
763 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
768 busy_diff = new_data.disk_busy - old_data->disk_busy;
769 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
771 new_data.disk_busy_percent = 100.0
772 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
775 /* Clear HAVE_* flags */
776 old_data->flags &= ~HAVE_DISK_ALL;
779 old_data->timestamp = new_data.timestamp;
780 old_data->disk_busy = new_data.disk_busy;
781 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
782 old_data->disk_busy_percent = new_data.disk_busy_percent;
785 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
787 if ((worst_disk == NULL)
788 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
789 worst_disk = old_data;
790 } /* for (all disks) */
792 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
793 submit_double (host->name, "system", "percent", "disk_busy",
794 worst_disk->disk_busy_percent, timestamp);
795 } /* }}} void query_submit_disk_data */
797 /* Data corresponding to <GetVolumeData /> */
798 static void collect_volume_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
801 cfg_volume_usage_t *cfg_volume_data = data;
803 out = na_elem_child(out, "volumes");
804 na_elem_iter_t inst_iter = na_child_iterator(out);
805 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
806 uint64_t size_free = 0, size_used = 0, snap_reserved = 0;
809 const char *sis_state;
810 uint64_t sis_saved_reported;
813 volume = get_volume(host, na_child_get_string(inst, "name"),
814 cfg_volume_data->flags, /* perf_flags = */ 0);
818 if (!(volume->cfg_volume_usage.flags & VOLUME_DF))
821 /* 2^4 exa-bytes? This will take a while ;) */
822 size_free = na_child_get_uint64(inst, "size-available", UINT64_MAX);
823 if (size_free != UINT64_MAX)
824 submit_double (host->name, volume->name, "df_complex", "used",
825 (double) size_used, /* time = */ 0);
827 size_used = na_child_get_uint64(inst, "size-used", UINT64_MAX);
828 if (size_free != UINT64_MAX)
829 submit_double (host->name, volume->name, "df_complex", "free",
830 (double) size_free, /* time = */ 0);
832 snap_reserved = na_child_get_uint64(inst, "snapshot-blocks-reserved", UINT64_MAX);
833 if (snap_reserved != UINT64_MAX)
834 /* 1 block == 1024 bytes as per API docs */
835 submit_double (host->name, volume->name, "df_complex", "snap_reserved",
836 (double) (1024 * snap_reserved), /* time = */ 0);
838 sis = na_elem_child(inst, "sis");
842 sis_state = na_child_get_string(sis, "state");
843 if ((sis_state == NULL)
844 || (strcmp ("enabled", sis_state) != 0))
847 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
848 if (sis_saved_reported == UINT64_MAX)
851 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
852 if ((sis_saved_reported >> 32) != 0) {
853 /* In case they ever fix this bug. */
854 sis_saved = sis_saved_reported;
856 uint64_t sis_saved_percent;
857 uint64_t sis_saved_guess;
858 uint64_t overflow_guess;
859 uint64_t guess1, guess2, guess3;
861 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
862 if (sis_saved_percent > 100)
865 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
866 * will hopefully be fixed in later versions. To work around the bug, try
867 * to figure out how often the 32bit integer wrapped around by using the
868 * "percentage-saved" value. Because the percentage is in the range
869 * [0-100], this should work as long as the saved space does not exceed
871 /* percentage-saved = size-saved / (size-saved + size-used) */
872 if (sis_saved_percent < 100)
873 sis_saved_guess = size_used * sis_saved_percent / (100 - sis_saved_percent);
875 sis_saved_guess = size_used;
877 overflow_guess = sis_saved_guess >> 32;
878 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
879 guess2 = (overflow_guess << 32) + sis_saved_reported;
880 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
882 if (sis_saved_guess < guess2) {
883 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
888 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
893 } /* end of 32-bit workaround */
895 submit_double (host->name, volume->name, "df_complex", "sis_saved",
896 (double) sis_saved, /* time = */ 0);
898 } /* }}} void collect_volume_data */
900 /* Data corresponding to <GetVolumePerfData /> */
901 static void query_volume_perf_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
902 cfg_volume_perf_t *cfg_volume_perf = data;
904 na_elem_t *counter, *inst;
906 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
908 out = na_elem_child(out, "instances");
909 na_elem_iter_t inst_iter = na_child_iterator(out);
910 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
911 data_volume_perf_t perf_data;
914 memset (&perf_data, 0, sizeof (perf_data));
915 perf_data.timestamp = timestamp;
917 volume = get_volume(host, na_child_get_string(inst, "name"),
918 /* data_flags = */ 0, cfg_volume_perf->flags);
922 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
923 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
927 name = na_child_get_string(counter, "name");
931 value = na_child_get_uint64(counter, "value", UINT64_MAX);
932 if (value == UINT64_MAX)
935 if (!strcmp(name, "read_data")) {
936 perf_data.read_bytes = value;
937 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
938 } else if (!strcmp(name, "write_data")) {
939 perf_data.write_bytes = value;
940 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
941 } else if (!strcmp(name, "read_ops")) {
942 perf_data.read_ops = value;
943 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
944 } else if (!strcmp(name, "write_ops")) {
945 perf_data.write_ops = value;
946 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
947 } else if (!strcmp(name, "read_latency")) {
948 perf_data.read_latency = value;
949 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
950 } else if (!strcmp(name, "write_latency")) {
951 perf_data.write_latency = value;
952 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
956 submit_volume_perf_data (host, volume, &perf_data);
958 } /* }}} void query_volume_perf_data */
960 /* Data corresponding to <GetSystemPerfData /> */
961 static void collect_perf_system_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
962 counter_t disk_read = 0, disk_written = 0;
963 counter_t net_recv = 0, net_sent = 0;
964 counter_t cpu_busy = 0, cpu_total = 0;
965 unsigned int counter_flags = 0;
967 cfg_system_t *cfg_system = data;
968 const char *instance;
972 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
973 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
974 instance = na_child_get_string(out, "name");
976 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
977 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
981 name = na_child_get_string(counter, "name");
985 value = na_child_get_uint64(counter, "value", UINT64_MAX);
986 if (value == UINT64_MAX)
989 if (!strcmp(name, "disk_data_read")) {
990 disk_read = (counter_t) (value * 1024);
991 counter_flags |= 0x01;
992 } else if (!strcmp(name, "disk_data_written")) {
993 disk_written = (counter_t) (value * 1024);
994 counter_flags |= 0x02;
995 } else if (!strcmp(name, "net_data_recv")) {
996 net_recv = (counter_t) (value * 1024);
997 counter_flags |= 0x04;
998 } else if (!strcmp(name, "net_data_sent")) {
999 net_sent = (counter_t) (value * 1024);
1000 counter_flags |= 0x08;
1001 } else if (!strcmp(name, "cpu_busy")) {
1002 cpu_busy = (counter_t) value;
1003 counter_flags |= 0x10;
1004 } else if (!strcmp(name, "cpu_elapsed_time")) {
1005 cpu_total = (counter_t) value;
1006 counter_flags |= 0x20;
1007 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1008 && (strlen(name) > 4)
1009 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1010 submit_counter (host->name, instance, "disk_ops_complex", name,
1011 (counter_t) value, timestamp);
1013 } /* for (counter) */
1015 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1016 && ((counter_flags & 0x03) == 0x03))
1017 submit_two_counters (host->name, instance, "disk_octets", NULL,
1018 disk_read, disk_written, timestamp);
1020 if ((cfg_system->flags & CFG_SYSTEM_NET)
1021 && ((counter_flags & 0x0c) == 0x0c))
1022 submit_two_counters (host->name, instance, "if_octets", NULL,
1023 net_recv, net_sent, timestamp);
1025 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1026 && ((counter_flags & 0x30) == 0x30)) {
1027 submit_counter (host->name, instance, "cpu", "system",
1028 cpu_busy, timestamp);
1029 submit_counter (host->name, instance, "cpu", "idle",
1030 cpu_total - cpu_busy, timestamp);
1032 } /* }}} void collect_perf_system_data */
1035 * Configuration handling
1037 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1038 * is false. On error, the flag-field is not changed. */
1039 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1040 uint32_t *flags, uint32_t flag)
1042 if ((ci == NULL) || (flags == NULL))
1045 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1047 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1052 if (ci->values[0].value.boolean)
1058 } /* }}} int cna_config_bool_to_flag */
1060 /* Handling of the "Multiplier" option which is allowed in every block. */
1061 static int cna_config_get_multiplier (const oconfig_item_t *ci, /* {{{ */
1062 cfg_service_t *service)
1066 if ((ci == NULL) || (service == NULL))
1069 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1071 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1075 tmp = (int) (ci->values[0].value.number + .5);
1078 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1082 service->multiplier = tmp;
1083 service->skip_countdown = tmp;
1086 } /* }}} int cna_config_get_multiplier */
1088 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1089 * <GetVolumePerfData /> block. */
1090 static void cna_config_volume_performance_option (host_config_t *host, /* {{{ */
1091 cfg_volume_perf_t *perf_volume, const oconfig_item_t *item,
1096 for (i = 0; i < item->values_num; ++i) {
1101 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1102 WARNING("netapp plugin: Ignoring non-string argument in "
1103 "\"GetVolumePerfData\" block for host %s", host->name);
1107 name = item->values[i].value.string;
1108 if (name[0] == '+') {
1111 } else if (name[0] == '-') {
1118 perf_volume->flags |= flag;
1119 else /* if (!set) */
1120 perf_volume->flags &= ~flag;
1122 host_set_all_perf_data_flags(host, flag, set);
1126 v = get_volume (host, name, /* data_flags = */ 0, perf_volume->flags);
1131 v->perf_data.flags |= flag;
1132 else /* if (!set) */
1133 v->perf_data.flags &= ~flag;
1134 } /* for (i = 0 .. item->values_num) */
1135 } /* }}} void cna_config_volume_performance_option */
1137 /* Corresponds to a <GetVolumePerfData /> block */
1138 static void cna_config_volume_performance(host_config_t *host, const oconfig_item_t *ci) { /* {{{ */
1139 int i, had_io = 0, had_ops = 0, had_latency = 0;
1140 cfg_service_t *service;
1141 cfg_volume_perf_t *perf_volume;
1143 service = malloc(sizeof(*service));
1145 service->handler = query_volume_perf_data;
1146 perf_volume = service->data = malloc(sizeof(*perf_volume));
1147 perf_volume->flags = CFG_VOLUME_PERF_INIT;
1148 service->next = host->services;
1149 host->services = service;
1150 for (i = 0; i < ci->children_num; ++i) {
1151 oconfig_item_t *item = ci->children + i;
1153 /* if (!item || !item->key || !*item->key) continue; */
1154 if (!strcasecmp(item->key, "Multiplier")) {
1155 cna_config_get_multiplier (item, service);
1156 } else if (!strcasecmp(item->key, "GetIO")) {
1158 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_IO);
1159 } else if (!strcasecmp(item->key, "GetOps")) {
1161 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_OPS);
1162 } else if (!strcasecmp(item->key, "GetLatency")) {
1164 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_LATENCY);
1168 perf_volume->flags |= CFG_VOLUME_PERF_IO;
1169 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_IO, /* set = */ true);
1172 perf_volume->flags |= CFG_VOLUME_PERF_OPS;
1173 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_OPS, /* set = */ true);
1176 perf_volume->flags |= CFG_VOLUME_PERF_LATENCY;
1177 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_LATENCY, /* set = */ true);
1179 } /* }}} void cna_config_volume_performance */
1181 /* Handling of the "GetDiskUtil" option within a <GetVolumeData /> block. */
1182 static void cna_config_volume_usage_option (host_config_t *host, /* {{{ */
1183 cfg_volume_usage_t *cfg_volume_data, const oconfig_item_t *item, uint32_t flag)
1187 for (i = 0; i < item->values_num; ++i) {
1192 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1193 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolData\""
1194 "block for host %s", host->name);
1198 name = item->values[i].value.string;
1199 if (name[0] == '+') {
1202 } else if (name[0] == '-') {
1209 cfg_volume_data->flags |= flag;
1210 else /* if (!set) */
1211 cfg_volume_data->flags &= ~flag;
1213 host_set_all_cfg_volume_usage_flags(host, flag, set);
1217 v = get_volume(host, name, cfg_volume_data->flags, /* perf_flags = */ 0);
1221 if (!v->cfg_volume_usage.flags)
1222 v->cfg_volume_usage.flags = cfg_volume_data->flags;
1225 v->cfg_volume_usage.flags |= flag;
1226 else /* if (!set) */
1227 v->cfg_volume_usage.flags &= ~flag;
1229 } /* }}} void cna_config_volume_usage_option */
1231 /* Corresponds to a <GetVolumeData /> block */
1232 static void cna_config_volume_usage(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1234 cfg_service_t *service;
1235 cfg_volume_usage_t *cfg_volume_data;
1237 service = malloc(sizeof(*service));
1239 service->handler = collect_volume_data;
1240 cfg_volume_data = service->data = malloc(sizeof(*cfg_volume_data));
1241 cfg_volume_data->flags = VOLUME_INIT;
1242 service->next = host->services;
1243 host->services = service;
1244 for (i = 0; i < ci->children_num; ++i) {
1245 oconfig_item_t *item = ci->children + i;
1247 /* if (!item || !item->key || !*item->key) continue; */
1248 if (!strcasecmp(item->key, "Multiplier")) {
1249 cna_config_get_multiplier (item, service);
1250 } else if (!strcasecmp(item->key, "GetDiskUtil")) {
1252 cna_config_volume_usage_option(host, cfg_volume_data, item, VOLUME_DF);
1256 cfg_volume_data->flags |= VOLUME_DF;
1257 host_set_all_cfg_volume_usage_flags(host, VOLUME_DF, /* set = */ true);
1259 } /* }}} void cna_config_volume_usage */
1261 /* Corresponds to a <GetDiskPerfData /> block */
1262 static void cna_config_disk(host_config_t *temp, oconfig_item_t *ci) { /* {{{ */
1264 cfg_service_t *service;
1265 cfg_disk_t *cfg_disk;
1267 service = malloc(sizeof(*service));
1269 service->handler = query_submit_disk_data;
1270 cfg_disk = service->data = malloc(sizeof(*cfg_disk));
1271 cfg_disk->flags = CFG_DISK_ALL;
1272 service->next = temp->services;
1273 temp->services = service;
1274 for (i = 0; i < ci->children_num; ++i) {
1275 oconfig_item_t *item = ci->children + i;
1277 /* if (!item || !item->key || !*item->key) continue; */
1278 if (!strcasecmp(item->key, "Multiplier")) {
1279 cna_config_get_multiplier (item, service);
1280 } else if (!strcasecmp(item->key, "GetBusy")) {
1281 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
1284 } /* }}} void cna_config_disk */
1286 /* Corresponds to a <GetWaflPerfData /> block */
1287 static void cna_config_wafl(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1289 cfg_service_t *service;
1290 data_wafl_t *perf_wafl;
1292 service = malloc(sizeof(*service));
1293 if (service == NULL)
1295 memset (service, 0, sizeof (*service));
1298 service->handler = query_wafl_data;
1299 perf_wafl = service->data = malloc(sizeof(*perf_wafl));
1300 perf_wafl->flags = CFG_WAFL_ALL;
1302 for (i = 0; i < ci->children_num; ++i) {
1303 oconfig_item_t *item = ci->children + i;
1305 if (!strcasecmp(item->key, "Multiplier")) {
1306 cna_config_get_multiplier (item, service);
1307 } else if (!strcasecmp(item->key, "GetNameCache")) {
1308 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_NAME_CACHE);
1309 } else if (!strcasecmp(item->key, "GetDirCache")) {
1310 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_DIR_CACHE);
1311 } else if (!strcasecmp(item->key, "GetBufCache")) {
1312 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_BUF_CACHE);
1313 } else if (!strcasecmp(item->key, "GetInodeCache")) {
1314 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_INODE_CACHE);
1316 WARNING ("netapp plugin: The %s config option is not allowed within "
1317 "`GetWaflPerfData' blocks.", item->key);
1321 service->next = host->services;
1322 host->services = service;
1323 } /* }}} void cna_config_wafl */
1325 /* Corresponds to a <GetSystemPerfData /> block */
1326 static int cna_config_system (host_config_t *host, /* {{{ */
1327 oconfig_item_t *ci, const cfg_service_t *default_service)
1330 cfg_service_t *service;
1331 cfg_system_t *cfg_system;
1333 service = malloc(sizeof(*service));
1334 if (service == NULL)
1336 memset (service, 0, sizeof (*service));
1337 *service = *default_service;
1338 service->handler = collect_perf_system_data;
1340 cfg_system = malloc(sizeof(*cfg_system));
1341 if (cfg_system == NULL) {
1345 memset (cfg_system, 0, sizeof (*cfg_system));
1346 cfg_system->flags = CFG_SYSTEM_ALL;
1347 service->data = cfg_system;
1349 for (i = 0; i < ci->children_num; ++i) {
1350 oconfig_item_t *item = ci->children + i;
1352 if (!strcasecmp(item->key, "Multiplier")) {
1353 cna_config_get_multiplier (item, service);
1354 } else if (!strcasecmp(item->key, "GetCPULoad")) {
1355 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
1356 } else if (!strcasecmp(item->key, "GetInterfaces")) {
1357 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
1358 } else if (!strcasecmp(item->key, "GetDiskOps")) {
1359 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
1360 } else if (!strcasecmp(item->key, "GetDiskIO")) {
1361 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
1363 WARNING ("netapp plugin: The %s config option is not allowed within "
1364 "`GetSystemPerfData' blocks.", item->key);
1368 service->next = host->services;
1369 host->services = service;
1372 } /* }}} int cna_config_system */
1374 /* Corresponds to a <Host /> block. */
1375 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
1376 const host_config_t *default_host, const cfg_service_t *def_def_service)
1378 oconfig_item_t *item;
1379 host_config_t *host, *hc;
1380 cfg_service_t default_service = *def_def_service;
1384 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1385 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
1389 host = malloc(sizeof(*host));
1390 memcpy (host, default_host, sizeof (*host));
1392 status = cf_util_get_string (ci, &host->name);
1399 for (i = 0; i < ci->children_num; ++i) {
1400 item = ci->children + i;
1404 if (!strcasecmp(item->key, "Address")) {
1405 status = cf_util_get_string (item, &host->host);
1406 } else if (!strcasecmp(item->key, "Port")) {
1409 tmp = cf_util_get_port_number (item);
1412 } else if (!strcasecmp(item->key, "Protocol")) {
1413 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"))) {
1414 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
1417 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
1418 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
1419 } else if (!strcasecmp(item->key, "User")) {
1420 status = cf_util_get_string (item, &host->username);
1421 } else if (!strcasecmp(item->key, "Password")) {
1422 status = cf_util_get_string (item, &host->password);
1423 } else if (!strcasecmp(item->key, "Interval")) {
1424 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) {
1425 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
1428 host->interval = item->values[0].value.number;
1429 } else if (!strcasecmp(item->key, "GetVolumePerfData")) {
1430 cna_config_volume_performance(host, item);
1431 } else if (!strcasecmp(item->key, "GetSystemPerfData")) {
1432 cna_config_system(host, item, &default_service);
1433 } else if (!strcasecmp(item->key, "GetWaflPerfData")) {
1434 cna_config_wafl(host, item);
1435 } else if (!strcasecmp(item->key, "GetDiskPerfData")) {
1436 cna_config_disk(host, item);
1437 } else if (!strcasecmp(item->key, "GetVolumeData")) {
1438 cna_config_volume_usage(host, item);
1440 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
1441 item->key, ci->values[0].value.string);
1448 if (host->host == NULL)
1449 host->host = strdup (host->name);
1451 if (host->host == NULL)
1454 if (host->port <= 0)
1455 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
1457 if ((host->username == NULL) || (host->password == NULL)) {
1458 WARNING("netapp plugin: Please supply login information for host \"%s\". "
1459 "Ignoring host block.", host->name);
1465 free_host_config (host);
1469 for (hc = global_host_config; hc; hc = hc->next) {
1470 if (!strcasecmp(hc->name, host->name)) WARNING("netapp plugin: Duplicate definition of host \"%s\". This is probably a bad idea.", hc->name);
1473 } /* }}} host_config_t *cna_config_host */
1476 * Callbacks registered with the daemon
1478 * Pretty standard stuff here.
1480 static int cna_init(void) { /* {{{ */
1483 host_config_t *host;
1484 cfg_service_t *service;
1486 if (!global_host_config) {
1487 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
1491 memset (err, 0, sizeof (err));
1492 if (!na_startup(err, sizeof(err))) {
1493 err[sizeof (err) - 1] = 0;
1494 ERROR("netapp plugin: Error initializing netapp API: %s", err);
1498 for (host = global_host_config; host; host = host->next) {
1499 /* Request version 1.1 of the ONTAP API */
1500 host->srv = na_server_open(host->host,
1501 /* major version = */ 1, /* minor version = */ 1);
1502 if (host->srv == NULL) {
1503 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
1507 if (host->interval < interval_g)
1508 host->interval = interval_g;
1510 na_server_set_transport_type(host->srv, host->protocol,
1511 /* transportarg = */ NULL);
1512 na_server_set_port(host->srv, host->port);
1513 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
1514 na_server_adminuser(host->srv, host->username, host->password);
1515 na_server_set_timeout(host->srv, 5 /* seconds */);
1517 for (service = host->services; service; service = service->next) {
1518 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("counters");
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("counters");
1538 na_child_add_string(e, "foo", "name_cache_hit");
1539 na_child_add_string(e, "foo", "name_cache_miss");
1540 na_child_add_string(e, "foo", "find_dir_hit");
1541 na_child_add_string(e, "foo", "find_dir_miss");
1542 na_child_add_string(e, "foo", "buf_hash_hit");
1543 na_child_add_string(e, "foo", "buf_hash_miss");
1544 na_child_add_string(e, "foo", "inode_cache_hit");
1545 na_child_add_string(e, "foo", "inode_cache_miss");
1546 /* na_child_add_string(e, "foo", "inode_eject_time"); */
1547 /* na_child_add_string(e, "foo", "buf_eject_time"); */
1548 na_child_add(service->query, e);
1549 } else if (service->handler == query_submit_disk_data) {
1550 service->query = na_elem_new("perf-object-get-instances");
1551 na_child_add_string(service->query, "objectname", "disk");
1552 e = na_elem_new("counters");
1553 na_child_add_string(e, "foo", "disk_busy");
1554 na_child_add_string(e, "foo", "base_for_disk_busy");
1555 na_child_add(service->query, e);
1556 } else if (service->handler == collect_volume_data) {
1557 service->query = na_elem_new("volume-list-info");
1558 /* na_child_add_string(service->query, "objectname", "volume"); */
1559 /* } else if (service->handler == collect_snapshot_data) { */
1560 /* service->query = na_elem_new("snapshot-list-info"); */
1565 } /* }}} int cna_init */
1567 static int cna_config (oconfig_item_t *ci) { /* {{{ */
1569 oconfig_item_t *item;
1570 host_config_t default_host = HOST_INIT;
1571 cfg_service_t default_service = SERVICE_INIT;
1573 for (i = 0; i < ci->children_num; ++i) {
1574 item = ci->children + i;
1576 /* if (!item || !item->key || !*item->key) continue; */
1577 if (!strcasecmp(item->key, "Host")) {
1578 host_config_t *host;
1581 host = cna_config_host(item, &default_host, &default_service);
1585 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
1587 if (strcasecmp (host->name, tmp->name) == 0)
1588 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
1589 "This is probably a bad idea.",
1592 if (tmp->next == NULL)
1598 global_host_config = host;
1602 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
1606 } /* }}} int cna_config */
1608 static int cna_read(void) { /* {{{ */
1610 host_config_t *host;
1611 cfg_service_t *service;
1613 for (host = global_host_config; host; host = host->next) {
1614 for (service = host->services; service; service = service->next) {
1615 if (--service->skip_countdown > 0) continue;
1616 service->skip_countdown = service->multiplier;
1617 out = na_server_invoke_elem(host->srv, service->query);
1618 if (na_results_status(out) != NA_OK) {
1619 int netapp_errno = na_results_errno(out);
1620 ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
1622 if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
1623 /* Network problems. Just give up on all other services on this host. */
1628 service->handler(host, out, service->data);
1633 } /* }}} int cna_read */
1635 void module_register(void) {
1636 plugin_register_complex_config("netapp", cna_config);
1637 plugin_register_init("netapp", cna_init);
1638 plugin_register_read("netapp", cna_read);
1641 /* vim: set sw=2 ts=2 noet fdm=marker : */