summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 92b0dd6)
raw | patch | inline | side by side (parent: 92b0dd6)
author | Florian Forster <octo@collectd.org> | |
Sat, 23 Mar 2013 08:27:24 +0000 (09:27 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Sat, 23 Mar 2013 08:27:24 +0000 (09:27 +0100) |
src/collectd.conf.in | patch | blob | history | |
src/collectd.conf.pod | patch | blob | history | |
src/tail_csv.c | patch | blob | history |
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index 75e2291b54c466b899f43655f9dc23a3838feb18..4d491c819aff1824306ab22c3aedf036ec5db8e3 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
# Instance "snort-eth0"
# Interval 600
# Collect "dropped" "mbps" "alerts" "kpps"
+# TimeFrom 0
# </File>
#</Plugin>
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index c740808ac11aab5b3b8ddf26b1f1895c2859eb88..25717de257ff56644de13ac32026f978ed340921 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
=item B<ValueFrom> I<Index>
-Each line in the statistics file is broken into many fields with the first
-field, the timestamp of the line, is index with zero. This option configures to
-read the value from the field with index I<Index>.
+Configure to read the value from the field with the zero-based index I<Index>.
+If the value is parsed as signed integer, unsigned integer or double depends on
+the B<Type> setting, see above.
=back
Configures the interval in which to read values from this instance / file.
Defaults to the plugin's default interval.
+=item B<TimeFrom> I<Index>
+
+Rather than using the local time when dispatching a value, read the timestamp
+from the field with the zero-based index I<Index>. The value is interpreted as
+seconds since epoch. The value is parsed as a double and may be factional.
+
=back
=back
diff --git a/src/tail_csv.c b/src/tail_csv.c
index 3a8304a6bdf1f9deec0f2df185861ffa3ad86c16..a70b66589d287f4affef5003576e3583e1d55a8e 100644 (file)
--- a/src/tail_csv.c
+++ b/src/tail_csv.c
metric_definition_t **metric_list;
size_t metric_list_len;
cdtime_t interval;
+ int time_from;
struct instance_definition_s *next;
};
typedef struct instance_definition_s instance_definition_t;
if (md->data_source_type == -1)
return (EINVAL);
- if (md->value_from >= fields_num)
+ if ((md->value_from >= fields_num) || (id->time_from >= fields_num))
return (EINVAL);
- t = parse_time (fields[0]);
+ t = 0;
+ if (id->time_from >= 0)
+ t = parse_time (fields[id->time_from]);
status = parse_value (fields[md->value_from], &v, md->data_source_type);
if (status != 0)
return (tcsv_submit (id, md, v, t));
}
+static _Bool tcsv_check_index (int index, size_t fields_num, char const *name)
+{
+ if (index < 0)
+ return 1;
+ else if (((size_t) index) < fields_num)
+ return 1;
+
+ ERROR ("tail_csv plugin: Metric \"%s\": Request for index %i when "
+ "only %zu fields are available.",
+ name, index, fields_num);
+ return (0);
+}
+
static int tcsv_read_buffer (instance_definition_t *id,
char *buffer, size_t buffer_size)
{
for (i = 0; i < id->metric_list_len; ++i){
metric_definition_t *md = id->metric_list[i];
- if (((size_t) md->value_from) >= metrics_num) {
- ERROR ("tail_csv plugin: Metric \"%s\": Request for index %i when "
- "only %zu fields are available.",
- md->name, md->value_from, metrics_num);
+ if (!tcsv_check_index (md->value_from, metrics_num, md->name)
+ || !tcsv_check_index (id->time_from, metrics_num, md->name))
continue;
- }
tcsv_read_metric (id, md, metrics, metrics_num);
}
if (id == NULL)
return;
- cu_tail_destroy (id->tail);
+ if (id->tail != NULL)
+ cu_tail_destroy (id->tail);
id->tail = NULL;
sfree(id->instance);
id->instance = NULL;
id->path = NULL;
id->metric_list = NULL;
+ id->time_from = -1;
id->next = NULL;
status = cf_util_get_string (ci, &id->path);
status = tcsv_config_add_instance_collect(id, option);
else if (strcasecmp("Interval", option->key) == 0)
cf_util_get_cdtime(option, &id->interval);
+ else if (strcasecmp("TimeFrom", option->key) == 0)
+ status = tcsv_config_get_index (option, &id->time_from);
else {
WARNING("tail_csv plugin: Option `%s' not allowed here.", option->key);
status = -1;