前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >prometheus告警

prometheus告警

作者头像
写一点笔记
发布2022-08-11 16:51:42
7260
发布2022-08-11 16:51:42
举报
文章被收录于专栏:程序员备忘录程序员备忘录

在讲解prometheus的时候我们说其具有告警的特征,也就是prometheus在收集监控数据的时候会根据规则判断相应指标是否达到了告警上线然后使用推送的方式进行告警。但是要明确的一点是prometheus的仅仅是用来收集和查询监控数据的,要让我们的prometheus具有告警功能还需要prometheus体系的另一个组件altermanger,这块我们大概的讲解一下。

https://prometheus.io/download/

下载好altermanager之后,我们解压。其中的altermanager.yml是altermanager的配置文件。主要用来管理告警信息发送的规则,也就是说给谁发,用那种方式。

这块作者简单测试了一下监控mysql的线程数的告警。首先配置一下prometheus的数据收集的规则和push告警信息的地址。

代码语言:javascript
复制
groups:
- name: test-mysql-rule
  rules:
  - alert: "连接数报警"
    expr: mysql_global_variables_mysqlx_max_connections > 90   #连接数大于90就告警
    for: 1s
    labels:
      severity: warning
    annotations:
      summary: "服务名:{{$labels.alertname}}"
      description: "业务msyql连接数不够报警: 当前值为:{{ $value }}"
      value: "{{ $value }}"

在prometheus配置文件中添加这个告警规则

代码语言:javascript
复制
# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).


# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets: ["localhost:9093"]  #发送到altermanager的告警分析中
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  - "tianjingle_rules.yml"
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=` to any timeseries scraped from this config.
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']
  # 添加msyql的监控
  - job_name: 'mysql'
    # 静态添加node
    static_configs:
    # 指定监控端
    - targets: ['localhost:9104']


  - job_name: 'bounter-monitor'
    scrape_interval: 5s
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['localhost:8081']

配置好上述配置之后对prometheus重启。并在prometheus的alter栏目中查看告警是否触发。发现已经触发了告警配置。

在配置好prometheus的告警之后,我们需要配置altermanager的告警信息路由规则。我们修改altermanager.yml文件。

代码语言:javascript
复制
global:
  resolve_timeout: 5m
  smtp_smarthost: 'smtp.qq.com:465'
  smtp_from: '2695062879@qq.com'
  smtp_auth_username: '2695062879@qq.com'
  smtp_auth_password: '********'
  smtp_require_tls: false
route:
  receiver: mail
receivers:
  - name: 'mail'
    email_configs:
      - to: '2695062879@qq.com'

配置好qq邮箱的报警提醒之后,我们重启altermanager。然后看一下是否会收到报警的邮件。稍等片刻,在邮箱中收到了邮件,如图。

早~

本文参与?腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-06-23,如有侵权请联系?cloudcommunity@tencent.com 删除

本文分享自 写点笔记 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体同步曝光计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 MySQL
腾讯云数据库 MySQL(TencentDB for MySQL)为用户提供安全可靠,性能卓越、易于维护的企业级云数据库服务。其具备6大企业级特性,包括企业级定制内核、企业级高可用、企业级高可靠、企业级安全、企业级扩展以及企业级智能运维。通过使用腾讯云数据库 MySQL,可实现分钟级别的数据库部署、弹性扩展以及全自动化的运维管理,不仅经济实惠,而且稳定可靠,易于运维。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com