Prometheus學習筆記(3)什么是node_exporter???


Node_exporter安裝配置啟動

node_exporter安裝在被監控端,安裝方式也比較簡單,直接下載解壓安裝即可,默認啟動后監聽9100端口。

# 下載
[root@node02 ~]# wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz

# 二進制解壓式安裝
[root@node02 ~]# tar -zxf node_exporter-0.18.1.linux-amd64.tar.gz -C /usr/local/
[root@node02 ~]# mv /usr/local/node_exporter-0.18.1.linux-amd64 /usr/local/node_exporter-0.18.1
[root@node02 ~]# ln -sv /usr/local/node_exporter-0.18.1 /usr/local/node_exporter

# 啟動
[root@node02 ~]# cd /usr/local/node_exporter
[root@node02 node_exporter]# ./node_exporter &
[root@node02 node_exporter]# netstat -tulnp |grep 9100
tcp6       0      0 :::9100                 :::*                    LISTEN      6433/./node_exporte 

node_exporter默認監聽9100端口,在服務端增加被監控的目標主機,即可通過客戶端的node_exporter采集數據,如下:

[root@prometheus prometheus]# cat prometheus.yml 
global:
  scrape_interval:     15s 
  evaluation_interval: 15s 
  external_labels:
    monitor: 'codelab-monitor'

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
    - targets: ['localhost:9090','192.168.0.128:9100']    #目標targets是一個列表,用逗號分隔,添加目標監控主機的ip和端口,也可以通過主機名,但是需要在hosts進行解析

重啟prometheus后生效!!!

可以通過訪問目標主機的ip+端口進行獲取數據測試,如下:

[root@prometheus ~]# curl 192.168.0.128:9100/metrics    # 可以看到一系列的系統指標,如cpu的1,5,15分鍾的負載值
...
# HELP node_load1 1m load average.
# TYPE node_load1 gauge
node_load1 0.08
# HELP node_load15 15m load average.
# TYPE node_load15 gauge
node_load15 0.05
# HELP node_load5 5m load average.
# TYPE node_load5 gauge
node_load5 0.04
# HELP node_memory_Active_anon_bytes Memory information field Active_anon_bytes.
# TYPE node_memory_Active_anon_bytes gauge
node_memory_Active_anon_bytes 2.45653504e+08
# HELP node_memory_Active_bytes Memory information field Active_bytes.
# TYPE node_memory_Active_bytes gauge
node_memory_Active_bytes 3.42388736e+08
...

在Prometheus的web端可以通過192.168.0.143/graph上的查詢搜索框進行查詢對應監控節點的負載值,如圖:

同理,默認沒有守護進程管理node_exporter,實在太麻煩了,來一份node_exporter.service,安排!!!

[root@node02 ~]# vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/docs/introduction/overview
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=simple
PIDFile==/var/run/node_exporter.pid
ExecStart=/usr/local/node_exporter/node_exporter
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target
[root@node02 ~]# systemctl daemon-reload
[root@node02 ~]# systemctl start node_exporter
[root@node02 ~]# ps -ef |grep node_exporter
root     15574     1  7 16:49 ?        00:00:00 /usr/local/node_exporter/node_exporter
root     15578  6373  0 16:49 pts/0    00:00:00 grep --color=auto node_exporter
[root@node02 ~]# netstat -tulnp |grep 9100
tcp6       0      0 :::9100                 :::*                    LISTEN      15574/node_exporter 
[root@node02 ~]# systemctl restart node_exporter


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM