summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5893831)
raw | patch | inline | side by side (parent: 5893831)
author | Vincent Bernat <bernat@luffy.cx> | |
Sat, 12 Oct 2013 20:38:57 +0000 (22:38 +0200) | ||
committer | Vincent Bernat <bernat@luffy.cx> | |
Sat, 12 Oct 2013 20:38:57 +0000 (22:38 +0200) |
By using a distinct read callback for each database block, collectd
will be able to query several databases in parallel. This is useful if
the plugin should handle many queries. This lets the user split them in
chunks and speed up the retrieval.
will be able to query several databases in parallel. This is useful if
the plugin should handle many queries. This lets the user split them in
chunks and speed up the retrieval.
src/dbi.c | patch | blob | history |
diff --git a/src/dbi.c b/src/dbi.c
index 45e0d31d973c6c437e3aeb2c2e846ab47fb4ec6e..779c723f91741de5f5db273993a4929a1bcb2a78 100644 (file)
--- a/src/dbi.c
+++ b/src/dbi.c
static cdbi_database_t **databases = NULL;
static size_t databases_num = 0;
+static int cdbi_read_database (user_data_t *ud);
+
/*
* Functions
*/
}
else
{
+ user_data_t ud;
+ char *name = NULL;
+
databases = temp;
databases[databases_num] = db;
databases_num++;
+
+ memset (&ud, 0, sizeof (ud));
+ ud.data = (void *) db;
+ ud.free_func = NULL;
+ name = ssnprintf_alloc("dbi:%s", db->name);
+
+ plugin_register_complex_read (/* group = */ NULL,
+ /* name = */ name ? name : db->name,
+ /* callback = */ cdbi_read_database,
+ /* interval = */ NULL,
+ /* user_data = */ &ud);
+ free (name);
}
}
return (0);
} /* }}} int cdbi_connect_database */
-static int cdbi_read_database (cdbi_database_t *db) /* {{{ */
+static int cdbi_read_database (user_data_t *ud) /* {{{ */
{
+ cdbi_database_t *db = (cdbi_database_t *) ud->data;
size_t i;
int success;
int status;
return (0);
} /* }}} int cdbi_read_database */
-static int cdbi_read (void) /* {{{ */
-{
- size_t i;
- int success = 0;
- int status;
-
- for (i = 0; i < databases_num; i++)
- {
- status = cdbi_read_database (databases[i]);
- if (status == 0)
- success++;
- }
-
- if (success == 0)
- {
- ERROR ("dbi plugin: No database could be read. Will return an error so "
- "the plugin will be delayed.");
- return (-1);
- }
-
- return (0);
-} /* }}} int cdbi_read */
-
static int cdbi_shutdown (void) /* {{{ */
{
size_t i;
{
plugin_register_complex_config ("dbi", cdbi_config);
plugin_register_init ("dbi", cdbi_init);
- plugin_register_read ("dbi", cdbi_read);
plugin_register_shutdown ("dbi", cdbi_shutdown);
} /* }}} void module_register */