2 * collectd - src/netapp.c
3 * Copyright (C) 2009 Sven Trenkel
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Sven Trenkel <collectd at semidefinite.de>
30 #include <netapp_api.h>
32 #define HAS_ALL_FLAGS(has,needs) (((has) & (needs)) == (needs))
34 typedef struct host_config_s host_config_t;
35 typedef void service_handler_t(host_config_t *host, na_elem_t *result, void *data);
42 typedef struct cna_interval_s cna_interval_t;
45 * \brief Persistent data for system performance counters
47 #define CFG_SYSTEM_CPU 0x01
48 #define CFG_SYSTEM_NET 0x02
49 #define CFG_SYSTEM_OPS 0x04
50 #define CFG_SYSTEM_DISK 0x08
51 #define CFG_SYSTEM_ALL 0x0F
54 cna_interval_t interval;
59 * \brief Persistent data for WAFL performance counters. (a.k.a. cache performance)
61 * The cache counters use old counter values to calculate a hit ratio for each
62 * counter. The "cfg_wafl_t" struct therefore contains old counter values along
63 * with flags, which are set if the counter is valid.
65 * The function "cna_handle_wafl_data" will fill a new structure of this kind
66 * with new values, then pass both, new and old data, to "submit_wafl_data".
67 * That function calculates the hit ratios, submits the calculated values and
68 * updates the old counter values for the next iteration.
70 #define CFG_WAFL_NAME_CACHE 0x0001
71 #define CFG_WAFL_DIR_CACHE 0x0002
72 #define CFG_WAFL_BUF_CACHE 0x0004
73 #define CFG_WAFL_INODE_CACHE 0x0008
74 #define CFG_WAFL_ALL 0x000F
75 #define HAVE_WAFL_NAME_CACHE_HIT 0x0100
76 #define HAVE_WAFL_NAME_CACHE_MISS 0x0200
77 #define HAVE_WAFL_NAME_CACHE (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
78 #define HAVE_WAFL_FIND_DIR_HIT 0x0400
79 #define HAVE_WAFL_FIND_DIR_MISS 0x0800
80 #define HAVE_WAFL_FIND_DIR (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
81 #define HAVE_WAFL_BUF_HASH_HIT 0x1000
82 #define HAVE_WAFL_BUF_HASH_MISS 0x2000
83 #define HAVE_WAFL_BUF_HASH (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
84 #define HAVE_WAFL_INODE_CACHE_HIT 0x4000
85 #define HAVE_WAFL_INODE_CACHE_MISS 0x8000
86 #define HAVE_WAFL_INODE_CACHE (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
87 #define HAVE_WAFL_ALL 0xff00
90 cna_interval_t interval;
94 uint64_t name_cache_hit;
95 uint64_t name_cache_miss;
96 uint64_t find_dir_hit;
97 uint64_t find_dir_miss;
98 uint64_t buf_hash_hit;
99 uint64_t buf_hash_miss;
100 uint64_t inode_cache_hit;
101 uint64_t inode_cache_miss;
105 * \brief Persistent data for volume performance data.
107 * The code below uses the difference of the operations and latency counters to
108 * calculate an average per-operation latency. For this, old counters need to
109 * be stored in the "data_volume_perf_t" structure. The byte-counters are just
110 * kept for completeness sake. The "flags" member indicates if each counter is
113 * The "query_volume_perf_data" function will fill a new struct of this type
114 * and pass both, old and new data, to "submit_volume_perf_data". In that
115 * function, the per-operation latency is calculated and dispatched, then the
116 * old counters are updated.
118 #define CFG_VOLUME_PERF_INIT 0x0001
119 #define CFG_VOLUME_PERF_IO 0x0002
120 #define CFG_VOLUME_PERF_OPS 0x0003
121 #define CFG_VOLUME_PERF_LATENCY 0x0008
122 #define CFG_VOLUME_PERF_ALL 0x000F
123 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
124 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
125 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
126 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
127 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
128 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
129 #define HAVE_VOLUME_PERF_ALL 0x03F0
138 uint64_t write_bytes;
141 uint64_t read_latency;
142 uint64_t write_latency;
143 } data_volume_perf_t;
146 * \brief Configuration struct for volume usage data (free / used).
148 #define CFG_VOLUME_USAGE_INIT 0x0001
149 #define CFG_VOLUME_USAGE_DF 0x0002
150 #define CFG_VOLUME_USAGE_SNAP 0x0004
151 #define HAVE_VOLUME_USAGE_SNAP 0x0008
155 } cfg_volume_usage_t;
157 typedef struct service_config_s {
159 service_handler_t *handler;
164 struct service_config_s *next;
166 #define SERVICE_INIT {0, 0, 1, 1, 0, 0, 0}
169 * \brief Struct representing a volume.
171 * A volume currently has a name and two sets of values:
173 * - Performance data, such as bytes read/written, number of operations
174 * performed and average time per operation.
176 * - Usage data, i. e. amount of used and free space in the volume.
178 typedef struct volume_s {
180 data_volume_perf_t perf_data;
181 cfg_volume_usage_t cfg_volume_usage;
182 struct volume_s *next;
186 * \brief A disk in the NetApp.
188 * A disk doesn't have any more information than its name at the moment.
189 * The name includes the "disk_" prefix.
191 #define HAVE_DISK_BUSY 0x10
192 #define HAVE_DISK_BASE 0x20
193 #define HAVE_DISK_ALL 0x30
194 typedef struct disk_s {
199 uint64_t base_for_disk_busy;
200 double disk_busy_percent;
204 #define CFG_DISK_BUSIEST 0x01
205 #define CFG_DISK_ALL 0x01
208 cna_interval_t interval;
213 struct host_config_s {
215 na_server_transport_t protocol;
223 cfg_service_t *services;
224 cfg_disk_t *cfg_disk;
225 cfg_wafl_t *cfg_wafl;
226 cfg_system_t *cfg_system;
229 struct host_config_s *next;
231 #define HOST_INIT { NULL, NA_SERVER_TRANSPORT_HTTPS, NULL, 0, NULL, NULL, 0, \
232 NULL, NULL, NULL, NULL, \
235 static host_config_t *global_host_config;
240 * Used to free the various structures above.
242 static void free_volume (volume_t *volume) /* {{{ */
248 sfree (volume->name);
252 } /* }}} void free_volume */
254 static void free_disk (disk_t *disk) /* {{{ */
264 } /* }}} void free_disk */
266 static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
271 if (cw->query != NULL)
272 na_elem_free (cw->query);
275 } /* }}} void free_cfg_wafl */
277 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
279 if (cfg_disk == NULL)
282 free_disk (cfg_disk->disks);
284 } /* }}} void free_cfg_disk */
286 static void free_cfg_service (cfg_service_t *service) /* {{{ */
293 next = service->next;
295 /* FIXME: Free service->data? */
296 na_elem_free(service->query);
300 free_cfg_service (next);
301 } /* }}} void free_cfg_service */
303 static void free_host_config (host_config_t *hc) /* {{{ */
314 sfree (hc->username);
315 sfree (hc->password);
317 free_cfg_service (hc->services);
318 free_cfg_disk (hc->cfg_disk);
319 free_cfg_wafl (hc->cfg_wafl);
320 free_volume (hc->volumes);
324 free_host_config (next);
325 } /* }}} void free_host_config */
328 * Auxiliary functions
330 * Used to look up volumes and disks or to handle flags.
332 static volume_t *get_volume (host_config_t *host, const char *name, /* {{{ */
333 uint32_t vol_usage_flags, uint32_t vol_perf_flags)
340 /* Make sure the default flags include the init-bit. */
341 if (vol_usage_flags != 0)
342 vol_usage_flags |= CFG_VOLUME_USAGE_INIT;
343 if (vol_perf_flags != 0)
344 vol_perf_flags |= CFG_VOLUME_PERF_INIT;
346 for (v = host->volumes; v; v = v->next) {
347 if (strcmp(v->name, name) != 0)
350 /* Check if the flags have been initialized. */
351 if (((v->cfg_volume_usage.flags & CFG_VOLUME_USAGE_INIT) == 0)
352 && (vol_usage_flags != 0))
353 v->cfg_volume_usage.flags = vol_usage_flags;
354 if (((v->perf_data.flags & CFG_VOLUME_PERF_INIT) == 0)
355 && (vol_perf_flags != 0))
356 v->perf_data.flags = vol_perf_flags;
361 DEBUG ("netapp plugin: Allocating new entry for volume %s.", name);
362 v = malloc(sizeof(*v));
365 memset (v, 0, sizeof (*v));
367 v->cfg_volume_usage.flags = vol_usage_flags;
368 v->perf_data.flags = vol_perf_flags;
370 v->name = strdup(name);
371 if (v->name == NULL) {
376 v->next = host->volumes;
380 } /* }}} volume_t *get_volume */
382 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
386 if ((cd == NULL) || (name == NULL))
389 for (d = cd->disks; d != NULL; d = d->next) {
390 if (strcmp(d->name, name) == 0)
394 d = malloc(sizeof(*d));
397 memset (d, 0, sizeof (*d));
400 d->name = strdup(name);
401 if (d->name == NULL) {
410 } /* }}} disk_t *get_disk */
412 static void host_set_all_perf_data_flags(const host_config_t *host, /* {{{ */
413 uint32_t flag, _Bool set)
417 for (v = host->volumes; v; v = v->next) {
419 v->perf_data.flags |= flag;
421 v->perf_data.flags &= ~flag;
423 } /* }}} void host_set_all_perf_data_flags */
425 static void host_set_all_cfg_volume_usage_flags(const host_config_t *host, /* {{{ */
426 uint32_t flag, _Bool set) {
429 for (v = host->volumes; v; v = v->next) {
431 v->cfg_volume_usage.flags |= flag;
433 v->cfg_volume_usage.flags &= ~flag;
435 } /* }}} void host_set_all_cfg_volume_usage_flags */
438 * Various submit functions.
440 * They all eventually call "submit_values" which creates a value_list_t and
441 * dispatches it to the daemon.
443 static int submit_values (const char *host, /* {{{ */
444 const char *plugin_inst,
445 const char *type, const char *type_inst,
446 value_t *values, int values_len,
449 value_list_t vl = VALUE_LIST_INIT;
452 vl.values_len = values_len;
458 sstrncpy (vl.host, host, sizeof (vl.host));
460 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
461 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
462 if (plugin_inst != NULL)
463 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
464 sstrncpy (vl.type, type, sizeof (vl.type));
465 if (type_inst != NULL)
466 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
468 return (plugin_dispatch_values (&vl));
469 } /* }}} int submit_uint64 */
471 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
472 const char *type, const char *type_inst, counter_t val0, counter_t val1,
477 values[0].counter = val0;
478 values[1].counter = val1;
480 return (submit_values (host, plugin_inst, type, type_inst,
481 values, 2, timestamp));
482 } /* }}} int submit_two_counters */
484 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
485 const char *type, const char *type_inst, counter_t counter, time_t timestamp)
491 return (submit_values (host, plugin_inst, type, type_inst,
493 } /* }}} int submit_counter */
495 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
496 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
501 values[0].gauge = val0;
502 values[1].gauge = val1;
504 return (submit_values (host, plugin_inst, type, type_inst,
505 values, 2, timestamp));
506 } /* }}} int submit_two_gauge */
508 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
509 const char *type, const char *type_inst, double d, time_t timestamp)
513 v.gauge = (gauge_t) d;
515 return (submit_values (host, plugin_inst, type, type_inst,
517 } /* }}} int submit_uint64 */
519 /* Calculate hit ratio from old and new counters and submit the resulting
520 * percentage. Used by "submit_wafl_data". */
521 static int submit_cache_ratio (const char *host, /* {{{ */
522 const char *plugin_inst,
523 const char *type_inst,
532 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
536 hits = new_hits - old_hits;
537 misses = new_misses - old_misses;
539 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
544 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
546 } /* }}} int submit_cache_ratio */
548 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
549 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
550 cfg_wafl_t *old_data, const cfg_wafl_t *new_data)
552 /* Submit requested counters */
553 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
554 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
555 submit_cache_ratio (hostname, instance, "name_cache_hit",
556 new_data->name_cache_hit, new_data->name_cache_miss,
557 old_data->name_cache_hit, old_data->name_cache_miss,
558 new_data->timestamp);
560 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
561 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
562 submit_cache_ratio (hostname, instance, "find_dir_hit",
563 new_data->find_dir_hit, new_data->find_dir_miss,
564 old_data->find_dir_hit, old_data->find_dir_miss,
565 new_data->timestamp);
567 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
568 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
569 submit_cache_ratio (hostname, instance, "buf_hash_hit",
570 new_data->buf_hash_hit, new_data->buf_hash_miss,
571 old_data->buf_hash_hit, old_data->buf_hash_miss,
572 new_data->timestamp);
574 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
575 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
576 submit_cache_ratio (hostname, instance, "inode_cache_hit",
577 new_data->inode_cache_hit, new_data->inode_cache_miss,
578 old_data->inode_cache_hit, old_data->inode_cache_miss,
579 new_data->timestamp);
581 /* Clear old HAVE_* flags */
582 old_data->flags &= ~HAVE_WAFL_ALL;
584 /* Copy all counters */
585 old_data->timestamp = new_data->timestamp;
586 old_data->name_cache_hit = new_data->name_cache_hit;
587 old_data->name_cache_miss = new_data->name_cache_miss;
588 old_data->find_dir_hit = new_data->find_dir_hit;
589 old_data->find_dir_miss = new_data->find_dir_miss;
590 old_data->buf_hash_hit = new_data->buf_hash_hit;
591 old_data->buf_hash_miss = new_data->buf_hash_miss;
592 old_data->inode_cache_hit = new_data->inode_cache_hit;
593 old_data->inode_cache_miss = new_data->inode_cache_miss;
595 /* Copy HAVE_* flags */
596 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
599 } /* }}} int submit_wafl_data */
601 /* Submits volume performance data to the daemon, taking care to honor and
602 * update flags appropriately. */
603 static int submit_volume_perf_data (const host_config_t *host, /* {{{ */
605 const data_volume_perf_t *new_data)
607 /* Check for and submit disk-octet values */
608 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_IO)
609 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
611 submit_two_counters (host->name, volume->name, "disk_octets", /* type instance = */ NULL,
612 (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
615 /* Check for and submit disk-operations values */
616 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_OPS)
617 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
619 submit_two_counters (host->name, volume->name, "disk_ops", /* type instance = */ NULL,
620 (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
623 /* Check for, calculate and submit disk-latency values */
624 if (HAS_ALL_FLAGS (volume->perf_data.flags, CFG_VOLUME_PERF_LATENCY
625 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
626 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
627 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
628 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
630 gauge_t latency_per_op_read;
631 gauge_t latency_per_op_write;
633 latency_per_op_read = NAN;
634 latency_per_op_write = NAN;
636 /* Check if a counter wrapped around. */
637 if ((new_data->read_ops > volume->perf_data.read_ops)
638 && (new_data->read_latency > volume->perf_data.read_latency))
640 uint64_t diff_ops_read;
641 uint64_t diff_latency_read;
643 diff_ops_read = new_data->read_ops - volume->perf_data.read_ops;
644 diff_latency_read = new_data->read_latency - volume->perf_data.read_latency;
646 if (diff_ops_read > 0)
647 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
650 if ((new_data->write_ops > volume->perf_data.write_ops)
651 && (new_data->write_latency > volume->perf_data.write_latency))
653 uint64_t diff_ops_write;
654 uint64_t diff_latency_write;
656 diff_ops_write = new_data->write_ops - volume->perf_data.write_ops;
657 diff_latency_write = new_data->write_latency - volume->perf_data.write_latency;
659 if (diff_ops_write > 0)
660 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
663 submit_two_gauge (host->name, volume->name, "disk_latency", /* type instance = */ NULL,
664 latency_per_op_read, latency_per_op_write, new_data->timestamp);
667 /* Clear all HAVE_* flags. */
668 volume->perf_data.flags &= ~HAVE_VOLUME_PERF_ALL;
670 /* Copy all counters */
671 volume->perf_data.timestamp = new_data->timestamp;
672 volume->perf_data.read_bytes = new_data->read_bytes;
673 volume->perf_data.write_bytes = new_data->write_bytes;
674 volume->perf_data.read_ops = new_data->read_ops;
675 volume->perf_data.write_ops = new_data->write_ops;
676 volume->perf_data.read_latency = new_data->read_latency;
677 volume->perf_data.write_latency = new_data->write_latency;
679 /* Copy the HAVE_* flags */
680 volume->perf_data.flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
683 } /* }}} int submit_volume_perf_data */
688 * These functions are called with appropriate data returned by the libnetapp
689 * interface which is parsed and submitted with the above functions.
691 /* Data corresponding to <WAFL /> */
692 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
695 cfg_wafl_t perf_data;
696 const char *plugin_inst;
698 na_elem_t *instances;
700 na_elem_iter_t counter_iter;
702 memset (&perf_data, 0, sizeof (perf_data));
704 perf_data.timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
706 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
707 if (instances == NULL)
709 ERROR ("netapp plugin: cna_handle_wafl_data: "
710 "na_elem_child (\"instances\") failed.");
714 plugin_inst = na_child_get_string(instances, "name");
715 if (plugin_inst == NULL)
717 ERROR ("netapp plugin: cna_handle_wafl_data: "
718 "na_child_get_string (\"name\") failed.");
722 /* Iterate over all counters */
723 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
724 for (counter = na_iterator_next (&counter_iter);
726 counter = na_iterator_next (&counter_iter))
731 name = na_child_get_string(counter, "name");
735 value = na_child_get_uint64(counter, "value", UINT64_MAX);
736 if (value == UINT64_MAX)
739 if (!strcmp(name, "name_cache_hit")) {
740 perf_data.name_cache_hit = value;
741 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
742 } else if (!strcmp(name, "name_cache_miss")) {
743 perf_data.name_cache_miss = value;
744 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
745 } else if (!strcmp(name, "find_dir_hit")) {
746 perf_data.find_dir_hit = value;
747 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
748 } else if (!strcmp(name, "find_dir_miss")) {
749 perf_data.find_dir_miss = value;
750 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
751 } else if (!strcmp(name, "buf_hash_hit")) {
752 perf_data.buf_hash_hit = value;
753 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
754 } else if (!strcmp(name, "buf_hash_miss")) {
755 perf_data.buf_hash_miss = value;
756 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
757 } else if (!strcmp(name, "inode_cache_hit")) {
758 perf_data.inode_cache_hit = value;
759 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
760 } else if (!strcmp(name, "inode_cache_miss")) {
761 perf_data.inode_cache_miss = value;
762 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
764 DEBUG("netapp plugin: cna_handle_wafl_data: "
765 "Found unexpected child: %s", name);
769 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data));
770 } /* }}} void cna_handle_wafl_data */
772 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
779 if (cw->query != NULL)
782 cw->query = na_elem_new("perf-object-get-instances");
783 if (cw->query == NULL)
785 ERROR ("netapp plugin: na_elem_new failed.");
788 na_child_add_string (cw->query, "objectname", "wafl");
790 e = na_elem_new("counters");
793 na_elem_free (cw->query);
795 ERROR ("netapp plugin: na_elem_new failed.");
798 na_child_add_string(e, "foo", "name_cache_hit");
799 na_child_add_string(e, "foo", "name_cache_miss");
800 na_child_add_string(e, "foo", "find_dir_hit");
801 na_child_add_string(e, "foo", "find_dir_miss");
802 na_child_add_string(e, "foo", "buf_hash_hit");
803 na_child_add_string(e, "foo", "buf_hash_miss");
804 na_child_add_string(e, "foo", "inode_cache_hit");
805 na_child_add_string(e, "foo", "inode_cache_miss");
807 na_child_add(cw->query, e);
810 } /* }}} int cna_setup_wafl */
812 static int cna_query_wafl (host_config_t *host) /* {{{ */
821 /* If WAFL was not configured, return without doing anything. */
822 if (host->cfg_wafl == NULL)
826 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
829 status = cna_setup_wafl (host->cfg_wafl);
832 assert (host->cfg_wafl->query != NULL);
834 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
835 if (na_results_status (data) != NA_OK)
837 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed: %s",
838 na_results_reason (data));
843 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data);
846 host->cfg_wafl->interval.last_read = now;
850 } /* }}} int cna_query_wafl */
852 /* Data corresponding to <Disks /> */
853 static int cna_handle_disk_data (const char *hostname, /* {{{ */
854 cfg_disk_t *cfg_disk, na_elem_t *data)
857 na_elem_t *instances;
859 na_elem_iter_t instance_iter;
860 disk_t *worst_disk = NULL;
862 if ((cfg_disk == NULL) || (data == NULL))
865 timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
867 instances = na_elem_child (data, "instances");
868 if (instances == NULL)
870 ERROR ("netapp plugin: cna_handle_disk_data: "
871 "na_elem_child (\"instances\") failed.");
875 /* Iterate over all children */
876 instance_iter = na_child_iterator (instances);
877 for (instance = na_iterator_next (&instance_iter);
879 instance = na_iterator_next(&instance_iter))
884 na_elem_iter_t counter_iterator;
887 memset (&new_data, 0, sizeof (new_data));
888 new_data.timestamp = timestamp;
889 new_data.disk_busy_percent = NAN;
891 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
892 if (old_data == NULL)
895 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
896 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
897 for (counter = na_iterator_next(&counter_iterator);
899 counter = na_iterator_next(&counter_iterator))
904 name = na_child_get_string(counter, "name");
908 value = na_child_get_uint64(counter, "value", UINT64_MAX);
909 if (value == UINT64_MAX)
912 if (strcmp(name, "disk_busy") == 0)
914 new_data.disk_busy = value;
915 new_data.flags |= HAVE_DISK_BUSY;
917 else if (strcmp(name, "base_for_disk_busy") == 0)
919 new_data.base_for_disk_busy = value;
920 new_data.flags |= HAVE_DISK_BASE;
924 DEBUG ("netapp plugin: cna_handle_disk_data: "
925 "Counter not handled: %s = %"PRIu64,
930 /* If all required counters are available and did not just wrap around,
931 * calculate the busy percentage. Otherwise, the value is initialized to
932 * NAN at the top of the for-loop. */
933 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
934 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
935 && (new_data.disk_busy >= old_data->disk_busy)
936 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
941 busy_diff = new_data.disk_busy - old_data->disk_busy;
942 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
944 new_data.disk_busy_percent = 100.0
945 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
948 /* Clear HAVE_* flags */
949 old_data->flags &= ~HAVE_DISK_ALL;
952 old_data->timestamp = new_data.timestamp;
953 old_data->disk_busy = new_data.disk_busy;
954 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
955 old_data->disk_busy_percent = new_data.disk_busy_percent;
958 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
960 if ((worst_disk == NULL)
961 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
962 worst_disk = old_data;
963 } /* for (all disks) */
965 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
966 submit_double (hostname, "system", "percent", "disk_busy",
967 worst_disk->disk_busy_percent, timestamp);
970 } /* }}} int cna_handle_disk_data */
972 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
979 if (cd->query != NULL)
982 cd->query = na_elem_new ("perf-object-get-instances");
983 if (cd->query == NULL)
985 ERROR ("netapp plugin: na_elem_new failed.");
988 na_child_add_string (cd->query, "objectname", "disk");
990 e = na_elem_new("counters");
993 na_elem_free (cd->query);
995 ERROR ("netapp plugin: na_elem_new failed.");
998 na_child_add_string(e, "foo", "disk_busy");
999 na_child_add_string(e, "foo", "base_for_disk_busy");
1000 na_child_add(cd->query, e);
1003 } /* }}} int cna_setup_disk */
1005 static int cna_query_disk (host_config_t *host) /* {{{ */
1014 /* If the user did not configure disk statistics, return without doing
1016 if (host->cfg_disk == NULL)
1020 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1023 status = cna_setup_disk (host->cfg_disk);
1026 assert (host->cfg_disk->query != NULL);
1028 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1029 if (na_results_status (data) != NA_OK)
1031 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed: %s",
1032 na_results_reason (data));
1033 na_elem_free (data);
1037 status = cna_handle_disk_data (host->name, host->cfg_disk, data);
1040 host->cfg_disk->interval.last_read = now;
1042 na_elem_free (data);
1044 } /* }}} int cna_query_disk */
1046 /* Data corresponding to <GetVolumeData /> */
1047 static void collect_volume_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
1050 cfg_volume_usage_t *cfg_volume_data = data;
1052 out = na_elem_child(out, "volumes");
1053 na_elem_iter_t inst_iter = na_child_iterator(out);
1054 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
1055 uint64_t size_free = 0, size_used = 0, snap_reserved = 0;
1058 const char *sis_state;
1059 uint64_t sis_saved_reported;
1062 volume = get_volume(host, na_child_get_string(inst, "name"),
1063 cfg_volume_data->flags, /* perf_flags = */ 0);
1067 if (!(volume->cfg_volume_usage.flags & CFG_VOLUME_USAGE_DF))
1070 /* 2^4 exa-bytes? This will take a while ;) */
1071 size_free = na_child_get_uint64(inst, "size-available", UINT64_MAX);
1072 if (size_free != UINT64_MAX)
1073 submit_double (host->name, volume->name, "df_complex", "free",
1074 (double) size_free, /* time = */ 0);
1076 size_used = na_child_get_uint64(inst, "size-used", UINT64_MAX);
1077 if (size_used != UINT64_MAX) {
1078 if ((volume->cfg_volume_usage.flags & HAVE_VOLUME_USAGE_SNAP)
1079 && (size_used >= volume->cfg_volume_usage.snap_used))
1080 size_used -= volume->cfg_volume_usage.snap_used;
1081 submit_double (host->name, volume->name, "df_complex", "used",
1082 (double) size_used, /* time = */ 0);
1085 snap_reserved = na_child_get_uint64(inst, "snapshot-blocks-reserved", UINT64_MAX);
1086 if (!(volume->cfg_volume_usage.flags & HAVE_VOLUME_USAGE_SNAP) && (snap_reserved != UINT64_MAX))
1087 /* If we have snap usage data this value has already been submitted. */
1088 /* 1 block == 1024 bytes as per API docs */
1089 submit_double (host->name, volume->name, "df_complex", "snap_reserved",
1090 (double) (1024 * snap_reserved), /* time = */ 0);
1092 sis = na_elem_child(inst, "sis");
1096 sis_state = na_child_get_string(sis, "state");
1097 if ((sis_state == NULL)
1098 || (strcmp ("enabled", sis_state) != 0))
1101 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1102 if (sis_saved_reported == UINT64_MAX)
1105 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1106 if ((sis_saved_reported >> 32) != 0) {
1107 /* In case they ever fix this bug. */
1108 sis_saved = sis_saved_reported;
1110 uint64_t sis_saved_percent;
1111 uint64_t sis_saved_guess;
1112 uint64_t overflow_guess;
1113 uint64_t guess1, guess2, guess3;
1115 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1116 if (sis_saved_percent > 100)
1119 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1120 * will hopefully be fixed in later versions. To work around the bug, try
1121 * to figure out how often the 32bit integer wrapped around by using the
1122 * "percentage-saved" value. Because the percentage is in the range
1123 * [0-100], this should work as long as the saved space does not exceed
1125 /* percentage-saved = size-saved / (size-saved + size-used) */
1126 if (sis_saved_percent < 100)
1127 sis_saved_guess = size_used * sis_saved_percent / (100 - sis_saved_percent);
1129 sis_saved_guess = size_used;
1131 overflow_guess = sis_saved_guess >> 32;
1132 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1133 guess2 = (overflow_guess << 32) + sis_saved_reported;
1134 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1136 if (sis_saved_guess < guess2) {
1137 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1142 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1147 } /* end of 32-bit workaround */
1149 submit_double (host->name, volume->name, "df_complex", "sis_saved",
1150 (double) sis_saved, /* time = */ 0);
1152 } /* }}} void collect_volume_data */
1154 /* Data corresponding to <GetVolumePerfData /> */
1155 static void query_volume_perf_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
1156 cfg_volume_perf_t *cfg_volume_perf = data;
1158 na_elem_t *counter, *inst;
1160 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
1162 out = na_elem_child(out, "instances");
1163 na_elem_iter_t inst_iter = na_child_iterator(out);
1164 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
1165 data_volume_perf_t perf_data;
1168 memset (&perf_data, 0, sizeof (perf_data));
1169 perf_data.timestamp = timestamp;
1171 volume = get_volume(host, na_child_get_string(inst, "name"),
1172 /* data_flags = */ 0, cfg_volume_perf->flags);
1176 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
1177 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
1181 name = na_child_get_string(counter, "name");
1185 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1186 if (value == UINT64_MAX)
1189 if (!strcmp(name, "read_data")) {
1190 perf_data.read_bytes = value;
1191 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1192 } else if (!strcmp(name, "write_data")) {
1193 perf_data.write_bytes = value;
1194 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1195 } else if (!strcmp(name, "read_ops")) {
1196 perf_data.read_ops = value;
1197 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1198 } else if (!strcmp(name, "write_ops")) {
1199 perf_data.write_ops = value;
1200 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1201 } else if (!strcmp(name, "read_latency")) {
1202 perf_data.read_latency = value;
1203 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1204 } else if (!strcmp(name, "write_latency")) {
1205 perf_data.write_latency = value;
1206 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1210 submit_volume_perf_data (host, volume, &perf_data);
1211 } /* for (volume) */
1212 } /* }}} void query_volume_perf_data */
1214 /* Data corresponding to <System /> */
1215 static int cna_handle_system_data (const char *hostname, /* {{{ */
1216 cfg_system_t *cfg_system, na_elem_t *data)
1218 na_elem_t *instances;
1220 na_elem_iter_t counter_iter;
1222 counter_t disk_read = 0, disk_written = 0;
1223 counter_t net_recv = 0, net_sent = 0;
1224 counter_t cpu_busy = 0, cpu_total = 0;
1225 uint32_t counter_flags = 0;
1227 const char *instance;
1230 timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
1232 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1233 if (instances == NULL)
1235 ERROR ("netapp plugin: cna_handle_system_data: "
1236 "na_elem_child (\"instances\") failed.");
1240 instance = na_child_get_string (instances, "name");
1241 if (instance == NULL)
1243 ERROR ("netapp plugin: cna_handle_system_data: "
1244 "na_child_get_string (\"name\") failed.");
1248 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
1249 for (counter = na_iterator_next (&counter_iter);
1251 counter = na_iterator_next (&counter_iter))
1256 name = na_child_get_string(counter, "name");
1260 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1261 if (value == UINT64_MAX)
1264 if (!strcmp(name, "disk_data_read")) {
1265 disk_read = (counter_t) (value * 1024);
1266 counter_flags |= 0x01;
1267 } else if (!strcmp(name, "disk_data_written")) {
1268 disk_written = (counter_t) (value * 1024);
1269 counter_flags |= 0x02;
1270 } else if (!strcmp(name, "net_data_recv")) {
1271 net_recv = (counter_t) (value * 1024);
1272 counter_flags |= 0x04;
1273 } else if (!strcmp(name, "net_data_sent")) {
1274 net_sent = (counter_t) (value * 1024);
1275 counter_flags |= 0x08;
1276 } else if (!strcmp(name, "cpu_busy")) {
1277 cpu_busy = (counter_t) value;
1278 counter_flags |= 0x10;
1279 } else if (!strcmp(name, "cpu_elapsed_time")) {
1280 cpu_total = (counter_t) value;
1281 counter_flags |= 0x20;
1282 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1283 && (value > 0) && (strlen(name) > 4)
1284 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1285 submit_counter (hostname, instance, "disk_ops_complex", name,
1286 (counter_t) value, timestamp);
1288 } /* for (counter) */
1290 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1291 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
1292 submit_two_counters (hostname, instance, "disk_octets", NULL,
1293 disk_read, disk_written, timestamp);
1295 if ((cfg_system->flags & CFG_SYSTEM_NET)
1296 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
1297 submit_two_counters (hostname, instance, "if_octets", NULL,
1298 net_recv, net_sent, timestamp);
1300 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1301 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
1303 submit_counter (hostname, instance, "cpu", "system",
1304 cpu_busy, timestamp);
1305 submit_counter (hostname, instance, "cpu", "idle",
1306 cpu_total - cpu_busy, timestamp);
1310 } /* }}} int cna_handle_system_data */
1312 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
1317 if (cs->query != NULL)
1320 cs->query = na_elem_new ("perf-object-get-instances");
1321 if (cs->query == NULL)
1323 ERROR ("netapp plugin: na_elem_new failed.");
1326 na_child_add_string (cs->query, "objectname", "system");
1329 } /* }}} int cna_setup_system */
1331 static int cna_query_system (host_config_t *host) /* {{{ */
1340 /* If system statistics were not configured, return without doing anything. */
1341 if (host->cfg_system == NULL)
1345 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
1348 status = cna_setup_system (host->cfg_system);
1351 assert (host->cfg_system->query != NULL);
1353 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
1354 if (na_results_status (data) != NA_OK)
1356 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed: %s",
1357 na_results_reason (data));
1358 na_elem_free (data);
1362 status = cna_handle_system_data (host->name, host->cfg_system, data);
1365 host->cfg_system->interval.last_read = now;
1367 na_elem_free (data);
1369 } /* }}} int cna_query_system */
1372 * Configuration handling
1374 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1375 * is false. On error, the flag-field is not changed. */
1376 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1377 uint32_t *flags, uint32_t flag)
1379 if ((ci == NULL) || (flags == NULL))
1382 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1384 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1389 if (ci->values[0].value.boolean)
1395 } /* }}} int cna_config_bool_to_flag */
1397 /* Handling of the "Multiplier" option which is allowed in every block. */
1398 static int cna_config_get_multiplier (const oconfig_item_t *ci, /* {{{ */
1399 cfg_service_t *service)
1403 if ((ci == NULL) || (service == NULL))
1406 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1408 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1412 tmp = (int) (ci->values[0].value.number + .5);
1415 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1419 service->multiplier = tmp;
1420 service->skip_countdown = tmp;
1423 } /* }}} int cna_config_get_multiplier */
1425 /* Handling of the "Interval" option which is allowed in every block. */
1426 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1427 cna_interval_t *out_interval)
1431 if ((ci == NULL) || (out_interval == NULL))
1434 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
1436 WARNING ("netapp plugin: The `Multiplier' option needs exactly one numeric argument.");
1440 tmp = (time_t) (ci->values[0].value.number + .5);
1443 WARNING ("netapp plugin: The `Multiplier' option needs a positive integer argument.");
1447 out_interval->interval = tmp;
1448 out_interval->last_read = 0;
1451 } /* }}} int cna_config_get_interval */
1453 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1454 * <GetVolumePerfData /> block. */
1455 static void cna_config_volume_performance_option (host_config_t *host, /* {{{ */
1456 cfg_volume_perf_t *perf_volume, const oconfig_item_t *item,
1461 for (i = 0; i < item->values_num; ++i) {
1466 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1467 WARNING("netapp plugin: Ignoring non-string argument in "
1468 "\"GetVolumePerfData\" block for host %s", host->name);
1472 name = item->values[i].value.string;
1473 if (name[0] == '+') {
1476 } else if (name[0] == '-') {
1483 perf_volume->flags |= flag;
1484 else /* if (!set) */
1485 perf_volume->flags &= ~flag;
1487 host_set_all_perf_data_flags(host, flag, set);
1491 v = get_volume (host, name, /* data_flags = */ 0, perf_volume->flags);
1496 v->perf_data.flags |= flag;
1497 else /* if (!set) */
1498 v->perf_data.flags &= ~flag;
1499 } /* for (i = 0 .. item->values_num) */
1500 } /* }}} void cna_config_volume_performance_option */
1502 /* Corresponds to a <GetVolumePerfData /> block */
1503 static void cna_config_volume_performance(host_config_t *host, const oconfig_item_t *ci) { /* {{{ */
1504 int i, had_io = 0, had_ops = 0, had_latency = 0;
1505 cfg_service_t *service;
1506 cfg_volume_perf_t *perf_volume;
1508 service = malloc(sizeof(*service));
1510 service->handler = query_volume_perf_data;
1511 perf_volume = service->data = malloc(sizeof(*perf_volume));
1512 perf_volume->flags = CFG_VOLUME_PERF_INIT;
1513 service->next = host->services;
1514 host->services = service;
1515 for (i = 0; i < ci->children_num; ++i) {
1516 oconfig_item_t *item = ci->children + i;
1518 /* if (!item || !item->key || !*item->key) continue; */
1519 if (!strcasecmp(item->key, "Multiplier")) {
1520 cna_config_get_multiplier (item, service);
1521 } else if (!strcasecmp(item->key, "GetIO")) {
1523 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_IO);
1524 } else if (!strcasecmp(item->key, "GetOps")) {
1526 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_OPS);
1527 } else if (!strcasecmp(item->key, "GetLatency")) {
1529 cna_config_volume_performance_option(host, perf_volume, item, CFG_VOLUME_PERF_LATENCY);
1533 perf_volume->flags |= CFG_VOLUME_PERF_IO;
1534 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_IO, /* set = */ true);
1537 perf_volume->flags |= CFG_VOLUME_PERF_OPS;
1538 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_OPS, /* set = */ true);
1541 perf_volume->flags |= CFG_VOLUME_PERF_LATENCY;
1542 host_set_all_perf_data_flags(host, CFG_VOLUME_PERF_LATENCY, /* set = */ true);
1544 } /* }}} void cna_config_volume_performance */
1546 /* Handling of the "GetDiskUtil" option within a <GetVolumeData /> block. */
1547 static void cna_config_volume_usage_option (host_config_t *host, /* {{{ */
1548 cfg_volume_usage_t *cfg_volume_data, const oconfig_item_t *item, uint32_t flag)
1552 for (i = 0; i < item->values_num; ++i) {
1557 if (item->values[i].type != OCONFIG_TYPE_STRING) {
1558 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolData\""
1559 "block for host %s", host->name);
1563 name = item->values[i].value.string;
1564 if (name[0] == '+') {
1567 } else if (name[0] == '-') {
1574 cfg_volume_data->flags |= flag;
1575 else /* if (!set) */
1576 cfg_volume_data->flags &= ~flag;
1578 host_set_all_cfg_volume_usage_flags(host, flag, set);
1582 v = get_volume(host, name, cfg_volume_data->flags, /* perf_flags = */ 0);
1586 if (!v->cfg_volume_usage.flags)
1587 v->cfg_volume_usage.flags = cfg_volume_data->flags;
1590 v->cfg_volume_usage.flags |= flag;
1591 else /* if (!set) */
1592 v->cfg_volume_usage.flags &= ~flag;
1594 } /* }}} void cna_config_volume_usage_option */
1596 /* Corresponds to a <GetVolumeData /> block */
1597 static void cna_config_volume_usage(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1599 cfg_service_t *service;
1600 cfg_volume_usage_t *cfg_volume_data;
1602 service = malloc(sizeof(*service));
1604 service->handler = collect_volume_data;
1605 cfg_volume_data = service->data = malloc(sizeof(*cfg_volume_data));
1606 cfg_volume_data->flags = CFG_VOLUME_USAGE_INIT;
1607 service->next = host->services;
1608 host->services = service;
1609 for (i = 0; i < ci->children_num; ++i) {
1610 oconfig_item_t *item = ci->children + i;
1612 /* if (!item || !item->key || !*item->key) continue; */
1613 if (!strcasecmp(item->key, "Multiplier")) {
1614 cna_config_get_multiplier (item, service);
1615 } else if (!strcasecmp(item->key, "GetDiskUtil")) {
1617 cna_config_volume_usage_option(host, cfg_volume_data, item, CFG_VOLUME_USAGE_DF);
1618 } else if (!strcasecmp(item->key, "GetSnapUtil")) {
1620 cna_config_volume_usage_option(host, cfg_volume_data, item, CFG_VOLUME_USAGE_SNAP);
1624 cfg_volume_data->flags |= CFG_VOLUME_USAGE_DF;
1625 host_set_all_cfg_volume_usage_flags(host, CFG_VOLUME_USAGE_DF, /* set = */ true);
1627 if (cfg_volume_data->flags & CFG_VOLUME_USAGE_SNAP) {
1628 WARNING("netapp plugin: The \"GetSnapUtil\" option does not support the \"+\" wildcard.");
1630 } /* }}} void cna_config_volume_usage */
1632 /* Corresponds to a <Disks /> block */
1633 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
1634 cfg_disk_t *cfg_disk;
1637 if ((host == NULL) || (ci == NULL))
1640 if (host->cfg_disk == NULL)
1642 cfg_disk = malloc (sizeof (*cfg_disk));
1643 if (cfg_disk == NULL)
1645 memset (cfg_disk, 0, sizeof (*cfg_disk));
1647 /* Set default flags */
1648 cfg_disk->flags = CFG_DISK_ALL;
1649 cfg_disk->query = NULL;
1650 cfg_disk->disks = NULL;
1652 host->cfg_disk = cfg_disk;
1654 cfg_disk = host->cfg_disk;
1656 for (i = 0; i < ci->children_num; ++i) {
1657 oconfig_item_t *item = ci->children + i;
1659 /* if (!item || !item->key || !*item->key) continue; */
1660 if (strcasecmp(item->key, "Interval") == 0)
1661 cna_config_get_interval (item, &cfg_disk->interval);
1662 else if (strcasecmp(item->key, "GetBusy") == 0)
1663 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
1667 } /* }}} int cna_config_disk */
1669 /* Corresponds to a <WAFL /> block */
1670 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
1672 cfg_wafl_t *cfg_wafl;
1675 if ((host == NULL) || (ci == NULL))
1678 if (host->cfg_wafl == NULL)
1680 cfg_wafl = malloc (sizeof (*cfg_wafl));
1681 if (cfg_wafl == NULL)
1683 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
1685 /* Set default flags */
1686 cfg_wafl->flags = CFG_WAFL_ALL;
1688 host->cfg_wafl = cfg_wafl;
1690 cfg_wafl = host->cfg_wafl;
1692 for (i = 0; i < ci->children_num; ++i) {
1693 oconfig_item_t *item = ci->children + i;
1695 if (strcasecmp(item->key, "Interval") == 0)
1696 cna_config_get_interval (item, &cfg_wafl->interval);
1697 else if (!strcasecmp(item->key, "GetNameCache"))
1698 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
1699 else if (!strcasecmp(item->key, "GetDirCache"))
1700 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
1701 else if (!strcasecmp(item->key, "GetBufferCache"))
1702 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
1703 else if (!strcasecmp(item->key, "GetInodeCache"))
1704 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
1706 WARNING ("netapp plugin: The %s config option is not allowed within "
1707 "`WAFL' blocks.", item->key);
1710 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
1712 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
1713 "Collection of WAFL data will be disabled entirely.");
1714 free_cfg_wafl (host->cfg_wafl);
1715 host->cfg_wafl = NULL;
1719 } /* }}} int cna_config_wafl */
1721 /* Corresponds to a <System /> block */
1722 static int cna_config_system (host_config_t *host, /* {{{ */
1723 oconfig_item_t *ci, const cfg_service_t *default_service)
1725 cfg_system_t *cfg_system;
1728 if ((host == NULL) || (ci == NULL))
1731 if (host->cfg_system == NULL)
1733 cfg_system = malloc (sizeof (*cfg_system));
1734 if (cfg_system == NULL)
1736 memset (cfg_system, 0, sizeof (*cfg_system));
1738 /* Set default flags */
1739 cfg_system->flags = CFG_SYSTEM_ALL;
1740 cfg_system->query = NULL;
1742 host->cfg_system = cfg_system;
1744 cfg_system = host->cfg_system;
1746 for (i = 0; i < ci->children_num; ++i) {
1747 oconfig_item_t *item = ci->children + i;
1749 if (strcasecmp(item->key, "Interval") == 0) {
1750 cna_config_get_interval (item, &cfg_system->interval);
1751 } else if (!strcasecmp(item->key, "GetCPULoad")) {
1752 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
1753 } else if (!strcasecmp(item->key, "GetInterfaces")) {
1754 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
1755 } else if (!strcasecmp(item->key, "GetDiskOps")) {
1756 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
1757 } else if (!strcasecmp(item->key, "GetDiskIO")) {
1758 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
1760 WARNING ("netapp plugin: The %s config option is not allowed within "
1761 "`System' blocks.", item->key);
1766 } /* }}} int cna_config_system */
1768 /* Corresponds to a <Host /> block. */
1769 static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
1770 const host_config_t *default_host, const cfg_service_t *def_def_service)
1772 oconfig_item_t *item;
1773 host_config_t *host;
1774 cfg_service_t default_service = *def_def_service;
1778 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1779 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
1783 host = malloc(sizeof(*host));
1784 memcpy (host, default_host, sizeof (*host));
1786 status = cf_util_get_string (ci, &host->name);
1793 for (i = 0; i < ci->children_num; ++i) {
1794 item = ci->children + i;
1798 if (!strcasecmp(item->key, "Address")) {
1799 status = cf_util_get_string (item, &host->host);
1800 } else if (!strcasecmp(item->key, "Port")) {
1803 tmp = cf_util_get_port_number (item);
1806 } else if (!strcasecmp(item->key, "Protocol")) {
1807 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"))) {
1808 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
1811 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
1812 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
1813 } else if (!strcasecmp(item->key, "User")) {
1814 status = cf_util_get_string (item, &host->username);
1815 } else if (!strcasecmp(item->key, "Password")) {
1816 status = cf_util_get_string (item, &host->password);
1817 } else if (!strcasecmp(item->key, "Interval")) {
1818 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) {
1819 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
1822 host->interval = item->values[0].value.number;
1823 } else if (!strcasecmp(item->key, "GetVolumePerfData")) {
1824 cna_config_volume_performance(host, item);
1825 } else if (!strcasecmp(item->key, "System")) {
1826 cna_config_system(host, item, &default_service);
1827 } else if (!strcasecmp(item->key, "WAFL")) {
1828 cna_config_wafl(host, item);
1829 } else if (!strcasecmp(item->key, "Disks")) {
1830 cna_config_disk(host, item);
1831 } else if (!strcasecmp(item->key, "GetVolumeData")) {
1832 cna_config_volume_usage(host, item);
1834 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
1835 item->key, ci->values[0].value.string);
1842 if (host->host == NULL)
1843 host->host = strdup (host->name);
1845 if (host->host == NULL)
1848 if (host->port <= 0)
1849 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
1851 if ((host->username == NULL) || (host->password == NULL)) {
1852 WARNING("netapp plugin: Please supply login information for host \"%s\". "
1853 "Ignoring host block.", host->name);
1859 free_host_config (host);
1864 } /* }}} host_config_t *cna_config_host */
1867 * Callbacks registered with the daemon
1869 * Pretty standard stuff here.
1871 static int cna_init(void) { /* {{{ */
1874 host_config_t *host;
1875 cfg_service_t *service;
1877 if (!global_host_config) {
1878 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
1882 memset (err, 0, sizeof (err));
1883 if (!na_startup(err, sizeof(err))) {
1884 err[sizeof (err) - 1] = 0;
1885 ERROR("netapp plugin: Error initializing netapp API: %s", err);
1889 for (host = global_host_config; host; host = host->next) {
1890 /* Request version 1.1 of the ONTAP API */
1891 host->srv = na_server_open(host->host,
1892 /* major version = */ 1, /* minor version = */ 1);
1893 if (host->srv == NULL) {
1894 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
1898 if (host->interval < interval_g)
1899 host->interval = interval_g;
1901 na_server_set_transport_type(host->srv, host->protocol,
1902 /* transportarg = */ NULL);
1903 na_server_set_port(host->srv, host->port);
1904 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
1905 na_server_adminuser(host->srv, host->username, host->password);
1906 na_server_set_timeout(host->srv, 5 /* seconds */);
1908 for (service = host->services; service; service = service->next) {
1909 service->interval = host->interval * service->multiplier;
1911 if (service->handler == query_volume_perf_data) {
1912 service->query = na_elem_new("perf-object-get-instances");
1913 na_child_add_string(service->query, "objectname", "volume");
1914 e = na_elem_new("counters");
1915 /* "foo" means: This string has to be here but
1916 the content doesn't matter. */
1917 na_child_add_string(e, "foo", "read_ops");
1918 na_child_add_string(e, "foo", "write_ops");
1919 na_child_add_string(e, "foo", "read_data");
1920 na_child_add_string(e, "foo", "write_data");
1921 na_child_add_string(e, "foo", "read_latency");
1922 na_child_add_string(e, "foo", "write_latency");
1923 na_child_add(service->query, e);
1924 } else if (service->handler == collect_volume_data) {
1925 service->query = na_elem_new("volume-list-info");
1926 /* na_child_add_string(service->query, "objectname", "volume"); */
1927 /* } else if (service->handler == collect_snapshot_data) { */
1928 /* service->query = na_elem_new("snapshot-list-info"); */
1930 } /* for (host->services) */
1933 } /* }}} int cna_init */
1935 static int cna_config (oconfig_item_t *ci) { /* {{{ */
1937 oconfig_item_t *item;
1938 host_config_t default_host = HOST_INIT;
1939 cfg_service_t default_service = SERVICE_INIT;
1941 for (i = 0; i < ci->children_num; ++i) {
1942 item = ci->children + i;
1944 if (!strcasecmp(item->key, "Host")) {
1945 host_config_t *host;
1948 host = cna_config_host(item, &default_host, &default_service);
1952 for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
1954 if (strcasecmp (host->name, tmp->name) == 0)
1955 WARNING ("netapp plugin: Duplicate definition of host `%s'. "
1956 "This is probably a bad idea.",
1959 if (tmp->next == NULL)
1965 global_host_config = host;
1969 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
1973 } /* }}} int cna_config */
1975 static int cna_read(void) { /* {{{ */
1977 host_config_t *host;
1978 cfg_service_t *service;
1980 for (host = global_host_config; host; host = host->next) {
1981 for (service = host->services; service; service = service->next) {
1982 if (--service->skip_countdown > 0) continue;
1983 service->skip_countdown = service->multiplier;
1984 out = na_server_invoke_elem(host->srv, service->query);
1985 if (na_results_status(out) != NA_OK) {
1986 int netapp_errno = na_results_errno(out);
1987 ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
1989 if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
1990 /* Network problems. Just give up on all other services on this host. */
1995 service->handler(host, out, service->data);
1997 } /* for (host->services) */
1999 cna_query_wafl (host);
2000 cna_query_disk (host);
2001 cna_query_system (host);
2004 } /* }}} int cna_read */
2006 void module_register(void) {
2007 plugin_register_complex_config("netapp", cna_config);
2008 plugin_register_init("netapp", cna_init);
2009 plugin_register_read("netapp", cna_read);
2012 /* vim: set sw=2 ts=2 noet fdm=marker : */