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 "data_wafl_t" struct therefore contains old counter values
61 * along with flags, which are set if the counter is valid.
63 * The function "query_wafl_data" will fill a new structure of this kind with
64 * new values, then pass both, new and old data, to "submit_wafl_data". That
65 * 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
89 uint64_t name_cache_hit;
90 uint64_t name_cache_miss;
91 uint64_t find_dir_hit;
92 uint64_t find_dir_miss;
93 uint64_t buf_hash_hit;
94 uint64_t buf_hash_miss;
95 uint64_t inode_cache_hit;
96 uint64_t inode_cache_miss;
100 * \brief Persistent data for volume performance data.
102 * The code below uses the difference of the operations and latency counters to
103 * calculate an average per-operation latency. For this, old counters need to
104 * be stored in the "data_volume_perf_t" structure. The byte-counters are just
105 * kept for completeness sake. The "flags" member indicates if each counter is
108 * The "query_volume_perf_data" function will fill a new struct of this type
109 * and pass both, old and new data, to "submit_volume_perf_data". In that
110 * function, the per-operation latency is calculated and dispatched, then the
111 * old counters are updated.
113 #define CFG_VOLUME_PERF_INIT 0x0001
114 #define CFG_VOLUME_PERF_IO 0x0002
115 #define CFG_VOLUME_PERF_OPS 0x0003
116 #define CFG_VOLUME_PERF_LATENCY 0x0008
117 #define CFG_VOLUME_PERF_ALL 0x000F
118 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
119 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
120 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
121 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
122 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
123 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
124 #define HAVE_VOLUME_PERF_ALL 0x03F0
133 uint64_t write_bytes;
136 uint64_t read_latency;
137 uint64_t write_latency;
138 } data_volume_perf_t;
141 * \brief Configuration struct for volume usage data (free / used).
143 #define CFG_VOLUME_USAGE_INIT 0x0001
144 #define CFG_VOLUME_USAGE_DF 0x0002
145 #define CFG_VOLUME_USAGE_SNAP 0x0004
146 #define HAVE_VOLUME_USAGE_SNAP 0x0008
150 } cfg_volume_usage_t;
152 typedef struct service_config_s {
154 service_handler_t *handler;
159 struct service_config_s *next;
161 #define SERVICE_INIT {0, 0, 1, 1, 0, 0, 0}
164 * \brief Struct representing a volume.
166 * A volume currently has a name and two sets of values:
168 * - Performance data, such as bytes read/written, number of operations
169 * performed and average time per operation.
171 * - Usage data, i. e. amount of used and free space in the volume.
173 typedef struct volume_s {
175 data_volume_perf_t perf_data;
176 cfg_volume_usage_t cfg_volume_usage;
177 struct volume_s *next;
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 #define HAVE_DISK_BUSY 0x10
187 #define HAVE_DISK_BASE 0x20
188 #define HAVE_DISK_ALL 0x30
189 typedef struct disk_s {
194 uint64_t base_for_disk_busy;
195 double disk_busy_percent;
199 #define CFG_DISK_BUSIEST 0x01
200 #define CFG_DISK_ALL 0x01
203 cna_interval_t interval;
208 struct host_config_s {
210 na_server_transport_t protocol;
218 cfg_service_t *services;
219 cfg_disk_t *cfg_disk;
222 struct host_config_s *next;
224 #define HOST_INIT { NULL, NA_SERVER_TRANSPORT_HTTPS, NULL, 0, NULL, NULL, 0, \
225 NULL, NULL, NULL, NULL, \
228 static host_config_t *global_host_config;
233 * Used to free the various structures above.
235 static void free_volume (volume_t *volume) /* {{{ */
241 sfree (volume->name);
245 } /* }}} void free_volume */
247 static void free_disk (disk_t *disk) /* {{{ */
257 } /* }}} void free_disk */
259 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
261 if (cfg_disk == NULL)
264 free_disk (cfg_disk->disks);
266 } /* }}} void free_cfg_disk */
268 static void free_cfg_service (cfg_service_t *service) /* {{{ */
275 next = service->next;
277 /* FIXME: Free service->data? */
278 na_elem_free(service->query);
282 free_cfg_service (next);
283 } /* }}} void free_cfg_service */
285 static void free_host_config (host_config_t *hc) /* {{{ */
296 sfree (hc->username);
297 sfree (hc->password);
299 free_cfg_service (hc->services);
300 free_cfg_disk (hc->cfg_disk);
301 free_volume (hc->volumes);
305 free_host_config (next);
306 } /* }}} void free_host_config */
309 * Auxiliary functions
311 * Used to look up volumes and disks or to handle flags.
313 static volume_t *get_volume (host_config_t *host, const char *name, /* {{{ */
314 uint32_t vol_usage_flags, uint32_t vol_perf_flags)
321 /* Make sure the default flags include the init-bit. */
322 if (vol_usage_flags != 0)
323 vol_usage_flags |= CFG_VOLUME_USAGE_INIT;
324 if (vol_perf_flags != 0)
325 vol_perf_flags |= CFG_VOLUME_PERF_INIT;
327 for (v = host->volumes; v; v = v->next) {
328 if (strcmp(v->name, name) != 0)
331 /* Check if the flags have been initialized. */
332 if (((v->cfg_volume_usage.flags & CFG_VOLUME_USAGE_INIT) == 0)
333 && (vol_usage_flags != 0))
334 v->cfg_volume_usage.flags = vol_usage_flags;
335 if (((v->perf_data.flags & CFG_VOLUME_PERF_INIT) == 0)
336 && (vol_perf_flags != 0))
337 v->perf_data.flags = vol_perf_flags;
342 DEBUG ("netapp plugin: Allocating new entry for volume %s.", name);
343 v = malloc(sizeof(*v));
346 memset (v, 0, sizeof (*v));
348 v->cfg_volume_usage.flags = vol_usage_flags;
349 v->perf_data.flags = vol_perf_flags;
351 v->name = strdup(name);
352 if (v->name == NULL) {
357 v->next = host->volumes;
361 } /* }}} volume_t *get_volume */
363 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
367 if ((cd == NULL) || (name == NULL))
370 for (d = cd->disks; d != NULL; d = d->next) {
371 if (strcmp(d->name, name) == 0)
375 d = malloc(sizeof(*d));
378 memset (d, 0, sizeof (*d));
381 d->name = strdup(name);
382 if (d->name == NULL) {
391 } /* }}} disk_t *get_disk */
393 static void host_set_all_perf_data_flags(const host_config_t *host, /* {{{ */
394 uint32_t flag, _Bool set)
398 for (v = host->volumes; v; v = v->next) {
400 v->perf_data.flags |= flag;
402 v->perf_data.flags &= ~flag;
404 } /* }}} void host_set_all_perf_data_flags */
406 static void host_set_all_cfg_volume_usage_flags(const host_config_t *host, /* {{{ */
407 uint32_t flag, _Bool set) {
410 for (v = host->volumes; v; v = v->next) {
412 v->cfg_volume_usage.flags |= flag;
414 v->cfg_volume_usage.flags &= ~flag;
416 } /* }}} void host_set_all_cfg_volume_usage_flags */
419 * Various submit functions.
421 * They all eventually call "submit_values" which creates a value_list_t and
422 * dispatches it to the daemon.
424 static int submit_values (const char *host, /* {{{ */
425 const char *plugin_inst,
426 const char *type, const char *type_inst,
427 value_t *values, int values_len,
430 value_list_t vl = VALUE_LIST_INIT;
433 vl.values_len = values_len;
439 sstrncpy (vl.host, host, sizeof (vl.host));
441 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
442 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
443 if (plugin_inst != NULL)
444 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
445 sstrncpy (vl.type, type, sizeof (vl.type));
446 if (type_inst != NULL)
447 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
449 return (plugin_dispatch_values (&vl));
450 } /* }}} int submit_uint64 */
452 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
453 const char *type, const char *type_inst, counter_t val0, counter_t val1,
458 values[0].counter = val0;
459 values[1].counter = val1;
461 return (submit_values (host, plugin_inst, type, type_inst,
462 values, 2, timestamp));
463 } /* }}} int submit_two_counters */
465 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
466 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
472 return (submit_values (host, plugin_inst, type, type_inst,
474 } /* }}} int submit_counter */
476 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
477 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
482 values[0].gauge = val0;
483 values[1].gauge = val1;
485 return (submit_values (host, plugin_inst, type, type_inst,
486 values, 2, timestamp));
487 } /* }}} int submit_two_gauge */
489 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
490 const char *type, const char *type_inst, double d, time_t timestamp)
494 v.gauge = (gauge_t) d;
496 return (submit_values (host, plugin_inst, type, type_inst,
498 } /* }}} int submit_uint64 */
500 /* Calculate hit ratio from old and new counters and submit the resulting
501 * percentage. Used by "submit_wafl_data". */
502 static int submit_cache_ratio (const char *host, /* {{{ */
503 const char *plugin_inst,
504 const char *type_inst,
513 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
517 hits = new_hits - old_hits;
518 misses = new_misses - old_misses;
520 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
525 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
527 } /* }}} int submit_cache_ratio */
529 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
530 static int submit_wafl_data (const host_config_t *host, const char *instance, /* {{{ */
531 data_wafl_t *old_data, const data_wafl_t *new_data)
533 /* Submit requested counters */
534 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
535 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
536 submit_cache_ratio (host->name, instance, "name_cache_hit",
537 new_data->name_cache_hit, new_data->name_cache_miss,
538 old_data->name_cache_hit, old_data->name_cache_miss,
539 new_data->timestamp);
541 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
542 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
543 submit_cache_ratio (host->name, instance, "find_dir_hit",
544 new_data->find_dir_hit, new_data->find_dir_miss,
545 old_data->find_dir_hit, old_data->find_dir_miss,
546 new_data->timestamp);
548 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
549 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
550 submit_cache_ratio (host->name, instance, "buf_hash_hit",
551 new_data->buf_hash_hit, new_data->buf_hash_miss,
552 old_data->buf_hash_hit, old_data->buf_hash_miss,
553 new_data->timestamp);
555 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
556 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
557 submit_cache_ratio (host->name, instance, "inode_cache_hit",
558 new_data->inode_cache_hit, new_data->inode_cache_miss,
559 old_data->inode_cache_hit, old_data->inode_cache_miss,
560 new_data->timestamp);
562 /* Clear old HAVE_* flags */
563 old_data->flags &= ~HAVE_WAFL_ALL;
565 /* Copy all counters */
566 old_data->timestamp = new_data->timestamp;
567 old_data->name_cache_hit = new_data->name_cache_hit;
568 old_data->name_cache_miss = new_data->name_cache_miss;
569 old_data->find_dir_hit = new_data->find_dir_hit;
570 old_data->find_dir_miss = new_data->find_dir_miss;
571 old_data->buf_hash_hit = new_data->buf_hash_hit;
572 old_data->buf_hash_miss = new_data->buf_hash_miss;
573 old_data->inode_cache_hit = new_data->inode_cache_hit;
574 old_data->inode_cache_miss = new_data->inode_cache_miss;
576 /* Copy HAVE_* flags */
577 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
580 } /* }}} int submit_wafl_data */
582 /* Submits volume performance data to the daemon, taking care to honor and
583 * update flags appropriately. */
584 static int submit_volume_perf_data (const host_config_t *host, /* {{{ */
586 const data_volume_perf_t *new_data)
588 /* Check for and submit disk-octet values */
589 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_IO)
590 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
592 submit_two_counters (host->name, volume->name, "disk_octets", /* type instance = */ NULL,
593 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
596 /* Check for and submit disk-operations values */
597 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_OPS)
598 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
600 submit_two_counters (host->name, volume->name, "disk_ops", /* type instance = */ NULL,
601 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
604 /* Check for, calculate and submit disk-latency values */
605 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_LATENCY
606 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
607 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
608 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
609 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
611 gauge_t latency_per_op_read;
612 gauge_t latency_per_op_write;
614 latency_per_op_read = NAN;
615 latency_per_op_write = NAN;
617 /* Check if a counter wrapped around. */
618 if ((new_data->read_ops > volume->perf_data.read_ops)
619 && (new_data->read_latency > volume->perf_data.read_latency))
621 uint64_t diff_ops_read;
622 uint64_t diff_latency_read;
624 diff_ops_read = new_data->read_ops - volume->perf_data.read_ops;
625 diff_latency_read = new_data->read_latency - volume->perf_data.read_latency;
627 if (diff_ops_read > 0)
628 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
631 if ((new_data->write_ops > volume->perf_data.write_ops)
632 && (new_data->write_latency > volume->perf_data.write_latency))
634 uint64_t diff_ops_write;
635 uint64_t diff_latency_write;
637 diff_ops_write = new_data->write_ops - volume->perf_data.write_ops;
638 diff_latency_write = new_data->write_latency - volume->perf_data.write_latency;
640 if (diff_ops_write > 0)
641 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
644 submit_two_gauge (host->name, volume->name, "disk_latency", /* type instance = */ NULL,
645 latency_per_op_read, latency_per_op_write, new_data->timestamp);
648 /* Clear all HAVE_* flags. */
649 volume->perf_data.flags &= ~HAVE_VOLUME_PERF_ALL;
651 /* Copy all counters */
652 volume->perf_data.timestamp = new_data->timestamp;
653 volume->perf_data.read_bytes = new_data->read_bytes;
654 volume->perf_data.write_bytes = new_data->write_bytes;
655 volume->perf_data.read_ops = new_data->read_ops;
656 volume->perf_data.write_ops = new_data->write_ops;
657 volume->perf_data.read_latency = new_data->read_latency;
658 volume->perf_data.write_latency = new_data->write_latency;
660 /* Copy the HAVE_* flags */
661 volume->perf_data.flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
664 } /* }}} int submit_volume_perf_data */
669 * These functions are called with appropriate data returned by the libnetapp
670 * interface which is parsed and submitted with the above functions.
672 /* Data corresponding to <GetWaflPerfData /> */
673 static void query_wafl_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
674 data_wafl_t *wafl = data;
675 data_wafl_t perf_data;
676 const char *plugin_inst;
679 memset (&perf_data, 0, sizeof (perf_data));
681 perf_data.timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
683 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
687 plugin_inst = na_child_get_string(out, "name");
688 if (plugin_inst == NULL)
691 /* Iterate over all counters */
692 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
693 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
697 name = na_child_get_string(counter, "name");
701 value = na_child_get_uint64(counter, "value", UINT64_MAX);
702 if (value == UINT64_MAX)
705 if (!strcmp(name, "name_cache_hit")) {
706 perf_data.name_cache_hit = value;
707 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
708 } else if (!strcmp(name, "name_cache_miss")) {
709 perf_data.name_cache_miss = value;
710 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
711 } else if (!strcmp(name, "find_dir_hit")) {
712 perf_data.find_dir_hit = value;
713 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
714 } else if (!strcmp(name, "find_dir_miss")) {
715 perf_data.find_dir_miss = value;
716 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
717 } else if (!strcmp(name, "buf_hash_hit")) {
718 perf_data.buf_hash_hit = value;
719 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
720 } else if (!strcmp(name, "buf_hash_miss")) {
721 perf_data.buf_hash_miss = value;
722 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
723 } else if (!strcmp(name, "inode_cache_hit")) {
724 perf_data.inode_cache_hit = value;
725 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
726 } else if (!strcmp(name, "inode_cache_miss")) {
727 perf_data.inode_cache_miss = value;
728 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
730 DEBUG("netapp plugin: query_wafl_data: Found unexpected child: %s",
735 submit_wafl_data (host, plugin_inst, wafl, &perf_data);
736 } /* }}} void query_wafl_data */
738 /* Data corresponding to <Disks /> */
739 static int cna_handle_disk_data (const char *hostname, /* {{{ */
740 cfg_disk_t *cfg_disk, na_elem_t *data)
743 na_elem_t *instances;
745 na_elem_iter_t instance_iter;
746 disk_t *worst_disk = NULL;
748 if ((cfg_disk == NULL) || (data == NULL))
751 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
753 instances = na_elem_child (data, "instances");
754 if (instances == NULL)
756 ERROR ("netapp plugin: cna_handle_disk_data: "
757 "na_elem_child (\"instances\") failed.");
761 /* Iterate over all children */
762 instance_iter = na_child_iterator (instances);
763 for (instance = na_iterator_next (&instance_iter);
765 instance = na_iterator_next(&instance_iter))
770 na_elem_iter_t counter_iterator;
773 memset (&new_data, 0, sizeof (new_data));
774 new_data.timestamp = timestamp;
775 new_data.disk_busy_percent = NAN;
777 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
778 if (old_data == NULL)
781 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
782 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
783 for (counter = na_iterator_next(&counter_iterator);
785 counter = na_iterator_next(&counter_iterator))
790 name = na_child_get_string(counter, "name");
794 value = na_child_get_uint64(counter, "value", UINT64_MAX);
795 if (value == UINT64_MAX)
798 if (strcmp(name, "disk_busy") == 0)
800 new_data.disk_busy = value;
801 new_data.flags |= HAVE_DISK_BUSY;
803 else if (strcmp(name, "base_for_disk_busy") == 0)
805 new_data.base_for_disk_busy = value;
806 new_data.flags |= HAVE_DISK_BASE;
810 DEBUG ("netapp plugin: cna_handle_disk_data: "
811 "Counter not handled: %s = %"PRIu64,
816 /* If all required counters are available and did not just wrap around,
817 * calculate the busy percentage. Otherwise, the value is initialized to
818 * NAN at the top of the for-loop. */
819 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
820 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
821 && (new_data.disk_busy >= old_data->disk_busy)
822 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
827 busy_diff = new_data.disk_busy - old_data->disk_busy;
828 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
830 new_data.disk_busy_percent = 100.0
831 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
834 /* Clear HAVE_* flags */
835 old_data->flags &= ~HAVE_DISK_ALL;
838 old_data->timestamp = new_data.timestamp;
839 old_data->disk_busy = new_data.disk_busy;
840 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
841 old_data->disk_busy_percent = new_data.disk_busy_percent;
844 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
846 if ((worst_disk == NULL)
847 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
848 worst_disk = old_data;
849 } /* for (all disks) */
851 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
852 submit_double (hostname, "system", "percent", "disk_busy",
853 worst_disk->disk_busy_percent, timestamp);
856 } /* }}} int cna_handle_disk_data */
858 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
865 if (cd->query != NULL)
868 cd->query = na_elem_new ("perf-object-get-instances");
869 if (cd->query == NULL)
871 ERROR ("netapp plugin: na_elem_new failed.");
874 na_child_add_string (cd->query, "objectname", "disk");
876 e = na_elem_new("counters");
879 na_elem_free (cd->query);
881 ERROR ("netapp plugin: na_elem_new failed.");
884 na_child_add_string(e, "foo", "disk_busy");
885 na_child_add_string(e, "foo", "base_for_disk_busy");
886 na_child_add(cd->query, e);
889 } /* }}} int cna_setup_disk */
891 static int cna_query_disk (host_config_t *host) /* {{{ */
900 if (host->cfg_disk == NULL)
904 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
907 status = cna_setup_disk (host->cfg_disk);
910 assert (host->cfg_disk->query != NULL);
912 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
913 if (na_results_status (data) != NA_OK)
915 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed: %s",
916 na_results_reason (data));
921 status = cna_handle_disk_data (host->name, host->cfg_disk, data);
924 host->cfg_disk->interval.last_read = now;
928 } /* }}} int cna_query_disk */
930 /* Data corresponding to <GetVolumeData /> */
931 static void collect_volume_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
934 cfg_volume_usage_t *cfg_volume_data = data;
936 out = na_elem_child(out, "volumes");
937 na_elem_iter_t inst_iter = na_child_iterator(out);
938 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
939 uint64_t size_free = 0, size_used = 0, snap_reserved = 0;
942 const char *sis_state;
943 uint64_t sis_saved_reported;
946 volume = get_volume(host, na_child_get_string(inst, "name"),
947 cfg_volume_data->flags, /* perf_flags = */ 0);
951 if (!(volume->cfg_volume_usage.flags & CFG_VOLUME_USAGE_DF))
954 /* 2^4 exa-bytes? This will take a while ;) */
955 size_free = na_child_get_uint64(inst, "size-available", UINT64_MAX);
956 if (size_free != UINT64_MAX)
957 submit_double (host->name, volume->name, "df_complex", "free",
958 (double) size_free, /* time = */ 0);
960 size_used = na_child_get_uint64(inst, "size-used", UINT64_MAX);
961 if (size_used != UINT64_MAX) {
962 if ((volume->cfg_volume_usage.flags & HAVE_VOLUME_USAGE_SNAP)
963 && (size_used >= volume->cfg_volume_usage.snap_used))
964 size_used -= volume->cfg_volume_usage.snap_used;
965 submit_double (host->name, volume->name, "df_complex", "used",
966 (double) size_used, /* time = */ 0);
969 snap_reserved = na_child_get_uint64(inst, "snapshot-blocks-reserved", UINT64_MAX);
970 if (!(volume->cfg_volume_usage.flags & HAVE_VOLUME_USAGE_SNAP) && (snap_reserved != UINT64_MAX))
971 /* If we have snap usage data this value has already been submitted. */
972 /* 1 block == 1024 bytes as per API docs */
973 submit_double (host->name, volume->name, "df_complex", "snap_reserved",
974 (double) (1024 * snap_reserved), /* time = */ 0);
976 sis = na_elem_child(inst, "sis");
980 sis_state = na_child_get_string(sis, "state");
981 if ((sis_state == NULL)
982 || (strcmp ("enabled", sis_state) != 0))
985 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
986 if (sis_saved_reported == UINT64_MAX)
989 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
990 if ((sis_saved_reported >> 32) != 0) {
991 /* In case they ever fix this bug. */
992 sis_saved = sis_saved_reported;
994 uint64_t sis_saved_percent;
995 uint64_t sis_saved_guess;
996 uint64_t overflow_guess;
997 uint64_t guess1, guess2, guess3;
999 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1000 if (sis_saved_percent > 100)
1003 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1004 * will hopefully be fixed in later versions. To work around the bug, try
1005 * to figure out how often the 32bit integer wrapped around by using the
1006 * "percentage-saved" value. Because the percentage is in the range
1007 * [0-100], this should work as long as the saved space does not exceed
1009 /* percentage-saved = size-saved / (size-saved + size-used) */
1010 if (sis_saved_percent < 100)
1011 sis_saved_guess = size_used * sis_saved_percent / (100 - sis_saved_percent);
1013 sis_saved_guess = size_used;
1015 overflow_guess = sis_saved_guess >> 32;
1016 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1017 guess2 = (overflow_guess << 32) + sis_saved_reported;
1018 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1020 if (sis_saved_guess < guess2) {
1021 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1026 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1031 } /* end of 32-bit workaround */
1033 submit_double (host->name, volume->name, "df_complex", "sis_saved",
1034 (double) sis_saved, /* time = */ 0);
1036 } /* }}} void collect_volume_data */
1038 /* Data corresponding to <GetVolumePerfData /> */
1039 static void query_volume_perf_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
1040 cfg_volume_perf_t *cfg_volume_perf = data;
1042 na_elem_t *counter, *inst;
1044 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
1046 out = na_elem_child(out, "instances");
1047 na_elem_iter_t inst_iter = na_child_iterator(out);
1048 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
1049 data_volume_perf_t perf_data;
1052 memset (&perf_data, 0, sizeof (perf_data));
1053 perf_data.timestamp = timestamp;
1055 volume = get_volume(host, na_child_get_string(inst, "name"),
1056 /* data_flags = */ 0, cfg_volume_perf->flags);
1060 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
1061 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
1065 name = na_child_get_string(counter, "name");
1069 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1070 if (value == UINT64_MAX)
1073 if (!strcmp(name, "read_data")) {
1074 perf_data.read_bytes = value;
1075 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1076 } else if (!strcmp(name, "write_data")) {
1077 perf_data.write_bytes = value;
1078 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1079 } else if (!strcmp(name, "read_ops")) {
1080 perf_data.read_ops = value;
1081 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1082 } else if (!strcmp(name, "write_ops")) {
1083 perf_data.write_ops = value;
1084 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1085 } else if (!strcmp(name, "read_latency")) {
1086 perf_data.read_latency = value;
1087 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1088 } else if (!strcmp(name, "write_latency")) {
1089 perf_data.write_latency = value;
1090 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1094 submit_volume_perf_data (host, volume, &perf_data);
1095 } /* for (volume) */
1096 } /* }}} void query_volume_perf_data */
1098 /* Data corresponding to <GetSystemPerfData /> */
1099 static void collect_perf_system_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
1100 counter_t disk_read = 0, disk_written = 0;
1101 counter_t net_recv = 0, net_sent = 0;
1102 counter_t cpu_busy = 0, cpu_total = 0;
1103 unsigned int counter_flags = 0;
1105 cfg_system_t *cfg_system = data;
1106 const char *instance;
1110 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
1111 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
1112 instance = na_child_get_string(out, "name");
1114 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
1115 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
1119 name = na_child_get_string(counter, "name");
1123 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1124 if (value == UINT64_MAX)
1127 if (!strcmp(name, "disk_data_read")) {
1128 disk_read = (counter_t) (value * 1024);
1129 counter_flags |= 0x01;
1130 } else if (!strcmp(name, "disk_data_written")) {
1131 disk_written = (counter_t) (value * 1024);
1132 counter_flags |= 0x02;
1133 } else if (!strcmp(name, "net_data_recv")) {
1134 net_recv = (counter_t) (value * 1024);
1135 counter_flags |= 0x04;
1136 } else if (!strcmp(name, "net_data_sent")) {
1137 net_sent = (counter_t) (value * 1024);
1138 counter_flags |= 0x08;
1139 } else if (!strcmp(name, "cpu_busy")) {
1140 cpu_busy = (counter_t) value;
1141 counter_flags |= 0x10;
1142 } else if (!strcmp(name, "cpu_elapsed_time")) {
1143 cpu_total = (counter_t) value;
1144 counter_flags |= 0x20;
1145 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1146 && (value > 0) && (strlen(name) > 4)
1147 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1148 submit_counter (host->name, instance, "disk_ops_complex", name,
1149 (counter_t) value, timestamp);
1151 } /* for (counter) */
1153 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1154 && ((counter_flags & 0x03) == 0x03))
1155 submit_two_counters (host->name, instance, "disk_octets", NULL,
1156 disk_read, disk_written, timestamp);
1158 if ((cfg_system->flags & CFG_SYSTEM_NET)
1159 && ((counter_flags & 0x0c) == 0x0c))
1160 submit_two_counters (host->name, instance, "if_octets", NULL,
1161 net_recv, net_sent, timestamp);
1163 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1164 && ((counter_flags & 0x30) == 0x30)) {
1165 submit_counter (host->name, instance, "cpu", "system",
1166 cpu_busy, timestamp);
1167 submit_counter (host->name, instance, "cpu", "idle",
1168 cpu_total - cpu_busy, timestamp);
1170 } /* }}} void collect_perf_system_data */
1173 * Configuration handling
1175 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1176 * is false. On error, the flag-field is not changed. */
1177 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1178 uint32_t *flags, uint32_t flag)
1180 if ((ci == NULL) || (flags == NULL))
1183 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1185 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1190 if (ci->values[0].value.boolean)
1196 } /* }}} int cna_config_bool_to_flag */
1198 /* Handling of the "Multiplier" option which is allowed in every block. */
1199 static int cna_config_get_multiplier (const oconfig_item_t *ci, /* {{{ */
1200 cfg_service_t *service)
1204 if ((ci == NULL) || (service == NULL))
1207 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1209 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1213 tmp = (int) (ci->values[0].value.number + .5);
1216 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1220 service->multiplier = tmp;
1221 service->skip_countdown = tmp;
1224 } /* }}} int cna_config_get_multiplier */
1226 /* Handling of the "Interval" option which is allowed in every block. */
1227 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1228 cna_interval_t *out_interval)
1232 if ((ci == NULL) || (out_interval == NULL))
1235 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1237 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1241 tmp = (time_t) (ci->values[0].value.number + .5);
1244 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1248 out_interval->interval = tmp;
1249 out_interval->last_read = 0;
1252 } /* }}} int cna_config_get_interval */
1254 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1255 * <GetVolumePerfData /> block. */
1256 static void cna_config_volume_performance_option (host_config_t *host, /* {{{ */
1257 cfg_volume_perf_t *perf_volume, const oconfig_item_t *item,
1262 for (i = 0; i < item->values_num; ++i) {
1267 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1268 WARNING("netapp plugin: Ignoring non-string argument in "
1269 "\"GetVolumePerfData\" block for host %s", host->name);
1273 name = item->values[i].value.string;
1274 if (name[0] == '+') {
1277 } else if (name[0] == '-') {
1284 perf_volume->flags |= flag;
1285 else /* if (!set) */
1286 perf_volume->flags &= ~flag;
1288 host_set_all_perf_data_flags(host, flag, set);
1292 v = get_volume (host, name, /* data_flags = */ 0, perf_volume->flags);
1297 v->perf_data.flags |= flag;
1298 else /* if (!set) */
1299 v->perf_data.flags &= ~flag;
1300 } /* for (i = 0 .. item->values_num) */
1301 } /* }}} void cna_config_volume_performance_option */
1303 /* Corresponds to a <GetVolumePerfData /> block */
1304 static void cna_config_volume_performance(host_config_t *host, const oconfig_item_t *ci) { /* {{{ */
1305 int i, had_io = 0, had_ops = 0, had_latency = 0;
1306 cfg_service_t *service;
1307 cfg_volume_perf_t *perf_volume;
1309 service = malloc(sizeof(*service));
1311 service->handler = query_volume_perf_data;
1312 perf_volume = service->data = malloc(sizeof(*perf_volume));
1313 perf_volume->flags = CFG_VOLUME_PERF_INIT;
1314 service->next = host->services;
1315 host->services = service;
1316 for (i = 0; i < ci->children_num; ++i) {
1317 oconfig_item_t *item = ci->children + i;
1319 /* if (!item || !item->key || !*item->key) continue; */
1320 if (!strcasecmp(item->key, "Multiplier")) {
1321 cna_config_get_multiplier (item, service);
1322 } else if (!strcasecmp(item->key, "GetIO")) {
1324 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_IO);
1325 } else if (!strcasecmp(item->key, "GetOps")) {
1327 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_OPS);
1328 } else if (!strcasecmp(item->key, "GetLatency")) {
1330 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_LATENCY);
1334 perf_volume->flags |= CFG_VOLUME_PERF_IO;
1335 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_IO, /* set = */ true);
1338 perf_volume->flags |= CFG_VOLUME_PERF_OPS;
1339 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_OPS, /* set = */ true);
1342 perf_volume->flags |= CFG_VOLUME_PERF_LATENCY;
1343 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_LATENCY, /* set = */ true);
1345 } /* }}} void cna_config_volume_performance */
1347 /* Handling of the "GetDiskUtil" option within a <GetVolumeData /> block. */
1348 static void cna_config_volume_usage_option (host_config_t *host, /* {{{ */
1349 cfg_volume_usage_t *cfg_volume_data, const oconfig_item_t *item, uint32_t flag)
1353 for (i = 0; i < item->values_num; ++i) {
1358 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1359 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolData\""
1360 "block for host %s", host->name);
1364 name = item->values[i].value.string;
1365 if (name[0] == '+') {
1368 } else if (name[0] == '-') {
1375 cfg_volume_data->flags |= flag;
1376 else /* if (!set) */
1377 cfg_volume_data->flags &= ~flag;
1379 host_set_all_cfg_volume_usage_flags(host, flag, set);
1383 v = get_volume(host, name, cfg_volume_data->flags, /* perf_flags = */ 0);
1387 if (!v->cfg_volume_usage.flags)
1388 v->cfg_volume_usage.flags = cfg_volume_data->flags;
1391 v->cfg_volume_usage.flags |= flag;
1392 else /* if (!set) */
1393 v->cfg_volume_usage.flags &= ~flag;
1395 } /* }}} void cna_config_volume_usage_option */
1397 /* Corresponds to a <GetVolumeData /> block */
1398 static void cna_config_volume_usage(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1400 cfg_service_t *service;
1401 cfg_volume_usage_t *cfg_volume_data;
1403 service = malloc(sizeof(*service));
1405 service->handler = collect_volume_data;
1406 cfg_volume_data = service->data = malloc(sizeof(*cfg_volume_data));
1407 cfg_volume_data->flags = CFG_VOLUME_USAGE_INIT;
1408 service->next = host->services;
1409 host->services = service;
1410 for (i = 0; i < ci->children_num; ++i) {
1411 oconfig_item_t *item = ci->children + i;
1413 /* if (!item || !item->key || !*item->key) continue; */
1414 if (!strcasecmp(item->key, "Multiplier")) {
1415 cna_config_get_multiplier (item, service);
1416 } else if (!strcasecmp(item->key, "GetDiskUtil")) {
1418 cna_config_volume_usage_option(host, cfg_volume_data, item, CFG_VOLUME_USAGE_DF);
1419 } else if (!strcasecmp(item->key, "GetSnapUtil")) {
1421 cna_config_volume_usage_option(host, cfg_volume_data, item, CFG_VOLUME_USAGE_SNAP);
1425 cfg_volume_data->flags |= CFG_VOLUME_USAGE_DF;
1426 host_set_all_cfg_volume_usage_flags(host, CFG_VOLUME_USAGE_DF, /* set = */ true);
1428 if (cfg_volume_data->flags & CFG_VOLUME_USAGE_SNAP) {
1429 WARNING("netapp plugin: The \"GetSnapUtil\" option does not support the \"+\" wildcard.");
1431 } /* }}} void cna_config_volume_usage */
1433 /* Corresponds to a <Disks /> block */
1434 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1435 cfg_disk_t *cfg_disk;
1438 if ((host == NULL) || (ci == NULL))
1441 if (host->cfg_disk == NULL)
1443 cfg_disk = malloc (sizeof (*cfg_disk));
1444 if (cfg_disk == NULL)
1446 memset (cfg_disk, 0, sizeof (*cfg_disk));
1448 /* Set default flags */
1449 cfg_disk->flags = CFG_DISK_ALL;
1450 cfg_disk->query = NULL;
1451 cfg_disk->disks = NULL;
1453 host->cfg_disk = cfg_disk;
1455 cfg_disk = host->cfg_disk;
1457 for (i = 0; i < ci->children_num; ++i) {
1458 oconfig_item_t *item = ci->children + i;
1460 /* if (!item || !item->key || !*item->key) continue; */
1461 if (strcasecmp(item->key, "Interval") == 0)
1462 cna_config_get_interval (item, &cfg_disk->interval);
1463 else if (strcasecmp(item->key, "GetBusy") == 0)
1464 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
1468 } /* }}} int cna_config_disk */
1470 /* Corresponds to a <GetWaflPerfData /> block */
1471 static void cna_config_wafl(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1473 cfg_service_t *service;
1474 data_wafl_t *perf_wafl;
1476 service = malloc(sizeof(*service));
1477 if (service == NULL)
1479 memset (service, 0, sizeof (*service));
1482 service->handler = query_wafl_data;
1483 perf_wafl = service->data = malloc(sizeof(*perf_wafl));
1484 perf_wafl->flags = CFG_WAFL_ALL;
1486 for (i = 0; i < ci->children_num; ++i) {
1487 oconfig_item_t *item = ci->children + i;
1489 if (!strcasecmp(item->key, "Multiplier")) {
1490 cna_config_get_multiplier (item, service);
1491 } else if (!strcasecmp(item->key, "GetNameCache")) {
1492 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_NAME_CACHE);
1493 } else if (!strcasecmp(item->key, "GetDirCache")) {
1494 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_DIR_CACHE);
1495 } else if (!strcasecmp(item->key, "GetBufCache")) {
1496 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_BUF_CACHE);
1497 } else if (!strcasecmp(item->key, "GetInodeCache")) {
1498 cna_config_bool_to_flag (item, &perf_wafl->flags, CFG_WAFL_INODE_CACHE);
1500 WARNING ("netapp plugin: The %s config option is not allowed within "
1501 "`GetWaflPerfData' blocks.", item->key);
1505 service->next = host->services;
1506 host->services = service;
1507 } /* }}} void cna_config_wafl */
1509 /* Corresponds to a <GetSystemPerfData /> block */
1510 static int cna_config_system (host_config_t *host, /* {{{ */
1511 oconfig_item_t *ci, const cfg_service_t *default_service)
1514 cfg_service_t *service;
1515 cfg_system_t *cfg_system;
1517 service = malloc(sizeof(*service));
1518 if (service == NULL)
1520 memset (service, 0, sizeof (*service));
1521 *service = *default_service;
1522 service->handler = collect_perf_system_data;
1524 cfg_system = malloc(sizeof(*cfg_system));
1525 if (cfg_system == NULL) {
1529 memset (cfg_system, 0, sizeof (*cfg_system));
1530 cfg_system->flags = CFG_SYSTEM_ALL;
1531 service->data = cfg_system;
1533 for (i = 0; i < ci->children_num; ++i) {
1534 oconfig_item_t *item = ci->children + i;
1536 if (!strcasecmp(item->key, "Multiplier")) {
1537 cna_config_get_multiplier (item, service);
1538 } else if (!strcasecmp(item->key, "GetCPULoad")) {
1539 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
1540 } else if (!strcasecmp(item->key, "GetInterfaces")) {
1541 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
1542 } else if (!strcasecmp(item->key, "GetDiskOps")) {
1543 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
1544 } else if (!strcasecmp(item->key, "GetDiskIO")) {
1545 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
1547 WARNING ("netapp plugin: The %s config option is not allowed within "
1548 "`GetSystemPerfData' blocks.", item->key);
1552 service->next = host->services;
1553 host->services = service;
1556 } /* }}} int cna_config_system */
1558 /* Corresponds to a <Host /> block. */
1559 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
1560 const host_config_t *default_host, const cfg_service_t *def_def_service)
1562 oconfig_item_t *item;
1563 host_config_t *host;
1564 cfg_service_t default_service = *def_def_service;
1568 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1569 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
1573 host = malloc(sizeof(*host));
1574 memcpy (host, default_host, sizeof (*host));
1576 status = cf_util_get_string (ci, &host->name);
1583 for (i = 0; i < ci->children_num; ++i) {
1584 item = ci->children + i;
1588 if (!strcasecmp(item->key, "Address")) {
1589 status = cf_util_get_string (item, &host->host);
1590 } else if (!strcasecmp(item->key, "Port")) {
1593 tmp = cf_util_get_port_number (item);
1596 } else if (!strcasecmp(item->key, "Protocol")) {
1597 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"))) {
1598 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
1601 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
1602 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
1603 } else if (!strcasecmp(item->key, "User")) {
1604 status = cf_util_get_string (item, &host->username);
1605 } else if (!strcasecmp(item->key, "Password")) {
1606 status = cf_util_get_string (item, &host->password);
1607 } else if (!strcasecmp(item->key, "Interval")) {
1608 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) {
1609 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
1612 host->interval = item->values[0].value.number;
1613 } else if (!strcasecmp(item->key, "GetVolumePerfData")) {
1614 cna_config_volume_performance(host, item);
1615 } else if (!strcasecmp(item->key, "GetSystemPerfData")) {
1616 cna_config_system(host, item, &default_service);
1617 } else if (!strcasecmp(item->key, "GetWaflPerfData")) {
1618 cna_config_wafl(host, item);
1619 } else if (!strcasecmp(item->key, "Disks")) {
1620 cna_config_disk(host, item);
1621 } else if (!strcasecmp(item->key, "GetVolumeData")) {
1622 cna_config_volume_usage(host, item);
1624 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
1625 item->key, ci->values[0].value.string);
1632 if (host->host == NULL)
1633 host->host = strdup (host->name);
1635 if (host->host == NULL)
1638 if (host->port <= 0)
1639 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
1641 if ((host->username == NULL) || (host->password == NULL)) {
1642 WARNING("netapp plugin: Please supply login information for host \"%s\". "
1643 "Ignoring host block.", host->name);
1649 free_host_config (host);
1654 } /* }}} host_config_t *cna_config_host */
1657 * Callbacks registered with the daemon
1659 * Pretty standard stuff here.
1661 static int cna_init(void) { /* {{{ */
1664 host_config_t *host;
1665 cfg_service_t *service;
1667 if (!global_host_config) {
1668 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
1672 memset (err, 0, sizeof (err));
1673 if (!na_startup(err, sizeof(err))) {
1674 err[sizeof (err) - 1] = 0;
1675 ERROR("netapp plugin: Error initializing netapp API: %s", err);
1679 for (host = global_host_config; host; host = host->next) {
1680 /* Request version 1.1 of the ONTAP API */
1681 host->srv = na_server_open(host->host,
1682 /* major version = */ 1, /* minor version = */ 1);
1683 if (host->srv == NULL) {
1684 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
1688 if (host->interval < interval_g)
1689 host->interval = interval_g;
1691 na_server_set_transport_type(host->srv, host->protocol,
1692 /* transportarg = */ NULL);
1693 na_server_set_port(host->srv, host->port);
1694 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
1695 na_server_adminuser(host->srv, host->username, host->password);
1696 na_server_set_timeout(host->srv, 5 /* seconds */);
1698 for (service = host->services; service; service = service->next) {
1699 service->interval = host->interval * service->multiplier;
1701 if (service->handler == collect_perf_system_data) {
1702 service->query = na_elem_new("perf-object-get-instances");
1703 na_child_add_string(service->query, "objectname", "system");
1704 } else if (service->handler == query_volume_perf_data) {
1705 service->query = na_elem_new("perf-object-get-instances");
1706 na_child_add_string(service->query, "objectname", "volume");
1707 e = na_elem_new("counters");
1708 /* "foo" means: This string has to be here but
1709 the content doesn't matter. */
1710 na_child_add_string(e, "foo", "read_ops");
1711 na_child_add_string(e, "foo", "write_ops");
1712 na_child_add_string(e, "foo", "read_data");
1713 na_child_add_string(e, "foo", "write_data");
1714 na_child_add_string(e, "foo", "read_latency");
1715 na_child_add_string(e, "foo", "write_latency");
1716 na_child_add(service->query, e);
1717 } else if (service->handler == query_wafl_data) {
1718 service->query = na_elem_new("perf-object-get-instances");
1719 na_child_add_string(service->query, "objectname", "wafl");
1720 e = na_elem_new("counters");
1721 na_child_add_string(e, "foo", "name_cache_hit");
1722 na_child_add_string(e, "foo", "name_cache_miss");
1723 na_child_add_string(e, "foo", "find_dir_hit");
1724 na_child_add_string(e, "foo", "find_dir_miss");
1725 na_child_add_string(e, "foo", "buf_hash_hit");
1726 na_child_add_string(e, "foo", "buf_hash_miss");
1727 na_child_add_string(e, "foo", "inode_cache_hit");
1728 na_child_add_string(e, "foo", "inode_cache_miss");
1729 /* na_child_add_string(e, "foo", "inode_eject_time"); */
1730 /* na_child_add_string(e, "foo", "buf_eject_time"); */
1731 na_child_add(service->query, e);
1732 } else if (service->handler == collect_volume_data) {
1733 service->query = na_elem_new("volume-list-info");
1734 /* na_child_add_string(service->query, "objectname", "volume"); */
1735 /* } else if (service->handler == collect_snapshot_data) { */
1736 /* service->query = na_elem_new("snapshot-list-info"); */
1738 } /* for (host->services) */
1741 } /* }}} int cna_init */
1743 static int cna_config (oconfig_item_t *ci) { /* {{{ */
1745 oconfig_item_t *item;
1746 host_config_t default_host = HOST_INIT;
1747 cfg_service_t default_service = SERVICE_INIT;
1749 for (i = 0; i < ci->children_num; ++i) {
1750 item = ci->children + i;
1752 if (!strcasecmp(item->key, "Host")) {
1753 host_config_t *host;
1756 host = cna_config_host(item, &default_host, &default_service);
1760 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
1762 if (strcasecmp (host->name, tmp->name) == 0)
1763 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
1764 "This is probably a bad idea.",
1767 if (tmp->next == NULL)
1773 global_host_config = host;
1777 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
1781 } /* }}} int cna_config */
1783 static int cna_read(void) { /* {{{ */
1785 host_config_t *host;
1786 cfg_service_t *service;
1788 for (host = global_host_config; host; host = host->next) {
1789 for (service = host->services; service; service = service->next) {
1790 if (--service->skip_countdown > 0) continue;
1791 service->skip_countdown = service->multiplier;
1792 out = na_server_invoke_elem(host->srv, service->query);
1793 if (na_results_status(out) != NA_OK) {
1794 int netapp_errno = na_results_errno(out);
1795 ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
1797 if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
1798 /* Network problems. Just give up on all other services on this host. */
1803 service->handler(host, out, service->data);
1805 } /* for (host->services) */
1807 cna_query_disk (host);
1810 } /* }}} int cna_read */
1812 void module_register(void) {
1813 plugin_register_complex_config("netapp", cna_config);
1814 plugin_register_init("netapp", cna_init);
1815 plugin_register_read("netapp", cna_read);
1818 /* vim: set sw=2 ts=2 noet fdm=marker : */