<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
=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<'>).
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
typedef struct {
char *name;
- char *query;
+ char *stmt;
c_psql_param_t *params;
int params_num;
}
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;
int i;
sfree (query->name);
- sfree (query->query);
+ sfree (query->stmt);
sfree (query->params);
query->params_num = 0;
}
}
- 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 */
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)
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;
}
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;
}
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"))
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;
# Pre-defined queries of collectd's postgresql plugin.
<Query backends>
- Query "SELECT count(*) \
+ Statement "SELECT count(*) \
FROM pg_stat_activity \
WHERE datname = $1;"
</Query>
<Query transactions>
- Query "SELECT xact_commit, xact_rollback \
+ Statement "SELECT xact_commit, xact_rollback \
FROM pg_stat_database \
WHERE datname = $1;"
</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
</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;"
</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;"
</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
</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) \
</Query>
<Query disk_usage>
- Query "SELECT pg_database_size($1);"
+ Statement "SELECT pg_database_size($1);"
Param database