DEV Community

vuong ⛈️
vuong ⛈️

Posted on • Updated on

Percona Monitoring with Postgres Docker on local environment

You have a Postgres running in Docker container, but don't know how to monitor its active connections. Percona Monitor can be considering for using in this case.

Install PMM

https://docs.percona.com/percona-monitoring-and-management/setting-up/server/docker.html#run-docker-with-volume

To access the web UI with port 80

If you don't want to use the port 443 in local (because it might be complicated to setup the key/cert/pem), can also use port 80.

docker run --detach --restart always \
--publish 8889:80 \
-v pmm-data:/srv \
--name pmm-server \
percona/pmm-server:2
Enter fullscreen mode Exit fullscreen mode

It will map port 8889 of host computer to port 80 on the container

Add new instance to PMM

After login into the tool, we can go to add the instance of DB that we want to do monitoring.

Image description

Then, ensure the pmm-server joins the network of DB, so it can connect to the instance DB host with container name:

docker network ls
Enter fullscreen mode Exit fullscreen mode

Given example that DB of your service is running on dev_default, here is how to add pmm-server into that network:

docker network connect dev_default pmm-server
Enter fullscreen mode Exit fullscreen mode

After pmm-server joining the network, we can just simply setup the instance:

Image description

Image description

Then click on Add service.

Enable the pg_stat_statements to have ability of looking at query analysis

This article is useful: https://gist.github.com/lfittl/1b0671ac07b33521ea35fcd22b0120f5

Query to test after enabling

SELECT /* pmm-agent:pgstatstatements */ "pg_stat_statements"."userid", "pg_stat_statements"."dbid", "pg_stat_statements"."queryid", "pg_stat_statements"."query", "pg_stat_statements"."calls", "pg_stat_statements"."total_time", "pg_stat_statements"."rows", "pg_stat_statements"."shared_blks_hit", "pg_stat_statements"."shared_blks_read", "pg_stat_statements"."shared_blks_dirtied", "pg_stat_statements"."shared_blks_written", "pg_stat_statements"."local_blks_hit", "pg_stat_statements"."local_blks_read", "pg_stat_statements"."local_blks_dirtied", "pg_stat_statements"."local_blks_written", "pg_stat_statements"."temp_blks_read", "pg_stat_statements"."temp_blks_written", "pg_stat_statements"."blk_read_time", "pg_stat_statements"."blk_write_time" FROM "pg_stat_statements" WHERE queryid IS NOT NULL AND query IS NOT NULL;

Enter fullscreen mode Exit fullscreen mode

Practice some DB activities on the service, then choose the menu to see the new monitoring data in this menu

Image description

The data looks cool now when checking dev-db host.
Image description

It's done to setup PMM with Postgres on the local env.

Top comments (4)

Collapse
 
ajeetraina profile image
Ajeet Singh Raina

Also, it's worth checking out Percona Monitoring Docker Extension
github.com/edithturn/pmm-docker-ex...

Collapse
 
vuong profile image
vuong ⛈️

Wow, absolutely nice. TIL PMM can be using as extension, thanks @ajeetraina!!

Collapse
 
perconabytes profile image
Percona Community Team

Hi, thank you very much for your article.
You have a small typo in the title
Perconal -> Percona

Collapse
 
vuong profile image
vuong ⛈️

So sorry about that. I just fixed it!