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
posted @ 2019-12-11 16:44  烟雨浮华  阅读(2038)  评论(0编辑  收藏