PGMon - installation and config
A brief description of installation and config of the PGMon project. As this project has two separate and more or less independent parts - a part responsible for data collection and a web interface used to display collected data - it's necessary to install and configure both of these parts.
As already stated, the project has two main separate parts,installable and configurable separately:
Actual package with source codes is available at sf.net - on the project page. Download the current package pgmon-xxx.zip, and extract it - a directory pgmon-xxx with the following content will be created:
- README - a brief description of the project
- LICENSE - license agreement (GPL v2)
- collect - skripts responsible for data collection
- doc - documentation (API description, examples, etc.)
- libs - library used for data collection and to display them
- web - web interface used to display data
- tests - unit tests
For operation of the project, only directories "collect", "libs" and "web" are necessary. As the directories "collect" and "web" are described in the following two sections, lets take a look at the "libs" directory", i.e. shared libraries:
- PgMon_collect.php - libraty used to collect data
- PgMon_read.php - library used to load collected data (within web interface)
- PhpChart.php - library used to build charts
- PgMon_db.php - libraries encapsulating database access
- PgMon_db_resultset.php - library encapsulating query results
If you need more detailed information about API of these libraries, check the "doc" directory for API documentation, or comments in the source codes.
Part responsible for data collection
This part consists of library PgMon_collect (in "libs" directory), a set of cron scripts and a configuration file (in the "collect" directory). For each table (Tables, Indexes, Databases, BgWriter) exists a separate script exists - after it's execution the current data are collected:
- save-tables.php
- save-indexes.php
- save-databases.php
- save-bgwriter.php
Besides these files the directory contains a file "config.php" with configuration of source and target databases, shared by all the scripts listed above. This file contains two important parts:
- list of source databases to collect data for data
- target database to store data into
Both parts are defined as associative arrays - e.g. definition of source databases might be:
<?php
$sourceDbs = array(
array('host' => 'localhost',
'port' => '5432',
'schema' => 'myapp', // 'myapp' schema only
'user' => 'username',
'password' => 'password',
'objects' => 'user' // user objects only
),
array('host' => 'other-machine',
'port' => '5431',
'schema' => null, // all schemas
'user' => 'other-user',
'password' => 'other-pass',
'objects' => 'all' // all objects (user and system)
)
);
?>
By this definition the data will be collected from two databases - only data about user objects in the "myapp" schema will be collected from the first one. Data about all objects (user and system) in all schemas will be collected.
A definition of the target database may be for example:
<?php
$targetDb = array(
array('host' => 'target-machine',
'port' => '5435',
'schema' => null,
'user' => 'myuser',
'password' => 'mypass'
)
);
?>
After execution of a script the source databases are processed one-by-one, i.e. the necessary data are collected and stored to the target database.
The last important parameter is path to the shared libraries (especially to files PgMon_collect.php, PgMon_db.php and PgMon_db_resultset.php). This path should be specified in the in the PGMON_LIBS constant, and a relative or absolute path may be used:
<?php
// definition of path to the libraries
define('PGMON_LIBS', '/var/www/pgmon/libs/');
?>
An important parameter of data collection (although not specified in the configuration file) is it's frequency. An optimal value depends on database load, amount of data, etc. I recommend to start with 15 minutes for example, and modify it later.
Web interface used to display data
Web interface is a simple web application written in PHP, that loads data collected by cron scripts and displays them in the form of tables and charts (a library PhpChart.php is used to generate charts).
After copying content of the "web" directory to a place accessible from web, you have to perform two small changes in the configuration - set the path to the libraries and define access to the database to load collected data from.
The database is defined in the include/config.php in the same way as in the case of collection scripts (and logically, this should be the same database):
<?php
$db = array(
array('host' => 'target-machine',
'port' => '5435',
'schema' => null,
'user' => 'myuser',
'password' => 'mypass'
)
);
?>
You have to define path to the libraries in the same file - using the PGMON_LIBS just as in case of cron scriopts:
<?php
// path to the libraries
define('PGMON_LIBS', '/var/www/pgmon/libs/');
?>
This finishes the web interface configuration.




