From b762e50bdd12424dc40a58f82a25bb86c7348849 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 18 Jul 2008 21:39:29 +0200 Subject: [PATCH] postgresql plugin: Moved pg_stat_database query to postgresql_default.conf. Signed-off-by: Sebastian Harl Signed-off-by: Florian Forster --- src/postgresql.c | 48 +------------------------------------ src/postgresql_default.conf | 12 ++++++++++ 2 files changed, 13 insertions(+), 47 deletions(-) diff --git a/src/postgresql.c b/src/postgresql.c index f2d7665f..5bf06145 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -123,6 +123,7 @@ typedef struct { } c_psql_database_t; static char *def_queries[] = { + "database", "user_tables", "io_user_tables" }; @@ -400,51 +401,6 @@ static int c_psql_exec_query (c_psql_database_t *db, int idx) return 0; } /* c_psql_exec_query */ -static int c_psql_stat_database (c_psql_database_t *db) -{ - const char *const query = - "SELECT numbackends, xact_commit, xact_rollback " - "FROM pg_stat_database " - "WHERE datname = $1;"; - - PGresult *res; - - int n; - - res = PQexecParams (db->conn, query, /* number of parameters */ 1, - NULL, (const char *const *)&db->database, NULL, NULL, - /* return text data */ 0); - - if (PGRES_TUPLES_OK != PQresultStatus (res)) { - log_err ("Failed to execute SQL query: %s", - PQerrorMessage (db->conn)); - log_info ("SQL query was: %s", query); - PQclear (res); - return -1; - } - - n = PQntuples (res); - if (1 < n) { - log_warn ("pg_stat_database has more than one entry " - "for database %s - ignoring additional results.", - db->database); - } - else if (1 > n) { - log_err ("pg_stat_database has no entry for database %s", - db->database); - PQclear (res); - return -1; - } - - submit_gauge (db, "pg_numbackends", NULL, PQgetvalue (res, 0, 0)); - - submit_counter (db, "pg_xact", "commit", PQgetvalue (res, 0, 1)); - submit_counter (db, "pg_xact", "rollback", PQgetvalue (res, 0, 2)); - - PQclear (res); - return 0; -} /* c_psql_stat_database */ - static int c_psql_read (void) { int success = 0; @@ -460,8 +416,6 @@ static int c_psql_read (void) if (0 != c_psql_check_connection (db)) continue; - c_psql_stat_database (db); - for (j = 0; j < db->queries_num; ++j) c_psql_exec_query (db, j); diff --git a/src/postgresql_default.conf b/src/postgresql_default.conf index 1391147c..d304de53 100644 --- a/src/postgresql_default.conf +++ b/src/postgresql_default.conf @@ -1,5 +1,17 @@ # Pre-defined queries of collectd's postgresql plugin. + + Query "SELECT numbackends, xact_commit, xact_rollback \ + FROM pg_stat_database \ + WHERE datname = $1;" + + Param database + + Column pg_numbackends + Column pg_xact commit + Column pg_xact rollback + + Query "SELECT sum(seq_scan), sum(seq_tup_read), \ sum(idx_scan), sum(idx_tup_fetch), \ -- 2.30.2