summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: edd0e26)
raw | patch | inline | side by side (parent: edd0e26)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 3 Nov 2010 12:49:58 +0000 (13:49 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 3 Nov 2010 12:49:58 +0000 (13:49 +0100) |
33 files changed:
diff --git a/bindings/java/org/collectd/api/ValueList.java b/bindings/java/org/collectd/api/ValueList.java
index 1baeff24ed7fb8e58e6a80df22c576f3adb3b78c..b8d6f40f86f604b56eb042eb413a11f6226fa58b 100644 (file)
_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;
}
diff --git a/src/collectd.c b/src/collectd.c
index 277d3b0dc9432917db2f0483ec812742148852e3..4f5fac901a8445f6992b225d806a456889fae81b 100644 (file)
--- a/src/collectd.c
+++ b/src/collectd.c
* 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 */
diff --git a/src/collectd.h b/src/collectd.h
index 7012f4d13f9261348f476495f67e8ffe0343ca9a..af0033a55b9fb29a55a63dae13426cfc984c2899 100644 (file)
--- a/src/collectd.h
+++ b/src/collectd.h
/* 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 */
diff --git a/src/cpu.c b/src/cpu.c
index 7aa6361bad3b7959f3dcba1a98ecd079fc48fc04..3dbe80eeb1b7f4727b491803e93e841cac09200a 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
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)
diff --git a/src/csv.c b/src/csv.c
index 889ad62c60ebad9a8532b7295682b53a9fd852b4..87a7b4e3a9d0a8cf82927d49913b947b699efe60 100644 (file)
--- a/src/csv.c
+++ b/src/csv.c
}
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);
}
diff --git a/src/dbi.c b/src/dbi.c
index cd9240a62931861bf2a468a5c8a8d49e6ed20a55..caa41ef64023d247bd14721f936b0323df0ccfae 100644 (file)
--- a/src/dbi.c
+++ b/src/dbi.c
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); /* {{{ */
diff --git a/src/dns.c b/src/dns.c
index 6e63fe4474f030a1ad65fb17360c5135e7adb308..47da4e94c122e60dbd3084212e09e71cb3e5fbc1 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
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)
{
diff --git a/src/exec.c b/src/exec.c
index 9aabe9fc9956fb87e2ea48e6240803daef745215..8d5ae9c3894932c6b21abbc1dc8bb952b84da870 100644 (file)
--- a/src/exec.c
+++ b/src/exec.c
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);
diff --git a/src/gmond.c b/src/gmond.c
index 2ffc42a57d93aadf0b3d3bf080d6566c093592f4..8c774e536ff9c23e112c3e440d18aa15284478c4 100644 (file)
--- a/src/gmond.c
+++ b/src/gmond.c
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)
diff --git a/src/ipmi.c b/src/ipmi.c
index c631574d982fa462ecc13615d9e18c03a2eda604..f341320ddec54ed9135f6cec34759f30eb74ecd7 100644 (file)
--- a/src/ipmi.c
+++ b/src/ipmi.c
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;
diff --git a/src/java.c b/src/java.c
index 4d490eb6db2dab69396bfeb647dcff1c43037b8d..3089a5337fdc4b21b5c592d06185789da8e72107 100644 (file)
--- a/src/java.c
+++ b/src/java.c
}
/* 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)
diff --git a/src/memcached.c b/src/memcached.c
index 8490bf661b358d793a0701c779ad2758587b2df7..8b4a8fc1b9a2495fb966442ff96ffad386787f5a 100644 (file)
--- a/src/memcached.c
+++ b/src/memcached.c
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
{
diff --git a/src/modbus.c b/src/modbus.c
index adab0d0fe8e0756641a509b0c39b6373c44735b4..3824097c5a43b57e34c170eb4782ff756d8524a7 100644 (file)
--- a/src/modbus.c
+++ b/src/modbus.c
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
{
diff --git a/src/network.c b/src/network.c
index 6d53504c2ae6b2d4b4404c645e4b30424d149042..43193cfca250093849a918b547904fc7f999981e 100644 (file)
--- a/src/network.c
+++ b/src/network.c
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;
}
diff --git a/src/onewire.c b/src/onewire.c
index d308122accc1f4953e4f2cb7e17daa943bd0157f..09a6bf0926154369c3fe75e408a3c79c9b194cfe 100644 (file)
--- a/src/onewire.c
+++ b/src/onewire.c
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);
diff --git a/src/oracle.c b/src/oracle.c
index 2f218519e34bfcc30faf29847eba91c00961e2e2..03567494f227cd281e41d528fbbee7fc67823620 100644 (file)
--- a/src/oracle.c
+++ b/src/oracle.c
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): "
diff --git a/src/perl.c b/src/perl.c
index 116c34f363d535b2d644ee73add242804be3465d..f8a482275d89bde294344222b060294cdaa8b3e6 100644 (file)
--- a/src/perl.c
+++ b/src/perl.c
{ "", 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) */
diff --git a/src/plugin.c b/src/plugin.c
index 83582763a5f72ece4c2cac586bcf01f2a0a7bede..2e25758e60609e77aa7a3074abc469f8c9bed6e9 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
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);
diff --git a/src/plugin.h b/src/plugin.h
index ada89322bbd0f4fc8db3edab7294d1db6da0a7aa..490aed031f2efd3c910b5e0f03ec7f1174ec6e4f 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
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];
diff --git a/src/postgresql.c b/src/postgresql.c
index 175cc095732d46c224684c469e2c64c21b929cd6..a8812e2158327bf86153689894e8eada7e620022 100644 (file)
--- a/src/postgresql.c
+++ b/src/postgresql.c
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 */
diff --git a/src/powerdns.c b/src/powerdns.c
index 508ea506f86cd08a1f2ff52ccae3333ad62ab8dd..a1b23555bec080592a261f91e1d6e02ae769bd6a 100644 (file)
--- a/src/powerdns.c
+++ b/src/powerdns.c
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);
diff --git a/src/rrdtool.c b/src/rrdtool.c
index bd7bd77bd697b8025aaa0bb67d624bca84f98134..c948d1f803b282d0707b8daafa7d8571d61eee59 100644 (file)
--- a/src/rrdtool.c
+++ b/src/rrdtool.c
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.");
diff --git a/src/snmp.c b/src/snmp.c
index e78ade9735538114ad9004d1e4e2ed493f101603..54bcf67242170ea93c6cdc070a5a81a8196ed067 100644 (file)
--- a/src/snmp.c
+++ b/src/snmp.c
@@ -1057,7 +1057,7 @@ static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *dat
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;
@@ -1445,7 +1445,7 @@ static int csnmp_read_value (host_definition_t *host, data_definition_t *data)
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 ();
diff --git a/src/target_scale.c b/src/target_scale.c
index 29fecdfd7b5818479437659982226c993934a63d..af224f109d6bb8de19066b8c472a6557d6058d3e 100644 (file)
--- a/src/target_scale.c
+++ b/src/target_scale.c
{
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
@@ -263,7 +263,7 @@ static int ts_invoke_absolute (const data_set_t *ds, value_list_t *vl, /* {{{ */
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))
@@ -272,7 +272,7 @@ static int ts_invoke_absolute (const data_set_t *ds, value_list_t *vl, /* {{{ */
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);
diff --git a/src/utils_cache.c b/src/utils_cache.c
index 05db70c888c220a897d52d417146e546a38b1cd0..10e8a48e20d2e1787f8c2c6cbc4b19b230154b5e 100644 (file)
--- a/src/utils_cache.c
+++ b/src/utils_cache.c
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;
diff --git a/src/utils_cmd_putval.c b/src/utils_cmd_putval.c
index 15cd939b00610b68215d8b54143e435d50530c8a..dd43337ee01390eb3c703a5d8c473bc93eb7ea90 100644 (file)
--- a/src/utils_cmd_putval.c
+++ b/src/utils_cmd_putval.c
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);
diff --git a/src/utils_db_query.c b/src/utils_db_query.c
index 78c8052e275336ea572f4a863e02fdfdd5768b47..dcac80764c665ca1dd98a456feea0cb2386692c4 100644 (file)
--- a/src/utils_db_query.c
+++ b/src/utils_db_query.c
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;
diff --git a/src/utils_db_query.h b/src/utils_db_query.h
index 846f81c291f8db86df780ee66d721a5c07aa8aea..727be03647714e8bc76f6b4d5403508eeca74616 100644 (file)
--- a/src/utils_db_query.h
+++ b/src/utils_db_query.h
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,
index ac88c0fa27c4f7ae4b50cd734d78f886a79482b3..65c886b6fc28239183be31d8a10a896ec5f7800c 100644 (file)
--- a/src/utils_format_json.c
+++ b/src/utils_format_json.c
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)); \
diff --git a/src/utils_rrdcreate.c b/src/utils_rrdcreate.c
index 5f21a17b8391c40e41de4e531d144d794a1bd359..7a389f26922d0f11e5c0ac8af4d07ae41f09d277 100644 (file)
--- a/src/utils_rrdcreate.c
+++ b/src/utils_rrdcreate.c
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);
diff --git a/src/utils_time.c b/src/utils_time.c
index 31e31090e58acd05b9f779f179f7175fc22ecfd8..420b425c0bd1a2739fa398f292062867f57f3144 100644 (file)
--- a/src/utils_time.c
+++ b/src/utils_time.c
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 : */
diff --git a/src/utils_time.h b/src/utils_time.h
index 0c477d8c7c413af0d618f60047c0799fff14b6d6..da73492cc922b785b0677df828180a1b9d5ac0c6 100644 (file)
--- a/src/utils_time.h
+++ b/src/utils_time.h
#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);
diff --git a/src/write_http.c b/src/write_http.c
index 9cf9fe11fb9df4c033df7728ca2d44b92f143bb5..1a0e4ef06d2fa13dc91cdb7faf315e6874e1d609 100644 (file)
--- a/src/write_http.c
+++ b/src/write_http.c
@@ -306,8 +306,10 @@ static int wh_write_command (const data_set_t *ds, const value_list_t *vl, /* {{
}
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);