summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4ce283a)
raw | patch | inline | side by side (parent: 4ce283a)
author | Akkarit Sangpetch <asangpet@andrew.cmu.edu> | |
Sat, 2 Oct 2010 15:49:43 +0000 (11:49 -0400) | ||
committer | Chris Lundquist <chris.lundquist@bluebox.net> | |
Tue, 24 Jan 2012 19:53:22 +0000 (11:53 -0800) |
src/write_mongo.c | patch | blob | history |
diff --git a/src/write_mongo.c b/src/write_mongo.c
index c17c35f10583eeb39ad78eda292d3ae80197293e..1f7e3d096525007ff3656c16af4b56310469ea9b 100644 (file)
--- a/src/write_mongo.c
+++ b/src/write_mongo.c
char collection_name[512];
int status;
int i;
- bson record[1];
- bson_buffer record_buf[1];
+ bson record;
+ bson_buffer record_buf;
ssnprintf(collection_name, sizeof (collection_name), "collectd.%s", vl->plugin);
- bson_buffer_init(record_buf);
- bson_append_time_t(record_buf,"ts",vl->time);
- bson_append_string(record_buf,"h",vl->host);
- bson_append_string(record_buf,"i",vl->plugin_instance);
- bson_append_string(record_buf,"t",vl->plugin_instance);
- bson_append_string(record_buf,"ti",vl->plugin_instance);
-
- if (ds->ds_num == 1) {
- if (ds->ds[0].type == DS_TYPE_COUNTER)
- bson_append_long(record_buf, "v", vl->values[0].counter);
- else if (ds->ds[0].type == DS_TYPE_GAUGE)
- bson_append_double(record_buf, "v", vl->values[0].gauge);
- else if (ds->ds[0].type == DS_TYPE_DERIVE)
- bson_append_long(record_buf, "v", vl->values[0].derive);
- else if (ds->ds[0].type == DS_TYPE_ABSOLUTE)
- bson_append_long(record_buf, "v", vl->values[0].absolute);
+ bson_buffer_init(&record_buf);
+ bson_append_time_t(&record_buf,"ts",vl->time);
+ bson_append_string(&record_buf,"h",vl->host);
+ bson_append_string(&record_buf,"i",vl->plugin_instance);
+ bson_append_string(&record_buf,"t",vl->type);
+ bson_append_string(&record_buf,"ti",vl->type_instance);
+
+ for (i = 0; i < ds->ds_num; i++)
+ {
+ if (ds->ds[i].type == DS_TYPE_COUNTER)
+ bson_append_long(&record_buf, ds->ds[i].name, vl->values[i].counter);
+ else if (ds->ds[i].type == DS_TYPE_GAUGE)
+ bson_append_double(&record_buf, ds->ds[i].name, vl->values[i].gauge);
+ else if (ds->ds[i].type == DS_TYPE_DERIVE)
+ bson_append_long(&record_buf, ds->ds[i].name, vl->values[i].derive);
+ else if (ds->ds[i].type == DS_TYPE_ABSOLUTE)
+ bson_append_long(&record_buf, ds->ds[i].name, vl->values[i].absolute);
else
assert (23 == 42);
- } else {
- bson_append_start_object(record_buf,"v");
- for (i = 0; i < ds->ds_num; i++)
- {
- if (ds->ds[i].type == DS_TYPE_COUNTER)
- bson_append_long(record_buf, ds->ds[i].name, vl->values[i].counter);
- else if (ds->ds[i].type == DS_TYPE_GAUGE)
- bson_append_double(record_buf, ds->ds[i].name, vl->values[i].gauge);
- else if (ds->ds[i].type == DS_TYPE_DERIVE)
- bson_append_long(record_buf, ds->ds[i].name, vl->values[i].derive);
- else if (ds->ds[i].type == DS_TYPE_ABSOLUTE)
- bson_append_long(record_buf, ds->ds[i].name, vl->values[i].absolute);
- else
- assert (23 == 42);
- }
- bson_append_finish_object(record_buf);
}
- bson_from_buffer(record,record_buf);
+
+ bson_from_buffer(&record,&record_buf);
pthread_mutex_lock (&node->lock);
if (status!=mongo_conn_success) {
ERROR ("write_mongo plugin: Connecting to host \"%s\" (port %i) failed.",
(node->host != NULL) ? node->host : "localhost",
- (node->port != 0) ? node->port : 6379);
+ (node->port != 0) ? node->port : 27017);
+ mongo_destroy(node->conn);
pthread_mutex_unlock (&node->lock);
return (-1);
} else {
/* Assert if the connection has been established */
assert (node->connected == 1);
- mongo_insert(node->conn,collection_name,record);
+ mongo_insert(node->conn,collection_name,&record);
pthread_mutex_unlock (&node->lock);
+ bson_buffer_destroy(&record_buf);
+
return (0);
} /* }}} int wm_write */