summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 09a1be1)
raw | patch | inline | side by side (parent: 09a1be1)
author | Florian Forster <octo@collectd.org> | |
Mon, 27 Feb 2012 21:41:48 +0000 (22:41 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Tue, 28 Feb 2012 05:49:47 +0000 (06:49 +0100) |
Change-Id: I73503de7605d456156664fd91c81cac1f3624939
src/collectd.conf.in | patch | blob | history | |
src/write_mongodb.c | patch | blob | history |
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index 983f5f1676d56bb9bee043a4c4dddfdb92d5cffa..d392a361cc2bd2240ab751775aa563355920a6be 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
# Host "localhost"
# Port "27017"
# Timeout 1000
+# StoreRates false
# </Node>
#</Plugin>
diff --git a/src/write_mongodb.c b/src/write_mongodb.c
index 4deb24d30979c748c546eaed464fb01113814fdc..3b17f8c84e41e5668d834f0cca0a04b552814b70 100644 (file)
--- a/src/write_mongodb.c
+++ b/src/write_mongodb.c
/**
* collectd - src/write_mongodb.c
- * Copyright (C) 2010 Florian Forster
- * Copyright (C) 2010 Akkarit Sangpetch
- * Copyright (C) 2012 Chris Lundquist
+ * Copyright (C) 2010-2012 Florian Forster
+ * Copyright (C) 2010 Akkarit Sangpetch
+ * Copyright (C) 2012 Chris Lundquist
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
#include "plugin.h"
#include "common.h"
#include "configfile.h"
+#include "utils_cache.h"
#include <pthread.h>
int connected;
+ _Bool store_rates;
+
mongo conn[1];
pthread_mutex_t lock;
};
int i;
bson record;
+ gauge_t *rates = NULL;
+ if (node->store_rates)
+ {
+ rates = uc_get_rate (ds, vl);
+ if (rates == NULL)
+ {
+ ERROR ("write_mongodb plugin: uc_get_rate() failed.");
+ return (-1);
+ }
+ }
+
ssnprintf(collection_name, sizeof (collection_name), "collectd.%s", vl->plugin);
bson_init(&record);
- bson_append_time_t(&record,"ts",CDTIME_T_TO_TIME_T(vl->time));
- bson_append_string(&record,"h",vl->host);
- bson_append_string(&record,"i",vl->plugin_instance);
- bson_append_string(&record,"t",vl->type);
- bson_append_string(&record,"ti",vl->type_instance);
+ bson_append_double (&record, "time", CDTIME_T_TO_DOUBLE (vl->time));
+ bson_append_string (&record, "host", vl->host);
+ bson_append_string (&record, "plugin_instance", vl->plugin_instance);
+ bson_append_string (&record, "type", vl->type);
+ bson_append_string (&record, "type_instance", vl->type_instance);
for (i = 0; i < ds->ds_num; i++)
{
- if (ds->ds[i].type == DS_TYPE_COUNTER)
- bson_append_long(&record, ds->ds[i].name, vl->values[i].counter);
- else if (ds->ds[i].type == DS_TYPE_GAUGE)
+ if (ds->ds[i].type == DS_TYPE_GAUGE)
bson_append_double(&record, ds->ds[i].name, vl->values[i].gauge);
+ else if (node->store_rates)
+ bson_append_double(&record, ds->ds[i].name, (double) rates[i]);
+ else if (ds->ds[i].type == DS_TYPE_COUNTER)
+ bson_append_long(&record, ds->ds[i].name, vl->values[i].counter);
else if (ds->ds[i].type == DS_TYPE_DERIVE)
bson_append_long(&record, ds->ds[i].name, vl->values[i].derive);
else if (ds->ds[i].type == DS_TYPE_ABSOLUTE)
/* We must finish the record, other wise the insert will fail */
bson_finish(&record);
+ sfree (rates);
+
pthread_mutex_lock (&node->lock);
if (node->connected == 0)
node->port = 0;
node->timeout = 1000;
node->connected = 0;
+ node->store_rates = 1;
pthread_mutex_init (&node->lock, /* attr = */ NULL);
status = cf_util_get_string_buffer (ci, node->name, sizeof (node->name));
}
else if (strcasecmp ("Timeout", child->key) == 0)
status = cf_util_get_int (child, &node->timeout);
+ else if (strcasecmp ("StoreRates", child->key) == 0)
+ status = cf_util_get_boolean (child, &node->store_rates);
else
WARNING ("write_mongodb plugin: Ignoring unknown config option \"%s\".",
child->key);