Cara Membuat Monitoring Server menggunakan Node Exporter , Prometheus dan Grafana - DevOps

image

Berikut adalah cara membuat Monitoring Server menggunakan Node Exporter , Prometheus dan Grafana di Linux.

Install Node Exporter

  • Link Download Node Exporter
  1. buka link : https://prometheus.io/download#node_exporter
  2. kemudian pilih yang berformat tar dan pilih sesuai sistem operasi , contohnya linux/amd64
    1
    wget url
  • Extract Node Exporter

    1
    tar xvfz node_exporter-*.*-amd64.tar.gz
  • Copy Node Exporter

    1
    2
    3
    cd node_exporter
    cp node_exporter /usr/local/bin/

  • Buat Service Node Exporter dengan cara menjalankan perintah dibawah ini.

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

    isi dengan code berikut :

    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=root
    Group=root
    Type=simple
    ExecStart=/usr/local/bin/node_exporter

    [Install]
    WantedBy=multi-user.target
Screenshot-2023-01-11-13-33-11-1920x2160
  • Jalankan Service Node Exporter

    1
    sudo systemctl start node_exporter
  • Aktifkan service node_exporter agar tetap jalan ketika di restart

    1
    sudo systemctl enable node_exporter
  • Buka Service menggunakan browser

  1. ketik url dengan ip address server , contohnya http://localhost:9100
  2. port node_exporter : 9100
  • Tampilan node_exporter didalam browser
Screenshot-2023-01-11-13-06-17-1920x2160

Install Prometheus ( docker )

image
  • Pull docker image

    1
    sudo docker pull prom/prometheus
  • Jalankan docker container

    1
    sudo docker run -d --name prometheus --restart always --net host /etc/localtime:/etc/localtime:ro prom/prometheus
  • config prometheus.yml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    # 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:
    # - alertmanager:9093

    # 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:
    # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
    - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ["localhost:9090"]
    - job_name: "node_exporter"
    static_configs:
    - targets: ["localhost:9100"]
  • copy config diatas menggunakan perintah berikut di dalam terminal

    1
    sudo docker exec -ti prometheus vi /etc/prometheus/prometheus.yml
  • hapus semua isinya dan ganti dengan config diatas

Screenshot-2023-01-11-13-34-11-1920x2160
  • Buka service menggunakan browser
  1. port default promotheus : 9090
  2. url : http://localhost:9090
  • Buka menu targets maka dan harusnya akan muncul 2 targets yaitu node_exporter dan promotheus seperti ini.
image

Install Grafana ( docker )

image
  • Pull docker image

    1
    sudo docker pull grafana/grafana
  • Jalankan docker container

    1
    sudo docker run -d --name grafana --net host grafana/grafana
  • Buka service menggunakan browser

  1. grafana default port : 3000
  2. url : http://localhost:3000
  3. user : admin
  4. pass : admin
    Screenshot-2023-01-11-13-18-34-1920x2160
    Screenshot-2023-01-11-13-18-53-1920x2160
  • Aktifkan Data Source di Configuration Datasource dan Pilih promotheus
Screenshot-2023-01-11-13-10-00-1920x2160
  • Masukan url promotheus
    Screenshot-2023-01-11-13-17-01-1920x2160
  • Pilih Service Promotheus
    Screenshot-2023-01-11-13-17-12-1920x2160
    Screenshot-2023-01-11-13-17-23-1920x2160
  • Pilih menu dashboard kemudian pilih Import
    Screenshot-2023-01-11-13-17-47-1920x2160
  • Import tampilan Dashboard dengan ID 11074
    Screenshot-2023-01-11-13-18-09-1920x2160
  • Buka dashboard yang sudah di import tadi dan akan tampil seperti ini.


Screenshot-2023-01-11-13-19-17-1920x2160

Screenshot-2023-01-11-13-30-47-1920x2160

Screenshot-2023-01-11-13-31-45-1920x2160