# PostgreSQL # Introduction Ver. 07-03-2022 With this plug-in we will be able to monitor postgreSQL through customized queries. Type: Server plug-in # Compatibility matrix
Systems where tested | CentOS 7, Fedora, rocky linux |
Systems where it should work | Cualquier sistema linux |
**Parámetro** | **Descripción** |
-d,--database | Database name (required) |
-u,--user | Name of the postgreSQL user(required) |
-p,-password | postgreSQL password (required) |
-i,--ip | server ip (required) |
--port | server port. Default 5432 (optional) |
--tentacle\_port | Tentacle port (default 41121)(optional) |
--tentacle\_address | Ip of the tentacle server to send the data (optional) |
--agent\_name | To name the agent that will contain the custom queries modules, by default: "PostgreSQL" (optional). |
--prefix\_module | To prefix the modules in case you want to differentiate them from other executions (optional). |
--conf | Path of the conf file with the queries (required) |
-g,--group | Pandora FMS target group (optional) |
--data\_dir | Pandora FMS data directory. By default it is /var/spool/pandora/data\_in/ (optional) |
--transfer\_mode | XML transfer method, the two possible options are: tentacle or local. |
La ruta por defecto de "data\_dir" es /var/spool/pandora/data\_in , si esta no existe en la máquina que se esta ejecutando el plugin dará error, de ser este el caso, se debe cambiar la ruta con el parámetro "--data\_dir" para elegir otra ruta donde se crearán los XML que posteriormente se envíaran.
# Configuration in PandoraFMS As a server plugin Installation from console To register the plugin, from the console, go to the "register plugin" section. **[](https://pandorafms.com/guides/public/uploads/images/gallery/2022-04/register-plugin.png)** Click on select file. **[](https://pandorafms.com/guides/public/uploads/images/gallery/2022-04/register-plugin2.png)** Select the pspz2 file that contains the plugin **[](https://pandorafms.com/guides/public/uploads/images/gallery/2022-04/register1-postgresql.png)** A message will be displayed indicating that you have successfully registered. **[](https://pandorafms.com/guides/public/uploads/images/gallery/2022-04/register2-postgresql.png)** Once the plugin is registered, we will see it in the plugins section. [](https://pandorafms.com/guides/public/uploads/images/gallery/2022-04/serversingles.png) Clicking on the plugin title will take you to the plugin menu. [](https://pandorafms.com/guides/public/uploads/images/gallery/2022-04/register3-postgresql.png) In macros will appear all those that have the plugin, remember that not all are obligatory, only those that are specified. [](https://pandorafms.com/guides/public/uploads/images/gallery/2022-04/register4-postgresql.png) Below you can assign the required value to each variable. [](https://pandorafms.com/guides/public/uploads/images/gallery/2022-04/register5-postgresql.png) **Manual installation** Go to servers > plugins: [](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/image-1629974405286.png) Click on add: [](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/image-1629974430627.png) We put the name and description of your choice: [](https://pandorafms.com/guides/public/uploads/images/gallery/2022-03/image-1646737918843.png) We enter as command the execution with the path of the plugin: ``` /path_pandora_postgresql ``` [](https://pandorafms.com/guides/public/uploads/images/gallery/2022-03/image-1646738193972.png) And in plugin parameters we will enter these followed by the macro "\_field\_", the mandatory ones for the plugin to work are -d,-u,-p,-i,--port, --transfer\_mode and --conf. We will define these with the macros below. **Database** [](https://pandorafms.com/guides/public/uploads/images/gallery/2022-03/image-1646741029424.png) **user** [](https://pandorafms.com/guides/public/uploads/images/gallery/2022-03/image-1646741076563.png) **password** [](https://pandorafms.com/guides/public/uploads/images/gallery/2022-03/image-1646741107573.png) **ip** [](https://pandorafms.com/guides/public/uploads/images/gallery/2022-03/image-1646741133355.png) **puerto** [](https://pandorafms.com/guides/public/uploads/images/gallery/2022-03/image-1646741160772.png) **conf** [](https://pandorafms.com/guides/public/uploads/images/gallery/2022-03/image-1646741187282.png) **transfer\_mode** [](https://pandorafms.com/guides/public/uploads/images/gallery/2023-08/image-1692351184433.png) Once this is done, click on "create". You can check that you have entered the values correctly by executing the terminal preview command If it does not give errors it is that it has been introduced well. Once this is done, the only thing left to do is to call it, so we will go to some agent's view and create a module of complements: [](https://pandorafms.com/guides/public/uploads/images/gallery/2022-03/image-1646741530197.png) We will give it a name and in the section "plugin" we will put the one we have just configured. [](https://pandorafms.com/guides/public/uploads/images/gallery/2022-03/image-1646741600061.png) Once this is done, click on create. If the module is shown with 1, it means that it is running correctly. [](https://pandorafms.com/guides/public/uploads/images/gallery/2022-03/image-1646741405902.png) # Modules generated by the plugin The plugin will create an agent with the name that we have set with the parameter "--agent\_name" if this parameter is not used it will stay with "PostgreSQL" by default: [](https://pandorafms.com/guides/public/uploads/images/gallery/2022-03/image-1646739709089.png) In this agent, a module will be created for each customized query specified in pandora\_postgresql.conf, with the name that we have assigned to each one of them. For example the following conf: ``` number_connections:SELECT count(*) FROM pg_stat_activity;:generic_data:Number of Connections or running backend connections_waiting_in_locks:SELECT count(*) FROM pg_stat_activity WHERE wait_event = 'Lock';:generic_data:Number of connections/backends waiting on locks connections_idle_in_transaction:SELECT count(*) FROM pg_stat_activity WHERE wait_event = 'idle in transaction';:generic_data number_users:SELECT COUNT(usename) FROM pg_stat_activity;:generic_data number_roles:SELECT count(*) FROM pg_roles;:generic_data psql_version:SELECT version();:generic_data_string num_blocks:SELECT COUNT(*) FROM pg_locks;:generic_data psql_diskspace:SELECT ROUND(SUM(pg_database_size(oid))/1024/1024) FROM pg_database;:generic_data number_commits:SELECT sum(xact_commit) FROM (pg_database AS db JOIN pg_stat_database sdb ON db.datname=sdb.datname) WHERE db.datname = 'postgres';:generic_data number_rollbacks:SELECT sum(xact_rollback) FROM (pg_database AS db JOIN pg_stat_database sdb ON db.datname=sdb.datname) WHERE db.datname = 'postgres';:generic_data tuples_returned:SELECT sum(tup_returned) FROM (pg_database AS db JOIN pg_stat_database sdb ON db.datname=sdb.datname) WHERE db.datname = 'postgres';:generic_data tuples_searched:SELECT sum(tup_fetched) FROM (pg_database AS db JOIN pg_stat_database sdb ON db.datname=sdb.datname )WHERE db.datname = 'postgres';:generic_data tuples_inserted:SELECT sum(tup_inserted) FROM (pg_database AS db JOIN pg_stat_database sdb ON db.datname=sdb.datname) WHERE db.datname = 'postgres';:generic_data tuples_updated:SELECT sum(tup_updated) FROM (pg_database AS db JOIN pg_stat_database sdb ON db.datname=sdb.datname) WHERE db.datname = 'postgres';:generic_data tuples_removed:SELECT sum(tup_deleted) FROM (pg_database AS db JOIN pg_stat_database sdb ON db.datname=sdb.datname) WHERE db.datname = 'postgres';:generic_data state:SELECT state FROM pg_stat_activity WHERE datname = 'postgres';:generic_data_string ``` It will create the following modules: [](https://pandorafms.com/guides/public/uploads/images/gallery/2022-03/image-1646740864822.png)