ret_value->counter = (counter_t)strtoll (value, &endptr, 0);
else if (DS_TYPE_GAUGE == ds.type)
ret_value->gauge = (gauge_t)strtod (value, &endptr);
+ else if (DS_TYPE_DERIVE == ds.type)
+ ret_value->counter = (derive_t)strtoll (value, &endptr, 0);
+ else if (DS_TYPE_ABSOLUTE == ds.type)
+ ret_value->counter = (absolute_t)strtoll (value, &endptr, 0);
else {
ERROR ("parse_value: Invalid data source \"%s\" "
"(type = %i).", ds.name, ds.type);
for (i = 0; i < ds->ds_num; i++)
{
if ((ds->ds[i].type != DS_TYPE_COUNTER)
- && (ds->ds[i].type != DS_TYPE_GAUGE))
+ && (ds->ds[i].type != DS_TYPE_GAUGE)
+ && (ds->ds[i].type != DS_TYPE_DERIVE)
+ && (ds->ds[i].type != DS_TYPE_ABSOLUTE))
return (-1);
if (ds->ds[i].type == DS_TYPE_COUNTER)
",%lf", rates[i]);
}
}
- else /* if (ds->ds[i].type == DS_TYPE_GAUGE) */
+ else if (ds->ds[i].type == DS_TYPE_GAUGE)
{
status = ssnprintf (buffer + offset, buffer_len - offset,
",%lf", vl->values[i].gauge);
+ }
+ else if (ds->ds[i].type == DS_TYPE_DERIVE)
+ {
+ if (store_rates == 0)
+ {
+ status = ssnprintf (buffer + offset,
+ buffer_len - offset,
+ ",%llu",
+ vl->values[i].derive);
+ }
+ else /* if (store_rates == 1) */
+ {
+ if (rates == NULL)
+ rates = uc_get_rate (ds, vl);
+ if (rates == NULL)
+ {
+ WARNING ("csv plugin: "
+ "uc_get_rate failed.");
+ return (-1);
+ }
+ status = ssnprintf (buffer + offset,
+ buffer_len - offset,
+ ",%lf", rates[i]);
+ }
+ }
+ else if (ds->ds[i].type == DS_TYPE_ABSOLUTE)
+ {
+ if (store_rates == 0)
+ {
+ status = ssnprintf (buffer + offset,
+ buffer_len - offset,
+ ",%llu",
+ vl->values[i].absolute);
+ }
+ else /* if (store_rates == 1) */
+ {
+ if (rates == NULL)
+ rates = uc_get_rate (ds, vl);
+ if (rates == NULL)
+ {
+ WARNING ("csv plugin: "
+ "uc_get_rate failed.");
+ return (-1);
+ }
+ status = ssnprintf (buffer + offset,
+ buffer_len - offset,
+ ",%lf", rates[i]);
+ }
}
if ((status < 1) || (status >= (buffer_len - offset)))
else
dstype = 0;
}
+else if (strncasecmp ("Derive", ci->values[0].value.string,
+ strlen ("Derive")) == 0)
+ {
+ dstype = UTILS_MATCH_DS_TYPE_DERIVE;
+ if (strcasecmp ("DeriveSet", ci->values[0].value.string) == 0)
+ dstype |= UTILS_MATCH_CF_DERIVE_SET;
+ else if (strcasecmp ("DeriveAdd", ci->values[0].value.string) == 0)
+ dstype |= UTILS_MATCH_CF_DERIVE_ADD;
+ else if (strcasecmp ("DeriveInc", ci->values[0].value.string) == 0)
+ dstype |= UTILS_MATCH_CF_DERIVE_INC;
+ else
+ dstype = 0;
+ }
+else if (strncasecmp ("Absolute", ci->values[0].value.string,
+ strlen ("Absolute")) == 0)
+ {
+ dstype = UTILS_MATCH_DS_TYPE_ABSOLUTE;
+ if (strcasecmp ("AbsoluteSet", ci->values[0].value.string) == 0) /* Absolute DS is reset-on-read so no sense doin anything else but set */
+ dstype |= UTILS_MATCH_CF_ABSOLUTE_SET;
+ else
+ dstype = 0;
+ }
+
else
{
dstype = 0;
return (ctoj_jlong_to_number (jvm_env, (jlong) value.counter));
else if (ds_type == DS_TYPE_GAUGE)
return (ctoj_jdouble_to_number (jvm_env, (jdouble) value.gauge));
+ if (ds_type == DS_TYPE_DERIVE)
+ return (ctoj_jlong_to_number (jvm_env, (jlong) value.derive));
+ if (ds_type == DS_TYPE_ABSOLUTE)
+ return (ctoj_jlong_to_number (jvm_env, (jlong) value.absolute));
else
return (NULL);
} /* }}} jobject ctoj_value_to_number */
else
SSTRCATF (command, ":%g", vl->values[i].gauge);
}
+ else if (vl->values_types[i] == LCC_TYPE_DERIVE)
+ SSTRCATF (command, ":%"PRIu64, vl->values[i].derive);
+ else if (vl->values_types[i] == LCC_TYPE_ABSOLUTE)
+ SSTRCATF (command, ":%"PRIu64, vl->values[i].absolute);
+
} /* for (i = 0; i < vl->values_len; i++) */
status = lcc_sendreceive (c, command, &res);
*/
#define LCC_TYPE_COUNTER 0
#define LCC_TYPE_GAUGE 1
+#define LCC_TYPE_DERIVE 2
+#define LCC_TYPE_ABSOLUTE 3
LCC_BEGIN_DECLS
typedef uint64_t counter_t;
typedef double gauge_t;
+typedef uint64_t derive_t;
+typedef uint64_t absolute_t;
union value_u
{
counter_t counter;
gauge_t gauge;
+ derive_t derive;
+ absolute_t absolute;
};
typedef union value_u value_t;
{ "Collectd::TYPE_DATASET", PLUGIN_DATASET },
{ "Collectd::DS_TYPE_COUNTER", DS_TYPE_COUNTER },
{ "Collectd::DS_TYPE_GAUGE", DS_TYPE_GAUGE },
+ { "Collectd::DS_TYPE_DERIVE", DS_TYPE_DERIVE },
+ { "Collectd::DS_TYPE_ABSOLUTE", DS_TYPE_ABSOLUTE },
{ "Collectd::LOG_ERR", LOG_ERR },
{ "Collectd::LOG_WARNING", LOG_WARNING },
{ "Collectd::LOG_NOTICE", LOG_NOTICE },
if (NULL != (tmp = hv_fetch (hash, "type", 4, 0))) {
ds->type = SvIV (*tmp);
- if ((DS_TYPE_COUNTER != ds->type) && (DS_TYPE_GAUGE != ds->type)) {
+ if ((DS_TYPE_COUNTER != ds->type) && (DS_TYPE_GAUGE != ds->type) && (DS_TYPE_DERIVE != ds->type) && (DS_TYPE_ABSOLUTE != ds->type)) {
log_err ("hv2data_source: Invalid DS type.");
return -1;
}
if (NULL != tmp) {
if (DS_TYPE_COUNTER == ds->ds[i].type)
value[i].counter = SvIV (*tmp);
- else
+ else if (DS_TYPE_GAUGE == ds->ds[i].type)
value[i].gauge = SvNV (*tmp);
+ else if (DS_TYPE_DERIVE == ds->ds[i].type)
+ value[i].derive = SvIV (*tmp);
+ else if (DS_TYPE_ABSOLUTE == ds->ds[i].type)
+ value[i].absolute = SvIV (*tmp);
}
else {
return -1;
if (DS_TYPE_COUNTER == ds->ds[i].type)
val = newSViv (vl->values[i].counter);
- else
+ else if (DS_TYPE_GAUGE == ds->ds[i].type)
val = newSVnv (vl->values[i].gauge);
+ else if (DS_TYPE_DERIVE == ds->ds[i].type)
+ val = newSVnv (vl->values[i].derive);
+ else if (DS_TYPE_ABSOLUTE == ds->ds[i].type)
+ val = newSVnv (vl->values[i].absolute);
if (NULL == av_store (values, i, val)) {
av_undef (values);
#define DS_TYPE_COUNTER 0
#define DS_TYPE_GAUGE 1
+#define DS_TYPE_DERIVE 2
+#define DS_TYPE_ABSOLUTE 3
#ifndef LOG_ERR
# define LOG_ERR 3
*/
typedef unsigned long long counter_t;
typedef double gauge_t;
+typedef unsigned long long derive_t;
+typedef unsigned long long absolute_t;
union value_u
{
counter_t counter;
gauge_t gauge;
+ derive_t derive;
+ absolute_t absolute;
};
typedef union value_u value_t;
for (i = 0; i < ds->ds_num; i++)
{
if ((ds->ds[i].type != DS_TYPE_COUNTER)
- && (ds->ds[i].type != DS_TYPE_GAUGE))
+ && (ds->ds[i].type != DS_TYPE_GAUGE)
+ && (ds->ds[i].type != DS_TYPE_DERIVE)
+ && (ds->ds[i].type != DS_TYPE_ABSOLUTE)
return (-1);
if (ds->ds[i].type == DS_TYPE_COUNTER)
status = ssnprintf (buffer + offset, buffer_len - offset,
":%llu", vl->values[i].counter);
}
- else /* if (ds->ds[i].type == DS_TYPE_GAUGE) */
+ else if (ds->ds[i].type == DS_TYPE_GAUGE)
{
status = ssnprintf (buffer + offset, buffer_len - offset,
":%lf", vl->values[i].gauge);
}
+ else if (ds->ds[i].type == DS_TYPE_DERIVE) {
+ status = ssnprintf (buffer + offset, buffer_len - offset,
+ ":%llu", vl->values[i].derive);
+ }
+ else /* if (ds->ds[i].type == DS_TYPE_ABSOLUTE) */ {
+ status = ssnprintf (buffer + offset, buffer_len - offset,
+ ":%llu", vl->values[i].absolute);
+
+ }
if ((status < 1) || (status >= (buffer_len - offset)))
return (-1);
for (i = 0; i < ds->ds_num; i++)
{
if ((ds->ds[i].type != DS_TYPE_COUNTER)
- && (ds->ds[i].type != DS_TYPE_GAUGE))
+ && (ds->ds[i].type != DS_TYPE_GAUGE)
+ && (ds->ds[i].type != DS_TYPE_DERIVE)
+ && (ds->ds[i].type != DS_TYPE_ABSOLUTE))
return (-1);
if (ds->ds[i].type == DS_TYPE_COUNTER)
status = ssnprintf (buffer + offset, buffer_len - offset,
":%llu", vl->values[i].counter);
- else
+ else if (ds->ds[i].type == DS_TYPE_GAUGE)
status = ssnprintf (buffer + offset, buffer_len - offset,
":%lf", vl->values[i].gauge);
+ else if (ds->ds[i].type == DS_TYPE_DERIVE)
+ status = ssnprintf (buffer + offset, buffer_len - offset,
+ ":%llu", vl->values[i].derive);
+ else /*if (ds->ds[i].type == DS_TYPE_ABSOLUTE) */
+ status = ssnprintf (buffer + offset, buffer_len - offset,
+ ":%llu", vl->values[i].absolute);
if ((status < 1) || (status >= (buffer_len - offset)))
return (-1);
else
cm->flags = 0;
}
+ else if (strncasecmp ("Derive", ci->values[0].value.string, strlen ("Derive")) == 0)
+ {
+ cm->flags = UTILS_MATCH_DS_TYPE_DERIVE;
+ if (strcasecmp ("DeriveSet", ci->values[0].value.string) == 0)
+ cm->flags |= UTILS_MATCH_CF_DERIVE_SET;
+ else if (strcasecmp ("DeriveAdd", ci->values[0].value.string) == 0)
+ cm->flags |= UTILS_MATCH_CF_DERIVE_ADD;
+ else if (strcasecmp ("DeriveInc", ci->values[0].value.string) == 0)
+ cm->flags |= UTILS_MATCH_CF_DERIVE_INC;
+ else
+ cm->flags = 0;
+ }
+ else if (strncasecmp ("Absolute", ci->values[0].value.string, strlen ("Absolute")) == 0)
+ {
+ cm->flags = UTILS_MATCH_DS_TYPE_ABSOLUTE;
+ if (strcasecmp ("AbsoluteSet", ci->values[0].value.string) == 0)
+ cm->flags |= UTILS_MATCH_CF_ABSOLUTE_SET;
+ else
+ cm->flags = 0;
+ }
else
{
cm->flags = 0;
+absolute count:ABSOLUTE:0:U
apache_bytes count:COUNTER:0:134217728
apache_connections count:GAUGE:0:65535
apache_requests count:COUNTER:0:134217728
cpu value:COUNTER:0:4294967295
current value:GAUGE:U:U
delay seconds:GAUGE:-1000000:1000000
+derive value:DERIVE:0:U
df used:GAUGE:0:1125899906842623, free:GAUGE:0:1125899906842623
disk_merged read:COUNTER:0:4294967295, write:COUNTER:0:4294967295
disk_octets read:COUNTER:0:17179869183, write:COUNTER:0:17179869183
dsrc->type = DS_TYPE_GAUGE;
else if (strcasecmp (fields[1], "COUNTER") == 0)
dsrc->type = DS_TYPE_COUNTER;
+ else if (strcasecmp (fields[1], "DERIVE") == 0)
+ dsrc->type = DS_TYPE_DERIVE;
+ else if (strcasecmp (fields[1], "ABSOLUTE") == 0)
+ dsrc->type = DS_TYPE_ABSOLUTE;
else
{
- ERROR ("(fields[1] = %s) != (GAUGE || COUNTER)", fields[1]);
+ ERROR ("(fields[1] = %s) != (GAUGE || COUNTER || DERIVE || ABSOLUTE)", fields[1]);
return (-1);
}
data->values_num++;
}
+ else if (data->ds_type & UTILS_MATCH_DS_TYPE_DERIVE)
+ {
+ derive_t value;
+ char *endptr = NULL;
+
+ if (data->ds_type & UTILS_MATCH_CF_DERIVE_INC)
+ {
+ data->value.counter++;
+ data->values_num++;
+ return (0);
+ }
+
+ if (matches_num < 2)
+ return (-1);
+
+ value = strtoll (matches[1], &endptr, 0);
+ if (matches[1] == endptr)
+ return (-1);
+
+ if (data->ds_type & UTILS_MATCH_CF_DERIVE_SET)
+ data->value.derive = value;
+ else if (data->ds_type & UTILS_MATCH_CF_DERIVE_ADD)
+ data->value.derive += value;
+ else
+ {
+ ERROR ("utils_match: default_callback: obj->ds_type is invalid!");
+ return (-1);
+ }
+
+ data->values_num++;
+ }
+ else if (data->ds_type & UTILS_MATCH_DS_TYPE_ABSOLUTE)
+ {
+ absolute_t value;
+ char *endptr = NULL;
+
+ if (matches_num < 2)
+ return (-1);
+
+ value = strtoll (matches[1], &endptr, 0);
+ if (matches[1] == endptr)
+ return (-1);
+
+ if (data->ds_type & UTILS_MATCH_CF_ABSOLUTE_SET)
+ data->value.absolute = value;
+ else
+ {
+ ERROR ("utils_match: default_callback: obj->ds_type is invalid!");
+ return (-1);
+ }
+
+ data->values_num++;
+ }
else
{
ERROR ("utils_match: default_callback: obj->ds_type is invalid!");
*/
#define UTILS_MATCH_DS_TYPE_GAUGE 0x10
#define UTILS_MATCH_DS_TYPE_COUNTER 0x20
+#define UTILS_MATCH_DS_TYPE_DERIVE 0x30
+#define UTILS_MATCH_DS_TYPE_ABSOLUTE 0x40
#define UTILS_MATCH_CF_GAUGE_AVERAGE 0x01
#define UTILS_MATCH_CF_GAUGE_MIN 0x02
#define UTILS_MATCH_CF_COUNTER_ADD 0x02
#define UTILS_MATCH_CF_COUNTER_INC 0x04
+#define UTILS_MATCH_CF_DERIVE_SET 0x01
+#define UTILS_MATCH_CF_DERIVE_ADD 0x02
+#define UTILS_MATCH_CF_DERIVE_INC 0x04
+
+#define UTILS_MATCH_CF_ABSOLUTE_SET 0x01
+#define UTILS_MATCH_CF_ABSOLUTE_ADD 0x02
+#define UTILS_MATCH_CF_ABSOLUTE_INC 0x04
+
/*
* Data types
*/
type = "COUNTER";
else if (d->type == DS_TYPE_GAUGE)
type = "GAUGE";
+ else if (d->type == DS_TYPE_DERIVE)
+ type = "DERIVE";
+ else if (d->type == DS_TYPE_ABSOLUTE)
+ type = "ABSOLUTE";
else
{
ERROR ("rrdtool plugin: Unknown DS type: %i",