{"id":15918,"date":"2026-04-26T09:55:54","date_gmt":"2026-04-26T01:55:54","guid":{"rendered":"https:\/\/top.duoku.icu\/libs\/15918.html"},"modified":"2026-04-26T09:55:54","modified_gmt":"2026-04-26T01:55:54","slug":"prometheus-%e7%9b%91%e6%8e%a7%e7%b3%bb%e7%bb%9f%e8%af%a6%e7%bb%86%e4%bd%bf%e7%94%a8%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.srclibs.com\/index.php\/2026\/04\/26\/prometheus-%e7%9b%91%e6%8e%a7%e7%b3%bb%e7%bb%9f%e8%af%a6%e7%bb%86%e4%bd%bf%e7%94%a8%e6%95%99%e7%a8%8b\/","title":{"rendered":"Prometheus \u76d1\u63a7\u7cfb\u7edf\u8be6\u7ec6\u4f7f\u7528\u6559\u7a0b"},"content":{"rendered":"<div style=\"text-align:center;margin:30px 0;\"><img decoding=\"async\" src=\"https:\/\/top.duoku.icu\/wp-content\/uploads\/2026\/04\/image-86.png\" alt=\"Prometheus \u76d1\u63a7\u7cfb\u7edf\u8be6\u7ec6\u4f7f\u7528\u6559\u7a0b\" style=\"max-width:100%;height:auto;border-radius:12px;box-shadow:0 4px 12px rgba(0,0,0,0.1);\"><\/div>\n<h1>Prometheus \u76d1\u63a7\u7cfb\u7edf\u8be6\u7ec6\u4f7f\u7528\u6559\u7a0b<\/h1>\n<h2>\u6838\u5fc3\u6982\u5ff5<\/h2>\n<p>Prometheus \u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u7cfb\u7edf\u76d1\u63a7\u548c\u8b66\u62a5\u5de5\u5177\u5305\uff0c\u6700\u521d\u7531 SoundCloud \u4e8e 2012 \u5e74\u5f00\u53d1\uff0c2016 \u5e74\u52a0\u5165 Cloud Native Computing Foundation (CNCF) \u6210\u4e3a\u7b2c\u4e8c\u4e2a\u5b75\u5316\u9879\u76ee\u3002\u5176\u6838\u5fc3\u8bbe\u8ba1\u7406\u5ff5\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u591a\u7ef4\u6570\u636e\u6a21\u578b<\/strong>\uff1a\u4ee5\u6307\u6807\u540d\u79f0\u548c\u952e\u503c\u5bf9\uff08labels\uff09\u6765\u6807\u8bc6\u65f6\u95f4\u5e8f\u5217\u6570\u636e\uff0c\u652f\u6301\u7075\u6d3b\u7684\u67e5\u8be2\u548c\u5206\u6790\u3002<\/li>\n<li><strong>Pull \u673a\u5236<\/strong>\uff1a\u901a\u8fc7 HTTP \u62c9\u53d6\u76ee\u6807\u670d\u52a1\u7684\u6307\u6807\u6570\u636e\uff0c\u800c\u975e\u88ab\u52a8\u63a5\u6536\u63a8\u9001\u3002<\/li>\n<li><strong>\u65e0\u4f9d\u8d56\u5b58\u50a8<\/strong>\uff1a\u672c\u5730\u65f6\u95f4\u5e8f\u5217\u5b58\u50a8\uff0c\u4e0d\u4f9d\u8d56\u5916\u90e8\u5b58\u50a8\u7cfb\u7edf\u3002<\/li>\n<li><strong>\u5f3a\u5927\u7684\u67e5\u8be2\u8bed\u8a00<\/strong>\uff1aPromQL \u63d0\u4f9b\u7075\u6d3b\u7684\u67e5\u8be2\u80fd\u529b\uff0c\u652f\u6301\u805a\u5408\u3001\u8fc7\u6ee4\u548c\u6570\u5b66\u8fd0\u7b97\u3002<\/li>\n<li><strong>\u544a\u8b66\u673a\u5236<\/strong>\uff1a\u5185\u7f6e Alertmanager \u8d1f\u8d23\u544a\u8b66\u7684\u63a5\u6536\u3001\u5206\u7ec4\u548c\u8def\u7531\u3002<\/li>\n<\/ul>\n<h2>\u5b89\u88c5\u914d\u7f6e<\/h2>\n<h3>\u65b9\u6cd5\u4e00\uff1a\u4e8c\u8fdb\u5236\u6587\u4ef6\u5b89\u88c5<\/h3>\n<pre><code># \u4e0b\u8f7d Prometheus\nwget https:\/\/github.com\/prometheus\/prometheus\/releases\/download\/v2.47.0\/prometheus-2.47.0.linux-amd64.tar.gz\ntar xvfz prometheus-2.47.0.linux-amd64.tar.gz\ncd prometheus-2.47.0.linux-amd64\/\n\n<h1>\u542f\u52a8\u670d\u52a1<\/h1>\n.\/prometheus --config.file=prometheus.yml\n<\/code><\/pre>\n<h3>\u65b9\u6cd5\u4e8c\uff1aDocker \u5b89\u88c5<\/h3>\n<pre><code>docker run -d \\\n  --name prometheus \\\n  -p 9090:9090 \\\n  -v $(pwd)\/prometheus.yml:\/etc\/prometheus\/prometheus.yml \\\n  prom\/prometheus\n<\/code><\/pre>\n<h3>\u65b9\u6cd5\u4e09\uff1aKubernetes \u5b89\u88c5\uff08\u63a8\u8350\uff09<\/h3>\n<p>\u4f7f\u7528 Helm Chart \u5b89\u88c5\uff1a<\/p>\n<pre><code>helm repo add prometheus-community https:\/\/prometheus-community.github.io\/helm-charts\nhelm install prometheus prometheus-community\/kube-prometheus-stack\n<\/code><\/pre>\n<h2>prometheus.yml \u914d\u7f6e\u793a\u4f8b<\/h2>\n<p>&#8220;`yaml<br \/>\nglobal:<br \/>\n  scrape_interval: 15s      # \u5168\u5c40\u6293\u53d6\u95f4\u9694<br \/>\n  evaluation_interval: 15s  # \u89c4\u5219\u8bc4\u4f30\u95f4\u9694<br \/>\n  external_labels:<br \/>\n    monitor: &#8216;my-project&#8217;<\/p>\n<h1>\u8b66\u62a5\u7ba1\u7406\u5668\u914d\u7f6e<\/h1>\n<p>alerting:<br \/>\n  alertmanagers:<\/p>\n<ul>\n<li>static_configs:<\/li>\n<li>targets:<\/li>\n<li>alertmanager:9093<\/li>\n<\/ul>\n<h1>\u76ee\u6807\u6293\u53d6\u914d\u7f6e<\/h1>\n<p>scrape_configs:<br \/>\n  # Prometheus \u81ea\u8eab\u76d1\u63a7<\/p>\n<ul>\n<li>job_name: &#8216;prometheus&#8217;<\/li>\n<\/ul>\n<p>    static_configs:<\/p>\n<ul>\n<li>targets: [&#8216;localhost:9090&#8217;]<\/li>\n<\/ul>\n<p>  # Kubernetes \u8282\u70b9\u76d1\u63a7<\/p>\n<ul>\n<li>job_name: &#8216;kubernetes-nodes&#8217;<\/li>\n<\/ul>\n<p>    kubernetes_sd_configs:<\/p>\n<ul>\n<li>role: node<\/li>\n<\/ul>\n<p>    relabel_configs:<\/p>\n<ul>\n<li>action: labelmap<\/li>\n<\/ul>\n<p>        regex: __meta_kubernetes_node_label_(.+)<\/p>\n<p>  # Kubernetes Pod \u76d1\u63a7<\/p>\n<ul>\n<li>job_name: &#8216;kubernetes-pods&#8217;<\/li>\n<\/ul>\n<p>    kubernetes_sd_configs:<\/p>\n<ul>\n<li>role: pod<\/li>\n<\/ul>\n<p>    relabel_configs:<\/p>\n<ul>\n<li>source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]<\/li>\n<\/ul>\n<p>        action: keep<br \/>\n        regex: true<\/p>\n<p>  # \u81ea\u5b9a\u4e49\u5e94\u7528\u76d1\u63a7<\/p>\n<ul>\n<li>job_name: &#8216;my-application&#8217;<\/li>\n<\/ul>\n<p>    static_configs:<\/p>\n<ul>\n<li>targets: [&#8216;192.168.1.100:8080&#8217;]<\/li>\n<\/ul>\n<p>    metrics_path: &#8216;\/actuator\/prometheus&#8217;<br \/>\n    relabel_configs:<\/p>\n<ul>\n<li>source_labels: [__address__]<\/li>\n<\/ul>\n<p>        target_label: instance<br \/>\n        regex: &#8216;(.+):(.+)&#8217;<br \/>\n        replacement: &#8216;${1}&#8217;<\/p>\n<p>  # Node Exporter \u7cfb\u7edf\u76d1\u63a7<\/p>\n<ul>\n<li>job_name: &#8216;node&#8217;<\/li>\n<\/ul>\n<p>    static_configs:<\/p>\n<ul>\n<li>targets: [&#8216;node-exporter:9100&#8217;]<\/li>\n<\/ul>\n<pre><code>\n<h2>\u544a\u8b66\u89c4\u5219<\/h2>\n\nPrometheus \u901a\u8fc7\u89c4\u5219\u6587\u4ef6\u5b9a\u4e49\u544a\u8b66\u903b\u8f91\uff1a\n\n<\/code><\/pre>\n<p>yaml<br \/>\ngroups:<\/p>\n<ul>\n<li>name: application_alerts<\/li>\n<\/ul>\n<p>    interval: 30s<br \/>\n    rules:<br \/>\n      # CPU \u4f7f\u7528\u7387\u8fc7\u9ad8\u544a\u8b66<\/p>\n<ul>\n<li>alert: HighCPUUsage<\/li>\n<\/ul>\n<p>        expr: 100 &#8211; (avg by(instance) (irate(node_cpu_seconds_total{mode=&#8221;idle&#8221;}[5m])) * 100) > 80<br \/>\n        for: 5m<br \/>\n        labels:<br \/>\n          severity: warning<br \/>\n        annotations:<br \/>\n          summary: &#8220;\u9ad8 CPU \u4f7f\u7528\u7387\u544a\u8b66&#8221;<br \/>\n          description: &#8220;{{ $labels.instance }} CPU \u4f7f\u7528\u7387\u8d85\u8fc7 80%&#8221;<\/p>\n<p>      # \u5185\u5b58\u4f7f\u7528\u7387\u8fc7\u9ad8\u544a\u8b66<\/p>\n<ul>\n<li>alert: HighMemoryUsage<\/li>\n<\/ul>\n<p>        expr: (1 &#8211; (node_memory_MemAvailable_bytes \/ node_memory_MemTotal_bytes)) * 100 > 85<br \/>\n        for: 5m<br \/>\n        labels:<br \/>\n          severity: critical<br \/>\n        annotations:<br \/>\n          summary: &#8220;\u9ad8\u5185\u5b58\u4f7f\u7528\u7387\u544a\u8b66&#8221;<br \/>\n          description: &#8220;{{ $labels.instance }} \u5185\u5b58\u4f7f\u7528\u7387\u8d85\u8fc7 85%&#8221;<\/p>\n<p>      # \u670d\u52a1\u4e0d\u53ef\u7528\u544a\u8b66<\/p>\n<ul>\n<li>alert: ServiceDown<\/li>\n<\/ul>\n<p>        expr: up == 0<br \/>\n        for: 1m<br \/>\n        labels:<br \/>\n          severity: critical<br \/>\n        annotations:<br \/>\n          summary: &#8220;\u670d\u52a1\u4e0d\u53ef\u7528&#8221;<br \/>\n          description: &#8220;{{ $labels.instance }} \u670d\u52a1\u5df2\u505c\u6b62\u54cd\u5e94&#8221;<\/p>\n<p>      # \u78c1\u76d8\u7a7a\u95f4\u4e0d\u8db3\u544a\u8b66<\/p>\n<ul>\n<li>alert: LowDiskSpace<\/li>\n<\/ul>\n<p>        expr: (node_filesystem_avail_bytes{fstype!=&#8221;tmpfs&#8221;} \/ node_filesystem_size_bytes{fstype!=&#8221;tmpfs&#8221;}) * 100 < 10\n        for: 10m\n        labels:\n          severity: warning\n        annotations:\n          summary: \"\u78c1\u76d8\u7a7a\u95f4\u4e0d\u8db3\"\n          description: \"{{ $labels.instance }} \u78c1\u76d8\u5269\u4f59\u7a7a\u95f4\u4e0d\u8db3 10%\"\n\n\n<pre><code>\n<h2>Grafana \u96c6\u6210<\/h2>\n\nGrafana \u662f Prometheus \u7684\u6700\u4f73\u53ef\u89c6\u5316\u4f34\u4fa3\uff0c\u96c6\u6210\u6b65\u9aa4\u5982\u4e0b\uff1a\n\n<h3>1. \u6dfb\u52a0 Prometheus \u6570\u636e\u6e90<\/h3>\n\n\u5728 Grafana \u4e2d\u914d\u7f6e\u6570\u636e\u6e90\uff1a\n<ul>\n<li>\u8bbf\u95ee Grafana Web \u754c\u9762\uff08\u9ed8\u8ba4\u7aef\u53e3 3000\uff09<\/li>\n<li>\u8fdb\u5165 Configuration \u2192 Data Sources<\/li>\n<li>\u70b9\u51fb \"Add data source\"\uff0c\u9009\u62e9 Prometheus<\/li>\n<li>\u8bbe\u7f6e Server URL: `http:\/\/prometheus:9090`<\/li>\n<li>\u70b9\u51fb \"Save & Test\" \u786e\u8ba4\u8fde\u63a5\u6210\u529f<\/li>\n<\/ul>\n\n<h3>2. \u5bfc\u5165\u9884\u7f6e\u4eea\u8868\u677f<\/h3>\n\nPrometheus \u5b98\u65b9\u63d0\u4f9b\u591a\u4e2a\u9884\u7f6e\u4eea\u8868\u677f\uff1a\n<ul>\n<li>Kubernetes \u76d1\u63a7\u4eea\u8868\u677f\uff08ID: 315\uff09<\/li>\n<li>Node Exporter \u5168\u529f\u80fd\u4eea\u8868\u677f\uff08ID: 1860\uff09<\/li>\n<li>\u81ea\u5b9a\u4e49\u4e1a\u52a1\u76d1\u63a7\u4eea\u8868\u677f<\/li>\n<\/ul>\n\n<h3>3. \u521b\u5efa\u81ea\u5b9a\u4e49\u67e5\u8be2<\/h3>\n\n\u4f7f\u7528 PromQL \u6784\u5efa\u590d\u6742\u67e5\u8be2\uff1a\n<\/code><\/pre>\n<p>promql<\/p>\n<h1>5 \u5206\u949f\u5185\u8bf7\u6c42\u9519\u8bef\u7387\u8d85\u8fc7 5%<\/h1>\n<p>sum(rate(http_requests_total{status=~&#8221;5..&#8221;}[5m])) \/ sum(rate(http_requests_total[5m])) * 100 > 5<\/p>\n<h1>\u6bcf\u79d2\u5e73\u5747\u54cd\u5e94\u65f6\u95f4<\/h1>\n<p>histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m]))<br \/>\n&#8220;`<\/p>\n<h2>\u5b9e\u9645\u5e94\u7528\u573a\u666f<\/h2>\n<h3>\u573a\u666f\u4e00\uff1a\u5fae\u670d\u52a1\u76d1\u63a7<\/h3>\n<p>\u5728 Kubernetes \u96c6\u7fa4\u4e2d\u90e8\u7f72 Prometheus\uff0c\u901a\u8fc7 Service Discovery \u81ea\u52a8\u53d1\u73b0\u6240\u6709\u5fae\u670d\u52a1\u5b9e\u4f8b\uff0c\u76d1\u63a7\u6bcf\u4e2a\u670d\u52a1\u7684 QPS\u3001\u5ef6\u8fdf\u3001\u9519\u8bef\u7387\u7b49\u5173\u952e\u6307\u6807\u3002<\/p>\n<h3>\u573a\u666f\u4e8c\uff1a\u57fa\u7840\u8bbe\u65bd\u76d1\u63a7<\/h3>\n<p>\u90e8\u7f72 Node Exporter \u5230\u6240\u6709\u670d\u52a1\u5668\u8282\u70b9\uff0c\u6536\u96c6 CPU\u3001\u5185\u5b58\u3001\u78c1\u76d8\u3001\u7f51\u7edc\u7b49\u7cfb\u7edf\u7ea7\u6307\u6807\uff0c\u8bbe\u7f6e\u544a\u8b66\u89c4\u5219\u5b9e\u73b0\u6545\u969c\u9884\u8b66\u3002<\/p>\n<h3>\u573a\u666f\u4e09\uff1a\u4e1a\u52a1\u6307\u6807\u76d1\u63a7<\/h3>\n<p>\u901a\u8fc7 Exporter \u6216\u81ea\u5b9a\u4e49\u4ee3\u7801\u66b4\u9732\u4e1a\u52a1\u6307\u6807\uff0c\u5982\u8ba2\u5355\u91cf\u3001\u7528\u6237\u6d3b\u8dc3\u5ea6\u3001\u652f\u4ed8\u6210\u529f\u7387\u7b49\uff0c\u7ed3\u5408 Grafana \u5b9e\u73b0\u4e1a\u52a1\u6570\u636e\u53ef\u89c6\u5316\u3002<\/p>\n<h3>\u573a\u666f\u56db\uff1a\u65e5\u5fd7\u805a\u5408\u4e0e\u5206\u6790<\/h3>\n<p>\u914d\u5408 Loki \u548c Promtail \u5b9e\u73b0\u65e5\u5fd7\u4e0e\u6307\u6807\u7684\u5173\u8054\u5206\u6790\uff0c\u5feb\u901f\u5b9a\u4f4d\u6545\u969c\u6839\u56e0\u3002<\/p>\n<h2>\u6700\u4f73\u5b9e\u8df5\u5efa\u8bae<\/h2>\n<ol>\n<li><strong>\u5408\u7406\u7684\u6307\u6807\u91c7\u96c6\u9891\u7387<\/strong>\uff1a\u907f\u514d\u8fc7\u9ad8\u9891\u7387\u5bfc\u81f4\u6027\u80fd\u5f00\u9500\uff0c\u4e00\u822c 15-30 \u79d2\u4e3a\u5b9c\u3002<\/li>\n<li><strong>\u6807\u7b7e\u4f18\u5316<\/strong>\uff1a\u907f\u514d\u9ad8\u57fa\u6570\u6807\u7b7e\u5bfc\u81f4\u5b58\u50a8\u81a8\u80c0\uff0c\u5408\u7406\u63a7\u5236\u6807\u7b7e\u503c\u6570\u91cf\u3002<\/li>\n<li><strong>\u544a\u8b66\u964d\u566a<\/strong>\uff1a\u901a\u8fc7\u5206\u7ec4\u3001\u6291\u5236\u89c4\u5219\u51cf\u5c11\u544a\u8b66\u98ce\u66b4\uff0c\u786e\u4fdd\u544a\u8b66\u6709\u6548\u6027\u3002<\/li>\n<li><strong>\u6570\u636e\u4fdd\u7559\u7b56\u7565<\/strong>\uff1a\u6839\u636e\u4e1a\u52a1\u9700\u6c42\u914d\u7f6e\u5408\u9002\u7684\u6570\u636e\u4fdd\u7559\u671f\u9650\uff0c\u5e73\u8861\u5b58\u50a8\u6210\u672c\u3002<\/li>\n<li><strong>\u5b9a\u671f\u5907\u4efd<\/strong>\uff1a\u5b9a\u671f\u5907\u4efd Prometheus \u6570\u636e\u76ee\u5f55\uff0c\u9632\u6b62\u6570\u636e\u4e22\u5931\u3002<\/li>\n<\/ul>\n<p>&#8212;<\/p>\n<p><strong>\u7ed3\u8bed<\/strong>\uff1aPrometheus \u4ee5\u5176\u7b80\u6d01\u7684\u8bbe\u8ba1\u3001\u5f3a\u5927\u7684\u67e5\u8be2\u80fd\u529b\u548c\u6d3b\u8dc3\u7684\u751f\u6001\u7cfb\u7edf\uff0c\u6210\u4e3a\u4e91\u539f\u751f\u65f6\u4ee3\u7684\u6807\u51c6\u76d1\u63a7\u89e3\u51b3\u65b9\u6848\u3002\u638c\u63e1 Prometheus \u7684\u6838\u5fc3\u6982\u5ff5\u548c\u4f7f\u7528\u65b9\u6cd5\uff0c\u5c06\u5927\u5927\u63d0\u5347\u4f60\u7684\u7cfb\u7edf\u53ef\u89c2\u6d4b\u6027\u548c\u8fd0\u7ef4\u6548\u7387\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prometheus \u76d1\u63a7\u7cfb\u7edf\u8be6\u7ec6\u4f7f\u7528\u6559\u7a0b \u6838\u5fc3\u6982\u5ff5 Prometheus \u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u7cfb\u7edf\u76d1\u63a7\u548c\u8b66\u62a5\u5de5\u5177\u5305\uff0c&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-15918","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/posts\/15918","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/comments?post=15918"}],"version-history":[{"count":0,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/posts\/15918\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/media?parent=15918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/categories?post=15918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/tags?post=15918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}