يعالج AlertManager التنبيهات التي يتم إرسالها بواسطة تطبيقات العميل مثل خادم Prometheus. إنه يهتم بتكريمها وتجميعها وتوجيهها إلى تكامل المتلقي الصحيح مثل البريد الإلكتروني أو PagerDuty أو Opsgenie أو العديد من الآليات الأخرى بفضل جهاز استقبال الويب. كما أنه يعتني بإسكات وتثبيط التنبيهات.
هناك طرق مختلفة لتثبيت AlertManager.
تتوفر الثنائيات المسبقة للإصدارات التي تم إصدارها في قسم التنزيل على Prometheus.io. باستخدام أحدث إصدار من الإنتاج الثنائي هو الطريقة الموصى بها لتثبيت AlertManager.
تتوفر صور Docker على quay.io أو Docker Hub.
يمكنك إطلاق حاوية تنبيه لتجربتها بها
$ docker run --name alertmanager -d -p 127.0.0.1:9093:9093 quay.io/prometheus/alertmanager
سيتم الوصول إلى AlertManager الآن على http: // localhost: 9093/.
يمكنك إما go get عليه:
$ GO15VENDOREXPERIMENT=1 go get github.com/prometheus/alertmanager/cmd/...
# cd $GOPATH/src/github.com/prometheus/alertmanager
$ alertmanager --config.file=<your_file>
أو استنساخ المستودع وبناء يدويًا:
$ mkdir -p $GOPATH/src/github.com/prometheus
$ cd $GOPATH/src/github.com/prometheus
$ git clone https://github.com/prometheus/alertmanager.git
$ cd alertmanager
$ make build
$ ./alertmanager --config.file=<your_file>
يمكنك أيضًا بناء واحدة فقط من الثنائيات في هذا الريبو عن طريق تمرير اسم إلى وظيفة الإنشاء:
$ make build BINARIES=amtool
هذا هو تكوين مثال يجب أن يغطي أكثر الجوانب ذات الصلة بتنسيق تكوين YAML الجديد. يمكن العثور على الوثائق الكاملة للتكوين هنا.
global :
# The smarthost and SMTP sender used for mail notifications.
smtp_smarthost : ' localhost:25 '
smtp_from : ' [email protected] '
# The root route on which each incoming alert enters.
route :
# The root route must not have any matchers as it is the entry point for
# all alerts. It needs to have a receiver configured so alerts that do not
# match any of the sub-routes are sent to someone.
receiver : ' team-X-mails '
# 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 '...' as the sole label name.
# 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. Example: group_by: [...]
group_by : ['alertname', 'cluster']
# When a new group of alerts is created by an incoming alert, wait at
# least 'group_wait' to send the initial notification.
# This way ensures that you get multiple alerts for the same group that start
# firing shortly after another are batched together on the first
# notification.
group_wait : 30s
# When the first notification was sent, wait 'group_interval' to send a batch
# of new alerts that started firing for that group.
group_interval : 5m
# If an alert has successfully been sent, wait 'repeat_interval' to
# resend them.
repeat_interval : 3h
# All the above attributes are inherited by all child routes and can
# overwritten on each.
# The child route trees.
routes :
# This route performs a regular expression match on alert labels to
# catch alerts that are related to a list of services.
- matchers :
- service=~"^(foo1|foo2|baz)$"
receiver : team-X-mails
# The service has a sub-route for critical alerts, any alerts
# that do not match, i.e. severity != critical, fall-back to the
# parent node and are sent to 'team-X-mails'
routes :
- matchers :
- severity="critical"
receiver : team-X-pager
- matchers :
- service="files"
receiver : team-Y-mails
routes :
- matchers :
- severity="critical"
receiver : team-Y-pager
# This route handles all alerts coming from a database service. If there's
# no team to handle it, it defaults to the DB team.
- matchers :
- service="database"
receiver : team-DB-pager
# Also group alerts by affected database.
group_by : [alertname, cluster, database]
routes :
- matchers :
- owner="team-X"
receiver : team-X-pager
- matchers :
- owner="team-Y"
receiver : team-Y-pager
# Inhibition rules allow to mute a set of alerts given that another alert is
# firing.
# We use this to mute any warning-level notifications if the same alert is
# already critical.
inhibit_rules :
- source_matchers :
- severity="critical"
target_matchers :
- severity="warning"
# Apply inhibition if the alertname is the same.
# CAUTION:
# If all label names listed in `equal` are missing
# from both the source and target alerts,
# the inhibition rule will apply!
equal : ['alertname']
receivers :
- name : ' team-X-mails '
email_configs :
- to : ' [email protected], [email protected] '
- name : ' team-X-pager '
email_configs :
- to : ' [email protected] '
pagerduty_configs :
- routing_key : <team-X-key>
- name : ' team-Y-mails '
email_configs :
- to : ' [email protected] '
- name : ' team-Y-pager '
pagerduty_configs :
- routing_key : <team-Y-key>
- name : ' team-DB-pager '
pagerduty_configs :
- routing_key : <team-DB-key> API API الحالي في API هو الإصدار 2. يتم إنشاء واجهة برمجة التطبيقات هذه بالكامل عبر مشروع OpenAPI وتذهب إلى Swagger باستثناء معالجات HTTP نفسها. يمكن العثور على مواصفات API في API/V2/OpenApi.yaml. يمكن الوصول إلى إصدار HTML المقدم هنا. يمكن إنشاء العملاء بسهولة عبر أي مولد OpenAPI لجميع اللغات الرئيسية.
مع التكوين الافتراضي ، يتم الوصول إلى نقاط النهاية تحت بادئة A /api/v1 أو /api/v2 . ستكون نقطة نهاية V2 /status /api/v2/status . إذا تم تعيين- --web.route-prefix ، فسيتم مسبوقة طرق API مع ذلك أيضًا ، لذلك- --web.route-prefix=/alertmanager/ سوف تتعلق بـ /alertmanager/api/v2/status .
لا يزال API V2 تحت التنمية الثقيلة وبالتالي تخضع للتغيير.
amtool هي أداة CLI للتفاعل مع API ALERTMANAGER. يتم تجميعها مع جميع إصدارات AlertManager.
بدلاً من ذلك ، يمكنك التثبيت مع:
$ go install github.com/prometheus/alertmanager/cmd/amtool@latest
عرض جميع تنبيهات إطلاق النار حاليًا:
$ amtool alert
Alertname Starts At Summary
Test_Alert 2017-08-02 18:30:18 UTC This is a testing alert!
Test_Alert 2017-08-02 18:30:18 UTC This is a testing alert!
Check_Foo_Fails 2017-08-02 18:30:18 UTC This is a testing alert!
Check_Foo_Fails 2017-08-02 18:30:18 UTC This is a testing alert!
عرض جميع تنبيهات إطلاق النار حاليًا مع الإخراج الممتد:
$ amtool -o extended alert
Labels Annotations Starts At Ends At Generator URL
alertname="Test_Alert" instance="node0" link="https://example.com" summary="This is a testing alert!" 2017-08-02 18:31:24 UTC 0001-01-01 00:00:00 UTC http://my.testing.script.local
alertname="Test_Alert" instance="node1" link="https://example.com" summary="This is a testing alert!" 2017-08-02 18:31:24 UTC 0001-01-01 00:00:00 UTC http://my.testing.script.local
alertname="Check_Foo_Fails" instance="node0" link="https://example.com" summary="This is a testing alert!" 2017-08-02 18:31:24 UTC 0001-01-01 00:00:00 UTC http://my.testing.script.local
alertname="Check_Foo_Fails" instance="node1" link="https://example.com" summary="This is a testing alert!" 2017-08-02 18:31:24 UTC 0001-01-01 00:00:00 UTC http://my.testing.script.local
بالإضافة إلى عرض تنبيهات ، يمكنك استخدام بناء جملة الاستعلام الغني الذي يوفره AlertManager:
$ amtool -o extended alert query alertname="Test_Alert"
Labels Annotations Starts At Ends At Generator URL
alertname="Test_Alert" instance="node0" link="https://example.com" summary="This is a testing alert!" 2017-08-02 18:31:24 UTC 0001-01-01 00:00:00 UTC http://my.testing.script.local
alertname="Test_Alert" instance="node1" link="https://example.com" summary="This is a testing alert!" 2017-08-02 18:31:24 UTC 0001-01-01 00:00:00 UTC http://my.testing.script.local
$ amtool -o extended alert query instance=~".+1"
Labels Annotations Starts At Ends At Generator URL
alertname="Test_Alert" instance="node1" link="https://example.com" summary="This is a testing alert!" 2017-08-02 18:31:24 UTC 0001-01-01 00:00:00 UTC http://my.testing.script.local
alertname="Check_Foo_Fails" instance="node1" link="https://example.com" summary="This is a testing alert!" 2017-08-02 18:31:24 UTC 0001-01-01 00:00:00 UTC http://my.testing.script.local
$ amtool -o extended alert query alertname=~"Test.*" instance=~".+1"
Labels Annotations Starts At Ends At Generator URL
alertname="Test_Alert" instance="node1" link="https://example.com" summary="This is a testing alert!" 2017-08-02 18:31:24 UTC 0001-01-01 00:00:00 UTC http://my.testing.script.local
صمت في حالة تأهب:
$ amtool silence add alertname=Test_Alert
b3ede22e-ca14-4aa0-932c-ca2f3445f926
$ amtool silence add alertname="Test_Alert" instance=~".+0"
e48cb58a-0b17-49ba-b734-3585139b1d25
عرض الصمت:
$ amtool silence query
ID Matchers Ends At Created By Comment
b3ede22e-ca14-4aa0-932c-ca2f3445f926 alertname=Test_Alert 2017-08-02 19:54:50 UTC kellel
$ amtool silence query instance=~".+0"
ID Matchers Ends At Created By Comment
e48cb58a-0b17-49ba-b734-3585139b1d25 alertname=Test_Alert instance=~.+0 2017-08-02 22:41:39 UTC kellel
تنتهي صمت:
$ amtool silence expire b3ede22e-ca14-4aa0-932c-ca2f3445f926
تنتهي صلاحية جميع الصمت المطابقة للاستعلام:
$ amtool silence query instance=~".+0"
ID Matchers Ends At Created By Comment
e48cb58a-0b17-49ba-b734-3585139b1d25 alertname=Test_Alert instance=~.+0 2017-08-02 22:41:39 UTC kellel
$ amtool silence expire $(amtool silence query -q instance=~".+0")
$ amtool silence query instance=~".+0"
تنتهي صلاحية كل الصمت:
$ amtool silence expire $(amtool silence query -q)
جرب كيف يعمل القالب. لنفترض أن لديك هذا في ملف التكوين الخاص بك:
templates:
- '/foo/bar/*.tmpl'
ثم يمكنك اختبار كيف سيبدو القالب مع مثال باستخدام هذا الأمر:
amtool template render --template.glob='/foo/bar/*.tmpl' --template.text='{{ template "slack.default.markdown.v1" . }}'
يسمح amtool بملف التكوين بتحديد بعض الخيارات للراحة. مسارات ملف التكوين الافتراضية هي $HOME/.config/amtool/config.yml أو /etc/amtool/config.yml
قد يبدو ملف تكوين مثال كما يلي:
# Define the path that `amtool` can find your `alertmanager` instance
alertmanager.url: "http://localhost:9093"
# Override the default author. (unset defaults to your username)
author: [email protected]
# Force amtool to give you an error if you don't include a comment on a silence
comment_required: true
# Set a default output format. (unset defaults to simple)
output: extended
# Set a default receiver
receiver: team-X-pager
يتيح لك amtool تصور طرق التكوين الخاص بك في شكل عرض شجرة النص. كما يمكنك استخدامه لاختبار التوجيه عن طريق تمرير مجموعة تسمية من تنبيه وطباعة جميع أجهزة الاستقبال التي يطابقها التنبيه المطلوبة وفصلها , . (إذا كنت تستخدم --verify.receivers amtool إرجاع رمز الخطأ 1 على عدم التوافق)
مثال على الاستخدام:
# View routing tree of remote Alertmanager
$ amtool config routes --alertmanager.url=http://localhost:9090
# Test if alert matches expected receiver
$ amtool config routes test --config.file=doc/examples/simple.yml --tree --verify.receivers=team-X-pager service=database owner=team-X
إن توفر AlertManager العالي قيد الإنتاج في العديد من الشركات ويتم تمكينه افتراضيًا.
هام: هناك حاجة إلى كل من UDP و TCP في AlertManager 0.15 وأعلى حتى تعمل المجموعة.
- إذا كنت تستخدم جدار الحماية ، فتأكد من القائمة البيضاء في منفذ التجميع لكلا البروتوكولات.
- إذا كنت تعمل في حاوية ، فتأكد من فضح منفذ التجميع لكلا البروتوكولات.
لإنشاء مجموعة متوفرة للغاية من التنبيه ، يجب تكوين الحالات للتواصل مع بعضها البعض. تم تكوين هذا باستخدام --cluster.* أعلام.
--cluster.listen-address سلسلة: العنوان الاستماع الكتلة (الافتراضي "0.0.0.0:9094" ؛--cluster.advertise-address string: عنوان الإعلان عنقودي--cluster.peer القيمة: أقرانهم الأولي (تكرار العلم لكل نظير إضافي)--cluster.peer-timeout القيمة: فترة مهلة الأقران (الافتراضي "15S")--cluster.gossip-interval القيمة: سرعة انتشار رسالة الكتلة (الافتراضي "200ms")--cluster.pushpull-interval القيمة: ستزيد القيم المنخفضة من سرعات التقارب على حساب النطاق الترددي (الافتراضي "1M0s")--cluster.settle-timeout القيمة: الحد الأقصى للوقت لانتظار توصيلات الكتلة لتستقر قبل تقييم الإخطارات.--cluster.tcp-timeout القيمة: قيمة المهلة لاتصالات TCP والقراءة والكتابة (الافتراضي "10s")--cluster.probe-timeout القيمة: حان الوقت لانتظار ACK قبل وضع علامة على العقدة غير الصحية (الافتراضي "500ms")--cluster.probe-interval القيمة: الفاصل بين تحقيقات العقدة العشوائية (الافتراضي "1S")--cluster.reconnect-interval القيمة: الفاصل بين محاولة إعادة الاتصال للأقران المفقودين (الافتراضي "10s")--cluster.reconnect-timeout القيمة: طول الوقت لمحاولة إعادة الاتصال إلى نظير ضائع (افتراضي: "6H0M0s")--cluster.label القيمة: التسمية عبارة عن سلسلة اختيارية لتضمينها على كل حزمة ودفق. إنه يحدد المجموعة بشكل فريد ويمنع مشكلات التواصل المتبادل عند إرسال رسائل القيل والقال (الافتراضي: "") المنفذ المختار في علامة cluster.listen-address هو المنفذ الذي يجب تحديده في cluster.peer الأقران الآخرين.
يجب أن يكون العلم cluster.advertise-address مطلوبًا إذا لم يكن للمثال عنوان IP الذي يعد جزءًا من RFC 6890 مع مسار افتراضي.
لبدء مجموعة من ثلاثة أقران على جهازك المحلي ، استخدم goreman و Procfile ضمن هذا المستودع.
goreman start
لتوجيه Prometheus 1.4 ، أو لاحقًا ، على مثيل إلى العديد من التنبيه ، قم بتكوينها في ملف تكوين prometheus.yml الخاص بك ، على سبيل المثال:
alerting :
alertmanagers :
- static_configs :
- targets :
- alertmanager1:9093
- alertmanager2:9093
- alertmanager3:9093هام: لا تقم بتحميل حركة التوازن بين بروميثيوس وموظفيه في التنبيه ، ولكن بدلاً من ذلك نقطة بروميثيوس إلى قائمة بجميع تنبيهات. يتوقع تطبيق AlertManager إرسال جميع التنبيهات إلى جميع التنبيهات لضمان توفر مرتفع.
إذا لم يكن تشغيل ALERTMANAGER في وضع التوفر العالي غير مطلوب ، فإن الإعداد- --cluster.listen-address= يمنع AlertManager من الاستماع إلى طلبات الأقران الواردة.
تحقق من صفحة Prometheus المساهمة.
للمساهمة في واجهة المستخدم ، راجع واجهة المستخدم/التطبيق/المساهمة.
ترخيص Apache 2.0 ، انظر الترخيص.