Using Prometheus + grafana to listen to PostgreSQL in docker environment

Time:2021-12-8

design sketch

Using Prometheus + grafana to listen to PostgreSQL in docker environment

Environmental preparation

Prepare the docker environment, including docker compose. Here, you can directly use the docker compose configuration file.

$ mkdir docker-composes
$ git clone https://github.com/docker-composes/postgres.git
$ git clone https://github.com/docker-composes/grafana.git
$ git clone https://github.com/docker-composes/prometheus.git

Note: the following operations start from the docker compositions directory.

Container configuration

Postgres exporter configuration

vim postgres/exporter/docker-compose.yml

Set the Postgres database connection information to data_ SOURCE_ Name environment variable. If it is a container under the same network, take the container name as the host. Here, use the container Postgres singleton under the same network (local net).

DATA_SOURCE_NAME=postgresql://root:[email protected]:5432/postgres?sslmode=disable

prometheus.yml

vim prometheus/singleton/config/prometheus.yml

In the scene_ Add under the configs scope:

  # Postgres
  - job_name: 'postgres'
    static_configs:
      - targets: ['postgres-exporter-singleton:9187']
        labels:
          instance: 'postgres-01'
          platform: 'ec2'

Start container

$ docker network create local-net
$ cd grafana && docker-compose up -d 
$ cd prometheus/signleton && docker-compose up -d 
$ cd postgres/signleton && docker-compose up -d
$ cd postgres/expoter && docker-compose up -d

Configure grafana

visithttp://localhost:3000

Configure data sources

stayConfiguration -> Data SourcesPage add data source:

Using Prometheus + grafana to listen to PostgreSQL in docker environment

Import dashboard

copyDashboardID: 9628, import:
Using Prometheus + grafana to listen to PostgreSQL in docker environment

Using Prometheus + grafana to listen to PostgreSQL in docker environment

After the import is successful, you can open the dashboard to view the effect.

epilogue

  1. Understand the network connection between docker containers.
  2. Understand the configuration file mounting in docker-compose.yml.
  3. Patiently configure grafana.

After running through, you can study the query of various indicators and the statistical function of grafana, which will benefit a lot.

Recommended Today

Heavyweight Tencent cloud open source industry’s first etcd one-stop governance platform kstone

​ Kstone open source At the kubecon China Conference held by CNCF cloud native foundation on December 9, 2021,Tencent cloud container tke team released the open source project of kstone etcd governance platform. KstoneIt was initiated by the TKE team of Tencent cloud containerCloud native one-stop etcd governance project based on kubernetes。 The project originates […]