3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Prometheusで監視してDiscordにアラートを通知する

Posted at
  • 監視の設定やエクスポーターについては記述していません。
  • Debian系はそのままaptコマンドで動きますが、RedHat系OSの場合はyumコマンドに置き換えてください。

prometheusのインストール

apt install prometheus prometheus-alertmanager
systemctl enable prometheus prometheus-alertmanager

alertmanager-discord

DLしてビルド

goが入っていない場合はインストール
Wiki

add-apt-repository ppa:longsleep/golang-backports
apt install golang-go

DLしてビルド

git clone https://github.com/benjojo/alertmanager-discord.git
cd alertmanager-discord
go build
cp alertmanager-discord /usr/local/bin/

benjojo/alertmanager-discord

Unitファイル作成

vim /lib/systemd/system/prometheus-alertmanager-discord.service

-webhook.urlは自分のものに置き換えてください webhookの作成
※ 9094ポートが使用済みの場合は別のポートに書き換えてください

[Unit]
Description=alertmanager-discord
Documentation=https://github.com/benjojo/alertmanager-discord
After=network-online.target

[Service]
ExecStart=/usr/local/bin/alertmanager-discord -webhook.url=https://discord.com/api/webhooks/*********** -listen.address=127.0.0.1:9094
ExecStop=/bin/kill -TERM ${MAINPID}
ExecReload=/bin/kill -HUP ${MAINPID}
Restart=on-failure

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start prometheus-alertmanager-discord
systemctl enable prometheus-alertmanager-discord

alertmanagerの設定

vim /etc/prometheus/alertmanager.yml

route:receivers:の部分を書き足す

# /etc/prometheus/alertmanager.yml
---
global: {}
templates: []
route:
  receiver: discord_webhook
  routes: []
receivers:
  - name: discord_webhook
    webhook_configs:
      - url: http://localhost:9094
inhibit_rules: []

これでDiscordにアラートが通知されるはずです。
後はお好みでexporterやアラートルールを設定してみてください!

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?