How does mogdb database fit perfectly with grafana and Prometheus?

Time:2022-5-9

Grafana is a cross platform, open source measurement analysis and visualization tool, which can connect various data sources and make visual display.

Prometheus is a famous open source monitoring project. Its monitoring task is realized by a specific exporter. The exporter grabs the monitoring data from the target end and saves it in the TSDB time series database. Prometheus also supports user-defined query combinations in promql query language.

Opengauss / mogdb database can be accessed through opengauss_ The exporter fits perfectly with grafana and Prometheus.

The following is the rendering:

How does mogdb database fit perfectly with grafana and Prometheus?

The deployment process is demonstrated in the Kirin arm test environment. The x86 environment needs to replace the relevant download and installation packages.

1 Prometheus deployment

1.1. Installation package download
Software download address:https://prometheus.io/download/

Download the file prometheus-2.31.1 linux-arm64. tar. gz

1.2. Create Prometheus user

# useradd prometheus
# password prometheus

1.3. Create the corresponding directory of Prometheus and extract the installation package

# mkdir /appdata/prometheus
# mkdir /appdata/prometheus/etc
# mkdir /appdata/prometheus/log
# mkdir /appdata/prometheus/data

# tar -zxvf prometheus-2.31.1.linux-arm64.tar.gz -C /appdata/prometheus
# chown -R prometheus: /appdata/prometheus
# chmod -R 755 /appdata/prometheus

1.4. Use the Prometheus user to check the installed version

$ /appdata/prometheus/prometheus-2.31.1.linux-arm64/prometheus --version

1.5. Use the Prometheus user to edit the profile

$ vi /appdata/prometheus/etc/prometheus.yml

The contents are as follows:

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['x.x.x.x:50090']

1.6. Configure Prometheus boot with root user

# vi /usr/lib/systemd/system/prometheus.service

The contents are as follows:

[Unit]
Description= Prometheus
After=network.target

[Service]
Type=simple
User=prometheus
ExecStart=/appdata/prometheus/prometheus-2.31.1.linux-arm64/prometheus --web.listen-address="0.0.0.0:50090" --config.file=/appdata/prometheus/etc/prometheus.yml --storage.tsdb.path=/appdata/prometheus/data
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure

[Install]
WantedBy=multi-user.target

Start service:

# systemctl daemon-reload
# systemctl enable prometheus
# systemctl start prometheus

1.7. Testing the Prometheus service using a web browser
openhttp://x.x.x.x:50090/As shown in the figure below, Prometheus service is normal.
How does mogdb database fit perfectly with grafana and Prometheus?

2node_ Exporter deployment

2.1. Installation package download
Software download address:https://github.com/prometheus…

Download file node_ exporter-1.2.2. linux-arm64. tar. gz

2.2. Use the root user to extract the installation package
The root user decompresses the installation package to the Prometheus user, and the test environment is deployed under the Prometheus user.

# tar -zxvf node_exporter-1.2.2.linux-arm64.tar.gz -C /appdata/prometheus/
# chown -R prometheus: /appdata/prometheus/node_exporter-1.2.2.linux-arm64

2.3. Use the Prometheus user to check the installed version

$ /appdata/prometheus/node_exporter-1.2.2.linux-arm64/node_exporter --version

2.4. Configure node with root user_ Exporter boot

# vi /usr/lib/systemd/system/node_exporter.service

The contents are as follows:

[Unit]
Description= node exporter
After=network.target

[Service]
Type=simple
User=prometheus
ExecStart=/appdata/prometheus/node_exporter-1.2.2.linux-arm64/node_exporter --web.listen-address=":9100" --no-collector.softnet
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure

[Install]
WantedBy=multi-user.target

# systemctl daemon-reload
# systemctl enable node_exporter
# systemctl start node_exporter

2.5. View node_ Exporter service
# systemctl status node_exporter
2.6. Prometheus configuration exporter
Prometheus configuration file Prometheus YML add the following:

  - job_name: 'node_exporter'
    static_configs:
    - targets: ['110.128.131.16:9100']

2.7. Restart the Prometheus service with root
`# systemctl restart prometheus
`

3opengauss_ Exporter deployment

3.1. Installation package download
Download address:https://github.com/enmotech/o…

Download file node_ exporter-1.2.2. linux-arm64. tar. gz

3.2. Use the root user to extract the installation package
The root user decompresses the installation package to the Prometheus user, and the test environment is deployed under the Prometheus user.

# unzip opengauss_exporter_0.0.9_linux_arm64.zip -d /appdata/prometheus/opengauss_exporter
# chown -R prometheus: /appdata/prometheus/opengauss_exporter

3.3. Use the Prometheus user to check the installed version

$ /appdata/prometheus/opengauss_exporter/opengauss_exporter --version

3.4. Upload yaml file
File storage path: / appdata / Prometheus / opengauss_ exporter

Modify permissions:

# chown prometheus: queries.yaml
3.5. Mogdb database side configuration
3.5.1. Create monitoring user
The password complexity shall meet the requirements of the database. The default requirement is case + special characters, no less than 8 digits.

$ gsql -Uomm postgres -r



CREATE USER db_exporter WITH PASSWORD 'XXXXXXXX' MONADMIN;

grant usage on schema dbe_perf to db_exporter;

grant select on pg_stat_replication to db_exporter;

3.5.2. Configure PG_ hba. conf
Add the mogdbmonitor whitelist in the encryption mode of MD5.

$ gs_guc set -I all -N all -h "host postgres db_exporter 110.128.131.16/32 md5"

3.6. Use the root user to configure the service startup

# vi /usr/lib/systemd/system/mogdb_exporter.service

The contents are as follows:

[Unit]

Description=Prometheus MogDB Exporter Server



[Service]

User=prometheus

Environment="DATA_SOURCE_NAME=postgresql://db_exporter:[email protected]:port/postgres?sslmode=disable"

ExecStart=/appdata/prometheus/opengauss_exporter/opengauss_exporter --web.listen-address=":51007" --config="/appdata/prometheus/opengauss_exporter/queries.yaml"



[Install]

WantedBy=multi-user.target

Start service:

# systemctl daemon-reload

# systemctl enable mogdb_exporter

# systemctl start mogdb_exporter

3.7. View exporter services
# systemctl status mogdb_exporter

3.8. Prometheus configuration exporter
Prometheus configuration file Prometheus YML add the following:


    - job_name: ' mogdb_exporter '

    static_configs:

        - targets: ['110.128.131.16: 51007']

3.9. Restart the Prometheus service with root
# systemctl restart prometheus

4grafana deployment

4.1. Installation package download
Download address:https://grafana.com/grafana/d…

Download the file grafana-enterprise-8.2.4 linux-arm64. tar. gz

4.2. Use the root user to extract the installation package
The root user decompresses the installation package to the Prometheus user, and the test environment is deployed under the Prometheus user.

# tar -zxvf grafana-enterprise-8.2.4.linux-arm64.tar.gz -C /appdata/prometheus/

# chown -R prometheus: /appdata/prometheus/grafana-8.2.4

4.3. Use the Prometheus user to check the installed version

$ /appdata/prometheus/grafana-8.2.4/bin/grafana-server -v

4.4. Configuring grafana using the Prometheus user

$ vi /appdata/prometheus/grafana-8.2.4/conf/defaults.ini

For example, modify http_ Port = 51009, modify 3306 port of built-in database, etc.

4.5. Use the root user to configure the service startup

# vi /usr/lib/systemd/system/grafana.service

The contents are as follows:

[Unit]

Description=Grafana Server



[Service]

User=prometheusExecStart=/appdata/prometheus/grafana-8.2.4/bin/grafana-server -homepath /appdata/prometheus/grafana-8.2.4/ -config /appdata/prometheus/grafana-8.2.4/conf/defaults.ini 



[Install]

WantedBy=multi-user.target

Start service:

# systemctl daemon-reload

# systemctl enable grafana.service

# systemctl start grafana.service

4.6. View grafana service status
# systemctl status grafana.service

4.7. Testing grafana with a web browser
openhttp://x.x.x.x:51009/, default account: admin, default password: admin

Then configure Prometheus and load dashboard.

About the author
Peng Chong, PG technical consultant of Yunhe enmo, online name “Duomi Papi”, PG community certification expert, China’s first PostgreSQL ace partner, has been engaged in software research and development based on PostgreSQL database for many years, and is good at PL / PgSQL business migration and optimization, Oracle to PostgreSQL migration and upgrading, and heterogeneous database integration; As a columnist of PostgreSQL practice of Mo Tianlun, he is keen on sharing PostgreSQL practice technology, actively promotes PostgreSQL in his own post, and is committed to making more contributions to PG community.