Prometheus学习系列(三十八)之报警配置

Alertmanager通过命令行标志和配置文件进行配置。 虽然命令行标志配置了不可变的系统参数,但配置文件定义了禁止规则,通知路由和通知接收器。可视化编辑器可以帮助构建路由树。要查看所有可用的命令行标志,请运行alertmanager -h。Alertmanager可以在运行时重新加载其配置。 如果新配置格式不正确,则不会应用更改并记录错误。 通过向进程发送SIGHUP或向/-/reloa...
摘要由CSDN通过智能技术生成

Alertmanager通过命令行标志和配置文件进行配置。 虽然命令行标志配置了不可变的系统参数,但配置文件定义了禁止规则,通知路由和通知接收器。

可视化编辑器可以帮助构建路由树。

要查看所有可用的命令行标志,请运行alertmanager -h

Alertmanager可以在运行时重新加载其配置。 如果新配置格式不正确,则不会应用更改并记录错误。 通过向进程发送SIGHUP或向/-/reload端点发送HTTP POST请求来触发配置重新加载。

一、配置文件

指定要加载的配置文件,使用--config.file标志

./alertmanager --config.file=simple.yml

该文件以YAML格式写入,由下面描述的方案定义。括号表示参数是可选的。对于非列表参数,该值设置为指定的默认值。

通用占位符定义如下:

  • <duration>:与正则表达式匹配的持续时间[0-9]+(ms|[smhdwy])
  • <labelname>:与正则表达式匹配的字符串[a-zA-Z _][a-zA-Z0-9 _]*
  • <labelvalue>:一串unicode字符
  • <filepath>:当前工作目录中的有效路径
  • <boolean>:一个可以取值为truefalse的布尔值
  • <string>:常规字符串
  • <secret>:一个秘密的常规字符串,例如密码
  • <tmpl_string>:在使用前进行模板扩展的字符串
  • <tmpl_secret>:在使用之前进行模板扩展的字符串,它是一个秘密
    其他占位符是单独指定的。

可以在此处找到有效的示例文件。

全局配置指定在所有其他配置上下文中有效的参数。它们还可用作其他配置节的默认值。

global:
  # ResolveTimeout is the time after which an alert is declared resolved
  # if it has not been updated.
  [ resolve_timeout: <duration> | default = 5m ]

  # The default SMTP From header field.
  [ smtp_from: <tmpl_string> ]
  # The default SMTP smarthost used for sending emails, including port number.
  # Port number usually is 25, or 587 for SMTP over TLS (sometimes referred to as STARTTLS).
  # Example: smtp.example.org:587
  [ smtp_smarthost: <string> ]
  # The default hostname to identify to the SMTP server.
  [ smtp_hello: <string> | default = "localhost" ]
  [ smtp_auth_username: <string> ]
  # SMTP Auth using LOGIN and PLAIN.
  [ smtp_auth_password: <secret> ]
  # SMTP Auth using PLAIN.
  [ smtp_auth_identity: <string> ]
  # SMTP Auth using CRAM-MD5. 
  [ smtp_auth_secret: <secret> ]
  # The default SMTP TLS requirement.
  [ smtp_require_tls: <bool> | default = true ]

  # The API URL to use for Slack notifications.
  [ slack_api_url: <secret> ]
  [ victorops_api_key: <secret> ]
  [ victorops_api_url: <string> | default = "https://alert.victorops.com/integrations/generic/20131114/alert/" ]
  [ pagerduty_url: <string> | default = "https://events.pagerduty.com/v2/enqueue" ]
  [ opsgenie_api_key: <secret> ]
  [ opsgenie_api_url: <string> | default = "https://api.opsgenie.com/" ]
  [ hipchat_api_url: <string> | default = "https://api.hipchat.com/" ]
  [ hipchat_auth_token: <secret> ]
  [ wechat_api_url: <string> | default = "https://qyapi.weixin.qq.com/cgi-bin/" ]
  [ wechat_api_secret: <secret> ]
  [ wechat_api_corp_id: <string> ]

  # The default HTTP client configuration
  [ http_config: <http_config> ]

# Files from which custom notification template definitions are read.
# The last component may use a wildcard matcher, e.g. 'templates/*.tmpl'.
templates:
  [ - <filepath> ... ]

# The root node of the routing tree.
route: <route>

# A list of notification receivers.
receivers:
  - <receiver> ...

# A list of inhibition rules.
inhibit_rules:
  [ - <inhibit_rule> ... ]
二、<route>

路由块定义路由树中的节点及其子节点。 如果未设置,则其可选配置参数将从其父节点继承。

每个警报都在配置的顶级路由中进入路由树,该路由必须匹配所有警报(即没有任何已配置的匹配器)。 然后它遍历子节点。 如果将continue设置为false,则在第一个匹配的子项后停止。 如果匹配节点上的continue为true,则警报将继续与后续兄弟节点匹配。 如果警报与节点的任何子节点都不匹配(没有匹配的子节点,或者不存在),则根据当前节点的配置参数处理警报。

[ receiver: <string> ]
# The labels by which incoming alerts are grouped together. For example,
# multiple alerts coming in for cluster=A and alertname=LatencyHigh would
# be batched into a single group.
#
# To aggregate by all possible labels use the special value '...' as the sole label name, for example:
# group_by: ['...'] 
# This effectively disables aggregation entirely, passing through all 
# alerts as-is. This is unlikely to be what you want, unless you have 
# a very low alert volume or your upstream notification system performs 
# its own grouping.
[ group_by: '[' <labelname>, ... ']' ]

# Whether an alert should continue matching subsequent sibling nodes.
[ continue: <boolean> | default = false ]

# A set of equality matchers an alert has to fulfill to match the node.
match:
  [ <labelname>: <labelvalue>, ... ]

# A set of regex-matchers an alert has to fulfill to match the node.
match_re:
  [ <labelname>: <regex>, ... ]

# How long to initially wait to send a notification for a group
# of al
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Prometheus报警配置可以通过以下步骤完成: 1. 检查语法:使用命令`promtool check config /etc/prometheus/prometheus.yml`来检查配置文件语法是否正确。 2. 重载服务:使用命令`systemctl restart prometheus`来重启Prometheus服务,以使配置更改生效。 3. 指定告警地址:编辑Prometheus配置文件`/etc/prometheus/prometheus.yml`,在`global`部分下添加以下内容: ``` alerting: alertmanagers: - static_configs: - targets: - 192.168.1.20:9093 - 192.168.1.21:9093 - 192.168.1.22:9093 ``` 这里指定了要将告警发送到的Alertmanager的地址。 4. 设置告警规则匹配目录:在配置文件中添加以下内容,以指定告警规则的匹配目录: ``` rule_files: - "rules/*.yml" ``` 5. 添加告警规则:创建告警规则文件,并在文件中添加告警规则。例如,可以使用以下命令创建一个名为`node_up.yml`的告警规则文件: ``` cat > /etc/prometheus/rules/node_up.yml <<EOF groups: - name: node-up rules: - alert: node-up expr: up{job="node"} == 0 for: 10s labels: severity: 1 team: node annotations: summary: "{{ \$labels.instance }} 已停止运行超过 15s" description: hello world EOF ``` 这里的示例规则是检测名为`node`的指标,如果该指标的值为0(即节点停止运行),则触发名为`node-up`的告警。告警规则中还可以指定标签和注释信息。 以上是配置Prometheus报警的基本步骤。根据实际需求,可以根据Prometheus官方文档中提供的更多配置选项来进一步定制报警设置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值