zoukankan      html  css  js  c++  java
  • 监控报警Prometheus

    监控服务器CPU、内存、磁盘、I/O等信息,首先需要安装node_exporter。

    node_exporter的作用是用于机器系统数据收集。

    Prometheus可以从Kubernetes集群的各个组件中采集数据,比如kubelet中自带的cadvisor,api-server等,而node-export就是其中一种来源

    Exporter是Prometheus的一类数据采集组件的总称。它负责从目标处搜集数据,并将其转化为Prometheus支持的格式。与传统的数据采集组件不同的是,它并不向中央服务器发送数据,而是等待中央服务器主动前来抓取,默认的抓取地址为http://CURRENT_IP:9100/metrics

    node-exporter用于采集服务器层面的运行指标,包括机器的loadavg、filesystem、meminfo等基础监控,类似于传统主机监控维度的zabbix-agent

    node-export由prometheus官方提供、维护,不会捆绑安装,但基本上是必备的exporter

    参考:

    https://www.jianshu.com/p/e3c9fc929d8a

    Node Exporter默认的抓取地址为http://IP:9100/metrics

    配置prometheus

    vim  /usr/local/prometheus/prometheus.yml
    
      - job_name: 'linux'
        static_configs:
          - targets: ['localhost:9100']
            labels:
              instance: node1
    

    prometheus.yml中一共定义了两个监控:一个是监控prometheus自身服务,另一个是监控Linux服务器。这里给个完整的示例:

    scrape_configs:
    
      - job_name: 'prometheus'
        static_configs:
          - targets: ['localhost:9090']
    
      - job_name: 'linux'
        static_configs:
          - targets: ['NODE_IP:9100']
            labels:
              instance: node1


    重启Prometheus

    systemctl restart prometheus
    

    访问Prometheus Web,在Status->Targets页面下,我们可以看到我们配置的两个Target,它们的State为UP。

    Prometheus针对nodes告警规则配置
    groups:
    - name: example
      rules:
     
      - alert: 实例丢失
        expr: up{job="node-exporter"} == 0
        for: 1m
        labels:
          severity: page
        annotations:
          summary: "服务器实例 {{ $labels.instance }} 丢失"
          description: "{{ $labels.instance }} 上的任务 {{ $labels.job }} 已经停止了 1 分钟已上了"
     
      - alert: 磁盘容量小于 5%
        expr: 100 - ((node_filesystem_avail_bytes{job="node-exporter",mountpoint=~".*",fstype=~"ext4|xfs|ext2|ext3"} * 100) / node_filesystem_size_bytes {job="node-exporter",mountpoint=~".*",fstype=~"ext4|xfs|ext2|ext3"}) > 95
        for: 30s
        annotations:
          summary: "服务器实例 {{ $labels.instance }} 磁盘不足 告警通知"
          description: "{{ $labels.instance }}磁盘 {{ $labels.device }} 资源 已不足 5%, 当前值: {{ $value }}"
     
      - alert: "内存容量小于 20%"
        expr: ((node_memory_MemTotal_bytes - node_memory_MemFree_bytes - node_memory_Buffers_bytes - node_memory_Cached_bytes) / (node_memory_MemTotal_bytes )) * 100 > 80
        for: 30s
        labels:
          severity: warning
        annotations:
          summary: "服务器实例 {{ $labels.instance }} 内存不足 告警通知"
          description: "{{ $labels.instance }}内存资源已不足 20%,当前值: {{ $value }}"
     
      - alert: "CPU 平均负载大于 4 个"
        expr: node_load5 > 4
        for: 30s
        annotations:
          sumary: "服务器实例 {{ $labels.instance }} CPU 负载 告警通知"
          description: "{{ $labels.instance }}CPU 平均负载(5 分钟) 已超过 4 ,当前值: {{ $value }}"
     
      - alert: "磁盘读 I/O 超过 30MB/s"
        expr: irate(node_disk_read_bytes_total{device="sda"}[1m]) > 30000000
        for: 30s
        annotations:
          sumary: "服务器实例 {{ $labels.instance }} I/O 读负载 告警通知"
          description: "{{ $labels.instance }}I/O 每分钟读已超过 30MB/s,当前值: {{ $value }}"
     
      - alert: "磁盘写 I/O 超过 30MB/s"
        expr: irate(node_disk_written_bytes_total{device="sda"}[1m]) > 30000000
        for: 30s
        annotations:
          sumary: "服务器实例 {{ $labels.instance }} I/O 写负载 告警通知"
          description: "{{ $labels.instance }}I/O 每分钟写已超过 30MB/s,当前值: {{ $value }}"
     
      - alert: "网卡流出速率大于 10MB/s"
        expr: (irate(node_network_transmit_bytes_total{device!~"lo"}[1m]) / 1000) > 1000000
        for: 30s
        annotations:
          sumary: "服务器实例 {{ $labels.instance }} 网卡流量负载 告警通知"
          description: "{{ $labels.instance }}网卡 {{ $labels.device }} 流量已经超过 10MB/s, 当前值: {{ $value }}"
     
      - alert: "CPU 使用率大于 90%"
        expr: 100 - ((avg by (instance,job,env)(irate(node_cpu_seconds_total{mode="idle"}[30s]))) *100) > 90
        for: 30s
        annotations:
          sumary: "服务器实例 {{ $labels.instance }} CPU 使用率 告警通知"
          description: "{{ $labels.instance }}CPU 使用率已超过 90%, 当前值: {{ $value }}"


     
     
     
     
     
     
     
  • 相关阅读:
    android studio的lib和jniLibs
    Android Broadcast Receive
    上周热点回顾(7.18-7.24)团队
    上周热点回顾(7.11-7.17)团队
    .NET跨平台之旅:在生产环境中上线第一个运行于Linux上的ASP.NET Core站点团队
    上周热点回顾(7.4-7.10)团队
    上周热点回顾(6.27-7.3)团队
    .NET跨平台之旅:将示例站点升级至ASP.NET Core 1.0团队
    上周热点回顾(6.20-6.26)团队
    上周热点回顾(6.13-6.19)团队
  • 原文地址:https://www.cnblogs.com/zccst/p/14555775.html
Copyright © 2011-2022 走看看