Grafana+prometheus+AlertManager+釘釘機器人

一.Grafana

(1)安裝Grafana的Linux環境

 在官網下載windows的Grafana的壓縮包到指定目錄,解壓縮Grafana壓縮文件到包含當前Grafana版本的文件夾。將該文件夾解壓縮到但願Grafana運行的任何位置。進入conf目錄中複製一份sample.ini,並將sample.ini更名爲custom.ini,打開文件custom.ini中,找到custom.ini中的http_port,將其取消註釋(.ini文件中的註釋爲 ; )端口號默認爲3000。php

         進入到 bin目錄下,經過執行 grafana-server.exe中的啓動Grafana(最好使用命令行啓動),若是須要將Grafana做爲windows服務進行,則下載NSSM,具體操做,博客:  https://www.jianshu.com/p/41b77a1eb7d3node

(2)開始練習操做Grafana

          首次進入Grafana的web頁面,localhost:3000,默認端口號爲3000,端口號能夠修改custom.ini中的http,默認登陸名密碼爲:admin/admin,進入後修改密碼。react

 二.操做流程:

    1.檢查服務器配置一個監控。(監控磁盤是否出問題)linux

            集羣由 node_exporter 進行監控內存、cpu、磁盤的狀況,能夠經過  ps aux |  grep node_exporter 來檢測是否有node_exporter 進程在運行,若是沒有則進行配置。web

            瞭解node_exporter的做用:windows

                 node-exporter用於採集服務器層面的運行指標,包括機器的loadavg、filesystem、meminfo等基礎監控安全

                node-exporter由prometheus官方提供、維護,不會捆綁安裝,但基本上是必備的exporter服務器

       2.若是沒有監控微信

        下載node_exporter架構

1.將node_exporter安裝到linux的/usr/local/node_exporter上
2.$ tar -zxvf 軟件壓縮包
   $ mv 軟件名  node_exporter
   $ cd node_exporter
   $ ./node_exporter &   #啓動node_exporter
3.訪問  ip:9000

 

prometheus

整個系統以prometheus爲核心,primetheus經過集成pushgateway、alertmanager、grafana、node_exporter來進行一系列的架構。下面爲總體的架構圖:

 

 

總體流程:
1.       Prometheus server 按期從配置好的 jobs 或者 exporters 中拉 metrics,或者接收來自 Pushgateway 發過來的 metrics,或者從其餘的 Prometheus server 中拉 metrics。
2.       Prometheus server 在本地存儲收集到的 metrics,並運行已定義好的 alert.rules,記錄新的時間序列或者向 Alertmanager 推送警報。
3.       Alertmanager 根據配置文件,對接收到的警報進行處理,發出告警。
4.       在圖形界面中(使用grafana),可視化採集數據 

 

Alertmanager

在Prometheus Server中支持基於PromQL建立告警規則,若是知足PromQL定義的規則,則會產生一條告警,而告警的後續處理流程則由AlertManager進行管理。在AlertManager中咱們能夠與郵件,Slack等等內置的通知方式進行集成,也能夠經過Webhook自定義告警處理方式。AlertManager即Prometheus體系中的告警處理中心。
Alertmanager主要負責對Prometheus產生的告警進行統一處理,所以在Alertmanager配置中通常會包含如下幾個主要部分:
  • 全局配置(global):用於定義一些全局的公共參數,如全局的SMTP配置,Slack配置等內容;
  • 模板(templates):用於定義告警通知時的模板,如HTML模板,郵件模板等;
  • 告警路由(route):根據標籤匹配,肯定當前告警應該如何處理;
  • 接收人(receivers):接收人是一個抽象的概念,它能夠是一個郵箱也能夠是微信,Slack或者Webhook等,接收人通常配合告警路由使用;
  • 抑制規則(inhibit_rules):合理設置抑制規則能夠減小垃圾告警的產生

釘釘機器人

建立釘釘機器人
       1.得到釘釘機器人的webhook,配置安全設置:自定義關鍵詞
       2.建立webhook服務
       3.在alertmanager中添加webhook的url
webhook_configs:
  - url: http://------ip----:8080/webhook

 

監控指標

CPU使用狀況

- alert: Bigdata_CPU
    #告警規則
   expr: 100-(avg(irate(node_cpu_seconds_total{ mode= "idle" }[5m])) by(instance)* 100) > 80
   for : 1m
   labels:
     token: {{ .Values.prometheus.prometheusSpec.externalLabels.env }}-bigdata
     priority: P0
     status: 告警
   #告警內容
   annotations:                    
     content:  "大數據告警:IPadress:{{`{{$labels.instance}}`}} CPU使用大於80%(目前使用:{{`{{$value}}`}}%)"
     title:  "大數據告警:CPU使用大於80%(目前使用:{{`{{$value}}`}}%)"

內存使用狀況

- alert: Bigdata_Memory
  expr: 100 - ((node_memory_MemAvailable_bytes  * 100) / node_memory_MemTotal_bytes ) > 80
  for : 1m
  labels:
    token: {{ .Values.prometheus.prometheusSpec.externalLabels.env }}-bigdata
    priority: P0
    status: 告警
  annotations:
    content:  "大數據告警:IPaddress:{{`{{$labels.instance}}`}} 內存使用大於80%(目前使用:{{`{{$value}}`}}%)!"
    title:  "大數據告警:內存使用大於80%(目前使用:{{`{{$value}}`}}%)"

磁盤使用狀況

系統盤

- alert: Bigdata_System_Disk
  expr: 100 - ((node_filesystem_avail_bytes{ mountpoint= "/" ,fstype!= "rootfs" } * 100) / node_filesystem_size_bytes{ mountpoint= "/" ,fstype!= "rootfs" }) > 90
  for : 1m
  labels:
    token: {{ .Values.prometheus.prometheusSpec.externalLabels.env }}-bigdata
    priority: P0
    status: 告警
  annotations:
    content:  "大數據告警:IPadress:{{`{{$labels.instance}}`}},device:{{`{{$labels.device}}`}},mount:{{`{{$labels.mountpoint}}`}} 磁盤分區使用量大於90%(目前使用:{{`{{$value}}`}}%)!"
    title:  "大數據告警:{{`{{$labels.mountpoint}}`}} 磁盤分區使用大於90%(目前使用:{{`{{$value}}`}}%)"

數據盤

- alert: Bigdata_Data_Disk
   expr: 100 - ((node_filesystem_avail_bytes{ device!~ 'rootfs' ,mountpoint=~ "/mnt/.*" } * 100) / node_filesystem_size_bytes{ device!~ 'rootfs' ,mountpoint=~ "/mnt/.*" }) > 80
   for : 1m
   labels:
     token: {{ .Values.prometheus.prometheusSpec.externalLabels.env }}-bigdata
     priority: P0
     status: 告警
   annotations:
     content:  "大數據告警:IPadress:{{`{{$labels.instance}}`}},device:{{`{{$labels.device}}`}},mount:{{`{{$labels.mountpoint}}`}} 磁盤分區使用大於80%(目前使用:{{`{{$value}}`}}%)"
     title:  "大數據告警:{{`{{$labels.mountpoint}}`}} 磁盤分區使用大於80%(目前使用:{{`{{$value}}`}}%)"
相關文章
相關標籤/搜索