{"id":236718,"date":"2022-03-10T08:40:30","date_gmt":"2022-03-10T00:40:30","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=236718"},"modified":"2022-02-28T10:41:53","modified_gmt":"2022-02-28T02:41:53","slug":"alertmanager-linux-graph","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/alertmanager-linux-graph.html","title":{"rendered":"\u6559\u4f60\u5982\u4f55\u5728 AlertManager \u62a5\u8b66\u901a\u77e5\u4e2d\u5c55\u793a\u76d1\u63a7\u56fe\u8868"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u4eca\u5929\u6362\u4e86\u53e6\u5916\u4e00\u79cd\u65b9\u5f0f\u6765\u5b9e\u73b0\uff0c\u76f4\u63a5\u53bb\u7ed8\u5236\u6e32\u67d3\u62a5\u8b66\u56fe\u8868\uff0c\u7136\u540e\u4e0a\u4f20\u5230\u5bf9\u8c61\u5b58\u50a8\u4e2d\u4fdd\u5b58\u8d77\u6765\uff0c\u5728\u9489\u9489\u4e2d\u5c31\u53ef\u4ee5\u76f4\u63a5\u5c55\u793a\u4e86\u3002Promoter \u5c31\u662f\u8fd9\u4e2a\u65b9\u6848\u7684\u4e00\u4e2a\u5b9e\u73b0\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u4e4b\u524d\u7528 Python \u5b9e\u73b0\u4e86\u4e00\u4e2a\u975e\u5e38\u7b80\u964b\u7684 AlertManager \u7684\u9489\u9489\u63a5\u6536\u5668\uff0c\u4e00\u76f4\u60f3\u5728\u9489\u9489\u7684\u6d88\u606f\u901a\u77e5\u4e2d\u5c06\u5f53\u524d\u62a5\u8b66\u56fe\u8868\u4e5f\u5c55\u793a\u51fa\u6765\uff0c\u8fd9\u6837\u663e\u7136\u5bf9\u7528\u6237\u6765\u8bf4\u66f4\u52a0\u53cb\u597d\u3002\u4e4b\u524d\u60f3\u7684\u601d\u8def\u662f\u901a\u8fc7\u722c\u866b\u7684\u65b9\u5f0f\u53bb Prometheus \u9875\u9762\u5c06 Graph \u56fe\u5f62\u622a\u56fe\u4fdd\u5b58\u4e0b\u6765\uff0c\u8be5\u65b9\u5f0f\u7406\u8bba\u4e0a\u786e\u5b9e\u662f\u53ef\u884c\u7684\uff0c\u4f46\u662f\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u7a33\u5b9a\u56e0\u7d20\u8f83\u591a\uff0c\u800c\u4e14\u4f1a\u5360\u7528\u5927\u91cf\u7684\u8d44\u6e90\u3002<\/p>\n \u4eca\u5929\u6362\u4e86\u53e6\u5916\u4e00\u79cd\u65b9\u5f0f\u6765\u5b9e\u73b0\uff0c\u76f4\u63a5\u53bb\u7ed8\u5236\u6e32\u67d3\u62a5\u8b66\u56fe\u8868\uff0c\u7136\u540e\u4e0a\u4f20\u5230\u5bf9\u8c61\u5b58\u50a8\u4e2d\u4fdd\u5b58\u8d77\u6765\uff0c\u5728\u9489\u9489\u4e2d\u5c31\u53ef\u4ee5\u76f4\u63a5\u5c55\u793a\u4e86\uff0cPromoter \u5c31\u662f\u8fd9\u4e2a\u65b9\u6848\u7684\u4e00\u4e2a\u5b9e\u73b0\uff0c\u652f\u6301\u5728\u6d88\u606f\u901a\u77e5\u4e2d\u5c55\u793a\u5b9e\u65f6\u62a5\u8b66\u56fe\u8868\uff0c\u6548\u679c\u56fe\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n <\/p>\n \u76ee\u524d\u662f\u5c06\u62a5\u8b66\u6570\u636e\u6e32\u67d3\u6210\u56fe\u7247\u540e\u4e0a\u4f20\u5230 S3 \u5bf9\u8c61\u5b58\u50a8\uff0c\u6240\u4ee5\u9700\u8981\u914d\u7f6e\u4e00\u4e2a\u5bf9\u8c61\u5b58\u50a8(\u963f\u91cc\u4e91 OSS \u4e5f\u53ef\u4ee5)\uff0c\u6b64\u5916\u6d88\u606f\u901a\u77e5\u5c55\u793a\u6837\u5f0f\u652f\u6301\u6a21\u677f\u5b9a\u5236.<\/p>\n \u6a21\u677f<\/strong><\/span><\/div>\n \u9ed8\u8ba4\u6a21\u677f\u4f4d\u4e8e template\/default.tmpl\uff0c\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u9700\u6c42\u5b9a\u5236\uff1a<\/p>\n {{ define \"__subject\" }}[{{ .Status | toUpper }}{{ if eq .Status \"firing\" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join \" \" }} {{ if gt (len .CommonLabels) (len .GroupLabels) }}({{ with .CommonLabels.Remove .GroupLabels.Names }}{{ .Values | join \" \" }}{{ end }}){{ end }}{{ end }}\r\n{{ define \"__alertmanagerURL\" }}{{ .ExternalURL }}\/#\/alerts?receiver={{ .Receiver }}{{ end }}\r\n{{ define \"default.__text_alert_list\" }}{{ range . }}\r\n### {{ .Annotations.summary }}\r\n**\u8be6\u60c5:** {{ .Annotations.description }}\r\n{{ range .Images }}\r\n**\u6761\u4ef6:** `{{ .Title }}`\r\n![📈]({{ .Url }})\r\n{{- end }}\r\n**\u6807\u7b7e:**\r\n{{ range .Labels.SortedPairs }}{{ if and (ne (.Name) \"severity\") (ne (.Name) \"summary\") }}> - {{ .Name }}: {{ .Value | markdown | html }}\r\n{{ end }}{{ end }}\r\n{{ end }}{{ end }}\r\n{{\/* Default *\/}}\r\n{{ define \"default.title\" }}{{ template \"__subject\" . }}{{ end }}\r\n{{ define \"default.content\" }}\r\n{{ if gt (len .Alerts.Firing) 0 -}}\r\n#### **{{ .Alerts.Firing | len }} \u6761\u62a5\u8b66**\r\n{{ template \"default.__text_alert_list\" .Alerts.Firing }}\r\n{{ range .AtMobiles }}@{{ . }}{{ end }}\r\n{{- end }}\r\n{{ if gt (len .Alerts.Resolved) 0 -}}\r\n#### **{{ .Alerts.Resolved | len }} \u6761\u62a5\u8b66\u6062\u590d**\r\n{{ template \"default.__text_alert_list\" .Alerts.Resolved }}\r\n{{ range .AtMobiles }}@{{ . }}{{ end }}\r\n{{- end }}\r\n{{- end }}<\/pre>\n |