From: Sebastian Harl Date: Fri, 26 Mar 2010 19:11:32 +0000 (+0100) Subject: postgresql plugin: Added the ``Interval'' config option. X-Git-Tag: collectd-4.10.0~39 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d1dedcaabaf204104a6e4f56cc13a5a4456d0a64;p=collectd.git postgresql plugin: Added the ``Interval'' config option. This option may be used to specify the read interval with which to query a database. --- diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 583e30cf..943a0897 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -2988,6 +2988,7 @@ L. + Interval 300 Service "service_name" Query backend # predefined Query rt36_tickets @@ -3189,6 +3190,11 @@ for details. =over 4 +=item B I + +Specify the interval with which the database should be queried. The default is +to use the global B setting. + =item B I 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 4f140b60..6698e0ee 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -105,6 +105,8 @@ typedef struct { udb_query_t **queries; size_t queries_num; + int interval; + char *host; char *port; char *database; @@ -154,6 +156,8 @@ static c_psql_database_t *c_psql_database_new (const char *name) db->queries = NULL; db->queries_num = 0; + db->interval = 0; + db->database = sstrdup (name); db->host = NULL; db->port = NULL; @@ -499,6 +503,28 @@ static int config_set_s (char *name, char **var, const oconfig_item_t *ci) 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; @@ -560,6 +586,7 @@ static int c_psql_config_database (oconfig_item_t *ci) c_psql_database_t *db; char cb_name[DATA_MAX_NAME_LEN]; + struct timespec cb_interval; user_data_t ud; int i; @@ -594,6 +621,8 @@ static int c_psql_config_database (oconfig_item_t *ci) 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); } @@ -619,8 +648,12 @@ static int c_psql_config_database (oconfig_item_t *ci) 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 */