_ds = new DataSet (_type, dsrc);
}
+ /**
+ * Returns the interval (in milliseconds) of the value list.
+ */
public long getInterval() {
return _interval;
}
+ /**
+ * Sets the interval (in milliseconds) of the value list.
+ */
public void setInterval(long interval) {
_interval = interval;
}
* Global variables
*/
char hostname_g[DATA_MAX_NAME_LEN];
-int interval_g;
+cdtime_t interval_g;
int timeout_g;
#if HAVE_LIBKSTAT
kstat_ctl_t *kc;
str = global_option_get ("Interval");
if (str == NULL)
- str = "10";
- interval_g = atoi (str);
- if (interval_g <= 0)
{
- fprintf (stderr, "Cannot set the interval to a correct value.\n"
- "Please check your settings.\n");
- return (-1);
+ interval_g = TIME_T_TO_CDTIME_T (10);
+ }
+ else
+ {
+ double tmp;
+
+ tmp = atof (str);
+ if (tmp <= 0.0)
+ {
+ fprintf (stderr, "Cannot set the interval to a "
+ "correct value.\n"
+ "Please check your settings.\n");
+ return (-1);
+ }
+
+ interval_g = DOUBLE_TO_CDTIME_T (tmp);
}
- DEBUG ("interval_g = %i;", interval_g);
+ DEBUG ("interval_g = %.3f;", CDTIME_T_TO_DOUBLE (interval_g));
str = global_option_get ("Timeout");
if (str == NULL)
static int do_loop (void)
{
- struct timeval tv_now;
- struct timeval tv_next;
- struct timeval tv_wait;
- struct timespec ts_wait;
+ cdtime_t wait_until;
+
+ wait_until = cdtime () + interval_g;
while (loop == 0)
{
- if (gettimeofday (&tv_next, NULL) < 0)
- {
- char errbuf[1024];
- ERROR ("gettimeofday failed: %s",
- sstrerror (errno, errbuf,
- sizeof (errbuf)));
- return (-1);
- }
- tv_next.tv_sec += interval_g;
+ struct timespec ts_wait = { 0, 0 };
+ cdtime_t now;
#if HAVE_LIBKSTAT
update_kstat ();
/* Issue all plugins */
plugin_read_all ();
- if (gettimeofday (&tv_now, NULL) < 0)
- {
- char errbuf[1024];
- ERROR ("gettimeofday failed: %s",
- sstrerror (errno, errbuf,
- sizeof (errbuf)));
- return (-1);
- }
-
- if (timeval_cmp (tv_next, tv_now, &tv_wait) <= 0)
+ now = cdtime ();
+ if (now >= wait_until)
{
WARNING ("Not sleeping because the next interval is "
- "%i.%06i seconds in the past!",
- (int) tv_wait.tv_sec, (int) tv_wait.tv_usec);
+ "%.3f seconds in the past!",
+ CDTIME_T_TO_DOUBLE (now - wait_until));
+ wait_until = now + interval_g;
continue;
}
- ts_wait.tv_sec = tv_wait.tv_sec;
- ts_wait.tv_nsec = (long) (1000 * tv_wait.tv_usec);
+ CDTIME_T_TO_TIMESPEC (wait_until - now, &ts_wait);
+ wait_until = wait_until + interval_g;
- while ((loop == 0) && (nanosleep (&ts_wait, &ts_wait) == -1))
+ while ((loop == 0) && (nanosleep (&ts_wait, &ts_wait) != 0))
{
if (errno != EINTR)
{
}
} /* while (loop == 0) */
- DEBUG ("return (0);");
return (0);
} /* int do_loop */
/* Type for time as used by "utils_time.h" */
typedef uint64_t cdtime_t;
-extern char hostname_g[];
-extern int interval_g;
-extern int timeout_g;
+extern char hostname_g[];
+extern cdtime_t interval_g;
+extern int timeout_g;
#endif /* COLLECTD_H */
DEBUG ("host_processors returned %i %s", (int) cpu_list_len, cpu_list_len == 1 ? "processor" : "processors");
INFO ("cpu plugin: Found %i processor%s.", (int) cpu_list_len, cpu_list_len == 1 ? "" : "s");
- cpu_temp_retry_max = 86400 / interval_g;
+ cpu_temp_retry_max = 86400 / CDTIME_T_TO_TIME_T (interval_g);
/* #endif PROCESSOR_CPU_LOAD_INFO */
#elif defined(HAVE_LIBKSTAT)
}
fprintf (use_stdio == 1 ? stdout : stderr,
- "PUTVAL %s interval=%i %s\n",
- filename, vl->interval, values);
+ "PUTVAL %s interval=%.3f %s\n",
+ filename,
+ CDTIME_T_TO_DOUBLE (vl->interval),
+ values);
return (0);
}
udb_query_prepare_result (q, prep_area, hostname_g,
/* plugin = */ "dbi", db->name,
- column_names, column_num, /* interval = */ -1);
+ column_names, column_num, /* interval = */ 0);
/* 0 = error; 1 = success; */
status = dbi_result_first_row (res); /* {{{ */
pcap_obj = pcap_open_live ((pcap_device != NULL) ? pcap_device : "any",
PCAP_SNAPLEN,
0 /* Not promiscuous */,
- interval_g,
+ (int) CDTIME_T_TO_MS (interval_g / 2),
pcap_error);
if (pcap_obj == NULL)
{
char buffer[1024];
#ifdef HAVE_SETENV
- ssnprintf (buffer, sizeof (buffer), "%i", interval_g);
+ ssnprintf (buffer, sizeof (buffer), "%.3f", CDTIME_T_TO_DOUBLE (interval_g));
setenv ("COLLECTD_INTERVAL", buffer, /* overwrite = */ 1);
ssnprintf (buffer, sizeof (buffer), "%s", hostname_g);
setenv ("COLLECTD_HOSTNAME", buffer, /* overwrite = */ 1);
#else
- ssnprintf (buffer, sizeof (buffer), "COLLECTD_INTERVAL=%i", interval_g);
+ ssnprintf (buffer, sizeof (buffer), "COLLECTD_INTERVAL=%.3f",
+ CDTIME_T_TO_DOUBLE (interval_g));
putenv (buffer);
ssnprintf (buffer, sizeof (buffer), "COLLECTD_HOSTNAME=%s", hostname_g);
map->type, map->type_instance,
ds->ds_num);
if (se != NULL)
- se->vl.interval = (int) msg_meta.metric.tmax;
+ se->vl.interval = TIME_T_TO_CDTIME_T (msg_meta.metric.tmax);
pthread_mutex_unlock (&staging_lock);
if (se == NULL)
int status;
/* Don't send `ADD' notifications during startup (~ 1 minute) */
- c_ipmi_init_in_progress = 1 + (60 / interval_g);
+ time_t iv = CDTIME_T_TO_TIME_T (interval_g);
+ c_ipmi_init_in_progress = 1 + (60 / iv);
c_ipmi_active = 1;
}
/* Set the `interval' member.. */
- status = ctoj_long (jvm_env, (jlong) vl->interval,
+ status = ctoj_long (jvm_env,
+ (jlong) CDTIME_T_TO_MS (vl->interval),
c_valuelist, o_valuelist, "setInterval");
if (status != 0)
{
return (NULL);
}
- /* Set the `interval' member.. */
+ /* Set the `severity' member.. */
status = ctoj_int (jvm_env, (jint) n->severity,
c_notification, o_notification, "setSeverity");
if (status != 0)
return (-1);
}
/* Java measures time in milliseconds. */
- vl->time = (time_t) (tmp_long / ((jlong) 1000));
+ vl->time = MS_TO_CDTIME_T (tmp_long);
status = jtoc_long (jvm_env, &tmp_long,
class_ptr, object_ptr, "getInterval");
ERROR ("java plugin: jtoc_value_list: jtoc_long (getInterval) failed.");
return (-1);
}
- vl->interval = (int) tmp_long;
+ vl->interval = MS_TO_CDTIME_T (tmp_long);
status = jtoc_values_array (jvm_env, ds, vl, class_ptr, object_ptr);
if (status != 0)
p.events = POLLIN | POLLERR | POLLHUP;
p.revents = 0;
- status = poll (&p, /* nfds = */ 1, /* timeout = */ 1000 * interval_g);
+ status = poll (&p, /* nfds = */ 1,
+ /* timeout = */ CDTIME_T_TO_MS (interval_g));
if (status <= 0)
{
if (status == 0)
{
- ERROR ("memcached: poll(2) timed out after %i seconds.", interval_g);
+ ERROR ("memcached: poll(2) timed out after %.3f seconds.",
+ CDTIME_T_TO_DOUBLE (interval_g));
}
else
{
char node[NI_MAXHOST];
/* char service[NI_MAXSERV]; */
int port;
- int interval;
+ cdtime_t interval;
mb_slave_t *slaves;
size_t slaves_num;
status = -1;
}
else if (strcasecmp ("Interval", child->key) == 0)
- status = cf_util_get_int (child, &host->interval);
+ status = cf_util_get_cdtime (child, &host->interval);
else if (strcasecmp ("Slave", child->key) == 0)
/* Don't set status: Gracefully continue if a slave fails. */
mb_config_add_slave (host, child);
{
user_data_t ud;
char name[1024];
- struct timespec interval;
+ struct timespec interval = { 0, 0 };
ud.data = host;
ud.free_func = host_free;
ssnprintf (name, sizeof (name), "modbus-%s", host->host);
- interval.tv_nsec = 0;
- if (host->interval > 0)
- interval.tv_sec = host->interval;
- else
- interval.tv_sec = 0;
+ CDTIME_T_TO_TIMESPEC (host->interval, &interval);
plugin_register_complex_read (/* group = */ NULL, name,
- mb_read, (interval.tv_sec > 0) ? &interval : NULL, &ud);
+ /* callback = */ mb_read,
+ /* interval = */ (host->interval > 0) ? &interval : NULL,
+ &ud);
}
else
{
status = parse_part_number (&buffer, &buffer_size,
&tmp);
if (status == 0)
- vl.interval = (int) tmp;
+ vl.interval = TIME_T_TO_CDTIME_T (tmp);
}
else if (pkg_type == TYPE_HOST)
{
if (vl_def->interval != vl->interval)
{
+ /* TODO: Create a new type for sub-second intervals. */
if (write_part_number (&buffer, &buffer_size, TYPE_INTERVAL,
- (uint64_t) vl->interval))
+ (uint64_t) CDTIME_T_TO_TIME_T (vl->interval)))
return (-1);
vl_def->interval = vl->interval;
}
static int ow_family_features_num = STATIC_ARRAY_SIZE (ow_family_features);
static char *device_g = NULL;
-static int ow_interval = 0;
+static cdtime_t ow_interval = 0;
static const char *config_keys[] =
{
CDTIME_T_TO_TIMESPEC (ow_interval, &cb_interval);
plugin_register_complex_read (/* group = */ NULL, "onewire", cow_read,
- &cb_interval, /* user data = */ NULL);
+ (ow_interval != 0) ? &cb_interval : NULL,
+ /* user data = */ NULL);
plugin_register_shutdown ("onewire", cow_shutdown);
return (0);
status = udb_query_prepare_result (q, prep_area, hostname_g,
/* plugin = */ "oracle", db->name, column_names, column_num,
- /* interval = */ -1);
+ /* interval = */ 0);
if (status != 0)
{
ERROR ("oracle plugin: o_read_database_query (%s, %s): "
{ "", NULL }
};
-struct {
- char name[64];
- int *var;
-} g_integers[] =
-{
- { "Collectd::interval_g", &interval_g },
- { "", NULL }
-};
-
/*
* Helper functions for data type conversion.
*/
}
if (NULL != (tmp = hv_fetch (hash, "interval", 8, 0)))
- vl->interval = SvIV (*tmp);
+ {
+ double t = SvNV (*tmp);
+ vl->interval = DOUBLE_TO_CDTIME_T (t);
+ }
if (NULL != (tmp = hv_fetch (hash, "host", 4, 0)))
sstrncpy (vl->host, SvPV_nolen (*tmp), sizeof (vl->host));
return -1;
}
- if (NULL == hv_store (hash, "interval", 8, newSViv (vl->interval), 0))
- return -1;
+ {
+ double t = CDTIME_T_TO_DOUBLE (vl->interval);
+ if (NULL == hv_store (hash, "interval", 8, newSVnv (t), 0))
+ return -1;
+ }
if ('\0' != vl->host[0])
if (NULL == hv_store (hash, "host", 4, newSVpv (vl->host, 0), 0))
return 0;
} /* static int g_pv_set (pTHX_ SV *, MAGIC *) */
-static int g_iv_get (pTHX_ SV *var, MAGIC *mg)
+static int g_interval_get (pTHX_ SV *var, MAGIC *mg)
{
- int *iv = (int *)mg->mg_ptr;
- sv_setiv (var, *iv);
+ cdtime_t *interval = (cdtime_t *)mg->mg_ptr;
+ double nv;
+
+ nv = CDTIME_T_TO_DOUBLE (*interval);
+
+ sv_setnv (var, nv);
return 0;
-} /* static int g_iv_get (pTHX_ SV *, MAGIC *) */
+} /* static int g_interval_get (pTHX_ SV *, MAGIC *) */
-static int g_iv_set (pTHX_ SV *var, MAGIC *mg)
+static int g_interval_set (pTHX_ SV *var, MAGIC *mg)
{
- int *iv = (int *)mg->mg_ptr;
- *iv = (int)SvIV (var);
+ cdtime_t *interval = (cdtime_t *)mg->mg_ptr;
+ double nv;
+
+ nv = (double)SvNV (var);
+
+ *interval = DOUBLE_TO_CDTIME_T (nv);
return 0;
-} /* static int g_iv_set (pTHX_ SV *, MAGIC *) */
+} /* static int g_interval_set (pTHX_ SV *, MAGIC *) */
static MGVTBL g_pv_vtbl = {
g_pv_get, g_pv_set, NULL, NULL, NULL, NULL, NULL
, NULL
#endif
};
-static MGVTBL g_iv_vtbl = {
- g_iv_get, g_iv_set, NULL, NULL, NULL, NULL, NULL
+static MGVTBL g_interval_vtbl = {
+ g_interval_get, g_interval_set, NULL, NULL, NULL, NULL, NULL
#if HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL
, NULL
#endif
g_strings[i].var, 0);
}
- /* global integers */
- for (i = 0; '\0' != g_integers[i].name[0]; ++i) {
- tmp = get_sv (g_integers[i].name, 1);
- sv_magicext (tmp, NULL, PERL_MAGIC_ext, &g_iv_vtbl,
- (char *)g_integers[i].var, 0);
- }
+ tmp = get_sv ("Collectd::interval_g", /* create = */ 1);
+ sv_magicext (tmp, NULL, /* how = */ PERL_MAGIC_ext,
+ /* vtbl = */ &g_interval_vtbl,
+ /* name = */ (char *) &interval_g, /* namelen = */ 0);
+
return;
} /* static void xs_init (pTHX) */
while (read_loop != 0)
{
read_func_t *rf;
- struct timeval now;
+ cdtime_t now;
int status;
int rf_type;
int rc;
{
struct timespec abstime;
- gettimeofday (&now, /* timezone = */ NULL);
+ now = cdtime ();
- abstime.tv_sec = now.tv_sec + interval_g;
- abstime.tv_nsec = 1000 * now.tv_usec;
+ CDTIME_T_TO_TIMESPEC (now + interval_g, &abstime);
pthread_mutex_lock (&read_lock);
pthread_cond_timedwait (&read_cond, &read_lock,
if ((rf->rf_interval.tv_sec == 0) && (rf->rf_interval.tv_nsec == 0))
{
- gettimeofday (&now, /* timezone = */ NULL);
+ now = cdtime ();
- rf->rf_interval.tv_sec = interval_g;
- rf->rf_interval.tv_nsec = 0;
+ CDTIME_T_TO_TIMESPEC (interval_g, &rf->rf_interval);
rf->rf_effective_interval = rf->rf_interval;
- rf->rf_next_read.tv_sec = now.tv_sec;
- rf->rf_next_read.tv_nsec = 1000 * now.tv_usec;
+ CDTIME_T_TO_TIMESPEC (now, &rf->rf_next_read);
}
/* sleep until this entry is due,
}
/* update the ``next read due'' field */
- gettimeofday (&now, /* timezone = */ NULL);
+ now = cdtime ();
DEBUG ("plugin_read_thread: Effective interval of the "
"%s plugin is %i.%09i.",
NORMALIZE_TIMESPEC (rf->rf_next_read);
/* Check, if `rf_next_read' is in the past. */
- if ((rf->rf_next_read.tv_sec < now.tv_sec)
- || ((rf->rf_next_read.tv_sec == now.tv_sec)
- && (rf->rf_next_read.tv_nsec < (1000 * now.tv_usec))))
+ if (TIMESPEC_TO_CDTIME_T (&rf->rf_next_read) < now)
{
/* `rf_next_read' is in the past. Insert `now'
* so this value doesn't trail off into the
* past too much. */
- rf->rf_next_read.tv_sec = now.tv_sec;
- rf->rf_next_read.tv_nsec = 1000 * now.tv_usec;
+ CDTIME_T_TO_TIMESPEC (now, &rf->rf_next_read);
}
DEBUG ("plugin_read_thread: Next read of the %s plugin at %i.%09i.",
if (vl->interval <= 0)
vl->interval = interval_g;
- DEBUG ("plugin_dispatch_values: time = %.3f; interval = %i; "
+ DEBUG ("plugin_dispatch_values: time = %.3f; interval = %.3f; "
"host = %s; "
"plugin = %s; plugin_instance = %s; "
"type = %s; type_instance = %s;",
- CDTIME_T_TO_DOUBLE (vl->time), vl->interval,
+ CDTIME_T_TO_DOUBLE (vl->time),
+ CDTIME_T_TO_DOUBLE (vl->interval),
vl->host,
vl->plugin, vl->plugin_instance,
vl->type, vl->type_instance);
value_t *values;
int values_len;
cdtime_t time;
- int interval;
+ cdtime_t interval;
char host[DATA_MAX_NAME_LEN];
char plugin[DATA_MAX_NAME_LEN];
char plugin_instance[DATA_MAX_NAME_LEN];
udb_query_t **queries;
size_t queries_num;
- int interval;
+ cdtime_t interval;
char *host;
char *port;
params[i] = db->user;
break;
case C_PSQL_PARAM_INTERVAL:
- ssnprintf (interval, sizeof (interval), "%i",
- db->interval > 0 ? db->interval : interval_g);
+ ssnprintf (interval, sizeof (interval), "%.3f",
+ (db->interval > 0)
+ ? CDTIME_T_TO_DOUBLE (db->interval) : interval_g);
params[i] = interval;
break;
default:
return 0;
} /* config_set_s */
-static int config_set_i (char *name, int *var,
- const oconfig_item_t *ci, int min)
-{
- int value;
-
- if ((0 != ci->children_num) || (1 != ci->values_num)
- || (OCONFIG_TYPE_NUMBER != ci->values[0].type)) {
- log_err ("%s expects a single number argument.", name);
- return 1;
- }
-
- value = (int)ci->values[0].value.number;
-
- if (value < min) {
- log_err ("%s expects a number greater or equal to %i.", name, min);
- return 1;
- }
-
- *var = value;
- return 0;
-} /* config_set_s */
-
static int config_query_param_add (udb_query_t *q, oconfig_item_t *ci)
{
c_psql_user_data_t *data;
c_psql_database_t *db;
char cb_name[DATA_MAX_NAME_LEN];
- struct timespec cb_interval;
+ struct timespec cb_interval = { 0, 0 };
user_data_t ud;
int i;
udb_query_pick_from_list (c, queries, queries_num,
&db->queries, &db->queries_num);
else if (0 == strcasecmp (c->key, "Interval"))
- config_set_i ("Interval", &db->interval, c, /* min = */ 1);
+ cf_util_get_cdtime (c, &db->interval);
else
log_warn ("Ignoring unknown config key \"%s\".", c->key);
}
ssnprintf (cb_name, sizeof (cb_name), "postgresql-%s", db->database);
- memset (&cb_interval, 0, sizeof (cb_interval));
- if (db->interval > 0)
- cb_interval.tv_sec = (time_t)db->interval;
+ CDTIME_T_TO_TIMESPEC (db->interval, &cb_interval);
plugin_register_complex_read ("postgresql", cb_name, c_psql_read,
- /* interval = */ &cb_interval, &ud);
+ /* interval = */ (db->interval > 0) ? &cb_interval : NULL,
+ &ud);
return 0;
} /* c_psql_config_database */
break;
}
- /* TODO: Remove the macro once interval_g is of type cdtime_t. */
- cdt_timeout = TIME_T_TO_CDTIME_T (interval_g);
- cdt_timeout = cdt_timeout * 3 / 4;
+ cdt_timeout = interval_g * 3 / 4;
if (cdt_timeout < TIME_T_TO_CDTIME_T (2))
cdt_timeout = TIME_T_TO_CDTIME_T (2);
rrdcreate_config.heartbeat = 2 * rrdcreate_config.stepsize;
if ((rrdcreate_config.heartbeat > 0)
- && (rrdcreate_config.heartbeat < interval_g))
+ && (rrdcreate_config.heartbeat < CDTIME_T_TO_TIME_T (interval_g)))
WARNING ("rrdtool plugin: Your `heartbeat' is "
"smaller than your `interval'. This will "
"likely cause problems.");
else if ((rrdcreate_config.stepsize > 0)
- && (rrdcreate_config.stepsize < interval_g))
+ && (rrdcreate_config.stepsize < CDTIME_T_TO_TIME_T (interval_g)))
WARNING ("rrdtool plugin: Your `stepsize' is "
"smaller than your `interval'. This will "
"create needlessly big RRD-files.");
sstrncpy (vl.host, host->name, sizeof (vl.host));
sstrncpy (vl.plugin, "snmp", sizeof (vl.plugin));
- vl.interval = (int) CDTIME_T_TO_TIME_T (host->interval);
+ vl.interval = host->interval;
subid = 0;
have_more = 1;
sstrncpy (vl.type, data->type, sizeof (vl.type));
sstrncpy (vl.type_instance, data->instance.string, sizeof (vl.type_instance));
- vl.interval = (int) CDTIME_T_TO_TIME_T (host->interval);
+ vl.interval = host->interval;
req = snmp_pdu_create (SNMP_MSG_GET);
if (req == NULL)
host = ud->data;
- /* FIXME: Convert "interval_g" to cdtime_t, too. */
if (host->interval == 0)
- host->interval = TIME_T_TO_CDTIME_T (interval_g);
+ host->interval = interval_g;
time_start = cdtime ();
{
difference = curr_counter - prev_counter;
}
- rate = ((double) difference) / ((double) vl->interval);
+ rate = ((double) difference) / CDTIME_T_TO_DOUBLE (vl->interval);
/* Modify the rate. */
if (!isnan (data->factor))
rate += data->offset;
/* Calculate the internal counter. */
- int_fraction += (rate * ((double) vl->interval));
+ int_fraction += (rate * CDTIME_T_TO_DOUBLE (vl->interval));
difference = (uint64_t) int_fraction;
int_fraction -= ((double) difference);
int_counter += difference;
/* Calcualte the rate */
difference = curr_derive - prev_derive;
- rate = ((double) difference) / ((double) vl->interval);
+ rate = ((double) difference) / CDTIME_T_TO_DOUBLE (vl->interval);
/* Modify the rate. */
if (!isnan (data->factor))
rate += data->offset;
/* Calculate the internal derive. */
- int_fraction += (rate * ((double) vl->interval));
+ int_fraction += (rate * CDTIME_T_TO_DOUBLE (vl->interval));
if (int_fraction < 0.0) /* handle negative integer rounding correctly */
difference = ((int64_t) int_fraction) - 1;
else
if (status != 0)
int_fraction = 0.0;
- rate = ((double) curr_absolute) / ((double) vl->interval);
+ rate = ((double) curr_absolute) / CDTIME_T_TO_DOUBLE (vl->interval);
/* Modify the rate. */
if (!isnan (data->factor))
rate += data->offset;
/* Calculate the new absolute. */
- int_fraction += (rate * ((double) vl->interval));
+ int_fraction += (rate * CDTIME_T_TO_DOUBLE (vl->interval));
curr_absolute = (uint64_t) int_fraction;
int_fraction -= ((double) curr_absolute);
cdtime_t last_update;
/* Interval in which the data is collected
* (for purding old entries) */
- int interval;
+ cdtime_t interval;
int state;
int hits;
ce->values_gauge[i] = NAN;
if (vl->interval > 0)
ce->values_gauge[i] = ((double) vl->values[i].absolute)
- / ((double) vl->interval);
+ / CDTIME_T_TO_DOUBLE (vl->interval);
ce->values_raw[i].absolute = vl->values[i].absolute;
break;
while (c_avl_iterator_next (iter, (void *) &key, (void *) &ce) == 0)
{
/* If entry has not been updated, add to `keys' array */
- /* FIXME: Remove macro once "ce->interval" is of type cdtime_t. */
- if ((now - ce->last_update) >= TIME_T_TO_CDTIME_T (timeout_g * ce->interval))
+ if ((now - ce->last_update) >= (ce->interval * timeout_g))
{
char **tmp;
if (strcasecmp ("interval", key) == 0)
{
- int tmp;
+ double tmp;
char *endptr;
endptr = NULL;
errno = 0;
- tmp = strtol (value, &endptr, 0);
+ tmp = strtod (value, &endptr);
if ((errno == 0) && (endptr != NULL)
- && (endptr != value) && (tmp > 0))
- vl->interval = tmp;
+ && (endptr != value) && (tmp > 0.0))
+ vl->interval = DOUBLE_TO_CDTIME_T (tmp);
}
else
return (1);
escape_string (buffer_values, sizeof (buffer_values));
ssnprintf (ret, ret_len,
- "PUTVAL %s interval=%i %s",
+ "PUTVAL %s interval=%.3f %s",
buffer_ident,
- (vl->interval > 0) ? vl->interval : interval_g,
+ (vl->interval > 0)
+ ? CDTIME_T_TO_DOUBLE (vl->interval)
+ : CDTIME_T_TO_DOUBLE (interval_g),
buffer_values);
return (0);
char *plugin;
char *db_name;
- int interval;
+ cdtime_t interval;
udb_result_preparation_area_t *result_prep_areas;
}; /* }}} */
sfree (prep_area->plugin);
sfree (prep_area->db_name);
- prep_area->interval = -1;
+ prep_area->interval = 0;
for (r = q->results, r_area = prep_area->result_prep_areas;
r != NULL; r = r->next, r_area = r_area->next)
int udb_query_prepare_result (const udb_query_t const *q, /* {{{ */
udb_query_preparation_area_t *prep_area,
const char *host, const char *plugin, const char *db_name,
- char **column_names, size_t column_num, int interval)
+ char **column_names, size_t column_num, cdtime_t interval)
{
udb_result_preparation_area_t *r_area;
udb_result_t *r;
int udb_query_prepare_result (const udb_query_t const *q,
udb_query_preparation_area_t *prep_area,
const char *host, const char *plugin, const char *db_name,
- char **column_names, size_t column_num, int interval);
+ char **column_names, size_t column_num, cdtime_t interval);
int udb_query_handle_result (const udb_query_t const *q,
udb_query_preparation_area_t *prep_area, char **column_values);
void udb_query_finish_result (const udb_query_t const *q,
BUFFER_ADD (",\"dsnames\":%s", temp);
BUFFER_ADD (",\"time\":%lu", (unsigned long) vl->time);
- BUFFER_ADD (",\"interval\":%i", vl->interval);
+ BUFFER_ADD (",\"interval\":%.3f", CDTIME_T_TO_DOUBLE (vl->interval));
#define BUFFER_ADD_KEYVAL(key, value) do { \
status = escape_string (temp, sizeof (temp), (value)); \
return (-1);
}
- ss = (cfg->stepsize > 0) ? cfg->stepsize : vl->interval;
+ if (cfg->stepsize > 0)
+ ss = cfg->stepsize;
+ else
+ ss = (int) CDTIME_T_TO_TIME_T (vl->interval);
if (ss <= 0)
{
*ret = NULL;
status = ssnprintf (buffer, sizeof (buffer),
"DS:%s:%s:%i:%s:%s",
d->name, type,
- (cfg->heartbeat > 0) ? cfg->heartbeat : (2 * vl->interval),
+ (cfg->heartbeat > 0)
+ ? cfg->heartbeat
+ : (int) CDTIME_T_TO_TIME_T (2 * vl->interval),
min, max);
if ((status < 1) || ((size_t) status >= sizeof (buffer)))
break;
int ds_num;
int status = 0;
time_t last_up;
+ int stepsize;
if (check_create_dir (filename))
return (-1);
else
last_up = CDTIME_T_TO_TIME_T (vl->time) - 10;
+ if (cfg->stepsize > 0)
+ stepsize = cfg->stepsize;
+ else
+ stepsize = (int) CDTIME_T_TO_TIME_T (vl->interval);
+
assert (vl->time > 10);
status = srrd_create (filename,
- (cfg->stepsize > 0) ? cfg->stepsize : vl->interval,
- last_up,
+ stepsize, last_up,
argc, (const char **) argv);
free (argv);
return (0);
}
- return (TIMESPEC_TO_CDTIME_T (ts));
+ return (TIMESPEC_TO_CDTIME_T (&ts));
} /* }}} cdtime_t cdtime */
/* vim: set sw=2 sts=2 et fdm=marker : */
#define CDTIME_T_TO_DOUBLE(t) (((double) (t)) / 1073741824.0)
#define DOUBLE_TO_CDTIME_T(d) ((cdtime_t) ((d) * 1073741824.0))
+#define MS_TO_CDTIME_T(ms) ((cdtime_t) (((double) (ms)) * 1073741.824))
#define CDTIME_T_TO_MS(t) ((long) (((double) (t)) / 1073741.824))
-
#define US_TO_CDTIME_T(us) ((cdtime_t) (((double) (us)) * 1073.741824))
#define CDTIME_T_TO_US(t) ((suseconds_t) (((double) (t)) / 1073.741824))
#define NS_TO_CDTIME_T(ns) ((cdtime_t) (((double) (ns)) * 1.073741824))
(tsp)->tv_sec = CDTIME_T_TO_TIME_T (cdt); \
(tsp)->tv_nsec = CDTIME_T_TO_NS ((cdt) % 1073741824); \
} while (0)
-#define TIMESPEC_TO_CDTIME_T(ts) (TIME_T_TO_CDTIME_T ((ts).tv_sec) \
- + NS_TO_CDTIME_T ((ts).tv_nsec))
+#define TIMESPEC_TO_CDTIME_T(ts) (TIME_T_TO_CDTIME_T ((ts)->tv_sec) \
+ + NS_TO_CDTIME_T ((ts)->tv_nsec))
cdtime_t cdtime (void);
}
command_len = (size_t) ssnprintf (command, sizeof (command),
- "PUTVAL %s interval=%i %s\r\n",
- key, vl->interval, values);
+ "PUTVAL %s interval=%.3f %s\r\n",
+ key,
+ CDTIME_T_TO_DOUBLE (vl->interval),
+ values);
if (command_len >= sizeof (command)) {
ERROR ("write_http plugin: Command buffer too small: "
"Need %zu bytes.", command_len + 1);