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_disk (cfg_disk_t *cfg_disk) /* {{{ */
268 if (cfg_disk == NULL)
271 free_disk (cfg_disk->disks);
273 } /* }}} void free_cfg_disk */
275 static void free_cfg_service (cfg_service_t *service) /* {{{ */
282 next = service->next;
284 /* FIXME: Free service->data? */
285 na_elem_free(service->query);
289 free_cfg_service (next);
290 } /* }}} void free_cfg_service */
292 static void free_host_config (host_config_t *hc) /* {{{ */
303 sfree (hc->username);
304 sfree (hc->password);
306 free_cfg_service (hc->services);
307 free_cfg_disk (hc->cfg_disk);
308 free_volume (hc->volumes);
312 free_host_config (next);
313 } /* }}} void free_host_config */
316 * Auxiliary functions
318 * Used to look up volumes and disks or to handle flags.
320 static volume_t *get_volume (host_config_t *host, const char *name, /* {{{ */
321 uint32_t vol_usage_flags, uint32_t vol_perf_flags)
328 /* Make sure the default flags include the init-bit. */
329 if (vol_usage_flags != 0)
330 vol_usage_flags |= CFG_VOLUME_USAGE_INIT;
331 if (vol_perf_flags != 0)
332 vol_perf_flags |= CFG_VOLUME_PERF_INIT;
334 for (v = host->volumes; v; v = v->next) {
335 if (strcmp(v->name, name) != 0)
338 /* Check if the flags have been initialized. */
339 if (((v->cfg_volume_usage.flags & CFG_VOLUME_USAGE_INIT) == 0)
340 && (vol_usage_flags != 0))
341 v->cfg_volume_usage.flags = vol_usage_flags;
342 if (((v->perf_data.flags & CFG_VOLUME_PERF_INIT) == 0)
343 && (vol_perf_flags != 0))
344 v->perf_data.flags = vol_perf_flags;
349 DEBUG ("netapp plugin: Allocating new entry for volume %s.", name);
350 v = malloc(sizeof(*v));
353 memset (v, 0, sizeof (*v));
355 v->cfg_volume_usage.flags = vol_usage_flags;
356 v->perf_data.flags = vol_perf_flags;
358 v->name = strdup(name);
359 if (v->name == NULL) {
364 v->next = host->volumes;
368 } /* }}} volume_t *get_volume */
370 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
374 if ((cd == NULL) || (name == NULL))
377 for (d = cd->disks; d != NULL; d = d->next) {
378 if (strcmp(d->name, name) == 0)
382 d = malloc(sizeof(*d));
385 memset (d, 0, sizeof (*d));
388 d->name = strdup(name);
389 if (d->name == NULL) {
398 } /* }}} disk_t *get_disk */
400 static void host_set_all_perf_data_flags(const host_config_t *host, /* {{{ */
401 uint32_t flag, _Bool set)
405 for (v = host->volumes; v; v = v->next) {
407 v->perf_data.flags |= flag;
409 v->perf_data.flags &= ~flag;
411 } /* }}} void host_set_all_perf_data_flags */
413 static void host_set_all_cfg_volume_usage_flags(const host_config_t *host, /* {{{ */
414 uint32_t flag, _Bool set) {
417 for (v = host->volumes; v; v = v->next) {
419 v->cfg_volume_usage.flags |= flag;
421 v->cfg_volume_usage.flags &= ~flag;
423 } /* }}} void host_set_all_cfg_volume_usage_flags */
426 * Various submit functions.
428 * They all eventually call "submit_values" which creates a value_list_t and
429 * dispatches it to the daemon.
431 static int submit_values (const char *host, /* {{{ */
432 const char *plugin_inst,
433 const char *type, const char *type_inst,
434 value_t *values, int values_len,
437 value_list_t vl = VALUE_LIST_INIT;
440 vl.values_len = values_len;
446 sstrncpy (vl.host, host, sizeof (vl.host));
448 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
449 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
450 if (plugin_inst != NULL)
451 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
452 sstrncpy (vl.type, type, sizeof (vl.type));
453 if (type_inst != NULL)
454 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
456 return (plugin_dispatch_values (&vl));
457 } /* }}} int submit_uint64 */
459 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
460 const char *type, const char *type_inst, counter_t val0, counter_t val1,
465 values[0].counter = val0;
466 values[1].counter = val1;
468 return (submit_values (host, plugin_inst, type, type_inst,
469 values, 2, timestamp));
470 } /* }}} int submit_two_counters */
472 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
473 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
479 return (submit_values (host, plugin_inst, type, type_inst,
481 } /* }}} int submit_counter */
483 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
484 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
489 values[0].gauge = val0;
490 values[1].gauge = val1;
492 return (submit_values (host, plugin_inst, type, type_inst,
493 values, 2, timestamp));
494 } /* }}} int submit_two_gauge */
496 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
497 const char *type, const char *type_inst, double d, time_t timestamp)
501 v.gauge = (gauge_t) d;
503 return (submit_values (host, plugin_inst, type, type_inst,
505 } /* }}} int submit_uint64 */
507 /* Calculate hit ratio from old and new counters and submit the resulting
508 * percentage. Used by "submit_wafl_data". */
509 static int submit_cache_ratio (const char *host, /* {{{ */
510 const char *plugin_inst,
511 const char *type_inst,
520 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
524 hits = new_hits - old_hits;
525 misses = new_misses - old_misses;
527 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
532 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
534 } /* }}} int submit_cache_ratio */
536 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
537 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
538 cfg_wafl_t *old_data, const cfg_wafl_t *new_data)
540 /* Submit requested counters */
541 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
542 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
543 submit_cache_ratio (hostname, instance, "name_cache_hit",
544 new_data->name_cache_hit, new_data->name_cache_miss,
545 old_data->name_cache_hit, old_data->name_cache_miss,
546 new_data->timestamp);
548 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
549 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
550 submit_cache_ratio (hostname, instance, "find_dir_hit",
551 new_data->find_dir_hit, new_data->find_dir_miss,
552 old_data->find_dir_hit, old_data->find_dir_miss,
553 new_data->timestamp);
555 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
556 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
557 submit_cache_ratio (hostname, instance, "buf_hash_hit",
558 new_data->buf_hash_hit, new_data->buf_hash_miss,
559 old_data->buf_hash_hit, old_data->buf_hash_miss,
560 new_data->timestamp);
562 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
563 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
564 submit_cache_ratio (hostname, instance, "inode_cache_hit",
565 new_data->inode_cache_hit, new_data->inode_cache_miss,
566 old_data->inode_cache_hit, old_data->inode_cache_miss,
567 new_data->timestamp);
569 /* Clear old HAVE_* flags */
570 old_data->flags &= ~HAVE_WAFL_ALL;
572 /* Copy all counters */
573 old_data->timestamp = new_data->timestamp;
574 old_data->name_cache_hit = new_data->name_cache_hit;
575 old_data->name_cache_miss = new_data->name_cache_miss;
576 old_data->find_dir_hit = new_data->find_dir_hit;
577 old_data->find_dir_miss = new_data->find_dir_miss;
578 old_data->buf_hash_hit = new_data->buf_hash_hit;
579 old_data->buf_hash_miss = new_data->buf_hash_miss;
580 old_data->inode_cache_hit = new_data->inode_cache_hit;
581 old_data->inode_cache_miss = new_data->inode_cache_miss;
583 /* Copy HAVE_* flags */
584 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
587 } /* }}} int submit_wafl_data */
589 /* Submits volume performance data to the daemon, taking care to honor and
590 * update flags appropriately. */
591 static int submit_volume_perf_data (const host_config_t *host, /* {{{ */
593 const data_volume_perf_t *new_data)
595 /* Check for and submit disk-octet values */
596 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_IO)
597 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
599 submit_two_counters (host->name, volume->name, "disk_octets", /* type instance = */ NULL,
600 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
603 /* Check for and submit disk-operations values */
604 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_OPS)
605 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
607 submit_two_counters (host->name, volume->name, "disk_ops", /* type instance = */ NULL,
608 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
611 /* Check for, calculate and submit disk-latency values */
612 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_LATENCY
613 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
614 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
615 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
616 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
618 gauge_t latency_per_op_read;
619 gauge_t latency_per_op_write;
621 latency_per_op_read = NAN;
622 latency_per_op_write = NAN;
624 /* Check if a counter wrapped around. */
625 if ((new_data->read_ops > volume->perf_data.read_ops)
626 && (new_data->read_latency > volume->perf_data.read_latency))
628 uint64_t diff_ops_read;
629 uint64_t diff_latency_read;
631 diff_ops_read = new_data->read_ops - volume->perf_data.read_ops;
632 diff_latency_read = new_data->read_latency - volume->perf_data.read_latency;
634 if (diff_ops_read > 0)
635 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
638 if ((new_data->write_ops > volume->perf_data.write_ops)
639 && (new_data->write_latency > volume->perf_data.write_latency))
641 uint64_t diff_ops_write;
642 uint64_t diff_latency_write;
644 diff_ops_write = new_data->write_ops - volume->perf_data.write_ops;
645 diff_latency_write = new_data->write_latency - volume->perf_data.write_latency;
647 if (diff_ops_write > 0)
648 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
651 submit_two_gauge (host->name, volume->name, "disk_latency", /* type instance = */ NULL,
652 latency_per_op_read, latency_per_op_write, new_data->timestamp);
655 /* Clear all HAVE_* flags. */
656 volume->perf_data.flags &= ~HAVE_VOLUME_PERF_ALL;
658 /* Copy all counters */
659 volume->perf_data.timestamp = new_data->timestamp;
660 volume->perf_data.read_bytes = new_data->read_bytes;
661 volume->perf_data.write_bytes = new_data->write_bytes;
662 volume->perf_data.read_ops = new_data->read_ops;
663 volume->perf_data.write_ops = new_data->write_ops;
664 volume->perf_data.read_latency = new_data->read_latency;
665 volume->perf_data.write_latency = new_data->write_latency;
667 /* Copy the HAVE_* flags */
668 volume->perf_data.flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
671 } /* }}} int submit_volume_perf_data */
676 * These functions are called with appropriate data returned by the libnetapp
677 * interface which is parsed and submitted with the above functions.
679 /* Data corresponding to <WAFL /> */
680 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
683 cfg_wafl_t perf_data;
684 const char *plugin_inst;
686 na_elem_t *instances;
688 na_elem_iter_t counter_iter;
690 memset (&perf_data, 0, sizeof (perf_data));
692 perf_data.timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
694 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
695 if (instances == NULL)
697 ERROR ("netapp plugin: cna_handle_wafl_data: "
698 "na_elem_child (\"instances\") failed.");
702 plugin_inst = na_child_get_string(instances, "name");
703 if (plugin_inst == NULL)
705 ERROR ("netapp plugin: cna_handle_wafl_data: "
706 "na_child_get_string (\"name\") failed.");
710 /* Iterate over all counters */
711 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
712 for (counter = na_iterator_next (&counter_iter);
714 counter = na_iterator_next (&counter_iter))
719 name = na_child_get_string(counter, "name");
723 value = na_child_get_uint64(counter, "value", UINT64_MAX);
724 if (value == UINT64_MAX)
727 if (!strcmp(name, "name_cache_hit")) {
728 perf_data.name_cache_hit = value;
729 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
730 } else if (!strcmp(name, "name_cache_miss")) {
731 perf_data.name_cache_miss = value;
732 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
733 } else if (!strcmp(name, "find_dir_hit")) {
734 perf_data.find_dir_hit = value;
735 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
736 } else if (!strcmp(name, "find_dir_miss")) {
737 perf_data.find_dir_miss = value;
738 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
739 } else if (!strcmp(name, "buf_hash_hit")) {
740 perf_data.buf_hash_hit = value;
741 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
742 } else if (!strcmp(name, "buf_hash_miss")) {
743 perf_data.buf_hash_miss = value;
744 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
745 } else if (!strcmp(name, "inode_cache_hit")) {
746 perf_data.inode_cache_hit = value;
747 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
748 } else if (!strcmp(name, "inode_cache_miss")) {
749 perf_data.inode_cache_miss = value;
750 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
752 DEBUG("netapp plugin: cna_handle_wafl_data: "
753 "Found unexpected child: %s", name);
757 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data));
758 } /* }}} void cna_handle_wafl_data */
760 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
767 if (cw->query != NULL)
770 cw->query = na_elem_new("perf-object-get-instances");
771 if (cw->query == NULL)
773 ERROR ("netapp plugin: na_elem_new failed.");
776 na_child_add_string (cw->query, "objectname", "wafl");
778 e = na_elem_new("counters");
781 na_elem_free (cw->query);
783 ERROR ("netapp plugin: na_elem_new failed.");
786 na_child_add_string(e, "foo", "name_cache_hit");
787 na_child_add_string(e, "foo", "name_cache_miss");
788 na_child_add_string(e, "foo", "find_dir_hit");
789 na_child_add_string(e, "foo", "find_dir_miss");
790 na_child_add_string(e, "foo", "buf_hash_hit");
791 na_child_add_string(e, "foo", "buf_hash_miss");
792 na_child_add_string(e, "foo", "inode_cache_hit");
793 na_child_add_string(e, "foo", "inode_cache_miss");
795 na_child_add(cw->query, e);
798 } /* }}} int cna_setup_wafl */
800 static int cna_query_wafl (host_config_t *host) /* {{{ */
809 if (host->cfg_wafl == NULL)
813 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
816 status = cna_setup_wafl (host->cfg_wafl);
819 assert (host->cfg_wafl->query != NULL);
821 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
822 if (na_results_status (data) != NA_OK)
824 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed: %s",
825 na_results_reason (data));
830 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data);
833 host->cfg_wafl->interval.last_read = now;
837 } /* }}} int cna_query_wafl */
839 /* Data corresponding to <Disks /> */
840 static int cna_handle_disk_data (const char *hostname, /* {{{ */
841 cfg_disk_t *cfg_disk, na_elem_t *data)
844 na_elem_t *instances;
846 na_elem_iter_t instance_iter;
847 disk_t *worst_disk = NULL;
849 if ((cfg_disk == NULL) || (data == NULL))
852 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
854 instances = na_elem_child (data, "instances");
855 if (instances == NULL)
857 ERROR ("netapp plugin: cna_handle_disk_data: "
858 "na_elem_child (\"instances\") failed.");
862 /* Iterate over all children */
863 instance_iter = na_child_iterator (instances);
864 for (instance = na_iterator_next (&instance_iter);
866 instance = na_iterator_next(&instance_iter))
871 na_elem_iter_t counter_iterator;
874 memset (&new_data, 0, sizeof (new_data));
875 new_data.timestamp = timestamp;
876 new_data.disk_busy_percent = NAN;
878 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
879 if (old_data == NULL)
882 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
883 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
884 for (counter = na_iterator_next(&counter_iterator);
886 counter = na_iterator_next(&counter_iterator))
891 name = na_child_get_string(counter, "name");
895 value = na_child_get_uint64(counter, "value", UINT64_MAX);
896 if (value == UINT64_MAX)
899 if (strcmp(name, "disk_busy") == 0)
901 new_data.disk_busy = value;
902 new_data.flags |= HAVE_DISK_BUSY;
904 else if (strcmp(name, "base_for_disk_busy") == 0)
906 new_data.base_for_disk_busy = value;
907 new_data.flags |= HAVE_DISK_BASE;
911 DEBUG ("netapp plugin: cna_handle_disk_data: "
912 "Counter not handled: %s = %"PRIu64,
917 /* If all required counters are available and did not just wrap around,
918 * calculate the busy percentage. Otherwise, the value is initialized to
919 * NAN at the top of the for-loop. */
920 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
921 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
922 && (new_data.disk_busy >= old_data->disk_busy)
923 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
928 busy_diff = new_data.disk_busy - old_data->disk_busy;
929 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
931 new_data.disk_busy_percent = 100.0
932 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
935 /* Clear HAVE_* flags */
936 old_data->flags &= ~HAVE_DISK_ALL;
939 old_data->timestamp = new_data.timestamp;
940 old_data->disk_busy = new_data.disk_busy;
941 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
942 old_data->disk_busy_percent = new_data.disk_busy_percent;
945 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
947 if ((worst_disk == NULL)
948 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
949 worst_disk = old_data;
950 } /* for (all disks) */
952 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
953 submit_double (hostname, "system", "percent", "disk_busy",
954 worst_disk->disk_busy_percent, timestamp);
957 } /* }}} int cna_handle_disk_data */
959 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
966 if (cd->query != NULL)
969 cd->query = na_elem_new ("perf-object-get-instances");
970 if (cd->query == NULL)
972 ERROR ("netapp plugin: na_elem_new failed.");
975 na_child_add_string (cd->query, "objectname", "disk");
977 e = na_elem_new("counters");
980 na_elem_free (cd->query);
982 ERROR ("netapp plugin: na_elem_new failed.");
985 na_child_add_string(e, "foo", "disk_busy");
986 na_child_add_string(e, "foo", "base_for_disk_busy");
987 na_child_add(cd->query, e);
990 } /* }}} int cna_setup_disk */
992 static int cna_query_disk (host_config_t *host) /* {{{ */
1001 if (host->cfg_disk == NULL)
1005 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1008 status = cna_setup_disk (host->cfg_disk);
1011 assert (host->cfg_disk->query != NULL);
1013 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1014 if (na_results_status (data) != NA_OK)
1016 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed: %s",
1017 na_results_reason (data));
1018 na_elem_free (data);
1022 status = cna_handle_disk_data (host->name, host->cfg_disk, data);
1025 host->cfg_disk->interval.last_read = now;
1027 na_elem_free (data);
1029 } /* }}} int cna_query_disk */
1031 /* Data corresponding to <GetVolumeData /> */
1032 static void collect_volume_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
1035 cfg_volume_usage_t *cfg_volume_data = data;
1037 out = na_elem_child(out, "volumes");
1038 na_elem_iter_t inst_iter = na_child_iterator(out);
1039 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
1040 uint64_t size_free = 0, size_used = 0, snap_reserved = 0;
1043 const char *sis_state;
1044 uint64_t sis_saved_reported;
1047 volume = get_volume(host, na_child_get_string(inst, "name"),
1048 cfg_volume_data->flags, /* perf_flags = */ 0);
1052 if (!(volume->cfg_volume_usage.flags & CFG_VOLUME_USAGE_DF))
1055 /* 2^4 exa-bytes? This will take a while ;) */
1056 size_free = na_child_get_uint64(inst, "size-available", UINT64_MAX);
1057 if (size_free != UINT64_MAX)
1058 submit_double (host->name, volume->name, "df_complex", "free",
1059 (double) size_free, /* time = */ 0);
1061 size_used = na_child_get_uint64(inst, "size-used", UINT64_MAX);
1062 if (size_used != UINT64_MAX) {
1063 if ((volume->cfg_volume_usage.flags & HAVE_VOLUME_USAGE_SNAP)
1064 && (size_used >= volume->cfg_volume_usage.snap_used))
1065 size_used -= volume->cfg_volume_usage.snap_used;
1066 submit_double (host->name, volume->name, "df_complex", "used",
1067 (double) size_used, /* time = */ 0);
1070 snap_reserved = na_child_get_uint64(inst, "snapshot-blocks-reserved", UINT64_MAX);
1071 if (!(volume->cfg_volume_usage.flags & HAVE_VOLUME_USAGE_SNAP) && (snap_reserved != UINT64_MAX))
1072 /* If we have snap usage data this value has already been submitted. */
1073 /* 1 block == 1024 bytes as per API docs */
1074 submit_double (host->name, volume->name, "df_complex", "snap_reserved",
1075 (double) (1024 * snap_reserved), /* time = */ 0);
1077 sis = na_elem_child(inst, "sis");
1081 sis_state = na_child_get_string(sis, "state");
1082 if ((sis_state == NULL)
1083 || (strcmp ("enabled", sis_state) != 0))
1086 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1087 if (sis_saved_reported == UINT64_MAX)
1090 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1091 if ((sis_saved_reported >> 32) != 0) {
1092 /* In case they ever fix this bug. */
1093 sis_saved = sis_saved_reported;
1095 uint64_t sis_saved_percent;
1096 uint64_t sis_saved_guess;
1097 uint64_t overflow_guess;
1098 uint64_t guess1, guess2, guess3;
1100 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1101 if (sis_saved_percent > 100)
1104 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1105 * will hopefully be fixed in later versions. To work around the bug, try
1106 * to figure out how often the 32bit integer wrapped around by using the
1107 * "percentage-saved" value. Because the percentage is in the range
1108 * [0-100], this should work as long as the saved space does not exceed
1110 /* percentage-saved = size-saved / (size-saved + size-used) */
1111 if (sis_saved_percent < 100)
1112 sis_saved_guess = size_used * sis_saved_percent / (100 - sis_saved_percent);
1114 sis_saved_guess = size_used;
1116 overflow_guess = sis_saved_guess >> 32;
1117 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1118 guess2 = (overflow_guess << 32) + sis_saved_reported;
1119 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1121 if (sis_saved_guess < guess2) {
1122 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1127 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1132 } /* end of 32-bit workaround */
1134 submit_double (host->name, volume->name, "df_complex", "sis_saved",
1135 (double) sis_saved, /* time = */ 0);
1137 } /* }}} void collect_volume_data */
1139 /* Data corresponding to <GetVolumePerfData /> */
1140 static void query_volume_perf_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
1141 cfg_volume_perf_t *cfg_volume_perf = data;
1143 na_elem_t *counter, *inst;
1145 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
1147 out = na_elem_child(out, "instances");
1148 na_elem_iter_t inst_iter = na_child_iterator(out);
1149 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
1150 data_volume_perf_t perf_data;
1153 memset (&perf_data, 0, sizeof (perf_data));
1154 perf_data.timestamp = timestamp;
1156 volume = get_volume(host, na_child_get_string(inst, "name"),
1157 /* data_flags = */ 0, cfg_volume_perf->flags);
1161 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
1162 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
1166 name = na_child_get_string(counter, "name");
1170 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1171 if (value == UINT64_MAX)
1174 if (!strcmp(name, "read_data")) {
1175 perf_data.read_bytes = value;
1176 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1177 } else if (!strcmp(name, "write_data")) {
1178 perf_data.write_bytes = value;
1179 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1180 } else if (!strcmp(name, "read_ops")) {
1181 perf_data.read_ops = value;
1182 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1183 } else if (!strcmp(name, "write_ops")) {
1184 perf_data.write_ops = value;
1185 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1186 } else if (!strcmp(name, "read_latency")) {
1187 perf_data.read_latency = value;
1188 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1189 } else if (!strcmp(name, "write_latency")) {
1190 perf_data.write_latency = value;
1191 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1195 submit_volume_perf_data (host, volume, &perf_data);
1196 } /* for (volume) */
1197 } /* }}} void query_volume_perf_data */
1199 /* Data corresponding to <System /> */
1200 static int cna_handle_system_data (const char *hostname, /* {{{ */
1201 cfg_system_t *cfg_system, na_elem_t *data)
1203 na_elem_t *instances;
1205 na_elem_iter_t counter_iter;
1207 counter_t disk_read = 0, disk_written = 0;
1208 counter_t net_recv = 0, net_sent = 0;
1209 counter_t cpu_busy = 0, cpu_total = 0;
1210 uint32_t counter_flags = 0;
1212 const char *instance;
1215 timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
1217 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1218 if (instances == NULL)
1220 ERROR ("netapp plugin: cna_handle_system_data: "
1221 "na_elem_child (\"instances\") failed.");
1225 instance = na_child_get_string (instances, "name");
1226 if (instance == NULL)
1228 ERROR ("netapp plugin: cna_handle_system_data: "
1229 "na_child_get_string (\"name\") failed.");
1233 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
1234 for (counter = na_iterator_next (&counter_iter);
1236 counter = na_iterator_next (&counter_iter))
1241 name = na_child_get_string(counter, "name");
1245 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1246 if (value == UINT64_MAX)
1249 if (!strcmp(name, "disk_data_read")) {
1250 disk_read = (counter_t) (value * 1024);
1251 counter_flags |= 0x01;
1252 } else if (!strcmp(name, "disk_data_written")) {
1253 disk_written = (counter_t) (value * 1024);
1254 counter_flags |= 0x02;
1255 } else if (!strcmp(name, "net_data_recv")) {
1256 net_recv = (counter_t) (value * 1024);
1257 counter_flags |= 0x04;
1258 } else if (!strcmp(name, "net_data_sent")) {
1259 net_sent = (counter_t) (value * 1024);
1260 counter_flags |= 0x08;
1261 } else if (!strcmp(name, "cpu_busy")) {
1262 cpu_busy = (counter_t) value;
1263 counter_flags |= 0x10;
1264 } else if (!strcmp(name, "cpu_elapsed_time")) {
1265 cpu_total = (counter_t) value;
1266 counter_flags |= 0x20;
1267 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1268 && (value > 0) && (strlen(name) > 4)
1269 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1270 submit_counter (hostname, instance, "disk_ops_complex", name,
1271 (counter_t) value, timestamp);
1273 } /* for (counter) */
1275 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1276 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
1277 submit_two_counters (hostname, instance, "disk_octets", NULL,
1278 disk_read, disk_written, timestamp);
1280 if ((cfg_system->flags & CFG_SYSTEM_NET)
1281 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
1282 submit_two_counters (hostname, instance, "if_octets", NULL,
1283 net_recv, net_sent, timestamp);
1285 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1286 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
1288 submit_counter (hostname, instance, "cpu", "system",
1289 cpu_busy, timestamp);
1290 submit_counter (hostname, instance, "cpu", "idle",
1291 cpu_total - cpu_busy, timestamp);
1295 } /* }}} int cna_handle_system_data */
1297 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
1302 if (cs->query != NULL)
1305 cs->query = na_elem_new ("perf-object-get-instances");
1306 if (cs->query == NULL)
1308 ERROR ("netapp plugin: na_elem_new failed.");
1311 na_child_add_string (cs->query, "objectname", "system");
1314 } /* }}} int cna_setup_system */
1316 static int cna_query_system (host_config_t *host) /* {{{ */
1325 /* If system statistics were not configured, return without doing anything. */
1326 if (host->cfg_system == NULL)
1330 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
1333 status = cna_setup_system (host->cfg_system);
1336 assert (host->cfg_system->query != NULL);
1338 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
1339 if (na_results_status (data) != NA_OK)
1341 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed: %s",
1342 na_results_reason (data));
1343 na_elem_free (data);
1347 status = cna_handle_system_data (host->name, host->cfg_system, data);
1350 host->cfg_system->interval.last_read = now;
1352 na_elem_free (data);
1354 } /* }}} int cna_query_system */
1357 * Configuration handling
1359 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1360 * is false. On error, the flag-field is not changed. */
1361 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1362 uint32_t *flags, uint32_t flag)
1364 if ((ci == NULL) || (flags == NULL))
1367 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1369 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1374 if (ci->values[0].value.boolean)
1380 } /* }}} int cna_config_bool_to_flag */
1382 /* Handling of the "Multiplier" option which is allowed in every block. */
1383 static int cna_config_get_multiplier (const oconfig_item_t *ci, /* {{{ */
1384 cfg_service_t *service)
1388 if ((ci == NULL) || (service == NULL))
1391 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1393 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1397 tmp = (int) (ci->values[0].value.number + .5);
1400 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1404 service->multiplier = tmp;
1405 service->skip_countdown = tmp;
1408 } /* }}} int cna_config_get_multiplier */
1410 /* Handling of the "Interval" option which is allowed in every block. */
1411 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1412 cna_interval_t *out_interval)
1416 if ((ci == NULL) || (out_interval == NULL))
1419 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1421 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1425 tmp = (time_t) (ci->values[0].value.number + .5);
1428 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1432 out_interval->interval = tmp;
1433 out_interval->last_read = 0;
1436 } /* }}} int cna_config_get_interval */
1438 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1439 * <GetVolumePerfData /> block. */
1440 static void cna_config_volume_performance_option (host_config_t *host, /* {{{ */
1441 cfg_volume_perf_t *perf_volume, const oconfig_item_t *item,
1446 for (i = 0; i < item->values_num; ++i) {
1451 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1452 WARNING("netapp plugin: Ignoring non-string argument in "
1453 "\"GetVolumePerfData\" block for host %s", host->name);
1457 name = item->values[i].value.string;
1458 if (name[0] == '+') {
1461 } else if (name[0] == '-') {
1468 perf_volume->flags |= flag;
1469 else /* if (!set) */
1470 perf_volume->flags &= ~flag;
1472 host_set_all_perf_data_flags(host, flag, set);
1476 v = get_volume (host, name, /* data_flags = */ 0, perf_volume->flags);
1481 v->perf_data.flags |= flag;
1482 else /* if (!set) */
1483 v->perf_data.flags &= ~flag;
1484 } /* for (i = 0 .. item->values_num) */
1485 } /* }}} void cna_config_volume_performance_option */
1487 /* Corresponds to a <GetVolumePerfData /> block */
1488 static void cna_config_volume_performance(host_config_t *host, const oconfig_item_t *ci) { /* {{{ */
1489 int i, had_io = 0, had_ops = 0, had_latency = 0;
1490 cfg_service_t *service;
1491 cfg_volume_perf_t *perf_volume;
1493 service = malloc(sizeof(*service));
1495 service->handler = query_volume_perf_data;
1496 perf_volume = service->data = malloc(sizeof(*perf_volume));
1497 perf_volume->flags = CFG_VOLUME_PERF_INIT;
1498 service->next = host->services;
1499 host->services = service;
1500 for (i = 0; i < ci->children_num; ++i) {
1501 oconfig_item_t *item = ci->children + i;
1503 /* if (!item || !item->key || !*item->key) continue; */
1504 if (!strcasecmp(item->key, "Multiplier")) {
1505 cna_config_get_multiplier (item, service);
1506 } else if (!strcasecmp(item->key, "GetIO")) {
1508 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_IO);
1509 } else if (!strcasecmp(item->key, "GetOps")) {
1511 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_OPS);
1512 } else if (!strcasecmp(item->key, "GetLatency")) {
1514 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_LATENCY);
1518 perf_volume->flags |= CFG_VOLUME_PERF_IO;
1519 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_IO, /* set = */ true);
1522 perf_volume->flags |= CFG_VOLUME_PERF_OPS;
1523 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_OPS, /* set = */ true);
1526 perf_volume->flags |= CFG_VOLUME_PERF_LATENCY;
1527 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_LATENCY, /* set = */ true);
1529 } /* }}} void cna_config_volume_performance */
1531 /* Handling of the "GetDiskUtil" option within a <GetVolumeData /> block. */
1532 static void cna_config_volume_usage_option (host_config_t *host, /* {{{ */
1533 cfg_volume_usage_t *cfg_volume_data, const oconfig_item_t *item, uint32_t flag)
1537 for (i = 0; i < item->values_num; ++i) {
1542 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1543 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolData\""
1544 "block for host %s", host->name);
1548 name = item->values[i].value.string;
1549 if (name[0] == '+') {
1552 } else if (name[0] == '-') {
1559 cfg_volume_data->flags |= flag;
1560 else /* if (!set) */
1561 cfg_volume_data->flags &= ~flag;
1563 host_set_all_cfg_volume_usage_flags(host, flag, set);
1567 v = get_volume(host, name, cfg_volume_data->flags, /* perf_flags = */ 0);
1571 if (!v->cfg_volume_usage.flags)
1572 v->cfg_volume_usage.flags = cfg_volume_data->flags;
1575 v->cfg_volume_usage.flags |= flag;
1576 else /* if (!set) */
1577 v->cfg_volume_usage.flags &= ~flag;
1579 } /* }}} void cna_config_volume_usage_option */
1581 /* Corresponds to a <GetVolumeData /> block */
1582 static void cna_config_volume_usage(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1584 cfg_service_t *service;
1585 cfg_volume_usage_t *cfg_volume_data;
1587 service = malloc(sizeof(*service));
1589 service->handler = collect_volume_data;
1590 cfg_volume_data = service->data = malloc(sizeof(*cfg_volume_data));
1591 cfg_volume_data->flags = CFG_VOLUME_USAGE_INIT;
1592 service->next = host->services;
1593 host->services = service;
1594 for (i = 0; i < ci->children_num; ++i) {
1595 oconfig_item_t *item = ci->children + i;
1597 /* if (!item || !item->key || !*item->key) continue; */
1598 if (!strcasecmp(item->key, "Multiplier")) {
1599 cna_config_get_multiplier (item, service);
1600 } else if (!strcasecmp(item->key, "GetDiskUtil")) {
1602 cna_config_volume_usage_option(host, cfg_volume_data, item, CFG_VOLUME_USAGE_DF);
1603 } else if (!strcasecmp(item->key, "GetSnapUtil")) {
1605 cna_config_volume_usage_option(host, cfg_volume_data, item, CFG_VOLUME_USAGE_SNAP);
1609 cfg_volume_data->flags |= CFG_VOLUME_USAGE_DF;
1610 host_set_all_cfg_volume_usage_flags(host, CFG_VOLUME_USAGE_DF, /* set = */ true);
1612 if (cfg_volume_data->flags & CFG_VOLUME_USAGE_SNAP) {
1613 WARNING("netapp plugin: The \"GetSnapUtil\" option does not support the \"+\" wildcard.");
1615 } /* }}} void cna_config_volume_usage */
1617 /* Corresponds to a <Disks /> block */
1618 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1619 cfg_disk_t *cfg_disk;
1622 if ((host == NULL) || (ci == NULL))
1625 if (host->cfg_disk == NULL)
1627 cfg_disk = malloc (sizeof (*cfg_disk));
1628 if (cfg_disk == NULL)
1630 memset (cfg_disk, 0, sizeof (*cfg_disk));
1632 /* Set default flags */
1633 cfg_disk->flags = CFG_DISK_ALL;
1634 cfg_disk->query = NULL;
1635 cfg_disk->disks = NULL;
1637 host->cfg_disk = cfg_disk;
1639 cfg_disk = host->cfg_disk;
1641 for (i = 0; i < ci->children_num; ++i) {
1642 oconfig_item_t *item = ci->children + i;
1644 /* if (!item || !item->key || !*item->key) continue; */
1645 if (strcasecmp(item->key, "Interval") == 0)
1646 cna_config_get_interval (item, &cfg_disk->interval);
1647 else if (strcasecmp(item->key, "GetBusy") == 0)
1648 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
1652 } /* }}} int cna_config_disk */
1654 /* Corresponds to a <WAFL /> block */
1655 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
1657 cfg_wafl_t *cfg_wafl;
1660 if ((host == NULL) || (ci == NULL))
1663 if (host->cfg_wafl == NULL)
1665 cfg_wafl = malloc (sizeof (*cfg_wafl));
1666 if (cfg_wafl == NULL)
1668 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
1670 /* Set default flags */
1671 cfg_wafl->flags = CFG_WAFL_ALL;
1673 host->cfg_wafl = cfg_wafl;
1675 cfg_wafl = host->cfg_wafl;
1677 for (i = 0; i < ci->children_num; ++i) {
1678 oconfig_item_t *item = ci->children + i;
1680 if (strcasecmp(item->key, "Interval") == 0)
1681 cna_config_get_interval (item, &cfg_wafl->interval);
1682 else if (!strcasecmp(item->key, "GetNameCache"))
1683 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
1684 else if (!strcasecmp(item->key, "GetDirCache"))
1685 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
1686 else if (!strcasecmp(item->key, "GetBufferCache"))
1687 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
1688 else if (!strcasecmp(item->key, "GetInodeCache"))
1689 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
1691 WARNING ("netapp plugin: The %s config option is not allowed within "
1692 "`WAFL' blocks.", item->key);
1696 } /* }}} int cna_config_wafl */
1698 /* Corresponds to a <System /> block */
1699 static int cna_config_system (host_config_t *host, /* {{{ */
1700 oconfig_item_t *ci, const cfg_service_t *default_service)
1702 cfg_system_t *cfg_system;
1705 if ((host == NULL) || (ci == NULL))
1708 if (host->cfg_system == NULL)
1710 cfg_system = malloc (sizeof (*cfg_system));
1711 if (cfg_system == NULL)
1713 memset (cfg_system, 0, sizeof (*cfg_system));
1715 /* Set default flags */
1716 cfg_system->flags = CFG_SYSTEM_ALL;
1717 cfg_system->query = NULL;
1719 host->cfg_system = cfg_system;
1721 cfg_system = host->cfg_system;
1723 for (i = 0; i < ci->children_num; ++i) {
1724 oconfig_item_t *item = ci->children + i;
1726 if (strcasecmp(item->key, "Interval") == 0) {
1727 cna_config_get_interval (item, &cfg_system->interval);
1728 } else if (!strcasecmp(item->key, "GetCPULoad")) {
1729 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
1730 } else if (!strcasecmp(item->key, "GetInterfaces")) {
1731 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
1732 } else if (!strcasecmp(item->key, "GetDiskOps")) {
1733 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
1734 } else if (!strcasecmp(item->key, "GetDiskIO")) {
1735 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
1737 WARNING ("netapp plugin: The %s config option is not allowed within "
1738 "`System' blocks.", item->key);
1743 } /* }}} int cna_config_system */
1745 /* Corresponds to a <Host /> block. */
1746 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
1747 const host_config_t *default_host, const cfg_service_t *def_def_service)
1749 oconfig_item_t *item;
1750 host_config_t *host;
1751 cfg_service_t default_service = *def_def_service;
1755 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1756 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
1760 host = malloc(sizeof(*host));
1761 memcpy (host, default_host, sizeof (*host));
1763 status = cf_util_get_string (ci, &host->name);
1770 for (i = 0; i < ci->children_num; ++i) {
1771 item = ci->children + i;
1775 if (!strcasecmp(item->key, "Address")) {
1776 status = cf_util_get_string (item, &host->host);
1777 } else if (!strcasecmp(item->key, "Port")) {
1780 tmp = cf_util_get_port_number (item);
1783 } else if (!strcasecmp(item->key, "Protocol")) {
1784 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"))) {
1785 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
1788 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
1789 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
1790 } else if (!strcasecmp(item->key, "User")) {
1791 status = cf_util_get_string (item, &host->username);
1792 } else if (!strcasecmp(item->key, "Password")) {
1793 status = cf_util_get_string (item, &host->password);
1794 } else if (!strcasecmp(item->key, "Interval")) {
1795 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) {
1796 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
1799 host->interval = item->values[0].value.number;
1800 } else if (!strcasecmp(item->key, "GetVolumePerfData")) {
1801 cna_config_volume_performance(host, item);
1802 } else if (!strcasecmp(item->key, "System")) {
1803 cna_config_system(host, item, &default_service);
1804 } else if (!strcasecmp(item->key, "WAFL")) {
1805 cna_config_wafl(host, item);
1806 } else if (!strcasecmp(item->key, "Disks")) {
1807 cna_config_disk(host, item);
1808 } else if (!strcasecmp(item->key, "GetVolumeData")) {
1809 cna_config_volume_usage(host, item);
1811 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
1812 item->key, ci->values[0].value.string);
1819 if (host->host == NULL)
1820 host->host = strdup (host->name);
1822 if (host->host == NULL)
1825 if (host->port <= 0)
1826 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
1828 if ((host->username == NULL) || (host->password == NULL)) {
1829 WARNING("netapp plugin: Please supply login information for host \"%s\". "
1830 "Ignoring host block.", host->name);
1836 free_host_config (host);
1841 } /* }}} host_config_t *cna_config_host */
1844 * Callbacks registered with the daemon
1846 * Pretty standard stuff here.
1848 static int cna_init(void) { /* {{{ */
1851 host_config_t *host;
1852 cfg_service_t *service;
1854 if (!global_host_config) {
1855 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
1859 memset (err, 0, sizeof (err));
1860 if (!na_startup(err, sizeof(err))) {
1861 err[sizeof (err) - 1] = 0;
1862 ERROR("netapp plugin: Error initializing netapp API: %s", err);
1866 for (host = global_host_config; host; host = host->next) {
1867 /* Request version 1.1 of the ONTAP API */
1868 host->srv = na_server_open(host->host,
1869 /* major version = */ 1, /* minor version = */ 1);
1870 if (host->srv == NULL) {
1871 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
1875 if (host->interval < interval_g)
1876 host->interval = interval_g;
1878 na_server_set_transport_type(host->srv, host->protocol,
1879 /* transportarg = */ NULL);
1880 na_server_set_port(host->srv, host->port);
1881 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
1882 na_server_adminuser(host->srv, host->username, host->password);
1883 na_server_set_timeout(host->srv, 5 /* seconds */);
1885 for (service = host->services; service; service = service->next) {
1886 service->interval = host->interval * service->multiplier;
1888 if (service->handler == query_volume_perf_data) {
1889 service->query = na_elem_new("perf-object-get-instances");
1890 na_child_add_string(service->query, "objectname", "volume");
1891 e = na_elem_new("counters");
1892 /* "foo" means: This string has to be here but
1893 the content doesn't matter. */
1894 na_child_add_string(e, "foo", "read_ops");
1895 na_child_add_string(e, "foo", "write_ops");
1896 na_child_add_string(e, "foo", "read_data");
1897 na_child_add_string(e, "foo", "write_data");
1898 na_child_add_string(e, "foo", "read_latency");
1899 na_child_add_string(e, "foo", "write_latency");
1900 na_child_add(service->query, e);
1901 } else if (service->handler == collect_volume_data) {
1902 service->query = na_elem_new("volume-list-info");
1903 /* na_child_add_string(service->query, "objectname", "volume"); */
1904 /* } else if (service->handler == collect_snapshot_data) { */
1905 /* service->query = na_elem_new("snapshot-list-info"); */
1907 } /* for (host->services) */
1910 } /* }}} int cna_init */
1912 static int cna_config (oconfig_item_t *ci) { /* {{{ */
1914 oconfig_item_t *item;
1915 host_config_t default_host = HOST_INIT;
1916 cfg_service_t default_service = SERVICE_INIT;
1918 for (i = 0; i < ci->children_num; ++i) {
1919 item = ci->children + i;
1921 if (!strcasecmp(item->key, "Host")) {
1922 host_config_t *host;
1925 host = cna_config_host(item, &default_host, &default_service);
1929 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
1931 if (strcasecmp (host->name, tmp->name) == 0)
1932 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
1933 "This is probably a bad idea.",
1936 if (tmp->next == NULL)
1942 global_host_config = host;
1946 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
1950 } /* }}} int cna_config */
1952 static int cna_read(void) { /* {{{ */
1954 host_config_t *host;
1955 cfg_service_t *service;
1957 for (host = global_host_config; host; host = host->next) {
1958 for (service = host->services; service; service = service->next) {
1959 if (--service->skip_countdown > 0) continue;
1960 service->skip_countdown = service->multiplier;
1961 out = na_server_invoke_elem(host->srv, service->query);
1962 if (na_results_status(out) != NA_OK) {
1963 int netapp_errno = na_results_errno(out);
1964 ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
1966 if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
1967 /* Network problems. Just give up on all other services on this host. */
1972 service->handler(host, out, service->data);
1974 } /* for (host->services) */
1976 cna_query_wafl (host);
1977 cna_query_disk (host);
1978 cna_query_system (host);
1981 } /* }}} int cna_read */
1983 void module_register(void) {
1984 plugin_register_complex_config("netapp", cna_config);
1985 plugin_register_init("netapp", cna_init);
1986 plugin_register_read("netapp", cna_read);
1989 /* vim: set sw=2 ts=2 noet fdm=marker : */