libzbxpgsql icon indicating copy to clipboard operation
libzbxpgsql copied to clipboard

Add 'state' parameter to pg.backends.count

Open fxpester opened this issue 10 years ago • 3 comments

We can monitor idle connections by - SELECT COUNT(datid) FROM pg_stat_activity where state='idle'; but currently monitoring of idle pgsql connections are not available.

I suppose it should be done in pg.backends.count in which currently implemented -something similar SELECT COUNT(datid) FROM pg_stat_activity where waiting='f';

fxpester avatar Nov 25 '15 09:11 fxpester

I did have this working at some stage but from memory, the state column was only introduced recently (maybe 9.2?). I'll take a look again at reimplementing it with graceful failure on older versions.

In the meantime, you can execute a custom query using pg.query.int http://cavaliercoder.com/libzbxpgsql/agent-keys/queries/#pg-query-integer

cavaliercoder avatar Nov 25 '15 14:11 cavaliercoder

Thx, just done it with - pg.query.integer[,,"SELECT COUNT(datid) FROM pg_stat_activity WHERE state='idle';",]

But it works only with superuser rights :(

p.s. Postgres 9.3.

fxpester avatar Nov 25 '15 16:11 fxpester

Awesome thanks. I'll look at adding a native key in the next version.

cavaliercoder avatar Nov 26 '15 13:11 cavaliercoder