postgresql plugin: Renamed the "Query" config option to "Statement".
authorSebastian Harl <sh@tokkee.org>
Thu, 29 Jan 2009 16:17:55 +0000 (17:17 +0100)
committerSebastian Harl <sh@tokkee.org>
Thu, 29 Jan 2009 16:41:56 +0000 (17:41 +0100)
This makes slightly more sense and is more consistent with the dbi and oracle
plugins.

src/collectd.conf.pod
src/postgresql.c
src/postgresql_default.conf

index 113bedd..f91a232 100644 (file)
@@ -1553,7 +1553,7 @@ L<http://www.postgresql.org/docs/manuals/>.
 
   <Plugin postgresql>
     <Query magic>
-      Query "SELECT magic, spells FROM wizard WHERE host = $1;"
+      Statement "SELECT magic, spells FROM wizard WHERE host = $1;"
       Param hostname
       Column gauge magic
       Column counter spells
@@ -1580,11 +1580,11 @@ following configuration options are available to define the query:
 
 =over 4
 
-=item B<Query> I<sql query>
+=item B<Statement> I<sql query statement>
 
-Specify the I<sql query> which the plugin should execute. The string may
-contain the tokens B<$1>, B<$2>, etc. which are used to reference the first,
-second, etc. parameter. The value of the parameters is specified by the
+Specify the I<sql query statement> which the plugin should execute. The string
+may contain the tokens B<$1>, B<$2>, etc. which are used to reference the
+first, second, etc. parameter. The value of the parameters is specified by the
 B<Param> configuration option - see below for details. To include a literal
 B<$> character followed by a number, surround it with single quotes (B<'>).
 
@@ -1592,6 +1592,11 @@ Any SQL command which may return data (such as C<SELECT> or C<SHOW>) is
 allowed. Note, however, that only a single command may be used. Semicolons are
 allowed as long as a single non-empty command has been specified only.
 
+=item B<Query> I<sql query statement>
+
+This is a deprecated synonym for B<Statement>. It will be removed in version 5
+of collectd.
+
 =item B<Param> I<hostname>|I<database>|I<username>
 
 Specify the parameters which should be passed to the SQL query. The parameters
index a5bacf4..6c8b814 100644 (file)
@@ -90,7 +90,7 @@ typedef struct {
 
 typedef struct {
        char *name;
-       char *query;
+       char *stmt;
 
        c_psql_param_t *params;
        int             params_num;
@@ -156,8 +156,8 @@ static c_psql_query_t *c_psql_query_new (const char *name)
        }
        query = queries + queries_num - 1;
 
-       query->name  = sstrdup (name);
-       query->query = NULL;
+       query->name = sstrdup (name);
+       query->stmt = NULL;
 
        query->params     = NULL;
        query->params_num = 0;
@@ -175,7 +175,7 @@ static void c_psql_query_delete (c_psql_query_t *query)
        int i;
 
        sfree (query->name);
-       sfree (query->query);
+       sfree (query->stmt);
 
        sfree (query->params);
        query->params_num = 0;
@@ -373,7 +373,7 @@ static PGresult *c_psql_exec_query_params (c_psql_database_t *db,
                }
        }
 
-       return PQexecParams (db->conn, query->query, query->params_num, NULL,
+       return PQexecParams (db->conn, query->stmt, query->params_num, NULL,
                        (const char *const *)((0 == query->params_num) ? NULL : params),
                        NULL, NULL, /* return text data */ 0);
 } /* c_psql_exec_query_params */
@@ -381,7 +381,7 @@ static PGresult *c_psql_exec_query_params (c_psql_database_t *db,
 static PGresult *c_psql_exec_query_noparams (c_psql_database_t *db,
                c_psql_query_t *query)
 {
-       return PQexec (db->conn, query->query);
+       return PQexec (db->conn, query->stmt);
 } /* c_psql_exec_query_noparams */
 
 static int c_psql_exec_query (c_psql_database_t *db, int idx)
@@ -411,7 +411,7 @@ static int c_psql_exec_query (c_psql_database_t *db, int idx)
        if (PGRES_TUPLES_OK != PQresultStatus (res)) {
                log_err ("Failed to execute SQL query: %s",
                                PQerrorMessage (db->conn));
-               log_info ("SQL query was: %s", query->query);
+               log_info ("SQL query was: %s", query->stmt);
                PQclear (res);
                return -1;
        }
@@ -426,7 +426,7 @@ static int c_psql_exec_query (c_psql_database_t *db, int idx)
        if (query->cols_num != cols) {
                log_err ("SQL query returned wrong number of fields "
                                "(expected: %i, got: %i)", query->cols_num, cols);
-               log_info ("SQL query was: %s", query->query);
+               log_info ("SQL query was: %s", query->stmt);
                PQclear (res);
                return -1;
        }
@@ -770,8 +770,13 @@ static int c_psql_config_query (oconfig_item_t *ci)
        for (i = 0; i < ci->children_num; ++i) {
                oconfig_item_t *c = ci->children + i;
 
-               if (0 == strcasecmp (c->key, "Query"))
-                       config_set_s ("Query", &query->query, c);
+               if (0 == strcasecmp (c->key, "Statement"))
+                       config_set_s ("Statement", &query->stmt, c);
+               /* backwards compat for versions < 4.6 */
+               else if (0 == strcasecmp (c->key, "Query")) {
+                       log_warn ("<Query>: 'Query' is deprecated - use 'Statement' instead.");
+                       config_set_s ("Query", &query->stmt, c);
+               }
                else if (0 == strcasecmp (c->key, "Param"))
                        config_set_param (query, c);
                else if (0 == strcasecmp (c->key, "Column"))
@@ -806,8 +811,8 @@ static int c_psql_config_query (oconfig_item_t *ci)
                return 1;
        }
 
-       if (NULL == query->query) {
-               log_err ("Query \"%s\" does not include an SQL query string - "
+       if (NULL == query->stmt) {
+               log_err ("Query \"%s\" does not include an SQL query statement - "
                                "please check your configuration.", query->name);
                c_psql_query_delete (query);
                --queries_num;
index 61844a0..ab0f178 100644 (file)
@@ -1,7 +1,7 @@
 # Pre-defined queries of collectd's postgresql plugin.
 
 <Query backends>
-       Query "SELECT count(*) \
+       Statement "SELECT count(*) \
                FROM pg_stat_activity \
                WHERE datname = $1;"
 
@@ -11,7 +11,7 @@
 </Query>
 
 <Query transactions>
-       Query "SELECT xact_commit, xact_rollback \
+       Statement "SELECT xact_commit, xact_rollback \
                FROM pg_stat_database \
                WHERE datname = $1;"
 
@@ -22,7 +22,7 @@
 </Query>
 
 <Query queries>
-       Query "SELECT sum(n_tup_ins), sum(n_tup_upd), sum(n_tup_del) \
+       Statement "SELECT sum(n_tup_ins), sum(n_tup_upd), sum(n_tup_del) \
                FROM pg_stat_user_tables;"
 
        Column pg_n_tup_c ins
@@ -33,7 +33,7 @@
 </Query>
 
 <Query queries>
-       Query "SELECT sum(n_tup_ins), sum(n_tup_upd), sum(n_tup_del), \
+       Statement "SELECT sum(n_tup_ins), sum(n_tup_upd), sum(n_tup_del), \
                        sum(n_tup_hot_upd) \
                FROM pg_stat_user_tables;"
 
@@ -46,7 +46,7 @@
 </Query>
 
 <Query query_plans>
-       Query "SELECT sum(seq_scan), sum(seq_tup_read), \
+       Statement "SELECT sum(seq_scan), sum(seq_tup_read), \
                        sum(idx_scan), sum(idx_tup_fetch) \
                FROM pg_stat_user_tables;"
 
@@ -57,7 +57,7 @@
 </Query>
 
 <Query table_states>
-       Query "SELECT sum(n_live_tup), sum(n_dead_tup) \
+       Statement "SELECT sum(n_live_tup), sum(n_dead_tup) \
                FROM pg_stat_user_tables;"
 
        Column pg_n_tup_g live
@@ -67,7 +67,7 @@
 </Query>
 
 <Query disk_io>
-       Query "SELECT sum(heap_blks_read), sum(heap_blks_hit), \
+       Statement "SELECT sum(heap_blks_read), sum(heap_blks_hit), \
                        sum(idx_blks_read), sum(idx_blks_hit), \
                        sum(toast_blks_read), sum(toast_blks_hit), \
                        sum(tidx_blks_read), sum(tidx_blks_hit) \
@@ -84,7 +84,7 @@
 </Query>
 
 <Query disk_usage>
-       Query "SELECT pg_database_size($1);"
+       Statement "SELECT pg_database_size($1);"
 
        Param database