Prometheus+grafana監控linux性能指標

監控linux主機

  • 1.下載並解壓node-exporter(在每個需要監控的linux服務器上)
wget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz
# 或者直接下載好拖進去就行
# 在data下创建目录
mkdir node_exporter
tar -zxvf node_exporter-1.8.2.linux-amd64.tar.gz -C /data/node_exporter
# 解壓:到/data下
tar -zxvf node_exporter-1.8.2.linux-amd64.tar.gz -C /data/node_exporter
  • 2.配置開機自啟node-exporter服務(注意根據情況修改ExecStart)
vi /etc/systemd/system/node_exporter.service

[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
User=root
Group=root
ExecStart=/data/node_exporter/node_exporter-1.8.2.linux-amd64/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target

# 檢驗防火墻、SELINUX協議有無關閉,會影響腳本的啟動
systemctl status firewalld
getenforce
setenforce 0

# 永久关闭(√)
vi /etc/selinux/config 

将 SELINUX=enforcing 修改为 SELINUX=disabled
# 重启系统
reboot
systemctl daemon-reload
systemctl start node_exporter.service
systemctl enable node_exporter.service
systemctl status node_exporter.service
  • 3.查看暴露端口
curl http://localhost:9100/metrics
or: 
http://localhost:9100/metrics
  • 4.prometheus 配置prometheus.yml,目前配置的是(prometheus:10.xxx.xxx.xxx)
  # Linux 服务器 监控
  - job_name: node_exporter
    metrics_path: '/metrics'
    static_configs:
    # 添加多个服务器节点
      - targets: ['ip1:9100','ip2:9100','ip3:9100',,,,]
  • 5.配置告警規則
cd /data/prometheus/
mkdir rules
cd rules
vi node-exporter_rules.yml
# 輸入下面內容:
groups:
    - name: 主机状态-监控告警
      rules:
      - alert: 主机状态
        expr: up{job=~".*node_exporter"} == 0
        for: 0m
        labels:
          status: 非常严重
        annotations:
          summary: "{{$labels.instance}}:服务器延时超过5分钟"
          description: "{{$labels.instance}}:服务器宕機,請注意排查原因!"
    
      - alert: CPU使用情况
        expr: 100-(avg(irate(node_cpu_seconds_total{mode="idle"}[5m])) by(instance)* 100) > 60
        for: 1m
        labels:
          status: 一般告警
        annotations:
          summary: "{{$labels.mountpoint}} CPU使用率过高!"
          description: "{{$labels.mountpoint }} CPU使用大于60%(目前使用:{{$value}}%)"

	- alert: 内存使用
    	expr: (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100 < 10) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}
    	for: 2m
    	labels:
      	severity: 严重告警
    	annotations:
      		summary: 主机内存不足 (instance {{ $labels.instance }})
      		description: "節點内存正在填满 (< 10% left)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

      - alert: IO性能
        expr: 100-(avg(irate(node_disk_io_time_seconds_total[1m])) by(instance)* 100) < 60
        for: 1m
        labels:
          status: 严重告警
        annotations:
          summary: "{{$labels.mountpoint}} 流入磁盘IO使用率过高!"
          description: "{{$labels.mountpoint }} 流入磁盘IO大于60%(目前使用:{{$value}})"
 
      - alert: 带宽流入过高
        expr: ((sum(rate (node_network_receive_bytes_total{device!~'tap.*|veth.*|br.*|docker.*|virbr*|lo*'}[5m])) by (instance)) / 100) > 102400
        for: 1m
        labels:
          status: 严重告警
        annotations:
          summary: "{{$labels.mountpoint}} 流入网络带宽过高!"
          description: "{{$labels.mountpoint }}流入网络带宽持续2分钟高于100M. RX带宽使用率{{$value}}"
 
      - alert: 带宽流出过高
        expr: ((sum(rate (node_network_transmit_bytes_total{device!~'tap.*|veth.*|br.*|docker.*|virbr*|lo*'}[5m])) by (instance)) / 100) > 102400
        for: 1m
        labels:
          status: 严重告警
        annotations:
          summary: "{{$labels.mountpoint}} 流出网络带宽过高!"
          description: "{{$labels.mountpoint }}流出网络带宽持续2分钟高于100M. RX带宽使用率{{$value}}"
    
      - alert: TCP会话
        expr: node_netstat_Tcp_CurrEstab > 1000
        for: 1m
        labels:
          status: 严重告警
        annotations:
          summary: "{{$labels.mountpoint}} TCP_ESTABLISHED过高!"
          description: "{{$labels.mountpoint }} TCP_ESTABLISHED大于1000%(目前使用:{{$value}}%)"
 
      - alert: 磁盘容量
        expr: 100-(node_filesystem_free_bytes{fstype=~"ext4|xfs"}/node_filesystem_size_bytes {fstype=~"ext4|xfs"}*100) > 80
        for: 1m
        labels:
          status: 严重告警
        annotations:
          summary: "{{$labels.mountpoint}} 磁盘分区使用率过高!"
          description: "{{$labels.mountpoint }} 磁盘分区使用大于80%(目前使用:{{$value}}%)"
  • 6.在pometheus.yml中配置rules規則
- "/data/prometheus/rules/node-exporter_rules.yml"
  • 7.熱加載prometheus、alertmanager
curl -X POST http://localhost:9090/-/reload
curl -X POST http://localhost:9093/-/reload
  • 8.配置grafana 出图

https://grafana.com/grafana/dashboards/?search=linux
12633/12632/8919

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值