欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Prometheus 整合 AlertManager的教程詳解

 更新時間:2019年07月30日 09:29:01   作者:程序員果果  
Alertmanager 主要用于接收 Prometheus 發(fā)送的告警信息,它很容易做到告警信息的去重,降噪,分組,策略路由,是一款前衛(wèi)的告警通知系統(tǒng)。這篇文章主要介紹了Prometheus 整合 AlertManager的教程 ,需要的朋友可以參考下

簡介

Alertmanager 主要用于接收 Prometheus 發(fā)送的告警信息,它很容易做到告警信息的去重,降噪,分組,策略路由,是一款前衛(wèi)的告警通知系統(tǒng)。它支持豐富的告警通知渠道,可以將告警信息轉(zhuǎn)發(fā)到郵箱、企業(yè)微信、釘釘?shù)取_@一節(jié)講解利用AlertManager,把接受到的告警信息,轉(zhuǎn)發(fā)到郵箱。

實驗

準備

啟動 http-simulator 度量模擬器:

docker run --name http-simulator -d -p 8080:8080 pierrevincent/prom-http-simulator:0.1

啟動 Prometheus,為了方便更新配置,使用掛載配置文件的方式:

docker run --name prometheus -d -p 9090:9090 -v /Users/huanchu/Documents/prometheus-data:/prometheus-data \
  prom/prometheus --web.enable-lifecycle --config.file=/prometheus-data/prometheus.yml

啟動添加了參數(shù) --web.enable-lifecycle,讓Prometheus支持通過web端點動態(tài)更新配置。

訪問http://127.0.0.1:9090/targets ,Prometheus 自身的 metrics 和 http-simulator 的 metrics 處于up 狀態(tài) ,那么準備工作就做好了。

實驗

實驗1

告警配置

在prometheus-data文件夾下,創(chuàng)建告警配置文件 simulator_alert_rules.yml:

groups:
- name: simulator-alert-rule
 rules:
 - alert: HttpSimulatorDown
 expr: sum(up{job="http-simulator"}) == 0
 for: 1m
 labels:
  severity: critical

配置文件的意思是 http-simulator 服務(wù)up狀態(tài)為 0 ,并且持續(xù)1分鐘時,產(chǎn)生告警 ,級別為 “嚴重的”。

修改prometheus.yml,引用simulator_alert_rules.yml文件,prometheus.yml 內(nèi)容如下:

global:
 scrape_interval: 5s
 evaluation_interval: 5s
 scrape_timeout: 5s
rule_files:
 - "simulator_alert_rules.yml"
scrape_configs:
 - job_name: 'prometheus'
 static_configs:
 - targets: ['localhost:9090']
 - job_name: 'http-simulator'
 metrics_path: /metrics
 static_configs:
 - targets: ['192.168.43.121:8080']

更新Prometheus配置:

curl -X POST http://localhost:9090/-/reload

訪問http://127.0.0.1:9090/config,可以看到已經(jīng)為更新了配置:

訪問http://127.0.0.1:9090/rules,Rules 下出現(xiàn)了新添加的告警規(guī)則:

驗證

訪問http://127.0.0.1:9090/alerts ,Alerts 下 HttpSimulatorDown 為綠色,處于INACTIVE 狀態(tài),表示什么都沒有發(fā)生。

關(guān)閉 http-simulator 服務(wù):

docker stop http-simulator

訪問http://127.0.0.1:9090/alerts,HttpSimulatorDown 變成黃色,處于 PENDING 狀態(tài),表示報警即將被激活。

一分鐘后,HttpSimulatorDown 變成紅色,處于 FIRING 狀態(tài),表示報警已經(jīng)被激活了。

實驗2

告警配置

在simulator_alert_rules.yml文件中增加告警配置:

- alert: ErrorRateHigh
 expr: sum(rate(http_requests_total{job="http-simulator", status="500"}[5m])) / sum(rate(http_requests_total{job="http-simulator"}[5m])) > 0.02
 for: 1m
 labels:
  severity: major
 annotations:
  summary: "High Error Rate detected"
  description: "Error Rate is above 2% (current value is: {{ $value }}"

配置文件的意思是 http-simulator 請求的錯誤率對2% ,并且持續(xù)1分鐘時,產(chǎn)生告警 ,級別為 “非常嚴重的”

更新Prometheus配置:

curl -X POST http://localhost:9090/-/reload

驗證

訪問http://127.0.0.1:9090/alerts,ErrorRateHigh 為綠色的 INACTIVE 狀態(tài)。

把 http-simulator 的錯誤率調(diào)到 10%

curl -H 'Content-Type: application/json' -X PUT -d '{"error_rate": 10}' http://localhost:8080/error_rate

稍等一會后,訪問http://127.0.0.1:9090/alerts, 可以看到錯誤率已經(jīng)大2%,ErrorRateHigh 為紅色的 FIRING 狀態(tài),報警已經(jīng)被激活了。

安裝和配置AlertManager

通過docker 掛載文件的方式安裝AlertManager,在本地創(chuàng)建文件夾 alertmanager-data 文件夾,在其中創(chuàng)建 alertmanager.yml,內(nèi)容如下:

global:
 smtp_smarthost: 'smtp.163.com:25'
 smtp_from: 'xxxxx@163.com'
 smtp_auth_username: 'xxxxx@163.com'
 smtp_auth_password: 'xxxxx'

route:
 group_interval: 1m #當?shù)谝粋€報警發(fā)送后,等待'group_interval'時間來發(fā)送新的一組報警信息
 repeat_interval: 1m # 如果一個報警信息已經(jīng)發(fā)送成功了,等待'repeat_interval'時間來重新發(fā)送他們
 receiver: 'mail-receiver'
receivers:
- name: 'mail-receiver'
 email_configs:
 - to: 'xxxxxx@163.com' 

啟動 AlertManager:

docker run --name alertmanager -d -p 9093:9093 -v /Users/huanchu/Documents/alertmanager-data:/alertmanager-data \
  prom/alertmanager --config.file=/alertmanager-data/alertmanager.yml

在Prometheus目錄下,修改prometheus.yml配置Alertmanager地址:

# Alertmanager configuration
alerting:
 alertmanagers:
 - static_configs:
 - targets:
  - 192.168.43.121:9093

更新Prometheus配置:

curl -X POST http://localhost:9090/-/reload

訪問http://127.0.0.1:9093,訪問Alertmanager UI界面,可以看到接收到ErrorRateHigh告警:

郵箱會收到告警信息:

總結(jié)

以上所述是小編給大家介紹的Prometheus 整合 AlertManager的教程詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

  • Docker如何修改容器已經(jīng)映射的端口

    Docker如何修改容器已經(jīng)映射的端口

    在項目中我們一般通過命令啟動一個容器的時候,通常會通過命令指定容器與物理機網(wǎng)絡(luò)端口的映射,這篇文章主要給大家介紹了關(guān)于Docker如何修改容器已經(jīng)映射的端口的相關(guān)資料,需要的朋友可以參考下
    2023-12-12
  • 記一次Docker生產(chǎn)環(huán)境搭建的方法

    記一次Docker生產(chǎn)環(huán)境搭建的方法

    這篇文章主要介紹了記一次Docker生產(chǎn)環(huán)境搭建的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-06-06
  • docker在已有的tomcat鏡像上打新的鏡像的Dockerfile編寫說明介紹

    docker在已有的tomcat鏡像上打新的鏡像的Dockerfile編寫說明介紹

    這篇文章主要介紹了docker在已有的tomcat鏡像上打新的鏡像的Dockerfile編寫說明介紹,需要的朋友可以參考下
    2016-10-10
  • docker下安裝Nginx的方法

    docker下安裝Nginx的方法

    這篇文章主要介紹了docker下安裝Nginx的方法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-07-07
  • Docker核心原理之 Cgroup詳解

    Docker核心原理之 Cgroup詳解

    cgroup的內(nèi)核通過hook鉤子來實現(xiàn)管理進程資源,提供了一個統(tǒng)一的接口,從單個進程的資源控制到操作系統(tǒng)層面的虛擬卡的過渡,今天通過本文給大家介紹Docker核心原理之 Cgroup詳解,需要的朋友參考下吧
    2021-07-07
  • docker安裝es與kibana的過程及遇到問題

    docker安裝es與kibana的過程及遇到問題

    這篇文章主要介紹了docker安裝es與kibana的過程及遇到問題,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2024-02-02
  • docker 上傳鏡像到hub倉庫的操作步驟

    docker 上傳鏡像到hub倉庫的操作步驟

    這篇文章主要介紹了docker 上傳鏡像到hub倉庫的操作步驟,首先Docker Hub需要登錄到 Docker Hub,具體操作方法跟隨小編一起看看吧
    2024-07-07
  • Docker配置國內(nèi)加速器加速鏡像下載的方法

    Docker配置國內(nèi)加速器加速鏡像下載的方法

    本篇文章主要介紹了Docker配置國內(nèi)加速器加速鏡像下載的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Docker教程之使用dockerfile生成鏡像

    Docker教程之使用dockerfile生成鏡像

    這篇文章主要介紹了Docker教程之使用dockerfile生成鏡像的相關(guān)資料,需要的朋友可以參考下
    2022-11-11
  • Dockerfile中multi-stage(多階段構(gòu)建)詳解

    Dockerfile中multi-stage(多階段構(gòu)建)詳解

    在2017年5月3日即將發(fā)行的 Docker 17.05.0-ce 中,Docker 官方提供了簡便的多階段構(gòu)建 (multi-stage build) 方案,下面這篇文章主要給大家介紹了關(guān)于Dockerfile中multi-stage(多階段構(gòu)建)的相關(guān)資料,需要的朋友可以參考借鑒,下面隨著小編來一起學習學習吧。
    2018-03-03

最新評論