X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fnetapp.c;h=5c4b6e7372361d309a3207a8d812028ee6f4034a;hp=c50b3dbdbcb707860d7a4658d211e844f1b3fe3a;hb=83077c18c3e78739c2d2d18debf99875944eaa72;hpb=053bea810096f410d3b03ade7ef761da05565a45
diff --git a/src/netapp.c b/src/netapp.c
index c50b3dbd..5c4b6e73 100644
--- a/src/netapp.c
+++ b/src/netapp.c
@@ -38,8 +38,8 @@ typedef void service_handler_t(host_config_t *host, na_elem_t *result, void *dat
struct cna_interval_s
{
- time_t interval;
- time_t last_read;
+ cdtime_t interval;
+ cdtime_t last_read;
};
typedef struct cna_interval_s cna_interval_t;
@@ -79,7 +79,7 @@ typedef struct {
cna_interval_t interval;
na_elem_t *query;
- time_t timestamp;
+ cdtime_t timestamp;
uint64_t name_cache_hit;
uint64_t name_cache_miss;
uint64_t find_dir_hit;
@@ -104,7 +104,7 @@ typedef struct {
typedef struct disk_s {
char *name;
uint32_t flags;
- time_t timestamp;
+ cdtime_t timestamp;
uint64_t disk_busy;
uint64_t base_for_disk_busy;
double disk_busy_percent;
@@ -153,7 +153,7 @@ typedef struct data_volume_perf_s data_volume_perf_t;
struct data_volume_perf_s {
char *name;
uint32_t flags;
- time_t timestamp;
+ cdtime_t timestamp;
uint64_t read_bytes;
uint64_t write_bytes;
@@ -242,7 +242,7 @@ struct host_config_s {
int port;
char *username;
char *password;
- int interval;
+ cdtime_t interval;
na_server_t *srv;
cfg_wafl_t *cfg_wafl;
@@ -566,7 +566,7 @@ 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, int interval)
+ cdtime_t timestamp, cdtime_t interval)
{
value_list_t vl = VALUE_LIST_INIT;
@@ -595,7 +595,7 @@ static int submit_values (const char *host, /* {{{ */
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, int interval)
+ cdtime_t timestamp, cdtime_t interval)
{
value_t values[2];
@@ -607,7 +607,8 @@ static int submit_two_counters (const char *host, const char *plugin_inst, /* {{
} /* }}} int submit_two_counters */
static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
- const char *type, const char *type_inst, counter_t counter, time_t timestamp, int interval)
+ const char *type, const char *type_inst, counter_t counter,
+ cdtime_t timestamp, cdtime_t interval)
{
value_t v;
@@ -619,7 +620,7 @@ static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
- time_t timestamp, int interval)
+ cdtime_t timestamp, cdtime_t interval)
{
value_t values[2];
@@ -631,7 +632,8 @@ static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ *
} /* }}} int submit_two_gauge */
static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
- const char *type, const char *type_inst, double d, time_t timestamp, int interval)
+ const char *type, const char *type_inst, double d,
+ cdtime_t timestamp, cdtime_t interval)
{
value_t v;
@@ -650,8 +652,8 @@ static int submit_cache_ratio (const char *host, /* {{{ */
uint64_t new_misses,
uint64_t old_hits,
uint64_t old_misses,
- time_t timestamp,
- int interval)
+ cdtime_t timestamp,
+ cdtime_t interval)
{
value_t v;
@@ -816,6 +818,16 @@ static int submit_volume_perf_data (const char *hostname, /* {{{ */
return (0);
} /* }}} int submit_volume_perf_data */
+static cdtime_t cna_child_get_cdtime (na_elem_t *data) /* {{{ */
+{
+ time_t t;
+
+ t = (time_t) na_child_get_uint64 (data, "timestamp", /* default = */ 0);
+
+ return (TIME_T_TO_CDTIME_T (t));
+} /* }}} cdtime_t cna_child_get_cdtime */
+
+
/*
* Query functions
*
@@ -835,7 +847,7 @@ static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /*
memset (&perf_data, 0, sizeof (perf_data));
- perf_data.timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
+ perf_data.timestamp = cna_child_get_cdtime (data);
instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
if (instances == NULL)
@@ -950,7 +962,7 @@ static int cna_query_wafl (host_config_t *host) /* {{{ */
{
na_elem_t *data;
int status;
- time_t now;
+ cdtime_t now;
if (host == NULL)
return (EINVAL);
@@ -959,7 +971,7 @@ static int cna_query_wafl (host_config_t *host) /* {{{ */
if (host->cfg_wafl == NULL)
return (0);
- now = time (NULL);
+ now = cdtime ();
if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
return (0);
@@ -988,9 +1000,9 @@ static int cna_query_wafl (host_config_t *host) /* {{{ */
/* Data corresponding to */
static int cna_handle_disk_data (const char *hostname, /* {{{ */
- cfg_disk_t *cfg_disk, na_elem_t *data, int interval)
+ cfg_disk_t *cfg_disk, na_elem_t *data, cdtime_t interval)
{
- time_t timestamp;
+ cdtime_t timestamp;
na_elem_t *instances;
na_elem_t *instance;
na_elem_iter_t instance_iter;
@@ -999,7 +1011,7 @@ static int cna_handle_disk_data (const char *hostname, /* {{{ */
if ((cfg_disk == NULL) || (data == NULL))
return (EINVAL);
- timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
+ timestamp = cna_child_get_cdtime (data);
instances = na_elem_child (data, "instances");
if (instances == NULL)
@@ -1144,7 +1156,7 @@ static int cna_query_disk (host_config_t *host) /* {{{ */
{
na_elem_t *data;
int status;
- time_t now;
+ cdtime_t now;
if (host == NULL)
return (EINVAL);
@@ -1154,7 +1166,7 @@ static int cna_query_disk (host_config_t *host) /* {{{ */
if (host->cfg_disk == NULL)
return (0);
- now = time (NULL);
+ now = cdtime ();
if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
return (0);
@@ -1183,14 +1195,14 @@ static int cna_query_disk (host_config_t *host) /* {{{ */
/* Data corresponding to */
static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
- cfg_volume_perf_t *cvp, na_elem_t *data, int interval)
+ cfg_volume_perf_t *cvp, na_elem_t *data, cdtime_t interval)
{
- time_t timestamp;
+ cdtime_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);
+ timestamp = cna_child_get_cdtime (data);
elem_instances = na_elem_child(data, "instances");
if (elem_instances == NULL)
@@ -1315,7 +1327,7 @@ static int cna_query_volume_perf (host_config_t *host) /* {{{ */
{
na_elem_t *data;
int status;
- time_t now;
+ cdtime_t now;
if (host == NULL)
return (EINVAL);
@@ -1325,7 +1337,7 @@ static int cna_query_volume_perf (host_config_t *host) /* {{{ */
if (host->cfg_volume_perf == NULL)
return (0);
- now = time (NULL);
+ now = cdtime ();
if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
return (0);
@@ -1444,7 +1456,7 @@ static int cna_change_volume_status (const char *hostname, /* {{{ */
notification_t n;
memset (&n, 0, sizeof (&n));
- n.time = time (NULL);
+ n.time = cdtime ();
sstrncpy (n.host, hostname, sizeof (n.host));
sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance));
@@ -1679,7 +1691,7 @@ static int cna_query_volume_usage (host_config_t *host) /* {{{ */
{
na_elem_t *data;
int status;
- time_t now;
+ cdtime_t now;
if (host == NULL)
return (EINVAL);
@@ -1689,7 +1701,7 @@ static int cna_query_volume_usage (host_config_t *host) /* {{{ */
if (host->cfg_volume_usage == NULL)
return (0);
- now = time (NULL);
+ now = cdtime ();
if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
return (0);
@@ -1730,9 +1742,9 @@ static int cna_handle_system_data (const char *hostname, /* {{{ */
uint32_t counter_flags = 0;
const char *instance;
- time_t timestamp;
+ cdtime_t timestamp;
- timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
+ timestamp = cna_child_get_cdtime (data);
instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
if (instances == NULL)
@@ -1839,7 +1851,7 @@ static int cna_query_system (host_config_t *host) /* {{{ */
{
na_elem_t *data;
int status;
- time_t now;
+ cdtime_t now;
if (host == NULL)
return (EINVAL);
@@ -1848,7 +1860,7 @@ static int cna_query_system (host_config_t *host) /* {{{ */
if (host->cfg_system == NULL)
return (0);
- now = time (NULL);
+ now = cdtime ();
if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
return (0);
@@ -1905,23 +1917,12 @@ static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
cna_interval_t *out_interval)
{
- time_t tmp;
-
- if ((ci == NULL) || (out_interval == NULL))
- return (EINVAL);
-
- if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
- {
- WARNING ("netapp plugin: The `Interval' option needs exactly one numeric argument.");
- return (-1);
- }
+ cdtime_t tmp = 0;
+ int status;
- tmp = (time_t) (ci->values[0].value.number + .5);
- if (tmp < 1)
- {
- WARNING ("netapp plugin: The `Interval' option needs a positive integer argument.");
- return (-1);
- }
+ status = cf_util_get_cdtime (ci, &tmp);
+ if (status != 0)
+ return (status);
out_interval->interval = tmp;
out_interval->last_read = 0;
@@ -2421,11 +2422,7 @@ static host_config_t *cna_config_host (const oconfig_item_t *ci) /* {{{ */
} else if (!strcasecmp(item->key, "Password")) {
status = cf_util_get_string (item, &host->password);
} else if (!strcasecmp(item->key, "Interval")) {
- 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) {
- WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
- continue;
- }
- host->interval = item->values[0].value.number;
+ status = cf_util_get_cdtime (item, &host->interval);
} else if (!strcasecmp(item->key, "WAFL")) {
cna_config_wafl(host, item);
} else if (!strcasecmp(item->key, "Disks")) {
@@ -2556,8 +2553,7 @@ static int cna_config (oconfig_item_t *ci) { /* {{{ */
ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name);
- memset (&interval, 0, sizeof (interval));
- interval.tv_sec = host->interval;
+ CDTIME_T_TO_TIMESPEC (host->interval, &interval);
memset (&ud, 0, sizeof (ud));
ud.data = host;