Monitoring Linux Server dengan Prometheus, Node Exporter, dan Grafana
- Caution
π Panduan hands-on untuk setup stack monitoring berbasis Prometheus. Kita akan pakai 2 VM berbasis Ubuntu: satu untuk Node Exporter, satu lagi untuk Prometheus + Grafana.
π₯οΈ Arsitektur Setup
Section titled βπ₯οΈ Arsitektur Setupβ- VM 1 (
vms-01, IP:192.168.1.7): Node Exporter - VM 2 (
vms-02, IP:192.168.1.8): Prometheus & Grafana
π§ Step 1 β Instalasi Node Exporter
Section titled βπ§ Step 1 β Instalasi Node ExporterβNode Exporter bertugas ngumpulin metrik hardware & OS, lalu dikirim ke Prometheus.
sudo useradd --no-create-home --shell /bin/false node_exporterwget https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz -P /mntcd /mnttar -zxvf node_exporter-1.6.1.linux-amd64.tar.gzcp node_exporter-1.6.1.linux-amd64/node_exporter /usr/local/binchown node_exporter:node_exporter /usr/local/bin/node_exporterBuat service:
[Unit]Description=Node ExporterWants=network-online.targetAfter=network-online.target
[Service]User=node_exporterGroup=node_exporterType=simpleExecStart=/usr/local/bin/node_exporter
[Install]WantedBy=multi-user.targetLalu aktifkan:
systemctl daemon-reloadsystemctl start node_exportersystemctl enable node_exporterCek di browser: http://192.168.1.7:9100/metrics
π¦ Step 2 β Instalasi Prometheus
Section titled βπ¦ Step 2 β Instalasi Prometheusβsudo useradd --no-create-home --shell /usr/sbin/nologin prometheuswget https://github.com/prometheus/prometheus/releases/download/v2.46.0/prometheus-2.46.0.linux-amd64.tar.gz -P /mntcd /mnttar -zxvf prometheus-2.46.0.linux-amd64.tar.gzcp prometheus-2.46.0.linux-amd64/{prometheus,promtool} /usr/local/bin/chown prometheus:prometheus /usr/local/bin/prom*
mkdir /etc/prometheuscp -r prometheus-2.46.0.linux-amd64/{consoles,console_libraries,prometheus.yml} /etc/prometheuschown -R prometheus:prometheus /etc/prometheusEdit /etc/prometheus/prometheus.yml:
scrape_configs: - job_name: "prometheus" static_configs: - targets: ["localhost:9090"]
- job_name: "node_exporter" static_configs: - targets: ["192.168.1.7:9100"]Service Prometheus:
[Unit]Description=Prometheus MonitoringWants=network-online.targetAfter=network-online.target
[Service]User=prometheusGroup=prometheusType=simpleExecStart=/usr/local/bin/prometheus \ --config.file /etc/prometheus/prometheus.yml \ --storage.tsdb.path /etc/prometheus/data/ \ --web.console.templates=/etc/prometheus/consoles \ --web.console.libraries=/etc/prometheus/console_libraries
[Install]WantedBy=multi-user.targetAktifkan:
systemctl daemon-reloadsystemctl start prometheussystemctl enable prometheusCek di browser: http://192.168.1.8:9090
π Step 3 β Instalasi Grafana
Section titled βπ Step 3 β Instalasi Grafanaβapt-get install -y apt-transport-https software-properties-common wgetwget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.keyecho "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.listapt-get update -yapt-get install grafana -y
systemctl start grafana-serversystemctl enable grafana-serverAkses http://192.168.1.8:3000 dengan:
- Username:
admin - Password:
admin
π§© Integrasi Grafana dengan Prometheus
Section titled βπ§© Integrasi Grafana dengan Prometheusβ- Menu
ConnectionsβData Sources - Pilih
Prometheusβ URL:http://192.168.1.8:9090 - Klik
Save & Test
π§ Dashboard
Section titled βπ§ DashboardβGunakan template dari: https://grafana.com/grafana/dashboards/10180
- Klik
NewβImport - Masukkan ID:
10180 - Pilih data source Prometheus β
Import
π Selesai! Sekarang lo punya observability stack yang keren dan open source!
Kalau lo nemu kendala pas setup, drop pertanyaan di komentar. Bisa juga kasih cerita chaos monitoring lo yang seru, siapa tau relate π