Prometheus监控Linux服务器(三)
一、使用node-exporter用来监控linux指标
node-exporter它是使用go语言编写的收集器
使用文档:https://prometheus.io/docs/guides/node-exporter/
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.0-rc.0/node_exporter-1.0.0-rc.0.linux-amd64.tar.gz tar xf node_exporter-1.0.0-rc.0.linux-amd64.tar.gz -C /usr/local/ ln -s /usr/local/node_exporter-1.0.0-rc.0.linux-amd64/ /usr/local/node_exporter # 可以直接执行node_exporter程序启动服务 /usr/local/node_exporter/node_exporter
二、使用systemd来管理node_exporter服务
# vim /usr/lib/systemd/system/node_exporter.service [Unit] Description=https://prometheus.io [Service] Restart=on-failure ExecStart=/usr/local/node_exporter/node_exporter [Install] WantedBy=multi-user.target # systemctl daemon-reload # systemctl start node_exporter.service # 启动服务后监听端口9100 # netstat -lntp | grep node_export tcp6 0 0 :::9100 :::* LISTEN 2986150/node_export
三、在prometheus服务端添加主机
前面已经配置了基于file_sd_configs的文件自动发现,所以添加完服务之后并不需要重启prometheus服务
[192-168-5-237 ~]# cd /usr/local/prometheus [192-168-5-237 prometheus]# vim sd_config/node.yml - targets: - 192.168.5.71:9100 labels: app: nginx [192-168-5-237 prometheus]# ./promtool check config prometheus.yml Checking prometheus.yml SUCCESS: 0 rule files found
在status中查看targets中能看到新添加的主机
四、promSQL获取CPU、内存、磁盘使用率(临时调试使用)
# 磁盘使用率 100 - (node_filesystem_free_bytes{mountpoint="/",fstype=~"ext4|xfs"} / node_filesystem_size_bytes{mountpoint="/",fstype=~"ext4|xfs"} * 100) # cpu使用率 100 - (avg(irate(node_cpu_seconds_total{mode="idle"}[5m])) by (instance) * 100) # 内存使用率 100 - (node_memory_MemFree_bytes+node_memory_Cached_bytes+node_memory_Buffers_bytes) / node_memory_MemTotal_bytes * 100
五、promSQL获取系统服务运行状态
5.1 查看node_exporter帮忙获取需要的参数选项
# ./node_exporter --help --collector.systemd # Enable the systemd collector (default: disabled). --collector.systemd.unit-whitelist=".+" # Regexp of systemd units to whitelist. Units must both match whitelist and not match blacklist to be included.
5.2 修改node_exporter服务启动参数(监控sshd和nginx服务)
# cat /usr/lib/systemd/system/node_exporter.service [Unit] Description=https://prometheus.io [Service] Restart=on-failure ExecStart=/usr/local/node_exporter/node_exporter --collector.systemd --collector.systemd.unit-whitelist=(sshd|nginx).service [Install] WantedBy=multi-user.target # systemctl daemon-reload # systemctl restart node_exporter.service
# ps aux | grep node
root 2993957 0.2 0.5 115760 10216 ? Ssl 20:46 0:00 /usr/local/node_exporter/node_exporter --collector.systemd --collector.systemd.unit-whitelist=(sshd|nginx).service
5.3 查看prometheus端是否成功
相关推荐
JackXuF 2020-09-06
RisenWang 2020-07-18
qdqht00 2020-06-11
wenwst 2020-06-07
BigDataMining 2020-06-02
地下库 2020-05-29
wenwst 2020-05-16
LCFlxfldy 2020-05-15
kuzilala 2020-05-14
luotuofeile 2020-04-17
bktest 2020-05-11
zhangmiao 2020-05-11
StupidBird00 2020-05-09
xcznb 2020-04-17
topswim 2020-04-09
yevvzi 2020-04-08
tangjianft 2020-03-05
guan000 2020-03-04