summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5603e2c)
raw | patch | inline | side by side (parent: 5603e2c)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 29 Jan 2009 16:17:55 +0000 (17:17 +0100) | ||
committer | Sebastian 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.
plugins.
src/collectd.conf.pod | patch | blob | history | |
src/postgresql.c | patch | blob | history | |
src/postgresql_default.conf | patch | blob | history |
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 113bedde8f6b7296a32ff6d81837bea4bb17679e..f91a23297ae812ae7deda1ee061de9b626914f34 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
<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
diff --git a/src/postgresql.c b/src/postgresql.c
index a5bacf49b2a4fc8df8aeaabbbdb2c8b4e3e63e4b..6c8b81467d96231bf0996abfd428713f13b7fcf0 100644 (file)
--- a/src/postgresql.c
+++ b/src/postgresql.c
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;
index 61844a024aa648def479fcf3171c00c29d745d0e..ab0f1782e08a24cbcdee5125888e22918cd906d8 100644 (file)
# 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