هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
ماذا يفعل
Prometheus fires alerts; Alertmanager (port 9093) decides who gets what: a route tree matches labels (severity, team), receivers send to channels, grouping joins many alerts into one message, inhibition hides warnings when a critical alert for the same thing fires, and silences mute alerts during maintenance.
amtool checks the config, lists alerts, adds and removes silences, and tests which receiver a label set reaches.
طريقة الكتابة
amtool [--alertmanager.url=URL] COMMAND [ARGS]الأجزاء الرئيسية
Commands
check-configFILE- Validate alertmanager.yml.
alertquery[MATCHERS]- List firing alerts.
alertaddNAMELABELS- Send a test alert.
silenceaddMATCHERS--commentTEXT--duration2h- Mute alerts.
silencequery- List silences.
silenceexpireID- End a silence.
configroutesshow/testLABELS- Show the route tree / which receiver matches.
configshow- Show the running config.
الخيارات 5
الأكثر استخدامًا
Flags
لا يوجد شيء يطابق هذا الفلتر.
أمثلة 10
$ مستخدم عادي# بصلاحية root (أو مع sudo)
1A route tree with two receivers
cat /etc/alertmanager/alertmanager.yml route: receiver: team-mail group_by: [alertname, instance] group_wait: 30s repeat_interval: 4h routes: - matchers: [severity="critical"] receiver: oncall-slack receivers: - name: team-mail email_configs: [{ to: ops@example.com }] - name: oncall-slack slack_configs: [{ api_url_file: /etc/alertmanager/slack.url, channel: "#oncall" }] inhibit_rules: - source_matchers: [severity="critical"] target_matchers: [severity="warning"] equal: [instance]2Check the config
amtool check-config /etc/alertmanager/alertmanager.yml3Set the URL once
cat ~/.config/amtool/config.yml alertmanager.url: http://localhost:90934See firing alerts
amtool alert query amtool alert query severity=critical -o extended5Silence a server during maintenance
amtool silence add instance="web1:9100" --comment "Kernel update, ticket OPS-412" --duration 1h amtool silence query amtool silence expire 7a3c2e1f-5b4d-4c6e-9f8a-1b2c3d4e5f606Test which receiver gets an alert
amtool config routes test severity=critical instance=db1:9100 oncall-slack amtool config routes show7Send a test alert end-to-end
amtool alert add TestAlert severity=warning instance=lab --annotation=summary="Test from amtool"8Query the API with curl
curl -s http://localhost:9093/api/v2/alerts | jq '.[].labels.alertname'9Reload after a change
curl -X POST http://localhost:9093/-/reload10Run in the cluster (kube-prometheus-stack)
kubectl -n monitoring exec -it alertmanager-monitoring-kube-prometheus-alertmanager-0 -- amtool alert query --alertmanager.url=http://localhost:9093
لا يوجد شيء يطابق هذا الفلتر.
انتبه
- Too many alerts = people stop reading them. Alert on symptoms (users hurt), not on every cause.
- Keep webhook URLs and passwords in files (
*_fileoptions), not in the YAML in Git.
الملفات
/etc/alertmanager/alertmanager.yml- Configuration.
~/.config/amtool/config.yml- amtool defaults.
نصائح للحفظ
- Always write a comment and a ticket number in silences.
رموز الخروج
0 | Success. |
1 | Error. |