+ if (cd == NULL)
+ return (EINVAL);
+
+ if (cd->query != NULL)
+ return (0);
+
+ cd->query = na_elem_new ("perf-object-get-instances");
+ if (cd->query == NULL)
+ {
+ ERROR ("netapp plugin: na_elem_new failed.");
+ return (-1);
+ }
+ na_child_add_string (cd->query, "objectname", "disk");
+
+ e = na_elem_new("counters");
+ if (e == NULL)
+ {
+ na_elem_free (cd->query);
+ cd->query = NULL;
+ ERROR ("netapp plugin: na_elem_new failed.");
+ return (-1);
+ }
+ na_child_add_string(e, "foo", "disk_busy");
+ na_child_add_string(e, "foo", "base_for_disk_busy");
+ na_child_add(cd->query, e);
+
+ return (0);
+} /* }}} int cna_setup_disk */
+
+static int cna_query_disk (host_config_t *host) /* {{{ */
+{
+ na_elem_t *data;
+ int status;
+ time_t now;
+
+ if (host == NULL)
+ return (EINVAL);
+
+ /* If the user did not configure disk statistics, return without doing
+ * anything. */
+ if (host->cfg_disk == NULL)
+ return (0);
+
+ now = time (NULL);
+ if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
+ return (0);
+
+ status = cna_setup_disk (host->cfg_disk);
+ if (status != 0)
+ return (status);
+ assert (host->cfg_disk->query != NULL);
+
+ data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
+ if (na_results_status (data) != NA_OK)
+ {
+ ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed: %s",
+ na_results_reason (data));
+ na_elem_free (data);
+ return (-1);
+ }
+
+ status = cna_handle_disk_data (host->name, host->cfg_disk, data);
+
+ if (status == 0)
+ host->cfg_disk->interval.last_read = now;
+
+ na_elem_free (data);
+ return (status);
+} /* }}} int cna_query_disk */
+
+/* Data corresponding to <VolumePerf /> */
+static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
+ cfg_volume_perf_t *cvp, na_elem_t *data)
+{
+ time_t timestamp;
+ na_elem_t *elem_instances;
+ na_elem_iter_t iter_instances;
+ na_elem_t *elem_instance;
+
+ timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
+
+ elem_instances = na_elem_child(data, "instances");
+ if (elem_instances == NULL)
+ {
+ ERROR ("netapp plugin: handle_volume_perf_data: "
+ "na_elem_child (\"instances\") failed.");
+ return (-1);
+ }
+
+ iter_instances = na_child_iterator (elem_instances);
+ for (elem_instance = na_iterator_next(&iter_instances);
+ elem_instance != NULL;
+ elem_instance = na_iterator_next(&iter_instances))
+ {
+ const char *name;
+
+ data_volume_perf_t perf_data;
+ data_volume_perf_t *v;
+
+ na_elem_t *elem_counters;
+ na_elem_iter_t iter_counters;
+ na_elem_t *elem_counter;
+
+ memset (&perf_data, 0, sizeof (perf_data));
+ perf_data.timestamp = timestamp;
+
+ name = na_child_get_string (elem_instance, "name");
+ if (name == NULL)
+ continue;
+
+ /* get_volume_perf may return NULL if this volume is to be ignored. */
+ v = get_volume_perf (cvp, perf_data.name);
+ if (v == NULL)
+ continue;
+
+ elem_counters = na_elem_child (elem_instance, "counters");
+ if (elem_counters == NULL)
+ continue;
+
+ iter_counters = na_child_iterator (elem_counters);
+ for (elem_counter = na_iterator_next(&iter_counters);
+ elem_counter != NULL;
+ elem_counter = na_iterator_next(&iter_counters))
+ {
+ const char *name;
+ uint64_t value;
+
+ name = na_child_get_string (elem_counter, "name");
+ if (name == NULL)
+ continue;
+
+ value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
+ if (value == UINT64_MAX)
+ continue;
+
+ if (!strcmp(name, "read_data")) {
+ perf_data.read_bytes = value;
+ perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
+ } else if (!strcmp(name, "write_data")) {
+ perf_data.write_bytes = value;
+ perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
+ } else if (!strcmp(name, "read_ops")) {
+ perf_data.read_ops = value;
+ perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
+ } else if (!strcmp(name, "write_ops")) {
+ perf_data.write_ops = value;
+ perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
+ } else if (!strcmp(name, "read_latency")) {
+ perf_data.read_latency = value;
+ perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
+ } else if (!strcmp(name, "write_latency")) {
+ perf_data.write_latency = value;
+ perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
+ }
+ } /* for (elem_counter) */
+
+ submit_volume_perf_data (hostname, v, &perf_data);
+ } /* for (volume) */
+
+ return (0);
+} /* }}} int cna_handle_volume_perf_data */
+
+static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
+{
+ na_elem_t *e;
+
+ if (cd == NULL)
+ return (EINVAL);
+
+ if (cd->query != NULL)
+ return (0);
+
+ cd->query = na_elem_new ("perf-object-get-instances");
+ if (cd->query == NULL)
+ {
+ ERROR ("netapp plugin: na_elem_new failed.");
+ return (-1);
+ }
+ na_child_add_string (cd->query, "objectname", "volume");
+
+ e = na_elem_new("counters");
+ if (e == NULL)
+ {
+ na_elem_free (cd->query);
+ cd->query = NULL;
+ ERROR ("netapp plugin: na_elem_new failed.");
+ return (-1);
+ }
+ /* "foo" means: This string has to be here but the content doesn't matter. */
+ na_child_add_string(e, "foo", "read_ops");
+ na_child_add_string(e, "foo", "write_ops");
+ na_child_add_string(e, "foo", "read_data");
+ na_child_add_string(e, "foo", "write_data");
+ na_child_add_string(e, "foo", "read_latency");
+ na_child_add_string(e, "foo", "write_latency");
+ na_child_add(cd->query, e);
+
+ return (0);
+} /* }}} int cna_setup_volume_perf */
+
+static int cna_query_volume_perf (host_config_t *host) /* {{{ */
+{
+ na_elem_t *data;
+ int status;
+ time_t now;
+
+ if (host == NULL)
+ return (EINVAL);
+
+ /* If the user did not configure volume performance statistics, return
+ * without doing anything. */
+ if (host->cfg_volume_perf == NULL)
+ return (0);
+
+ now = time (NULL);
+ if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
+ return (0);
+
+ status = cna_setup_volume_perf (host->cfg_volume_perf);
+ if (status != 0)
+ return (status);
+ assert (host->cfg_volume_perf->query != NULL);
+
+ data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
+ if (na_results_status (data) != NA_OK)
+ {
+ ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed: %s",
+ na_results_reason (data));
+ na_elem_free (data);
+ return (-1);
+ }
+
+ status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data);
+
+ if (status == 0)
+ host->cfg_volume_perf->interval.last_read = now;
+
+ na_elem_free (data);
+ return (status);
+} /* }}} int cna_query_volume_perf */
+
+/* Data corresponding to <VolumeUsage /> */
+static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
+ cfg_volume_usage_t *cfg_volume)
+{
+ data_volume_usage_t *v;
+
+ for (v = cfg_volume->volumes; v != NULL; v = v->next)
+ {
+ if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
+ submit_double (hostname, /* plugin instance = */ v->name,
+ "df_complex", "free",
+ (double) v->norm_free, /* timestamp = */ 0);
+
+ if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
+ submit_double (hostname, /* plugin instance = */ v->name,
+ "df_complex", "used",
+ (double) v->norm_used, /* timestamp = */ 0);
+
+ if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
+ submit_double (hostname, /* plugin instance = */ v->name,
+ "df_complex", "snap_reserved",
+ (double) v->snap_reserved, /* timestamp = */ 0);
+
+ if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
+ submit_double (hostname, /* plugin instance = */ v->name,
+ "df_complex", "snap_used",
+ (double) v->snap_used, /* timestamp = */ 0);
+
+ if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
+ submit_double (hostname, /* plugin instance = */ v->name,
+ "df_complex", "sis_saved",
+ (double) v->sis_saved, /* timestamp = */ 0);
+
+ /* Clear all the HAVE_* flags */
+ v->flags &= ~HAVE_VOLUME_USAGE_ALL;
+ } /* for (v = cfg_volume->volumes) */
+
+ return (0);
+} /* }}} int cna_submit_volume_usage_data */
+
+static int cna_handle_volume_usage_data (const char *hostname, /* {{{ */
+ cfg_volume_usage_t *cfg_volume, na_elem_t *data)
+{
+ na_elem_t *elem_volume;
+ na_elem_t *elem_volumes;
+ na_elem_iter_t iter_volume;
+
+ elem_volumes = na_elem_child (data, "volumes");
+ if (elem_volumes == NULL)
+ {
+ ERROR ("netapp plugin: cna_handle_volume_usage_data: "
+ "na_elem_child (\"volumes\") failed.");
+ return (-1);
+ }
+
+ iter_volume = na_child_iterator (elem_volumes);
+ for (elem_volume = na_iterator_next (&iter_volume);
+ elem_volume != NULL;
+ elem_volume = na_iterator_next (&iter_volume))
+ {
+ const char *volume_name;
+
+ data_volume_usage_t *v;
+ uint64_t value;
+
+ na_elem_t *sis;