Cara Install Prometheus untuk System Monitoring di Ubuntu 18.04

Prometheus adalah open source system monitoring dan alerting toolkit yang awalnya dikembangkan oleh SoundCloud. Prometheus bergabung dengan Cloud Native Computing Foundation pada tahun 2016. Prometheus memiliki banyak metric (pengukuran) yang dibutuhkan untuk memantau system dan dapat dikombinasikan dengan Grafana untuk visualisasi.

*0.Membuat User*

Membuat user untuk prometheus dan node_exporter.

[INPUT]

1 2 useradd –no-create-home –shell /bin/false prometheus useradd –no-create-home –shell /bin/false node_exporter

Membuat folder prometheus.

[INPUT]

1 2 mkdir /etc/prometheus mkdir /var/lib/prometheus

Set user dan group ownership folder.

[INPUT]

1 2 chown prometheus:prometheus /etc/prometheus chown prometheus:prometheus /var/lib/prometheus

*1.Download Prometheus*

Download dan extract prometheus.

[INPUT]

1 2 curl -LO https://github.com/prometheus/prometheus/releases/download/v2.17.1/prometheus-2.17.1.linux-amd64.tar.gz tar xzvf prometheus-2.17.1.linux-amd64.tar.gz

Copy folder prometheus dan promtool.

[INPUT]

1 2 cp prometheus-2.17.1.linux-amd64/prometheus /usr/local/bin cp prometheus-2.17.1.linux-amd64/promtool /usr/local/bin

Set user dan group ownership untuk prometheus dan promtool.

[INPUT]

1 2 chown prometheus:prometheus /usr/local/bin/prometheus chown prometheus:prometheus /usr/local/bin/promtool

Copy folder consoles dan console_libraries.

[INPUT]

1 2 cp -r prometheus-2.17.1.linux-amd64/consoles /etc/prometheus cp -r prometheus-2.17.1.linux-amd64/console_libraries /etc/prometheus

Set user dan group ownership folder consoles dan console_libraries.

[INPUT]

1 2 chown -R prometheus:prometheus /etc/prometheus/consoles chown -R prometheus:prometheus /etc/prometheus/console_libraries

*2.Konfigurasi Prometheus*

Membuat file konfigurasi untuk prometheus.

[INPUT]

1 nano /etc/prometheus/prometheus.yml

Isi dari prometheus.yml. Di target masukkan IP address server.

[INPUT]

1 2 3 4 5 6 7 global:   scrape_interval: 15s scrape_configs:   – job_name: ‘prometheus’     scrape_interval: 5s     static_configs:       – targets: [‘45.77.252.94:9090’]    

Set user dan group ownership prometheus.yml

[INPUT]

1 chown prometheus:prometheus /etc/prometheus/prometheus.yml

*3.Prometheus Service*

Membuat service untuk prometheus.

[INPUT]

1 nano /etc/systemd/system/prometheus.service

Isi dari file prometheus.service.

[INPUT]

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [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  

Aktifkan prometheus service.

[INPUT]

1 2 3 4 systemctl daemon-reload systemctl enable prometheus systemctl start prometheus systemctl status prometheus

*4.Download Node Exporter*

Download dan extract Node Exporter.

[INPUT]

1 2 curl -LO https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz tar xzvf node_exporter-0.18.1.linux-amd64.tar.gz

Copy node_exporter. Set user dan group ownership node_exporter.

[INPUT]

1 2 cp node_exporter-0.18.1.linux-amd64/node_exporter /usr/local/bin chown node_exporter:node_exporter /usr/local/bin/node_exporter

*5.Node Exporter Service*

Membuat service untuk node_exporter.

[INPUT]

1 nano /etc/systemd/system/node_exporter.service

Isi dari file node_exporter.service.

[INPUT]

1 2 3 4 5 6 7 8 9 10 11 12 13 [Unit] Description=Node Exporter Wants=network-online.target After=network-online.target   [Service] User=node_exporter Group=node_exporter Type=simple ExecStart=/usr/local/bin/node_exporter   [Install] WantedBy=multi-user.target  

Aktifkan node_exporter service.

[INPUT]

1 2 3 4 systemctl daemon-reload systemctl enable node_exporter systemctl start node_exporter systemctl status node_exporter

*6.Konfigurasi Prometheus untuk Node Exporter*

Membuka file konfigurasi prometheus.yml.

[INPUT]

1 nano /etc/prometheus/prometheus.yml

Tambahkan job untuk node_exporter.

[INPUT]

1 2 3 4   – job_name: ‘node_exporter’     scrape_interval: 5s     static_configs:       – targets: [‘45.77.252.94:9100’]  

Hasil akhir file prometheus.yml.

[INPUT]

1 2 3 4 5 6 7 8 9 10 11 global:   scrape_interval: 15s scrape_configs:   – job_name: ‘prometheus’     scrape_interval: 5s     static_configs:       – targets: [‘45.77.252.94:9090’]   – job_name: ‘node_exporter’     scrape_interval: 5s     static_configs:       – targets: [‘45.77.252.94:9100’]

Restart prometheus.

[INPUT]

1 2 systemctl restart prometheus systemctl status prometheus

*7.Menambahkan Node Exporter*

Prometheus dapat mengakses metric yang berada di server lain yang telah terpasang Node Exporter dengan cara menambahkan IP address di konfigurasi prometheus.yml. IP address dipasang di bagian *job_name: ‘node_exporter’ – targets*.

[INPUT]

1 2 3 4 5 6 7 8 9 10 11 global:   scrape_interval: 15s scrape_configs:   – job_name: ‘prometheus’     scrape_interval: 5s     static_configs:       – targets: [‘45.77.252.94:9090’]   – job_name: ‘node_exporter’     scrape_interval: 5s     static_configs:       – targets: [‘45.77.252.94:9100’, ‘IP_ADDR#2:9100’, ‘IP_ADDR#3:9100’]  

*8.Mengakses Prometheus*

Browse *http://SERVER-IP:9100/metrics* untuk melihat query metric apa saja yang bisa dijalankan.

Metric

Browse *http://SERVER-IP:9090/graph* untuk menjalankan query metric dan memvisualisasikannya ke dalam bentuk grafik. Masukkan *Expression*, lalu klik tombol *Execute* untuk menjalankan query metric, dan klik tab *Graph* untuk menampilkan hasil query ke dalam bentuk grafik.

Prometheus Graph

*Contoh query* Total memory.

[INPUT]

1 node_memory_MemTotal_bytes{instance=”45.77.252.94:9100″,job=”node_exporter”}

Memory yang tersisa.

[INPUT]

1 node_memory_MemAvailable_bytes{instance=”45.77.252.94:9100″,job=”node_exporter”}    

Free space di partisi /.

[INPUT]

1 node_filesystem_avail_bytes{device=”/dev/vda1″,fstype=”ext4″,instance=”45.77.252.94:9100″,job=”node_exporter”,mountpoint=”/”}  

Selamat mencoba 🙂

Leave a Reply

Your email address will not be published.