cephの構成員osd HDDの管理は常時必要. 異常がでたら関知して、通知する仕組みを入れてみる
Prometheus: データの収集と蓄積を担う
Alertmanager: 通知の判断と配送役
PrometheusとAlertmanagerは共にcephからデプロイされます
まずはAlertmanagerを構築して、Gmailへテストメールが飛ぶことを確認します
Alertmanagerはコンテナとして用意されています。
[root@ceph-mgr ~]# ceph orch apply alertmanager --placement="ceph-mgr" --dry-run
:
####################
SERVICESPEC PREVIEWS
####################
+--------------+--------------+----------+-------------+
|SERVICE |NAME |ADD_TO |REMOVE_FROM |
+--------------+--------------+----------+-------------+
|alertmanager |alertmanager |ceph-mgr | |
+--------------+--------------+----------+-------------+
:
[root@ceph-mgr ~]# ceph orch apply alertmanager --placement="ceph-mgr"
[root@ceph-mgr ~]# ceph orch ls alertmanager
NAME PORTS RUNNING REFRESHED AGE PLACEMENT
alertmanager ?:9093,9094 1/1 74s ago 97s ceph-mgr
[root@ceph-mgr ~]# ceph orch ps ceph-mgr
NAME HOST PORTS STATUS REFRESHED AGE MEM USE MEM LIM VERSION IMAGE ID CONTAINER ID
alertmanager.ceph-mgr ceph-mgr *:9093,9094 running (98s) 97s ago 107s 15.2M - 0.28.1 91c01b3cec9b 2bca804e1112
crash.ceph-mgr ceph-mgr running (45m) 97s ago 3w 19.2M - 20.2.1 fb63cba66eea ed24078efa6d
mgr.ceph-mgr.nwgopq ceph-mgr *:8443,8765 running (45m) 97s ago 3w 633M - 20.2.1 fb63cba66eea d8361cc56882
[root@ceph-mgr ~]#次にメール設定を行います
[root@ceph-mgr ~]# cat alertmanager.yml
global:
smtp_smarthost: 'smtp.gmail.com:587'
smtp_from: 'xxxxxxxxxxxxxxxxxxxxxxxx@gmail.com'
smtp_auth_username: 'xxxxxxxxxxxxxxxxxxxxxxxx@gmail.com'
smtp_auth_password: 'aaaabbbbccccdddd'
smtp_require_tls: true
route:
receiver: 'gmail-notice'
group_by: ['alertname']
group_wait: 30s
group_interval: 5m
repeat_interval: 3h
receivers:
- name: 'gmail-notice'
email_configs:
- to: 'xxxxxxxxxxxxxxxxxxxxxxxx@gmail.com'
send_resolved: true
[root@ceph-mgr ~]# ceph config-key set mgr/cephadm/services/alertmanager/alertmanager.yml -i alertmanager.yml
[root@ceph-mgr ~]# ceph orch redeploy alertmanager
(確認)
[root@ceph-mgr ~]# curl -s http://localhost:9093/api/v2/status | jq -r .config.original <-- smtp.gmail.comがあるか確認しますテストメールを投じてみます. ceph-mgrにて
[root@ceph-mgr ~]# curl -X POST http://localhost:9093/api/v2/alerts \
-H "Content-Type: application/json" \
-d '[
{
"labels": {
"alertname": "TestAlert",
"severity": "critical"
},
"annotations": {
"summary": "Alertmanager mail test 1st",
"description": "manual test"
},
"generatorURL": "http://localhost/test",
"startsAt": "'$(date -u +"%Y-%m-%dT%H:%M:%SZ")'",
"endsAt": "'$(date -u -d "+10 minutes" +"%Y-%m-%dT%H:%M:%SZ")'"
}
]'
[root@ceph-mgr ~]#通信設定が上手く行ってれば、下記のようなGmailが届きます

Alertmanagerと同様にコンテナで動きます
[root@ceph-mgr ~]# ceph orch apply prometheus --placement="ceph-mgr" --dry-run
:
####################
SERVICESPEC PREVIEWS
####################
+------------+------------+----------+-------------+
|SERVICE |NAME |ADD_TO |REMOVE_FROM |
+------------+------------+----------+-------------+
|prometheus |prometheus |ceph-mgr | |
+------------+------------+----------+-------------+
:
[root@ceph-mgr ~]# ceph orch apply prometheus --placement="ceph-mgr"
[root@ceph-mgr ~]# ceph orch ps ceph-mgr
NAME HOST PORTS STATUS REFRESHED AGE MEM USE MEM LIM VERSION IMAGE ID CONTAINER ID
alertmanager.ceph-mgr ceph-mgr *:9093,9094 running (15m) 3m ago 39m 19.8M - 0.28.1 91c01b3cec9b 73758e00d14c
crash.ceph-mgr ceph-mgr running (83m) 3m ago 3w 19.2M - 20.2.1 fb63cba66eea ed24078efa6d
mgr.ceph-mgr.nwgopq ceph-mgr *:8443,8765 running (83m) 3m ago 3w 614M - 20.2.1 fb63cba66eea d8361cc56882
prometheus.ceph-mgr ceph-mgr *:9095 running (3m) 3m ago 3m 27.4M - 3.6.0 4fcecf061b74 4e9a9ce8ec2d
[root@ceph-mgr ~]# ceph orch ls prometheus
NAME PORTS RUNNING REFRESHED AGE PLACEMENT
prometheus ?:9095 1/1 3m ago 4m ceph-mgr
[root@ceph-mgr ~]#どのような状態になれば Alertmanager に通知を依頼するかはPrometheus内で用意されているルールファイルに従う
その内容は http://ceph-mgr:9095 の上部メニュー「Status」->「Rule health」にある

あるいは prometheus のコンテナ内の/etc/prometheus/alerting/ceph_alerts.ymlに書かれている
ここでは cintainer idが「4e9a9ce8ec2d」なので
[root@ceph-mgr ~]# podman exec -it 4e9a9ce8ec2d cat /etc/prometheus/alerting/ceph_alerts.ymlで閲覧できる.
こちらは仮想マシンなのでいくらやっても大丈夫ですが、本番システムには適用しないように。。
osd hddの1つを停止してみる
[root@ceph-mgr ~]# ceph orch daemon stop osd.1
Scheduled to stop osd.1 on host 'ceph-osd01'
[root@ceph-mgr ~]#
[root@ceph-mgr ~]# ceph osd tree
ID CLASS WEIGHT TYPE NAME STATUS REWEIGHT PRI-AFF
-1 0.29279 root default
-3 0.09760 host ceph-osd01
1 hdd 0.04880 osd.1 down 1.00000 1.00000
0 ssd 0.04880 osd.0 up 1.00000 1.00000
-7 0.09760 host ceph-osd02
3 hdd 0.04880 osd.3 up 1.00000 1.00000
2 ssd 0.04880 osd.2 up 1.00000 1.00000
-10 0.09760 host ceph-osd03
5 hdd 0.04880 osd.5 up 1.00000 1.00000
4 ssd 0.04880 osd.4 up 1.00000 1.00000
[root@ceph-mgr ~]#
[root@ceph-mgr ~]# ceph health
HEALTH_WARN 1 osds down; Degraded data redundancy: 8/90 objects degraded (8.889%), 7 pgs degraded
[root@ceph-mgr ~]#っでメールが届く

っで復旧させてみる
[root@ceph-mgr ~]# ceph orch daemon start osd.1
Scheduled to start osd.1 on host 'ceph-osd01'
[root@ceph-mgr ~]#っでメールが届く

[root@ceph-mgr ~]# cat alertmanager.yml
global:
smtp_smarthost: 'smtp.gmail.com:587'
smtp_from: 'xxxxxxxxxxxxxxxxxxxxxxxx@gmail.com'
smtp_auth_username: 'xxxxxxxxxxxxxxxxxxxxxxxx@gmail.com'
smtp_auth_password: 'aaaabbbbccccdddd'
smtp_require_tls: true
route:
group_by: ['alertname']
group_wait: 30s
group_interval: 5m
repeat_interval: 3h
receiver: 'gmail-slack-notice'
receivers:
- name: 'gmail-slack-notice'
email_configs:
- to: 'xxxxxxxxxxxxxxxxxxxxxxxx@gmail.com'
send_resolved: true
slack_configs:
- api_url: 'https://hooks.slack.com/services/AAAAAAAAAAAAA/VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV'
channel: '#ceph-alerts'
send_resolved: true
title: 'Ceph Alert'
text: 'Ceph alert detected'
[root@ceph-mgr ~]#
[root@ceph-mgr ~]# ceph config-key set mgr/cephadm/services/alertmanager/alertmanager.yml -i alertmanager.yml
[root@ceph-mgr ~]# ceph orch redeploy alertmanager
(確認)
[root@ceph-mgr ~]# ceph config-key get mgr/cephadm/services/alertmanager/alertmanager.ymlこれでslackにも通知が届きます
slackでの「api_url」の値ですが、
slackの「チャンネル」欄の「+」から「チェンネルを作成する」を行います。

ここでは「#ceph-alert」を作ります

すると「チャンネル」欄に「#ceph-alrt」が表示されます

次に、「https://api.slack.com/apps」にアクセスして(認証がある場合はそれに応じて)
下記画面が表示されたら「Create an App」をクリックします

下記画面が表示されて、「From scratch」を押下します

appの名称を入れます。あとworkspaceを選択します。
ここではappの名称は「ceph-alerts」にしてます。「Create App」ボタンを押下します

作られた「ceph-alerts」アプリの設定画面が表示され、左縦メニューから「Incoming Webhooks」を選択します。
表示された「Incoming Webhooks」画面で、「Active Incoming Webhooks」を有効にして(OffからOnへ)、表示された項目「Webhook URLs for Your Workspace」の「Add New Webhook」ボタンを押下します

作ったAppをチャンネルにアサインします

すると Webhook 向けのURLが用意されます。「Webhook URL」欄にある「Copy」を押下すしてURLをコピーして 先ほどの api_url に貼り付けます。

「Sample curl request to post to channel:」にある文字列は、そのまま「Copy」してターミナルに貼って実行すればslackにメッセージが届きます。テスト用ですね。