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 WAFL was not configured, return without doing anything. */
810 if (host->cfg_wafl == NULL)
814 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
817 status = cna_setup_wafl (host->cfg_wafl);
820 assert (host->cfg_wafl->query != NULL);
822 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
823 if (na_results_status (data) != NA_OK)
825 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed: %s",
826 na_results_reason (data));
831 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data);
834 host->cfg_wafl->interval.last_read = now;
838 } /* }}} int cna_query_wafl */
840 /* Data corresponding to <Disks /> */
841 static int cna_handle_disk_data (const char *hostname, /* {{{ */
842 cfg_disk_t *cfg_disk, na_elem_t *data)
845 na_elem_t *instances;
847 na_elem_iter_t instance_iter;
848 disk_t *worst_disk = NULL;
850 if ((cfg_disk == NULL) || (data == NULL))
853 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
855 instances = na_elem_child (data, "instances");
856 if (instances == NULL)
858 ERROR ("netapp plugin: cna_handle_disk_data: "
859 "na_elem_child (\"instances\") failed.");
863 /* Iterate over all children */
864 instance_iter = na_child_iterator (instances);
865 for (instance = na_iterator_next (&instance_iter);
867 instance = na_iterator_next(&instance_iter))
872 na_elem_iter_t counter_iterator;
875 memset (&new_data, 0, sizeof (new_data));
876 new_data.timestamp = timestamp;
877 new_data.disk_busy_percent = NAN;
879 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
880 if (old_data == NULL)
883 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
884 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
885 for (counter = na_iterator_next(&counter_iterator);
887 counter = na_iterator_next(&counter_iterator))
892 name = na_child_get_string(counter, "name");
896 value = na_child_get_uint64(counter, "value", UINT64_MAX);
897 if (value == UINT64_MAX)
900 if (strcmp(name, "disk_busy") == 0)
902 new_data.disk_busy = value;
903 new_data.flags |= HAVE_DISK_BUSY;
905 else if (strcmp(name, "base_for_disk_busy") == 0)
907 new_data.base_for_disk_busy = value;
908 new_data.flags |= HAVE_DISK_BASE;
912 DEBUG ("netapp plugin: cna_handle_disk_data: "
913 "Counter not handled: %s = %"PRIu64,
918 /* If all required counters are available and did not just wrap around,
919 * calculate the busy percentage. Otherwise, the value is initialized to
920 * NAN at the top of the for-loop. */
921 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
922 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
923 && (new_data.disk_busy >= old_data->disk_busy)
924 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
929 busy_diff = new_data.disk_busy - old_data->disk_busy;
930 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
932 new_data.disk_busy_percent = 100.0
933 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
936 /* Clear HAVE_* flags */
937 old_data->flags &= ~HAVE_DISK_ALL;
940 old_data->timestamp = new_data.timestamp;
941 old_data->disk_busy = new_data.disk_busy;
942 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
943 old_data->disk_busy_percent = new_data.disk_busy_percent;
946 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
948 if ((worst_disk == NULL)
949 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
950 worst_disk = old_data;
951 } /* for (all disks) */
953 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
954 submit_double (hostname, "system", "percent", "disk_busy",
955 worst_disk->disk_busy_percent, timestamp);
958 } /* }}} int cna_handle_disk_data */
960 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
967 if (cd->query != NULL)
970 cd->query = na_elem_new ("perf-object-get-instances");
971 if (cd->query == NULL)
973 ERROR ("netapp plugin: na_elem_new failed.");
976 na_child_add_string (cd->query, "objectname", "disk");
978 e = na_elem_new("counters");
981 na_elem_free (cd->query);
983 ERROR ("netapp plugin: na_elem_new failed.");
986 na_child_add_string(e, "foo", "disk_busy");
987 na_child_add_string(e, "foo", "base_for_disk_busy");
988 na_child_add(cd->query, e);
991 } /* }}} int cna_setup_disk */
993 static int cna_query_disk (host_config_t *host) /* {{{ */
1002 /* If the user did not configure disk statistics, return without doing
1004 if (host->cfg_disk == NULL)
1008 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1011 status = cna_setup_disk (host->cfg_disk);
1014 assert (host->cfg_disk->query != NULL);
1016 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1017 if (na_results_status (data) != NA_OK)
1019 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed: %s",
1020 na_results_reason (data));
1021 na_elem_free (data);
1025 status = cna_handle_disk_data (host->name, host->cfg_disk, data);
1028 host->cfg_disk->interval.last_read = now;
1030 na_elem_free (data);
1032 } /* }}} int cna_query_disk */
1034 /* Data corresponding to <GetVolumeData /> */
1035 static void collect_volume_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
1038 cfg_volume_usage_t *cfg_volume_data = data;
1040 out = na_elem_child(out, "volumes");
1041 na_elem_iter_t inst_iter = na_child_iterator(out);
1042 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
1043 uint64_t size_free = 0, size_used = 0, snap_reserved = 0;
1046 const char *sis_state;
1047 uint64_t sis_saved_reported;
1050 volume = get_volume(host, na_child_get_string(inst, "name"),
1051 cfg_volume_data->flags, /* perf_flags = */ 0);
1055 if (!(volume->cfg_volume_usage.flags & CFG_VOLUME_USAGE_DF))
1058 /* 2^4 exa-bytes? This will take a while ;) */
1059 size_free = na_child_get_uint64(inst, "size-available", UINT64_MAX);
1060 if (size_free != UINT64_MAX)
1061 submit_double (host->name, volume->name, "df_complex", "free",
1062 (double) size_free, /* time = */ 0);
1064 size_used = na_child_get_uint64(inst, "size-used", UINT64_MAX);
1065 if (size_used != UINT64_MAX) {
1066 if ((volume->cfg_volume_usage.flags & HAVE_VOLUME_USAGE_SNAP)
1067 && (size_used >= volume->cfg_volume_usage.snap_used))
1068 size_used -= volume->cfg_volume_usage.snap_used;
1069 submit_double (host->name, volume->name, "df_complex", "used",
1070 (double) size_used, /* time = */ 0);
1073 snap_reserved = na_child_get_uint64(inst, "snapshot-blocks-reserved", UINT64_MAX);
1074 if (!(volume->cfg_volume_usage.flags & HAVE_VOLUME_USAGE_SNAP) && (snap_reserved != UINT64_MAX))
1075 /* If we have snap usage data this value has already been submitted. */
1076 /* 1 block == 1024 bytes as per API docs */
1077 submit_double (host->name, volume->name, "df_complex", "snap_reserved",
1078 (double) (1024 * snap_reserved), /* time = */ 0);
1080 sis = na_elem_child(inst, "sis");
1084 sis_state = na_child_get_string(sis, "state");
1085 if ((sis_state == NULL)
1086 || (strcmp ("enabled", sis_state) != 0))
1089 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1090 if (sis_saved_reported == UINT64_MAX)
1093 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1094 if ((sis_saved_reported >> 32) != 0) {
1095 /* In case they ever fix this bug. */
1096 sis_saved = sis_saved_reported;
1098 uint64_t sis_saved_percent;
1099 uint64_t sis_saved_guess;
1100 uint64_t overflow_guess;
1101 uint64_t guess1, guess2, guess3;
1103 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1104 if (sis_saved_percent > 100)
1107 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1108 * will hopefully be fixed in later versions. To work around the bug, try
1109 * to figure out how often the 32bit integer wrapped around by using the
1110 * "percentage-saved" value. Because the percentage is in the range
1111 * [0-100], this should work as long as the saved space does not exceed
1113 /* percentage-saved = size-saved / (size-saved + size-used) */
1114 if (sis_saved_percent < 100)
1115 sis_saved_guess = size_used * sis_saved_percent / (100 - sis_saved_percent);
1117 sis_saved_guess = size_used;
1119 overflow_guess = sis_saved_guess >> 32;
1120 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1121 guess2 = (overflow_guess << 32) + sis_saved_reported;
1122 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1124 if (sis_saved_guess < guess2) {
1125 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1130 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1135 } /* end of 32-bit workaround */
1137 submit_double (host->name, volume->name, "df_complex", "sis_saved",
1138 (double) sis_saved, /* time = */ 0);
1140 } /* }}} void collect_volume_data */
1142 /* Data corresponding to <GetVolumePerfData /> */
1143 static void query_volume_perf_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
1144 cfg_volume_perf_t *cfg_volume_perf = data;
1146 na_elem_t *counter, *inst;
1148 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
1150 out = na_elem_child(out, "instances");
1151 na_elem_iter_t inst_iter = na_child_iterator(out);
1152 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
1153 data_volume_perf_t perf_data;
1156 memset (&perf_data, 0, sizeof (perf_data));
1157 perf_data.timestamp = timestamp;
1159 volume = get_volume(host, na_child_get_string(inst, "name"),
1160 /* data_flags = */ 0, cfg_volume_perf->flags);
1164 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
1165 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
1169 name = na_child_get_string(counter, "name");
1173 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1174 if (value == UINT64_MAX)
1177 if (!strcmp(name, "read_data")) {
1178 perf_data.read_bytes = value;
1179 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1180 } else if (!strcmp(name, "write_data")) {
1181 perf_data.write_bytes = value;
1182 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1183 } else if (!strcmp(name, "read_ops")) {
1184 perf_data.read_ops = value;
1185 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1186 } else if (!strcmp(name, "write_ops")) {
1187 perf_data.write_ops = value;
1188 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1189 } else if (!strcmp(name, "read_latency")) {
1190 perf_data.read_latency = value;
1191 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1192 } else if (!strcmp(name, "write_latency")) {
1193 perf_data.write_latency = value;
1194 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1198 submit_volume_perf_data (host, volume, &perf_data);
1199 } /* for (volume) */
1200 } /* }}} void query_volume_perf_data */
1202 /* Data corresponding to <System /> */
1203 static int cna_handle_system_data (const char *hostname, /* {{{ */
1204 cfg_system_t *cfg_system, na_elem_t *data)
1206 na_elem_t *instances;
1208 na_elem_iter_t counter_iter;
1210 counter_t disk_read = 0, disk_written = 0;
1211 counter_t net_recv = 0, net_sent = 0;
1212 counter_t cpu_busy = 0, cpu_total = 0;
1213 uint32_t counter_flags = 0;
1215 const char *instance;
1218 timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
1220 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1221 if (instances == NULL)
1223 ERROR ("netapp plugin: cna_handle_system_data: "
1224 "na_elem_child (\"instances\") failed.");
1228 instance = na_child_get_string (instances, "name");
1229 if (instance == NULL)
1231 ERROR ("netapp plugin: cna_handle_system_data: "
1232 "na_child_get_string (\"name\") failed.");
1236 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
1237 for (counter = na_iterator_next (&counter_iter);
1239 counter = na_iterator_next (&counter_iter))
1244 name = na_child_get_string(counter, "name");
1248 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1249 if (value == UINT64_MAX)
1252 if (!strcmp(name, "disk_data_read")) {
1253 disk_read = (counter_t) (value * 1024);
1254 counter_flags |= 0x01;
1255 } else if (!strcmp(name, "disk_data_written")) {
1256 disk_written = (counter_t) (value * 1024);
1257 counter_flags |= 0x02;
1258 } else if (!strcmp(name, "net_data_recv")) {
1259 net_recv = (counter_t) (value * 1024);
1260 counter_flags |= 0x04;
1261 } else if (!strcmp(name, "net_data_sent")) {
1262 net_sent = (counter_t) (value * 1024);
1263 counter_flags |= 0x08;
1264 } else if (!strcmp(name, "cpu_busy")) {
1265 cpu_busy = (counter_t) value;
1266 counter_flags |= 0x10;
1267 } else if (!strcmp(name, "cpu_elapsed_time")) {
1268 cpu_total = (counter_t) value;
1269 counter_flags |= 0x20;
1270 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1271 && (value > 0) && (strlen(name) > 4)
1272 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1273 submit_counter (hostname, instance, "disk_ops_complex", name,
1274 (counter_t) value, timestamp);
1276 } /* for (counter) */
1278 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1279 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
1280 submit_two_counters (hostname, instance, "disk_octets", NULL,
1281 disk_read, disk_written, timestamp);
1283 if ((cfg_system->flags & CFG_SYSTEM_NET)
1284 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
1285 submit_two_counters (hostname, instance, "if_octets", NULL,
1286 net_recv, net_sent, timestamp);
1288 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1289 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
1291 submit_counter (hostname, instance, "cpu", "system",
1292 cpu_busy, timestamp);
1293 submit_counter (hostname, instance, "cpu", "idle",
1294 cpu_total - cpu_busy, timestamp);
1298 } /* }}} int cna_handle_system_data */
1300 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
1305 if (cs->query != NULL)
1308 cs->query = na_elem_new ("perf-object-get-instances");
1309 if (cs->query == NULL)
1311 ERROR ("netapp plugin: na_elem_new failed.");
1314 na_child_add_string (cs->query, "objectname", "system");
1317 } /* }}} int cna_setup_system */
1319 static int cna_query_system (host_config_t *host) /* {{{ */
1328 /* If system statistics were not configured, return without doing anything. */
1329 if (host->cfg_system == NULL)
1333 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
1336 status = cna_setup_system (host->cfg_system);
1339 assert (host->cfg_system->query != NULL);
1341 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
1342 if (na_results_status (data) != NA_OK)
1344 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed: %s",
1345 na_results_reason (data));
1346 na_elem_free (data);
1350 status = cna_handle_system_data (host->name, host->cfg_system, data);
1353 host->cfg_system->interval.last_read = now;
1355 na_elem_free (data);
1357 } /* }}} int cna_query_system */
1360 * Configuration handling
1362 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1363 * is false. On error, the flag-field is not changed. */
1364 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1365 uint32_t *flags, uint32_t flag)
1367 if ((ci == NULL) || (flags == NULL))
1370 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1372 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1377 if (ci->values[0].value.boolean)
1383 } /* }}} int cna_config_bool_to_flag */
1385 /* Handling of the "Multiplier" option which is allowed in every block. */
1386 static int cna_config_get_multiplier (const oconfig_item_t *ci, /* {{{ */
1387 cfg_service_t *service)
1391 if ((ci == NULL) || (service == NULL))
1394 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1396 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1400 tmp = (int) (ci->values[0].value.number + .5);
1403 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1407 service->multiplier = tmp;
1408 service->skip_countdown = tmp;
1411 } /* }}} int cna_config_get_multiplier */
1413 /* Handling of the "Interval" option which is allowed in every block. */
1414 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1415 cna_interval_t *out_interval)
1419 if ((ci == NULL) || (out_interval == NULL))
1422 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1424 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1428 tmp = (time_t) (ci->values[0].value.number + .5);
1431 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1435 out_interval->interval = tmp;
1436 out_interval->last_read = 0;
1439 } /* }}} int cna_config_get_interval */
1441 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1442 * <GetVolumePerfData /> block. */
1443 static void cna_config_volume_performance_option (host_config_t *host, /* {{{ */
1444 cfg_volume_perf_t *perf_volume, const oconfig_item_t *item,
1449 for (i = 0; i < item->values_num; ++i) {
1454 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1455 WARNING("netapp plugin: Ignoring non-string argument in "
1456 "\"GetVolumePerfData\" block for host %s", host->name);
1460 name = item->values[i].value.string;
1461 if (name[0] == '+') {
1464 } else if (name[0] == '-') {
1471 perf_volume->flags |= flag;
1472 else /* if (!set) */
1473 perf_volume->flags &= ~flag;
1475 host_set_all_perf_data_flags(host, flag, set);
1479 v = get_volume (host, name, /* data_flags = */ 0, perf_volume->flags);
1484 v->perf_data.flags |= flag;
1485 else /* if (!set) */
1486 v->perf_data.flags &= ~flag;
1487 } /* for (i = 0 .. item->values_num) */
1488 } /* }}} void cna_config_volume_performance_option */
1490 /* Corresponds to a <GetVolumePerfData /> block */
1491 static void cna_config_volume_performance(host_config_t *host, const oconfig_item_t *ci) { /* {{{ */
1492 int i, had_io = 0, had_ops = 0, had_latency = 0;
1493 cfg_service_t *service;
1494 cfg_volume_perf_t *perf_volume;
1496 service = malloc(sizeof(*service));
1498 service->handler = query_volume_perf_data;
1499 perf_volume = service->data = malloc(sizeof(*perf_volume));
1500 perf_volume->flags = CFG_VOLUME_PERF_INIT;
1501 service->next = host->services;
1502 host->services = service;
1503 for (i = 0; i < ci->children_num; ++i) {
1504 oconfig_item_t *item = ci->children + i;
1506 /* if (!item || !item->key || !*item->key) continue; */
1507 if (!strcasecmp(item->key, "Multiplier")) {
1508 cna_config_get_multiplier (item, service);
1509 } else if (!strcasecmp(item->key, "GetIO")) {
1511 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_IO);
1512 } else if (!strcasecmp(item->key, "GetOps")) {
1514 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_OPS);
1515 } else if (!strcasecmp(item->key, "GetLatency")) {
1517 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_LATENCY);
1521 perf_volume->flags |= CFG_VOLUME_PERF_IO;
1522 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_IO, /* set = */ true);
1525 perf_volume->flags |= CFG_VOLUME_PERF_OPS;
1526 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_OPS, /* set = */ true);
1529 perf_volume->flags |= CFG_VOLUME_PERF_LATENCY;
1530 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_LATENCY, /* set = */ true);
1532 } /* }}} void cna_config_volume_performance */
1534 /* Handling of the "GetDiskUtil" option within a <GetVolumeData /> block. */
1535 static void cna_config_volume_usage_option (host_config_t *host, /* {{{ */
1536 cfg_volume_usage_t *cfg_volume_data, const oconfig_item_t *item, uint32_t flag)
1540 for (i = 0; i < item->values_num; ++i) {
1545 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1546 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolData\""
1547 "block for host %s", host->name);
1551 name = item->values[i].value.string;
1552 if (name[0] == '+') {
1555 } else if (name[0] == '-') {
1562 cfg_volume_data->flags |= flag;
1563 else /* if (!set) */
1564 cfg_volume_data->flags &= ~flag;
1566 host_set_all_cfg_volume_usage_flags(host, flag, set);
1570 v = get_volume(host, name, cfg_volume_data->flags, /* perf_flags = */ 0);
1574 if (!v->cfg_volume_usage.flags)
1575 v->cfg_volume_usage.flags = cfg_volume_data->flags;
1578 v->cfg_volume_usage.flags |= flag;
1579 else /* if (!set) */
1580 v->cfg_volume_usage.flags &= ~flag;
1582 } /* }}} void cna_config_volume_usage_option */
1584 /* Corresponds to a <GetVolumeData /> block */
1585 static void cna_config_volume_usage(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1587 cfg_service_t *service;
1588 cfg_volume_usage_t *cfg_volume_data;
1590 service = malloc(sizeof(*service));
1592 service->handler = collect_volume_data;
1593 cfg_volume_data = service->data = malloc(sizeof(*cfg_volume_data));
1594 cfg_volume_data->flags = CFG_VOLUME_USAGE_INIT;
1595 service->next = host->services;
1596 host->services = service;
1597 for (i = 0; i < ci->children_num; ++i) {
1598 oconfig_item_t *item = ci->children + i;
1600 /* if (!item || !item->key || !*item->key) continue; */
1601 if (!strcasecmp(item->key, "Multiplier")) {
1602 cna_config_get_multiplier (item, service);
1603 } else if (!strcasecmp(item->key, "GetDiskUtil")) {
1605 cna_config_volume_usage_option(host, cfg_volume_data, item, CFG_VOLUME_USAGE_DF);
1606 } else if (!strcasecmp(item->key, "GetSnapUtil")) {
1608 cna_config_volume_usage_option(host, cfg_volume_data, item, CFG_VOLUME_USAGE_SNAP);
1612 cfg_volume_data->flags |= CFG_VOLUME_USAGE_DF;
1613 host_set_all_cfg_volume_usage_flags(host, CFG_VOLUME_USAGE_DF, /* set = */ true);
1615 if (cfg_volume_data->flags & CFG_VOLUME_USAGE_SNAP) {
1616 WARNING("netapp plugin: The \"GetSnapUtil\" option does not support the \"+\" wildcard.");
1618 } /* }}} void cna_config_volume_usage */
1620 /* Corresponds to a <Disks /> block */
1621 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1622 cfg_disk_t *cfg_disk;
1625 if ((host == NULL) || (ci == NULL))
1628 if (host->cfg_disk == NULL)
1630 cfg_disk = malloc (sizeof (*cfg_disk));
1631 if (cfg_disk == NULL)
1633 memset (cfg_disk, 0, sizeof (*cfg_disk));
1635 /* Set default flags */
1636 cfg_disk->flags = CFG_DISK_ALL;
1637 cfg_disk->query = NULL;
1638 cfg_disk->disks = NULL;
1640 host->cfg_disk = cfg_disk;
1642 cfg_disk = host->cfg_disk;
1644 for (i = 0; i < ci->children_num; ++i) {
1645 oconfig_item_t *item = ci->children + i;
1647 /* if (!item || !item->key || !*item->key) continue; */
1648 if (strcasecmp(item->key, "Interval") == 0)
1649 cna_config_get_interval (item, &cfg_disk->interval);
1650 else if (strcasecmp(item->key, "GetBusy") == 0)
1651 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
1655 } /* }}} int cna_config_disk */
1657 /* Corresponds to a <WAFL /> block */
1658 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
1660 cfg_wafl_t *cfg_wafl;
1663 if ((host == NULL) || (ci == NULL))
1666 if (host->cfg_wafl == NULL)
1668 cfg_wafl = malloc (sizeof (*cfg_wafl));
1669 if (cfg_wafl == NULL)
1671 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
1673 /* Set default flags */
1674 cfg_wafl->flags = CFG_WAFL_ALL;
1676 host->cfg_wafl = cfg_wafl;
1678 cfg_wafl = host->cfg_wafl;
1680 for (i = 0; i < ci->children_num; ++i) {
1681 oconfig_item_t *item = ci->children + i;
1683 if (strcasecmp(item->key, "Interval") == 0)
1684 cna_config_get_interval (item, &cfg_wafl->interval);
1685 else if (!strcasecmp(item->key, "GetNameCache"))
1686 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
1687 else if (!strcasecmp(item->key, "GetDirCache"))
1688 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
1689 else if (!strcasecmp(item->key, "GetBufferCache"))
1690 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
1691 else if (!strcasecmp(item->key, "GetInodeCache"))
1692 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
1694 WARNING ("netapp plugin: The %s config option is not allowed within "
1695 "`WAFL' blocks.", item->key);
1699 } /* }}} int cna_config_wafl */
1701 /* Corresponds to a <System /> block */
1702 static int cna_config_system (host_config_t *host, /* {{{ */
1703 oconfig_item_t *ci, const cfg_service_t *default_service)
1705 cfg_system_t *cfg_system;
1708 if ((host == NULL) || (ci == NULL))
1711 if (host->cfg_system == NULL)
1713 cfg_system = malloc (sizeof (*cfg_system));
1714 if (cfg_system == NULL)
1716 memset (cfg_system, 0, sizeof (*cfg_system));
1718 /* Set default flags */
1719 cfg_system->flags = CFG_SYSTEM_ALL;
1720 cfg_system->query = NULL;
1722 host->cfg_system = cfg_system;
1724 cfg_system = host->cfg_system;
1726 for (i = 0; i < ci->children_num; ++i) {
1727 oconfig_item_t *item = ci->children + i;
1729 if (strcasecmp(item->key, "Interval") == 0) {
1730 cna_config_get_interval (item, &cfg_system->interval);
1731 } else if (!strcasecmp(item->key, "GetCPULoad")) {
1732 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
1733 } else if (!strcasecmp(item->key, "GetInterfaces")) {
1734 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
1735 } else if (!strcasecmp(item->key, "GetDiskOps")) {
1736 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
1737 } else if (!strcasecmp(item->key, "GetDiskIO")) {
1738 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
1740 WARNING ("netapp plugin: The %s config option is not allowed within "
1741 "`System' blocks.", item->key);
1746 } /* }}} int cna_config_system */
1748 /* Corresponds to a <Host /> block. */
1749 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
1750 const host_config_t *default_host, const cfg_service_t *def_def_service)
1752 oconfig_item_t *item;
1753 host_config_t *host;
1754 cfg_service_t default_service = *def_def_service;
1758 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1759 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
1763 host = malloc(sizeof(*host));
1764 memcpy (host, default_host, sizeof (*host));
1766 status = cf_util_get_string (ci, &host->name);
1773 for (i = 0; i < ci->children_num; ++i) {
1774 item = ci->children + i;
1778 if (!strcasecmp(item->key, "Address")) {
1779 status = cf_util_get_string (item, &host->host);
1780 } else if (!strcasecmp(item->key, "Port")) {
1783 tmp = cf_util_get_port_number (item);
1786 } else if (!strcasecmp(item->key, "Protocol")) {
1787 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"))) {
1788 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
1791 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
1792 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
1793 } else if (!strcasecmp(item->key, "User")) {
1794 status = cf_util_get_string (item, &host->username);
1795 } else if (!strcasecmp(item->key, "Password")) {
1796 status = cf_util_get_string (item, &host->password);
1797 } else if (!strcasecmp(item->key, "Interval")) {
1798 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) {
1799 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
1802 host->interval = item->values[0].value.number;
1803 } else if (!strcasecmp(item->key, "GetVolumePerfData")) {
1804 cna_config_volume_performance(host, item);
1805 } else if (!strcasecmp(item->key, "System")) {
1806 cna_config_system(host, item, &default_service);
1807 } else if (!strcasecmp(item->key, "WAFL")) {
1808 cna_config_wafl(host, item);
1809 } else if (!strcasecmp(item->key, "Disks")) {
1810 cna_config_disk(host, item);
1811 } else if (!strcasecmp(item->key, "GetVolumeData")) {
1812 cna_config_volume_usage(host, item);
1814 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
1815 item->key, ci->values[0].value.string);
1822 if (host->host == NULL)
1823 host->host = strdup (host->name);
1825 if (host->host == NULL)
1828 if (host->port <= 0)
1829 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
1831 if ((host->username == NULL) || (host->password == NULL)) {
1832 WARNING("netapp plugin: Please supply login information for host \"%s\". "
1833 "Ignoring host block.", host->name);
1839 free_host_config (host);
1844 } /* }}} host_config_t *cna_config_host */
1847 * Callbacks registered with the daemon
1849 * Pretty standard stuff here.
1851 static int cna_init(void) { /* {{{ */
1854 host_config_t *host;
1855 cfg_service_t *service;
1857 if (!global_host_config) {
1858 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
1862 memset (err, 0, sizeof (err));
1863 if (!na_startup(err, sizeof(err))) {
1864 err[sizeof (err) - 1] = 0;
1865 ERROR("netapp plugin: Error initializing netapp API: %s", err);
1869 for (host = global_host_config; host; host = host->next) {
1870 /* Request version 1.1 of the ONTAP API */
1871 host->srv = na_server_open(host->host,
1872 /* major version = */ 1, /* minor version = */ 1);
1873 if (host->srv == NULL) {
1874 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
1878 if (host->interval < interval_g)
1879 host->interval = interval_g;
1881 na_server_set_transport_type(host->srv, host->protocol,
1882 /* transportarg = */ NULL);
1883 na_server_set_port(host->srv, host->port);
1884 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
1885 na_server_adminuser(host->srv, host->username, host->password);
1886 na_server_set_timeout(host->srv, 5 /* seconds */);
1888 for (service = host->services; service; service = service->next) {
1889 service->interval = host->interval * service->multiplier;
1891 if (service->handler == query_volume_perf_data) {
1892 service->query = na_elem_new("perf-object-get-instances");
1893 na_child_add_string(service->query, "objectname", "volume");
1894 e = na_elem_new("counters");
1895 /* "foo" means: This string has to be here but
1896 the content doesn't matter. */
1897 na_child_add_string(e, "foo", "read_ops");
1898 na_child_add_string(e, "foo", "write_ops");
1899 na_child_add_string(e, "foo", "read_data");
1900 na_child_add_string(e, "foo", "write_data");
1901 na_child_add_string(e, "foo", "read_latency");
1902 na_child_add_string(e, "foo", "write_latency");
1903 na_child_add(service->query, e);
1904 } else if (service->handler == collect_volume_data) {
1905 service->query = na_elem_new("volume-list-info");
1906 /* na_child_add_string(service->query, "objectname", "volume"); */
1907 /* } else if (service->handler == collect_snapshot_data) { */
1908 /* service->query = na_elem_new("snapshot-list-info"); */
1910 } /* for (host->services) */
1913 } /* }}} int cna_init */
1915 static int cna_config (oconfig_item_t *ci) { /* {{{ */
1917 oconfig_item_t *item;
1918 host_config_t default_host = HOST_INIT;
1919 cfg_service_t default_service = SERVICE_INIT;
1921 for (i = 0; i < ci->children_num; ++i) {
1922 item = ci->children + i;
1924 if (!strcasecmp(item->key, "Host")) {
1925 host_config_t *host;
1928 host = cna_config_host(item, &default_host, &default_service);
1932 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
1934 if (strcasecmp (host->name, tmp->name) == 0)
1935 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
1936 "This is probably a bad idea.",
1939 if (tmp->next == NULL)
1945 global_host_config = host;
1949 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
1953 } /* }}} int cna_config */
1955 static int cna_read(void) { /* {{{ */
1957 host_config_t *host;
1958 cfg_service_t *service;
1960 for (host = global_host_config; host; host = host->next) {
1961 for (service = host->services; service; service = service->next) {
1962 if (--service->skip_countdown > 0) continue;
1963 service->skip_countdown = service->multiplier;
1964 out = na_server_invoke_elem(host->srv, service->query);
1965 if (na_results_status(out) != NA_OK) {
1966 int netapp_errno = na_results_errno(out);
1967 ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
1969 if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
1970 /* Network problems. Just give up on all other services on this host. */
1975 service->handler(host, out, service->data);
1977 } /* for (host->services) */
1979 cna_query_wafl (host);
1980 cna_query_disk (host);
1981 cna_query_system (host);
1984 } /* }}} int cna_read */
1986 void module_register(void) {
1987 plugin_register_complex_config("netapp", cna_config);
1988 plugin_register_init("netapp", cna_init);
1989 plugin_register_read("netapp", cna_read);
1992 /* vim: set sw=2 ts=2 noet fdm=marker : */