1 /**
2 * collectd - src/netapp.c
3 * Copyright (C) 2009,2010 Sven Trenkel
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
22 *
23 * Authors:
24 * Sven Trenkel <collectd at semidefinite.de>
25 **/
27 #include "collectd.h"
28 #include "common.h"
29 #include "utils_ignorelist.h"
31 #include <netapp_api.h>
32 #include <netapp_errno.h>
34 #define HAS_ALL_FLAGS(has,needs) (((has) & (needs)) == (needs))
36 typedef struct host_config_s host_config_t;
37 typedef void service_handler_t(host_config_t *host, na_elem_t *result, void *data);
39 struct cna_interval_s
40 {
41 cdtime_t interval;
42 cdtime_t last_read;
43 };
44 typedef struct cna_interval_s cna_interval_t;
46 /*! Data types for WAFL statistics {{{
47 *
48 * \brief Persistent data for WAFL performance counters. (a.k.a. cache performance)
49 *
50 * The cache counters use old counter values to calculate a hit ratio for each
51 * counter. The "cfg_wafl_t" struct therefore contains old counter values along
52 * with flags, which are set if the counter is valid.
53 *
54 * The function "cna_handle_wafl_data" will fill a new structure of this kind
55 * with new values, then pass both, new and old data, to "submit_wafl_data".
56 * That function calculates the hit ratios, submits the calculated values and
57 * updates the old counter values for the next iteration.
58 */
59 #define CFG_WAFL_NAME_CACHE 0x0001
60 #define CFG_WAFL_DIR_CACHE 0x0002
61 #define CFG_WAFL_BUF_CACHE 0x0004
62 #define CFG_WAFL_INODE_CACHE 0x0008
63 #define CFG_WAFL_ALL 0x000F
64 #define HAVE_WAFL_NAME_CACHE_HIT 0x0100
65 #define HAVE_WAFL_NAME_CACHE_MISS 0x0200
66 #define HAVE_WAFL_NAME_CACHE (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
67 #define HAVE_WAFL_FIND_DIR_HIT 0x0400
68 #define HAVE_WAFL_FIND_DIR_MISS 0x0800
69 #define HAVE_WAFL_FIND_DIR (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
70 #define HAVE_WAFL_BUF_HASH_HIT 0x1000
71 #define HAVE_WAFL_BUF_HASH_MISS 0x2000
72 #define HAVE_WAFL_BUF_HASH (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
73 #define HAVE_WAFL_INODE_CACHE_HIT 0x4000
74 #define HAVE_WAFL_INODE_CACHE_MISS 0x8000
75 #define HAVE_WAFL_INODE_CACHE (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
76 #define HAVE_WAFL_ALL 0xff00
77 typedef struct {
78 uint32_t flags;
79 cna_interval_t interval;
80 na_elem_t *query;
82 cdtime_t timestamp;
83 uint64_t name_cache_hit;
84 uint64_t name_cache_miss;
85 uint64_t find_dir_hit;
86 uint64_t find_dir_miss;
87 uint64_t buf_hash_hit;
88 uint64_t buf_hash_miss;
89 uint64_t inode_cache_hit;
90 uint64_t inode_cache_miss;
91 } cfg_wafl_t;
92 /* }}} cfg_wafl_t */
94 /*! Data types for disk statistics {{{
95 *
96 * \brief A disk in the NetApp.
97 *
98 * A disk doesn't have any more information than its name at the moment.
99 * The name includes the "disk_" prefix.
100 */
101 #define HAVE_DISK_BUSY 0x10
102 #define HAVE_DISK_BASE 0x20
103 #define HAVE_DISK_ALL 0x30
104 typedef struct disk_s {
105 char *name;
106 uint32_t flags;
107 cdtime_t timestamp;
108 uint64_t disk_busy;
109 uint64_t base_for_disk_busy;
110 double disk_busy_percent;
111 struct disk_s *next;
112 } disk_t;
114 #define CFG_DISK_BUSIEST 0x01
115 #define CFG_DISK_ALL 0x01
116 typedef struct {
117 uint32_t flags;
118 cna_interval_t interval;
119 na_elem_t *query;
120 disk_t *disks;
121 } cfg_disk_t;
122 /* }}} cfg_disk_t */
124 /*! Data types for volume performance statistics {{{
125 *
126 * \brief Persistent data for volume performance data.
127 *
128 * The code below uses the difference of the operations and latency counters to
129 * calculate an average per-operation latency. For this, old counters need to
130 * be stored in the "data_volume_perf_t" structure. The byte-counters are just
131 * kept for completeness sake. The "flags" member indicates if each counter is
132 * valid or not.
133 *
134 * The "cna_handle_volume_perf_data" function will fill a new struct of this
135 * type and pass both, old and new data, to "submit_volume_perf_data". In that
136 * function, the per-operation latency is calculated and dispatched, then the
137 * old counters are updated.
138 */
139 #define CFG_VOLUME_PERF_INIT 0x0001
140 #define CFG_VOLUME_PERF_IO 0x0002
141 #define CFG_VOLUME_PERF_OPS 0x0003
142 #define CFG_VOLUME_PERF_LATENCY 0x0008
143 #define CFG_VOLUME_PERF_ALL 0x000F
144 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
145 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
146 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
147 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
148 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
149 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
150 #define HAVE_VOLUME_PERF_ALL 0x03F0
151 struct data_volume_perf_s;
152 typedef struct data_volume_perf_s data_volume_perf_t;
153 struct data_volume_perf_s {
154 char *name;
155 uint32_t flags;
156 cdtime_t timestamp;
158 uint64_t read_bytes;
159 uint64_t write_bytes;
160 uint64_t read_ops;
161 uint64_t write_ops;
162 uint64_t read_latency;
163 uint64_t write_latency;
165 data_volume_perf_t *next;
166 };
168 typedef struct {
169 cna_interval_t interval;
170 na_elem_t *query;
172 ignorelist_t *il_octets;
173 ignorelist_t *il_operations;
174 ignorelist_t *il_latency;
176 data_volume_perf_t *volumes;
177 } cfg_volume_perf_t;
178 /* }}} data_volume_perf_t */
180 /*! Data types for volume usage statistics {{{
181 *
182 * \brief Configuration struct for volume usage data (free / used).
183 */
184 #define CFG_VOLUME_USAGE_DF 0x0002
185 #define CFG_VOLUME_USAGE_SNAP 0x0004
186 #define CFG_VOLUME_USAGE_ALL 0x0006
187 #define HAVE_VOLUME_USAGE_NORM_FREE 0x0010
188 #define HAVE_VOLUME_USAGE_NORM_USED 0x0020
189 #define HAVE_VOLUME_USAGE_SNAP_RSVD 0x0040
190 #define HAVE_VOLUME_USAGE_SNAP_USED 0x0080
191 #define HAVE_VOLUME_USAGE_SIS_SAVED 0x0100
192 #define HAVE_VOLUME_USAGE_ALL 0x01f0
193 #define IS_VOLUME_USAGE_OFFLINE 0x0200
194 struct data_volume_usage_s;
195 typedef struct data_volume_usage_s data_volume_usage_t;
196 struct data_volume_usage_s {
197 char *name;
198 uint32_t flags;
200 na_elem_t *snap_query;
202 uint64_t norm_free;
203 uint64_t norm_used;
204 uint64_t snap_reserved;
205 uint64_t snap_used;
206 uint64_t sis_saved;
208 data_volume_usage_t *next;
209 };
211 typedef struct {
212 cna_interval_t interval;
213 na_elem_t *query;
215 ignorelist_t *il_capacity;
216 ignorelist_t *il_snapshot;
218 data_volume_usage_t *volumes;
219 } cfg_volume_usage_t;
220 /* }}} cfg_volume_usage_t */
222 /*! Data types for system statistics {{{
223 *
224 * \brief Persistent data for system performance counters
225 */
226 #define CFG_SYSTEM_CPU 0x01
227 #define CFG_SYSTEM_NET 0x02
228 #define CFG_SYSTEM_OPS 0x04
229 #define CFG_SYSTEM_DISK 0x08
230 #define CFG_SYSTEM_ALL 0x0F
231 typedef struct {
232 uint32_t flags;
233 cna_interval_t interval;
234 na_elem_t *query;
235 } cfg_system_t;
236 /* }}} cfg_system_t */
238 struct host_config_s {
239 char *name;
240 na_server_transport_t protocol;
241 char *host;
242 int port;
243 char *username;
244 char *password;
245 cdtime_t interval;
247 na_server_t *srv;
248 cfg_wafl_t *cfg_wafl;
249 cfg_disk_t *cfg_disk;
250 cfg_volume_perf_t *cfg_volume_perf;
251 cfg_volume_usage_t *cfg_volume_usage;
252 cfg_system_t *cfg_system;
254 struct host_config_s *next;
255 };
257 /*
258 * Free functions
259 *
260 * Used to free the various structures above.
261 */
262 static void free_disk (disk_t *disk) /* {{{ */
263 {
264 disk_t *next;
266 if (disk == NULL)
267 return;
269 next = disk->next;
271 sfree (disk->name);
272 sfree (disk);
274 free_disk (next);
275 } /* }}} void free_disk */
277 static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
278 {
279 if (cw == NULL)
280 return;
282 if (cw->query != NULL)
283 na_elem_free (cw->query);
285 sfree (cw);
286 } /* }}} void free_cfg_wafl */
288 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
289 {
290 if (cfg_disk == NULL)
291 return;
293 if (cfg_disk->query != NULL)
294 na_elem_free (cfg_disk->query);
296 free_disk (cfg_disk->disks);
297 sfree (cfg_disk);
298 } /* }}} void free_cfg_disk */
300 static void free_cfg_volume_perf (cfg_volume_perf_t *cvp) /* {{{ */
301 {
302 data_volume_perf_t *data;
304 if (cvp == NULL)
305 return;
307 /* Free the ignorelists */
308 ignorelist_free (cvp->il_octets);
309 ignorelist_free (cvp->il_operations);
310 ignorelist_free (cvp->il_latency);
312 /* Free the linked list of volumes */
313 data = cvp->volumes;
314 while (data != NULL)
315 {
316 data_volume_perf_t *next = data->next;
317 sfree (data->name);
318 sfree (data);
319 data = next;
320 }
322 if (cvp->query != NULL)
323 na_elem_free (cvp->query);
325 sfree (cvp);
326 } /* }}} void free_cfg_volume_perf */
328 static void free_cfg_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
329 {
330 data_volume_usage_t *data;
332 if (cvu == NULL)
333 return;
335 /* Free the ignorelists */
336 ignorelist_free (cvu->il_capacity);
337 ignorelist_free (cvu->il_snapshot);
339 /* Free the linked list of volumes */
340 data = cvu->volumes;
341 while (data != NULL)
342 {
343 data_volume_usage_t *next = data->next;
344 sfree (data->name);
345 if (data->snap_query != NULL)
346 na_elem_free(data->snap_query);
347 sfree (data);
348 data = next;
349 }
351 if (cvu->query != NULL)
352 na_elem_free (cvu->query);
354 sfree (cvu);
355 } /* }}} void free_cfg_volume_usage */
357 static void free_cfg_system (cfg_system_t *cs) /* {{{ */
358 {
359 if (cs == NULL)
360 return;
362 if (cs->query != NULL)
363 na_elem_free (cs->query);
365 sfree (cs);
366 } /* }}} void free_cfg_system */
368 static void free_host_config (host_config_t *hc) /* {{{ */
369 {
370 host_config_t *next;
372 if (hc == NULL)
373 return;
375 next = hc->next;
377 sfree (hc->name);
378 sfree (hc->host);
379 sfree (hc->username);
380 sfree (hc->password);
382 free_cfg_disk (hc->cfg_disk);
383 free_cfg_wafl (hc->cfg_wafl);
384 free_cfg_volume_perf (hc->cfg_volume_perf);
385 free_cfg_volume_usage (hc->cfg_volume_usage);
386 free_cfg_system (hc->cfg_system);
388 if (hc->srv != NULL)
389 na_server_close (hc->srv);
391 sfree (hc);
393 free_host_config (next);
394 } /* }}} void free_host_config */
396 /*
397 * Auxiliary functions
398 *
399 * Used to look up volumes and disks or to handle flags.
400 */
401 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
402 {
403 disk_t *d;
405 if ((cd == NULL) || (name == NULL))
406 return (NULL);
408 for (d = cd->disks; d != NULL; d = d->next) {
409 if (strcmp(d->name, name) == 0)
410 return d;
411 }
413 d = malloc(sizeof(*d));
414 if (d == NULL)
415 return (NULL);
416 memset (d, 0, sizeof (*d));
417 d->next = NULL;
419 d->name = strdup(name);
420 if (d->name == NULL) {
421 sfree (d);
422 return (NULL);
423 }
425 d->next = cd->disks;
426 cd->disks = d;
428 return d;
429 } /* }}} disk_t *get_disk */
431 static data_volume_usage_t *get_volume_usage (cfg_volume_usage_t *cvu, /* {{{ */
432 const char *name)
433 {
434 data_volume_usage_t *last;
435 data_volume_usage_t *new;
437 int ignore_capacity = 0;
438 int ignore_snapshot = 0;
440 if ((cvu == NULL) || (name == NULL))
441 return (NULL);
443 last = cvu->volumes;
444 while (last != NULL)
445 {
446 if (strcmp (last->name, name) == 0)
447 return (last);
449 if (last->next == NULL)
450 break;
452 last = last->next;
453 }
455 /* Check the ignorelists. If *both* tell us to ignore a volume, return NULL. */
456 ignore_capacity = ignorelist_match (cvu->il_capacity, name);
457 ignore_snapshot = ignorelist_match (cvu->il_snapshot, name);
458 if ((ignore_capacity != 0) && (ignore_snapshot != 0))
459 return (NULL);
461 /* Not found: allocate. */
462 new = malloc (sizeof (*new));
463 if (new == NULL)
464 return (NULL);
465 memset (new, 0, sizeof (*new));
466 new->next = NULL;
468 new->name = strdup (name);
469 if (new->name == NULL)
470 {
471 sfree (new);
472 return (NULL);
473 }
475 if (ignore_capacity == 0)
476 new->flags |= CFG_VOLUME_USAGE_DF;
477 if (ignore_snapshot == 0) {
478 new->flags |= CFG_VOLUME_USAGE_SNAP;
479 new->snap_query = na_elem_new ("snapshot-list-info");
480 na_child_add_string(new->snap_query, "target-type", "volume");
481 na_child_add_string(new->snap_query, "target-name", name);
482 } else {
483 new->snap_query = NULL;
484 }
486 /* Add to end of list. */
487 if (last == NULL)
488 cvu->volumes = new;
489 else
490 last->next = new;
492 return (new);
493 } /* }}} data_volume_usage_t *get_volume_usage */
495 static data_volume_perf_t *get_volume_perf (cfg_volume_perf_t *cvp, /* {{{ */
496 const char *name)
497 {
498 data_volume_perf_t *last;
499 data_volume_perf_t *new;
501 int ignore_octets = 0;
502 int ignore_operations = 0;
503 int ignore_latency = 0;
505 if ((cvp == NULL) || (name == NULL))
506 return (NULL);
508 last = cvp->volumes;
509 while (last != NULL)
510 {
511 if (strcmp (last->name, name) == 0)
512 return (last);
514 if (last->next == NULL)
515 break;
517 last = last->next;
518 }
520 /* Check the ignorelists. If *all three* tell us to ignore a volume, return
521 * NULL. */
522 ignore_octets = ignorelist_match (cvp->il_octets, name);
523 ignore_operations = ignorelist_match (cvp->il_operations, name);
524 ignore_latency = ignorelist_match (cvp->il_latency, name);
525 if ((ignore_octets != 0) || (ignore_operations != 0)
526 || (ignore_latency != 0))
527 return (NULL);
529 /* Not found: allocate. */
530 new = malloc (sizeof (*new));
531 if (new == NULL)
532 return (NULL);
533 memset (new, 0, sizeof (*new));
534 new->next = NULL;
536 new->name = strdup (name);
537 if (new->name == NULL)
538 {
539 sfree (new);
540 return (NULL);
541 }
543 if (ignore_octets == 0)
544 new->flags |= CFG_VOLUME_PERF_IO;
545 if (ignore_operations == 0)
546 new->flags |= CFG_VOLUME_PERF_OPS;
547 if (ignore_latency == 0)
548 new->flags |= CFG_VOLUME_PERF_LATENCY;
550 /* Add to end of list. */
551 if (last == NULL)
552 cvp->volumes = new;
553 else
554 last->next = new;
556 return (new);
557 } /* }}} data_volume_perf_t *get_volume_perf */
559 /*
560 * Various submit functions.
561 *
562 * They all eventually call "submit_values" which creates a value_list_t and
563 * dispatches it to the daemon.
564 */
565 static int submit_values (const char *host, /* {{{ */
566 const char *plugin_inst,
567 const char *type, const char *type_inst,
568 value_t *values, int values_len,
569 cdtime_t timestamp, cdtime_t interval)
570 {
571 value_list_t vl = VALUE_LIST_INIT;
573 vl.values = values;
574 vl.values_len = values_len;
576 if (timestamp > 0)
577 vl.time = timestamp;
579 if (interval > 0)
580 vl.interval = interval;
582 if (host != NULL)
583 sstrncpy (vl.host, host, sizeof (vl.host));
584 else
585 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
586 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
587 if (plugin_inst != NULL)
588 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
589 sstrncpy (vl.type, type, sizeof (vl.type));
590 if (type_inst != NULL)
591 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
593 return (plugin_dispatch_values (&vl));
594 } /* }}} int submit_uint64 */
596 static int submit_two_derive (const char *host, const char *plugin_inst, /* {{{ */
597 const char *type, const char *type_inst, derive_t val0, derive_t val1,
598 cdtime_t timestamp, cdtime_t interval)
599 {
600 value_t values[2];
602 values[0].derive = val0;
603 values[1].derive = val1;
605 return (submit_values (host, plugin_inst, type, type_inst,
606 values, 2, timestamp, interval));
607 } /* }}} int submit_two_derive */
609 static int submit_derive (const char *host, const char *plugin_inst, /* {{{ */
610 const char *type, const char *type_inst, derive_t counter,
611 cdtime_t timestamp, cdtime_t interval)
612 {
613 value_t v;
615 v.derive = counter;
617 return (submit_values (host, plugin_inst, type, type_inst,
618 &v, 1, timestamp, interval));
619 } /* }}} int submit_derive */
621 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
622 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
623 cdtime_t timestamp, cdtime_t interval)
624 {
625 value_t values[2];
627 values[0].gauge = val0;
628 values[1].gauge = val1;
630 return (submit_values (host, plugin_inst, type, type_inst,
631 values, 2, timestamp, interval));
632 } /* }}} int submit_two_gauge */
634 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
635 const char *type, const char *type_inst, double d,
636 cdtime_t timestamp, cdtime_t interval)
637 {
638 value_t v;
640 v.gauge = (gauge_t) d;
642 return (submit_values (host, plugin_inst, type, type_inst,
643 &v, 1, timestamp, interval));
644 } /* }}} int submit_uint64 */
646 /* Calculate hit ratio from old and new counters and submit the resulting
647 * percentage. Used by "submit_wafl_data". */
648 static int submit_cache_ratio (const char *host, /* {{{ */
649 const char *plugin_inst,
650 const char *type_inst,
651 uint64_t new_hits,
652 uint64_t new_misses,
653 uint64_t old_hits,
654 uint64_t old_misses,
655 cdtime_t timestamp,
656 cdtime_t interval)
657 {
658 value_t v;
660 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
661 uint64_t hits;
662 uint64_t misses;
664 hits = new_hits - old_hits;
665 misses = new_misses - old_misses;
667 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
668 } else {
669 v.gauge = NAN;
670 }
672 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
673 &v, 1, timestamp, interval));
674 } /* }}} int submit_cache_ratio */
676 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
677 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
678 cfg_wafl_t *old_data, const cfg_wafl_t *new_data, cdtime_t interval)
679 {
680 /* Submit requested counters */
681 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
682 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
683 submit_cache_ratio (hostname, instance, "name_cache_hit",
684 new_data->name_cache_hit, new_data->name_cache_miss,
685 old_data->name_cache_hit, old_data->name_cache_miss,
686 new_data->timestamp, interval);
688 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
689 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
690 submit_cache_ratio (hostname, instance, "find_dir_hit",
691 new_data->find_dir_hit, new_data->find_dir_miss,
692 old_data->find_dir_hit, old_data->find_dir_miss,
693 new_data->timestamp, interval);
695 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
696 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
697 submit_cache_ratio (hostname, instance, "buf_hash_hit",
698 new_data->buf_hash_hit, new_data->buf_hash_miss,
699 old_data->buf_hash_hit, old_data->buf_hash_miss,
700 new_data->timestamp, interval);
702 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
703 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
704 submit_cache_ratio (hostname, instance, "inode_cache_hit",
705 new_data->inode_cache_hit, new_data->inode_cache_miss,
706 old_data->inode_cache_hit, old_data->inode_cache_miss,
707 new_data->timestamp, interval);
709 /* Clear old HAVE_* flags */
710 old_data->flags &= ~HAVE_WAFL_ALL;
712 /* Copy all counters */
713 old_data->timestamp = new_data->timestamp;
714 old_data->name_cache_hit = new_data->name_cache_hit;
715 old_data->name_cache_miss = new_data->name_cache_miss;
716 old_data->find_dir_hit = new_data->find_dir_hit;
717 old_data->find_dir_miss = new_data->find_dir_miss;
718 old_data->buf_hash_hit = new_data->buf_hash_hit;
719 old_data->buf_hash_miss = new_data->buf_hash_miss;
720 old_data->inode_cache_hit = new_data->inode_cache_hit;
721 old_data->inode_cache_miss = new_data->inode_cache_miss;
723 /* Copy HAVE_* flags */
724 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
726 return (0);
727 } /* }}} int submit_wafl_data */
729 /* Submits volume performance data to the daemon, taking care to honor and
730 * update flags appropriately. */
731 static int submit_volume_perf_data (const char *hostname, /* {{{ */
732 data_volume_perf_t *old_data,
733 const data_volume_perf_t *new_data, int interval)
734 {
735 char plugin_instance[DATA_MAX_NAME_LEN];
737 if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
738 return (-1);
740 ssnprintf (plugin_instance, sizeof (plugin_instance),
741 "volume-%s", old_data->name);
743 /* Check for and submit disk-octet values */
744 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
745 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
746 {
747 submit_two_derive (hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
748 (derive_t) new_data->read_bytes, (derive_t) new_data->write_bytes, new_data->timestamp, interval);
749 }
751 /* Check for and submit disk-operations values */
752 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
753 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
754 {
755 submit_two_derive (hostname, plugin_instance, "disk_ops", /* type instance = */ NULL,
756 (derive_t) new_data->read_ops, (derive_t) new_data->write_ops, new_data->timestamp, interval);
757 }
759 /* Check for, calculate and submit disk-latency values */
760 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
761 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
762 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
763 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
764 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
765 {
766 gauge_t latency_per_op_read;
767 gauge_t latency_per_op_write;
769 latency_per_op_read = NAN;
770 latency_per_op_write = NAN;
772 /* Check if a counter wrapped around. */
773 if ((new_data->read_ops > old_data->read_ops)
774 && (new_data->read_latency > old_data->read_latency))
775 {
776 uint64_t diff_ops_read;
777 uint64_t diff_latency_read;
779 diff_ops_read = new_data->read_ops - old_data->read_ops;
780 diff_latency_read = new_data->read_latency - old_data->read_latency;
782 if (diff_ops_read > 0)
783 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
784 }
786 if ((new_data->write_ops > old_data->write_ops)
787 && (new_data->write_latency > old_data->write_latency))
788 {
789 uint64_t diff_ops_write;
790 uint64_t diff_latency_write;
792 diff_ops_write = new_data->write_ops - old_data->write_ops;
793 diff_latency_write = new_data->write_latency - old_data->write_latency;
795 if (diff_ops_write > 0)
796 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
797 }
799 submit_two_gauge (hostname, plugin_instance, "disk_latency", /* type instance = */ NULL,
800 latency_per_op_read, latency_per_op_write, new_data->timestamp, interval);
801 }
803 /* Clear all HAVE_* flags. */
804 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
806 /* Copy all counters */
807 old_data->timestamp = new_data->timestamp;
808 old_data->read_bytes = new_data->read_bytes;
809 old_data->write_bytes = new_data->write_bytes;
810 old_data->read_ops = new_data->read_ops;
811 old_data->write_ops = new_data->write_ops;
812 old_data->read_latency = new_data->read_latency;
813 old_data->write_latency = new_data->write_latency;
815 /* Copy the HAVE_* flags */
816 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
818 return (0);
819 } /* }}} int submit_volume_perf_data */
821 static cdtime_t cna_child_get_cdtime (na_elem_t *data) /* {{{ */
822 {
823 time_t t;
825 t = (time_t) na_child_get_uint64 (data, "timestamp", /* default = */ 0);
827 return (TIME_T_TO_CDTIME_T (t));
828 } /* }}} cdtime_t cna_child_get_cdtime */
831 /*
832 * Query functions
833 *
834 * These functions are called with appropriate data returned by the libnetapp
835 * interface which is parsed and submitted with the above functions.
836 */
837 /* Data corresponding to <WAFL /> */
838 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
839 na_elem_t *data, cdtime_t interval)
840 {
841 cfg_wafl_t perf_data;
842 const char *plugin_inst;
844 na_elem_t *instances;
845 na_elem_t *counter;
846 na_elem_iter_t counter_iter;
848 memset (&perf_data, 0, sizeof (perf_data));
850 perf_data.timestamp = cna_child_get_cdtime (data);
852 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
853 if (instances == NULL)
854 {
855 ERROR ("netapp plugin: cna_handle_wafl_data: "
856 "na_elem_child (\"instances\") failed "
857 "for host %s.", hostname);
858 return (-1);
859 }
861 plugin_inst = na_child_get_string(instances, "name");
862 if (plugin_inst == NULL)
863 {
864 ERROR ("netapp plugin: cna_handle_wafl_data: "
865 "na_child_get_string (\"name\") failed "
866 "for host %s.", hostname);
867 return (-1);
868 }
870 /* Iterate over all counters */
871 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
872 for (counter = na_iterator_next (&counter_iter);
873 counter != NULL;
874 counter = na_iterator_next (&counter_iter))
875 {
876 const char *name;
877 uint64_t value;
879 name = na_child_get_string(counter, "name");
880 if (name == NULL)
881 continue;
883 value = na_child_get_uint64(counter, "value", UINT64_MAX);
884 if (value == UINT64_MAX)
885 continue;
887 if (!strcmp(name, "name_cache_hit")) {
888 perf_data.name_cache_hit = value;
889 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
890 } else if (!strcmp(name, "name_cache_miss")) {
891 perf_data.name_cache_miss = value;
892 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
893 } else if (!strcmp(name, "find_dir_hit")) {
894 perf_data.find_dir_hit = value;
895 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
896 } else if (!strcmp(name, "find_dir_miss")) {
897 perf_data.find_dir_miss = value;
898 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
899 } else if (!strcmp(name, "buf_hash_hit")) {
900 perf_data.buf_hash_hit = value;
901 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
902 } else if (!strcmp(name, "buf_hash_miss")) {
903 perf_data.buf_hash_miss = value;
904 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
905 } else if (!strcmp(name, "inode_cache_hit")) {
906 perf_data.inode_cache_hit = value;
907 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
908 } else if (!strcmp(name, "inode_cache_miss")) {
909 perf_data.inode_cache_miss = value;
910 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
911 } else {
912 DEBUG("netapp plugin: cna_handle_wafl_data: "
913 "Found unexpected child: %s "
914 "for host %s.", name, hostname);
915 }
916 }
918 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data, interval));
919 } /* }}} void cna_handle_wafl_data */
921 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
922 {
923 na_elem_t *e;
925 if (cw == NULL)
926 return (EINVAL);
928 if (cw->query != NULL)
929 return (0);
931 cw->query = na_elem_new("perf-object-get-instances");
932 if (cw->query == NULL)
933 {
934 ERROR ("netapp plugin: na_elem_new failed.");
935 return (-1);
936 }
937 na_child_add_string (cw->query, "objectname", "wafl");
939 e = na_elem_new("counters");
940 if (e == NULL)
941 {
942 na_elem_free (cw->query);
943 cw->query = NULL;
944 ERROR ("netapp plugin: na_elem_new failed.");
945 return (-1);
946 }
947 na_child_add_string(e, "counter", "name_cache_hit");
948 na_child_add_string(e, "counter", "name_cache_miss");
949 na_child_add_string(e, "counter", "find_dir_hit");
950 na_child_add_string(e, "counter", "find_dir_miss");
951 na_child_add_string(e, "counter", "buf_hash_hit");
952 na_child_add_string(e, "counter", "buf_hash_miss");
953 na_child_add_string(e, "counter", "inode_cache_hit");
954 na_child_add_string(e, "counter", "inode_cache_miss");
956 na_child_add(cw->query, e);
958 return (0);
959 } /* }}} int cna_setup_wafl */
961 static int cna_query_wafl (host_config_t *host) /* {{{ */
962 {
963 na_elem_t *data;
964 int status;
965 cdtime_t now;
967 if (host == NULL)
968 return (EINVAL);
970 /* If WAFL was not configured, return without doing anything. */
971 if (host->cfg_wafl == NULL)
972 return (0);
974 now = cdtime ();
975 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
976 return (0);
978 status = cna_setup_wafl (host->cfg_wafl);
979 if (status != 0)
980 return (status);
981 assert (host->cfg_wafl->query != NULL);
983 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
984 if (na_results_status (data) != NA_OK)
985 {
986 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed for host %s: %s",
987 host->name, na_results_reason (data));
988 na_elem_free (data);
989 return (-1);
990 }
992 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data,
993 host->cfg_wafl->interval.interval);
995 if (status == 0)
996 host->cfg_wafl->interval.last_read = now;
998 na_elem_free (data);
999 return (status);
1000 } /* }}} int cna_query_wafl */
1002 /* Data corresponding to <Disks /> */
1003 static int cna_handle_disk_data (const char *hostname, /* {{{ */
1004 cfg_disk_t *cfg_disk, na_elem_t *data, cdtime_t interval)
1005 {
1006 cdtime_t timestamp;
1007 na_elem_t *instances;
1008 na_elem_t *instance;
1009 na_elem_iter_t instance_iter;
1010 disk_t *worst_disk = NULL;
1012 if ((cfg_disk == NULL) || (data == NULL))
1013 return (EINVAL);
1015 timestamp = cna_child_get_cdtime (data);
1017 instances = na_elem_child (data, "instances");
1018 if (instances == NULL)
1019 {
1020 ERROR ("netapp plugin: cna_handle_disk_data: "
1021 "na_elem_child (\"instances\") failed "
1022 "for host %s.", hostname);
1023 return (-1);
1024 }
1026 /* Iterate over all children */
1027 instance_iter = na_child_iterator (instances);
1028 for (instance = na_iterator_next (&instance_iter);
1029 instance != NULL;
1030 instance = na_iterator_next(&instance_iter))
1031 {
1032 disk_t *old_data;
1033 disk_t new_data;
1035 na_elem_iter_t counter_iterator;
1036 na_elem_t *counter;
1038 memset (&new_data, 0, sizeof (new_data));
1039 new_data.timestamp = timestamp;
1040 new_data.disk_busy_percent = NAN;
1042 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1043 if (old_data == NULL)
1044 continue;
1046 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1047 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1048 for (counter = na_iterator_next(&counter_iterator);
1049 counter != NULL;
1050 counter = na_iterator_next(&counter_iterator))
1051 {
1052 const char *name;
1053 uint64_t value;
1055 name = na_child_get_string(counter, "name");
1056 if (name == NULL)
1057 continue;
1059 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1060 if (value == UINT64_MAX)
1061 continue;
1063 if (strcmp(name, "disk_busy") == 0)
1064 {
1065 new_data.disk_busy = value;
1066 new_data.flags |= HAVE_DISK_BUSY;
1067 }
1068 else if (strcmp(name, "base_for_disk_busy") == 0)
1069 {
1070 new_data.base_for_disk_busy = value;
1071 new_data.flags |= HAVE_DISK_BASE;
1072 }
1073 else
1074 {
1075 DEBUG ("netapp plugin: cna_handle_disk_data: "
1076 "Counter not handled: %s = %"PRIu64,
1077 name, value);
1078 }
1079 }
1081 /* If all required counters are available and did not just wrap around,
1082 * calculate the busy percentage. Otherwise, the value is initialized to
1083 * NAN at the top of the for-loop. */
1084 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1085 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1086 && (new_data.disk_busy >= old_data->disk_busy)
1087 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1088 {
1089 uint64_t busy_diff;
1090 uint64_t base_diff;
1092 busy_diff = new_data.disk_busy - old_data->disk_busy;
1093 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1095 new_data.disk_busy_percent = 100.0
1096 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1097 }
1099 /* Clear HAVE_* flags */
1100 old_data->flags &= ~HAVE_DISK_ALL;
1102 /* Copy data */
1103 old_data->timestamp = new_data.timestamp;
1104 old_data->disk_busy = new_data.disk_busy;
1105 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1106 old_data->disk_busy_percent = new_data.disk_busy_percent;
1108 /* Copy flags */
1109 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1111 if ((worst_disk == NULL)
1112 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1113 worst_disk = old_data;
1114 } /* for (all disks) */
1116 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1117 submit_double (hostname, "system", "percent", "disk_busy",
1118 worst_disk->disk_busy_percent, timestamp, interval);
1120 return (0);
1121 } /* }}} int cna_handle_disk_data */
1123 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1124 {
1125 na_elem_t *e;
1127 if (cd == NULL)
1128 return (EINVAL);
1130 if (cd->query != NULL)
1131 return (0);
1133 cd->query = na_elem_new ("perf-object-get-instances");
1134 if (cd->query == NULL)
1135 {
1136 ERROR ("netapp plugin: na_elem_new failed.");
1137 return (-1);
1138 }
1139 na_child_add_string (cd->query, "objectname", "disk");
1141 e = na_elem_new("counters");
1142 if (e == NULL)
1143 {
1144 na_elem_free (cd->query);
1145 cd->query = NULL;
1146 ERROR ("netapp plugin: na_elem_new failed.");
1147 return (-1);
1148 }
1149 na_child_add_string(e, "counter", "disk_busy");
1150 na_child_add_string(e, "counter", "base_for_disk_busy");
1151 na_child_add(cd->query, e);
1153 return (0);
1154 } /* }}} int cna_setup_disk */
1156 static int cna_query_disk (host_config_t *host) /* {{{ */
1157 {
1158 na_elem_t *data;
1159 int status;
1160 cdtime_t now;
1162 if (host == NULL)
1163 return (EINVAL);
1165 /* If the user did not configure disk statistics, return without doing
1166 * anything. */
1167 if (host->cfg_disk == NULL)
1168 return (0);
1170 now = cdtime ();
1171 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1172 return (0);
1174 status = cna_setup_disk (host->cfg_disk);
1175 if (status != 0)
1176 return (status);
1177 assert (host->cfg_disk->query != NULL);
1179 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1180 if (na_results_status (data) != NA_OK)
1181 {
1182 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed for host %s: %s",
1183 host->name, na_results_reason (data));
1184 na_elem_free (data);
1185 return (-1);
1186 }
1188 status = cna_handle_disk_data (host->name, host->cfg_disk, data,
1189 host->cfg_disk->interval.interval);
1191 if (status == 0)
1192 host->cfg_disk->interval.last_read = now;
1194 na_elem_free (data);
1195 return (status);
1196 } /* }}} int cna_query_disk */
1198 /* Data corresponding to <VolumePerf /> */
1199 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1200 cfg_volume_perf_t *cvp, na_elem_t *data, cdtime_t interval)
1201 {
1202 cdtime_t timestamp;
1203 na_elem_t *elem_instances;
1204 na_elem_iter_t iter_instances;
1205 na_elem_t *elem_instance;
1207 timestamp = cna_child_get_cdtime (data);
1209 elem_instances = na_elem_child(data, "instances");
1210 if (elem_instances == NULL)
1211 {
1212 ERROR ("netapp plugin: handle_volume_perf_data: "
1213 "na_elem_child (\"instances\") failed "
1214 "for host %s.", hostname);
1215 return (-1);
1216 }
1218 iter_instances = na_child_iterator (elem_instances);
1219 for (elem_instance = na_iterator_next(&iter_instances);
1220 elem_instance != NULL;
1221 elem_instance = na_iterator_next(&iter_instances))
1222 {
1223 const char *name;
1225 data_volume_perf_t perf_data;
1226 data_volume_perf_t *v;
1228 na_elem_t *elem_counters;
1229 na_elem_iter_t iter_counters;
1230 na_elem_t *elem_counter;
1232 memset (&perf_data, 0, sizeof (perf_data));
1233 perf_data.timestamp = timestamp;
1235 name = na_child_get_string (elem_instance, "name");
1236 if (name == NULL)
1237 continue;
1239 /* get_volume_perf may return NULL if this volume is to be ignored. */
1240 v = get_volume_perf (cvp, name);
1241 if (v == NULL)
1242 continue;
1244 elem_counters = na_elem_child (elem_instance, "counters");
1245 if (elem_counters == NULL)
1246 continue;
1248 iter_counters = na_child_iterator (elem_counters);
1249 for (elem_counter = na_iterator_next(&iter_counters);
1250 elem_counter != NULL;
1251 elem_counter = na_iterator_next(&iter_counters))
1252 {
1253 const char *name;
1254 uint64_t value;
1256 name = na_child_get_string (elem_counter, "name");
1257 if (name == NULL)
1258 continue;
1260 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1261 if (value == UINT64_MAX)
1262 continue;
1264 if (!strcmp(name, "read_data")) {
1265 perf_data.read_bytes = value;
1266 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1267 } else if (!strcmp(name, "write_data")) {
1268 perf_data.write_bytes = value;
1269 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1270 } else if (!strcmp(name, "read_ops")) {
1271 perf_data.read_ops = value;
1272 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1273 } else if (!strcmp(name, "write_ops")) {
1274 perf_data.write_ops = value;
1275 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1276 } else if (!strcmp(name, "read_latency")) {
1277 perf_data.read_latency = value;
1278 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1279 } else if (!strcmp(name, "write_latency")) {
1280 perf_data.write_latency = value;
1281 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1282 }
1283 } /* for (elem_counter) */
1285 submit_volume_perf_data (hostname, v, &perf_data, interval);
1286 } /* for (volume) */
1288 return (0);
1289 } /* }}} int cna_handle_volume_perf_data */
1291 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1292 {
1293 na_elem_t *e;
1295 if (cd == NULL)
1296 return (EINVAL);
1298 if (cd->query != NULL)
1299 return (0);
1301 cd->query = na_elem_new ("perf-object-get-instances");
1302 if (cd->query == NULL)
1303 {
1304 ERROR ("netapp plugin: na_elem_new failed.");
1305 return (-1);
1306 }
1307 na_child_add_string (cd->query, "objectname", "volume");
1309 e = na_elem_new("counters");
1310 if (e == NULL)
1311 {
1312 na_elem_free (cd->query);
1313 cd->query = NULL;
1314 ERROR ("netapp plugin: na_elem_new failed.");
1315 return (-1);
1316 }
1317 na_child_add_string(e, "counter", "read_ops");
1318 na_child_add_string(e, "counter", "write_ops");
1319 na_child_add_string(e, "counter", "read_data");
1320 na_child_add_string(e, "counter", "write_data");
1321 na_child_add_string(e, "counter", "read_latency");
1322 na_child_add_string(e, "counter", "write_latency");
1323 na_child_add(cd->query, e);
1325 return (0);
1326 } /* }}} int cna_setup_volume_perf */
1328 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1329 {
1330 na_elem_t *data;
1331 int status;
1332 cdtime_t now;
1334 if (host == NULL)
1335 return (EINVAL);
1337 /* If the user did not configure volume performance statistics, return
1338 * without doing anything. */
1339 if (host->cfg_volume_perf == NULL)
1340 return (0);
1342 now = cdtime ();
1343 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1344 return (0);
1346 status = cna_setup_volume_perf (host->cfg_volume_perf);
1347 if (status != 0)
1348 return (status);
1349 assert (host->cfg_volume_perf->query != NULL);
1351 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1352 if (na_results_status (data) != NA_OK)
1353 {
1354 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed for host %s: %s",
1355 host->name, na_results_reason (data));
1356 na_elem_free (data);
1357 return (-1);
1358 }
1360 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data,
1361 host->cfg_volume_perf->interval.interval);
1363 if (status == 0)
1364 host->cfg_volume_perf->interval.last_read = now;
1366 na_elem_free (data);
1367 return (status);
1368 } /* }}} int cna_query_volume_perf */
1370 /* Data corresponding to <VolumeUsage /> */
1371 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1372 cfg_volume_usage_t *cfg_volume, int interval)
1373 {
1374 data_volume_usage_t *v;
1376 for (v = cfg_volume->volumes; v != NULL; v = v->next)
1377 {
1378 char plugin_instance[DATA_MAX_NAME_LEN];
1380 uint64_t norm_used = v->norm_used;
1381 uint64_t norm_free = v->norm_free;
1382 uint64_t sis_saved = v->sis_saved;
1383 uint64_t snap_reserve_used = 0;
1384 uint64_t snap_reserve_free = v->snap_reserved;
1385 uint64_t snap_norm_used = v->snap_used;
1387 ssnprintf (plugin_instance, sizeof (plugin_instance),
1388 "volume-%s", v->name);
1390 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD)) {
1391 if (v->snap_reserved > v->snap_used) {
1392 snap_reserve_free = v->snap_reserved - v->snap_used;
1393 snap_reserve_used = v->snap_used;
1394 snap_norm_used = 0;
1395 } else {
1396 snap_reserve_free = 0;
1397 snap_reserve_used = v->snap_reserved;
1398 snap_norm_used = v->snap_used - v->snap_reserved;
1399 }
1400 }
1402 /* The space used by snapshots but not reserved for them is included in
1403 * both, norm_used and snap_norm_used. If possible, subtract this here. */
1404 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED))
1405 {
1406 if (norm_used >= snap_norm_used)
1407 norm_used -= snap_norm_used;
1408 else
1409 {
1410 ERROR ("netapp plugin: (norm_used = %"PRIu64") < (snap_norm_used = "
1411 "%"PRIu64") for host %s. Invalidating both.",
1412 norm_used, snap_norm_used, hostname);
1413 v->flags &= ~(HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED);
1414 }
1415 }
1417 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1418 submit_double (hostname, /* plugin instance = */ plugin_instance,
1419 "df_complex", "free",
1420 (double) norm_free, /* timestamp = */ 0, interval);
1422 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1423 submit_double (hostname, /* plugin instance = */ plugin_instance,
1424 "df_complex", "sis_saved",
1425 (double) sis_saved, /* timestamp = */ 0, interval);
1427 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1428 submit_double (hostname, /* plugin instance = */ plugin_instance,
1429 "df_complex", "used",
1430 (double) norm_used, /* timestamp = */ 0, interval);
1432 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1433 submit_double (hostname, /* plugin instance = */ plugin_instance,
1434 "df_complex", "snap_reserved",
1435 (double) snap_reserve_free, /* timestamp = */ 0, interval);
1437 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
1438 submit_double (hostname, /* plugin instance = */ plugin_instance,
1439 "df_complex", "snap_reserve_used",
1440 (double) snap_reserve_used, /* timestamp = */ 0, interval);
1442 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1443 submit_double (hostname, /* plugin instance = */ plugin_instance,
1444 "df_complex", "snap_normal_used",
1445 (double) snap_norm_used, /* timestamp = */ 0, interval);
1447 /* Clear all the HAVE_* flags */
1448 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1449 } /* for (v = cfg_volume->volumes) */
1451 return (0);
1452 } /* }}} int cna_submit_volume_usage_data */
1454 /* Switch the state of a volume between online and offline and send out a
1455 * notification. */
1456 static int cna_change_volume_status (const char *hostname, /* {{{ */
1457 data_volume_usage_t *v)
1458 {
1459 notification_t n;
1461 memset (&n, 0, sizeof (&n));
1462 n.time = cdtime ();
1463 sstrncpy (n.host, hostname, sizeof (n.host));
1464 sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
1465 sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance));
1467 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
1468 n.severity = NOTIF_OKAY;
1469 ssnprintf (n.message, sizeof (n.message),
1470 "Volume %s is now online.", v->name);
1471 v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
1472 } else {
1473 n.severity = NOTIF_WARNING;
1474 ssnprintf (n.message, sizeof (n.message),
1475 "Volume %s is now offline.", v->name);
1476 v->flags |= IS_VOLUME_USAGE_OFFLINE;
1477 }
1479 return (plugin_dispatch_notification (&n));
1480 } /* }}} int cna_change_volume_status */
1482 static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
1483 data_volume_usage_t *v)
1484 {
1485 uint64_t snap_used = 0, value;
1486 na_elem_t *data, *elem_snap, *elem_snapshots;
1487 na_elem_iter_t iter_snap;
1489 data = na_server_invoke_elem(host->srv, v->snap_query);
1490 if (na_results_status(data) != NA_OK)
1491 {
1492 if (na_results_errno(data) == EVOLUMEOFFLINE) {
1493 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
1494 cna_change_volume_status (host->name, v);
1495 } else {
1496 ERROR ("netapp plugin: cna_handle_volume_snap_usage: na_server_invoke_elem for "
1497 "volume \"%s\" on host %s failed with error %d: %s", v->name,
1498 host->name, na_results_errno(data), na_results_reason(data));
1499 }
1500 na_elem_free(data);
1501 return;
1502 }
1504 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0)
1505 cna_change_volume_status (host->name, v);
1507 elem_snapshots = na_elem_child (data, "snapshots");
1508 if (elem_snapshots == NULL)
1509 {
1510 ERROR ("netapp plugin: cna_handle_volume_snap_usage: "
1511 "na_elem_child (\"snapshots\") failed "
1512 "for host %s.", host->name);
1513 na_elem_free(data);
1514 return;
1515 }
1517 iter_snap = na_child_iterator (elem_snapshots);
1518 for (elem_snap = na_iterator_next (&iter_snap);
1519 elem_snap != NULL;
1520 elem_snap = na_iterator_next (&iter_snap))
1521 {
1522 value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
1523 /* "cumulative-total" is the total size of the oldest snapshot plus all
1524 * newer ones in blocks (1KB). We therefore are looking for the highest
1525 * number of all snapshots - that's the size required for the snapshots. */
1526 if (value > snap_used)
1527 snap_used = value;
1528 }
1529 na_elem_free (data);
1530 /* snap_used is in 1024 byte blocks */
1531 v->snap_used = snap_used * 1024;
1532 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1533 } /* }}} void cna_handle_volume_snap_usage */
1535 static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
1536 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1537 {
1538 na_elem_t *elem_volume;
1539 na_elem_t *elem_volumes;
1540 na_elem_iter_t iter_volume;
1542 elem_volumes = na_elem_child (data, "volumes");
1543 if (elem_volumes == NULL)
1544 {
1545 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1546 "na_elem_child (\"volumes\") failed "
1547 "for host %s.", host->name);
1548 return (-1);
1549 }
1551 iter_volume = na_child_iterator (elem_volumes);
1552 for (elem_volume = na_iterator_next (&iter_volume);
1553 elem_volume != NULL;
1554 elem_volume = na_iterator_next (&iter_volume))
1555 {
1556 const char *volume_name, *state;
1558 data_volume_usage_t *v;
1559 uint64_t value;
1561 na_elem_t *sis;
1562 const char *sis_state;
1563 uint64_t sis_saved_reported;
1565 volume_name = na_child_get_string (elem_volume, "name");
1566 if (volume_name == NULL)
1567 continue;
1569 state = na_child_get_string (elem_volume, "state");
1570 if ((state == NULL) || (strcmp(state, "online") != 0))
1571 continue;
1573 /* get_volume_usage may return NULL if the volume is to be ignored. */
1574 v = get_volume_usage (cfg_volume, volume_name);
1575 if (v == NULL)
1576 continue;
1578 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1579 cna_handle_volume_snap_usage(host, v);
1581 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1582 continue;
1584 /* 2^4 exa-bytes? This will take a while ;) */
1585 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1586 if (value != UINT64_MAX) {
1587 v->norm_free = value;
1588 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1589 }
1591 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1592 if (value != UINT64_MAX) {
1593 v->norm_used = value;
1594 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1595 }
1597 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1598 if (value != UINT64_MAX) {
1599 /* 1 block == 1024 bytes as per API docs */
1600 v->snap_reserved = 1024 * value;
1601 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1602 }
1604 sis = na_elem_child(elem_volume, "sis");
1605 if (sis == NULL)
1606 continue;
1608 if (na_elem_child(sis, "sis-info"))
1609 sis = na_elem_child(sis, "sis-info");
1611 sis_state = na_child_get_string(sis, "state");
1612 if (sis_state == NULL)
1613 continue;
1615 /* If SIS is not enabled, there's nothing left to do for this volume. */
1616 if (strcmp ("enabled", sis_state) != 0)
1617 continue;
1619 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1620 if (sis_saved_reported == UINT64_MAX)
1621 continue;
1623 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1624 if ((sis_saved_reported >> 32) != 0) {
1625 /* In case they ever fix this bug. */
1626 v->sis_saved = sis_saved_reported;
1627 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1628 } else { /* really hacky work-around code. {{{ */
1629 uint64_t sis_saved_percent;
1630 uint64_t sis_saved_guess;
1631 uint64_t overflow_guess;
1632 uint64_t guess1, guess2, guess3;
1634 /* Check if we have v->norm_used. Without it, we cannot calculate
1635 * sis_saved_guess. */
1636 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1637 continue;
1639 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1640 if (sis_saved_percent > 100)
1641 continue;
1643 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1644 * will hopefully be fixed in later versions. To work around the bug, try
1645 * to figure out how often the 32bit integer wrapped around by using the
1646 * "percentage-saved" value. Because the percentage is in the range
1647 * [0-100], this should work as long as the saved space does not exceed
1648 * 400 GBytes. */
1649 /* percentage-saved = size-saved / (size-saved + size-used) */
1650 if (sis_saved_percent < 100)
1651 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1652 else
1653 sis_saved_guess = v->norm_used;
1655 overflow_guess = sis_saved_guess >> 32;
1656 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1657 guess2 = (overflow_guess << 32) + sis_saved_reported;
1658 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1660 if (sis_saved_guess < guess2) {
1661 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1662 v->sis_saved = guess1;
1663 else
1664 v->sis_saved = guess2;
1665 } else {
1666 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1667 v->sis_saved = guess2;
1668 else
1669 v->sis_saved = guess3;
1670 }
1671 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1672 } /* }}} end of 32-bit workaround */
1673 } /* for (elem_volume) */
1675 return (cna_submit_volume_usage_data (host->name, cfg_volume,
1676 host->cfg_volume_usage->interval.interval));
1677 } /* }}} int cna_handle_volume_usage_data */
1679 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1680 {
1681 if (cvu == NULL)
1682 return (EINVAL);
1684 if (cvu->query != NULL)
1685 return (0);
1687 cvu->query = na_elem_new ("volume-list-info");
1688 if (cvu->query == NULL)
1689 {
1690 ERROR ("netapp plugin: na_elem_new failed.");
1691 return (-1);
1692 }
1694 return (0);
1695 } /* }}} int cna_setup_volume_usage */
1697 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1698 {
1699 na_elem_t *data;
1700 int status;
1701 cdtime_t now;
1703 if (host == NULL)
1704 return (EINVAL);
1706 /* If the user did not configure volume_usage statistics, return without
1707 * doing anything. */
1708 if (host->cfg_volume_usage == NULL)
1709 return (0);
1711 now = cdtime ();
1712 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1713 return (0);
1715 status = cna_setup_volume_usage (host->cfg_volume_usage);
1716 if (status != 0)
1717 return (status);
1718 assert (host->cfg_volume_usage->query != NULL);
1720 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1721 if (na_results_status (data) != NA_OK)
1722 {
1723 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed for host %s: %s",
1724 host->name, na_results_reason (data));
1725 na_elem_free (data);
1726 return (-1);
1727 }
1729 status = cna_handle_volume_usage_data (host, host->cfg_volume_usage, data);
1731 if (status == 0)
1732 host->cfg_volume_usage->interval.last_read = now;
1734 na_elem_free (data);
1735 return (status);
1736 } /* }}} int cna_query_volume_usage */
1738 /* Data corresponding to <System /> */
1739 static int cna_handle_system_data (const char *hostname, /* {{{ */
1740 cfg_system_t *cfg_system, na_elem_t *data, int interval)
1741 {
1742 na_elem_t *instances;
1743 na_elem_t *counter;
1744 na_elem_iter_t counter_iter;
1746 derive_t disk_read = 0, disk_written = 0;
1747 derive_t net_recv = 0, net_sent = 0;
1748 derive_t cpu_busy = 0, cpu_total = 0;
1749 uint32_t counter_flags = 0;
1751 const char *instance;
1752 cdtime_t timestamp;
1754 timestamp = cna_child_get_cdtime (data);
1756 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
1757 if (instances == NULL)
1758 {
1759 ERROR ("netapp plugin: cna_handle_system_data: "
1760 "na_elem_child (\"instances\") failed "
1761 "for host %s.", hostname);
1762 return (-1);
1763 }
1765 instance = na_child_get_string (instances, "name");
1766 if (instance == NULL)
1767 {
1768 ERROR ("netapp plugin: cna_handle_system_data: "
1769 "na_child_get_string (\"name\") failed "
1770 "for host %s.", hostname);
1771 return (-1);
1772 }
1774 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
1775 for (counter = na_iterator_next (&counter_iter);
1776 counter != NULL;
1777 counter = na_iterator_next (&counter_iter))
1778 {
1779 const char *name;
1780 uint64_t value;
1782 name = na_child_get_string(counter, "name");
1783 if (name == NULL)
1784 continue;
1786 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1787 if (value == UINT64_MAX)
1788 continue;
1790 if (!strcmp(name, "disk_data_read")) {
1791 disk_read = (derive_t) (value * 1024);
1792 counter_flags |= 0x01;
1793 } else if (!strcmp(name, "disk_data_written")) {
1794 disk_written = (derive_t) (value * 1024);
1795 counter_flags |= 0x02;
1796 } else if (!strcmp(name, "net_data_recv")) {
1797 net_recv = (derive_t) (value * 1024);
1798 counter_flags |= 0x04;
1799 } else if (!strcmp(name, "net_data_sent")) {
1800 net_sent = (derive_t) (value * 1024);
1801 counter_flags |= 0x08;
1802 } else if (!strcmp(name, "cpu_busy")) {
1803 cpu_busy = (derive_t) value;
1804 counter_flags |= 0x10;
1805 } else if (!strcmp(name, "cpu_elapsed_time")) {
1806 cpu_total = (derive_t) value;
1807 counter_flags |= 0x20;
1808 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
1809 && (value > 0) && (strlen(name) > 4)
1810 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
1811 submit_derive (hostname, instance, "disk_ops_complex", name,
1812 (derive_t) value, timestamp, interval);
1813 }
1814 } /* for (counter) */
1816 if ((cfg_system->flags & CFG_SYSTEM_DISK)
1817 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
1818 submit_two_derive (hostname, instance, "disk_octets", NULL,
1819 disk_read, disk_written, timestamp, interval);
1821 if ((cfg_system->flags & CFG_SYSTEM_NET)
1822 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
1823 submit_two_derive (hostname, instance, "if_octets", NULL,
1824 net_recv, net_sent, timestamp, interval);
1826 if ((cfg_system->flags & CFG_SYSTEM_CPU)
1827 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
1828 {
1829 submit_derive (hostname, instance, "cpu", "system",
1830 cpu_busy, timestamp, interval);
1831 submit_derive (hostname, instance, "cpu", "idle",
1832 cpu_total - cpu_busy, timestamp, interval);
1833 }
1835 return (0);
1836 } /* }}} int cna_handle_system_data */
1838 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
1839 {
1840 if (cs == NULL)
1841 return (EINVAL);
1843 if (cs->query != NULL)
1844 return (0);
1846 cs->query = na_elem_new ("perf-object-get-instances");
1847 if (cs->query == NULL)
1848 {
1849 ERROR ("netapp plugin: na_elem_new failed.");
1850 return (-1);
1851 }
1852 na_child_add_string (cs->query, "objectname", "system");
1854 return (0);
1855 } /* }}} int cna_setup_system */
1857 static int cna_query_system (host_config_t *host) /* {{{ */
1858 {
1859 na_elem_t *data;
1860 int status;
1861 cdtime_t now;
1863 if (host == NULL)
1864 return (EINVAL);
1866 /* If system statistics were not configured, return without doing anything. */
1867 if (host->cfg_system == NULL)
1868 return (0);
1870 now = cdtime ();
1871 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
1872 return (0);
1874 status = cna_setup_system (host->cfg_system);
1875 if (status != 0)
1876 return (status);
1877 assert (host->cfg_system->query != NULL);
1879 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
1880 if (na_results_status (data) != NA_OK)
1881 {
1882 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed for host %s: %s",
1883 host->name, na_results_reason (data));
1884 na_elem_free (data);
1885 return (-1);
1886 }
1888 status = cna_handle_system_data (host->name, host->cfg_system, data,
1889 host->cfg_system->interval.interval);
1891 if (status == 0)
1892 host->cfg_system->interval.last_read = now;
1894 na_elem_free (data);
1895 return (status);
1896 } /* }}} int cna_query_system */
1898 /*
1899 * Configuration handling
1900 */
1901 /* Sets a given flag if the boolean argument is true and unsets the flag if it
1902 * is false. On error, the flag-field is not changed. */
1903 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
1904 uint32_t *flags, uint32_t flag)
1905 {
1906 if ((ci == NULL) || (flags == NULL))
1907 return (EINVAL);
1909 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1910 {
1911 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
1912 ci->key);
1913 return (-1);
1914 }
1916 if (ci->values[0].value.boolean)
1917 *flags |= flag;
1918 else
1919 *flags &= ~flag;
1921 return (0);
1922 } /* }}} int cna_config_bool_to_flag */
1924 /* Handling of the "Interval" option which is allowed in every block. */
1925 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
1926 cna_interval_t *out_interval)
1927 {
1928 cdtime_t tmp = 0;
1929 int status;
1931 status = cf_util_get_cdtime (ci, &tmp);
1932 if (status != 0)
1933 return (status);
1935 out_interval->interval = tmp;
1936 out_interval->last_read = 0;
1938 return (0);
1939 } /* }}} int cna_config_get_interval */
1941 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
1942 * <VolumePerf /> block. */
1943 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
1944 const oconfig_item_t *ci)
1945 {
1946 char *name;
1947 ignorelist_t * il;
1949 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
1950 {
1951 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1952 ci->key);
1953 return;
1954 }
1956 name = ci->values[0].value.string;
1958 if (strcasecmp ("GetIO", ci->key) == 0)
1959 il = cvp->il_octets;
1960 else if (strcasecmp ("GetOps", ci->key) == 0)
1961 il = cvp->il_operations;
1962 else if (strcasecmp ("GetLatency", ci->key) == 0)
1963 il = cvp->il_latency;
1964 else
1965 return;
1967 ignorelist_add (il, name);
1968 } /* }}} void cna_config_volume_perf_option */
1970 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
1971 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
1972 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
1973 const oconfig_item_t *ci)
1974 {
1975 ignorelist_t *il;
1977 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
1978 {
1979 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
1980 ci->key);
1981 return;
1982 }
1984 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
1985 il = cvp->il_octets;
1986 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
1987 il = cvp->il_operations;
1988 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
1989 il = cvp->il_latency;
1990 else
1991 return;
1993 if (ci->values[0].value.boolean)
1994 ignorelist_set_invert (il, /* invert = */ 0);
1995 else
1996 ignorelist_set_invert (il, /* invert = */ 1);
1997 } /* }}} void cna_config_volume_perf_default */
1999 /* Corresponds to a <Disks /> block */
2000 /*
2001 * <VolumePerf>
2002 * GetIO "vol0"
2003 * GetIO "vol1"
2004 * IgnoreSelectedIO false
2005 *
2006 * GetOps "vol0"
2007 * GetOps "vol2"
2008 * IgnoreSelectedOps false
2009 *
2010 * GetLatency "vol2"
2011 * GetLatency "vol3"
2012 * IgnoreSelectedLatency false
2013 * </VolumePerf>
2014 */
2015 /* Corresponds to a <VolumePerf /> block */
2016 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
2017 const oconfig_item_t *ci)
2018 {
2019 cfg_volume_perf_t *cfg_volume_perf;
2020 int i;
2022 if ((host == NULL) || (ci == NULL))
2023 return (EINVAL);
2025 if (host->cfg_volume_perf == NULL)
2026 {
2027 cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
2028 if (cfg_volume_perf == NULL)
2029 return (ENOMEM);
2030 memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
2032 /* Set default flags */
2033 cfg_volume_perf->query = NULL;
2034 cfg_volume_perf->volumes = NULL;
2036 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
2037 if (cfg_volume_perf->il_octets == NULL)
2038 {
2039 sfree (cfg_volume_perf);
2040 return (ENOMEM);
2041 }
2043 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
2044 if (cfg_volume_perf->il_operations == NULL)
2045 {
2046 ignorelist_free (cfg_volume_perf->il_octets);
2047 sfree (cfg_volume_perf);
2048 return (ENOMEM);
2049 }
2051 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
2052 if (cfg_volume_perf->il_latency == NULL)
2053 {
2054 ignorelist_free (cfg_volume_perf->il_octets);
2055 ignorelist_free (cfg_volume_perf->il_operations);
2056 sfree (cfg_volume_perf);
2057 return (ENOMEM);
2058 }
2060 host->cfg_volume_perf = cfg_volume_perf;
2061 }
2062 cfg_volume_perf = host->cfg_volume_perf;
2064 for (i = 0; i < ci->children_num; ++i) {
2065 oconfig_item_t *item = ci->children + i;
2067 /* if (!item || !item->key || !*item->key) continue; */
2068 if (strcasecmp(item->key, "Interval") == 0)
2069 cna_config_get_interval (item, &cfg_volume_perf->interval);
2070 else if (!strcasecmp(item->key, "GetIO"))
2071 cna_config_volume_perf_option (cfg_volume_perf, item);
2072 else if (!strcasecmp(item->key, "GetOps"))
2073 cna_config_volume_perf_option (cfg_volume_perf, item);
2074 else if (!strcasecmp(item->key, "GetLatency"))
2075 cna_config_volume_perf_option (cfg_volume_perf, item);
2076 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
2077 cna_config_volume_perf_default (cfg_volume_perf, item);
2078 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
2079 cna_config_volume_perf_default (cfg_volume_perf, item);
2080 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2081 cna_config_volume_perf_default (cfg_volume_perf, item);
2082 else
2083 WARNING ("netapp plugin: The option %s is not allowed within "
2084 "`VolumePerf' blocks.", item->key);
2085 }
2087 return (0);
2088 } /* }}} int cna_config_volume_performance */
2090 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2091 * <VolumeUsage /> block. */
2092 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
2093 const oconfig_item_t *ci)
2094 {
2095 char *name;
2096 ignorelist_t * il;
2098 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2099 {
2100 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2101 ci->key);
2102 return;
2103 }
2105 name = ci->values[0].value.string;
2107 if (strcasecmp ("GetCapacity", ci->key) == 0)
2108 il = cvu->il_capacity;
2109 else if (strcasecmp ("GetSnapshot", ci->key) == 0)
2110 il = cvu->il_snapshot;
2111 else
2112 return;
2114 ignorelist_add (il, name);
2115 } /* }}} void cna_config_volume_usage_option */
2117 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2118 * options within a <VolumeUsage /> block. */
2119 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
2120 const oconfig_item_t *ci)
2121 {
2122 ignorelist_t *il;
2124 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2125 {
2126 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2127 ci->key);
2128 return;
2129 }
2131 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2132 il = cvu->il_capacity;
2133 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2134 il = cvu->il_snapshot;
2135 else
2136 return;
2138 if (ci->values[0].value.boolean)
2139 ignorelist_set_invert (il, /* invert = */ 0);
2140 else
2141 ignorelist_set_invert (il, /* invert = */ 1);
2142 } /* }}} void cna_config_volume_usage_default */
2144 /* Corresponds to a <Disks /> block */
2145 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2146 cfg_disk_t *cfg_disk;
2147 int i;
2149 if ((host == NULL) || (ci == NULL))
2150 return (EINVAL);
2152 if (host->cfg_disk == NULL)
2153 {
2154 cfg_disk = malloc (sizeof (*cfg_disk));
2155 if (cfg_disk == NULL)
2156 return (ENOMEM);
2157 memset (cfg_disk, 0, sizeof (*cfg_disk));
2159 /* Set default flags */
2160 cfg_disk->flags = CFG_DISK_ALL;
2161 cfg_disk->query = NULL;
2162 cfg_disk->disks = NULL;
2164 host->cfg_disk = cfg_disk;
2165 }
2166 cfg_disk = host->cfg_disk;
2168 for (i = 0; i < ci->children_num; ++i) {
2169 oconfig_item_t *item = ci->children + i;
2171 /* if (!item || !item->key || !*item->key) continue; */
2172 if (strcasecmp(item->key, "Interval") == 0)
2173 cna_config_get_interval (item, &cfg_disk->interval);
2174 else if (strcasecmp(item->key, "GetBusy") == 0)
2175 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2176 }
2178 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2179 {
2180 NOTICE ("netapp plugin: All disk related values have been disabled. "
2181 "Collection of per-disk data will be disabled entirely.");
2182 free_cfg_disk (host->cfg_disk);
2183 host->cfg_disk = NULL;
2184 }
2186 return (0);
2187 } /* }}} int cna_config_disk */
2189 /* Corresponds to a <WAFL /> block */
2190 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2191 {
2192 cfg_wafl_t *cfg_wafl;
2193 int i;
2195 if ((host == NULL) || (ci == NULL))
2196 return (EINVAL);
2198 if (host->cfg_wafl == NULL)
2199 {
2200 cfg_wafl = malloc (sizeof (*cfg_wafl));
2201 if (cfg_wafl == NULL)
2202 return (ENOMEM);
2203 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
2205 /* Set default flags */
2206 cfg_wafl->flags = CFG_WAFL_ALL;
2208 host->cfg_wafl = cfg_wafl;
2209 }
2210 cfg_wafl = host->cfg_wafl;
2212 for (i = 0; i < ci->children_num; ++i) {
2213 oconfig_item_t *item = ci->children + i;
2215 if (strcasecmp(item->key, "Interval") == 0)
2216 cna_config_get_interval (item, &cfg_wafl->interval);
2217 else if (!strcasecmp(item->key, "GetNameCache"))
2218 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2219 else if (!strcasecmp(item->key, "GetDirCache"))
2220 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2221 else if (!strcasecmp(item->key, "GetBufferCache"))
2222 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2223 else if (!strcasecmp(item->key, "GetInodeCache"))
2224 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2225 else
2226 WARNING ("netapp plugin: The %s config option is not allowed within "
2227 "`WAFL' blocks.", item->key);
2228 }
2230 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2231 {
2232 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2233 "Collection of WAFL data will be disabled entirely.");
2234 free_cfg_wafl (host->cfg_wafl);
2235 host->cfg_wafl = NULL;
2236 }
2238 return (0);
2239 } /* }}} int cna_config_wafl */
2241 /*
2242 * <VolumeUsage>
2243 * GetCapacity "vol0"
2244 * GetCapacity "vol1"
2245 * GetCapacity "vol2"
2246 * GetCapacity "vol3"
2247 * GetCapacity "vol4"
2248 * IgnoreSelectedCapacity false
2249 *
2250 * GetSnapshot "vol0"
2251 * GetSnapshot "vol3"
2252 * GetSnapshot "vol4"
2253 * GetSnapshot "vol7"
2254 * IgnoreSelectedSnapshot false
2255 * </VolumeUsage>
2256 */
2257 /* Corresponds to a <VolumeUsage /> block */
2258 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2259 const oconfig_item_t *ci)
2260 {
2261 cfg_volume_usage_t *cfg_volume_usage;
2262 int i;
2264 if ((host == NULL) || (ci == NULL))
2265 return (EINVAL);
2267 if (host->cfg_volume_usage == NULL)
2268 {
2269 cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
2270 if (cfg_volume_usage == NULL)
2271 return (ENOMEM);
2272 memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
2274 /* Set default flags */
2275 cfg_volume_usage->query = NULL;
2276 cfg_volume_usage->volumes = NULL;
2278 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2279 if (cfg_volume_usage->il_capacity == NULL)
2280 {
2281 sfree (cfg_volume_usage);
2282 return (ENOMEM);
2283 }
2285 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2286 if (cfg_volume_usage->il_snapshot == NULL)
2287 {
2288 ignorelist_free (cfg_volume_usage->il_capacity);
2289 sfree (cfg_volume_usage);
2290 return (ENOMEM);
2291 }
2293 host->cfg_volume_usage = cfg_volume_usage;
2294 }
2295 cfg_volume_usage = host->cfg_volume_usage;
2297 for (i = 0; i < ci->children_num; ++i) {
2298 oconfig_item_t *item = ci->children + i;
2300 /* if (!item || !item->key || !*item->key) continue; */
2301 if (strcasecmp(item->key, "Interval") == 0)
2302 cna_config_get_interval (item, &cfg_volume_usage->interval);
2303 else if (!strcasecmp(item->key, "GetCapacity"))
2304 cna_config_volume_usage_option (cfg_volume_usage, item);
2305 else if (!strcasecmp(item->key, "GetSnapshot"))
2306 cna_config_volume_usage_option (cfg_volume_usage, item);
2307 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2308 cna_config_volume_usage_default (cfg_volume_usage, item);
2309 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2310 cna_config_volume_usage_default (cfg_volume_usage, item);
2311 else
2312 WARNING ("netapp plugin: The option %s is not allowed within "
2313 "`VolumeUsage' blocks.", item->key);
2314 }
2316 return (0);
2317 } /* }}} int cna_config_volume_usage */
2319 /* Corresponds to a <System /> block */
2320 static int cna_config_system (host_config_t *host, /* {{{ */
2321 oconfig_item_t *ci)
2322 {
2323 cfg_system_t *cfg_system;
2324 int i;
2326 if ((host == NULL) || (ci == NULL))
2327 return (EINVAL);
2329 if (host->cfg_system == NULL)
2330 {
2331 cfg_system = malloc (sizeof (*cfg_system));
2332 if (cfg_system == NULL)
2333 return (ENOMEM);
2334 memset (cfg_system, 0, sizeof (*cfg_system));
2336 /* Set default flags */
2337 cfg_system->flags = CFG_SYSTEM_ALL;
2338 cfg_system->query = NULL;
2340 host->cfg_system = cfg_system;
2341 }
2342 cfg_system = host->cfg_system;
2344 for (i = 0; i < ci->children_num; ++i) {
2345 oconfig_item_t *item = ci->children + i;
2347 if (strcasecmp(item->key, "Interval") == 0) {
2348 cna_config_get_interval (item, &cfg_system->interval);
2349 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2350 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2351 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2352 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2353 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2354 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2355 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2356 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2357 } else {
2358 WARNING ("netapp plugin: The %s config option is not allowed within "
2359 "`System' blocks.", item->key);
2360 }
2361 }
2363 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2364 {
2365 NOTICE ("netapp plugin: All system related values have been disabled. "
2366 "Collection of system data will be disabled entirely.");
2367 free_cfg_system (host->cfg_system);
2368 host->cfg_system = NULL;
2369 }
2371 return (0);
2372 } /* }}} int cna_config_system */
2374 /* Corresponds to a <Host /> block. */
2375 static host_config_t *cna_config_host (const oconfig_item_t *ci) /* {{{ */
2376 {
2377 oconfig_item_t *item;
2378 host_config_t *host;
2379 int status;
2380 int i;
2382 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2383 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
2384 return 0;
2385 }
2387 host = malloc(sizeof(*host));
2388 memset (host, 0, sizeof (*host));
2389 host->name = NULL;
2390 host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2391 host->host = NULL;
2392 host->username = NULL;
2393 host->password = NULL;
2394 host->srv = NULL;
2395 host->cfg_wafl = NULL;
2396 host->cfg_disk = NULL;
2397 host->cfg_volume_perf = NULL;
2398 host->cfg_volume_usage = NULL;
2399 host->cfg_system = NULL;
2401 status = cf_util_get_string (ci, &host->name);
2402 if (status != 0)
2403 {
2404 sfree (host);
2405 return (NULL);
2406 }
2408 for (i = 0; i < ci->children_num; ++i) {
2409 item = ci->children + i;
2411 status = 0;
2413 if (!strcasecmp(item->key, "Address")) {
2414 status = cf_util_get_string (item, &host->host);
2415 } else if (!strcasecmp(item->key, "Port")) {
2416 int tmp;
2418 tmp = cf_util_get_port_number (item);
2419 if (tmp > 0)
2420 host->port = tmp;
2421 } else if (!strcasecmp(item->key, "Protocol")) {
2422 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"))) {
2423 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2424 return 0;
2425 }
2426 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2427 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2428 } else if (!strcasecmp(item->key, "User")) {
2429 status = cf_util_get_string (item, &host->username);
2430 } else if (!strcasecmp(item->key, "Password")) {
2431 status = cf_util_get_string (item, &host->password);
2432 } else if (!strcasecmp(item->key, "Interval")) {
2433 status = cf_util_get_cdtime (item, &host->interval);
2434 } else if (!strcasecmp(item->key, "WAFL")) {
2435 cna_config_wafl(host, item);
2436 } else if (!strcasecmp(item->key, "Disks")) {
2437 cna_config_disk(host, item);
2438 } else if (!strcasecmp(item->key, "VolumePerf")) {
2439 cna_config_volume_performance(host, item);
2440 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2441 cna_config_volume_usage(host, item);
2442 } else if (!strcasecmp(item->key, "System")) {
2443 cna_config_system(host, item);
2444 } else {
2445 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
2446 item->key, ci->values[0].value.string);
2447 }
2449 if (status != 0)
2450 break;
2451 }
2453 if (host->host == NULL)
2454 host->host = strdup (host->name);
2456 if (host->host == NULL)
2457 status = -1;
2459 if (host->port <= 0)
2460 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2462 if ((host->username == NULL) || (host->password == NULL)) {
2463 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2464 "Ignoring host block.", host->name);
2465 status = -1;
2466 }
2468 if (status != 0)
2469 {
2470 free_host_config (host);
2471 return (NULL);
2472 }
2474 return host;
2475 } /* }}} host_config_t *cna_config_host */
2477 /*
2478 * Callbacks registered with the daemon
2479 *
2480 * Pretty standard stuff here.
2481 */
2482 static int cna_init_host (host_config_t *host) /* {{{ */
2483 {
2484 if (host == NULL)
2485 return (EINVAL);
2487 if (host->srv != NULL)
2488 return (0);
2490 /* Request version 1.1 of the ONTAP API */
2491 host->srv = na_server_open(host->host,
2492 /* major version = */ 1, /* minor version = */ 1);
2493 if (host->srv == NULL) {
2494 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
2495 return (-1);
2496 }
2498 na_server_set_transport_type(host->srv, host->protocol,
2499 /* transportarg = */ NULL);
2500 na_server_set_port(host->srv, host->port);
2501 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
2502 na_server_adminuser(host->srv, host->username, host->password);
2503 na_server_set_timeout(host->srv, 5 /* seconds */);
2505 return (0);
2506 } /* }}} int cna_init_host */
2508 static int cna_init (void) /* {{{ */
2509 {
2510 char err[256];
2512 memset (err, 0, sizeof (err));
2513 if (!na_startup(err, sizeof(err))) {
2514 err[sizeof (err) - 1] = 0;
2515 ERROR("netapp plugin: Error initializing netapp API: %s", err);
2516 return 1;
2517 }
2519 return (0);
2520 } /* }}} cna_init */
2522 static int cna_read_internal (host_config_t *host) { /* {{{ */
2523 int status;
2525 status = cna_query_wafl (host);
2526 if (status != 0)
2527 return (status);
2529 status = cna_query_disk (host);
2530 if (status != 0)
2531 return (status);
2533 status = cna_query_volume_perf (host);
2534 if (status != 0)
2535 return (status);
2537 status = cna_query_volume_usage (host);
2538 if (status != 0)
2539 return (status);
2541 status = cna_query_system (host);
2542 if (status != 0)
2543 return (status);
2545 return 0;
2546 } /* }}} int cna_read_internal */
2548 static int cna_read (user_data_t *ud) { /* {{{ */
2549 host_config_t *host;
2550 int status;
2552 if ((ud == NULL) || (ud->data == NULL))
2553 return (-1);
2555 host = ud->data;
2557 status = cna_init_host (host);
2558 if (status != 0)
2559 return (status);
2561 status = cna_read_internal (host);
2562 if (status != 0)
2563 {
2564 if (host->srv != NULL)
2565 na_server_close (host->srv);
2566 host->srv = NULL;
2567 }
2569 return 0;
2570 } /* }}} int cna_read */
2572 static int cna_config (oconfig_item_t *ci) { /* {{{ */
2573 int i;
2574 oconfig_item_t *item;
2576 for (i = 0; i < ci->children_num; ++i) {
2577 item = ci->children + i;
2579 if (strcasecmp(item->key, "Host") == 0)
2580 {
2581 host_config_t *host;
2582 char cb_name[256];
2583 struct timespec interval;
2584 user_data_t ud;
2586 host = cna_config_host (item);
2587 if (host == NULL)
2588 continue;
2590 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name);
2592 CDTIME_T_TO_TIMESPEC (host->interval, &interval);
2594 memset (&ud, 0, sizeof (ud));
2595 ud.data = host;
2596 ud.free_func = (void (*) (void *)) free_host_config;
2598 plugin_register_complex_read (/* group = */ NULL, cb_name,
2599 /* callback = */ cna_read,
2600 /* interval = */ (host->interval > 0) ? &interval : NULL,
2601 /* user data = */ &ud);
2602 continue;
2603 }
2604 else /* if (item->key != "Host") */
2605 {
2606 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
2607 }
2608 }
2609 return 0;
2610 } /* }}} int cna_config */
2612 static int cna_shutdown (void) /* {{{ */
2613 {
2614 /* Clean up system resources and stuff. */
2615 na_shutdown ();
2617 return (0);
2618 } /* }}} int cna_shutdown */
2620 void module_register(void) {
2621 plugin_register_complex_config("netapp", cna_config);
2622 plugin_register_init("netapp", cna_init);
2623 plugin_register_shutdown("netapp", cna_shutdown);
2624 }
2626 /* vim: set sw=2 ts=2 noet fdm=marker : */