{"id":1561,"date":"2023-03-25T15:55:27","date_gmt":"2023-03-25T07:55:27","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1561"},"modified":"2023-04-27T21:36:00","modified_gmt":"2023-04-27T13:36:00","slug":"prometheus-alertmanager-alarm-optimization","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/25\/prometheus-alertmanager-alarm-optimization\/","title":{"rendered":"Prometheus + Alertmanager \u62a5\u8b66\u4f18\u5316"},"content":{"rendered":"<h2>\u539f\u59cb\u90ae\u4ef6<\/h2>\n<p>\u4f7f\u7528\u539f\u59cb\u90ae\u4ef6\u544a\u8b66\u6a21\u677f\uff0c\u4e0d\u4f7f\u7528\u81ea\u5b9a\u4e49\u90ae\u4ef6\u6a21\u677f<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-yml\"># \u5b9a\u4e49\u6a21\u677f\u4fe1\u606f\n#templates:\n#  - &#039;template\/*.tmpl&#039;\n\nreceivers:\n  - name: &#039;email&#039; # \u8b66\u62a5\n    email_configs: # \u90ae\u7bb1\u914d\u7f6e\n    - to: &#039;yezhou@appblog.cn&#039; # \u63a5\u6536\u8b66\u62a5\u7684email\u914d\u7f6e\n      #html: &#039;{{ template &quot;email.html&quot; . }}&#039; # \u8bbe\u5b9a\u90ae\u7bb1\u7684\u5185\u5bb9\u6a21\u677f\n      #headers: { Subject: &quot;[WARN] \u62a5\u8b66\u90ae\u4ef6&quot;} # \u63a5\u6536\u90ae\u4ef6\u7684\u6807\u9898<\/code><\/pre>\n<h2>\u914d\u7f6e\u591a\u4e2a\u90ae\u4ef6\u63a5\u6536\u8005<\/h2>\n<p>\u4ee5\u9017\u53f7\u95f4\u9694<\/p>\n<pre><code class=\"language-yml\">receivers:\n  - name: &#039;email&#039; # \u8b66\u62a5\n    email_configs: # \u90ae\u7bb1\u914d\u7f6e\n    - to: &#039;yezhou@appblog.cn, test@appblog.cn&#039; # \u63a5\u6536\u8b66\u62a5\u7684email\u914d\u7f6e\n      html: &#039;{{ template &quot;email.html&quot; . }}&#039; # \u8bbe\u5b9a\u90ae\u7bb1\u7684\u5185\u5bb9\u6a21\u677f\n      headers: { Subject: &quot;[WARN] \u62a5\u8b66\u90ae\u4ef6&quot;} # \u63a5\u6536\u90ae\u4ef6\u7684\u6807\u9898<\/code><\/pre>\n<h2>\u90ae\u4ef6\u6a21\u677f\u7f8e\u5316<\/h2>\n<pre><code class=\"language-html\">{{ define &quot;email.html&quot; }}\n\n&lt;style type=&quot;text\/css&quot;&gt;\ntable.gridtable {\n  font-family: verdana,arial,sans-serif;\n  font-size:11px;\n  color:#333333;\n  border-width: 1px;\n  border-color: #666666;\n  border-collapse: collapse;\n}\ntable.gridtable th {\n  border-width: 1px;\n  padding: 8px;\n  border-style: solid;\n  border-color: #666666;\n  background-color: #dedede;\n}\ntable.gridtable td {\n  border-width: 1px;\n  padding: 8px;\n  border-style: solid;\n  border-color: #666666;\n  background-color: #ffffff;\n}\n&lt;\/style&gt;\n\n&lt;table class=&quot;gridtable&quot;&gt;\n  &lt;tr&gt;\n    &lt;th&gt;\u62a5\u8b66\u9879&lt;\/th&gt;\n    &lt;th&gt;\u5b9e\u4f8b&lt;\/th&gt;\n    &lt;th&gt;\u62a5\u8b66\u9600\u503c&lt;\/th&gt;\n    &lt;th&gt;\u5f00\u59cb\u65f6\u95f4&lt;\/th&gt;\n  &lt;\/tr&gt;\n  {{ range $i, $alert := .Alerts }}\n    &lt;tr&gt;\n      &lt;td&gt;{{ index $alert.Labels &quot;alertname&quot; }}&lt;\/td&gt;\n      &lt;td&gt;{{ index $alert.Labels &quot;instance&quot; }}&lt;\/td&gt;\n      &lt;td&gt;{{ index $alert.Annotations &quot;value&quot; }}&lt;\/td&gt;\n      &lt;td&gt;{{ $alert.StartsAt }}&lt;\/td&gt;\n    &lt;\/tr&gt;\n  {{ end }}\n&lt;\/table&gt;\n{{ end }}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u59cb\u90ae\u4ef6 \u4f7f\u7528\u539f\u59cb\u90ae\u4ef6\u544a\u8b66\u6a21\u677f\uff0c\u4e0d\u4f7f\u7528\u81ea\u5b9a\u4e49\u90ae\u4ef6\u6a21\u677f # \u5b9a\u4e49\u6a21\u677f\u4fe1\u606f #templates: # &#8211; &#038;#0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[386],"tags":[389,387],"class_list":["post-1561","post","type-post","status-publish","format-standard","hentry","category-monitor","tag-alertmanager","tag-prometheus"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1561","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1561"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1561\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}