netapp plugin: collect_perf_disk_data: Only query "percentage-saved" if required.
[collectd.git] / src / netapp.c
index 14ec72a..96ca5a4 100644 (file)
@@ -168,276 +168,392 @@ struct host_config_s {
 
 static host_config_t *host_config;
 
-static volume_t *get_volume(host_config_t *host, const char *name) {
+static volume_t *get_volume (host_config_t *host, const char *name) /* {{{ */
+{
        volume_t *v;
+
+       if (name == NULL)
+               return (NULL);
        
        for (v = host->volumes; v; v = v->next) {
-               if (!strcmp(v->name/* + 4*/, name)) return v;
+               if (strcmp(v->name, name) == 0)
+                       return v;
        }
+
        v = malloc(sizeof(*v));
+       if (v == NULL)
+               return (NULL);
+       memset (v, 0, sizeof (*v));
+
        v->name = strdup(name);
-//     v->name = malloc(strlen(name) + 5);
-//     strcpy(v->name, "vol-");
-//     strcpy(v->name + 4, name);
-       v->perf_data.flags = 0;
-       v->volume_data.flags = 0;
+       if (v->name == NULL) {
+               sfree (v);
+               return (NULL);
+       }
+
        v->next = host->volumes;
        host->volumes = v;
+
        return v;
-}
+} /* }}} volume_t *get_volume */
 
-static disk_t *get_disk(host_config_t *host, const char *name) {
+static disk_t *get_disk(host_config_t *host, const char *name) /* {{{ */
+{
        disk_t *v, init = DISK_INIT;
+
+       if (name == NULL)
+               return (NULL);
        
        for (v = host->disks; v; v = v->next) {
-               if (!strcmp(v->name/* + 5*/, name)) return v;
+               if (strcmp(v->name, name) == 0)
+                       return v;
        }
        v = malloc(sizeof(*v));
+       if (v == NULL)
+               return (NULL);
+
        *v = init;
        v->name = strdup(name);
-//     v->name = malloc(strlen(name) + 6);
-//     strcpy(v->name, "disk-");
-//     strcpy(v->name + 5, name);
+       if (v->name == NULL) {
+               sfree (v);
+               return (NULL);
+       }
+
        v->next = host->disks;
        host->disks = v;
+
        return v;
-}
+} /* }}} disk_t *get_disk */
+
+static int submit_values (const char *host, /* {{{ */
+               const char *plugin_inst,
+               const char *type, const char *type_inst,
+               value_t *values, int values_len,
+               time_t timestamp)
+{
+       value_list_t vl = VALUE_LIST_INIT;
+
+       vl.values = values;
+       vl.values_len = values_len;
+
+       if (timestamp > 0)
+               vl.time = timestamp;
+
+       if (host != NULL)
+               sstrncpy (vl.host, host, sizeof (vl.host));
+       else
+               sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
+       if (plugin_inst != NULL)
+               sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
+       sstrncpy (vl.type, type, sizeof (vl.type));
+       if (type_inst != NULL)
+               sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
+
+       return (plugin_dispatch_values (&vl));
+} /* }}} int submit_uint64 */
+
+static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
+               const char *type, const char *type_inst, counter_t val0, counter_t val1,
+               time_t timestamp)
+{
+       value_t values[2];
+
+       values[0].counter = val0;
+       values[1].counter = val1;
+
+       return (submit_values (host, plugin_inst, type, type_inst,
+                               values, 2, timestamp));
+} /* }}} int submit_two_counters */
+
+static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
+               const char *type, const char *type_inst, double d, time_t timestamp)
+{
+       value_t v;
+
+       v.gauge = (gauge_t) d;
+
+       return (submit_values (host, plugin_inst, type, type_inst,
+                               &v, 1, timestamp));
+} /* }}} int submit_uint64 */
+
+static int submit_cache_ratio (const char *host, /* {{{ */
+               const char *plugin_inst,
+               const char *type_inst,
+               uint64_t new_hits,
+               uint64_t new_misses,
+               uint64_t *old_hits,
+               uint64_t *old_misses,
+               time_t timestamp)
+{
+       value_t v;
+
+       if ((new_hits >= (*old_hits)) && (new_misses >= (*old_misses))) {
+               uint64_t hits;
+               uint64_t misses;
+
+               hits = new_hits - (*old_hits);
+               misses = new_misses - (*old_misses);
+
+               v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
+       } else {
+               v.gauge = NAN;
+       }
+
+       *old_hits = new_hits;
+       *old_misses = new_misses;
 
-static void collect_perf_wafl_data(host_config_t *host, na_elem_t *out, void *data) {
+       return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
+                               &v, 1, timestamp));
+} /* }}} int submit_cache_ratio */
+
+static void collect_perf_wafl_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
        perf_wafl_data_t *wafl = data;
-       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;
-       const char *instance, *name;
+       uint64_t name_cache_hit  = 0,  name_cache_miss  = 0;
+       uint64_t find_dir_hit    = 0,  find_dir_miss    = 0;
+       uint64_t buf_hash_hit    = 0,  buf_hash_miss    = 0;
+       uint64_t inode_cache_hit = 0,  inode_cache_miss = 0;
+       const char *plugin_inst;
        time_t timestamp;
        na_elem_t *counter;
-       value_t values[2];
-       value_list_t vl = VALUE_LIST_INIT;
        
        timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
        out = na_elem_child(na_elem_child(out, "instances"), "instance-data");
-       instance = na_child_get_string(out, "name");
+       plugin_inst = na_child_get_string(out, "name");
 
+       /* Iterate over all counters */
        na_elem_iter_t iter = na_child_iterator(na_elem_child(out, "counters"));
        for (counter = na_iterator_next(&iter); counter; counter = na_iterator_next(&iter)) {
+               const char *name;
+
                name = na_child_get_string(counter, "name");
-               if (!strcmp(name, "name_cache_hit")) {
-                       name_cache_hit = na_child_get_uint64(counter, "value", 0);
-               } else if (!strcmp(name, "name_cache_miss")) {
-                       name_cache_miss = na_child_get_uint64(counter, "value", 0);
-               } else if (!strcmp(name, "find_dir_hit")) {
-                       find_dir_hit = na_child_get_uint64(counter, "value", 0);
-               } else if (!strcmp(name, "find_dir_miss")) {
-                       find_dir_miss = na_child_get_uint64(counter, "value", 0);
-               } else if (!strcmp(name, "buf_hash_hit")) {
-                       buf_hash_hit = na_child_get_uint64(counter, "value", 0);
-               } else if (!strcmp(name, "buf_hash_miss")) {
-                       buf_hash_miss = na_child_get_uint64(counter, "value", 0);
-               } else if (!strcmp(name, "inode_cache_hit")) {
-                       inode_cache_hit = na_child_get_uint64(counter, "value", 0);
-               } else if (!strcmp(name, "inode_cache_miss")) {
-                       inode_cache_miss = na_child_get_uint64(counter, "value", 0);
-               }
-       }
-       if ((wafl->flags & PERF_WAFL_NAME_CACHE) && name_cache_hit && name_cache_miss) {
-               values[0].gauge = 0;
-               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);
-               vl.values = values;
-               vl.values_len = 1;
-               vl.time = timestamp;
-               vl.interval = interval_g;
-               sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
-               sstrncpy(vl.host, host->name, sizeof(vl.host));
-               sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
-               sstrncpy(vl.type, "cache_ratio", sizeof(vl.type));
-               sstrncpy(vl.type_instance, "name_cache_hit", sizeof(vl.type_instance));
-               if (wafl->last_name_cache_hit && wafl->last_name_cache_miss) {
-                       DEBUG("%s/netapp-%s/cache_ratio: %lf", host->name, instance, values[0].gauge);
-                       plugin_dispatch_values (&vl);
-               }
-               wafl->last_name_cache_hit = name_cache_hit;
-               wafl->last_name_cache_miss = name_cache_miss;
-       }
-       if ((wafl->flags & PERF_WAFL_DIR_CACHE) && find_dir_hit && find_dir_miss) {
-               values[0].gauge = 0;
-               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);
-               vl.values = values;
-               vl.values_len = 1;
-               vl.time = timestamp;
-               vl.interval = interval_g;
-               sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
-               sstrncpy(vl.host, host->name, sizeof(vl.host));
-               sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
-               sstrncpy(vl.type, "cache_ratio", sizeof(vl.type));
-               sstrncpy(vl.type_instance, "find_dir_hit", sizeof(vl.type_instance));
-               if (wafl->last_find_dir_hit && wafl->last_find_dir_miss) {
-                       DEBUG("%s/netapp-%s/cache_ratio: %lf", host->name, instance, values[0].gauge);
-                       plugin_dispatch_values (&vl);
-               }
-               wafl->last_find_dir_hit = find_dir_hit;
-               wafl->last_find_dir_miss = find_dir_miss;
-       }
-       if ((wafl->flags & PERF_WAFL_BUF_CACHE) && buf_hash_hit && buf_hash_miss) {
-               values[0].gauge = 0;
-               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);
-               vl.values = values;
-               vl.values_len = 1;
-               vl.time = timestamp;
-               vl.interval = interval_g;
-               sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
-               sstrncpy(vl.host, host->name, sizeof(vl.host));
-               sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
-               sstrncpy(vl.type, "cache_ratio", sizeof(vl.type));
-               sstrncpy(vl.type_instance, "buf_hash_hit", sizeof(vl.type_instance));
-               if (wafl->last_buf_hash_hit && wafl->last_buf_hash_miss) {
-                       DEBUG("%s/netapp-%s/cache_ratio: %lf", host->name, instance, values[0].gauge);
-                       plugin_dispatch_values (&vl);
-               }
-               wafl->last_buf_hash_hit = buf_hash_hit;
-               wafl->last_buf_hash_miss = buf_hash_miss;
-       }
-       if ((wafl->flags & PERF_WAFL_INODE_CACHE) && inode_cache_hit && inode_cache_miss) {
-               values[0].gauge = 0;
-               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);
-               vl.values = values;
-               vl.values_len = 1;
-               vl.time = timestamp;
-               vl.interval = interval_g;
-               sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
-               sstrncpy(vl.host, host->name, sizeof(vl.host));
-               sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
-               sstrncpy(vl.type, "cache_ratio", sizeof(vl.type));
-               sstrncpy(vl.type_instance, "inode_cache_hit", sizeof(vl.type_instance));
-               if (wafl->last_inode_cache_hit && wafl->last_inode_cache_miss) {
-                       DEBUG("%s/netapp-%s/cache_ratio: %lf", host->name, instance, values[0].gauge);
-                       plugin_dispatch_values (&vl);
-               }
-               wafl->last_inode_cache_hit = inode_cache_hit;
-               wafl->last_inode_cache_miss = inode_cache_miss;
+               if (!strcmp(name, "name_cache_hit"))
+                       name_cache_hit = na_child_get_uint64(counter, "value", UINT64_MAX);
+               else if (!strcmp(name, "name_cache_miss"))
+                       name_cache_miss = na_child_get_uint64(counter, "value", UINT64_MAX);
+               else if (!strcmp(name, "find_dir_hit"))
+                       find_dir_hit = na_child_get_uint64(counter, "value", UINT64_MAX);
+               else if (!strcmp(name, "find_dir_miss"))
+                       find_dir_miss = na_child_get_uint64(counter, "value", UINT64_MAX);
+               else if (!strcmp(name, "buf_hash_hit"))
+                       buf_hash_hit = na_child_get_uint64(counter, "value", UINT64_MAX);
+               else if (!strcmp(name, "buf_hash_miss"))
+                       buf_hash_miss = na_child_get_uint64(counter, "value", UINT64_MAX);
+               else if (!strcmp(name, "inode_cache_hit"))
+                       inode_cache_hit = na_child_get_uint64(counter, "value", UINT64_MAX);
+               else if (!strcmp(name, "inode_cache_miss"))
+                       inode_cache_miss = na_child_get_uint64(counter, "value", UINT64_MAX);
+               else
+                       DEBUG("netapp plugin: Found unexpected child: %s", name);
        }
-}
 
-static void collect_perf_disk_data(host_config_t *host, na_elem_t *out, void *data) {
+       /* Submit requested counters */
+       if ((wafl->flags & PERF_WAFL_NAME_CACHE)
+                       && (name_cache_hit != UINT64_MAX) && (name_cache_miss != UINT64_MAX))
+               submit_cache_ratio (host->name, plugin_inst, "name_cache_hit",
+                               name_cache_hit, name_cache_miss,
+                               &wafl->last_name_cache_hit, &wafl->last_name_cache_miss,
+                               timestamp);
+
+       if ((wafl->flags & PERF_WAFL_DIR_CACHE)
+                       && (find_dir_hit != UINT64_MAX) && (find_dir_miss != UINT64_MAX))
+               submit_cache_ratio (host->name, plugin_inst, "find_dir_hit",
+                               find_dir_hit, find_dir_miss,
+                               &wafl->last_find_dir_hit, &wafl->last_find_dir_miss,
+                               timestamp);
+
+       if ((wafl->flags & PERF_WAFL_BUF_CACHE)
+                       && (buf_hash_hit != UINT64_MAX) && (buf_hash_miss != UINT64_MAX))
+               submit_cache_ratio (host->name, plugin_inst, "buf_hash_hit",
+                               buf_hash_hit, buf_hash_miss,
+                               &wafl->last_buf_hash_hit, &wafl->last_buf_hash_miss,
+                               timestamp);
+
+       if ((wafl->flags & PERF_WAFL_INODE_CACHE)
+                       && (inode_cache_hit != UINT64_MAX) && (inode_cache_miss != UINT64_MAX))
+               submit_cache_ratio (host->name, plugin_inst, "inode_cache_hit",
+                               inode_cache_hit, inode_cache_miss,
+                               &wafl->last_inode_cache_hit, &wafl->last_inode_cache_miss,
+                               timestamp);
+} /* }}} void collect_perf_wafl_data */
+
+static void collect_perf_disk_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
        perf_disk_data_t *perf = data;
        const char *name;
        time_t timestamp;
        na_elem_t *counter, *inst;
        disk_t *disk, *worst_disk = 0;
-       value_t values[2];
-       value_list_t vl = VALUE_LIST_INIT;
        
        timestamp = (time_t) na_child_get_uint64(out, "timestamp", 0);
        out = na_elem_child(out, "instances");
+
+       /* Iterate over all children */
        na_elem_iter_t inst_iter = na_child_iterator(out);
        for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
-               uint64_t disk_busy = 0, base_for_disk_busy = 0;
+               uint64_t disk_busy = 0;
+               uint64_t base_for_disk_busy = 0;
 
                disk = get_disk(host, na_child_get_string(inst, "name"));
+               if (disk == NULL)
+                       continue;
+
+               /* Look for the "disk_busy" and "base_for_disk_busy" counters */
                na_elem_iter_t count_iter = na_child_iterator(na_elem_child(inst, "counters"));
                for (counter = na_iterator_next(&count_iter); counter; counter = na_iterator_next(&count_iter)) {
                        name = na_child_get_string(counter, "name");
-                       if (!strcmp(name, "disk_busy")) {
-                               disk_busy = na_child_get_uint64(counter, "value", 0);
-                       } else if (!strcmp(name, "base_for_disk_busy")) {
-                               base_for_disk_busy = na_child_get_uint64(counter, "value", 0);
-                       }
+                       if (name == NULL)
+                               continue;
+
+                       if (strcmp(name, "disk_busy") == 0)
+                               disk_busy = na_child_get_uint64(counter, "value", UINT64_MAX);
+                       else if (strcmp(name, "base_for_disk_busy") == 0)
+                               base_for_disk_busy = na_child_get_uint64(counter, "value", UINT64_MAX);
+               }
+
+               if ((disk_busy == UINT64_MAX) || (base_for_disk_busy == UINT64_MAX))
+               {
+                       disk->perf_data.last_disk_busy = 0;
+                       disk->perf_data.last_base_for_disk_busy = 0;
+                       continue;
                }
-               if (disk_busy && base_for_disk_busy) {
-                       disk->perf_data.last_update = timestamp;
-                       disk->perf_data.last_disk_busy_percent = 0;
-                       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);
-                       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;
-                       disk->perf_data.last_disk_busy = disk_busy;
-                       disk->perf_data.last_base_for_disk_busy = base_for_disk_busy;
+
+               disk->perf_data.last_update = timestamp;
+               if ((disk_busy >= disk->perf_data.last_disk_busy)
+                               && (base_for_disk_busy >= disk->perf_data.last_base_for_disk_busy))
+               {
+                       uint64_t disk_busy_diff;
+                       uint64_t base_diff;
+
+                       disk_busy_diff = disk_busy - disk->perf_data.last_disk_busy;
+                       base_diff = base_for_disk_busy - disk->perf_data.last_base_for_disk_busy;
+
+                       if (base_diff == 0)
+                               disk->perf_data.last_disk_busy_percent = NAN;
+                       else
+                               disk->perf_data.last_disk_busy_percent = 100.0
+                                       * ((gauge_t) disk_busy_diff) / ((gauge_t) base_diff);
                }
+               else
+               {
+                       disk->perf_data.last_disk_busy_percent = NAN;
+               }
+
+               disk->perf_data.last_disk_busy = disk_busy;
+               disk->perf_data.last_base_for_disk_busy = base_for_disk_busy;
+
+               if ((worst_disk == NULL)
+                               || (worst_disk->perf_data.last_disk_busy_percent < disk->perf_data.last_disk_busy_percent))
+                       worst_disk = disk;
        }
-       if ((perf->flags & PERF_DISK_BUSIEST) && worst_disk) {
-               values[0].gauge = worst_disk->perf_data.last_disk_busy_percent;
-               vl.values = values;
-               vl.values_len = 1;
-               vl.time = timestamp;
-               vl.interval = interval_g;
-               sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
-               sstrncpy(vl.host, host->name, sizeof(vl.host));
-               sstrncpy(vl.plugin_instance, "system", sizeof(vl.plugin_instance));
-               sstrncpy(vl.type, "percent", sizeof(vl.type));
-               sstrncpy(vl.type_instance, "disk_busy", sizeof(vl.type_instance));
-               DEBUG("%s/netapp-system/percent-disk_busy: %lf", host->name, worst_disk->perf_data.last_disk_busy_percent);
-               plugin_dispatch_values (&vl);
-       }
-}
 
-static void collect_volume_data(host_config_t *host, na_elem_t *out, void *data) {
-       na_elem_t *inst, *sis;
+       if ((perf->flags & PERF_DISK_BUSIEST) && (worst_disk != NULL))
+               submit_double (host->name, "system", "percent", "disk_busy",
+                               worst_disk->perf_data.last_disk_busy_percent, timestamp);
+} /* }}} void collect_perf_disk_data */
+
+static void collect_volume_data(host_config_t *host, na_elem_t *out, void *data) { /* {{{ */
+       na_elem_t *inst;
        volume_t *volume;
        volume_data_t *volume_data = data;
-       value_t values[1];
-       value_list_t vl = VALUE_LIST_INIT;
 
        out = na_elem_child(out, "volumes");
        na_elem_iter_t inst_iter = na_child_iterator(out);
        for (inst = na_iterator_next(&inst_iter); inst; inst = na_iterator_next(&inst_iter)) {
-               uint64_t size_free = 0, size_used = 0, snap_reserved = 0, sis_saved = 0;
+               uint64_t size_free = 0, size_used = 0, snap_reserved = 0;
+
+               na_elem_t *sis;
+               const char *sis_state;
+               uint64_t sis_saved_reported;
+               uint64_t sis_saved;
+
                volume = get_volume(host, na_child_get_string(inst, "name"));
-               if (!(volume->volume_data.flags & VOLUME_INIT)) volume->volume_data.flags = volume_data->flags;
-               if (!(volume->volume_data.flags & VOLUME_DF)) continue;
-               size_free = na_child_get_uint64(inst, "size-available", 0);
-               size_used = na_child_get_uint64(inst, "size-used", 0);
-               snap_reserved = na_child_get_uint64(inst, "snapshot-blocks-reserved", 0) * 1024;
+               if (volume == NULL)
+                       continue;
 
-               vl.values_len = 1;
-               vl.values = values;
-               vl.time = time(0);
-               vl.interval = interval_g;
-               sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
-               sstrncpy(vl.host, host->name, sizeof(vl.host));
-               sstrncpy(vl.plugin_instance, volume->name, sizeof(vl.plugin_instance));
-               sstrncpy(vl.type, "df_complex", sizeof(vl.type));
+               if (!(volume->volume_data.flags & VOLUME_INIT))
+                       volume->volume_data.flags = volume_data->flags;
 
-               values[0].gauge = size_used;
-               sstrncpy(vl.type_instance, "used", sizeof(vl.type_instance));
-               DEBUG("%s/netapp-%s/df_complex-used: %"PRIu64, host->name, volume->name, size_used);
-               plugin_dispatch_values (&vl);
+               if (!(volume->volume_data.flags & VOLUME_DF))
+                       continue;
 
-               values[0].gauge = size_free;
-               sstrncpy(vl.type_instance, "free", sizeof(vl.type_instance));
-               DEBUG("%s/netapp-%s/df_complex-free: %"PRIu64, host->name, volume->name, size_free);
-               plugin_dispatch_values (&vl);
+               /* 2^4 exa-bytes? This will take a while ;) */
+               size_free = na_child_get_uint64(inst, "size-available", UINT64_MAX);
+               if (size_free != UINT64_MAX)
+                       submit_double (host->name, volume->name, "df_complex", "used",
+                                       (double) size_used, /* time = */ 0);
 
-               if (snap_reserved) {
-                       values[0].gauge = snap_reserved;
-                       sstrncpy(vl.type_instance, "snap_reserved", sizeof(vl.type_instance));
-                       DEBUG("%s/netapp-%s/df_complex-snap_reserved: %"PRIu64, host->name, volume->name, snap_reserved);
-                       plugin_dispatch_values (&vl);
-               }
+               size_used = na_child_get_uint64(inst, "size-used", UINT64_MAX);
+               if (size_free != UINT64_MAX)
+                       submit_double (host->name, volume->name, "df_complex", "free",
+                                       (double) size_free, /* time = */ 0);
+
+               snap_reserved = na_child_get_uint64(inst, "snapshot-blocks-reserved", UINT64_MAX);
+               if (snap_reserved != UINT64_MAX)
+                       /* 1 block == 1024 bytes  as per API docs */
+                       submit_double (host->name, volume->name, "df_complex", "snap_reserved",
+                                       (double) (1024 * snap_reserved), /* time = */ 0);
 
                sis = na_elem_child(inst, "sis");
-               if (sis && !strcmp(na_child_get_string(sis, "state"), "enabled")) {
-                       uint64_t sis_saved_reported = na_child_get_uint64(sis, "size-saved", 0), sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", 0);
-                       /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
-                       if (sis_saved_reported >> 32) {
-                               /* In case they ever fix this bug. */
-                               sis_saved = sis_saved_reported;
+               if (sis == NULL)
+                       continue;
+
+               sis_state = na_child_get_string(sis, "state");
+               if ((sis_state == NULL)
+                               || (strcmp ("enabled", sis_state) != 0))
+                       continue;
+
+               sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
+               if (sis_saved_reported == UINT64_MAX)
+                       continue;
+
+               /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
+               if ((sis_saved_reported >> 32) != 0) {
+                       /* In case they ever fix this bug. */
+                       sis_saved = sis_saved_reported;
+               } else {
+                       uint64_t sis_saved_percent;
+                       uint64_t sis_saved_guess;
+                       uint64_t overflow_guess;
+                       uint64_t guess1, guess2, guess3;
+
+                       sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
+                       if (sis_saved_percent > 100)
+                               continue;
+
+                       /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
+                        * will hopefully be fixed in later versions. To work around the bug, try
+                        * to figure out how often the 32bit integer wrapped around by using the
+                        * "percentage-saved" value. Because the percentage is in the range
+                        * [0-100], this should work as long as the saved space does not exceed
+                        * 400 GBytes. */
+                       /* percentage-saved = size-saved / (size-saved + size-used) */
+                       if (sis_saved_percent < 100)
+                               sis_saved_guess = size_used * sis_saved_percent / (100 - sis_saved_percent);
+                       else
+                               sis_saved_guess = size_used;
+
+                       overflow_guess = sis_saved_guess >> 32;
+                       guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
+                       guess2 = (overflow_guess << 32) + sis_saved_reported;
+                       guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
+
+                       if (sis_saved_guess < guess2) {
+                               if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
+                                       sis_saved = guess1;
+                               else
+                                       sis_saved = guess2;
                        } else {
-                               uint64_t real_saved = sis_saved_percent * size_used / (100 - sis_saved_percent);
-                               uint64_t overflow_guess = real_saved >> 32;
-                               uint64_t guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
-                               uint64_t guess2 = (overflow_guess << 32) + sis_saved_reported;
-                               uint64_t guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
-                               
-                               if (real_saved < guess2) {
-                                       if (real_saved - guess1 < guess2 - real_saved) sis_saved = guess1;
-                                       else sis_saved = guess2;
-                               } else {
-                                       if (real_saved - guess2 < guess3 - real_saved) sis_saved = guess2;
-                                       else sis_saved = guess3;
-                               }
+                               if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
+                                       sis_saved = guess2;
+                               else
+                                       sis_saved = guess3;
                        }
-                       values[0].gauge = sis_saved;
-                       sstrncpy(vl.type_instance, "sis_saved", sizeof(vl.type_instance));
-                       DEBUG("%s/netapp-%s/df_complex-sis_saved: %"PRIu64, host->name, volume->name, sis_saved);
-                       plugin_dispatch_values (&vl);
-               }
+               } /* end of 32-bit workaround */
+
+               submit_double (host->name, volume->name, "df_complex", "sis_saved",
+                               (double) sis_saved, /* time = */ 0);
        }
-}
+} /* }}} void collect_volume_data */
 
 static void collect_perf_volume_data(host_config_t *host, na_elem_t *out, void *data) {
        perf_volume_data_t *perf = data;
@@ -620,7 +736,7 @@ static void collect_perf_system_data(host_config_t *host, na_elem_t *out, void *
                plugin_dispatch_values (&vl);
        }
        if ((perf->flags & PERF_SYSTEM_CPU) && cpu_busy && cpu_total) {
-//             values[0].gauge = (double) (cpu_busy - perf->last_cpu_busy) / (cpu_total - perf->last_cpu_total) * 100;
+               /* values[0].gauge = (double) (cpu_busy - perf->last_cpu_busy) / (cpu_total - perf->last_cpu_total) * 100; */
                values[0].counter = cpu_busy / 10000;
                vl.values = values;
                vl.values_len = 1;
@@ -631,12 +747,12 @@ static void collect_perf_system_data(host_config_t *host, na_elem_t *out, void *
                sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
                sstrncpy(vl.type, "cpu", sizeof(vl.type));
                sstrncpy(vl.type_instance, "system", sizeof(vl.plugin_instance));
-//             if (perf->last_cpu_busy && perf->last_cpu_total) printf("CPU: busy: %lf - idle: %lf\n", values[0].gauge, 100.0 - values[0].gauge);
-//             if (perf->last_cpu_busy && perf->last_cpu_total) plugin_dispatch_values ("cpu", &vl);
+               /* if (perf->last_cpu_busy && perf->last_cpu_total) printf("CPU: busy: %lf - idle: %lf\n", values[0].gauge, 100.0 - values[0].gauge); */
+               /* if (perf->last_cpu_busy && perf->last_cpu_total) plugin_dispatch_values ("cpu", &vl); */
                DEBUG("%s/netapp-%s/cpu: busy: %"PRIu64" - idle: %"PRIu64, host->name, instance, cpu_busy / 10000, cpu_total / 10000);
                plugin_dispatch_values (&vl);
 
-//             values[0].gauge = 100.0 - (double) (cpu_busy - perf->last_cpu_busy) / (cpu_total - perf->last_cpu_total) * 100;
+               /* values[0].gauge = 100.0 - (double) (cpu_busy - perf->last_cpu_busy) / (cpu_total - perf->last_cpu_total) * 100; */
                values[0].counter = (cpu_total - cpu_busy) / 10000;
                vl.values = values;
                vl.values_len = 1;
@@ -647,7 +763,7 @@ static void collect_perf_system_data(host_config_t *host, na_elem_t *out, void *
                sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
                sstrncpy(vl.type, "cpu", sizeof(vl.type));
                sstrncpy(vl.type_instance, "idle", sizeof(vl.plugin_instance));
-//             if (perf->last_cpu_busy && perf->last_cpu_total) plugin_dispatch_values ("cpu", &vl);
+               /* if (perf->last_cpu_busy && perf->last_cpu_total) plugin_dispatch_values ("cpu", &vl); */
                plugin_dispatch_values (&vl);
 
                perf->last_cpu_busy = cpu_busy;
@@ -712,8 +828,8 @@ int config_init() {
                                na_child_add_string(e, "foo", "buf_hash_miss");
                                na_child_add_string(e, "foo", "inode_cache_hit");
                                na_child_add_string(e, "foo", "inode_cache_miss");
-//                             na_child_add_string(e, "foo", "inode_eject_time");
-//                             na_child_add_string(e, "foo", "buf_eject_time");
+                               /* na_child_add_string(e, "foo", "inode_eject_time"); */
+                               /* na_child_add_string(e, "foo", "buf_eject_time"); */
                                na_child_add(service->query, e);
                        } else if (service->handler == collect_perf_disk_data) {
                                service->query = na_elem_new("perf-object-get-instances");
@@ -724,9 +840,9 @@ int config_init() {
                                na_child_add(service->query, e);
                        } else if (service->handler == collect_volume_data) {
                                service->query = na_elem_new("volume-list-info");
-//                             na_child_add_string(service->query, "objectname", "volume");
-//                     } else if (service->handler == collect_snapshot_data) {
-//                             service->query = na_elem_new("snapshot-list-info");
+                               /* na_child_add_string(service->query, "objectname", "volume"); */
+                               /* } else if (service->handler == collect_snapshot_data) { */
+                               /* service->query = na_elem_new("snapshot-list-info"); */
                        }
                }
        }
@@ -830,7 +946,7 @@ static void build_perf_vol_config(host_config_t *host, const oconfig_item_t *ci)
        for (i = 0; i < ci->children_num; ++i) {
                oconfig_item_t *item = ci->children + i;
                
-//             if (!item || !item->key || !*item->key) continue;
+               /* if (!item || !item->key || !*item->key) continue; */
                if (!strcasecmp(item->key, "Multiplier")) {
                        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) {
                                WARNING("netapp plugin: \"Multiplier\" of host %s service GetVolPerfData needs exactly one positive integer argument.", host->name);
@@ -877,7 +993,7 @@ static void build_volume_config(host_config_t *host, oconfig_item_t *ci) {
        for (i = 0; i < ci->children_num; ++i) {
                oconfig_item_t *item = ci->children + i;
                
-//             if (!item || !item->key || !*item->key) continue;
+               /* if (!item || !item->key || !*item->key) continue; */
                if (!strcasecmp(item->key, "Multiplier")) {
                        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) {
                                WARNING("netapp plugin: \"Multiplier\" of host %s service GetVolPerfData needs exactly one positive integer argument.", host->name);
@@ -916,7 +1032,7 @@ static void build_perf_disk_config(host_config_t *temp, oconfig_item_t *ci) {
        for (i = 0; i < ci->children_num; ++i) {
                oconfig_item_t *item = ci->children + i;
                
-//             if (!item || !item->key || !*item->key) continue;
+               /* if (!item || !item->key || !*item->key) continue; */
                if (!strcasecmp(item->key, "Multiplier")) {
                        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) {
                                WARNING("netapp plugin: \"Multiplier\" of host %s service GetWaflPerfData needs exactly one positive integer argument.", ci->values[0].value.string);
@@ -956,7 +1072,7 @@ static void build_perf_wafl_config(host_config_t *temp, oconfig_item_t *ci) {
        for (i = 0; i < ci->children_num; ++i) {
                oconfig_item_t *item = ci->children + i;
                
-//             if (!item || !item->key || !*item->key) continue;
+               /* if (!item || !item->key || !*item->key) continue; */
                if (!strcasecmp(item->key, "Multiplier")) {
                        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) {
                                WARNING("netapp plugin: \"Multiplier\" of host %s service GetWaflPerfData needs exactly one positive integer argument.", ci->values[0].value.string);
@@ -1008,7 +1124,7 @@ static void build_perf_sys_config(host_config_t *temp, oconfig_item_t *ci, const
        for (i = 0; i < ci->children_num; ++i) {
                oconfig_item_t *item = ci->children + i;
 
-//             if (!item || !item->key || !*item->key) continue;
+               /* if (!item || !item->key || !*item->key) continue; */
                if (!strcasecmp(item->key, "Multiplier")) {
                        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) {
                                WARNING("netapp plugin: \"Multiplier\" of host %s service GetSystemPerfData needs exactly one positive integer argument.", ci->values[0].value.string);
@@ -1058,7 +1174,7 @@ static host_config_t *build_host_config(const oconfig_item_t *ci, const host_con
        for (i = 0; i < ci->children_num; ++i) {
                item = ci->children + i;
 
-//             if (!item || !item->key || !*item->key) continue;
+               /* if (!item || !item->key || !*item->key) continue; */
                if (!strcasecmp(item->key, "Address")) {
                        if ((item->values_num != 1) || (item->values[0].type != OCONFIG_TYPE_STRING)) {
                                WARNING("netapp plugin: \"Name\" needs exactly one string argument. Ignoring host block \"%s\".", ci->values[0].value.string);
@@ -1141,7 +1257,7 @@ static int build_config (oconfig_item_t *ci) {
        for (i = 0; i < ci->children_num; ++i) {
                item = ci->children + i;
 
-//             if (!item || !item->key || !*item->key) continue;
+               /* if (!item || !item->key || !*item->key) continue; */
                if (!strcasecmp(item->key, "Host")) {
                        build_host_config(item, &default_host, &default_service);
                } else {
@@ -1166,7 +1282,7 @@ static int netapp_read() {
                                ERROR("netapp plugin: Error %d from host %s: %s", netapp_errno, host->name, na_results_reason(out));
                                na_elem_free(out);
                                if (netapp_errno == EIO || netapp_errno == ETIMEDOUT) {
-                                       // Network problems. Just give up on all other services on this host.
+                                       /* Network problems. Just give up on all other services on this host. */
                                        break;
                                }
                                continue;
@@ -1183,3 +1299,5 @@ void module_register() {
        plugin_register_init("netapp", config_init);
        plugin_register_read("netapp", netapp_read);
 }
+
+/* vim: set sw=2 ts=2 noet fdm=marker : */