Coder Social home page Coder Social logo

snmp_psql_performance's Introduction

Introduction

This program allows to export statistics of all the databases of your PostgreSQL cluster via SNMP. Those statistics can then be easily monitored or graphed via all the "usual" SNMP-based tools.

The statistics are gathered from the pg_stat_database table, and then exported using NET-SNMP's pass_persist directive.

Installation

The script sould probably be installed on the PostgreSQL server itself (although it could be running on any server which can connect to the database).

It requires a valid user which can do a select on the pg_stat_database table.

Prerequisites

Use pip to get the following packages:

  • psycopg2
  • snmp_passpersist
  • argparse
sudo pip install psycopg2 snmp_passpersist argparse

Checking

Check that the script runs correctly by launching it manually:

./snmp_psql_performance.py -U USER -W PASSWORD

The program should start. By typing DUMP<CR>, you should see a long list of OIDS similar to this one:

{'1.1.1.1': {'type': 'STRING', 'value': '1'},
 '1.1.1.10': {'type': 'Counter32', 'value': '0'},
 '1.1.1.11': {'type': 'Counter32', 'value': '2'},
 '1.1.1.12': {'type': 'Counter32', 'value': '0'},
 '1.1.1.13': {'type': 'Counter32', 'value': '0'},
 '1.1.1.19': {'type': 'TIMETICKS', 'value': '19'},
 '1.1.1.2': {'type': 'STRING', 'value': 'template1'},
 '1.1.1.3': {'type': 'GAUGE', 'value': '0'},

If this doesn't work, check the logs (probably in /var/log/messages , depending on your Syslog configuration)

Configuring NET-SNMP

Add the following line to /etc/snmp/snmpd.conf:

pass_persist .1.3.6.1.4.1.42916 /path/to/snmp_psql_performance.py -U USER -W PASSWORD

And restart snmpd:

sudo /etc/init.d/snmpd restart

Check the outcome by doing a direct SNMP request:

snmpwalk -Cc -v 1 -c public localhost .1.3.6.1.4.1.42916

You should see something similar to this:

iso.3.6.1.4.1.42916.1.1.1.1 = STRING: "1"
iso.3.6.1.4.1.42916.1.1.1.2 = STRING: "template1"
iso.3.6.1.4.1.42916.1.1.1.3 = Gauge32: 0
iso.3.6.1.4.1.42916.1.1.1.4 = Counter32: 33
iso.3.6.1.4.1.42916.1.1.1.5 = Counter32: 2
iso.3.6.1.4.1.42916.1.1.1.6 = Counter32: 10
iso.3.6.1.4.1.42916.1.1.1.7 = Counter32: 7
iso.3.6.1.4.1.42916.1.1.1.8 = Counter32: 28
iso.3.6.1.4.1.42916.1.1.1.9 = Counter32: 21
iso.3.6.1.4.1.42916.1.1.1.10 = Counter32: 0
iso.3.6.1.4.1.42916.1.1.1.11 = Counter32: 2

The list of OIDs returned is described at the beginning of the source code of the file.

TODO

  • Be compatible with all versions of PostgreSQL (the content of pg_stat_database is not always the same)
  • Get an own OID identifier
  • Export more data ?
  • Write the MIB file to make the SNMP output nicer to read

snmp_psql_performance's People

Contributors

omacchioni avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.