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
54 cna_interval_t interval;
59 * \brief Persistent data for WAFL performance counters. (a.k.a. cache performance)
61 * The cache counters use old counter values to calculate a hit ratio for each
62 * counter. The "cfg_wafl_t" struct therefore contains old counter values along
63 * with flags, which are set if the counter is valid.
65 * The function "cna_handle_wafl_data" will fill a new structure of this kind
66 * with new values, then pass both, new and old data, to "submit_wafl_data".
67 * That function calculates the hit ratios, submits the calculated values and
68 * updates the old counter values for the next iteration.
70 #define CFG_WAFL_NAME_CACHE 0x0001
71 #define CFG_WAFL_DIR_CACHE 0x0002
72 #define CFG_WAFL_BUF_CACHE 0x0004
73 #define CFG_WAFL_INODE_CACHE 0x0008
74 #define CFG_WAFL_ALL 0x000F
75 #define HAVE_WAFL_NAME_CACHE_HIT 0x0100
76 #define HAVE_WAFL_NAME_CACHE_MISS 0x0200
77 #define HAVE_WAFL_NAME_CACHE (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
78 #define HAVE_WAFL_FIND_DIR_HIT 0x0400
79 #define HAVE_WAFL_FIND_DIR_MISS 0x0800
80 #define HAVE_WAFL_FIND_DIR (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
81 #define HAVE_WAFL_BUF_HASH_HIT 0x1000
82 #define HAVE_WAFL_BUF_HASH_MISS 0x2000
83 #define HAVE_WAFL_BUF_HASH (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
84 #define HAVE_WAFL_INODE_CACHE_HIT 0x4000
85 #define HAVE_WAFL_INODE_CACHE_MISS 0x8000
86 #define HAVE_WAFL_INODE_CACHE (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
87 #define HAVE_WAFL_ALL 0xff00
90 cna_interval_t interval;
94 uint64_t name_cache_hit;
95 uint64_t name_cache_miss;
96 uint64_t find_dir_hit;
97 uint64_t find_dir_miss;
98 uint64_t buf_hash_hit;
99 uint64_t buf_hash_miss;
100 uint64_t inode_cache_hit;
101 uint64_t inode_cache_miss;
105 * \brief Persistent data for volume performance data.
107 * The code below uses the difference of the operations and latency counters to
108 * calculate an average per-operation latency. For this, old counters need to
109 * be stored in the "data_volume_perf_t" structure. The byte-counters are just
110 * kept for completeness sake. The "flags" member indicates if each counter is
113 * The "query_volume_perf_data" function will fill a new struct of this type
114 * and pass both, old and new data, to "submit_volume_perf_data". In that
115 * function, the per-operation latency is calculated and dispatched, then the
116 * old counters are updated.
118 #define CFG_VOLUME_PERF_INIT 0x0001
119 #define CFG_VOLUME_PERF_IO 0x0002
120 #define CFG_VOLUME_PERF_OPS 0x0003
121 #define CFG_VOLUME_PERF_LATENCY 0x0008
122 #define CFG_VOLUME_PERF_ALL 0x000F
123 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
124 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
125 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
126 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
127 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
128 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
129 #define HAVE_VOLUME_PERF_ALL 0x03F0
138 uint64_t write_bytes;
141 uint64_t read_latency;
142 uint64_t write_latency;
143 } data_volume_perf_t;
146 * \brief Configuration struct for volume usage data (free / used).
148 #define CFG_VOLUME_USAGE_INIT 0x0001
149 #define CFG_VOLUME_USAGE_DF 0x0002
150 #define CFG_VOLUME_USAGE_SNAP 0x0004
151 #define HAVE_VOLUME_USAGE_SNAP 0x0008
155 } cfg_volume_usage_t;
157 typedef struct service_config_s {
159 service_handler_t *handler;
164 struct service_config_s *next;
166 #define SERVICE_INIT {0, 0, 1, 1, 0, 0, 0}
169 * \brief Struct representing a volume.
171 * A volume currently has a name and two sets of values:
173 * - Performance data, such as bytes read/written, number of operations
174 * performed and average time per operation.
176 * - Usage data, i. e. amount of used and free space in the volume.
178 typedef struct volume_s {
180 data_volume_perf_t perf_data;
181 cfg_volume_usage_t cfg_volume_usage;
182 struct volume_s *next;
186 * \brief A disk in the NetApp.
188 * A disk doesn't have any more information than its name at the moment.
189 * The name includes the "disk_" prefix.
191 #define HAVE_DISK_BUSY 0x10
192 #define HAVE_DISK_BASE 0x20
193 #define HAVE_DISK_ALL 0x30
194 typedef struct disk_s {
199 uint64_t base_for_disk_busy;
200 double disk_busy_percent;
204 #define CFG_DISK_BUSIEST 0x01
205 #define CFG_DISK_ALL 0x01
208 cna_interval_t interval;
213 struct host_config_s {
215 na_server_transport_t protocol;
223 cfg_service_t *services;
224 cfg_disk_t *cfg_disk;
225 cfg_wafl_t *cfg_wafl;
226 cfg_system_t *cfg_system;
229 struct host_config_s *next;
231 #define HOST_INIT { NULL, NA_SERVER_TRANSPORT_HTTPS, NULL, 0, NULL, NULL, 0, \
232 NULL, NULL, NULL, NULL, \
235 static host_config_t *global_host_config;
240 * Used to free the various structures above.
242 static void free_volume (volume_t *volume) /* {{{ */
248 sfree (volume->name);
252 } /* }}} void free_volume */
254 static void free_disk (disk_t *disk) /* {{{ */
264 } /* }}} void free_disk */
266 static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
271 if (cw->query != NULL)
272 na_elem_free (cw->query);
275 } /* }}} void free_cfg_wafl */
277 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
279 if (cfg_disk == NULL)
282 if (cfg_disk->query != NULL)
283 na_elem_free (cfg_disk->query);
285 free_disk (cfg_disk->disks);
287 } /* }}} void free_cfg_disk */
289 static void free_cfg_system (cfg_system_t *cs) /* {{{ */
294 if (cs->query != NULL)
295 na_elem_free (cs->query);
298 } /* }}} void free_cfg_system */
300 static void free_cfg_service (cfg_service_t *service) /* {{{ */
307 next = service->next;
309 /* FIXME: Free service->data? */
310 na_elem_free(service->query);
314 free_cfg_service (next);
315 } /* }}} void free_cfg_service */
317 static void free_host_config (host_config_t *hc) /* {{{ */
328 sfree (hc->username);
329 sfree (hc->password);
331 free_cfg_service (hc->services);
332 free_cfg_disk (hc->cfg_disk);
333 free_cfg_wafl (hc->cfg_wafl);
334 free_cfg_system (hc->cfg_system);
335 free_volume (hc->volumes);
339 free_host_config (next);
340 } /* }}} void free_host_config */
343 * Auxiliary functions
345 * Used to look up volumes and disks or to handle flags.
347 static volume_t *get_volume (host_config_t *host, const char *name, /* {{{ */
348 uint32_t vol_usage_flags, uint32_t vol_perf_flags)
355 /* Make sure the default flags include the init-bit. */
356 if (vol_usage_flags != 0)
357 vol_usage_flags |= CFG_VOLUME_USAGE_INIT;
358 if (vol_perf_flags != 0)
359 vol_perf_flags |= CFG_VOLUME_PERF_INIT;
361 for (v = host->volumes; v; v = v->next) {
362 if (strcmp(v->name, name) != 0)
365 /* Check if the flags have been initialized. */
366 if (((v->cfg_volume_usage.flags & CFG_VOLUME_USAGE_INIT) == 0)
367 && (vol_usage_flags != 0))
368 v->cfg_volume_usage.flags = vol_usage_flags;
369 if (((v->perf_data.flags & CFG_VOLUME_PERF_INIT) == 0)
370 && (vol_perf_flags != 0))
371 v->perf_data.flags = vol_perf_flags;
376 DEBUG ("netapp plugin: Allocating new entry for volume %s.", name);
377 v = malloc(sizeof(*v));
380 memset (v, 0, sizeof (*v));
382 v->cfg_volume_usage.flags = vol_usage_flags;
383 v->perf_data.flags = vol_perf_flags;
385 v->name = strdup(name);
386 if (v->name == NULL) {
391 v->next = host->volumes;
395 } /* }}} volume_t *get_volume */
397 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
401 if ((cd == NULL) || (name == NULL))
404 for (d = cd->disks; d != NULL; d = d->next) {
405 if (strcmp(d->name, name) == 0)
409 d = malloc(sizeof(*d));
412 memset (d, 0, sizeof (*d));
415 d->name = strdup(name);
416 if (d->name == NULL) {
425 } /* }}} disk_t *get_disk */
427 static void host_set_all_perf_data_flags(const host_config_t *host, /* {{{ */
428 uint32_t flag, _Bool set)
432 for (v = host->volumes; v; v = v->next) {
434 v->perf_data.flags |= flag;
436 v->perf_data.flags &= ~flag;
438 } /* }}} void host_set_all_perf_data_flags */
440 static void host_set_all_cfg_volume_usage_flags(const host_config_t *host, /* {{{ */
441 uint32_t flag, _Bool set) {
444 for (v = host->volumes; v; v = v->next) {
446 v->cfg_volume_usage.flags |= flag;
448 v->cfg_volume_usage.flags &= ~flag;
450 } /* }}} void host_set_all_cfg_volume_usage_flags */
453 * Various submit functions.
455 * They all eventually call "submit_values" which creates a value_list_t and
456 * dispatches it to the daemon.
458 static int submit_values (const char *host, /* {{{ */
459 const char *plugin_inst,
460 const char *type, const char *type_inst,
461 value_t *values, int values_len,
464 value_list_t vl = VALUE_LIST_INIT;
467 vl.values_len = values_len;
473 sstrncpy (vl.host, host, sizeof (vl.host));
475 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
476 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
477 if (plugin_inst != NULL)
478 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
479 sstrncpy (vl.type, type, sizeof (vl.type));
480 if (type_inst != NULL)
481 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
483 return (plugin_dispatch_values (&vl));
484 } /* }}} int submit_uint64 */
486 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
487 const char *type, const char *type_inst, counter_t val0, counter_t val1,
492 values[0].counter = val0;
493 values[1].counter = val1;
495 return (submit_values (host, plugin_inst, type, type_inst,
496 values, 2, timestamp));
497 } /* }}} int submit_two_counters */
499 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
500 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
506 return (submit_values (host, plugin_inst, type, type_inst,
508 } /* }}} int submit_counter */
510 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
511 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
516 values[0].gauge = val0;
517 values[1].gauge = val1;
519 return (submit_values (host, plugin_inst, type, type_inst,
520 values, 2, timestamp));
521 } /* }}} int submit_two_gauge */
523 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
524 const char *type, const char *type_inst, double d, time_t timestamp)
528 v.gauge = (gauge_t) d;
530 return (submit_values (host, plugin_inst, type, type_inst,
532 } /* }}} int submit_uint64 */
534 /* Calculate hit ratio from old and new counters and submit the resulting
535 * percentage. Used by "submit_wafl_data". */
536 static int submit_cache_ratio (const char *host, /* {{{ */
537 const char *plugin_inst,
538 const char *type_inst,
547 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
551 hits = new_hits - old_hits;
552 misses = new_misses - old_misses;
554 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
559 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
561 } /* }}} int submit_cache_ratio */
563 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
564 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
565 cfg_wafl_t *old_data, const cfg_wafl_t *new_data)
567 /* Submit requested counters */
568 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
569 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
570 submit_cache_ratio (hostname, instance, "name_cache_hit",
571 new_data->name_cache_hit, new_data->name_cache_miss,
572 old_data->name_cache_hit, old_data->name_cache_miss,
573 new_data->timestamp);
575 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
576 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
577 submit_cache_ratio (hostname, instance, "find_dir_hit",
578 new_data->find_dir_hit, new_data->find_dir_miss,
579 old_data->find_dir_hit, old_data->find_dir_miss,
580 new_data->timestamp);
582 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
583 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
584 submit_cache_ratio (hostname, instance, "buf_hash_hit",
585 new_data->buf_hash_hit, new_data->buf_hash_miss,
586 old_data->buf_hash_hit, old_data->buf_hash_miss,
587 new_data->timestamp);
589 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
590 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
591 submit_cache_ratio (hostname, instance, "inode_cache_hit",
592 new_data->inode_cache_hit, new_data->inode_cache_miss,
593 old_data->inode_cache_hit, old_data->inode_cache_miss,
594 new_data->timestamp);
596 /* Clear old HAVE_* flags */
597 old_data->flags &= ~HAVE_WAFL_ALL;
599 /* Copy all counters */
600 old_data->timestamp = new_data->timestamp;
601 old_data->name_cache_hit = new_data->name_cache_hit;
602 old_data->name_cache_miss = new_data->name_cache_miss;
603 old_data->find_dir_hit = new_data->find_dir_hit;
604 old_data->find_dir_miss = new_data->find_dir_miss;
605 old_data->buf_hash_hit = new_data->buf_hash_hit;
606 old_data->buf_hash_miss = new_data->buf_hash_miss;
607 old_data->inode_cache_hit = new_data->inode_cache_hit;
608 old_data->inode_cache_miss = new_data->inode_cache_miss;
610 /* Copy HAVE_* flags */
611 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
614 } /* }}} int submit_wafl_data */
616 /* Submits volume performance data to the daemon, taking care to honor and
617 * update flags appropriately. */
618 static int submit_volume_perf_data (const host_config_t *host, /* {{{ */
620 const data_volume_perf_t *new_data)
622 /* Check for and submit disk-octet values */
623 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_IO)
624 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
626 submit_two_counters (host->name, volume->name, "disk_octets", /* type instance = */ NULL,
627 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
630 /* Check for and submit disk-operations values */
631 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_OPS)
632 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
634 submit_two_counters (host->name, volume->name, "disk_ops", /* type instance = */ NULL,
635 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
638 /* Check for, calculate and submit disk-latency values */
639 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_LATENCY
640 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
641 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
642 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
643 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
645 gauge_t latency_per_op_read;
646 gauge_t latency_per_op_write;
648 latency_per_op_read = NAN;
649 latency_per_op_write = NAN;
651 /* Check if a counter wrapped around. */
652 if ((new_data->read_ops > volume->perf_data.read_ops)
653 && (new_data->read_latency > volume->perf_data.read_latency))
655 uint64_t diff_ops_read;
656 uint64_t diff_latency_read;
658 diff_ops_read = new_data->read_ops - volume->perf_data.read_ops;
659 diff_latency_read = new_data->read_latency - volume->perf_data.read_latency;
661 if (diff_ops_read > 0)
662 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
665 if ((new_data->write_ops > volume->perf_data.write_ops)
666 && (new_data->write_latency > volume->perf_data.write_latency))
668 uint64_t diff_ops_write;
669 uint64_t diff_latency_write;
671 diff_ops_write = new_data->write_ops - volume->perf_data.write_ops;
672 diff_latency_write = new_data->write_latency - volume->perf_data.write_latency;
674 if (diff_ops_write > 0)
675 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
678 submit_two_gauge (host->name, volume->name, "disk_latency", /* type instance = */ NULL,
679 latency_per_op_read, latency_per_op_write, new_data->timestamp);
682 /* Clear all HAVE_* flags. */
683 volume->perf_data.flags &= ~HAVE_VOLUME_PERF_ALL;
685 /* Copy all counters */
686 volume->perf_data.timestamp = new_data->timestamp;
687 volume->perf_data.read_bytes = new_data->read_bytes;
688 volume->perf_data.write_bytes = new_data->write_bytes;
689 volume->perf_data.read_ops = new_data->read_ops;
690 volume->perf_data.write_ops = new_data->write_ops;
691 volume->perf_data.read_latency = new_data->read_latency;
692 volume->perf_data.write_latency = new_data->write_latency;
694 /* Copy the HAVE_* flags */
695 volume->perf_data.flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
698 } /* }}} int submit_volume_perf_data */
703 * These functions are called with appropriate data returned by the libnetapp
704 * interface which is parsed and submitted with the above functions.
706 /* Data corresponding to <WAFL /> */
707 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
710 cfg_wafl_t perf_data;
711 const char *plugin_inst;
713 na_elem_t *instances;
715 na_elem_iter_t counter_iter;
717 memset (&perf_data, 0, sizeof (perf_data));
719 perf_data.timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
721 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
722 if (instances == NULL)
724 ERROR ("netapp plugin: cna_handle_wafl_data: "
725 "na_elem_child (\"instances\") failed.");
729 plugin_inst = na_child_get_string(instances, "name");
730 if (plugin_inst == NULL)
732 ERROR ("netapp plugin: cna_handle_wafl_data: "
733 "na_child_get_string (\"name\") failed.");
737 /* Iterate over all counters */
738 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
739 for (counter = na_iterator_next (&counter_iter);
741 counter = na_iterator_next (&counter_iter))
746 name = na_child_get_string(counter, "name");
750 value = na_child_get_uint64(counter, "value", UINT64_MAX);
751 if (value == UINT64_MAX)
754 if (!strcmp(name, "name_cache_hit")) {
755 perf_data.name_cache_hit = value;
756 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
757 } else if (!strcmp(name, "name_cache_miss")) {
758 perf_data.name_cache_miss = value;
759 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
760 } else if (!strcmp(name, "find_dir_hit")) {
761 perf_data.find_dir_hit = value;
762 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
763 } else if (!strcmp(name, "find_dir_miss")) {
764 perf_data.find_dir_miss = value;
765 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
766 } else if (!strcmp(name, "buf_hash_hit")) {
767 perf_data.buf_hash_hit = value;
768 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
769 } else if (!strcmp(name, "buf_hash_miss")) {
770 perf_data.buf_hash_miss = value;
771 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
772 } else if (!strcmp(name, "inode_cache_hit")) {
773 perf_data.inode_cache_hit = value;
774 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
775 } else if (!strcmp(name, "inode_cache_miss")) {
776 perf_data.inode_cache_miss = value;
777 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
779 DEBUG("netapp plugin: cna_handle_wafl_data: "
780 "Found unexpected child: %s", name);
784 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data));
785 } /* }}} void cna_handle_wafl_data */
787 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
794 if (cw->query != NULL)
797 cw->query = na_elem_new("perf-object-get-instances");
798 if (cw->query == NULL)
800 ERROR ("netapp plugin: na_elem_new failed.");
803 na_child_add_string (cw->query, "objectname", "wafl");
805 e = na_elem_new("counters");
808 na_elem_free (cw->query);
810 ERROR ("netapp plugin: na_elem_new failed.");
813 na_child_add_string(e, "foo", "name_cache_hit");
814 na_child_add_string(e, "foo", "name_cache_miss");
815 na_child_add_string(e, "foo", "find_dir_hit");
816 na_child_add_string(e, "foo", "find_dir_miss");
817 na_child_add_string(e, "foo", "buf_hash_hit");
818 na_child_add_string(e, "foo", "buf_hash_miss");
819 na_child_add_string(e, "foo", "inode_cache_hit");
820 na_child_add_string(e, "foo", "inode_cache_miss");
822 na_child_add(cw->query, e);
825 } /* }}} int cna_setup_wafl */
827 static int cna_query_wafl (host_config_t *host) /* {{{ */
836 /* If WAFL was not configured, return without doing anything. */
837 if (host->cfg_wafl == NULL)
841 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
844 status = cna_setup_wafl (host->cfg_wafl);
847 assert (host->cfg_wafl->query != NULL);
849 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
850 if (na_results_status (data) != NA_OK)
852 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed: %s",
853 na_results_reason (data));
858 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data);
861 host->cfg_wafl->interval.last_read = now;
865 } /* }}} int cna_query_wafl */
867 /* Data corresponding to <Disks /> */
868 static int cna_handle_disk_data (const char *hostname, /* {{{ */
869 cfg_disk_t *cfg_disk, na_elem_t *data)
872 na_elem_t *instances;
874 na_elem_iter_t instance_iter;
875 disk_t *worst_disk = NULL;
877 if ((cfg_disk == NULL) || (data == NULL))
880 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
882 instances = na_elem_child (data, "instances");
883 if (instances == NULL)
885 ERROR ("netapp plugin: cna_handle_disk_data: "
886 "na_elem_child (\"instances\") failed.");
890 /* Iterate over all children */
891 instance_iter = na_child_iterator (instances);
892 for (instance = na_iterator_next (&instance_iter);
894 instance = na_iterator_next(&instance_iter))
899 na_elem_iter_t counter_iterator;
902 memset (&new_data, 0, sizeof (new_data));
903 new_data.timestamp = timestamp;
904 new_data.disk_busy_percent = NAN;
906 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
907 if (old_data == NULL)
910 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
911 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
912 for (counter = na_iterator_next(&counter_iterator);
914 counter = na_iterator_next(&counter_iterator))
919 name = na_child_get_string(counter, "name");
923 value = na_child_get_uint64(counter, "value", UINT64_MAX);
924 if (value == UINT64_MAX)
927 if (strcmp(name, "disk_busy") == 0)
929 new_data.disk_busy = value;
930 new_data.flags |= HAVE_DISK_BUSY;
932 else if (strcmp(name, "base_for_disk_busy") == 0)
934 new_data.base_for_disk_busy = value;
935 new_data.flags |= HAVE_DISK_BASE;
939 DEBUG ("netapp plugin: cna_handle_disk_data: "
940 "Counter not handled: %s = %"PRIu64,
945 /* If all required counters are available and did not just wrap around,
946 * calculate the busy percentage. Otherwise, the value is initialized to
947 * NAN at the top of the for-loop. */
948 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
949 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
950 && (new_data.disk_busy >= old_data->disk_busy)
951 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
956 busy_diff = new_data.disk_busy - old_data->disk_busy;
957 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
959 new_data.disk_busy_percent = 100.0
960 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
963 /* Clear HAVE_* flags */
964 old_data->flags &= ~HAVE_DISK_ALL;
967 old_data->timestamp = new_data.timestamp;
968 old_data->disk_busy = new_data.disk_busy;
969 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
970 old_data->disk_busy_percent = new_data.disk_busy_percent;
973 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
975 if ((worst_disk == NULL)
976 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
977 worst_disk = old_data;
978 } /* for (all disks) */
980 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
981 submit_double (hostname, "system", "percent", "disk_busy",
982 worst_disk->disk_busy_percent, timestamp);
985 } /* }}} int cna_handle_disk_data */
987 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
994 if (cd->query != NULL)
997 cd->query = na_elem_new ("perf-object-get-instances");
998 if (cd->query == NULL)
1000 ERROR ("netapp plugin: na_elem_new failed.");
1003 na_child_add_string (cd->query, "objectname", "disk");
1005 e = na_elem_new("counters");
1008 na_elem_free (cd->query);
1010 ERROR ("netapp plugin: na_elem_new failed.");
1013 na_child_add_string(e, "foo", "disk_busy");
1014 na_child_add_string(e, "foo", "base_for_disk_busy");
1015 na_child_add(cd->query, e);
1018 } /* }}} int cna_setup_disk */
1020 static int cna_query_disk (host_config_t *host) /* {{{ */
1029 /* If the user did not configure disk statistics, return without doing
1031 if (host->cfg_disk == NULL)
1035 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1038 status = cna_setup_disk (host->cfg_disk);
1041 assert (host->cfg_disk->query != NULL);
1043 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1044 if (na_results_status (data) != NA_OK)
1046 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed: %s",
1047 na_results_reason (data));
1048 na_elem_free (data);
1052 status = cna_handle_disk_data (host->name, host->cfg_disk, data);
1055 host->cfg_disk->interval.last_read = now;
1057 na_elem_free (data);
1059 } /* }}} int cna_query_disk */
1061 /* Data corresponding to <GetVolumeData /> */
1062 static void collect_volume_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
1065 cfg_volume_usage_t *cfg_volume_data = data;
1067 out = na_elem_child(out, "volumes");
1068 na_elem_iter_t inst_iter = na_child_iterator(out);
1069 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
1070 uint64_t size_free = 0, size_used = 0, snap_reserved = 0;
1073 const char *sis_state;
1074 uint64_t sis_saved_reported;
1077 volume = get_volume(host, na_child_get_string(inst, "name"),
1078 cfg_volume_data->flags, /* perf_flags = */ 0);
1082 if (!(volume->cfg_volume_usage.flags & CFG_VOLUME_USAGE_DF))
1085 /* 2^4 exa-bytes? This will take a while ;) */
1086 size_free = na_child_get_uint64(inst, "size-available", UINT64_MAX);
1087 if (size_free != UINT64_MAX)
1088 submit_double (host->name, volume->name, "df_complex", "free",
1089 (double) size_free, /* time = */ 0);
1091 size_used = na_child_get_uint64(inst, "size-used", UINT64_MAX);
1092 if (size_used != UINT64_MAX) {
1093 if ((volume->cfg_volume_usage.flags & HAVE_VOLUME_USAGE_SNAP)
1094 && (size_used >= volume->cfg_volume_usage.snap_used))
1095 size_used -= volume->cfg_volume_usage.snap_used;
1096 submit_double (host->name, volume->name, "df_complex", "used",
1097 (double) size_used, /* time = */ 0);
1100 snap_reserved = na_child_get_uint64(inst, "snapshot-blocks-reserved", UINT64_MAX);
1101 if (!(volume->cfg_volume_usage.flags & HAVE_VOLUME_USAGE_SNAP) && (snap_reserved != UINT64_MAX))
1102 /* If we have snap usage data this value has already been submitted. */
1103 /* 1 block == 1024 bytes as per API docs */
1104 submit_double (host->name, volume->name, "df_complex", "snap_reserved",
1105 (double) (1024 * snap_reserved), /* time = */ 0);
1107 sis = na_elem_child(inst, "sis");
1111 sis_state = na_child_get_string(sis, "state");
1112 if ((sis_state == NULL)
1113 || (strcmp ("enabled", sis_state) != 0))
1116 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1117 if (sis_saved_reported == UINT64_MAX)
1120 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1121 if ((sis_saved_reported >> 32) != 0) {
1122 /* In case they ever fix this bug. */
1123 sis_saved = sis_saved_reported;
1125 uint64_t sis_saved_percent;
1126 uint64_t sis_saved_guess;
1127 uint64_t overflow_guess;
1128 uint64_t guess1, guess2, guess3;
1130 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1131 if (sis_saved_percent > 100)
1134 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1135 * will hopefully be fixed in later versions. To work around the bug, try
1136 * to figure out how often the 32bit integer wrapped around by using the
1137 * "percentage-saved" value. Because the percentage is in the range
1138 * [0-100], this should work as long as the saved space does not exceed
1140 /* percentage-saved = size-saved / (size-saved + size-used) */
1141 if (sis_saved_percent < 100)
1142 sis_saved_guess = size_used * sis_saved_percent / (100 - sis_saved_percent);
1144 sis_saved_guess = size_used;
1146 overflow_guess = sis_saved_guess >> 32;
1147 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1148 guess2 = (overflow_guess << 32) + sis_saved_reported;
1149 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1151 if (sis_saved_guess < guess2) {
1152 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1157 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1162 } /* end of 32-bit workaround */
1164 submit_double (host->name, volume->name, "df_complex", "sis_saved",
1165 (double) sis_saved, /* time = */ 0);
1167 } /* }}} void collect_volume_data */
1169 /* Data corresponding to <GetVolumePerfData /> */
1170 static void query_volume_perf_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
1171 cfg_volume_perf_t *cfg_volume_perf = data;
1173 na_elem_t *counter, *inst;
1175 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
1177 out = na_elem_child(out, "instances");
1178 na_elem_iter_t inst_iter = na_child_iterator(out);
1179 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
1180 data_volume_perf_t perf_data;
1183 memset (&perf_data, 0, sizeof (perf_data));
1184 perf_data.timestamp = timestamp;
1186 volume = get_volume(host, na_child_get_string(inst, "name"),
1187 /* data_flags = */ 0, cfg_volume_perf->flags);
1191 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
1192 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
1196 name = na_child_get_string(counter, "name");
1200 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1201 if (value == UINT64_MAX)
1204 if (!strcmp(name, "read_data")) {
1205 perf_data.read_bytes = value;
1206 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1207 } else if (!strcmp(name, "write_data")) {
1208 perf_data.write_bytes = value;
1209 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1210 } else if (!strcmp(name, "read_ops")) {
1211 perf_data.read_ops = value;
1212 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1213 } else if (!strcmp(name, "write_ops")) {
1214 perf_data.write_ops = value;
1215 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1216 } else if (!strcmp(name, "read_latency")) {
1217 perf_data.read_latency = value;
1218 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1219 } else if (!strcmp(name, "write_latency")) {
1220 perf_data.write_latency = value;
1221 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1225 submit_volume_perf_data (host, volume, &perf_data);
1226 } /* for (volume) */
1227 } /* }}} void query_volume_perf_data */
1229 /* Data corresponding to <System /> */
1230 static int cna_handle_system_data (const char *hostname, /* {{{ */
1231 cfg_system_t *cfg_system, na_elem_t *data)
1233 na_elem_t *instances;
1235 na_elem_iter_t counter_iter;
1237 counter_t disk_read = 0, disk_written = 0;
1238 counter_t net_recv = 0, net_sent = 0;
1239 counter_t cpu_busy = 0, cpu_total = 0;
1240 uint32_t counter_flags = 0;
1242 const char *instance;
1245 timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
1247 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1248 if (instances == NULL)
1250 ERROR ("netapp plugin: cna_handle_system_data: "
1251 "na_elem_child (\"instances\") failed.");
1255 instance = na_child_get_string (instances, "name");
1256 if (instance == NULL)
1258 ERROR ("netapp plugin: cna_handle_system_data: "
1259 "na_child_get_string (\"name\") failed.");
1263 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
1264 for (counter = na_iterator_next (&counter_iter);
1266 counter = na_iterator_next (&counter_iter))
1271 name = na_child_get_string(counter, "name");
1275 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1276 if (value == UINT64_MAX)
1279 if (!strcmp(name, "disk_data_read")) {
1280 disk_read = (counter_t) (value * 1024);
1281 counter_flags |= 0x01;
1282 } else if (!strcmp(name, "disk_data_written")) {
1283 disk_written = (counter_t) (value * 1024);
1284 counter_flags |= 0x02;
1285 } else if (!strcmp(name, "net_data_recv")) {
1286 net_recv = (counter_t) (value * 1024);
1287 counter_flags |= 0x04;
1288 } else if (!strcmp(name, "net_data_sent")) {
1289 net_sent = (counter_t) (value * 1024);
1290 counter_flags |= 0x08;
1291 } else if (!strcmp(name, "cpu_busy")) {
1292 cpu_busy = (counter_t) value;
1293 counter_flags |= 0x10;
1294 } else if (!strcmp(name, "cpu_elapsed_time")) {
1295 cpu_total = (counter_t) value;
1296 counter_flags |= 0x20;
1297 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1298 && (value > 0) && (strlen(name) > 4)
1299 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1300 submit_counter (hostname, instance, "disk_ops_complex", name,
1301 (counter_t) value, timestamp);
1303 } /* for (counter) */
1305 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1306 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
1307 submit_two_counters (hostname, instance, "disk_octets", NULL,
1308 disk_read, disk_written, timestamp);
1310 if ((cfg_system->flags & CFG_SYSTEM_NET)
1311 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
1312 submit_two_counters (hostname, instance, "if_octets", NULL,
1313 net_recv, net_sent, timestamp);
1315 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1316 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
1318 submit_counter (hostname, instance, "cpu", "system",
1319 cpu_busy, timestamp);
1320 submit_counter (hostname, instance, "cpu", "idle",
1321 cpu_total - cpu_busy, timestamp);
1325 } /* }}} int cna_handle_system_data */
1327 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
1332 if (cs->query != NULL)
1335 cs->query = na_elem_new ("perf-object-get-instances");
1336 if (cs->query == NULL)
1338 ERROR ("netapp plugin: na_elem_new failed.");
1341 na_child_add_string (cs->query, "objectname", "system");
1344 } /* }}} int cna_setup_system */
1346 static int cna_query_system (host_config_t *host) /* {{{ */
1355 /* If system statistics were not configured, return without doing anything. */
1356 if (host->cfg_system == NULL)
1360 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
1363 status = cna_setup_system (host->cfg_system);
1366 assert (host->cfg_system->query != NULL);
1368 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
1369 if (na_results_status (data) != NA_OK)
1371 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed: %s",
1372 na_results_reason (data));
1373 na_elem_free (data);
1377 status = cna_handle_system_data (host->name, host->cfg_system, data);
1380 host->cfg_system->interval.last_read = now;
1382 na_elem_free (data);
1384 } /* }}} int cna_query_system */
1387 * Configuration handling
1389 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1390 * is false. On error, the flag-field is not changed. */
1391 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1392 uint32_t *flags, uint32_t flag)
1394 if ((ci == NULL) || (flags == NULL))
1397 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1399 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1404 if (ci->values[0].value.boolean)
1410 } /* }}} int cna_config_bool_to_flag */
1412 /* Handling of the "Multiplier" option which is allowed in every block. */
1413 static int cna_config_get_multiplier (const oconfig_item_t *ci, /* {{{ */
1414 cfg_service_t *service)
1418 if ((ci == NULL) || (service == NULL))
1421 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1423 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1427 tmp = (int) (ci->values[0].value.number + .5);
1430 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1434 service->multiplier = tmp;
1435 service->skip_countdown = tmp;
1438 } /* }}} int cna_config_get_multiplier */
1440 /* Handling of the "Interval" option which is allowed in every block. */
1441 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1442 cna_interval_t *out_interval)
1446 if ((ci == NULL) || (out_interval == NULL))
1449 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1451 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1455 tmp = (time_t) (ci->values[0].value.number + .5);
1458 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1462 out_interval->interval = tmp;
1463 out_interval->last_read = 0;
1466 } /* }}} int cna_config_get_interval */
1468 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1469 * <GetVolumePerfData /> block. */
1470 static void cna_config_volume_performance_option (host_config_t *host, /* {{{ */
1471 cfg_volume_perf_t *perf_volume, const oconfig_item_t *item,
1476 for (i = 0; i < item->values_num; ++i) {
1481 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1482 WARNING("netapp plugin: Ignoring non-string argument in "
1483 "\"GetVolumePerfData\" block for host %s", host->name);
1487 name = item->values[i].value.string;
1488 if (name[0] == '+') {
1491 } else if (name[0] == '-') {
1498 perf_volume->flags |= flag;
1499 else /* if (!set) */
1500 perf_volume->flags &= ~flag;
1502 host_set_all_perf_data_flags(host, flag, set);
1506 v = get_volume (host, name, /* data_flags = */ 0, perf_volume->flags);
1511 v->perf_data.flags |= flag;
1512 else /* if (!set) */
1513 v->perf_data.flags &= ~flag;
1514 } /* for (i = 0 .. item->values_num) */
1515 } /* }}} void cna_config_volume_performance_option */
1517 /* Corresponds to a <GetVolumePerfData /> block */
1518 static void cna_config_volume_performance(host_config_t *host, const oconfig_item_t *ci) { /* {{{ */
1519 int i, had_io = 0, had_ops = 0, had_latency = 0;
1520 cfg_service_t *service;
1521 cfg_volume_perf_t *perf_volume;
1523 service = malloc(sizeof(*service));
1525 service->handler = query_volume_perf_data;
1526 perf_volume = service->data = malloc(sizeof(*perf_volume));
1527 perf_volume->flags = CFG_VOLUME_PERF_INIT;
1528 service->next = host->services;
1529 host->services = service;
1530 for (i = 0; i < ci->children_num; ++i) {
1531 oconfig_item_t *item = ci->children + i;
1533 /* if (!item || !item->key || !*item->key) continue; */
1534 if (!strcasecmp(item->key, "Multiplier")) {
1535 cna_config_get_multiplier (item, service);
1536 } else if (!strcasecmp(item->key, "GetIO")) {
1538 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_IO);
1539 } else if (!strcasecmp(item->key, "GetOps")) {
1541 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_OPS);
1542 } else if (!strcasecmp(item->key, "GetLatency")) {
1544 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_LATENCY);
1548 perf_volume->flags |= CFG_VOLUME_PERF_IO;
1549 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_IO, /* set = */ true);
1552 perf_volume->flags |= CFG_VOLUME_PERF_OPS;
1553 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_OPS, /* set = */ true);
1556 perf_volume->flags |= CFG_VOLUME_PERF_LATENCY;
1557 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_LATENCY, /* set = */ true);
1559 } /* }}} void cna_config_volume_performance */
1561 /* Handling of the "GetDiskUtil" option within a <GetVolumeData /> block. */
1562 static void cna_config_volume_usage_option (host_config_t *host, /* {{{ */
1563 cfg_volume_usage_t *cfg_volume_data, const oconfig_item_t *item, uint32_t flag)
1567 for (i = 0; i < item->values_num; ++i) {
1572 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1573 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolData\""
1574 "block for host %s", host->name);
1578 name = item->values[i].value.string;
1579 if (name[0] == '+') {
1582 } else if (name[0] == '-') {
1589 cfg_volume_data->flags |= flag;
1590 else /* if (!set) */
1591 cfg_volume_data->flags &= ~flag;
1593 host_set_all_cfg_volume_usage_flags(host, flag, set);
1597 v = get_volume(host, name, cfg_volume_data->flags, /* perf_flags = */ 0);
1601 if (!v->cfg_volume_usage.flags)
1602 v->cfg_volume_usage.flags = cfg_volume_data->flags;
1605 v->cfg_volume_usage.flags |= flag;
1606 else /* if (!set) */
1607 v->cfg_volume_usage.flags &= ~flag;
1609 } /* }}} void cna_config_volume_usage_option */
1611 /* Corresponds to a <GetVolumeData /> block */
1612 static void cna_config_volume_usage(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1614 cfg_service_t *service;
1615 cfg_volume_usage_t *cfg_volume_data;
1617 service = malloc(sizeof(*service));
1619 service->handler = collect_volume_data;
1620 cfg_volume_data = service->data = malloc(sizeof(*cfg_volume_data));
1621 cfg_volume_data->flags = CFG_VOLUME_USAGE_INIT;
1622 service->next = host->services;
1623 host->services = service;
1624 for (i = 0; i < ci->children_num; ++i) {
1625 oconfig_item_t *item = ci->children + i;
1627 /* if (!item || !item->key || !*item->key) continue; */
1628 if (!strcasecmp(item->key, "Multiplier")) {
1629 cna_config_get_multiplier (item, service);
1630 } else if (!strcasecmp(item->key, "GetDiskUtil")) {
1632 cna_config_volume_usage_option(host, cfg_volume_data, item, CFG_VOLUME_USAGE_DF);
1633 } else if (!strcasecmp(item->key, "GetSnapUtil")) {
1635 cna_config_volume_usage_option(host, cfg_volume_data, item, CFG_VOLUME_USAGE_SNAP);
1639 cfg_volume_data->flags |= CFG_VOLUME_USAGE_DF;
1640 host_set_all_cfg_volume_usage_flags(host, CFG_VOLUME_USAGE_DF, /* set = */ true);
1642 if (cfg_volume_data->flags & CFG_VOLUME_USAGE_SNAP) {
1643 WARNING("netapp plugin: The \"GetSnapUtil\" option does not support the \"+\" wildcard.");
1645 } /* }}} void cna_config_volume_usage */
1647 /* Corresponds to a <Disks /> block */
1648 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1649 cfg_disk_t *cfg_disk;
1652 if ((host == NULL) || (ci == NULL))
1655 if (host->cfg_disk == NULL)
1657 cfg_disk = malloc (sizeof (*cfg_disk));
1658 if (cfg_disk == NULL)
1660 memset (cfg_disk, 0, sizeof (*cfg_disk));
1662 /* Set default flags */
1663 cfg_disk->flags = CFG_DISK_ALL;
1664 cfg_disk->query = NULL;
1665 cfg_disk->disks = NULL;
1667 host->cfg_disk = cfg_disk;
1669 cfg_disk = host->cfg_disk;
1671 for (i = 0; i < ci->children_num; ++i) {
1672 oconfig_item_t *item = ci->children + i;
1674 /* if (!item || !item->key || !*item->key) continue; */
1675 if (strcasecmp(item->key, "Interval") == 0)
1676 cna_config_get_interval (item, &cfg_disk->interval);
1677 else if (strcasecmp(item->key, "GetBusy") == 0)
1678 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
1681 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
1683 NOTICE ("netapp plugin: All disk related values have been disabled. "
1684 "Collection of per-disk data will be disabled entirely.");
1685 free_cfg_disk (host->cfg_disk);
1686 host->cfg_disk = NULL;
1690 } /* }}} int cna_config_disk */
1692 /* Corresponds to a <WAFL /> block */
1693 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
1695 cfg_wafl_t *cfg_wafl;
1698 if ((host == NULL) || (ci == NULL))
1701 if (host->cfg_wafl == NULL)
1703 cfg_wafl = malloc (sizeof (*cfg_wafl));
1704 if (cfg_wafl == NULL)
1706 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
1708 /* Set default flags */
1709 cfg_wafl->flags = CFG_WAFL_ALL;
1711 host->cfg_wafl = cfg_wafl;
1713 cfg_wafl = host->cfg_wafl;
1715 for (i = 0; i < ci->children_num; ++i) {
1716 oconfig_item_t *item = ci->children + i;
1718 if (strcasecmp(item->key, "Interval") == 0)
1719 cna_config_get_interval (item, &cfg_wafl->interval);
1720 else if (!strcasecmp(item->key, "GetNameCache"))
1721 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
1722 else if (!strcasecmp(item->key, "GetDirCache"))
1723 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
1724 else if (!strcasecmp(item->key, "GetBufferCache"))
1725 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
1726 else if (!strcasecmp(item->key, "GetInodeCache"))
1727 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
1729 WARNING ("netapp plugin: The %s config option is not allowed within "
1730 "`WAFL' blocks.", item->key);
1733 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
1735 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
1736 "Collection of WAFL data will be disabled entirely.");
1737 free_cfg_wafl (host->cfg_wafl);
1738 host->cfg_wafl = NULL;
1742 } /* }}} int cna_config_wafl */
1744 /* Corresponds to a <System /> block */
1745 static int cna_config_system (host_config_t *host, /* {{{ */
1746 oconfig_item_t *ci, const cfg_service_t *default_service)
1748 cfg_system_t *cfg_system;
1751 if ((host == NULL) || (ci == NULL))
1754 if (host->cfg_system == NULL)
1756 cfg_system = malloc (sizeof (*cfg_system));
1757 if (cfg_system == NULL)
1759 memset (cfg_system, 0, sizeof (*cfg_system));
1761 /* Set default flags */
1762 cfg_system->flags = CFG_SYSTEM_ALL;
1763 cfg_system->query = NULL;
1765 host->cfg_system = cfg_system;
1767 cfg_system = host->cfg_system;
1769 for (i = 0; i < ci->children_num; ++i) {
1770 oconfig_item_t *item = ci->children + i;
1772 if (strcasecmp(item->key, "Interval") == 0) {
1773 cna_config_get_interval (item, &cfg_system->interval);
1774 } else if (!strcasecmp(item->key, "GetCPULoad")) {
1775 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
1776 } else if (!strcasecmp(item->key, "GetInterfaces")) {
1777 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
1778 } else if (!strcasecmp(item->key, "GetDiskOps")) {
1779 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
1780 } else if (!strcasecmp(item->key, "GetDiskIO")) {
1781 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
1783 WARNING ("netapp plugin: The %s config option is not allowed within "
1784 "`System' blocks.", item->key);
1788 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
1790 NOTICE ("netapp plugin: All system related values have been disabled. "
1791 "Collection of system data will be disabled entirely.");
1792 free_cfg_system (host->cfg_system);
1793 host->cfg_system = NULL;
1797 } /* }}} int cna_config_system */
1799 /* Corresponds to a <Host /> block. */
1800 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
1801 const host_config_t *default_host, const cfg_service_t *def_def_service)
1803 oconfig_item_t *item;
1804 host_config_t *host;
1805 cfg_service_t default_service = *def_def_service;
1809 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1810 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
1814 host = malloc(sizeof(*host));
1815 memcpy (host, default_host, sizeof (*host));
1817 status = cf_util_get_string (ci, &host->name);
1824 for (i = 0; i < ci->children_num; ++i) {
1825 item = ci->children + i;
1829 if (!strcasecmp(item->key, "Address")) {
1830 status = cf_util_get_string (item, &host->host);
1831 } else if (!strcasecmp(item->key, "Port")) {
1834 tmp = cf_util_get_port_number (item);
1837 } else if (!strcasecmp(item->key, "Protocol")) {
1838 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"))) {
1839 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
1842 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
1843 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
1844 } else if (!strcasecmp(item->key, "User")) {
1845 status = cf_util_get_string (item, &host->username);
1846 } else if (!strcasecmp(item->key, "Password")) {
1847 status = cf_util_get_string (item, &host->password);
1848 } else if (!strcasecmp(item->key, "Interval")) {
1849 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) {
1850 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
1853 host->interval = item->values[0].value.number;
1854 } else if (!strcasecmp(item->key, "GetVolumePerfData")) {
1855 cna_config_volume_performance(host, item);
1856 } else if (!strcasecmp(item->key, "System")) {
1857 cna_config_system(host, item, &default_service);
1858 } else if (!strcasecmp(item->key, "WAFL")) {
1859 cna_config_wafl(host, item);
1860 } else if (!strcasecmp(item->key, "Disks")) {
1861 cna_config_disk(host, item);
1862 } else if (!strcasecmp(item->key, "GetVolumeData")) {
1863 cna_config_volume_usage(host, item);
1865 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
1866 item->key, ci->values[0].value.string);
1873 if (host->host == NULL)
1874 host->host = strdup (host->name);
1876 if (host->host == NULL)
1879 if (host->port <= 0)
1880 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
1882 if ((host->username == NULL) || (host->password == NULL)) {
1883 WARNING("netapp plugin: Please supply login information for host \"%s\". "
1884 "Ignoring host block.", host->name);
1890 free_host_config (host);
1895 } /* }}} host_config_t *cna_config_host */
1898 * Callbacks registered with the daemon
1900 * Pretty standard stuff here.
1902 static int cna_init(void) { /* {{{ */
1905 host_config_t *host;
1906 cfg_service_t *service;
1908 if (!global_host_config) {
1909 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
1913 memset (err, 0, sizeof (err));
1914 if (!na_startup(err, sizeof(err))) {
1915 err[sizeof (err) - 1] = 0;
1916 ERROR("netapp plugin: Error initializing netapp API: %s", err);
1920 for (host = global_host_config; host; host = host->next) {
1921 /* Request version 1.1 of the ONTAP API */
1922 host->srv = na_server_open(host->host,
1923 /* major version = */ 1, /* minor version = */ 1);
1924 if (host->srv == NULL) {
1925 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
1929 if (host->interval < interval_g)
1930 host->interval = interval_g;
1932 na_server_set_transport_type(host->srv, host->protocol,
1933 /* transportarg = */ NULL);
1934 na_server_set_port(host->srv, host->port);
1935 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
1936 na_server_adminuser(host->srv, host->username, host->password);
1937 na_server_set_timeout(host->srv, 5 /* seconds */);
1939 for (service = host->services; service; service = service->next) {
1940 service->interval = host->interval * service->multiplier;
1942 if (service->handler == query_volume_perf_data) {
1943 service->query = na_elem_new("perf-object-get-instances");
1944 na_child_add_string(service->query, "objectname", "volume");
1945 e = na_elem_new("counters");
1946 /* "foo" means: This string has to be here but
1947 the content doesn't matter. */
1948 na_child_add_string(e, "foo", "read_ops");
1949 na_child_add_string(e, "foo", "write_ops");
1950 na_child_add_string(e, "foo", "read_data");
1951 na_child_add_string(e, "foo", "write_data");
1952 na_child_add_string(e, "foo", "read_latency");
1953 na_child_add_string(e, "foo", "write_latency");
1954 na_child_add(service->query, e);
1955 } else if (service->handler == collect_volume_data) {
1956 service->query = na_elem_new("volume-list-info");
1957 /* na_child_add_string(service->query, "objectname", "volume"); */
1958 /* } else if (service->handler == collect_snapshot_data) { */
1959 /* service->query = na_elem_new("snapshot-list-info"); */
1961 } /* for (host->services) */
1964 } /* }}} int cna_init */
1966 static int cna_config (oconfig_item_t *ci) { /* {{{ */
1968 oconfig_item_t *item;
1969 host_config_t default_host = HOST_INIT;
1970 cfg_service_t default_service = SERVICE_INIT;
1972 for (i = 0; i < ci->children_num; ++i) {
1973 item = ci->children + i;
1975 if (!strcasecmp(item->key, "Host")) {
1976 host_config_t *host;
1979 host = cna_config_host(item, &default_host, &default_service);
1983 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
1985 if (strcasecmp (host->name, tmp->name) == 0)
1986 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
1987 "This is probably a bad idea.",
1990 if (tmp->next == NULL)
1996 global_host_config = host;
2000 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
2004 } /* }}} int cna_config */
2006 static int cna_read(void) { /* {{{ */
2008 host_config_t *host;
2009 cfg_service_t *service;
2011 for (host = global_host_config; host; host = host->next) {
2012 for (service = host->services; service; service = service->next) {
2013 if (--service->skip_countdown > 0) continue;
2014 service->skip_countdown = service->multiplier;
2015 out = na_server_invoke_elem(host->srv, service->query);
2016 if (na_results_status(out) != NA_OK) {
2017 int netapp_errno = na_results_errno(out);
2018 ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
2020 if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
2021 /* Network problems. Just give up on all other services on this host. */
2026 service->handler(host, out, service->data);
2028 } /* for (host->services) */
2030 cna_query_wafl (host);
2031 cna_query_disk (host);
2032 cna_query_system (host);
2035 } /* }}} int cna_read */
2037 void module_register(void) {
2038 plugin_register_complex_config("netapp", cna_config);
2039 plugin_register_init("netapp", cna_init);
2040 plugin_register_read("netapp", cna_read);
2043 /* vim: set sw=2 ts=2 noet fdm=marker : */