Prometheus : アラートの設定 (Email)2025/09/26 |
|
Prometheus のアラートの設定です。 アラートの受け取り方法は、Slack, HipChat, WeChat 等々、多くの手段が提供されていますが、当例では Email での通知の設定をします。
アラート設定の詳細は公式サイトを参照ください。 |
|
| [1] |
メールでの通知をする場合は、使用可能な SMTP サーバーが必要となります。 |
| [2] | Prometheus サーバーが稼働するホストで、アラートの機能を提供する Alertmanager をインストールします。 |
|
root@dlp:~# apt -y install prometheus-alertmanager |
| [3] | 例として、Email で通知する場合の Alertmanager の設定です。 |
|
root@dlp:~#
mv /etc/prometheus/alertmanager.yml /etc/prometheus/alertmanager.yml.org root@dlp:~# vi /etc/prometheus/alertmanager.yml # 新規作成 global: # 使用する SMTP サーバー smtp_smarthost: 'localhost:25' # TLS 要/不要 smtp_require_tls: false # 通知メールの送信者アドレス smtp_from: 'Alertmanager <root@dlp.srv.world>' # SMTP Auth を設定している場合はアカウント名とパスワード # smtp_auth_username: 'alertmanager' # smtp_auth_password: 'password' route: # 通知先の Receiver名 receiver: 'email-notice' # アラートをグループ化する条件 group_by: ['alertname', 'Service', 'Stage', 'Role'] # グループ化されたアラートを初回通知するまでの待ち時間 # 待ち時間の間に発生した同様のアラートはグループ化される group_wait: 30s # 通知済みのグループアラートに新しいアラートが追加された場合の次回通知までの待ち時間 group_interval: 5m # 通知済みの同内容のアラートを再送信する間隔 repeat_interval: 4h receivers: # 任意の [Receiver] 名 - name: 'email-notice' email_configs: # 通知先アドレス - to: "root@localhost" # 新規作成 # 例として [node-exporter] の [Up/Down] を監視
groups:
- name: Instances
rules:
- alert: InstanceDown
expr: up == 0
for: 5m
labels:
severity: critical
annotations:
description: '{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes.'
summary: 'Instance {{ $labels.instance }} down'
root@dlp:~#
vi /etc/prometheus/prometheus.yml # 17行目 : (Alertmanager 稼働ホスト):(ポート) alerting: alertmanagers: - static_configs: - targets: ['localhost:9093'] # 23行目 : 作成したアラートルールを追記 rule_files: # - "first_rules.yml" # - "second_rules.yml" - "alert_rules.yml"root@dlp:~# systemctl restart prometheus prometheus-alertmanager root@dlp:~# systemctl enable prometheus-alertmanager |
| [4] | [node-exporter] がダウンすると以下のようなメールが送信されます。(本文は HTML 形式) |
|
root@dlp:~# mail
? 1
Return-Path: <root@dlp.srv.world>
X-Original-To: root@localhost
Delivered-To: root@localhost
Received: from localhost (localhost [IPv6:::1])
by dlp.srv.world (Postfix) with UTF8SMTP id CD99EDFD5B
for <root@localhost>; Fri, 26 Sep 2025 10:44:52 +0900 (JST)
Subject: [FIRING:1] InstanceDown (node01.srv.world:9100 Hiroshima example critical)
To: root@localhost
From: Alertmanager <root@dlp.srv.world>
Message-Id: <1758851092842573436.17443484982068580011@dlp.srv.world>
Date: Fri, 26 Sep 2025 10:44:52 +0900
Content-Type: multipart/alternative; boundary=4cc0c2ee37543bfc1e8339e05aef0622b1e66afcd18aa6fc2232610fa693
MIME-Version: 1.0
--4cc0c2ee37543bfc1e8339e05aef0622b1e66afcd18aa6fc2232610fa693
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.=
w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=3D"http://www.w3.org/1999/xhtml" style=3D"margin: 0; font-famil=
y: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; =
font-size: 14px;">
<head>
<meta name=3D"viewport" content=3D"width=3Ddevice-width">
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DUTF-8">
<title>[FIRING:1] InstanceDown (node01.srv.world:9100 Hiroshima example cri=
tical)</title>
.....
.....
|
| Sponsored Link |
|
|