Graphing "connections" in postgres module


One of the metrics we alert on in the Nagios script is the number of connections to the DB (backends).

After implementing the postgres graphing module in LibreNMS, I can’t find this metric in there.

We pull this from the by using:

--actions backends

Can this check be graphed in the postgres module please?


Hi team,

I think this is an important metric to graph, as connection limits are set on the DB and if they are exceeded, the DB no longer accepts new connections.

We have Nagios alerting on this stuff, but graphing it all is what is required.

I’m not a programmer, but if I wanted to give this one a shot, how would I start?



@micoots Have you seen this?

Hi Murrant,

Yes, that is what I am using. It uses the Nagios check_postgres plugin but neglects to graph the “–actions backends” parameter from the script.

In other words, it uses output of that script to graph all sorts of things, but it isn’t using the output of “–actions backends” to graph the number of connections to the backend database.

I’m not sure why this paramater wasn’t chosen to be graphed, but what I’m saying is it should be. It’s an important paramater to graph as discussed above.

In regards to my query, I don’t know the internals of how results returned from a script end up as a graph in LibreNMS, but the return of that paramater to Nagios is:

POSTGRES_BACKENDS OK: DB db_name (host:host_ip) (port=5598) 432 of 500 connections (86%)

which generates a WARNING in Nagios. In LibreNMS, x / 500 can be graphed, which will show the number of DB connections on each check.



No, that has nothing to do with check_postgres

Hi Murrant,

Note in the link:

items 5 and 6:

5: Install the Nagios check on your system.

6: Verify the path to in /etc/snmp/postgres is correct.

that is the Nagios script I’m talking about and this Nagios script is called from /etc/snmp/postgres



Odd, that is the only one like that. Sorry about that.

try running /etc/snmp/postgres and check the output.

Hi Murrant,

Thanks for all your comments so far. But I should be clear or re-iterate the problem.

I am getting graphs and output for postgres, that’s not a problem. My request is to graph the connections to the backend DB.

At the moment the postgres script, which calls the check_postgres Nagios script, pulls various details but does not include backend connections.

Backend connections to graph are very important as I described earlier.

So my query is, if I wanted to try and make this work ie. get the output of the "--actions backends" and graph the results in LibreNMS, how would I do this?



As far as I remember LibreNMS determines the data it will record upon first successful check execution.
So if your check output changed after the first run that resulted in “OK…”, LibreNMS won’t pick up on additional data sources and will not store them in services.service_ds in the database.

If that might be the underlying cause in your case, delete the check (and all rrd’s, db entries etc.) and re-add it. Be aware that this means you will lose your historical data.

To be clear: LibreNMS will graph all “perfdata” output from Nagios checks it will find (but as said above, only checks for perfdata ds’es on first succesful run). So maybe you can add the correct output to your postgres check if it is not in the defined format.

Hi florianbeer,

Thank you for your response.

I dedicated some time to this today and worked it all out (thanks to your guidance as a starting point).

I also have this problem which no one could answer:

but have been able to work out both issues from your response.

Firstly, the “Backends” was always showing up correctly, I just never realised it at the time.

Secondly, I de-selected the postgres App, then removed the RRD files. I couldn’t work out how to remove db entries etc, couldn’t find anything to remove even when installing phpMyAdmin on it. If you have a document/help on this anywhere, please advise (just for my interest).

I then checked the /etc/snmp/postgres script, which calls the Nagios script, and noticed that the Nagios script allows for multiple ports to be included on the ports line, so I changed the top of the postgres script to be:

#make sure the paths are right for your system
cpg='/usr/bin/env /usr/local/nagios/libexec/check_postgres'

$cpg -u $DBuser -p 5598,5599 --action dbstats | awk -F ' ' '

Notice the important part there is “-p 5598,5599” which must be added to the script. This is nowhere to be found in any documentation but the Nagios script supports multiple ports to be defined there, therefore supplying access to all the DB’s. This should be added to the LibreNMS docs so it can help others.

Then I waited 5 minutes for the poll to finish, then I re-added the entry into /etc/snmp/snmpd.conf and re-enabled in LibreNMS, then waited.

The script was then able to see all databases, and pull the right metrics for each.

Very happy. I’ll update the other case with the same reference to this case for solved status.