From: Sebastian Harl Date: Sun, 1 Feb 2009 22:09:08 +0000 (+0100) Subject: postgresql plugin: Added support for the "interval" parameter. X-Git-Tag: collectd-4.6.0~81 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=75555c1cdc99e4b1efa4a9d664f189906e2c3427;p=collectd.git postgresql plugin: Added support for the "interval" parameter. This query parameter expands to the interval collectd is using. --- diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 00c7ed35..67fe3b63 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -1663,7 +1663,7 @@ The returned lines will be handled separately one after another. This is a deprecated synonym for B. It will be removed in version 5 of collectd. -=item B I|I|I +=item B I|I|I|I Specify the parameters which should be passed to the SQL query. The parameters are referred to in the SQL query as B<$1>, B<$2>, etc. in the same order as @@ -1685,6 +1685,10 @@ The name of the database of the current connection. The username used to connect to the database. +=item I + +The interval collectd is using (as specified by the B option). + =back Please note that parameters are only supported by PostgreSQL's protocol diff --git a/src/postgresql.c b/src/postgresql.c index bb2f0d28..2814cc4a 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -80,6 +80,7 @@ typedef enum { C_PSQL_PARAM_HOST = 1, C_PSQL_PARAM_DB, C_PSQL_PARAM_USER, + C_PSQL_PARAM_INTERVAL, } c_psql_param_t; typedef struct { @@ -550,6 +551,7 @@ static PGresult *c_psql_exec_query_params (c_psql_database_t *db, c_psql_query_t *query) { char *params[db->max_params_num]; + char interval[64]; int i; assert (db->max_params_num >= query->params_num); @@ -566,6 +568,10 @@ static PGresult *c_psql_exec_query_params (c_psql_database_t *db, case C_PSQL_PARAM_USER: params[i] = db->user; break; + case C_PSQL_PARAM_INTERVAL: + ssnprintf (interval, sizeof (interval), "%i", interval_g); + params[i] = interval; + break; default: assert (0); } @@ -828,6 +834,8 @@ static int config_set_param (c_psql_query_t *query, const oconfig_item_t *ci) param = C_PSQL_PARAM_DB; else if (0 == strcasecmp (param_str, "username")) param = C_PSQL_PARAM_USER; + else if (0 == strcasecmp (param_str, "interval")) + param = C_PSQL_PARAM_INTERVAL; else { log_err ("Invalid parameter \"%s\".", param_str); return 1;