GithubHelp home page GithubHelp logo

pgmon_zabbix's Introduction

pgmon_2ndQ

pgmon_2ndq is a set of postgresql monitoring functions implemented in the server.

The functions are installed in their own database and connect back to all databases in the server to get database specific info

A cronjob gets the monitoring info from these functions in a single database call and saves it to a file

Then zabbix user parameters are used to get the data from this file.

This architecture was chosen to make it easy to control number of connections to database

create monitoring database and user

CREATE USER zbx_monuser PASSWORD 'zbx_monpwd';

CREATE DATABASE zbx_mondb;

CREATE USER zbx_monuser
  WITH NOSUPERUSER INHERIT NOCREATEROLE NOCREATEDB
  PASSWORD 'zbx_monpwd';

CREATE SCHEMA moninfo_2ndq;
-- needed if zbx_monuser is not superuser
GRANT USAGE ON SCHEMA moninfo_2ndq TO zbx_monuser;

connect to monitoring database

\c zbx_mondb

CREATE EXTENSION plpythonu;

and load the function definitions:

\i mondb_functions.sql

your database host must have pl/python language installed. It is usually either in its own package called something like postgresql-python or postgresql-plpython.

pl/python makes use of pythons postgresql module psycopg2 to connect to all monitored databases in this server, so the following needs to succeed when run on the database server:

user@host:~/pgmon_zabbix$ python
Python 2.7.3 (default, Aug  1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>>

If it does not work, you need to install psycopg2. Usually it is in a package python-psycopg2 or similar.

Next, check pg_hba.conf to make sure that the monitoring user can connect to the monitoring database. ( It may be a good idea to let it connect to _only_ the monitoring database ).

Test it from the host you are going to run the zabbix monitoring info collector from

psql -h <database host> zbx_mondb zbx_monuser

if connecting succeeds, run:

select * from moninfo_2ndq.moninfo_full();

if this also succeeds, you have successfully configured the database side of zabbix monitoring for postgresql.

first edit copy mon_collector.py to /usr/local/bin and set the executable bit

sudo cp mon_collector.py /usr/local/bin
sudo chmod +x /usr/local/bin/mon_collector.py

and set the PG_* constants to correct values:

### configuration
LOGDIR_BASE = "/var/log/pgmon_2ndQ/"
### moninfo files will be kept in LOGDIR_BASE/PG_HOST/PG_PORT
### edit the folowing to connect to your database
MONDB = 'zbx_mondb' # recommendation to use dedicated database
PG_HOST = 'localhost' if (len(sys.argv) < 2 or sys.argv[1].startswith('--')) else sys.argv[1]
PG_PORT = '5432' if (len(sys.argv) < 3 or sys.argv[2].startswith('--')) else sys.argv[2]
PG_USER =  'zbx_monuser'
PG_PWD = 'zbx_monpwd'
##print PG_HOST,PG_PORT,PG_USER
### number of latest logs to keep, 0 - no cleanup
CLEANUP_OLD_LOGS = 5
### end of configuration

you have to create the directory LOGDIR_BASE and make it writable by the user who will be running the cronjob. Probably the best choice is user 'zabbix' as this is the used which will later consume the collected data:

sudo mkdir /var/log/pgmon_2ndQ/
sudo chown zabbix /var/log/pgmon_2ndQ/

host and port can be specified also when calling the collector script, so you can use the same script for multiple servers if they are otherways set up in similar manner, that is the monitoring database, user and password or other access controls are the same.

(You are welcome to contribute support for config files or more command line parameters)

Once done test it:

sudo -u zabbix mon_collector.py

if this runs with no errors, check that you have the LOGDIR_BASE/PG_HOST/PG_PORT/latest file.

if this is also ok generate the user parameters for zabbix

sudo -u zabbix mon_collector.py --UserParameter.conf > /etc/zabbix/zabbix_agentd.d/userparameter_pgmon_zabbix.conf

and restart zabbix agents

sudo /etc/init.d/zabbix-agent restart

as a last step add mon_collector.py to crontab of user zabbix

sudo -u zabbix crontab -e

and add line

* * * * * /usr/local/bin/mon_collector.py

to get collect monitoring info every minute.

See if you start getting new files in LOGDIR_BASE/PG_HOST/PG_PORT/ each minute

Test if zabbix agent works

# get one value for a key
/usr/sbin/zabbix_agentd -t pg2ndq.mon_collector.runtime

# get all available values
/usr/sbin/zabbix_agentd -p

If not, check mail for zabbix user for cron errors

sudo -u zabbix mail

Copy zabbix_2ndQ.py to /usr/local/bin and set the executable bit

sudo cp zabbix_2ndQ.py /usr/local/bin
sudo chmod +x /usr/local/bin/zabbix_2ndQ.py

Import the provided template into zabbix

in Configuration/Templates screen click Import.

Then select the Template_2ndq_PostgreSQL.xml file and import it

Finally activate "PostgreSQL servers" from Configuration/HostGroups

And you should be done now!

You can also try the zabbix_get command manually from the machine running the server:

zabbix_get -s 192.168.11.65 -p 10050 -k "pg2ndq.TABLESPACE.discovery"

pgmon_zabbix's People

Contributors

postsql 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.