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 <collectd at semidefinite.de>
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);
42 typedef struct cna_interval_s cna_interval_t;
45 * \brief Persistent data for system performance counters
47 #define CFG_SYSTEM_CPU 0x01
48 #define CFG_SYSTEM_NET 0x02
49 #define CFG_SYSTEM_OPS 0x04
50 #define CFG_SYSTEM_DISK 0x08
51 #define CFG_SYSTEM_ALL 0x0F
57 * \brief Persistent data for WAFL performance counters. (a.k.a. cache performance)
59 * The cache counters use old counter values to calculate a hit ratio for each
60 * counter. The "cfg_wafl_t" struct therefore contains old counter values along
61 * with flags, which are set if the counter is valid.
63 * The function "cna_handle_wafl_data" will fill a new structure of this kind
64 * with new values, then pass both, new and old data, to "submit_wafl_data".
65 * That function calculates the hit ratios, submits the calculated values and
66 * updates the old counter values for the next iteration.
68 #define CFG_WAFL_NAME_CACHE 0x0001
69 #define CFG_WAFL_DIR_CACHE 0x0002
70 #define CFG_WAFL_BUF_CACHE 0x0004
71 #define CFG_WAFL_INODE_CACHE 0x0008
72 #define CFG_WAFL_ALL 0x000F
73 #define HAVE_WAFL_NAME_CACHE_HIT 0x0100
74 #define HAVE_WAFL_NAME_CACHE_MISS 0x0200
75 #define HAVE_WAFL_NAME_CACHE (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
76 #define HAVE_WAFL_FIND_DIR_HIT 0x0400
77 #define HAVE_WAFL_FIND_DIR_MISS 0x0800
78 #define HAVE_WAFL_FIND_DIR (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
79 #define HAVE_WAFL_BUF_HASH_HIT 0x1000
80 #define HAVE_WAFL_BUF_HASH_MISS 0x2000
81 #define HAVE_WAFL_BUF_HASH (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
82 #define HAVE_WAFL_INODE_CACHE_HIT 0x4000
83 #define HAVE_WAFL_INODE_CACHE_MISS 0x8000
84 #define HAVE_WAFL_INODE_CACHE (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
85 #define HAVE_WAFL_ALL 0xff00
88 cna_interval_t interval;
92 uint64_t name_cache_hit;
93 uint64_t name_cache_miss;
94 uint64_t find_dir_hit;
95 uint64_t find_dir_miss;
96 uint64_t buf_hash_hit;
97 uint64_t buf_hash_miss;
98 uint64_t inode_cache_hit;
99 uint64_t inode_cache_miss;
103 * \brief Persistent data for volume performance data.
105 * The code below uses the difference of the operations and latency counters to
106 * calculate an average per-operation latency. For this, old counters need to
107 * be stored in the "data_volume_perf_t" structure. The byte-counters are just
108 * kept for completeness sake. The "flags" member indicates if each counter is
111 * The "query_volume_perf_data" function will fill a new struct of this type
112 * and pass both, old and new data, to "submit_volume_perf_data". In that
113 * function, the per-operation latency is calculated and dispatched, then the
114 * old counters are updated.
116 #define CFG_VOLUME_PERF_INIT 0x0001
117 #define CFG_VOLUME_PERF_IO 0x0002
118 #define CFG_VOLUME_PERF_OPS 0x0003
119 #define CFG_VOLUME_PERF_LATENCY 0x0008
120 #define CFG_VOLUME_PERF_ALL 0x000F
121 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
122 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
123 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
124 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
125 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
126 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
127 #define HAVE_VOLUME_PERF_ALL 0x03F0
136 uint64_t write_bytes;
139 uint64_t read_latency;
140 uint64_t write_latency;
141 } data_volume_perf_t;
144 * \brief Configuration struct for volume usage data (free / used).
146 #define VOLUME_INIT 0x01
147 #define VOLUME_DF 0x02
148 #define VOLUME_SNAP 0x04
151 } cfg_volume_usage_t;
153 typedef struct service_config_s {
155 service_handler_t *handler;
160 struct service_config_s *next;
162 #define SERVICE_INIT {0, 0, 1, 1, 0, 0, 0}
165 * \brief Struct representing a volume.
167 * A volume currently has a name and two sets of values:
169 * - Performance data, such as bytes read/written, number of operations
170 * performed and average time per operation.
172 * - Usage data, i. e. amount of used and free space in the volume.
174 typedef struct volume_s {
176 data_volume_perf_t perf_data;
177 cfg_volume_usage_t cfg_volume_usage;
178 struct volume_s *next;
182 * \brief A disk in the NetApp.
184 * A disk doesn't have any more information than its name at the moment.
185 * The name includes the "disk_" prefix.
187 #define HAVE_DISK_BUSY 0x10
188 #define HAVE_DISK_BASE 0x20
189 #define HAVE_DISK_ALL 0x30
190 typedef struct disk_s {
195 uint64_t base_for_disk_busy;
196 double disk_busy_percent;
200 #define CFG_DISK_BUSIEST 0x01
201 #define CFG_DISK_ALL 0x01
204 cna_interval_t interval;
209 struct host_config_s {
211 na_server_transport_t protocol;
219 cfg_service_t *services;
220 cfg_disk_t *cfg_disk;
221 cfg_wafl_t *cfg_wafl;
224 struct host_config_s *next;
226 #define HOST_INIT { NULL, NA_SERVER_TRANSPORT_HTTPS, NULL, 0, NULL, NULL, 0, \
227 NULL, NULL, NULL, NULL, \
230 static host_config_t *global_host_config;
235 * Used to free the various structures above.
237 static void free_volume (volume_t *volume) /* {{{ */
243 sfree (volume->name);
247 } /* }}} void free_volume */
249 static void free_disk (disk_t *disk) /* {{{ */
259 } /* }}} void free_disk */
261 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
263 if (cfg_disk == NULL)
266 free_disk (cfg_disk->disks);
268 } /* }}} void free_cfg_disk */
270 static void free_cfg_service (cfg_service_t *service) /* {{{ */
274 next = service->next;
276 /* FIXME: Free service->data? */
279 free_cfg_service (next);
280 } /* }}} void free_cfg_service */
282 static void free_host_config (host_config_t *hc) /* {{{ */
293 sfree (hc->username);
294 sfree (hc->password);
296 free_cfg_service (hc->services);
297 free_cfg_disk (hc->cfg_disk);
298 free_volume (hc->volumes);
302 free_host_config (next);
303 } /* }}} void free_host_config */
306 * Auxiliary functions
308 * Used to look up volumes and disks or to handle flags.
310 static volume_t *get_volume (host_config_t *host, const char *name, /* {{{ */
311 uint32_t vol_usage_flags, uint32_t vol_perf_flags)
318 /* Make sure the default flags include the init-bit. */
319 if (vol_usage_flags != 0)
320 vol_usage_flags |= VOLUME_INIT;
321 if (vol_perf_flags != 0)
322 vol_perf_flags |= CFG_VOLUME_PERF_INIT;
324 for (v = host->volumes; v; v = v->next) {
325 if (strcmp(v->name, name) != 0)
328 /* Check if the flags have been initialized. */
329 if (((v->cfg_volume_usage.flags & VOLUME_INIT) == 0)
330 && (vol_usage_flags != 0))
331 v->cfg_volume_usage.flags = vol_usage_flags;
332 if (((v->perf_data.flags & CFG_VOLUME_PERF_INIT) == 0)
333 && (vol_perf_flags != 0))
334 v->perf_data.flags = vol_perf_flags;
339 DEBUG ("netapp plugin: Allocating new entry for volume %s.", name);
340 v = malloc(sizeof(*v));
343 memset (v, 0, sizeof (*v));
345 v->cfg_volume_usage.flags = vol_usage_flags;
346 v->perf_data.flags = vol_perf_flags;
348 v->name = strdup(name);
349 if (v->name == NULL) {
354 v->next = host->volumes;
358 } /* }}} volume_t *get_volume */
360 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
364 if ((cd == NULL) || (name == NULL))
367 for (d = cd->disks; d != NULL; d = d->next) {
368 if (strcmp(d->name, name) == 0)
372 d = malloc(sizeof(*d));
375 memset (d, 0, sizeof (*d));
378 d->name = strdup(name);
379 if (d->name == NULL) {
388 } /* }}} disk_t *get_disk */
390 static void host_set_all_perf_data_flags(const host_config_t *host, /* {{{ */
391 uint32_t flag, _Bool set)
395 for (v = host->volumes; v; v = v->next) {
397 v->perf_data.flags |= flag;
399 v->perf_data.flags &= ~flag;
401 } /* }}} void host_set_all_perf_data_flags */
403 static void host_set_all_cfg_volume_usage_flags(const host_config_t *host, /* {{{ */
404 uint32_t flag, _Bool set) {
407 for (v = host->volumes; v; v = v->next) {
409 v->cfg_volume_usage.flags |= flag;
411 v->cfg_volume_usage.flags &= ~flag;
413 } /* }}} void host_set_all_cfg_volume_usage_flags */
416 * Various submit functions.
418 * They all eventually call "submit_values" which creates a value_list_t and
419 * dispatches it to the daemon.
421 static int submit_values (const char *host, /* {{{ */
422 const char *plugin_inst,
423 const char *type, const char *type_inst,
424 value_t *values, int values_len,
427 value_list_t vl = VALUE_LIST_INIT;
430 vl.values_len = values_len;
436 sstrncpy (vl.host, host, sizeof (vl.host));
438 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
439 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
440 if (plugin_inst != NULL)
441 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
442 sstrncpy (vl.type, type, sizeof (vl.type));
443 if (type_inst != NULL)
444 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
446 return (plugin_dispatch_values (&vl));
447 } /* }}} int submit_uint64 */
449 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
450 const char *type, const char *type_inst, counter_t val0, counter_t val1,
455 values[0].counter = val0;
456 values[1].counter = val1;
458 return (submit_values (host, plugin_inst, type, type_inst,
459 values, 2, timestamp));
460 } /* }}} int submit_two_counters */
462 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
463 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
469 return (submit_values (host, plugin_inst, type, type_inst,
471 } /* }}} int submit_counter */
473 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
474 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
479 values[0].gauge = val0;
480 values[1].gauge = val1;
482 return (submit_values (host, plugin_inst, type, type_inst,
483 values, 2, timestamp));
484 } /* }}} int submit_two_gauge */
486 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
487 const char *type, const char *type_inst, double d, time_t timestamp)
491 v.gauge = (gauge_t) d;
493 return (submit_values (host, plugin_inst, type, type_inst,
495 } /* }}} int submit_uint64 */
497 /* Calculate hit ratio from old and new counters and submit the resulting
498 * percentage. Used by "submit_wafl_data". */
499 static int submit_cache_ratio (const char *host, /* {{{ */
500 const char *plugin_inst,
501 const char *type_inst,
510 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
514 hits = new_hits - old_hits;
515 misses = new_misses - old_misses;
517 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
522 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
524 } /* }}} int submit_cache_ratio */
526 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
527 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
528 cfg_wafl_t *old_data, const cfg_wafl_t *new_data)
530 /* Submit requested counters */
531 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
532 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
533 submit_cache_ratio (hostname, instance, "name_cache_hit",
534 new_data->name_cache_hit, new_data->name_cache_miss,
535 old_data->name_cache_hit, old_data->name_cache_miss,
536 new_data->timestamp);
538 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
539 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
540 submit_cache_ratio (hostname, instance, "find_dir_hit",
541 new_data->find_dir_hit, new_data->find_dir_miss,
542 old_data->find_dir_hit, old_data->find_dir_miss,
543 new_data->timestamp);
545 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
546 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
547 submit_cache_ratio (hostname, instance, "buf_hash_hit",
548 new_data->buf_hash_hit, new_data->buf_hash_miss,
549 old_data->buf_hash_hit, old_data->buf_hash_miss,
550 new_data->timestamp);
552 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
553 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
554 submit_cache_ratio (hostname, instance, "inode_cache_hit",
555 new_data->inode_cache_hit, new_data->inode_cache_miss,
556 old_data->inode_cache_hit, old_data->inode_cache_miss,
557 new_data->timestamp);
559 /* Clear old HAVE_* flags */
560 old_data->flags &= ~HAVE_WAFL_ALL;
562 /* Copy all counters */
563 old_data->timestamp = new_data->timestamp;
564 old_data->name_cache_hit = new_data->name_cache_hit;
565 old_data->name_cache_miss = new_data->name_cache_miss;
566 old_data->find_dir_hit = new_data->find_dir_hit;
567 old_data->find_dir_miss = new_data->find_dir_miss;
568 old_data->buf_hash_hit = new_data->buf_hash_hit;
569 old_data->buf_hash_miss = new_data->buf_hash_miss;
570 old_data->inode_cache_hit = new_data->inode_cache_hit;
571 old_data->inode_cache_miss = new_data->inode_cache_miss;
573 /* Copy HAVE_* flags */
574 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
577 } /* }}} int submit_wafl_data */
579 /* Submits volume performance data to the daemon, taking care to honor and
580 * update flags appropriately. */
581 static int submit_volume_perf_data (const host_config_t *host, /* {{{ */
583 const data_volume_perf_t *new_data)
585 /* Check for and submit disk-octet values */
586 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_IO)
587 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
589 submit_two_counters (host->name, volume->name, "disk_octets", /* type instance = */ NULL,
590 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
593 /* Check for and submit disk-operations values */
594 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_OPS)
595 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
597 submit_two_counters (host->name, volume->name, "disk_ops", /* type instance = */ NULL,
598 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
601 /* Check for, calculate and submit disk-latency values */
602 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_LATENCY
603 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
604 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
605 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
606 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
608 gauge_t latency_per_op_read;
609 gauge_t latency_per_op_write;
611 latency_per_op_read = NAN;
612 latency_per_op_write = NAN;
614 /* Check if a counter wrapped around. */
615 if ((new_data->read_ops > volume->perf_data.read_ops)
616 && (new_data->read_latency > volume->perf_data.read_latency))
618 uint64_t diff_ops_read;
619 uint64_t diff_latency_read;
621 diff_ops_read = new_data->read_ops - volume->perf_data.read_ops;
622 diff_latency_read = new_data->read_latency - volume->perf_data.read_latency;
624 if (diff_ops_read > 0)
625 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
628 if ((new_data->write_ops > volume->perf_data.write_ops)
629 && (new_data->write_latency > volume->perf_data.write_latency))
631 uint64_t diff_ops_write;
632 uint64_t diff_latency_write;
634 diff_ops_write = new_data->write_ops - volume->perf_data.write_ops;
635 diff_latency_write = new_data->write_latency - volume->perf_data.write_latency;
637 if (diff_ops_write > 0)
638 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
641 submit_two_gauge (host->name, volume->name, "disk_latency", /* type instance = */ NULL,
642 latency_per_op_read, latency_per_op_write, new_data->timestamp);
645 /* Clear all HAVE_* flags. */
646 volume->perf_data.flags &= ~HAVE_VOLUME_PERF_ALL;
648 /* Copy all counters */
649 volume->perf_data.timestamp = new_data->timestamp;
650 volume->perf_data.read_bytes = new_data->read_bytes;
651 volume->perf_data.write_bytes = new_data->write_bytes;
652 volume->perf_data.read_ops = new_data->read_ops;
653 volume->perf_data.write_ops = new_data->write_ops;
654 volume->perf_data.read_latency = new_data->read_latency;
655 volume->perf_data.write_latency = new_data->write_latency;
657 /* Copy the HAVE_* flags */
658 volume->perf_data.flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
661 } /* }}} int submit_volume_perf_data */
666 * These functions are called with appropriate data returned by the libnetapp
667 * interface which is parsed and submitted with the above functions.
669 /* Data corresponding to <WAFL /> */
670 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
673 cfg_wafl_t perf_data;
674 const char *plugin_inst;
676 na_elem_t *instances;
678 na_elem_iter_t counter_iter;
680 memset (&perf_data, 0, sizeof (perf_data));
682 perf_data.timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
684 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
685 if (instances == NULL)
687 ERROR ("netapp plugin: cna_handle_wafl_data: "
688 "na_elem_child (\"instances\") failed.");
692 plugin_inst = na_child_get_string(instances, "name");
693 if (plugin_inst == NULL)
695 ERROR ("netapp plugin: cna_handle_wafl_data: "
696 "na_child_get_string (\"name\") failed.");
700 /* Iterate over all counters */
701 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
702 for (counter = na_iterator_next (&counter_iter);
704 counter = na_iterator_next (&counter_iter))
709 name = na_child_get_string(counter, "name");
713 value = na_child_get_uint64(counter, "value", UINT64_MAX);
714 if (value == UINT64_MAX)
717 if (!strcmp(name, "name_cache_hit")) {
718 perf_data.name_cache_hit = value;
719 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
720 } else if (!strcmp(name, "name_cache_miss")) {
721 perf_data.name_cache_miss = value;
722 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
723 } else if (!strcmp(name, "find_dir_hit")) {
724 perf_data.find_dir_hit = value;
725 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
726 } else if (!strcmp(name, "find_dir_miss")) {
727 perf_data.find_dir_miss = value;
728 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
729 } else if (!strcmp(name, "buf_hash_hit")) {
730 perf_data.buf_hash_hit = value;
731 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
732 } else if (!strcmp(name, "buf_hash_miss")) {
733 perf_data.buf_hash_miss = value;
734 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
735 } else if (!strcmp(name, "inode_cache_hit")) {
736 perf_data.inode_cache_hit = value;
737 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
738 } else if (!strcmp(name, "inode_cache_miss")) {
739 perf_data.inode_cache_miss = value;
740 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
742 DEBUG("netapp plugin: cna_handle_wafl_data: "
743 "Found unexpected child: %s", name);
747 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data));
748 } /* }}} void cna_handle_wafl_data */
750 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
757 if (cw->query != NULL)
760 cw->query = na_elem_new("perf-object-get-instances");
761 if (cw->query == NULL)
763 ERROR ("netapp plugin: na_elem_new failed.");
766 na_child_add_string (cw->query, "objectname", "wafl");
768 e = na_elem_new("counters");
771 na_elem_free (cw->query);
773 ERROR ("netapp plugin: na_elem_new failed.");
776 na_child_add_string(e, "foo", "name_cache_hit");
777 na_child_add_string(e, "foo", "name_cache_miss");
778 na_child_add_string(e, "foo", "find_dir_hit");
779 na_child_add_string(e, "foo", "find_dir_miss");
780 na_child_add_string(e, "foo", "buf_hash_hit");
781 na_child_add_string(e, "foo", "buf_hash_miss");
782 na_child_add_string(e, "foo", "inode_cache_hit");
783 na_child_add_string(e, "foo", "inode_cache_miss");
785 na_child_add(cw->query, e);
788 } /* }}} int cna_setup_wafl */
790 static int cna_query_wafl (host_config_t *host) /* {{{ */
799 if (host->cfg_wafl == NULL)
803 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
806 status = cna_setup_wafl (host->cfg_wafl);
809 assert (host->cfg_wafl->query != NULL);
811 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
812 if (na_results_status (data) != NA_OK)
814 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed: %s",
815 na_results_reason (data));
820 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data);
823 host->cfg_wafl->interval.last_read = now;
827 } /* }}} int cna_query_wafl */
829 /* Data corresponding to <Disks /> */
830 static int cna_handle_disk_data (const char *hostname, /* {{{ */
831 cfg_disk_t *cfg_disk, na_elem_t *data)
834 na_elem_t *instances;
836 na_elem_iter_t instance_iter;
837 disk_t *worst_disk = NULL;
839 if ((cfg_disk == NULL) || (data == NULL))
842 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
844 instances = na_elem_child (data, "instances");
845 if (instances == NULL)
847 ERROR ("netapp plugin: cna_handle_disk_data: "
848 "na_elem_child (\"instances\") failed.");
852 /* Iterate over all children */
853 instance_iter = na_child_iterator (instances);
854 for (instance = na_iterator_next (&instance_iter);
856 instance = na_iterator_next(&instance_iter))
861 na_elem_iter_t counter_iterator;
864 memset (&new_data, 0, sizeof (new_data));
865 new_data.timestamp = timestamp;
866 new_data.disk_busy_percent = NAN;
868 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
869 if (old_data == NULL)
872 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
873 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
874 for (counter = na_iterator_next(&counter_iterator);
876 counter = na_iterator_next(&counter_iterator))
881 name = na_child_get_string(counter, "name");
885 value = na_child_get_uint64(counter, "value", UINT64_MAX);
886 if (value == UINT64_MAX)
889 if (strcmp(name, "disk_busy") == 0)
891 new_data.disk_busy = value;
892 new_data.flags |= HAVE_DISK_BUSY;
894 else if (strcmp(name, "base_for_disk_busy") == 0)
896 new_data.base_for_disk_busy = value;
897 new_data.flags |= HAVE_DISK_BASE;
901 DEBUG ("netapp plugin: cna_handle_disk_data: "
902 "Counter not handled: %s = %"PRIu64,
907 /* If all required counters are available and did not just wrap around,
908 * calculate the busy percentage. Otherwise, the value is initialized to
909 * NAN at the top of the for-loop. */
910 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
911 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
912 && (new_data.disk_busy >= old_data->disk_busy)
913 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
918 busy_diff = new_data.disk_busy - old_data->disk_busy;
919 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
921 new_data.disk_busy_percent = 100.0
922 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
925 /* Clear HAVE_* flags */
926 old_data->flags &= ~HAVE_DISK_ALL;
929 old_data->timestamp = new_data.timestamp;
930 old_data->disk_busy = new_data.disk_busy;
931 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
932 old_data->disk_busy_percent = new_data.disk_busy_percent;
935 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
937 if ((worst_disk == NULL)
938 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
939 worst_disk = old_data;
940 } /* for (all disks) */
942 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
943 submit_double (hostname, "system", "percent", "disk_busy",
944 worst_disk->disk_busy_percent, timestamp);
947 } /* }}} int cna_handle_disk_data */
949 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
956 if (cd->query != NULL)
959 cd->query = na_elem_new ("perf-object-get-instances");
960 if (cd->query == NULL)
962 ERROR ("netapp plugin: na_elem_new failed.");
965 na_child_add_string (cd->query, "objectname", "disk");
967 e = na_elem_new("counters");
970 na_elem_free (cd->query);
972 ERROR ("netapp plugin: na_elem_new failed.");
975 na_child_add_string(e, "foo", "disk_busy");
976 na_child_add_string(e, "foo", "base_for_disk_busy");
977 na_child_add(cd->query, e);
980 } /* }}} int cna_setup_disk */
982 static int cna_query_disk (host_config_t *host) /* {{{ */
991 if (host->cfg_disk == NULL)
995 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
998 status = cna_setup_disk (host->cfg_disk);
1001 assert (host->cfg_disk->query != NULL);
1003 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1004 if (na_results_status (data) != NA_OK)
1006 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed: %s",
1007 na_results_reason (data));
1008 na_elem_free (data);
1012 status = cna_handle_disk_data (host->name, host->cfg_disk, data);
1015 host->cfg_disk->interval.last_read = now;
1017 na_elem_free (data);
1019 } /* }}} int cna_query_disk */
1021 /* Data corresponding to <GetVolumeData /> */
1022 static void collect_volume_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
1025 cfg_volume_usage_t *cfg_volume_data = data;
1027 out = na_elem_child(out, "volumes");
1028 na_elem_iter_t inst_iter = na_child_iterator(out);
1029 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
1030 uint64_t size_free = 0, size_used = 0, snap_reserved = 0;
1033 const char *sis_state;
1034 uint64_t sis_saved_reported;
1037 volume = get_volume(host, na_child_get_string(inst, "name"),
1038 cfg_volume_data->flags, /* perf_flags = */ 0);
1042 if (!(volume->cfg_volume_usage.flags & VOLUME_DF))
1045 /* 2^4 exa-bytes? This will take a while ;) */
1046 size_free = na_child_get_uint64(inst, "size-available", UINT64_MAX);
1047 if (size_free != UINT64_MAX)
1048 submit_double (host->name, volume->name, "df_complex", "used",
1049 (double) size_used, /* time = */ 0);
1051 size_used = na_child_get_uint64(inst, "size-used", UINT64_MAX);
1052 if (size_free != UINT64_MAX)
1053 submit_double (host->name, volume->name, "df_complex", "free",
1054 (double) size_free, /* time = */ 0);
1056 snap_reserved = na_child_get_uint64(inst, "snapshot-blocks-reserved", UINT64_MAX);
1057 if (snap_reserved != UINT64_MAX)
1058 /* 1 block == 1024 bytes as per API docs */
1059 submit_double (host->name, volume->name, "df_complex", "snap_reserved",
1060 (double) (1024 * snap_reserved), /* time = */ 0);
1062 sis = na_elem_child(inst, "sis");
1066 sis_state = na_child_get_string(sis, "state");
1067 if ((sis_state == NULL)
1068 || (strcmp ("enabled", sis_state) != 0))
1071 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1072 if (sis_saved_reported == UINT64_MAX)
1075 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1076 if ((sis_saved_reported >> 32) != 0) {
1077 /* In case they ever fix this bug. */
1078 sis_saved = sis_saved_reported;
1080 uint64_t sis_saved_percent;
1081 uint64_t sis_saved_guess;
1082 uint64_t overflow_guess;
1083 uint64_t guess1, guess2, guess3;
1085 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1086 if (sis_saved_percent > 100)
1089 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1090 * will hopefully be fixed in later versions. To work around the bug, try
1091 * to figure out how often the 32bit integer wrapped around by using the
1092 * "percentage-saved" value. Because the percentage is in the range
1093 * [0-100], this should work as long as the saved space does not exceed
1095 /* percentage-saved = size-saved / (size-saved + size-used) */
1096 if (sis_saved_percent < 100)
1097 sis_saved_guess = size_used * sis_saved_percent / (100 - sis_saved_percent);
1099 sis_saved_guess = size_used;
1101 overflow_guess = sis_saved_guess >> 32;
1102 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1103 guess2 = (overflow_guess << 32) + sis_saved_reported;
1104 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1106 if (sis_saved_guess < guess2) {
1107 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1112 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1117 } /* end of 32-bit workaround */
1119 submit_double (host->name, volume->name, "df_complex", "sis_saved",
1120 (double) sis_saved, /* time = */ 0);
1122 } /* }}} void collect_volume_data */
1124 /* Data corresponding to <GetVolumePerfData /> */
1125 static void query_volume_perf_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
1126 cfg_volume_perf_t *cfg_volume_perf = data;
1128 na_elem_t *counter, *inst;
1130 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
1132 out = na_elem_child(out, "instances");
1133 na_elem_iter_t inst_iter = na_child_iterator(out);
1134 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
1135 data_volume_perf_t perf_data;
1138 memset (&perf_data, 0, sizeof (perf_data));
1139 perf_data.timestamp = timestamp;
1141 volume = get_volume(host, na_child_get_string(inst, "name"),
1142 /* data_flags = */ 0, cfg_volume_perf->flags);
1146 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
1147 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
1151 name = na_child_get_string(counter, "name");
1155 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1156 if (value == UINT64_MAX)
1159 if (!strcmp(name, "read_data")) {
1160 perf_data.read_bytes = value;
1161 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1162 } else if (!strcmp(name, "write_data")) {
1163 perf_data.write_bytes = value;
1164 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1165 } else if (!strcmp(name, "read_ops")) {
1166 perf_data.read_ops = value;
1167 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1168 } else if (!strcmp(name, "write_ops")) {
1169 perf_data.write_ops = value;
1170 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1171 } else if (!strcmp(name, "read_latency")) {
1172 perf_data.read_latency = value;
1173 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1174 } else if (!strcmp(name, "write_latency")) {
1175 perf_data.write_latency = value;
1176 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1180 submit_volume_perf_data (host, volume, &perf_data);
1181 } /* for (volume) */
1182 } /* }}} void query_volume_perf_data */
1184 /* Data corresponding to <GetSystemPerfData /> */
1185 static void collect_perf_system_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
1186 counter_t disk_read = 0, disk_written = 0;
1187 counter_t net_recv = 0, net_sent = 0;
1188 counter_t cpu_busy = 0, cpu_total = 0;
1189 unsigned int counter_flags = 0;
1191 cfg_system_t *cfg_system = data;
1192 const char *instance;
1196 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
1197 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
1198 instance = na_child_get_string(out, "name");
1200 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
1201 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
1205 name = na_child_get_string(counter, "name");
1209 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1210 if (value == UINT64_MAX)
1213 if (!strcmp(name, "disk_data_read")) {
1214 disk_read = (counter_t) (value * 1024);
1215 counter_flags |= 0x01;
1216 } else if (!strcmp(name, "disk_data_written")) {
1217 disk_written = (counter_t) (value * 1024);
1218 counter_flags |= 0x02;
1219 } else if (!strcmp(name, "net_data_recv")) {
1220 net_recv = (counter_t) (value * 1024);
1221 counter_flags |= 0x04;
1222 } else if (!strcmp(name, "net_data_sent")) {
1223 net_sent = (counter_t) (value * 1024);
1224 counter_flags |= 0x08;
1225 } else if (!strcmp(name, "cpu_busy")) {
1226 cpu_busy = (counter_t) value;
1227 counter_flags |= 0x10;
1228 } else if (!strcmp(name, "cpu_elapsed_time")) {
1229 cpu_total = (counter_t) value;
1230 counter_flags |= 0x20;
1231 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1232 && (strlen(name) > 4)
1233 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1234 submit_counter (host->name, instance, "disk_ops_complex", name,
1235 (counter_t) value, timestamp);
1237 } /* for (counter) */
1239 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1240 && ((counter_flags & 0x03) == 0x03))
1241 submit_two_counters (host->name, instance, "disk_octets", NULL,
1242 disk_read, disk_written, timestamp);
1244 if ((cfg_system->flags & CFG_SYSTEM_NET)
1245 && ((counter_flags & 0x0c) == 0x0c))
1246 submit_two_counters (host->name, instance, "if_octets", NULL,
1247 net_recv, net_sent, timestamp);
1249 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1250 && ((counter_flags & 0x30) == 0x30)) {
1251 submit_counter (host->name, instance, "cpu", "system",
1252 cpu_busy, timestamp);
1253 submit_counter (host->name, instance, "cpu", "idle",
1254 cpu_total - cpu_busy, timestamp);
1256 } /* }}} void collect_perf_system_data */
1259 * Configuration handling
1261 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1262 * is false. On error, the flag-field is not changed. */
1263 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1264 uint32_t *flags, uint32_t flag)
1266 if ((ci == NULL) || (flags == NULL))
1269 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1271 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1276 if (ci->values[0].value.boolean)
1282 } /* }}} int cna_config_bool_to_flag */
1284 /* Handling of the "Multiplier" option which is allowed in every block. */
1285 static int cna_config_get_multiplier (const oconfig_item_t *ci, /* {{{ */
1286 cfg_service_t *service)
1290 if ((ci == NULL) || (service == NULL))
1293 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1295 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1299 tmp = (int) (ci->values[0].value.number + .5);
1302 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1306 service->multiplier = tmp;
1307 service->skip_countdown = tmp;
1310 } /* }}} int cna_config_get_multiplier */
1312 /* Handling of the "Interval" option which is allowed in every block. */
1313 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1314 cna_interval_t *out_interval)
1318 if ((ci == NULL) || (out_interval == NULL))
1321 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1323 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1327 tmp = (time_t) (ci->values[0].value.number + .5);
1330 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1334 out_interval->interval = tmp;
1335 out_interval->last_read = 0;
1338 } /* }}} int cna_config_get_interval */
1340 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1341 * <GetVolumePerfData /> block. */
1342 static void cna_config_volume_performance_option (host_config_t *host, /* {{{ */
1343 cfg_volume_perf_t *perf_volume, const oconfig_item_t *item,
1348 for (i = 0; i < item->values_num; ++i) {
1353 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1354 WARNING("netapp plugin: Ignoring non-string argument in "
1355 "\"GetVolumePerfData\" block for host %s", host->name);
1359 name = item->values[i].value.string;
1360 if (name[0] == '+') {
1363 } else if (name[0] == '-') {
1370 perf_volume->flags |= flag;
1371 else /* if (!set) */
1372 perf_volume->flags &= ~flag;
1374 host_set_all_perf_data_flags(host, flag, set);
1378 v = get_volume (host, name, /* data_flags = */ 0, perf_volume->flags);
1383 v->perf_data.flags |= flag;
1384 else /* if (!set) */
1385 v->perf_data.flags &= ~flag;
1386 } /* for (i = 0 .. item->values_num) */
1387 } /* }}} void cna_config_volume_performance_option */
1389 /* Corresponds to a <GetVolumePerfData /> block */
1390 static void cna_config_volume_performance(host_config_t *host, const oconfig_item_t *ci) { /* {{{ */
1391 int i, had_io = 0, had_ops = 0, had_latency = 0;
1392 cfg_service_t *service;
1393 cfg_volume_perf_t *perf_volume;
1395 service = malloc(sizeof(*service));
1397 service->handler = query_volume_perf_data;
1398 perf_volume = service->data = malloc(sizeof(*perf_volume));
1399 perf_volume->flags = CFG_VOLUME_PERF_INIT;
1400 service->next = host->services;
1401 host->services = service;
1402 for (i = 0; i < ci->children_num; ++i) {
1403 oconfig_item_t *item = ci->children + i;
1405 /* if (!item || !item->key || !*item->key) continue; */
1406 if (!strcasecmp(item->key, "Multiplier")) {
1407 cna_config_get_multiplier (item, service);
1408 } else if (!strcasecmp(item->key, "GetIO")) {
1410 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_IO);
1411 } else if (!strcasecmp(item->key, "GetOps")) {
1413 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_OPS);
1414 } else if (!strcasecmp(item->key, "GetLatency")) {
1416 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_LATENCY);
1420 perf_volume->flags |= CFG_VOLUME_PERF_IO;
1421 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_IO, /* set = */ true);
1424 perf_volume->flags |= CFG_VOLUME_PERF_OPS;
1425 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_OPS, /* set = */ true);
1428 perf_volume->flags |= CFG_VOLUME_PERF_LATENCY;
1429 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_LATENCY, /* set = */ true);
1431 } /* }}} void cna_config_volume_performance */
1433 /* Handling of the "GetDiskUtil" option within a <GetVolumeData /> block. */
1434 static void cna_config_volume_usage_option (host_config_t *host, /* {{{ */
1435 cfg_volume_usage_t *cfg_volume_data, const oconfig_item_t *item, uint32_t flag)
1439 for (i = 0; i < item->values_num; ++i) {
1444 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1445 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolData\""
1446 "block for host %s", host->name);
1450 name = item->values[i].value.string;
1451 if (name[0] == '+') {
1454 } else if (name[0] == '-') {
1461 cfg_volume_data->flags |= flag;
1462 else /* if (!set) */
1463 cfg_volume_data->flags &= ~flag;
1465 host_set_all_cfg_volume_usage_flags(host, flag, set);
1469 v = get_volume(host, name, cfg_volume_data->flags, /* perf_flags = */ 0);
1473 if (!v->cfg_volume_usage.flags)
1474 v->cfg_volume_usage.flags = cfg_volume_data->flags;
1477 v->cfg_volume_usage.flags |= flag;
1478 else /* if (!set) */
1479 v->cfg_volume_usage.flags &= ~flag;
1481 } /* }}} void cna_config_volume_usage_option */
1483 /* Corresponds to a <GetVolumeData /> block */
1484 static void cna_config_volume_usage(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1486 cfg_service_t *service;
1487 cfg_volume_usage_t *cfg_volume_data;
1489 service = malloc(sizeof(*service));
1491 service->handler = collect_volume_data;
1492 cfg_volume_data = service->data = malloc(sizeof(*cfg_volume_data));
1493 cfg_volume_data->flags = VOLUME_INIT;
1494 service->next = host->services;
1495 host->services = service;
1496 for (i = 0; i < ci->children_num; ++i) {
1497 oconfig_item_t *item = ci->children + i;
1499 /* if (!item || !item->key || !*item->key) continue; */
1500 if (!strcasecmp(item->key, "Multiplier")) {
1501 cna_config_get_multiplier (item, service);
1502 } else if (!strcasecmp(item->key, "GetDiskUtil")) {
1504 cna_config_volume_usage_option(host, cfg_volume_data, item, VOLUME_DF);
1508 cfg_volume_data->flags |= VOLUME_DF;
1509 host_set_all_cfg_volume_usage_flags(host, VOLUME_DF, /* set = */ true);
1511 } /* }}} void cna_config_volume_usage */
1513 /* Corresponds to a <Disks /> block */
1514 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1515 cfg_disk_t *cfg_disk;
1518 if ((host == NULL) || (ci == NULL))
1521 if (host->cfg_disk == NULL)
1523 cfg_disk = malloc (sizeof (*cfg_disk));
1524 if (cfg_disk == NULL)
1526 memset (cfg_disk, 0, sizeof (*cfg_disk));
1528 /* Set default flags */
1529 cfg_disk->flags = CFG_DISK_ALL;
1530 cfg_disk->query = NULL;
1531 cfg_disk->disks = NULL;
1533 host->cfg_disk = cfg_disk;
1535 cfg_disk = host->cfg_disk;
1537 for (i = 0; i < ci->children_num; ++i) {
1538 oconfig_item_t *item = ci->children + i;
1540 /* if (!item || !item->key || !*item->key) continue; */
1541 if (strcasecmp(item->key, "Interval") == 0)
1542 cna_config_get_interval (item, &cfg_disk->interval);
1543 else if (strcasecmp(item->key, "GetBusy") == 0)
1544 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
1548 } /* }}} int cna_config_disk */
1550 /* Corresponds to a <WAFL /> block */
1551 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
1553 cfg_wafl_t *cfg_wafl;
1556 if ((host == NULL) || (ci == NULL))
1559 if (host->cfg_wafl == NULL)
1561 cfg_wafl = malloc (sizeof (*cfg_wafl));
1562 if (cfg_wafl == NULL)
1564 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
1566 /* Set default flags */
1567 cfg_wafl->flags = CFG_WAFL_ALL;
1569 host->cfg_wafl = cfg_wafl;
1571 cfg_wafl = host->cfg_wafl;
1573 for (i = 0; i < ci->children_num; ++i) {
1574 oconfig_item_t *item = ci->children + i;
1576 if (strcasecmp(item->key, "Interval") == 0)
1577 cna_config_get_interval (item, &cfg_wafl->interval);
1578 else if (!strcasecmp(item->key, "GetNameCache"))
1579 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
1580 else if (!strcasecmp(item->key, "GetDirCache"))
1581 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
1582 else if (!strcasecmp(item->key, "GetBufferCache"))
1583 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
1584 else if (!strcasecmp(item->key, "GetInodeCache"))
1585 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
1587 WARNING ("netapp plugin: The %s config option is not allowed within "
1588 "`WAFL' blocks.", item->key);
1592 } /* }}} int cna_config_wafl */
1594 /* Corresponds to a <GetSystemPerfData /> block */
1595 static int cna_config_system (host_config_t *host, /* {{{ */
1596 oconfig_item_t *ci, const cfg_service_t *default_service)
1599 cfg_service_t *service;
1600 cfg_system_t *cfg_system;
1602 service = malloc(sizeof(*service));
1603 if (service == NULL)
1605 memset (service, 0, sizeof (*service));
1606 *service = *default_service;
1607 service->handler = collect_perf_system_data;
1609 cfg_system = malloc(sizeof(*cfg_system));
1610 if (cfg_system == NULL) {
1614 memset (cfg_system, 0, sizeof (*cfg_system));
1615 cfg_system->flags = CFG_SYSTEM_ALL;
1616 service->data = cfg_system;
1618 for (i = 0; i < ci->children_num; ++i) {
1619 oconfig_item_t *item = ci->children + i;
1621 if (!strcasecmp(item->key, "Multiplier")) {
1622 cna_config_get_multiplier (item, service);
1623 } else if (!strcasecmp(item->key, "GetCPULoad")) {
1624 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
1625 } else if (!strcasecmp(item->key, "GetInterfaces")) {
1626 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
1627 } else if (!strcasecmp(item->key, "GetDiskOps")) {
1628 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
1629 } else if (!strcasecmp(item->key, "GetDiskIO")) {
1630 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
1632 WARNING ("netapp plugin: The %s config option is not allowed within "
1633 "`GetSystemPerfData' blocks.", item->key);
1637 service->next = host->services;
1638 host->services = service;
1641 } /* }}} int cna_config_system */
1643 /* Corresponds to a <Host /> block. */
1644 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
1645 const host_config_t *default_host, const cfg_service_t *def_def_service)
1647 oconfig_item_t *item;
1648 host_config_t *host, *hc;
1649 cfg_service_t default_service = *def_def_service;
1653 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1654 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
1658 host = malloc(sizeof(*host));
1659 memcpy (host, default_host, sizeof (*host));
1661 status = cf_util_get_string (ci, &host->name);
1668 for (i = 0; i < ci->children_num; ++i) {
1669 item = ci->children + i;
1673 if (!strcasecmp(item->key, "Address")) {
1674 status = cf_util_get_string (item, &host->host);
1675 } else if (!strcasecmp(item->key, "Port")) {
1678 tmp = cf_util_get_port_number (item);
1681 } else if (!strcasecmp(item->key, "Protocol")) {
1682 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"))) {
1683 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
1686 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
1687 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
1688 } else if (!strcasecmp(item->key, "User")) {
1689 status = cf_util_get_string (item, &host->username);
1690 } else if (!strcasecmp(item->key, "Password")) {
1691 status = cf_util_get_string (item, &host->password);
1692 } else if (!strcasecmp(item->key, "Interval")) {
1693 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) {
1694 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
1697 host->interval = item->values[0].value.number;
1698 } else if (!strcasecmp(item->key, "GetVolumePerfData")) {
1699 cna_config_volume_performance(host, item);
1700 } else if (!strcasecmp(item->key, "GetSystemPerfData")) {
1701 cna_config_system(host, item, &default_service);
1702 } else if (!strcasecmp(item->key, "WAFL")) {
1703 cna_config_wafl(host, item);
1704 } else if (!strcasecmp(item->key, "Disks")) {
1705 cna_config_disk(host, item);
1706 } else if (!strcasecmp(item->key, "GetVolumeData")) {
1707 cna_config_volume_usage(host, item);
1709 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
1710 item->key, ci->values[0].value.string);
1717 if (host->host == NULL)
1718 host->host = strdup (host->name);
1720 if (host->host == NULL)
1723 if (host->port <= 0)
1724 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
1726 if ((host->username == NULL) || (host->password == NULL)) {
1727 WARNING("netapp plugin: Please supply login information for host \"%s\". "
1728 "Ignoring host block.", host->name);
1734 free_host_config (host);
1738 for (hc = global_host_config; hc; hc = hc->next) {
1739 if (!strcasecmp(hc->name, host->name)) WARNING("netapp plugin: Duplicate definition of host \"%s\". This is probably a bad idea.", hc->name);
1742 } /* }}} host_config_t *cna_config_host */
1745 * Callbacks registered with the daemon
1747 * Pretty standard stuff here.
1749 static int cna_init(void) { /* {{{ */
1752 host_config_t *host;
1753 cfg_service_t *service;
1755 if (!global_host_config) {
1756 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
1760 memset (err, 0, sizeof (err));
1761 if (!na_startup(err, sizeof(err))) {
1762 err[sizeof (err) - 1] = 0;
1763 ERROR("netapp plugin: Error initializing netapp API: %s", err);
1767 for (host = global_host_config; host; host = host->next) {
1768 /* Request version 1.1 of the ONTAP API */
1769 host->srv = na_server_open(host->host,
1770 /* major version = */ 1, /* minor version = */ 1);
1771 if (host->srv == NULL) {
1772 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
1776 if (host->interval < interval_g)
1777 host->interval = interval_g;
1779 na_server_set_transport_type(host->srv, host->protocol,
1780 /* transportarg = */ NULL);
1781 na_server_set_port(host->srv, host->port);
1782 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
1783 na_server_adminuser(host->srv, host->username, host->password);
1784 na_server_set_timeout(host->srv, 5 /* seconds */);
1786 for (service = host->services; service; service = service->next) {
1787 service->interval = host->interval * service->multiplier;
1789 if (service->handler == collect_perf_system_data) {
1790 service->query = na_elem_new("perf-object-get-instances");
1791 na_child_add_string(service->query, "objectname", "system");
1792 } else if (service->handler == query_volume_perf_data) {
1793 service->query = na_elem_new("perf-object-get-instances");
1794 na_child_add_string(service->query, "objectname", "volume");
1795 e = na_elem_new("counters");
1796 na_child_add_string(e, "foo", "read_ops");
1797 na_child_add_string(e, "foo", "write_ops");
1798 na_child_add_string(e, "foo", "read_data");
1799 na_child_add_string(e, "foo", "write_data");
1800 na_child_add_string(e, "foo", "read_latency");
1801 na_child_add_string(e, "foo", "write_latency");
1802 na_child_add(service->query, e);
1803 } else if (service->handler == collect_volume_data) {
1804 service->query = na_elem_new("volume-list-info");
1805 /* na_child_add_string(service->query, "objectname", "volume"); */
1806 /* } else if (service->handler == collect_snapshot_data) { */
1807 /* service->query = na_elem_new("snapshot-list-info"); */
1809 } /* for (host->services) */
1812 } /* }}} int cna_init */
1814 static int cna_config (oconfig_item_t *ci) { /* {{{ */
1816 oconfig_item_t *item;
1817 host_config_t default_host = HOST_INIT;
1818 cfg_service_t default_service = SERVICE_INIT;
1820 for (i = 0; i < ci->children_num; ++i) {
1821 item = ci->children + i;
1823 /* if (!item || !item->key || !*item->key) continue; */
1824 if (!strcasecmp(item->key, "Host")) {
1825 host_config_t *host;
1828 host = cna_config_host(item, &default_host, &default_service);
1832 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
1834 if (strcasecmp (host->name, tmp->name) == 0)
1835 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
1836 "This is probably a bad idea.",
1839 if (tmp->next == NULL)
1845 global_host_config = host;
1849 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
1853 } /* }}} int cna_config */
1855 static int cna_read(void) { /* {{{ */
1857 host_config_t *host;
1858 cfg_service_t *service;
1860 for (host = global_host_config; host; host = host->next) {
1861 for (service = host->services; service; service = service->next) {
1862 if (--service->skip_countdown > 0) continue;
1863 service->skip_countdown = service->multiplier;
1864 out = na_server_invoke_elem(host->srv, service->query);
1865 if (na_results_status(out) != NA_OK) {
1866 int netapp_errno = na_results_errno(out);
1867 ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
1869 if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
1870 /* Network problems. Just give up on all other services on this host. */
1875 service->handler(host, out, service->data);
1877 } /* for (host->services) */
1879 cna_query_wafl (host);
1880 cna_query_disk (host);
1883 } /* }}} int cna_read */
1885 void module_register(void) {
1886 plugin_register_complex_config("netapp", cna_config);
1887 plugin_register_init("netapp", cna_init);
1888 plugin_register_read("netapp", cna_read);
1891 /* vim: set sw=2 ts=2 noet fdm=marker : */