AlertManager จัดการการแจ้งเตือนที่ส่งโดยแอปพลิเคชันไคลเอนต์เช่นเซิร์ฟเวอร์ Prometheus มันดูแลการซ้ำซ้อนการจัดกลุ่มและการกำหนดเส้นทางไปยังการรวมตัวรับสัญญาณที่ถูกต้องเช่นอีเมล, pagerduty, opsgenie หรือกลไกอื่น ๆ อีกมากมายด้วยเครื่องรับ webhook นอกจากนี้ยังดูแลการปิดเสียงและการยับยั้งการแจ้งเตือน
มีหลายวิธีในการติดตั้ง AlertManager
Binaries Precompiled สำหรับเวอร์ชันที่วางจำหน่ายมีอยู่ในส่วน ดาวน์โหลด บน prometheus.io การใช้ไบนารีรุ่นล่าสุดคือวิธีที่แนะนำในการติดตั้ง AlertManager
รูปภาพ Docker มีอยู่ใน quay.io หรือ Docker Hub
คุณสามารถเปิดตัวคอนเทนเนอร์ AlertManager เพื่อลองด้วย
$ 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>
นอกจากนี้คุณยังสามารถสร้างหนึ่งในไบนารีใน repo นี้โดยส่งชื่อไปยังฟังก์ชั่นการสร้าง:
$ 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 AlertManager ปัจจุบันคือเวอร์ชัน 2 API นี้สร้างขึ้นอย่างสมบูรณ์ผ่านโครงการ OpenAPI และ GO 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 สำหรับการโต้ตอบกับ AlertManager API มันมาพร้อมกับการเผยแพร่ทั้งหมดของ 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
นอกเหนือจากการดูการแจ้งเตือนคุณสามารถใช้ไวยากรณ์การสืบค้นแบบ Rich ที่จัดทำโดย 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 และสูงกว่าสำหรับคลัสเตอร์ในการทำงาน
- หากคุณใช้ไฟร์วอลล์ตรวจสอบให้แน่ใจว่าได้อนุญาตให้ใช้พอร์ตการจัดกลุ่มสำหรับโปรโตคอลทั้งสอง
- หากคุณใช้งานในคอนเทนเนอร์ตรวจสอบให้แน่ใจว่าได้เปิดเผยพอร์ตการจัดกลุ่มสำหรับโปรโตคอลทั้งสอง
ในการสร้างคลัสเตอร์ที่มีอยู่อย่างสูงของการ AlertManager อินสแตนซ์จะต้องมีการกำหนดค่าเพื่อสื่อสารซึ่งกันและกัน สิ่งนี้ถูกกำหนดค่าโดยใช้ --cluster.* ตั้งค่าสถานะ
--cluster.listen-address String: คลัสเตอร์ฟังที่อยู่ (ค่าเริ่มต้น "0.0.0.0:9094"; สตริงว่างปิดใช้งานโหมด HA)--cluster.advertise-address String: ที่อยู่โฆษณาคลัสเตอร์--cluster.peer Value: peer เริ่มต้น (ทำซ้ำธงสำหรับแต่ละเพียร์เพิ่มเติม)--cluster.peer-timeout Value: ระยะเวลาหมดเวลาเพียร์ (ค่าเริ่มต้น "15S")--cluster.gossip-interval Value: คลัสเตอร์ความเร็วการแพร่กระจายข้อความ (ค่าเริ่มต้น "200ms")--cluster.pushpull-interval Value: ค่าที่ต่ำกว่าจะเพิ่มความเร็วการบรรจบกันที่ค่าใช้จ่ายของแบนด์วิดท์ (ค่าเริ่มต้น "1M0S")--cluster.settle-timeout Value: เวลาสูงสุดในการรอการเชื่อมต่อคลัสเตอร์เพื่อชำระก่อนประเมินการแจ้งเตือน--cluster.tcp-timeout Value: ค่าหมดเวลาสำหรับการเชื่อมต่อ TCP, อ่านและเขียน (เริ่มต้น "10s")--cluster.probe-timeout Value: เวลารอ ACK ก่อนที่จะทำเครื่องหมายโหนดที่ไม่ดีต่อสุขภาพ (ค่าเริ่มต้น "500ms")--cluster.probe-interval Value: ช่วงเวลาระหว่างโพรบโหนดสุ่ม (ค่าเริ่มต้น "1S")--cluster.reconnect-interval Value: ช่วงเวลาระหว่างการพยายามเชื่อมต่อกับ Peers ที่หายไปอีกครั้ง (ค่าเริ่มต้น "10S")--cluster.reconnect-timeout ค่า: ระยะเวลาในการพยายามเชื่อมต่อกับเพียร์ที่หายไป (ค่าเริ่มต้น: "6H0M0S"))--cluster.label Value: ฉลากเป็นสตริงเสริมที่จะรวมไว้ในแต่ละแพ็คเก็ตและสตรีม มันระบุคลัสเตอร์โดยเฉพาะและป้องกันปัญหาการสื่อสารข้ามเมื่อส่งข้อความซุบซิบ (ค่าเริ่มต้น: "") พอร์ตที่เลือกไว้ใน 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สำคัญ: อย่าโหลดการรับส่งข้อมูลสมดุลระหว่าง Prometheus และการแจ้งเตือนของมัน แต่แทนที่จะชี้ Prometheus ไปยังรายการของการแจ้งเตือนทั้งหมด การดำเนินการ AlertManager คาดว่าการแจ้งเตือนทั้งหมดจะถูกส่งไปยัง AlertManagers ทั้งหมดเพื่อให้แน่ใจว่ามีความพร้อมใช้งานสูง
หากไม่ต้องการเรียกใช้ AlertManager ในโหมดความพร้อมใช้งานสูงการตั้งค่า --cluster.listen-address= ป้องกันการ AlertManager จากการฟังคำขอเพียร์ที่เข้ามา
ตรวจสอบหน้า Prometheus
หากต้องการมีส่วนร่วมในส่วนต่อประสานผู้ใช้ให้ดูที่ UI/App/Interning.md
ใบอนุญาต Apache 2.0 ดูใบอนุญาต