为监控服务器CPU、内存、磁盘、I/O等信息,需要node_exporter,作用是用于机器系统数据收集。
- 安装 node_exporter
$ git clone https://github.com/prometheus/node_exporter.git
$ mv node_exporter-0.18.1.linux-amd64 /usr/local/prometheus/node_exporter
- 创建Systemd服务
$ vim /etc/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/prometheus/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
- 启动Node exporter,并使其在系统启动时每次启动。
$ systemctl start node_exporter
$ systemctl enable node_exporter
- 验证Node exporter是否启动成功
$ systemctl status node_exporter
● node_exporter.service - node_exporter
Loaded: loaded (/etc/systemd/system/node_exporter.service; disabled; vendor preset: enabled)
Active: active (running) since Wed 2019-07-17 15:10:26 CST; 10s ago
Main PID: 13085 (node_exporter)
Tasks: 3
Memory: 1.1M
CPU: 5ms
CGroup: /system.slice/node_exporter.service
└─13085 /usr/local/prometheus/node_exporter/node_exporter
- 修改prometheus.yml,加入下面的监控目标:
Node Exporter默认的抓取地址为http://IP:9100/metrics
$ vim /usr/local/prometheus/prometheus.yml
- job_name: 'linux'
static_configs:
- targets: ['localhost:9100']
labels:
instance: node1
prometheus.yml中一共定义了两个监控:一个是监控prometheus自身服务,另一个是监控Linux服务器。这里给个完整的示例:
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: 'linux'
static_configs:
- targets: ['localhost:9100']
labels:
instance: node1
- 重启Prometheus
$ systemctl restart prometheus
- 在Prometheus Web查看监控的目标
-
访问Prometheus Web,在Status->Targets页面下,我们可以看到我们配置的两个Target,它们的State为UP。
- 使用Prometheus Web来验证Node Exporter的数据已经被正确的采集。
-
查看当前主机的CPU负载情况
常用指令
- systemctl daemon-reload
- systemctl start node_exporter
- systemctl stop node_exporter
https://www.howtoing.com/how-to-install-prometheus-and-node-exporter-on-centos-7
网友评论