summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0175b4a)
raw | patch | inline | side by side (parent: 0175b4a)
author | Sebastian Harl <sh@tokkee.org> | |
Fri, 26 Mar 2010 19:11:32 +0000 (20:11 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Fri, 26 Mar 2010 19:11:32 +0000 (20:11 +0100) |
This option may be used to specify the read interval with which to query a
database.
database.
src/collectd.conf.pod | patch | blob | history | |
src/postgresql.c | patch | blob | history |
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 583e30cfd9af41328cfa3dbb86cc26cdbbccb543..943a089765b2c23d0c8a793fadd1d7e75a18d6fd 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
</Database>
<Database bar>
+ Interval 300
Service "service_name"
Query backend # predefined
Query rt36_tickets
=over 4
+=item B<Interval> I<seconds>
+
+Specify the interval with which the database should be queried. The default is
+to use the global B<Interval> setting.
+
=item B<Host> I<hostname>
Specify the hostname or IP of the PostgreSQL server to connect to. If the
diff --git a/src/postgresql.c b/src/postgresql.c
index 4f140b6062a8c9043a7462abee4dd775e9e14392..6698e0ee4dba81ea5995bff4635ef97d031735c4 100644 (file)
--- a/src/postgresql.c
+++ b/src/postgresql.c
udb_query_t **queries;
size_t queries_num;
+ int interval;
+
char *host;
char *port;
char *database;
db->queries = NULL;
db->queries_num = 0;
+ db->interval = 0;
+
db->database = sstrdup (name);
db->host = NULL;
db->port = NULL;
return 0;
} /* config_set_s */
+static int config_set_i (char *name, int *var,
+ const oconfig_item_t *ci, int min)
+{
+ int value;
+
+ if ((0 != ci->children_num) || (1 != ci->values_num)
+ || (OCONFIG_TYPE_NUMBER != ci->values[0].type)) {
+ log_err ("%s expects a single number argument.", name);
+ return 1;
+ }
+
+ value = (int)ci->values[0].value.number;
+
+ if (value < min) {
+ log_err ("%s expects a number greater or equal to %i.", name, min);
+ return 1;
+ }
+
+ *var = value;
+ return 0;
+} /* config_set_s */
+
static int config_query_param_add (udb_query_t *q, oconfig_item_t *ci)
{
c_psql_user_data_t *data;
c_psql_database_t *db;
char cb_name[DATA_MAX_NAME_LEN];
+ struct timespec cb_interval;
user_data_t ud;
int i;
else if (0 == strcasecmp (c->key, "Query"))
udb_query_pick_from_list (c, queries, queries_num,
&db->queries, &db->queries_num);
+ else if (0 == strcasecmp (c->key, "Interval"))
+ config_set_i ("Interval", &db->interval, c, /* min = */ 1);
else
log_warn ("Ignoring unknown config key \"%s\".", c->key);
}
ssnprintf (cb_name, sizeof (cb_name), "postgresql-%s", db->database);
+ memset (&cb_interval, 0, sizeof (cb_interval));
+ if (db->interval > 0)
+ cb_interval.tv_sec = (time_t)db->interval;
+
plugin_register_complex_read ("postgresql", cb_name, c_psql_read,
- /* interval = */ NULL, &ud);
+ /* interval = */ &cb_interval, &ud);
return 0;
} /* c_psql_config_database */