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 <sven.trenkel at noris.net>
30 #include <netapp_api.h>
32 typedef struct host_config_s host_config_t;
33 typedef void service_handler_t(host_config_t *host, na_elem_t *result, void *data);
35 #define PERF_SYSTEM_CPU 0x01
36 #define PERF_SYSTEM_NET 0x02
37 #define PERF_SYSTEM_OPS 0x04
38 #define PERF_SYSTEM_DISK 0x08
39 #define PERF_SYSTEM_ALL 0x0F
42 * \brief Persistent data for system performence counters
47 uint64_t last_cpu_busy;
48 uint64_t last_cpu_total;
52 * \brief Persistent data for WAFL performence counters. (a.k.a. cache performence)
55 #define PERF_WAFL_NAME_CACHE 0x01
56 #define PERF_WAFL_DIR_CACHE 0x02
57 #define PERF_WAFL_BUF_CACHE 0x04
58 #define PERF_WAFL_INODE_CACHE 0x08
59 #define PERF_WAFL_ALL 0x0F
63 uint64_t last_name_cache_hit;
64 uint64_t last_name_cache_miss;
65 uint64_t last_find_dir_hit;
66 uint64_t last_find_dir_miss;
67 uint64_t last_buf_hash_hit;
68 uint64_t last_buf_hash_miss;
69 uint64_t last_inode_cache_hit;
70 uint64_t last_inode_cache_miss;
73 #define PERF_VOLUME_INIT 0x01
74 #define PERF_VOLUME_IO 0x02
75 #define PERF_VOLUME_OPS 0x03
76 #define PERF_VOLUME_LATENCY 0x08
77 #define PERF_VOLUME_ALL 0x0F
87 #define PERF_DISK_BUSIEST 0x01
88 #define PERF_DISK_ALL 0x01
96 time_t last_timestamp;
97 uint64_t last_read_latency;
98 uint64_t last_write_latency;
99 uint64_t last_read_ops;
100 uint64_t last_write_ops;
101 } per_volume_perf_data_t;
103 #define VOLUME_INIT 0x01
104 #define VOLUME_DF 0x02
105 #define VOLUME_SNAP 0x04
113 double last_disk_busy_percent;
114 uint64_t last_disk_busy;
115 uint64_t last_base_for_disk_busy;
116 } per_disk_perf_data_t;
118 typedef struct service_config_s {
120 service_handler_t *handler;
125 struct service_config_s *next;
128 #define SERVICE_INIT {0, 0, 1, 1, 0, 0, 0}
130 typedef struct volume_s {
132 per_volume_perf_data_t perf_data;
133 per_volume_data_t volume_data;
134 struct volume_s *next;
138 * \brief A disk in the netapp.
140 * A disk doesn't have any more information than its name atm.
141 * The name includes the "disk_" prefix.
144 typedef struct disk_s {
146 per_disk_perf_data_t perf_data;
150 #define DISK_INIT {0, {0, 0, 0, 0}, 0}
152 struct host_config_s {
155 na_server_transport_t protocol;
161 service_config_t *services;
164 struct host_config_s *next;
167 #define HOST_INIT {0, 0, NA_SERVER_TRANSPORT_HTTPS, 0, 0, 0, 0, 10, 0, 0, 0}
169 static host_config_t *host_config;
171 static volume_t *get_volume(host_config_t *host, const char *name) {
174 for (v = host->volumes; v; v = v->next) {
175 if (!strcmp(v->name/* + 4*/, name)) return v;
177 v = malloc(sizeof(*v));
178 v->name = strdup(name);
179 // v->name = malloc(strlen(name) + 5);
180 // strcpy(v->name, "vol-");
181 // strcpy(v->name + 4, name);
182 v->perf_data.flags = 0;
183 v->volume_data.flags = 0;
184 v->next = host->volumes;
189 static disk_t *get_disk(host_config_t *host, const char *name) {
190 disk_t *v, init = DISK_INIT;
192 for (v = host->disks; v; v = v->next) {
193 if (!strcmp(v->name/* + 5*/, name)) return v;
195 v = malloc(sizeof(*v));
197 v->name = strdup(name);
198 // v->name = malloc(strlen(name) + 6);
199 // strcpy(v->name, "disk-");
200 // strcpy(v->name + 5, name);
201 v->next = host->disks;
206 static void collect_perf_wafl_data(host_config_t *host, na_elem_t *out, void *data) {
207 perf_wafl_data_t *wafl = data;
208 uint64_t name_cache_hit = 0, name_cache_miss = 0, find_dir_hit = 0, find_dir_miss = 0, buf_hash_hit = 0, buf_hash_miss = 0, inode_cache_hit = 0, inode_cache_miss = 0;
209 const char *instance, *name;
213 value_list_t vl = VALUE_LIST_INIT;
215 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
216 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
217 instance = na_child_get_string(out, "name");
219 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
220 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
221 name = na_child_get_string(counter, "name");
222 if (!strcmp(name, "name_cache_hit")) {
223 name_cache_hit = na_child_get_uint64(counter, "value", 0);
224 } else if (!strcmp(name, "name_cache_miss")) {
225 name_cache_miss = na_child_get_uint64(counter, "value", 0);
226 } else if (!strcmp(name, "find_dir_hit")) {
227 find_dir_hit = na_child_get_uint64(counter, "value", 0);
228 } else if (!strcmp(name, "find_dir_miss")) {
229 find_dir_miss = na_child_get_uint64(counter, "value", 0);
230 } else if (!strcmp(name, "buf_hash_hit")) {
231 buf_hash_hit = na_child_get_uint64(counter, "value", 0);
232 } else if (!strcmp(name, "buf_hash_miss")) {
233 buf_hash_miss = na_child_get_uint64(counter, "value", 0);
234 } else if (!strcmp(name, "inode_cache_hit")) {
235 inode_cache_hit = na_child_get_uint64(counter, "value", 0);
236 } else if (!strcmp(name, "inode_cache_miss")) {
237 inode_cache_miss = na_child_get_uint64(counter, "value", 0);
240 if ((wafl->flags & PERF_WAFL_NAME_CACHE) && name_cache_hit && name_cache_miss) {
242 if (name_cache_miss - wafl->last_name_cache_miss + name_cache_hit - wafl->last_name_cache_hit) values[0].gauge = 100.0 * (name_cache_hit - wafl->last_name_cache_hit) / (name_cache_miss - wafl->last_name_cache_miss + name_cache_hit - wafl->last_name_cache_hit);
246 vl.interval = interval_g;
247 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
248 sstrncpy(vl.host, host->name, sizeof(vl.host));
249 sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
250 sstrncpy(vl.type_instance, "name_cache_hit", sizeof(vl.type_instance));
251 if (wafl->last_name_cache_hit && wafl->last_name_cache_miss) {
252 DEBUG("%s/netapp-%s/cache_ratio: %lf", host->name, instance, values[0].gauge);
253 plugin_dispatch_values ("cache_ratio", &vl);
255 wafl->last_name_cache_hit = name_cache_hit;
256 wafl->last_name_cache_miss = name_cache_miss;
258 if ((wafl->flags & PERF_WAFL_DIR_CACHE) && find_dir_hit && find_dir_miss) {
260 if (find_dir_miss - wafl->last_find_dir_miss + find_dir_hit - wafl->last_find_dir_hit) values[0].gauge = 100.0 * (find_dir_hit - wafl->last_find_dir_hit) / (find_dir_miss - wafl->last_find_dir_miss + find_dir_hit - wafl->last_find_dir_hit);
264 vl.interval = interval_g;
265 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
266 sstrncpy(vl.host, host->name, sizeof(vl.host));
267 sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
268 sstrncpy(vl.type_instance, "find_dir_hit", sizeof(vl.type_instance));
269 if (wafl->last_find_dir_hit && wafl->last_find_dir_miss) {
270 DEBUG("%s/netapp-%s/cache_ratio: %lf", host->name, instance, values[0].gauge);
271 plugin_dispatch_values ("cache_ratio", &vl);
273 wafl->last_find_dir_hit = find_dir_hit;
274 wafl->last_find_dir_miss = find_dir_miss;
276 if ((wafl->flags & PERF_WAFL_BUF_CACHE) && buf_hash_hit && buf_hash_miss) {
278 if (buf_hash_miss - wafl->last_buf_hash_miss + buf_hash_hit - wafl->last_buf_hash_hit) values[0].gauge = 100.0 * (buf_hash_hit - wafl->last_buf_hash_hit) / (buf_hash_miss - wafl->last_buf_hash_miss + buf_hash_hit - wafl->last_buf_hash_hit);
282 vl.interval = interval_g;
283 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
284 sstrncpy(vl.host, host->name, sizeof(vl.host));
285 sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
286 sstrncpy(vl.type_instance, "buf_hash_hit", sizeof(vl.type_instance));
287 if (wafl->last_buf_hash_hit && wafl->last_buf_hash_miss) {
288 DEBUG("%s/netapp-%s/cache_ratio: %lf", host->name, instance, values[0].gauge);
289 plugin_dispatch_values ("cache_ratio", &vl);
291 wafl->last_buf_hash_hit = buf_hash_hit;
292 wafl->last_buf_hash_miss = buf_hash_miss;
294 if ((wafl->flags & PERF_WAFL_INODE_CACHE) && inode_cache_hit && inode_cache_miss) {
296 if (inode_cache_miss - wafl->last_inode_cache_miss + inode_cache_hit - wafl->last_inode_cache_hit) values[0].gauge = 100.0 * (inode_cache_hit - wafl->last_inode_cache_hit) / (inode_cache_miss - wafl->last_inode_cache_miss + inode_cache_hit - wafl->last_inode_cache_hit);
300 vl.interval = interval_g;
301 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
302 sstrncpy(vl.host, host->name, sizeof(vl.host));
303 sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
304 sstrncpy(vl.type_instance, "inode_cache_hit", sizeof(vl.type_instance));
305 if (wafl->last_inode_cache_hit && wafl->last_inode_cache_miss) {
306 DEBUG("%s/netapp-%s/cache_ratio: %lf", host->name, instance, values[0].gauge);
307 plugin_dispatch_values ("cache_ratio", &vl);
309 wafl->last_inode_cache_hit = inode_cache_hit;
310 wafl->last_inode_cache_miss = inode_cache_miss;
314 static void collect_perf_disk_data(host_config_t *host, na_elem_t *out, void *data) {
315 perf_disk_data_t *perf = data;
318 na_elem_t *counter, *inst;
319 disk_t *disk, *worst_disk = 0;
321 value_list_t vl = VALUE_LIST_INIT;
323 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
324 out = na_elem_child(out, "instances");
325 na_elem_iter_t inst_iter = na_child_iterator(out);
326 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
327 uint64_t disk_busy = 0, base_for_disk_busy = 0;
329 disk = get_disk(host, na_child_get_string(inst, "name"));
330 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
331 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
332 name = na_child_get_string(counter, "name");
333 if (!strcmp(name, "disk_busy")) {
334 disk_busy = na_child_get_uint64(counter, "value", 0);
335 } else if (!strcmp(name, "base_for_disk_busy")) {
336 base_for_disk_busy = na_child_get_uint64(counter, "value", 0);
339 if (disk_busy && base_for_disk_busy) {
340 disk->perf_data.last_update = timestamp;
341 disk->perf_data.last_disk_busy_percent = 0;
342 if (base_for_disk_busy - disk->perf_data.last_base_for_disk_busy) disk->perf_data.last_disk_busy_percent = 100.0 * (disk_busy - disk->perf_data.last_disk_busy) / (base_for_disk_busy - disk->perf_data.last_base_for_disk_busy);
343 if (disk->perf_data.last_disk_busy && disk->perf_data.last_base_for_disk_busy && (!worst_disk || worst_disk->perf_data.last_disk_busy_percent < disk->perf_data.last_disk_busy_percent)) worst_disk = disk;
344 disk->perf_data.last_disk_busy = disk_busy;
345 disk->perf_data.last_base_for_disk_busy = base_for_disk_busy;
348 if ((perf->flags & PERF_DISK_BUSIEST) && worst_disk) {
349 values[0].gauge = worst_disk->perf_data.last_disk_busy_percent;
353 vl.interval = interval_g;
354 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
355 sstrncpy(vl.host, host->name, sizeof(vl.host));
356 sstrncpy(vl.plugin_instance, "system", sizeof(vl.plugin_instance));
357 sstrncpy(vl.type_instance, "disk_busy", sizeof(vl.type_instance));
358 DEBUG("%s/netapp-system/percent-disk_busy: %lf", host->name, worst_disk->perf_data.last_disk_busy_percent);
359 plugin_dispatch_values ("percent", &vl);
363 static void collect_volume_data(host_config_t *host, na_elem_t *out, void *data) {
364 na_elem_t *inst, *sis;
366 volume_data_t *volume_data = data;
368 value_list_t vl = VALUE_LIST_INIT;
370 out = na_elem_child(out, "volumes");
371 na_elem_iter_t inst_iter = na_child_iterator(out);
372 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
373 uint64_t size_free = 0, size_used = 0, snap_reserved = 0, sis_saved = 0;
374 volume = get_volume(host, na_child_get_string(inst, "name"));
375 if (!(volume->volume_data.flags & VOLUME_INIT)) volume->volume_data.flags = volume_data->flags;
376 if (!(volume->volume_data.flags & VOLUME_DF)) continue;
377 size_free = na_child_get_uint64(inst, "size-available", 0);
378 size_used = na_child_get_uint64(inst, "size-used", 0);
379 snap_reserved = na_child_get_uint64(inst, "snapshot-blocks-reserved", 0) * 1024;
384 vl.interval = interval_g;
385 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
386 sstrncpy(vl.host, host->name, sizeof(vl.host));
387 sstrncpy(vl.plugin_instance, volume->name, sizeof(vl.plugin_instance));
389 values[0].gauge = size_used;
390 sstrncpy(vl.type_instance, "used", sizeof(vl.type_instance));
391 DEBUG("%s/netapp-%s/df_complex-used: %llu", host->name, volume->name, size_used);
392 plugin_dispatch_values ("df_complex", &vl);
394 values[0].gauge = size_free;
395 sstrncpy(vl.type_instance, "free", sizeof(vl.type_instance));
396 DEBUG("%s/netapp-%s/df_complex-free: %llu", host->name, volume->name, size_free);
397 plugin_dispatch_values ("df_complex", &vl);
400 values[0].gauge = snap_reserved;
401 sstrncpy(vl.type_instance, "snap_reserved", sizeof(vl.type_instance));
402 DEBUG("%s/netapp-%s/df_complex-snap_reserved: %llu", host->name, volume->name, snap_reserved);
403 plugin_dispatch_values ("df_complex", &vl);
406 sis = na_elem_child(inst, "sis");
407 if (sis && !strcmp(na_child_get_string(sis, "state"), "enabled")) {
408 uint64_t sis_saved_reported = na_child_get_uint64(sis, "size-saved", 0), sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", 0);
409 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
410 if (sis_saved_reported >> 32) {
411 /* In case they ever fix this bug. */
412 sis_saved = sis_saved_reported;
414 uint64_t real_saved = sis_saved_percent * size_used / (100 - sis_saved_percent);
415 uint64_t overflow_guess = real_saved >> 32;
416 uint64_t guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
417 uint64_t guess2 = (overflow_guess << 32) + sis_saved_reported;
418 uint64_t guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
420 if (real_saved < guess2) {
421 if (real_saved - guess1 < guess2 - real_saved) sis_saved = guess1;
422 else sis_saved = guess2;
424 if (real_saved - guess2 < guess3 - real_saved) sis_saved = guess2;
425 else sis_saved = guess3;
428 values[0].gauge = sis_saved;
429 sstrncpy(vl.type_instance, "sis_saved", sizeof(vl.type_instance));
430 DEBUG("%s/netapp-%s/df_complex-sis_saved: %llu", host->name, volume->name, sis_saved);
431 plugin_dispatch_values ("df_complex", &vl);
436 static void collect_perf_volume_data(host_config_t *host, na_elem_t *out, void *data) {
437 perf_volume_data_t *perf = data;
440 na_elem_t *counter, *inst;
443 value_list_t vl = VALUE_LIST_INIT;
445 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
446 out = na_elem_child(out, "instances");
447 na_elem_iter_t inst_iter = na_child_iterator(out);
448 for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
449 uint64_t read_data = 0, write_data = 0, read_ops = 0, write_ops = 0, read_latency = 0, write_latency = 0;
451 volume = get_volume(host, na_child_get_string(inst, "name"));
452 if (!volume->perf_data.flags) {
453 volume->perf_data.flags = perf->flags;
454 volume->perf_data.last_read_latency = volume->perf_data.last_read_ops = 0;
455 volume->perf_data.last_write_latency = volume->perf_data.last_write_ops = 0;
457 na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
458 for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
459 name = na_child_get_string(counter, "name");
460 if (!strcmp(name, "read_ops")) {
461 read_ops = na_child_get_uint64(counter, "value", 0);
462 } else if (!strcmp(name, "write_ops")) {
463 write_ops = na_child_get_uint64(counter, "value", 0);
464 } else if (!strcmp(name, "read_data")) {
465 read_data = na_child_get_uint64(counter, "value", 0);
466 } else if (!strcmp(name, "write_data")) {
467 write_data = na_child_get_uint64(counter, "value", 0);
468 } else if (!strcmp(name, "read_latency")) {
469 read_latency = na_child_get_uint64(counter, "value", 0);
470 } else if (!strcmp(name, "write_latency")) {
471 write_latency = na_child_get_uint64(counter, "value", 0);
474 if (read_ops && write_ops) {
475 values[0].counter = read_ops;
476 values[1].counter = write_ops;
480 vl.interval = interval_g;
481 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
482 sstrncpy(vl.host, host->name, sizeof(vl.host));
483 sstrncpy(vl.plugin_instance, volume->name, sizeof(vl.plugin_instance));
484 vl.type_instance[0] = 0;
485 if (volume->perf_data.flags & PERF_VOLUME_OPS) {
486 /* We might need the data even if it wasn't configured to calculate
487 the latency. Therefore we just skip the dispatch. */
488 DEBUG("%s/netapp-%s/disk_ops: %llu %llu", host->name, instance, read_ops, write_ops);
489 plugin_dispatch_values("disk_ops", &vl);
491 if ((volume->perf_data.flags & PERF_VOLUME_LATENCY) && read_latency && write_latency) {
493 if (read_ops - volume->perf_data.last_read_ops) values[0].gauge = (read_latency - volume->perf_data.last_read_latency) * (timestamp - volume->perf_data.last_timestamp) / (read_ops - volume->perf_data.last_read_ops);
495 if (write_ops - volume->perf_data.last_write_ops) values[1].gauge = (write_latency - volume->perf_data.last_write_latency) * (timestamp - volume->perf_data.last_timestamp) / (write_ops - volume->perf_data.last_write_ops);
499 vl.interval = interval_g;
500 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
501 sstrncpy(vl.host, host->name, sizeof(vl.host));
502 sstrncpy(vl.plugin_instance, volume->name, sizeof(vl.plugin_instance));
503 vl.type_instance[0] = 0;
504 if (volume->perf_data.last_read_ops && volume->perf_data.last_write_ops) {
505 DEBUG("%s/netapp-%s/disk_latency: lrlc: %llu ro: %llu lro: %llu rl: %llu lrl: %llu %llu %llu", host->name, instance, volume->perf_data.last_read_latency_counter, read_ops, volume->perf_data.last_read_ops, read_latency, volume->perf_data.last_read_latency, values[0].counter, values[1].counter);
506 plugin_dispatch_values("disk_latency", &vl);
508 volume->perf_data.last_timestamp = timestamp;
509 volume->perf_data.last_read_latency = read_latency;
510 volume->perf_data.last_read_ops = read_ops;
511 volume->perf_data.last_write_latency = write_latency;
512 volume->perf_data.last_write_ops = write_ops;
515 if ((volume->perf_data.flags & PERF_VOLUME_IO) && read_data && write_data) {
516 values[0].counter = read_data;
517 values[1].counter = write_data;
521 vl.interval = interval_g;
522 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
523 sstrncpy(vl.host, host->name, sizeof(vl.host));
524 sstrncpy(vl.plugin_instance, volume->name, sizeof(vl.plugin_instance));
525 vl.type_instance[0] = 0;
526 DEBUG("%s/netapp-%s/disk_octets: %llu %llu", host->name, instance, read_data, write_data);
527 plugin_dispatch_values ("disk_octets", &vl);
532 static void collect_perf_system_data(host_config_t *host, na_elem_t *out, void *data) {
533 uint64_t disk_read = 0, disk_written = 0, net_recv = 0, net_sent = 0, cpu_busy = 0, cpu_total = 0;
534 perf_system_data_t *perf = data;
535 const char *instance, *name;
539 value_list_t vl = VALUE_LIST_INIT;
541 timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
542 out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
543 instance = na_child_get_string(out, "name");
545 na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
546 for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
547 name = na_child_get_string(counter, "name");
548 if (!strcmp(name, "disk_data_read")) {
549 disk_read = na_child_get_uint64(counter, "value", 0) * 1024;
550 } else if (!strcmp(name, "disk_data_written")) {
551 disk_written = na_child_get_uint64(counter, "value", 0) * 1024;
552 } else if (!strcmp(name, "net_data_recv")) {
553 net_recv = na_child_get_uint64(counter, "value", 0) * 1024;
554 } else if (!strcmp(name, "net_data_sent")) {
555 net_sent = na_child_get_uint64(counter, "value", 0) * 1024;
556 } else if (!strcmp(name, "cpu_busy")) {
557 cpu_busy = na_child_get_uint64(counter, "value", 0);
558 } else if (!strcmp(name, "cpu_elapsed_time")) {
559 cpu_total = na_child_get_uint64(counter, "value", 0);
560 } else if ((perf->flags & PERF_SYSTEM_OPS) && strlen(name) > 4 && !strcmp(name + strlen(name) - 4, "_ops")) {
561 values[0].counter = na_child_get_uint64(counter, "value", 0);
562 if (!values[0].counter) continue;
566 vl.interval = interval_g;
567 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
568 sstrncpy(vl.host, host->name, sizeof(vl.host));
569 sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
570 sstrncpy(vl.type_instance, name, sizeof(vl.plugin_instance));
571 DEBUG("%s/netapp-%s/disk_ops_complex-%s: %llu", host->name, instance, name, values[0].counter);
572 plugin_dispatch_values ("disk_ops_complex", &vl);
575 if ((perf->flags & PERF_SYSTEM_DISK) && disk_read && disk_written) {
576 values[0].counter = disk_read;
577 values[1].counter = disk_written;
581 vl.interval = interval_g;
582 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
583 sstrncpy(vl.host, host->name, sizeof(vl.host));
584 sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
585 vl.type_instance[0] = 0;
586 DEBUG("%s/netapp-%s/disk_octets: %llu %llu", host->name, instance, disk_read, disk_written);
587 plugin_dispatch_values ("disk_octets", &vl);
589 if ((perf->flags & PERF_SYSTEM_NET) && net_recv && net_sent) {
590 values[0].counter = net_recv;
591 values[1].counter = net_sent;
595 vl.interval = interval_g;
596 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
597 sstrncpy(vl.host, host->name, sizeof(vl.host));
598 sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
599 vl.type_instance[0] = 0;
600 DEBUG("%s/netapp-%s/if_octects: %llu %llu", host->name, instance, net_recv, net_sent);
601 plugin_dispatch_values ("if_octets", &vl);
603 if ((perf->flags & PERF_SYSTEM_CPU) && cpu_busy && cpu_total) {
604 // values[0].gauge = (double) (cpu_busy - perf->last_cpu_busy) / (cpu_total - perf->last_cpu_total) * 100;
605 values[0].counter = cpu_busy / 10000;
609 vl.interval = interval_g;
610 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
611 sstrncpy(vl.host, host->name, sizeof(vl.host));
612 sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
613 sstrncpy(vl.type_instance, "system", sizeof(vl.plugin_instance));
614 // if (perf->last_cpu_busy && perf->last_cpu_total) printf("CPU: busy: %lf - idle: %lf\n", values[0].gauge, 100.0 - values[0].gauge);
615 // if (perf->last_cpu_busy && perf->last_cpu_total) plugin_dispatch_values ("cpu", &vl);
616 DEBUG("%s/netapp-%s/cpu: busy: %llu - idle: %llu", host->name, instance, cpu_busy / 10000, cpu_total / 10000);
617 plugin_dispatch_values ("cpu", &vl);
619 // values[0].gauge = 100.0 - (double) (cpu_busy - perf->last_cpu_busy) / (cpu_total - perf->last_cpu_total) * 100;
620 values[0].counter = (cpu_total - cpu_busy) / 10000;
624 vl.interval = interval_g;
625 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
626 sstrncpy(vl.host, host->name, sizeof(vl.host));
627 sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
628 sstrncpy(vl.type_instance, "idle", sizeof(vl.plugin_instance));
629 // if (perf->last_cpu_busy && perf->last_cpu_total) plugin_dispatch_values ("cpu", &vl);
630 plugin_dispatch_values ("cpu", &vl);
632 perf->last_cpu_busy = cpu_busy;
633 perf->last_cpu_total = cpu_total;
641 service_config_t *service;
644 WARNING("netapp plugin: Plugin loaded but no hosts defined.");
648 if (!na_startup(err, sizeof(err))) {
649 ERROR("netapp plugin: Error initializing netapp API: %s", err);
653 for (host = host_config; host; host = host->next) {
654 host->srv = na_server_open(host->host, 1, 1);
655 na_server_set_transport_type(host->srv, host->protocol, 0);
656 na_server_set_port(host->srv, host->port);
657 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
658 na_server_adminuser(host->srv, host->username, host->password);
659 na_server_set_timeout(host->srv, 5);
660 for (service = host->services; service; service = service->next) {
661 service->interval = host->interval * service->multiplier;
662 if (service->handler == collect_perf_system_data) {
663 service->query = na_elem_new("perf-object-get-instances");
664 na_child_add_string(service->query, "objectname", "system");
665 } else if (service->handler == collect_perf_volume_data) {
666 service->query = na_elem_new("perf-object-get-instances");
667 na_child_add_string(service->query, "objectname", "volume");
668 /* e = na_elem_new("instances");
669 na_child_add_string(e, "foo", "system");
670 na_child_add(root, e);*/
671 e = na_elem_new("counters");
672 na_child_add_string(e, "foo", "read_ops");
673 na_child_add_string(e, "foo", "write_ops");
674 na_child_add_string(e, "foo", "read_data");
675 na_child_add_string(e, "foo", "write_data");
676 na_child_add_string(e, "foo", "read_latency");
677 na_child_add_string(e, "foo", "write_latency");
678 na_child_add(service->query, e);
679 } else if (service->handler == collect_perf_wafl_data) {
680 service->query = na_elem_new("perf-object-get-instances");
681 na_child_add_string(service->query, "objectname", "wafl");
682 /* e = na_elem_new("instances");
683 na_child_add_string(e, "foo", "system");
684 na_child_add(root, e);*/
685 e = na_elem_new("counters");
686 na_child_add_string(e, "foo", "name_cache_hit");
687 na_child_add_string(e, "foo", "name_cache_miss");
688 na_child_add_string(e, "foo", "find_dir_hit");
689 na_child_add_string(e, "foo", "find_dir_miss");
690 na_child_add_string(e, "foo", "buf_hash_hit");
691 na_child_add_string(e, "foo", "buf_hash_miss");
692 na_child_add_string(e, "foo", "inode_cache_hit");
693 na_child_add_string(e, "foo", "inode_cache_miss");
694 // na_child_add_string(e, "foo", "inode_eject_time");
695 // na_child_add_string(e, "foo", "buf_eject_time");
696 na_child_add(service->query, e);
697 } else if (service->handler == collect_perf_disk_data) {
698 service->query = na_elem_new("perf-object-get-instances");
699 na_child_add_string(service->query, "objectname", "disk");
700 e = na_elem_new("counters");
701 na_child_add_string(e, "foo", "disk_busy");
702 na_child_add_string(e, "foo", "base_for_disk_busy");
703 na_child_add(service->query, e);
704 } else if (service->handler == collect_volume_data) {
705 service->query = na_elem_new("volume-list-info");
706 // na_child_add_string(service->query, "objectname", "volume");
707 // } else if (service->handler == collect_snapshot_data) {
708 // service->query = na_elem_new("snapshot-list-info");
715 static void set_global_perf_vol_flag(const host_config_t *host, uint32_t flag, int value) {
718 for (v = host->volumes; v; v = v->next) {
719 v->perf_data.flags &= ~flag;
720 if (value) v->perf_data.flags |= flag;
724 static void set_global_vol_flag(const host_config_t *host, uint32_t flag, int value) {
727 for (v = host->volumes; v; v = v->next) {
728 v->volume_data.flags &= ~flag;
729 if (value) v->volume_data.flags |= flag;
733 static void process_perf_volume_flag(host_config_t *host, perf_volume_data_t *perf_volume, const oconfig_item_t *item, uint32_t flag) {
736 for (n = 0; n < item->values_num; ++n) {
738 const char *name = item->values[n].value.string;
740 if (item->values[n].type != OCONFIG_TYPE_STRING) {
741 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolPerfData\" block for host %s", host->name);
744 if (name[0] == '+') {
746 } else if (name[0] == '-') {
751 perf_volume->flags &= ~flag;
752 if (!minus) perf_volume->flags |= flag;
753 set_global_perf_vol_flag(host, flag, !minus);
756 v = get_volume(host, name);
757 if (!v->perf_data.flags) {
758 v->perf_data.flags = perf_volume->flags;
759 v->perf_data.last_read_latency = v->perf_data.last_read_ops = 0;
760 v->perf_data.last_write_latency = v->perf_data.last_write_ops = 0;
762 v->perf_data.flags &= ~flag;
763 if (!minus) v->perf_data.flags |= flag;
767 static void process_volume_flag(host_config_t *host, volume_data_t *volume_data, const oconfig_item_t *item, uint32_t flag) {
770 for (n = 0; n < item->values_num; ++n) {
772 const char *name = item->values[n].value.string;
774 if (item->values[n].type != OCONFIG_TYPE_STRING) {
775 WARNING("netapp plugin: Ignoring non-string argument in \"GetVolData\" block for host %s", host->name);
778 if (name[0] == '+') {
780 } else if (name[0] == '-') {
785 volume_data->flags &= ~flag;
786 if (!minus) volume_data->flags |= flag;
787 set_global_vol_flag(host, flag, !minus);
790 v = get_volume(host, name);
791 if (!v->volume_data.flags) v->volume_data.flags = volume_data->flags;
792 v->volume_data.flags &= ~flag;
793 if (!minus) v->volume_data.flags |= flag;
797 static void build_perf_vol_config(host_config_t *host, const oconfig_item_t *ci) {
798 int i, had_io = 0, had_ops = 0, had_latency = 0;
799 service_config_t *service;
800 perf_volume_data_t *perf_volume;
802 service = malloc(sizeof(*service));
804 service->handler = collect_perf_volume_data;
805 perf_volume = service->data = malloc(sizeof(*perf_volume));
806 perf_volume->flags = PERF_VOLUME_INIT;
807 service->next = host->services;
808 host->services = service;
809 for (i = 0; i < ci->children_num; ++i) {
810 oconfig_item_t *item = ci->children + i;
812 // if (!item || !item->key || !*item->key) continue;
813 if (!strcasecmp(item->key, "Multiplier")) {
814 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 < 1) {
815 WARNING("netapp plugin: \"Multiplier\" of host %s service GetVolPerfData needs exactly one positive integer argument.", host->name);
818 service->skip_countdown = service->multiplier = item->values[0].value.number;
819 } else if (!strcasecmp(item->key, "GetIO")) {
821 process_perf_volume_flag(host, perf_volume, item, PERF_VOLUME_IO);
822 } else if (!strcasecmp(item->key, "GetOps")) {
824 process_perf_volume_flag(host, perf_volume, item, PERF_VOLUME_OPS);
825 } else if (!strcasecmp(item->key, "GetLatency")) {
827 process_perf_volume_flag(host, perf_volume, item, PERF_VOLUME_LATENCY);
831 perf_volume->flags |= PERF_VOLUME_IO;
832 set_global_perf_vol_flag(host, PERF_VOLUME_IO, 1);
835 perf_volume->flags |= PERF_VOLUME_OPS;
836 set_global_perf_vol_flag(host, PERF_VOLUME_OPS, 1);
839 perf_volume->flags |= PERF_VOLUME_LATENCY;
840 set_global_perf_vol_flag(host, PERF_VOLUME_LATENCY, 1);
844 static void build_volume_config(host_config_t *host, oconfig_item_t *ci) {
846 service_config_t *service;
847 volume_data_t *volume_data;
849 service = malloc(sizeof(*service));
851 service->handler = collect_volume_data;
852 volume_data = service->data = malloc(sizeof(*volume_data));
853 volume_data->flags = VOLUME_INIT;
854 service->next = host->services;
855 host->services = service;
856 for (i = 0; i < ci->children_num; ++i) {
857 oconfig_item_t *item = ci->children + i;
859 // if (!item || !item->key || !*item->key) continue;
860 if (!strcasecmp(item->key, "Multiplier")) {
861 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 < 1) {
862 WARNING("netapp plugin: \"Multiplier\" of host %s service GetVolPerfData needs exactly one positive integer argument.", host->name);
865 service->skip_countdown = service->multiplier = item->values[0].value.number;
866 } else if (!strcasecmp(item->key, "GetDiskUtil")) {
868 process_volume_flag(host, volume_data, item, VOLUME_DF);
872 volume_data->flags |= VOLUME_DF;
873 set_global_vol_flag(host, VOLUME_DF, 1);
875 /* service = malloc(sizeof(*service));
877 service->handler = collect_snapshot_data;
878 service->data = volume_data;
879 service->next = temp->services;
880 temp->services = service;*/
883 static void build_perf_disk_config(host_config_t *temp, oconfig_item_t *ci) {
885 service_config_t *service;
886 perf_disk_data_t *perf_disk;
888 service = malloc(sizeof(*service));
890 service->handler = collect_perf_disk_data;
891 perf_disk = service->data = malloc(sizeof(*perf_disk));
892 perf_disk->flags = PERF_DISK_ALL;
893 service->next = temp->services;
894 temp->services = service;
895 for (i = 0; i < ci->children_num; ++i) {
896 oconfig_item_t *item = ci->children + i;
898 // if (!item || !item->key || !*item->key) continue;
899 if (!strcasecmp(item->key, "Multiplier")) {
900 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 < 1) {
901 WARNING("netapp plugin: \"Multiplier\" of host %s service GetWaflPerfData needs exactly one positive integer argument.", ci->values[0].value.string);
904 service->skip_countdown = service->multiplier = item->values[0].value.number;
905 } else if (!strcasecmp(item->key, "GetBusy")) {
906 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
907 WARNING("netapp plugin: \"GetBusy\" of host %s service GetDiskPerfData needs exactly one bool argument.", ci->values[0].value.string);
910 perf_disk->flags = (perf_disk->flags & ~PERF_SYSTEM_CPU) | (item->values[0].value.boolean ? PERF_DISK_BUSIEST : 0);
915 static void build_perf_wafl_config(host_config_t *temp, oconfig_item_t *ci) {
917 service_config_t *service;
918 perf_wafl_data_t *perf_wafl;
920 service = malloc(sizeof(*service));
922 service->handler = collect_perf_wafl_data;
923 perf_wafl = service->data = malloc(sizeof(*perf_wafl));
924 perf_wafl->flags = PERF_WAFL_ALL;
925 perf_wafl->last_name_cache_hit = 0;
926 perf_wafl->last_name_cache_miss = 0;
927 perf_wafl->last_find_dir_hit = 0;
928 perf_wafl->last_find_dir_miss = 0;
929 perf_wafl->last_buf_hash_hit = 0;
930 perf_wafl->last_buf_hash_miss = 0;
931 perf_wafl->last_inode_cache_hit = 0;
932 perf_wafl->last_inode_cache_miss = 0;
933 service->next = temp->services;
934 temp->services = service;
935 for (i = 0; i < ci->children_num; ++i) {
936 oconfig_item_t *item = ci->children + i;
938 // if (!item || !item->key || !*item->key) continue;
939 if (!strcasecmp(item->key, "Multiplier")) {
940 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 < 1) {
941 WARNING("netapp plugin: \"Multiplier\" of host %s service GetWaflPerfData needs exactly one positive integer argument.", ci->values[0].value.string);
944 service->skip_countdown = service->multiplier = item->values[0].value.number;
945 } else if (!strcasecmp(item->key, "GetNameCache")) {
946 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
947 WARNING("netapp plugin: \"GetNameCache\" of host %s service GetWaflPerfData needs exactly one bool argument.", ci->values[0].value.string);
950 perf_wafl->flags = (perf_wafl->flags & ~PERF_WAFL_NAME_CACHE) | (item->values[0].value.boolean ? PERF_WAFL_NAME_CACHE : 0);
951 } else if (!strcasecmp(item->key, "GetDirCache")) {
952 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
953 WARNING("netapp plugin: \"GetDirChache\" of host %s service GetWaflPerfData needs exactly one bool argument.", ci->values[0].value.string);
956 perf_wafl->flags = (perf_wafl->flags & ~PERF_WAFL_DIR_CACHE) | (item->values[0].value.boolean ? PERF_WAFL_DIR_CACHE : 0);
957 } else if (!strcasecmp(item->key, "GetBufCache")) {
958 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
959 WARNING("netapp plugin: \"GetBufCache\" of host %s service GetWaflPerfData needs exactly one bool argument.", ci->values[0].value.string);
962 perf_wafl->flags = (perf_wafl->flags & ~PERF_WAFL_BUF_CACHE) | (item->values[0].value.boolean ? PERF_WAFL_BUF_CACHE : 0);
963 } else if (!strcasecmp(item->key, "GetInodeCache")) {
964 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
965 WARNING("netapp plugin: \"GetInodeCache\" of host %s service GetWaflPerfData needs exactly one bool argument.", ci->values[0].value.string);
968 perf_wafl->flags = (perf_wafl->flags & ~PERF_WAFL_INODE_CACHE) | (item->values[0].value.boolean ? PERF_WAFL_INODE_CACHE : 0);
973 static void build_perf_sys_config(host_config_t *temp, oconfig_item_t *ci, const service_config_t *default_service) {
975 service_config_t *service;
976 perf_system_data_t *perf_system;
978 service = malloc(sizeof(*service));
979 *service = *default_service;
980 service->handler = collect_perf_system_data;
981 perf_system = service->data = malloc(sizeof(*perf_system));
982 perf_system->flags = PERF_SYSTEM_ALL;
983 perf_system->last_cpu_busy = 0;
984 perf_system->last_cpu_total = 0;
985 service->next = temp->services;
986 temp->services = service;
987 for (i = 0; i < ci->children_num; ++i) {
988 oconfig_item_t *item = ci->children + i;
990 // if (!item || !item->key || !*item->key) continue;
991 if (!strcasecmp(item->key, "Multiplier")) {
992 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 < 1) {
993 WARNING("netapp plugin: \"Multiplier\" of host %s service GetSystemPerfData needs exactly one positive integer argument.", ci->values[0].value.string);
996 service->skip_countdown = service->multiplier = item->values[0].value.number;
997 } else if (!strcasecmp(item->key, "GetCPULoad")) {
998 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
999 WARNING("netapp plugin: \"GetCPULoad\" of host %s service GetSystemPerfData needs exactly one bool argument.", ci->values[0].value.string);
1002 perf_system->flags = (perf_system->flags & ~PERF_SYSTEM_CPU) | (item->values[0].value.boolean ? PERF_SYSTEM_CPU : 0);
1003 } else if (!strcasecmp(item->key, "GetInterfaces")) {
1004 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
1005 WARNING("netapp plugin: \"GetInterfaces\" of host %s service GetSystemPerfData needs exactly one bool argument.", ci->values[0].value.string);
1008 perf_system->flags = (perf_system->flags & ~PERF_SYSTEM_NET) | (item->values[0].value.boolean ? PERF_SYSTEM_NET : 0);
1009 } else if (!strcasecmp(item->key, "GetDiskOps")) {
1010 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
1011 WARNING("netapp plugin: \"GetDiskOps\" of host %s service GetSystemPerfData needs exactly one bool argument.", ci->values[0].value.string);
1014 perf_system->flags = (perf_system->flags & ~PERF_SYSTEM_OPS) | (item->values[0].value.boolean ? PERF_SYSTEM_OPS : 0);
1015 } else if (!strcasecmp(item->key, "GetDiskIO")) {
1016 if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) {
1017 WARNING("netapp plugin: \"GetDiskIO\" of host %s service GetSystemPerfData needs exactly one bool argument.", ci->values[0].value.string);
1020 perf_system->flags = (perf_system->flags & ~PERF_SYSTEM_DISK) | (item->values[0].value.boolean ? PERF_SYSTEM_DISK : 0);
1025 static host_config_t *build_host_config(const oconfig_item_t *ci, const host_config_t *default_host, const service_config_t *def_def_service) {
1027 oconfig_item_t *item;
1028 host_config_t *host, *hc, temp = *default_host;
1029 service_config_t default_service = *def_def_service;
1031 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
1032 WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
1036 temp.name = ci->values[0].value.string;
1037 for (i = 0; i < ci->children_num; ++i) {
1038 item = ci->children + i;
1040 // if (!item || !item->key || !*item->key) continue;
1041 if (!strcasecmp(item->key, "Address")) {
1042 if ((item->values_num != 1) || (item->values[0].type != OCONFIG_TYPE_STRING)) {
1043 WARNING("netapp plugin: \"Name\" needs exactly one string argument. Ignoring host block \"%s\".", ci->values[0].value.string);
1046 temp.host = item->values[0].value.string;
1047 } else if (!strcasecmp(item->key, "Port")) {
1048 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 < 1) || (item->values[0].value.number > 65535)) {
1049 WARNING("netapp plugin: \"Port\" needs exactly one integer argument in the range of 1-65535. Ignoring host block \"%s\".", ci->values[0].value.string);
1052 temp.port = item->values[0].value.number;
1053 } else if (!strcasecmp(item->key, "Protocol")) {
1054 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"))) {
1055 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
1058 if (!strcasecmp(item->values[0].value.string, "http")) temp.protocol = NA_SERVER_TRANSPORT_HTTP;
1059 else temp.protocol = NA_SERVER_TRANSPORT_HTTPS;
1060 } else if (!strcasecmp(item->key, "Login")) {
1061 if ((item->values_num != 2) || (item->values[0].type != OCONFIG_TYPE_STRING) || (item->values[1].type != OCONFIG_TYPE_STRING)) {
1062 WARNING("netapp plugin: \"Login\" needs exactly two string arguments, username and password. Ignoring host block \"%s\".", ci->values[0].value.string);
1065 temp.username = item->values[0].value.string;
1066 temp.password = item->values[1].value.string;
1067 } else if (!strcasecmp(item->key, "Interval")) {
1068 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) {
1069 WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
1072 temp.interval = item->values[0].value.number;
1073 } else if (!strcasecmp(item->key, "GetVolumePerfData")) {
1074 build_perf_vol_config(&temp, item);
1075 } else if (!strcasecmp(item->key, "GetSystemPerfData")) {
1076 build_perf_sys_config(&temp, item, &default_service);
1077 /* if ((item->values_num != 1) || (item->values[0].type != OCONFIG_TYPE_STRING)) {
1078 WARNING("netapp plugin: \"Collect\" needs exactly one string argument. Ignoring collect block for \"%s\".", ci->values[0].value.string);
1081 build_collect_config(&temp, item);*/
1082 } else if (!strcasecmp(item->key, "GetWaflPerfData")) {
1083 build_perf_wafl_config(&temp, item);
1084 } else if (!strcasecmp(item->key, "GetDiskPerfData")) {
1085 build_perf_disk_config(&temp, item);
1086 } else if (!strcasecmp(item->key, "GetVolumeData")) {
1087 build_volume_config(&temp, item);
1089 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".", item->key, ci->values[0].value.string);
1093 if (!temp.host) temp.host = temp.name;
1094 if (!temp.port) temp.port = temp.protocol == NA_SERVER_TRANSPORT_HTTP ? 80 : 443;
1095 if (!temp.username) {
1096 WARNING("netapp plugin: Please supply login information for host \"%s\". Ignoring host block.", temp.name);
1099 for (hc = host_config; hc; hc = hc->next) {
1100 if (!strcasecmp(hc->name, temp.name)) WARNING("netapp plugin: Duplicate definition of host \"%s\". This is probably a bad idea.", hc->name);
1102 host = malloc(sizeof(*host));
1104 host->name = strdup(temp.name);
1105 host->protocol = temp.protocol;
1106 host->host = strdup(temp.host);
1107 host->username = strdup(temp.username);
1108 host->password = strdup(temp.password);
1109 host->next = host_config;
1114 static int build_config (oconfig_item_t *ci) {
1116 oconfig_item_t *item;
1117 host_config_t default_host = HOST_INIT;
1118 service_config_t default_service = SERVICE_INIT;
1120 for (i = 0; i < ci->children_num; ++i) {
1121 item = ci->children + i;
1123 // if (!item || !item->key || !*item->key) continue;
1124 if (!strcasecmp(item->key, "Host")) {
1125 build_host_config(item, &default_host, &default_service);
1127 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
1133 static int netapp_read() {
1135 host_config_t *host;
1136 service_config_t *service;
1138 for (host = host_config; host; host = host->next) {
1139 for (service = host->services; service; service = service->next) {
1140 if (--service->skip_countdown > 0) continue;
1141 service->skip_countdown = service->multiplier;
1142 out = na_server_invoke_elem(host->srv, service->query);
1143 if (na_results_status(out) != NA_OK) {
1144 int netapp_errno = na_results_errno(out);
1145 ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
1147 if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
1148 // Network problems. Just give up on all other services on this host.
1153 service->handler(host, out, service->data);
1160 void module_register() {
1161 plugin_register_complex_config("netapp", build_config);
1162 plugin_register_init("netapp", config_init);
1163 plugin_register_read("netapp", netapp_read);