postgres-node-exporter install

İbrahim Yıldız
3 min readSep 5, 2023

PostgreSQL Node Exporter, PostgreSQL veritabanı sunucusunun performans metriklerini toplamak ve izlemek için kullanılan bir Prometheus veri toplayıcı (exporter) aracıdır. Bu araç, PostgreSQL sunucusunun farklı metriklerini toplayarak Prometheus veya diğer metrik toplama ve izleme sistemlerine aktarır. Bu sayede PostgreSQL veritabanınızın performansını ve sağlığını gözlemleyebilirsiniz.

İşte PostgreSQL Node Exporter’ın bazı temel özellikleri:

  1. Metrik Toplama: PostgreSQL Node Exporter, PostgreSQL veritabanı sunucusundan çeşitli metrikleri düzenli aralıklarla toplar. Bu metrikler, veritabanının performansı, kullanımı ve sağlığı hakkında bilgi sağlar.
  2. Prometheus Entegrasyonu: Node Exporter, topladığı metrikleri Prometheus veri toplama sistemi tarafından kullanılabilir hale getirir. Bu sayede Prometheus ile PostgreSQL veritabanını izleyebilir ve metrik verilerini grafikler veya uyarılar oluşturmak için kullanabilirsiniz.
  3. Kullanım Kolaylığı: PostgreSQL Node Exporter, kurulumu ve yapılandırması kolay bir araçtır. PostgreSQL sunucusuna bağlantı bilgilerini ve export edilecek metrikleri belirleyerek hızlıca kullanmaya başlayabilirsiniz.
  4. Özelleştirme Yeteneği: Node Exporter’ın yapılandırma dosyasını düzenleyerek hangi metrikleri toplatacağınızı ve nasıl davranacağınızı özelleştirebilirsiniz. Bu, ihtiyaca göre özelleştirilmiş metrik toplama işlemleri yapmanıza olanak tanır.

Ne işe yaradığını bahsettiysek kurumlara hızlaca geçebiliriz RHEL Üzerinde Kurumlarını Gerçekleştireceğiz

grafana install :

wget -q -O gpg.key https://rpm.grafana.com/gpg.key

sudo rpm --import gpg.key

vi /etc/yum.repos.d/grafana.repo

[grafana]
name=grafana
baseurl=https://rpm.grafana.com
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://rpm.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt

!:wq

exclude=*beta*
sudo dnf install grafana
systemctl start grafana-server
systemctl enable grafana-server


http://localhost:3000

node exporter install:

mkdir /opt/postgres_exporter
cd /opt/postgres_exporter

wget https://github.com/wrouesnel/postgres_exporter/releases/download/v0.5.1/postgres_exporter_v0.5.1_linux-amd64.tar.gz

tar -xzvf postgres_exporter_v0.5.1_linux-amd64.tar.gz
cd postgres_exporter_v0.5.1_linux-amd64
cp postgres_exporter /usr/local/bin
cd /opt/postgres_exporter

sudo vi postgres_exporter.env

DSN: postgres://user:password@localhost:5432/mydb?sslmode=disable

vi /etc/systemd/system/postgres_exporter.service

[Unit]
Description=Prometheus exporter for Postgresql
Wants=network-online.target
After=network-online.target
[Service]
User=postgres
Group=postgres
WorkingDirectory=/opt/postgres_exporter
EnvironmentFile=/opt/postgres_exporter/postgres_exporter.env
ExecStart=/usr/local/bin/postgres_exporter
Restart=always
[Install]
WantedBy=multi-user.target

localhost:9187/metrics

Evet evet metirclerimiz geliyor gelen metricleri prometheus'a ekleyelim

prometheus install :

#wget https://github.com/prometheus/prometheus/releases/download/v2.29.1/prometheus-2.29.1.linux-amd64.tar.gz

Extract the Prometheus installation source.
# tar -xzf prometheus-2.29.1.linux-amd64.tar.gz -C /tmp/prometheus-files

Rename the Prometheus binary file to the user binary folder in the server.

# mv prometheus-2.29.1.linux-amd64 prometheus-files
# cp /root/prometheus-files/prometheus /usr/bin/
# cp /root/prometheus-files/promtool /usr/bin/

Finally Verify the Prometheus version

# prometheus -V

Configure Prometheus to get linux matrix such as CPU, Memory, etc.
The Prometheus needs to be configured for use. For this we need to create a user and directory first and then set the ownership to Prometheus.
# sudo useradd –no-create-home –shell /bin/false prometheus
# sudo mkdir /etc/prometheus
# sudo mkdir /var/lib/prometheus
# sudo chown prometheus:prometheus /etc/prometheus
# sudo chown prometheus:prometheus /var/lib/prometheus

Copy all the Prometheus files to the user binary directory and give permissions using this command below:

# sudo cp prometheus-files/prometheus /usr/local/bin/
# sudo cp prometheus-files/promtool /usr/local/bin/
# sudo chown prometheus:prometheus /usr/local/bin/prometheus
# sudo chown prometheus:prometheus /usr/local/bin/promtool
# sudo cp -r prometheus-files/consoles /etc/prometheus
# sudo cp -r prometheus-files/console_libraries /etc/prometheus
# sudo chown -R prometheus:prometheus /etc/prometheus/consoles
# sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries

Create the Prometheus yml file

# vi /etc/prometheus/prometheus.yml
global:
scrape_interval: 10s

scrape_configs:
– job_name: ‘prometheus’
scrape_interval: 5s
static_configs:
– targets: ['localhost:9187']

Change the ownership of yml file to Prometheus.

# chown prometheus.prometheus /etc/prometheus/prometheus.yml

Create and start the Prometheus service.

# vi /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
–config.file /etc/prometheus/prometheus.yml \
–storage.tsdb.path /var/lib/prometheus/ \
–web.console.templates=/etc/prometheus/consoles \
–web.console.libraries=/etc/prometheus/console_libraries

[Install]
WantedBy=multi-user.target

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

Umarım faydalı olmuştur beğenmeyi ve takip etmeyi unutmayın :)

--

--

No responses yet