{"id":46970,"date":"2025-07-30T05:07:41","date_gmt":"2025-07-29T21:07:41","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/46970.html"},"modified":"2025-07-30T05:07:41","modified_gmt":"2025-07-29T21:07:41","slug":"prometheus%e9%94%99%e8%af%af%e7%8e%87%e7%9b%91%e6%8e%a7%e4%b8%8e%e5%91%8a%e8%ad%a6%e5%ae%9e%e6%88%98%ef%bc%9a%e5%a6%82%e4%bd%95%e8%87%aa%e5%ae%9a%e4%b9%89%e8%a7%84%e5%88%99%e7%b2%be%e5%87%86%e9%a2%84","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/46970.html","title":{"rendered":"Prometheus\u9519\u8bef\u7387\u76d1\u63a7\u4e0e\u544a\u8b66\u5b9e\u6218\uff1a\u5982\u4f55\u81ea\u5b9a\u4e49\u89c4\u5219\u7cbe\u51c6\u9884\u8b66\u670d\u52a1\u5668\u5f02\u5e38"},"content":{"rendered":"<p>\n \u66f4\u591a\u4e91\u670d\u52a1\u5668\u77e5\u8bc6&#xff0c;\u5c3d\u5728hostol.com<\/p>\n<p>\u4f60\u6709\u6ca1\u6709\u8fc7\u8fd9\u79cd\u611f\u89c9&#xff1a;\u670d\u52a1\u8dd1\u5f97\u633a\u7a33\u7684&#xff0c;\u673a\u5668\u8d44\u6e90\u4e5f\u6ca1\u7206&#xff0c;\u4e1a\u52a1\u5374\u201c\u9ed8\u9ed8\u5730\u201d\u5f00\u59cb\u5f02\u5e38\u4e86&#xff0c;\u63a5\u53e3\u54cd\u5e94\u65f6\u95f4\u98d8\u4e86&#xff0c;\u7528\u6237\u6295\u8bc9\u201c\u7ecf\u5e38\u6253\u4e0d\u5f00\u201d&#xff0c;\u800c\u4f60\u5565\u76d1\u63a7\u90fd\u6ca1\u54cd&#xff1f;\u6ca1\u6709\u544a\u8b66&#xff0c;\u4e0d\u4ee3\u8868\u6ca1\u95ee\u9898\u3002\u4f60\u4ee5\u4e3a\u4e00\u5207 OK&#xff0c;\u5176\u5b9e\u53ea\u662f\u4f60\u76ef\u9519\u4e86\u4e1c\u897f\u3002<\/p>\n<\/p>\n<p>\u6211\u4eec\u76d1\u63a7 CPU\u3001\u5185\u5b58\u3001\u78c1\u76d8 IO&#xff0c;\u662f\u56e0\u4e3a\u90a3\u201c\u770b\u5f97\u89c1\u201d&#xff1b;\u53ef\u670d\u52a1\u771f\u6b63\u7684\u4f53\u9a8c&#xff0c;\u6709\u65f6\u5019\u662f\u201c\u770b\u4e0d\u89c1\u7684\u8840\u201d&#xff0c;\u4f60\u4e0d\u770b\u9519\u7387\u3001\u4e0d\u770b\u63a5\u53e3\u54cd\u5e94&#xff0c;\u4e0d\u53bb\u611f\u77e5\u9519\u8bef\u7387\u98d9\u5347&#xff0c;\u7528\u6237\u5d29\u6e83\u4e86&#xff0c;\u4f60\u8fd8\u5728\u56fe\u8868\u91cc\u627e\u201c\u74f6\u9888\u201d\u2026\u2026<\/p>\n<\/p>\n<p>\u6240\u4ee5&#xff0c;\u4eca\u5929\u6211\u4eec\u4e0d\u804a\u8d44\u6e90\u5360\u7528&#xff0c;\u4e5f\u4e0d\u804a\u7cfb\u7edf\u8d1f\u8f7d\u3002\u6211\u4eec\u6765\u804a\u4e00\u4ef6\u66f4\u9690\u853d\u3001\u66f4\u5bb9\u6613\u88ab\u5ffd\u89c6\u3001\u4f46\u8db3\u591f\u81f4\u547d\u7684\u8fd0\u7ef4\u76f2\u70b9\u2014\u2014\u9519\u8bef\u7387\u76d1\u63a7\u4e0e\u81ea\u5b9a\u4e49\u544a\u8b66&#xff0c;\u7528 Prometheus &#043; Alertmanager \u73a9\u51fa\u70b9\u5b9e\u7528\u53c8\u72e0\u7684\u4e1c\u897f\u3002<\/p>\n<\/p>\n<hr \/>\n<h3>\u9519\u8bef\u7387\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u96be\u76d1\u63a7&#xff1f;<\/h3>\n<\/p>\n<p>\u5982\u679c\u4f60\u95ee 10 \u4e2a\u8fd0\u7ef4\u5de5\u7a0b\u5e08\u201c\u600e\u4e48\u5224\u65ad\u670d\u52a1\u51fa\u95ee\u9898\u4e86\u201d&#xff0c;\u8d77\u7801\u6709\u4e00\u534a\u4f1a\u544a\u8bc9\u4f60\u201cCPU\u98d9\u4e86\u201d\u201c\u8fde\u63a5\u6570\u7206\u4e86\u201d\u201c\u8d85\u65f6\u591a\u4e86\u201d\u3002<\/p>\n<\/p>\n<p>\u53ef\u4f60\u95ee\u4ed6\u4eec\u201c\u600e\u4e48\u5224\u65ad\u4e00\u4e2a\u63a5\u53e3\u9519\u8bef\u7387\u5f02\u5e38\u201d&#xff0c;\u4ed6\u4eec\u591a\u534a\u4f1a\u56de\u7b54&#xff1a;\u201c\u770b\u65e5\u5fd7\u5427&#xff1f;\u201d<\/p>\n<\/p>\n<p>\u662f\u4e0d\u662f\u7a81\u7136\u6709\u70b9\u7a7a&#xff1f;\u5c31\u50cf\u4f60\u8bf7\u4fdd\u5b89\u76ef\u7740\u6bcf\u4e2a\u89d2\u843d&#xff0c;\u5374\u6ca1\u4eba\u76ef\u6444\u50cf\u5934\u91cc\u6709\u6ca1\u6709\u4eba\u95ef\u8fdb\u6765\u3002\u9519\u8bef\u7387&#xff0c;\u5c24\u5176\u662f\u4e1a\u52a1\u9519\u8bef\u7387&#xff0c;\u5e38\u5e38\u6e38\u79bb\u4e8e\u5e38\u89c4\u76d1\u63a7\u4e4b\u5916\u3002<\/p>\n<\/p>\n<p>\u8fd9\u73a9\u610f\u513f\u96be\u5728\u54ea&#xff1f;<\/p>\n<\/p>\n<h4>\u274c \u7cfb\u7edf\u6307\u6807\u4e0d\u7b49\u4e8e\u4e1a\u52a1\u5065\u5eb7<\/h4>\n<\/p>\n<p>Prometheus \u9ed8\u8ba4\u6293\u7684\u662f\u7cfb\u7edf\u5c42\u7ea7\u6307\u6807&#xff0c;\u6bd4\u5982 node_cpu_seconds_total&#xff0c;\u4f60\u80fd\u770b\u5230\u8d1f\u8f7d\u9ad8\u4e0d\u9ad8&#xff0c;\u4f46\u4f60\u770b\u4e0d\u5230 \/api\/pay \u662f\u4e0d\u662f 10 \u6b21\u6709 3 \u6b21\u8fd4\u56de\u4e86 500\u3002<\/p>\n<\/p>\n<h4>\u274c \u65e5\u5fd7\u91c7\u96c6\u5ef6\u8fdf\/\u4e22\u5931\u4e25\u91cd<\/h4>\n<\/p>\n<p>\u9760\u65e5\u5fd7\u544a\u8b66&#xff1f;\u5f97\u4e86\u5427&#xff0c;\u8981 ELK \u6ca1 ELK&#xff0c;Logstash \u5361\u6210\u72d7&#xff0c;ES \u4e00\u6ee1\u5c31\u6389\u7ebf&#xff0c;\u65e5\u5fd7\u91cf\u4e00\u5927\u5c31\u6f0f\u6570\u636e\u3002\u4f60\u8fde\u201c\u6709\u591a\u5c11\u8bf7\u6c42\u662f 5xx\u201d\u90fd\u8bf4\u4e0d\u51c6&#xff0c;\u8fd8\u544a\u8b66&#xff1f;<\/p>\n<\/p>\n<h4>\u274c \u9519\u8bef\u7684\u201c\u9608\u503c\u601d\u7ef4\u201d<\/h4>\n<\/p>\n<p>\u5f88\u591a\u4eba\u4f1a\u8bbe\u5b9a\u201c\u9519\u8bef\u6570 &gt; 100 \u5c31\u62a5\u8b66\u201d&#xff0c;\u542c\u8d77\u6765\u5408\u7406&#xff1f;\u4e0d\u4e00\u5b9a\u3002\u4f60\u603b\u8bf7\u6c42\u6570\u662f 10w&#xff0c;100 \u4e2a\u9519\u538b\u6839\u4e0d\u7b97\u5565&#xff1b;\u4f60\u4eca\u5929\u4e0a\u7ebf\u4e86\u65b0\u63a5\u53e3&#xff0c;\u8bf7\u6c42\u603b\u6570\u624d 300&#xff0c;\u51fa 10 \u4e2a\u9519\u5c31\u8be5\u70b8\u9505\u4e86\u3002<\/p>\n<\/p>\n<p>\u6240\u4ee5\u5149\u9760\u7edd\u5bf9\u503c&#xff0c;\u662f\u778e\u62a5\u8b66\u3002\u6211\u4eec\u771f\u6b63\u8981\u770b\u7684&#xff0c;\u662f \u9519\u8bef\u7387\u8d8b\u52bf\u53d8\u5316 &#043; \u81ea\u5b9a\u4e49\u4e0a\u4e0b\u6587\u6761\u4ef6\u3002<\/p>\n<\/p>\n<hr \/>\n<h3>\u5148\u95ee\u81ea\u5df1&#xff1a;\u4f60\u5230\u5e95\u60f3\u76d1\u63a7\u4ec0\u4e48\u201c\u9519\u201d&#xff1f;<\/h3>\n<\/p>\n<p>\u201c\u9519\u8bef\u201d\u662f\u4e2a\u7384\u5b66\u8bcd&#xff0c;\u4e0d\u540c\u4e1a\u52a1\u73af\u5883\u4e0b\u7684\u542b\u4e49\u5b8c\u5168\u4e0d\u4e00\u6837\u3002\u4f60\u5f97\u5148\u5b9a\u4e49\u201c\u4ec0\u4e48\u662f\u9519\u201d&#xff1a;<\/p>\n<\/p>\n<li>HTTP \u72b6\u6001\u7801\u9519\u8bef&#xff08;\u6700\u5e38\u89c1&#xff09;\n<ul>\n<li>\u6bd4\u5982 5xx&#xff08;\u670d\u52a1\u5668\u9519&#xff09;\u30014xx&#xff08;\u7528\u6237\u9519&#xff09;\u4f46\u4e0d\u62a5\u8b66<\/li>\n<\/ul>\n<\/li>\n<li>\u4e1a\u52a1\u8bed\u4e49\u9519\u8bef&#xff08;\u6bd4\u5982\u8fd4\u56de\u7801\u662f 200&#xff0c;body \u5374\u8bf4\u5931\u8d25&#xff09;\n<ul>\n<li>\u8fd9\u4e2a\u5f97\u9760\u57cb\u70b9\u6216\u65e5\u5fd7\u5904\u7406<\/li>\n<\/ul>\n<\/li>\n<li>\u63a5\u53e3\u8d85\u65f6\/\u5ef6\u8fdf\u8d85\u8fc7\u9608\u503c\n<ul>\n<li>\u867d\u7136\u6ca1\u9519&#xff0c;\u4f46\u201c\u6162\u201d\u6709\u65f6\u5019\u6bd4\u201c\u9519\u201d\u66f4\u81f4\u547d<\/li>\n<\/ul>\n<\/li>\n<p>\u6211\u4eec\u672c\u7bc7\u805a\u7126\u7b2c\u4e00\u4e2a&#xff1a;HTTP \u72b6\u6001\u7801\u9519\u8bef\u76d1\u63a7\u544a\u8b66&#xff0c;\u8fd9\u662f\u6700\u6613\u843d\u5730\u3001\u6700\u901a\u7528\u3001\u4e5f\u6700\u5177\u4ee3\u8868\u6027\u7684\u5f00\u59cb\u3002<\/p>\n<\/p>\n<hr \/>\n<h3>Metrics \u600e\u4e48\u6765&#xff1f;\u4e0d\u8981\u4e00\u5f00\u59cb\u5c31 Prometheus&#xff0c;\u5148\u8ba9\u4f60\u7684\u670d\u52a1\u201c\u4f1a\u8bf4\u8bdd\u201d<\/h3>\n<\/p>\n<p>Prometheus \u672c\u8eab\u4e0d\u4f1a\u5e2e\u4f60\u201c\u6293\u201d\u9519\u8bef&#xff0c;\u5b83\u53ea\u662f\u4e2a\u201c\u542c\u8bdd\u7684\u4eba\u201d\u2014\u2014\u4f60\u5f97\u8ba9\u670d\u52a1\u5148\u8bf4\u51fa\u6765\u3002<\/p>\n<\/p>\n<h4>Go \u670d\u52a1\u4e3e\u4e2a\u4f8b\u5b50<\/h4>\n<\/p>\n<p>\u7528 Prometheus \u5b98\u65b9\u63a8\u8350\u7684 promhttp \u4e2d\u95f4\u4ef6\u5373\u53ef&#xff1a;<\/p>\n<\/p>\n<p>go<br \/>\nhttp.Handle(&#034;\/metrics&#034;, promhttp.Handler())<\/p>\n<p>\u7136\u540e\u4f60\u7528 http_requests_total \u8fd9\u7c7b\u6307\u6807\u66b4\u9732&#xff1a;<\/p>\n<\/p>\n<p>go<br \/>\nhttp_requests_total{status&#061;&#034;200&#034;, method&#061;&#034;GET&#034;, handler&#061;&#034;\/api\/v1\/users&#034;}<br \/>\nhttp_requests_total{status&#061;&#034;500&#034;, method&#061;&#034;GET&#034;, handler&#061;&#034;\/api\/v1\/users&#034;}<\/p>\n<p>\u91cd\u70b9\u662f\u4f60\u8981\u628a status \u6807\u7b7e\u6302\u51fa\u6765&#xff0c;\u5b83\u662f\u4f60\u505a\u9519\u8bef\u7387\u8ba1\u7b97\u7684\u5173\u952e\u7ef4\u5ea6\u3002<\/p>\n<\/p>\n<h4>Nginx \u600e\u4e48\u641e&#xff1f;<\/h4>\n<\/p>\n<p>\u6253\u5f00 stub_status&#xff1f;\u90a3\u53ea\u80fd\u770b\u5230\u8fde\u63a5\u6570\u3002<\/p>\n<\/p>\n<p>\u4f60\u5f97\u7528 nginx-vts-exporter \u6216\u8005 nginx-prometheus-exporter&#xff0c;\u914d\u5408\u4e0b\u9762\u7684 log_format \u8f93\u51fa&#xff1a;<\/p>\n<\/p>\n<p>nginx<br \/>\nlog_format prometheus &#039;$remote_addr &#8211; $remote_user [$time_local] &#039;<br \/>\n                      &#039;&#034;$request&#034; $status $body_bytes_sent &#039;<br \/>\n                      &#039;&#034;$http_referer&#034; &#034;$http_user_agent&#034;&#039;;<\/p>\n<p>\u7136\u540e\u4f60\u5c31\u80fd\u62ff\u5230\u8bf7\u6c42\u6570\u4e0e\u72b6\u6001\u7801\u7edf\u8ba1\u6570\u636e\u3002<\/p>\n<\/p>\n<hr \/>\n<h3>PromQL \u600e\u4e48\u5199&#xff1f;\u522b\u518d\u53ea\u4f1a count() \u4e86\u5144\u5f1f<\/h3>\n<\/p>\n<p>\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u771f\u5b9e\u4f8b\u5b50\u3002<\/p>\n<\/p>\n<h4>&#x1f522; \u76ee\u6807&#xff1a;\u6bcf5\u5206\u949f\u5185&#xff0c;5xx\u6bd4\u4f8b &gt; 5%&#xff0c;\u544a\u8b66<\/h4>\n<\/p>\n<h5>\u6b65\u9aa41&#xff1a;\u9519\u8bef\u7387 PromQL \u516c\u5f0f<\/h5>\n<\/p>\n<p>promql<br \/>\nsum(rate(http_requests_total{status&#061;~&#034;5..&#034;}[5m]))<br \/>\n\/<br \/>\nsum(rate(http_requests_total[5m]))<\/p>\n<p>\u662f\u4e0d\u662f\u5f88\u773c\u719f&#xff1f;\u8fd9\u662f\u6700\u5e38\u89c1\u7684\u201c\u9519\u8bef\u7387\u201d\u8ba1\u7b97\u65b9\u5f0f&#xff0c;\u6ce8\u610f\u7528\u4e86 rate \u8868\u793a\u6bcf\u79d2\u901f\u7387&#xff0c;5\u5206\u949f\u6ed1\u7a97\u5e73\u5747\u3002\u4e5f\u5c31\u662f\u8bf4\u8fc7\u53bb5\u5206\u949f\u91cc&#xff0c;\u9519\u8bef\u6bd4\u4f8b\u662f\u591a\u5c11\u3002<\/p>\n<\/p>\n<h5>\u6b65\u9aa42&#xff1a;\u628a\u5b83\u5199\u6210\u544a\u8b66\u89c4\u5219<\/h5>\n<\/p>\n<p>yaml<br \/>\ngroups:<br \/>\n&#8211; name: errors<br \/>\n  rules:<br \/>\n  &#8211; alert: HighHttpErrorRate<br \/>\n    expr: |<br \/>\n      sum(rate(http_requests_total{status&#061;~&#034;5..&#034;}[5m]))<br \/>\n      \/<br \/>\n      sum(rate(http_requests_total[5m])) &gt; 0.05<br \/>\n    for: 1m<br \/>\n    labels:<br \/>\n      severity: warning<br \/>\n    annotations:<br \/>\n      summary: &#034;\u63a5\u53e3\u9519\u8bef\u7387\u8fc7\u9ad8&#034;<br \/>\n      description: &#034;5xx \u9519\u8bef\u6bd4\u4f8b\u8fc7\u53bb5\u5206\u949f\u8d85\u8fc75%&#034;<\/p>\n<p>\u6ce8\u610f for: 1m \u8868\u793a\u8fd9\u4e2a\u6761\u4ef6\u8981\u6301\u7eed\u6ee1\u8db31\u5206\u949f\u624d\u4f1a\u89e6\u53d1&#xff0c;\u9632\u6b62\u6296\u52a8\u8bef\u62a5\u3002<\/p>\n<\/p>\n<hr \/>\n<h3>\u66f4\u8fdb\u4e00\u6b65&#xff1a;\u652f\u6301\u4e0d\u540c\u63a5\u53e3\u5206\u5f00\u544a\u8b66<\/h3>\n<\/p>\n<p>\u4f60\u4e0d\u53ef\u80fd\u7528\u4e00\u4e2a\u544a\u8b66\u89c4\u5219\u76d1\u63a7\u6240\u6709\u63a5\u53e3&#xff0c;\u4e0d\u7136 GET \/favicon.ico \u62a5\u9519\u90fd\u62a5\u8b66&#xff0c;\u90a3\u4e0d\u75af\u4e86\u5417\u3002<\/p>\n<\/p>\n<p>\u4f60\u53ef\u4ee5\u7528 group by handler&#xff1a;<\/p>\n<\/p>\n<p>promql<br \/>\nsum(rate(http_requests_total{status&#061;~&#034;5..&#034;}[5m])) by (handler)<br \/>\n\/<br \/>\nsum(rate(http_requests_total[5m])) by (handler)<\/p>\n<p>\u8fd9\u6837\u6bcf\u4e2a\u63a5\u53e3\u90fd\u6709\u81ea\u5df1\u7684\u9519\u8bef\u7387\u7edf\u8ba1\u3002<\/p>\n<\/p>\n<p>\u4f46\u8fd9\u65f6\u5019\u95ee\u9898\u6765\u4e86&#xff1a;\u4f60\u4f1a\u62a5\u8b66\u592a\u591a\u3002<\/p>\n<\/p>\n<h4>\u90a3\u600e\u4e48\u89e3\u51b3\u544a\u8b66\u6cdb\u6ee5&#xff1f;<\/h4>\n<\/p>\n<p>\u6709\u4e09\u79cd\u65b9\u6cd5&#xff1a;<\/p>\n<\/p>\n<li>\u8fc7\u6ee4 QPS \u592a\u4f4e\u7684\u63a5\u53e3<\/li>\n<li>promql<\/li>\n<li>sum(rate(http_requests_total[5m])) by (handler) &gt; 0.5 \u610f\u601d\u662f\u53ea\u544a\u8b66\u90a3\u4e9b 5 \u5206\u949f\u8bf7\u6c42\u6570 &gt; 150 \u7684\u63a5\u53e3<\/li>\n<li>\u589e\u52a0\u91cd\u590d\u6291\u5236&#xff08;inhibit rules&#xff09; Alertmanager \u652f\u6301\u540c\u7c7b\u578b\u544a\u8b66\u5408\u5e76&#xff0c;\u6bd4\u5982&#xff1a; yaml<\/li>\n<li>inhibit_rules: &#8211; source_match: severity: &#039;critical&#039; target_match: severity: &#039;warning&#039; equal: [&#039;handler&#039;]<\/li>\n<li>\u6dfb\u52a0 error_budget \u601d\u7ef4 \u5c06\u9608\u503c\u52a8\u6001\u8c03\u6574&#xff0c;\u6bd4\u5982\u5141\u8bb8\u67d0\u63a5\u53e3\u6bcf\u5929 0.1% \u9519\u8bef\u7387&#xff0c;\u4e00\u65e6\u8d85\u51fa\u5c31\u544a\u8b66&#xff0c;\u800c\u4e0d\u662f\u6b7b\u677f\u5199\u6b7b 5%\u3002<\/li>\n<hr \/>\n<h3>\u53ef\u89c6\u5316\u76d1\u63a7&#xff1a;\u7528 Grafana \u5c55\u793a\u9519\u8bef\u7387\u8d8b\u52bf<\/h3>\n<\/p>\n<p>\u522b\u8ba9 Alertmanager \u53d8\u6210\u201c\u62a5\u8b66\u9ed1\u5323\u5b50\u201d&#xff0c;\u6211\u4eec\u9700\u8981\u7528\u56fe\u8868\u544a\u8bc9\u522b\u4eba\u201c\u9519\u5728\u54ea\u201d\u201c\u4ec0\u4e48\u65f6\u5019\u5f00\u59cb\u9519\u7684\u201d\u201c\u9519\u4e86\u591a\u4e45\u201d\u3002<\/p>\n<\/p>\n<p>\u63a8\u8350\u7684 Dashboard \u6a21\u5757&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>\u9519\u8bef\u7387\u65f6\u95f4\u5e8f\u5217\u66f2\u7ebf<\/li>\n<li>Top N \u9519\u8bef\u7387\u63a5\u53e3\u6392\u884c<\/li>\n<li>\u6309 status_code \u7ef4\u5ea6\u5c55\u793a\u9519\u8bef\u5206\u5e03<\/li>\n<li>\u6700\u8fd1\u4e00\u6b21\u544a\u8b66\u65f6\u95f4 \/ \u5904\u7406\u72b6\u6001&#xff08;\u4ece Alertmanager webhook \u62ff&#xff09;<\/li>\n<\/ul>\n<p>\u914d\u5408 grafana-image-renderer \u63d2\u4ef6&#xff0c;\u4f60\u751a\u81f3\u53ef\u4ee5\u628a\u8fd9\u5f20\u56fe\u5d4c\u5165\u90ae\u4ef6\u6216\u98de\u4e66\u544a\u8b66\u91cc&#xff0c;\u89c6\u89c9\u76f4\u89c2\u3002<\/p>\n<\/p>\n<hr \/>\n<h3>\u9ad8\u9636\u73a9\u6cd5&#xff1a;\u52a0\u4e0a SLIs \u548c SLOs \u601d\u7ef4<\/h3>\n<\/p>\n<p>\u4f20\u7edf\u76d1\u63a7\u5173\u6ce8\u201c\u5f02\u5e38\u201d&#xff0c;SRE\u66f4\u5173\u6ce8\u201c\u7528\u6237\u4f53\u9a8c\u201d\u3002\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u501f\u52a9 Google SRE \u63d0\u51fa\u7684 SLI\/SLO \u6846\u67b6&#xff0c;\u5c06\u9519\u8bef\u7387\u4e0e\u201c\u670d\u52a1\u53ef\u7528\u6027\u201d\u7ed1\u5b9a\u3002<\/p>\n<\/p>\n<h4>\u4e3e\u4e2a\u4f8b\u5b50&#xff1a;<\/h4>\n<\/p>\n<ul>\n<li>\u4f60\u627f\u8bfa API \u6708\u53ef\u7528\u6027 99.9%&#xff0c;\u6bcf\u5929\u6700\u591a\u5141\u8bb8\u9519\u8bef\u8bf7\u6c42\u6570 &#061; \u8bf7\u6c42\u603b\u6570 * 0.001<\/li>\n<li>\u90a3\u4e48\u4f60\u5c31\u53ef\u4ee5\u8ba1\u7b97&#xff1a;\u4eca\u5929\u7528\u4e86\u591a\u5c11 Error Budget&#xff1f;<\/li>\n<\/ul>\n<p>promql<br \/>\n(sum(rate(http_requests_total{status&#061;~&#034;5..&#034;}[5m])) \/ sum(rate(http_requests_total[5m]))) &gt; 0.001<\/p>\n<p>\u8fd9\u7c7b\u544a\u8b66\u53ef\u4ee5\u6539\u4e3a\u201c\u8d8b\u52bf\u578b\u201d&#xff0c;\u800c\u4e0d\u662f\u201c\u4e8b\u4ef6\u578b\u201d\u544a\u8b66\u3002<\/p>\n<\/p>\n<hr \/>\n<h3>\u544a\u8b66\u4e86&#xff0c;\u7136\u540e\u5462&#xff1f;\u522b\u5149\u54cd\u4e0d\u5904\u7406&#xff01;<\/h3>\n<\/p>\n<p>\u6700\u540e\u522b\u5fd8\u4e86&#xff0c;\u544a\u8b66\u53ea\u662f\u8d77\u70b9&#xff0c;\u4e0d\u662f\u7ec8\u70b9\u3002<\/p>\n<\/p>\n<p>\u4e00\u4e2a\u771f\u6b63\u6210\u719f\u7684\u9519\u8bef\u7387\u76d1\u63a7\u7cfb\u7edf&#xff0c;\u5e94\u8be5\u5305\u62ec&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>\u81ea\u52a8\u5224\u65ad\u6839\u56e0&#xff08;\u6bd4\u5982 5xx \u662f\u5426\u53ea\u96c6\u4e2d\u5728\u67d0\u4e2a\u63a5\u53e3&#xff09;<\/li>\n<li>\u81ea\u52a8\u5173\u8054\u4ee3\u7801\u7248\u672c&#xff08;\u662f\u5426\u521a\u521a\u90e8\u7f72&#xff09;<\/li>\n<li>\u81ea\u52a8\u751f\u6210\u5de5\u5355\u6216\u53d1\u9001\u98de\u4e66\u901a\u77e5<\/li>\n<li>\u53ef\u9009\u9759\u9ed8\u673a\u5236&#xff08;\u6bd4\u5982\u53d1\u5e03\u7a97\u53e3\u4e0d\u62a5\u8b66&#xff09;<\/li>\n<\/ul>\n<p>\u800c\u8fd9&#xff0c;\u90fd\u53ef\u4ee5\u901a\u8fc7 Prometheus &#043; Alertmanager &#043; Webhook &#043; CI\/CD \u5de5\u5177 &#043; \u53ef\u89c2\u6d4b\u5e73\u53f0&#xff08;\u5982 Grafana Loki\u3001Jaeger&#xff09;\u6765\u5b8c\u6210\u95ed\u73af\u3002<\/p>\n<\/p>\n<hr \/>\n<p>\u4f60\u4ee5\u4e3a\u4f60\u6ca1\u95ee\u9898&#xff0c;\u53ef\u80fd\u53ea\u662f\u4f60\u8fd8\u6ca1\u770b\u89c1\u95ee\u9898\u3002\u9519\u8bef\u7387\u4e0d\u662f\u6302\u4e86\u624d\u7b97\u9519&#xff0c;\u7528\u6237\u70b9\u4e2a\u6309\u94ae\u53613\u79d2\u8f6c\u5708\u5708\u4e5f\u53ef\u80fd\u76f4\u63a5\u5378\u8f7d\u4f60 App\u3002Prometheus \u80fd\u4e0d\u80fd\u544a\u8bc9\u4f60\u201c\u670d\u52a1\u8fd8\u6d3b\u7740\u201d\u5f88\u5bb9\u6613&#xff0c;\u80fd\u4e0d\u80fd\u544a\u8bc9\u4f60\u201c\u7528\u6237\u723d\u4e0d\u723d\u201d&#xff0c;\u5c31\u770b\u4f60\u6709\u6ca1\u6709\u5b9a\u4e49\u51fa\u5c5e\u4e8e\u4f60\u81ea\u5df1\u7684\u544a\u8b66\u6807\u51c6\u3002<\/p>\n<\/p>\n<p>\u522b\u518d\u7b49\u7ebf\u4e0a\u70b8\u9505\u4e86\u624d\u540e\u6094\u6ca1\u52a0\u544a\u8b66&#xff0c;\u5c24\u5176\u662f\u8fd9\u79cd\u201c\u4e0d\u70b8\u4f46\u6301\u7eed\u6e17\u8840\u201d\u7684\u9519\u8bef\u7387\u3002<\/p>\n<\/p>\n<p>\u8bf4\u5230\u5e95&#xff0c;\u4f60\u76d1\u63a7\u7684\u662f\u6570\u5b57&#xff0c;\u4f46\u4f60\u8981\u4fdd\u969c\u7684\u662f\u4f53\u9a8c\u3002<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb920\u6b21\uff0c\u70b9\u8d5e13\u6b21\uff0c\u6536\u85cf20\u6b21\u3002CPU\u6ca1\u7206\u3001\u5185\u5b58\u4e5f\u7a33\uff0c\u7528\u6237\u5374\u9891\u7e41\u62a5\u9519\uff1f\u9519\u8bef\u7387\u76d1\u63a7\u624d\u662f\u53d1\u73b0\u9690\u85cf\u6545\u969c\u7684\u5173\u952e\u3002\u672c\u6587\u6559\u4f60\u7528Prometheus + Alertmanager\u5b9e\u73b0\u81ea\u5b9a\u4e49\u9519\u8bef\u7387\u544a\u8b66\uff0c\u914d\u5957\u5b9e\u6218PromQL\u89c4\u5219\u3001\u5206\u63a5\u53e3\u76d1\u63a7\u3001Grafana\u53ef\u89c6\u5316\u65b9\u6848\uff0c\u5168\u9762\u638c\u63a7\u670d\u52a1\u5065\u5eb7\u3002_\u670d\u52a1\u544a\u8b66\u5982\u4f55\u76d1\u63a7qps\u7b49\u6307\u6807<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[678,43,44],"topic":[],"class_list":["post-46970","post","type-post","status-publish","format-standard","hentry","category-server","tag-prometheus","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Prometheus\u9519\u8bef\u7387\u76d1\u63a7\u4e0e\u544a\u8b66\u5b9e\u6218\uff1a\u5982\u4f55\u81ea\u5b9a\u4e49\u89c4\u5219\u7cbe\u51c6\u9884\u8b66\u670d\u52a1\u5668\u5f02\u5e38 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/46970.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Prometheus\u9519\u8bef\u7387\u76d1\u63a7\u4e0e\u544a\u8b66\u5b9e\u6218\uff1a\u5982\u4f55\u81ea\u5b9a\u4e49\u89c4\u5219\u7cbe\u51c6\u9884\u8b66\u670d\u52a1\u5668\u5f02\u5e38 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb920\u6b21\uff0c\u70b9\u8d5e13\u6b21\uff0c\u6536\u85cf20\u6b21\u3002CPU\u6ca1\u7206\u3001\u5185\u5b58\u4e5f\u7a33\uff0c\u7528\u6237\u5374\u9891\u7e41\u62a5\u9519\uff1f\u9519\u8bef\u7387\u76d1\u63a7\u624d\u662f\u53d1\u73b0\u9690\u85cf\u6545\u969c\u7684\u5173\u952e\u3002\u672c\u6587\u6559\u4f60\u7528Prometheus + Alertmanager\u5b9e\u73b0\u81ea\u5b9a\u4e49\u9519\u8bef\u7387\u544a\u8b66\uff0c\u914d\u5957\u5b9e\u6218PromQL\u89c4\u5219\u3001\u5206\u63a5\u53e3\u76d1\u63a7\u3001Grafana\u53ef\u89c6\u5316\u65b9\u6848\uff0c\u5168\u9762\u638c\u63a7\u670d\u52a1\u5065\u5eb7\u3002_\u670d\u52a1\u544a\u8b66\u5982\u4f55\u76d1\u63a7qps\u7b49\u6307\u6807\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/46970.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-29T21:07:41+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/46970.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/46970.html\",\"name\":\"Prometheus\u9519\u8bef\u7387\u76d1\u63a7\u4e0e\u544a\u8b66\u5b9e\u6218\uff1a\u5982\u4f55\u81ea\u5b9a\u4e49\u89c4\u5219\u7cbe\u51c6\u9884\u8b66\u670d\u52a1\u5668\u5f02\u5e38 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-29T21:07:41+00:00\",\"dateModified\":\"2025-07-29T21:07:41+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/46970.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/46970.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/46970.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Prometheus\u9519\u8bef\u7387\u76d1\u63a7\u4e0e\u544a\u8b66\u5b9e\u6218\uff1a\u5982\u4f55\u81ea\u5b9a\u4e49\u89c4\u5219\u7cbe\u51c6\u9884\u8b66\u670d\u52a1\u5668\u5f02\u5e38\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Prometheus\u9519\u8bef\u7387\u76d1\u63a7\u4e0e\u544a\u8b66\u5b9e\u6218\uff1a\u5982\u4f55\u81ea\u5b9a\u4e49\u89c4\u5219\u7cbe\u51c6\u9884\u8b66\u670d\u52a1\u5668\u5f02\u5e38 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/46970.html","og_locale":"zh_CN","og_type":"article","og_title":"Prometheus\u9519\u8bef\u7387\u76d1\u63a7\u4e0e\u544a\u8b66\u5b9e\u6218\uff1a\u5982\u4f55\u81ea\u5b9a\u4e49\u89c4\u5219\u7cbe\u51c6\u9884\u8b66\u670d\u52a1\u5668\u5f02\u5e38 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb920\u6b21\uff0c\u70b9\u8d5e13\u6b21\uff0c\u6536\u85cf20\u6b21\u3002CPU\u6ca1\u7206\u3001\u5185\u5b58\u4e5f\u7a33\uff0c\u7528\u6237\u5374\u9891\u7e41\u62a5\u9519\uff1f\u9519\u8bef\u7387\u76d1\u63a7\u624d\u662f\u53d1\u73b0\u9690\u85cf\u6545\u969c\u7684\u5173\u952e\u3002\u672c\u6587\u6559\u4f60\u7528Prometheus + Alertmanager\u5b9e\u73b0\u81ea\u5b9a\u4e49\u9519\u8bef\u7387\u544a\u8b66\uff0c\u914d\u5957\u5b9e\u6218PromQL\u89c4\u5219\u3001\u5206\u63a5\u53e3\u76d1\u63a7\u3001Grafana\u53ef\u89c6\u5316\u65b9\u6848\uff0c\u5168\u9762\u638c\u63a7\u670d\u52a1\u5065\u5eb7\u3002_\u670d\u52a1\u544a\u8b66\u5982\u4f55\u76d1\u63a7qps\u7b49\u6307\u6807","og_url":"https:\/\/www.wsisp.com\/helps\/46970.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-29T21:07:41+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/46970.html","url":"https:\/\/www.wsisp.com\/helps\/46970.html","name":"Prometheus\u9519\u8bef\u7387\u76d1\u63a7\u4e0e\u544a\u8b66\u5b9e\u6218\uff1a\u5982\u4f55\u81ea\u5b9a\u4e49\u89c4\u5219\u7cbe\u51c6\u9884\u8b66\u670d\u52a1\u5668\u5f02\u5e38 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-29T21:07:41+00:00","dateModified":"2025-07-29T21:07:41+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/46970.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/46970.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/46970.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Prometheus\u9519\u8bef\u7387\u76d1\u63a7\u4e0e\u544a\u8b66\u5b9e\u6218\uff1a\u5982\u4f55\u81ea\u5b9a\u4e49\u89c4\u5219\u7cbe\u51c6\u9884\u8b66\u670d\u52a1\u5668\u5f02\u5e38"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/46970","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=46970"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/46970\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=46970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=46970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=46970"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=46970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}