Skip to content

Commit

Permalink
Added pg.prepared_xacts_ratio key
Browse files Browse the repository at this point in the history
  • Loading branch information
cavaliercoder committed Jun 25, 2016
1 parent acbffad commit eee3692
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ v1.0.0 TBC
that have been modified since the last table analyze
* Added support for `pg.queries.longest` in PostgreSQL versions prior to 9.2
* Added `pg.prepared_xacts_count` to return the number of transactions currently
parepared for two phase commit
prepared for two phase commit
* Added `pg.prepared_xacts_ratio` to return the number of transactions currently
prepared for two phase commit as a ratio of the maximum permitted prepared
transaction count
* Added `--with-postgresql` switch to source configuration script
* Added `--with-zabbix` switch to source configuration script
* Fixed misreporting in `pg.queries.longest` when no queries were in progress
Expand Down
1 change: 1 addition & 0 deletions src/libzbxpgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ static ZBX_METRIC keys[] =
{"pg.starttime", CF_HAVEPARAMS, PG_STARTTIME, NULL},
{"pg.uptime", CF_HAVEPARAMS, PG_UPTIME, NULL},
{"pg.prepared_xacts_count", CF_HAVEPARAMS, PG_PREPARED_XACTS_COUNT, NULL},
{"pg.prepared_xacts_ratio", CF_HAVEPARAMS, PG_PREPARED_XACTS_RATIO, NULL},

{"pg.setting", CF_HAVEPARAMS, PG_SETTING, ",,data_directory"},
{"pg.setting.discovery", CF_HAVEPARAMS, PG_SETTING_DISCOVERY, NULL},
Expand Down
1 change: 1 addition & 0 deletions src/libzbxpgsql.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ int PG_VERSION(AGENT_REQUEST *request, AGENT_RESULT *result);
int PG_STARTTIME(AGENT_REQUEST *request, AGENT_RESULT *result);
int PG_UPTIME(AGENT_REQUEST *request, AGENT_RESULT *result);
int PG_PREPARED_XACTS_COUNT(AGENT_REQUEST *request, AGENT_RESULT *result);
int PG_PREPARED_XACTS_RATIO(AGENT_REQUEST *request, AGENT_RESULT *result);

int PG_SETTING(AGENT_REQUEST *request, AGENT_RESULT *result);
int PG_SETTING_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result);
Expand Down
37 changes: 37 additions & 0 deletions src/pg_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,43 @@ int PG_PREPARED_XACTS_COUNT(AGENT_REQUEST *request, AGENT_RESULT *result)
ret = pg_get_int(request, result, "SELECT COUNT (transaction) FROM pg_prepared_xacts WHERE database = $1;", param_new(datname));
}

zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
return ret;
}

/*
* Custom key pg.prepared_xacts_ratio
*
* Returns the number of transactions that are currently prepared for two phase
* commit as ratio of the maximum allowed prepared transactions.
*
* Parameters:
* 0: connection string
* 1: connection database
*
* Returns: d
*/
int PG_PREPARED_XACTS_RATIO(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int ret = SYSINFO_RET_FAIL;
const char *__function_name = "PG_PREPARED_XACTS_RATIO";

zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);

ret = pg_get_dbl(
request,
result,
"\
SELECT \
CASE \
WHEN setting::integer = 0 THEN 0.00 \
ELSE ((SELECT COUNT (transaction) FROM pg_prepared_xacts)::float / setting::integer) \
END \
FROM pg_settings \
WHERE name = 'max_prepared_transactions';",
NULL
);

zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
return ret;
}

0 comments on commit eee3692

Please sign in to comment.