Difference between revisions of "Plugin:PostgreSQL"

From collectd Wiki
Jump to: navigation, search
(Relicensed to MIT license.)
Line 73: Line 73:

Latest revision as of 01:59, 12 March 2020

PostgreSQL plugin
Type: read
Callbacks: config, init, read, write, shutdown
Status: supported
First version: 4.5
Copyright: 2008–2012 Sebastian Harl
2009 Florian Forster
License: MIT license
Manpage: collectd.conf(5)
List of Plugins

The PostgreSQL plugin connects to and executes SQL statements on a PostgreSQL database. It then reads back the results and, depending on the configuration, the returned values are then converted into collectd “value lists” (the data structure used internally to pass statistics around). This plugin is a generic plugin, i.e. it cannot work without configuration, because there is no reasonable default behavior. Please read the Plugin postgresql section of the collectd.conf(5) manual page for an in-depth description of the plugin's configuration.

The configuration syntax of the PostgreSQL, DBI, and Oracle plugins is very similar, because the configuration of those plugins is handled by the same module. Also, we tried to keep the syntax similar to that of the SNMP plugin. So if you use any of those plugins already, most of the following will look familiar.


<Plugin postgresql>
  <Query magic>
    Statement "SELECT magic FROM wizard WHERE host = $1;"
    Param hostname
      Type gauge
      InstancePrefix "magic" 
      ValuesFrom magic

  <Query rt36_tickets>
    Statement "SELECT COUNT(type) AS count, type \
                      FROM (SELECT CASE \
                                   WHEN resolved = 'epoch' THEN 'open' \
                                   ELSE 'resolved' END AS type \
                                   FROM tickets) type \
                      GROUP BY type;"
      Type counter 
      InstancePrefix "rt36_tickets"
      InstancesFrom "type"
      ValuesFrom "count" 

  <Database foo>
    Host "hostname"
    Port "5432"
    User "username"
    Password "secret"
    SSLMode "prefer"
    KRBSrvName "kerberos_service_name"
    Query magic

  <Database bar>
    Service "service_name"
    Query backend # predefined
    Query rt36_tickets

Example graphs

Plugin-postgresql-idx tup fetch.png


  • libpq
    (The PostgreSQL C client library.)

See also