{"id":94008,"date":"2026-08-13T13:25:11","date_gmt":"2026-08-13T05:25:11","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/94008.html"},"modified":"2026-08-13T13:25:11","modified_gmt":"2026-08-13T05:25:11","slug":"prometheus-loki-%e5%85%a8%e6%a0%88%e5%ae%9e%e6%88%98%ef%bc%9a%e6%a0%87%e7%ad%be%e5%85%b1%e4%ba%ab%e4%b8%8b%e7%9a%84%e6%97%a5%e5%bf%97%e4%b8%8e%e6%8c%87%e6%a0%87%e8%9e%8d%e5%90%88%e5%8f%af%e8%a7%82","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/94008.html","title":{"rendered":"Prometheus Loki \u5168\u6808\u5b9e\u6218\uff1a\u6807\u7b7e\u5171\u4eab\u4e0b\u7684\u65e5\u5fd7\u4e0e\u6307\u6807\u878d\u5408\u53ef\u89c2\u6d4b\u6027"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813052501-6a7d552d3a309.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>Prometheus Loki \u5168\u6808\u5b9e\u6218&#xff1a;\u6807\u7b7e\u5171\u4eab\u4e0b\u7684\u65e5\u5fd7\u4e0e\u6307\u6807\u878d\u5408\u53ef\u89c2\u6d4b\u6027<\/h3>\n<hr \/>\n<p>\u5728\u73b0\u4ee3\u53ef\u89c2\u6d4b\u6027\u4f53\u7cfb\u4e2d&#xff0c;Metrics&#xff08;\u6307\u6807&#xff09; \u544a\u8bc9\u6211\u4eec\u7cfb\u7edf\u54ea\u91cc\u51fa\u4e86\u95ee\u9898&#xff0c;Logs&#xff08;\u65e5\u5fd7&#xff09; \u5219\u89e3\u91ca\u95ee\u9898\u53d1\u751f\u7684\u539f\u56e0\u3002Prometheus \u8d1f\u8d23\u6307\u6807&#xff0c;\u800c Grafana Loki \u662f\u4e13\u95e8\u4e3a Prometheus \u751f\u6001\u8bbe\u8ba1\u7684\u8f7b\u91cf\u7ea7\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u3002\u4e8c\u8005\u6700\u5927\u7684\u534f\u540c\u79d8\u5bc6\u5728\u4e8e&#xff1a;Loki \u4f7f\u7528\u4e0e Prometheus \u5b8c\u5168\u76f8\u540c\u7684\u6807\u7b7e\u6a21\u578b\u6765\u7d22\u5f15\u548c\u67e5\u8be2\u65e5\u5fd7\u3002\u8fd9\u610f\u5473\u7740\u4f60\u53ef\u4ee5\u7528\u4e00\u6a21\u4e00\u6837\u7684 {job&#061;&#034;nginx&#034;, env&#061;&#034;prod&#034;} \u6807\u7b7e\u9009\u62e9\u5668&#xff0c;\u5728 Grafana \u4e2d\u65e0\u7f1d\u5730\u4ece\u6307\u6807\u8df3\u8f6c\u5230\u65e5\u5fd7&#xff0c;\u771f\u6b63\u5b9e\u73b0\u201c\u6307\u6807\u53d1\u73b0\u95ee\u9898&#xff0c;\u65e5\u5fd7\u5b9a\u4f4d\u6839\u56e0\u201d\u7684\u95ed\u73af\u3002\u672c\u6587\u5c06\u5e26\u4f60\u4ece\u96f6\u90e8\u7f72 Loki \u4e0e Promtail&#xff0c;\u914d\u7f6e\u6807\u7b7e\u6620\u5c04&#xff0c;\u5728 Grafana \u4e2d\u6784\u5efa\u8054\u52a8\u770b\u677f&#xff0c;\u5e76\u843d\u5730\u9488\u5bf9\u65e5\u5fd7\u672c\u8eab\u7684\u76d1\u63a7\u4e0e\u544a\u8b66&#xff0c;\u8ba9\u4f60\u7684\u65e5\u5fd7\u7ba1\u9053\u4e5f\u5177\u5907\u5b8c\u6574\u7684\u53ef\u89c2\u6d4b\u6027\u3002<\/p>\n<hr \/>\n<h4>1. Loki &#043; Prometheus&#xff1a;\u6807\u7b7e\u5171\u4eab\u7684\u672c\u8d28<\/h4>\n<table>\n<tr>\u7279\u6027\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u7d22\u5f15\u6a21\u578b<\/td>\n<td>Loki \u4e0d\u7d22\u5f15\u65e5\u5fd7\u5168\u6587&#xff0c;\u800c\u662f\u7d22\u5f15\u5143\u6570\u636e\u6807\u7b7e&#xff08;\u5982 job, instance, env&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u6807\u7b7e\u6765\u6e90<\/td>\n<td>Promtail \u6216\u5ba2\u6237\u7aef\u81ea\u52a8\u4e3a\u65e5\u5fd7\u9644\u52a0\u6807\u7b7e&#xff0c;\u901a\u5e38\u6765\u81ea\u670d\u52a1\u53d1\u73b0\u548c\u6587\u4ef6\u8def\u5f84<\/td>\n<\/tr>\n<tr>\n<td>Prometheus \u517c\u5bb9<\/td>\n<td>\u6807\u7b7e\u540d\u5b8c\u5168\u517c\u5bb9 Prometheus \u89c4\u5219&#xff08;\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u4e0b\u5212\u7ebf&#xff09;&#xff0c;\u67e5\u8be2\u8bed\u6cd5\u76f8\u540c<\/td>\n<\/tr>\n<tr>\n<td>\u5173\u8054\u67e5\u8be2<\/td>\n<td>\u5728 Grafana \u4e2d&#xff0c;\u53ef\u901a\u8fc7\u76f8\u540c\u6807\u7b7e\u503c\u76f4\u63a5\u8df3\u8f6c&#xff08;\u4f8b\u5982 {job&#061;&#034;api&#034;} \u67e5\u770b\u65e5\u5fd7&#xff0c;rate(http_requests_total{job&#061;&#034;api&#034;}[5m]) \u67e5\u770b\u6307\u6807&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u79cd\u8bbe\u8ba1\u8ba9 Loki \u6210\u4e3a\u4e00\u4e2a\u201c\u6307\u6807\u822c\u7684\u65e5\u5fd7\u7cfb\u7edf\u201d&#xff0c;\u51e0\u4e4e\u4e0d\u9700\u8981\u5b66\u4e60\u65b0\u8bed\u8a00&#xff0c;\u4e5f\u5927\u5927\u964d\u4f4e\u4e86\u4e0e Prometheus \u96c6\u6210\u7684\u95e8\u69db\u3002<\/p>\n<hr \/>\n<h4>2. Loki \u67b6\u6784\u7b80\u4ecb<\/h4>\n<p>Loki \u91c7\u7528\u7c7b\u4f3c Prometheus \u7684\u8bfb\u5199\u8def\u5f84&#xff1a;<\/p>\n<ul>\n<li>Distributor&#xff1a;\u63a5\u6536\u65e5\u5fd7&#xff0c;\u9a8c\u8bc1\u5e76\u5206\u53d1\u5230 Ingester\u3002<\/li>\n<li>Ingester&#xff1a;\u7f13\u5b58\u65e5\u5fd7\u5e76\u5199\u5165\u5bf9\u8c61\u5b58\u50a8\u3002<\/li>\n<li>Querier&#xff1a;\u5904\u7406\u67e5\u8be2&#xff0c;\u4ece Ingester \u548c\u5b58\u50a8\u4e2d\u83b7\u53d6\u65e5\u5fd7\u3002<\/li>\n<li>Ruler&#xff08;\u53ef\u9009&#xff09;&#xff1a;\u7528\u4e8e\u65e5\u5fd7\u544a\u8b66\u89c4\u5219\u8bc4\u4f30&#xff08;\u81ea 2.0 \u8d77\u652f\u6301&#xff09;\u3002<\/li>\n<li>Promtail&#xff1a;\u90e8\u7f72\u5728\u6bcf\u53f0\u673a\u5668\u4e0a&#xff0c;\u91c7\u96c6\u65e5\u5fd7\u5e76\u63a8\u9001\u5230 Loki&#xff0c;\u540c\u65f6\u81ea\u52a8\u9644\u52a0\u6807\u7b7e\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>3. \u90e8\u7f72 Loki \u4e0e Promtail<\/h4>\n<p>\u63a8\u8350\u4f7f\u7528 Docker Compose \u5feb\u901f\u642d\u5efa&#xff0c;\u6216\u57fa\u4e8e Helm \u90e8\u7f72\u5728 Kubernetes \u4e2d\u3002<\/p>\n<h5>3.1 Docker Compose \u65b9\u6848<\/h5>\n<p>docker-compose.yml&#xff1a;<\/p>\n<p><span class=\"token key atrule\">version<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;3&#034;<\/span><br \/>\n<span class=\"token key atrule\">services<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">loki<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">image<\/span><span class=\"token punctuation\">:<\/span> grafana\/loki<span class=\"token punctuation\">:<\/span>2.9.0<br \/>\n    <span class=\"token key atrule\">ports<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token string\">&#034;3100:3100&#034;<\/span><br \/>\n    <span class=\"token key atrule\">command<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">&#8211;<\/span>config.file&#061;\/etc\/loki\/loki<span class=\"token punctuation\">&#8211;<\/span>config.yaml<br \/>\n    <span class=\"token key atrule\">volumes<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> .\/loki<span class=\"token punctuation\">&#8211;<\/span>config.yaml<span class=\"token punctuation\">:<\/span>\/etc\/loki\/loki<span class=\"token punctuation\">&#8211;<\/span>config.yaml<br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> loki_data<span class=\"token punctuation\">:<\/span>\/loki<\/p>\n<p>  <span class=\"token key atrule\">promtail<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">image<\/span><span class=\"token punctuation\">:<\/span> grafana\/promtail<span class=\"token punctuation\">:<\/span>2.9.0<br \/>\n    <span class=\"token key atrule\">volumes<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> .\/promtail<span class=\"token punctuation\">&#8211;<\/span>config.yaml<span class=\"token punctuation\">:<\/span>\/etc\/promtail\/promtail<span class=\"token punctuation\">&#8211;<\/span>config.yaml<br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> \/var\/log<span class=\"token punctuation\">:<\/span>\/var\/log<br \/>\n    <span class=\"token key atrule\">command<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">&#8211;<\/span>config.file&#061;\/etc\/promtail\/promtail<span class=\"token punctuation\">&#8211;<\/span>config.yaml<\/p>\n<p>  <span class=\"token comment\"># \u53ef\u9009&#xff1a;\u6dfb\u52a0 Grafana<\/span><br \/>\n  <span class=\"token key atrule\">grafana<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">image<\/span><span class=\"token punctuation\">:<\/span> grafana\/grafana<span class=\"token punctuation\">:<\/span>latest<br \/>\n    <span class=\"token key atrule\">ports<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token string\">&#034;3000:3000&#034;<\/span><br \/>\n    <span class=\"token key atrule\">environment<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> GF_AUTH_ANONYMOUS_ENABLED&#061;true<br \/>\n<span class=\"token key atrule\">volumes<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">loki_data<\/span><span class=\"token punctuation\">:<\/span><\/p>\n<h5>3.2 Loki \u914d\u7f6e (loki-config.yaml)<\/h5>\n<p><span class=\"token key atrule\">auth_enabled<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token boolean important\">false<\/span><\/p>\n<p><span class=\"token key atrule\">server<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">http_listen_port<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">3100<\/span><\/p>\n<p><span class=\"token key atrule\">ingester<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">lifecycler<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">ring<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token key atrule\">kvstore<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token key atrule\">store<\/span><span class=\"token punctuation\">:<\/span> inmemory<br \/>\n      <span class=\"token key atrule\">replication_factor<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">1<\/span><br \/>\n  <span class=\"token key atrule\">chunk_idle_period<\/span><span class=\"token punctuation\">:<\/span> 5m<br \/>\n  <span class=\"token key atrule\">chunk_retain_period<\/span><span class=\"token punctuation\">:<\/span> 30s<br \/>\n  <span class=\"token key atrule\">max_transfer_retries<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">0<\/span><\/p>\n<p><span class=\"token key atrule\">schema_config<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">configs<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">from<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token datetime number\">2024-01-01<\/span><br \/>\n      <span class=\"token key atrule\">store<\/span><span class=\"token punctuation\">:<\/span> boltdb<span class=\"token punctuation\">&#8211;<\/span>shipper<br \/>\n      <span class=\"token key atrule\">object_store<\/span><span class=\"token punctuation\">:<\/span> filesystem<br \/>\n      <span class=\"token key atrule\">schema<\/span><span class=\"token punctuation\">:<\/span> v11<br \/>\n      <span class=\"token key atrule\">index<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token key atrule\">prefix<\/span><span class=\"token punctuation\">:<\/span> index_<br \/>\n        <span class=\"token key atrule\">period<\/span><span class=\"token punctuation\">:<\/span> 24h<\/p>\n<p><span class=\"token key atrule\">storage_config<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">boltdb_shipper<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">active_index_directory<\/span><span class=\"token punctuation\">:<\/span> \/loki\/index<br \/>\n    <span class=\"token key atrule\">cache_location<\/span><span class=\"token punctuation\">:<\/span> \/loki\/index_cache<br \/>\n    <span class=\"token key atrule\">cache_ttl<\/span><span class=\"token punctuation\">:<\/span> 24h<br \/>\n  <span class=\"token key atrule\">filesystem<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">directory<\/span><span class=\"token punctuation\">:<\/span> \/loki\/chunks<\/p>\n<p><span class=\"token key atrule\">limits_config<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">reject_old_samples<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token boolean important\">true<\/span><br \/>\n  <span class=\"token key atrule\">reject_old_samples_max_age<\/span><span class=\"token punctuation\">:<\/span> 168h<br \/>\n  <span class=\"token key atrule\">max_entries_limit_per_query<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">5000<\/span><\/p>\n<h5>3.3 Promtail \u914d\u7f6e (promtail-config.yaml)<\/h5>\n<p><span class=\"token key atrule\">server<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">http_listen_port<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">9080<\/span><br \/>\n  <span class=\"token key atrule\">grpc_listen_port<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">0<\/span><\/p>\n<p><span class=\"token key atrule\">clients<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">url<\/span><span class=\"token punctuation\">:<\/span> http<span class=\"token punctuation\">:<\/span>\/\/loki<span class=\"token punctuation\">:<\/span>3100\/loki\/api\/v1\/push<\/p>\n<p><span class=\"token key atrule\">scrape_configs<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">job_name<\/span><span class=\"token punctuation\">:<\/span> system<br \/>\n    <span class=\"token key atrule\">static_configs<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">targets<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token punctuation\">&#8211;<\/span> localhost<br \/>\n        <span class=\"token key atrule\">labels<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token key atrule\">job<\/span><span class=\"token punctuation\">:<\/span> varlogs<br \/>\n          <span class=\"token key atrule\">__path__<\/span><span class=\"token punctuation\">:<\/span> \/var\/log\/<span class=\"token important\">*.log<\/span><\/p>\n<p>  <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">job_name<\/span><span class=\"token punctuation\">:<\/span> docker<br \/>\n    <span class=\"token key atrule\">static_configs<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">targets<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token punctuation\">&#8211;<\/span> localhost<br \/>\n        <span class=\"token key atrule\">labels<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token key atrule\">job<\/span><span class=\"token punctuation\">:<\/span> docker<br \/>\n          <span class=\"token key atrule\">__path__<\/span><span class=\"token punctuation\">:<\/span> \/var\/lib\/docker\/containers\/<span class=\"token important\">*\/*.log<\/span><\/p>\n<p>  <span class=\"token comment\"># \u53ef\u9488\u5bf9\u7279\u5b9a\u5e94\u7528\u6dfb\u52a0\u66f4\u7ec6\u7c92\u5ea6\u7684\u6807\u7b7e<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">job_name<\/span><span class=\"token punctuation\">:<\/span> nginx<br \/>\n    <span class=\"token key atrule\">static_configs<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">targets<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token punctuation\">&#8211;<\/span> localhost<br \/>\n        <span class=\"token key atrule\">labels<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token key atrule\">job<\/span><span class=\"token punctuation\">:<\/span> nginx<br \/>\n          <span class=\"token key atrule\">app<\/span><span class=\"token punctuation\">:<\/span> web<br \/>\n          <span class=\"token key atrule\">__path__<\/span><span class=\"token punctuation\">:<\/span> \/var\/log\/nginx\/<span class=\"token important\">*.log<\/span><\/p>\n<p>\u5173\u952e\u70b9&#xff1a;Promtail \u7684 labels \u4e2d\u7684 job\u3001app \u7b49\u4f1a\u76f4\u63a5\u6210\u4e3a Loki \u7684\u7d22\u5f15\u6807\u7b7e&#xff0c;\u800c __path__ \u662f\u5185\u90e8\u53d1\u73b0\u6807\u7b7e&#xff0c;\u4e0d\u4f1a\u8fdb\u5165\u65e5\u5fd7\u6d41\u3002<\/p>\n<hr \/>\n<h4>4. \u4e0e Prometheus \u6807\u7b7e\u5bf9\u9f50\u7684\u6700\u4f73\u5b9e\u8df5<\/h4>\n<p>\u4e3a\u4e86\u8ba9 Loki \u4e0e Prometheus \u65e0\u7f1d\u8054\u52a8&#xff0c;\u6807\u7b7e\u547d\u540d\u548c\u53d6\u503c\u5e94\u4e0e Prometheus \u5b8c\u5168\u4e00\u81f4&#xff1a;<\/p>\n<table>\n<tr>Prometheus \u5e38\u89c1\u6807\u7b7eLoki \u5e94\u4f7f\u7528\u76f8\u540c\u6807\u7b7e\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>job&#061;&#034;nginx&#034;<\/td>\n<td>job&#061;&#034;nginx&#034;<\/td>\n<td>\u4e8c\u8005\u6293\u53d6\u914d\u7f6e\u7684 job \u540d\u5e94\u4e00\u81f4<\/td>\n<\/tr>\n<tr>\n<td>instance&#061;&#034;web-01&#034;<\/td>\n<td>instance&#061;&#034;web-01&#034;<\/td>\n<td>\u4e3b\u673a\u540d\u6216\u5b9e\u4f8b ID<\/td>\n<\/tr>\n<tr>\n<td>env&#061;&#034;prod&#034;<\/td>\n<td>env&#061;&#034;prod&#034;<\/td>\n<td>\u73af\u5883\u6807\u7b7e<\/td>\n<\/tr>\n<tr>\n<td>app&#061;&#034;order-service&#034;<\/td>\n<td>app&#061;&#034;order-service&#034;<\/td>\n<td>\u5e94\u7528\u540d\u79f0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5728 Promtail \u7684 static_configs \u6216 kubernetes_sd_configs \u4e2d&#xff0c;\u4ece\u76ee\u6807\u5143\u6570\u636e\u63d0\u53d6\u8fd9\u4e9b\u6807\u7b7e\u5e76\u91cd\u547d\u540d&#xff0c;\u786e\u4fdd\u4e0e Prometheus \u6293\u53d6\u7684\u6807\u7b7e\u76f8\u540c\u3002<\/p>\n<p>\u793a\u4f8b&#xff1a;Kubernetes \u73af\u5883\u4e0b\u7684\u6807\u7b7e\u5bf9\u9f50<\/p>\n<p><span class=\"token comment\"># Promtail \u5728 K8s \u4e2d\u7684\u91c7\u96c6\u914d\u7f6e<\/span><br \/>\n<span class=\"token key atrule\">scrape_configs<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">job_name<\/span><span class=\"token punctuation\">:<\/span> kubernetes<span class=\"token punctuation\">&#8211;<\/span>pods<br \/>\n    <span class=\"token key atrule\">kubernetes_sd_configs<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">role<\/span><span class=\"token punctuation\">:<\/span> pod<br \/>\n    <span class=\"token key atrule\">relabel_configs<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">source_labels<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token punctuation\">&#8211;<\/span> __meta_kubernetes_pod_label_app<br \/>\n        <span class=\"token key atrule\">target_label<\/span><span class=\"token punctuation\">:<\/span> app<br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">source_labels<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token punctuation\">&#8211;<\/span> __meta_kubernetes_namespace<br \/>\n        <span class=\"token key atrule\">target_label<\/span><span class=\"token punctuation\">:<\/span> namespace<br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">action<\/span><span class=\"token punctuation\">:<\/span> replace<br \/>\n        <span class=\"token key atrule\">source_labels<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token punctuation\">&#8211;<\/span> __meta_kubernetes_pod_name<br \/>\n        <span class=\"token key atrule\">target_label<\/span><span class=\"token punctuation\">:<\/span> instance<br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">action<\/span><span class=\"token punctuation\">:<\/span> labelmap<br \/>\n        <span class=\"token key atrule\">regex<\/span><span class=\"token punctuation\">:<\/span> __meta_kubernetes_pod_label_(.&#043;)<\/p>\n<p>\u8fd9\u6837&#xff0c;Loki \u4e2d\u7684 {app&#061;&#034;order-service&#034;, namespace&#061;&#034;production&#034;} \u5c31\u80fd\u5339\u914d Prometheus \u4e2d app&#061;&#034;order-service&#034;, namespace&#061;&#034;production&#034; \u7684\u6307\u6807\u3002<\/p>\n<hr \/>\n<h4>5. \u5728 Grafana \u4e2d\u5b9e\u73b0\u6307\u6807\u4e0e\u65e5\u5fd7\u8054\u52a8<\/h4>\n<h5>5.1 \u6dfb\u52a0 Loki \u6570\u636e\u6e90<\/h5>\n<p>\u5728 Grafana \u914d\u7f6e\u4e2d\u6dfb\u52a0 Loki \u6570\u636e\u6e90&#xff0c;URL \u6307\u5411 http:\/\/loki:3100\u3002\u4fdd\u5b58\u540e\u5373\u53ef\u5728 Explore \u4e2d\u67e5\u8be2\u65e5\u5fd7\u3002<\/p>\n<h5>5.2 \u521b\u5efa\u8054\u52a8\u4eea\u8868\u76d8<\/h5>\n<p>\u5728\u76d1\u63a7\u9762\u677f\u4e2d&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u4ece\u6307\u6807\u56fe\u5f62\u8df3\u8f6c\u5230 Loki \u67e5\u8be2&#xff1a;<\/p>\n<ul>\n<li>\u7f16\u8f91 Prometheus \u9762\u677f&#xff0c;\u5728 Links \u4e2d\u6dfb\u52a0\u4e00\u6761&#xff1a;\n<ul>\n<li>\u7c7b\u578b&#xff1a;Data link<\/li>\n<li>URL&#xff1a;\/explore?left&#061;{&#034;datasource&#034;:&#034;Loki&#034;,&#034;queries&#034;:[{&#034;expr&#034;:&#034;{app&#061;\\\\&#034;${app:queryparam}\\\\&#034;, job&#061;\\\\&#034;${job:queryparam}\\\\&#034;}&#034;}]}<\/li>\n<li>\u8fd9\u6837\u70b9\u51fb\u56fe\u5f62\u4e0a\u67d0\u4e2a\u65f6\u95f4\u70b9&#xff0c;\u5c31\u4f1a\u6253\u5f00\u5bf9\u5e94\u6807\u7b7e\u7684\u65e5\u5fd7\u4e0a\u4e0b\u6587\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u6216\u8005\u5728 Grafana 8&#043; \u7248\u672c\u4e2d&#xff0c;\u4f7f\u7528 Logs \u9762\u677f \u76f4\u63a5\u653e\u5728\u6307\u6807\u9762\u677f\u4e0b\u65b9&#xff0c;\u8fc7\u6ee4\u76f8\u540c\u6807\u7b7e\u3002<\/p>\n<p>Grafana \u5185\u7f6e\u7684 Loki \u67e5\u8be2\u53d8\u91cf \u53ef\u4ee5\u4ece Prometheus \u6307\u6807\u7684\u503c\u52a8\u6001\u751f\u6210&#xff0c;\u4f8b\u5982\u67e5\u8be2 {job&#061;&#034;nginx&#034;} \u4e2d\u7684\u552f\u4e00 host \u6807\u7b7e\u3002<\/p>\n<hr \/>\n<h4>6. \u76d1\u63a7 Loki \u81ea\u8eab&#xff1a;\u8ba9\u65e5\u5fd7\u7ba1\u9053\u4e5f\u900f\u660e<\/h4>\n<p>Loki \u66b4\u9732 Prometheus \u6307\u6807\u7aef\u70b9&#xff08;\u9ed8\u8ba4 http:\/\/loki:3100\/metrics&#xff09;&#xff0c;\u5305\u542b\u7ec4\u4ef6\u5065\u5eb7\u3001\u8bf7\u6c42\u5ef6\u8fdf\u3001Ingester \u5185\u5b58\u3001\u5b58\u50a8\u64cd\u4f5c\u7b49\u3002Promtail \u4e5f\u66b4\u9732\u7aef\u70b9&#xff08;http:\/\/promtail:9080\/metrics&#xff09;\u3002<\/p>\n<h5>6.1 \u914d\u7f6e Prometheus \u6293\u53d6 Loki \u6307\u6807<\/h5>\n<p><span class=\"token key atrule\">scrape_configs<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">job_name<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;loki&#039;<\/span><br \/>\n    <span class=\"token key atrule\">scrape_interval<\/span><span class=\"token punctuation\">:<\/span> 15s<br \/>\n    <span class=\"token key atrule\">static_configs<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">targets<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;loki:3100&#039;<\/span><span class=\"token punctuation\">]<\/span><br \/>\n        <span class=\"token key atrule\">labels<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token key atrule\">component<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;loki&#039;<\/span><\/p>\n<p>  <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">job_name<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;promtail&#039;<\/span><br \/>\n    <span class=\"token key atrule\">scrape_interval<\/span><span class=\"token punctuation\">:<\/span> 15s<br \/>\n    <span class=\"token key atrule\">static_configs<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">targets<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;promtail:9080&#039;<\/span><span class=\"token punctuation\">]<\/span><br \/>\n        <span class=\"token key atrule\">labels<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token key atrule\">component<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;promtail&#039;<\/span><\/p>\n<h5>6.2 \u6838\u5fc3 Loki \u6307\u6807\u4e0e PromQL<\/h5>\n<table>\n<tr>\u6307\u6807\u542b\u4e49<\/tr>\n<tbody>\n<tr>\n<td>loki_distributor_lines_received_total<\/td>\n<td>\u63a5\u6536\u5230\u7684\u65e5\u5fd7\u884c\u6570<\/td>\n<\/tr>\n<tr>\n<td>loki_ingester_chunks_flushed_total<\/td>\n<td>\u5237\u76d8\u5230\u5b58\u50a8\u7684\u5757\u6570\u91cf<\/td>\n<\/tr>\n<tr>\n<td>loki_ingester_memory_streams<\/td>\n<td>\u5185\u5b58\u4e2d\u7684\u65e5\u5fd7\u6d41\u6570\u91cf<\/td>\n<\/tr>\n<tr>\n<td>loki_request_duration_seconds_bucket<\/td>\n<td>Loki API \u8bf7\u6c42\u5ef6\u8fdf\u76f4\u65b9\u56fe<\/td>\n<\/tr>\n<tr>\n<td>promtail_read_lines_total<\/td>\n<td>Promtail \u8bfb\u53d6\u7684\u65e5\u5fd7\u884c\u6570<\/td>\n<\/tr>\n<tr>\n<td>promtail_dropped_lines_total<\/td>\n<td>\u4e22\u5f03\u7684\u884c\u6570&#xff08;\u5982\u56e0\u901f\u7387\u9650\u5236&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>promtail_file_fd_open_total<\/td>\n<td>\u6253\u5f00\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>PromQL \u793a\u4f8b&#xff1a;<\/p>\n<ul>\n<li>Loki \u65e5\u5fd7\u63a5\u6536\u901f\u7387&#xff1a;rate(loki_distributor_lines_received_total[5m])<\/li>\n<li>Ingester \u5185\u5b58\u538b\u529b&#xff1a;loki_ingester_memory_streams &gt; 10000<\/li>\n<li>Promtail \u662f\u5426\u6709\u65e5\u5fd7\u4e22\u5f03&#xff1a;rate(promtail_dropped_lines_total[5m]) &gt; 0<\/li>\n<\/ul>\n<h5>6.3 Grafana \u4eea\u8868\u76d8\u63a8\u8350<\/h5>\n<ul>\n<li>Loki Dashboard&#xff1a;ID 14055&#xff08;\u5b98\u65b9\u53d1\u5e03&#xff09;&#xff0c;\u5168\u9762\u5c55\u793a Loki \u5404\u7ec4\u4ef6\u72b6\u6001\u3002<\/li>\n<li>Loki Metrics&#xff1a;ID 13639&#xff0c;\u805a\u7126\u5199\u5165\u3001\u67e5\u8be2\u3001\u5b58\u50a8\u6027\u80fd\u3002<\/li>\n<li>Promtail Dashboard&#xff1a;ID 10880&#xff0c;\u76d1\u63a7\u91c7\u96c6\u4ee3\u7406\u5065\u5eb7\u3002<\/li>\n<\/ul>\n<p>\u5bfc\u5165\u540e\u9009\u62e9\u6570\u636e\u6e90&#xff0c;\u7528 component \u53d8\u91cf\u8fc7\u6ee4\u3002<\/p>\n<hr \/>\n<h4>7. \u57fa\u4e8e Loki \u65e5\u5fd7\u7684\u544a\u8b66\u89c4\u5219<\/h4>\n<p>\u4ece Loki 2.0 \u5f00\u59cb&#xff0c;\u5185\u7f6e\u4e86 Ruler \u7ec4\u4ef6&#xff0c;\u53ef\u4ee5\u50cf Prometheus \u4e00\u6837\u5b9a\u4e49\u57fa\u4e8e\u65e5\u5fd7\u6d41\u91cf\u7684\u544a\u8b66\u89c4\u5219&#xff0c;\u5e76\u7531 Alertmanager \u53d1\u9001\u901a\u77e5\u3002<\/p>\n<h5>7.1 \u542f\u7528 Loki Ruler<\/h5>\n<p>\u5728 loki-config.yaml \u4e2d\u6dfb\u52a0&#xff1a;<\/p>\n<p><span class=\"token key atrule\">ruler<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">storage<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">type<\/span><span class=\"token punctuation\">:<\/span> local<br \/>\n    <span class=\"token key atrule\">local<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token key atrule\">directory<\/span><span class=\"token punctuation\">:<\/span> \/loki\/rules<br \/>\n  <span class=\"token key atrule\">rule_path<\/span><span class=\"token punctuation\">:<\/span> \/loki\/rules\/fake<br \/>\n  <span class=\"token key atrule\">alertmanager_url<\/span><span class=\"token punctuation\">:<\/span> http<span class=\"token punctuation\">:<\/span>\/\/alertmanager<span class=\"token punctuation\">:<\/span><span class=\"token number\">9093<\/span><br \/>\n  <span class=\"token key atrule\">ring<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">kvstore<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token key atrule\">store<\/span><span class=\"token punctuation\">:<\/span> inmemory<\/p>\n<h5>7.2 \u5b9a\u4e49\u65e5\u5fd7\u544a\u8b66\u89c4\u5219<\/h5>\n<p>\u5728 \/loki\/rules\/fake\/rules.yml \u4e2d\u7f16\u5199&#xff1a;<\/p>\n<p><span class=\"token key atrule\">groups<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">name<\/span><span class=\"token punctuation\">:<\/span> loki<span class=\"token punctuation\">&#8211;<\/span>log<span class=\"token punctuation\">&#8211;<\/span>alerts<br \/>\n    <span class=\"token key atrule\">rules<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">alert<\/span><span class=\"token punctuation\">:<\/span> HighErrorLogRate<br \/>\n        <span class=\"token key atrule\">expr<\/span><span class=\"token punctuation\">:<\/span> sum(rate(<span class=\"token punctuation\">{<\/span>job&#061;&#034;nginx&#034;<span class=\"token punctuation\">}<\/span> <span class=\"token punctuation\">|<\/span>~ &#034;500<span class=\"token punctuation\">|<\/span>error&#034; <span class=\"token punctuation\">[<\/span>5m<span class=\"token punctuation\">]<\/span>)) <span class=\"token punctuation\">&gt;<\/span> 0.5<br \/>\n        <span class=\"token key atrule\">for<\/span><span class=\"token punctuation\">:<\/span> 5m<br \/>\n        <span class=\"token key atrule\">labels<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token key atrule\">severity<\/span><span class=\"token punctuation\">:<\/span> critical<br \/>\n        <span class=\"token key atrule\">annotations<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token key atrule\">summary<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;Nginx \u9519\u8bef\u65e5\u5fd7\u901f\u7387\u8fc7\u9ad8&#034;<\/span><br \/>\n          <span class=\"token key atrule\">description<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;\u8fc7\u53bb 5 \u5206\u949f\u5e73\u5747\u6bcf\u79d2 {{ $value }} \u6761\u9519\u8bef\u65e5\u5fd7&#034;<\/span><\/p>\n<p>      <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">alert<\/span><span class=\"token punctuation\">:<\/span> NoLogsFromInstance<br \/>\n        <span class=\"token key atrule\">expr<\/span><span class=\"token punctuation\">:<\/span> absent_over_time(<span class=\"token punctuation\">{<\/span>job&#061;&#034;myapp&#034;<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">[<\/span>10m<span class=\"token punctuation\">]<\/span>)<br \/>\n        <span class=\"token key atrule\">for<\/span><span class=\"token punctuation\">:<\/span> 10m<br \/>\n        <span class=\"token key atrule\">labels<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token key atrule\">severity<\/span><span class=\"token punctuation\">:<\/span> critical<br \/>\n        <span class=\"token key atrule\">annotations<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token key atrule\">summary<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;\u5b9e\u4f8b {{ $labels.instance }} \u5df2 10 \u5206\u949f\u65e0\u65e5\u5fd7&#xff0c;\u53ef\u80fd\u5df2\u5b95\u673a&#034;<\/span><\/p>\n<p>\u8fd9\u4e9b\u89c4\u5219\u4f7f\u7528 LogQL&#xff08;\u7c7b\u4f3c PromQL \u4f46\u9488\u5bf9\u65e5\u5fd7&#xff09;&#xff0c;\u53ef\u4ee5\u5bf9\u7279\u5b9a\u6807\u7b7e\u7684\u65e5\u5fd7\u901f\u7387\u3001\u6a21\u5f0f\u8fdb\u884c\u544a\u8b66\u3002Alertmanager \u6536\u5230\u7684\u544a\u8b66\u540c\u6837\u5305\u542b\u6807\u7b7e&#xff0c;\u53ef\u4e0e Prometheus \u544a\u8b66\u7edf\u4e00\u8def\u7531\u3002<\/p>\n<hr \/>\n<h4>8. \u8fdb\u9636&#xff1a;\u591a\u79df\u6237\u3001\u957f\u671f\u5b58\u50a8\u4e0e\u6027\u80fd\u8c03\u4f18<\/h4>\n<h5>8.1 \u591a\u79df\u6237\u9694\u79bb<\/h5>\n<p>Loki \u652f\u6301\u901a\u8fc7 X-Scope-OrgID \u5934\u5b9e\u73b0\u591a\u79df\u6237\u3002\u5728\u914d\u7f6e\u4e2d\u542f\u7528 auth_enabled: true&#xff0c;\u5e76\u5728 Promtail \u7684 client \u90e8\u5206\u6dfb\u52a0 tenant_id \u5b57\u6bb5\u5373\u53ef\u3002\u4e0d\u540c\u79df\u6237\u7684\u65e5\u5fd7\u548c\u6307\u6807\u5b8c\u5168\u9694\u79bb\u3002<\/p>\n<h5>8.2 \u957f\u671f\u5b58\u50a8<\/h5>\n<p>\u5c06 storage_config \u4e2d\u7684 object_store \u6539\u4e3a s3, gcs, azure \u7b49\u4e91\u5bf9\u8c61\u5b58\u50a8&#xff0c;\u914d\u5408 boltdb_shipper&#xff0c;\u5b9e\u73b0\u65e5\u5fd7\u65e0\u9650\u7559\u5b58\u4e14\u4f4e\u6210\u672c\u3002<\/p>\n<h5>8.3 \u63a7\u5236\u6807\u7b7e\u57fa\u6570<\/h5>\n<p>Loki \u7684\u6807\u7b7e\u6570\u91cf\u4e0d\u80fd\u8fc7\u9ad8&#xff0c;\u5426\u5219\u7d22\u5f15\u81a8\u80c0\u3002\u907f\u514d\u5c06\u9ad8\u57fa\u6570\u5b57\u6bb5&#xff08;\u5982 user_id, request_id&#xff09;\u4f5c\u4e3a\u6807\u7b7e&#xff0c;\u800c\u662f\u4f7f\u7528\u65e5\u5fd7\u8fc7\u6ee4&#xff08;LogQL \u7684 |~ \u6b63\u5219&#xff09;\u8fdb\u884c\u5168\u6587\u641c\u7d22\u3002\u4fdd\u7559\u6838\u5fc3\u6807\u7b7e&#xff08;job, instance, app&#xff09;\u5373\u53ef\u3002<\/p>\n<h5>8.4 \u4e0e Tempo \u8ffd\u8e2a\u96c6\u6210<\/h5>\n<p>Loki \u53ef\u4e0e Grafana Tempo \u96c6\u6210&#xff0c;\u901a\u8fc7 Trace ID \u76f4\u63a5\u4ece\u65e5\u5fd7\u8df3\u8f6c\u5230 trace&#xff0c;\u5b9e\u73b0 \u6307\u6807 \u2192 \u65e5\u5fd7 \u2192 \u8ffd\u8e2a \u7684\u5b8c\u6574\u94fe\u8def\u3002<\/p>\n<hr \/>\n<h4>9. \u603b\u7ed3<\/h4>\n<p>Loki \u7684\u8bbe\u8ba1\u54f2\u5b66\u2014\u2014\u50cf Prometheus \u4e00\u6837\u5904\u7406\u65e5\u5fd7\u2014\u2014\u8ba9\u65e5\u5fd7\u548c\u6307\u6807\u4e4b\u95f4\u7684\u9e3f\u6c9f\u6d88\u5931\u3002\u901a\u8fc7\u5171\u4eab\u6807\u7b7e&#xff0c;Grafana \u4e2d\u4e00\u6761\u70b9\u51fb\u5c31\u80fd\u4ece CPU \u5c16\u523a\u7684\u76d1\u63a7\u56fe\u8df3\u8f6c\u5230\u76f8\u5173\u65f6\u95f4\u6bb5\u7684\u5e94\u7528\u65e5\u5fd7&#xff0c;\u8fd0\u7ef4\u6548\u7387\u6210\u500d\u63d0\u5347\u3002\u800c Loki \u81ea\u8eab\u7684\u76d1\u63a7\u4e0e\u57fa\u4e8e\u65e5\u5fd7\u7684\u544a\u8b66&#xff0c;\u53c8\u4fdd\u8bc1\u4e86\u65e5\u5fd7\u7ba1\u9053\u672c\u8eab\u7684\u5065\u5eb7\u3002\u90e8\u7f72\u8fd9\u5957\u65b9\u6848&#xff0c;\u4f60\u7684\u53ef\u89c2\u6d4b\u6027\u5c06\u4e0d\u518d\u5206\u88c2\u4e3a\u201c\u6307\u6807\u770b\u677f\u201d\u548c\u201c\u65e5\u5fd7\u641c\u7d22\u201d\u4e24\u4e2a\u5b64\u5c9b&#xff0c;\u800c\u662f\u6210\u4e3a\u4e00\u4e2a\u6807\u7b7e\u7edf\u4e00\u3001\u8054\u52a8\u6d41\u7545\u7684\u5168\u666f\u89c6\u56fe&#xff0c;\u771f\u6b63\u5b9e\u73b0\u201c1&#043;1 &gt; 2\u201d\u7684\u878d\u5408\u529b\u91cf\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prometheus Loki \u5168\u6808\u5b9e\u6218&#xff1a;\u6807\u7b7e\u5171\u4eab\u4e0b\u7684\u65e5\u5fd7\u4e0e\u6307\u6807\u878d\u5408\u53ef\u89c2\u6d4b\u6027\u5728\u73b0\u4ee3\u53ef\u89c2\u6d4b\u6027\u4f53\u7cfb\u4e2d&#xff0c;Metrics&#xff08;\u6307\u6807&#xff09; \u544a\u8bc9\u6211\u4eec\u7cfb\u7edf\u54ea\u91cc\u51fa\u4e86\u95ee\u9898&#xff0c;Logs&#xff08;\u65e5\u5fd7&#xff09; \u5219\u89e3\u91ca\u95ee\u9898\u53d1\u751f\u7684\u539f\u56e0\u3002Prometheus \u8d1f\u8d23\u6307\u6807&#xff0c;\u800c Grafana Loki \u662f\u4e13\u95e8\u4e3a Prometheus \u751f\u6001\u8bbe\u8ba1\u7684\u8f7b\u91cf\u7ea7\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u3002\u4e8c\u8005\u6700\u5927\u7684\u534f\u540c\u79d8\u5bc6\u5728\u4e8e&#xff1a;Loki \u4f7f\u7528\u4e0e <\/p>\n","protected":false},"author":2,"featured_media":94007,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10751,678,44],"topic":[],"class_list":["post-94008","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-10751","tag-prometheus","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Prometheus Loki \u5168\u6808\u5b9e\u6218\uff1a\u6807\u7b7e\u5171\u4eab\u4e0b\u7684\u65e5\u5fd7\u4e0e\u6307\u6807\u878d\u5408\u53ef\u89c2\u6d4b\u6027 - \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\/94008.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Prometheus Loki \u5168\u6808\u5b9e\u6218\uff1a\u6807\u7b7e\u5171\u4eab\u4e0b\u7684\u65e5\u5fd7\u4e0e\u6307\u6807\u878d\u5408\u53ef\u89c2\u6d4b\u6027 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Prometheus Loki \u5168\u6808\u5b9e\u6218&#xff1a;\u6807\u7b7e\u5171\u4eab\u4e0b\u7684\u65e5\u5fd7\u4e0e\u6307\u6807\u878d\u5408\u53ef\u89c2\u6d4b\u6027\u5728\u73b0\u4ee3\u53ef\u89c2\u6d4b\u6027\u4f53\u7cfb\u4e2d&#xff0c;Metrics&#xff08;\u6307\u6807&#xff09; \u544a\u8bc9\u6211\u4eec\u7cfb\u7edf\u54ea\u91cc\u51fa\u4e86\u95ee\u9898&#xff0c;Logs&#xff08;\u65e5\u5fd7&#xff09; \u5219\u89e3\u91ca\u95ee\u9898\u53d1\u751f\u7684\u539f\u56e0\u3002Prometheus \u8d1f\u8d23\u6307\u6807&#xff0c;\u800c Grafana Loki \u662f\u4e13\u95e8\u4e3a Prometheus \u751f\u6001\u8bbe\u8ba1\u7684\u8f7b\u91cf\u7ea7\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u3002\u4e8c\u8005\u6700\u5927\u7684\u534f\u540c\u79d8\u5bc6\u5728\u4e8e&#xff1a;Loki \u4f7f\u7528\u4e0e\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/94008.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-13T05:25:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813052501-6a7d552d3a309.png\" \/>\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=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/94008.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/94008.html\",\"name\":\"Prometheus Loki \u5168\u6808\u5b9e\u6218\uff1a\u6807\u7b7e\u5171\u4eab\u4e0b\u7684\u65e5\u5fd7\u4e0e\u6307\u6807\u878d\u5408\u53ef\u89c2\u6d4b\u6027 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-13T05:25:11+00:00\",\"dateModified\":\"2026-08-13T05:25:11+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/94008.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/94008.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/94008.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Prometheus Loki \u5168\u6808\u5b9e\u6218\uff1a\u6807\u7b7e\u5171\u4eab\u4e0b\u7684\u65e5\u5fd7\u4e0e\u6307\u6807\u878d\u5408\u53ef\u89c2\u6d4b\u6027\"}]},{\"@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 Loki \u5168\u6808\u5b9e\u6218\uff1a\u6807\u7b7e\u5171\u4eab\u4e0b\u7684\u65e5\u5fd7\u4e0e\u6307\u6807\u878d\u5408\u53ef\u89c2\u6d4b\u6027 - \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\/94008.html","og_locale":"zh_CN","og_type":"article","og_title":"Prometheus Loki \u5168\u6808\u5b9e\u6218\uff1a\u6807\u7b7e\u5171\u4eab\u4e0b\u7684\u65e5\u5fd7\u4e0e\u6307\u6807\u878d\u5408\u53ef\u89c2\u6d4b\u6027 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Prometheus Loki \u5168\u6808\u5b9e\u6218&#xff1a;\u6807\u7b7e\u5171\u4eab\u4e0b\u7684\u65e5\u5fd7\u4e0e\u6307\u6807\u878d\u5408\u53ef\u89c2\u6d4b\u6027\u5728\u73b0\u4ee3\u53ef\u89c2\u6d4b\u6027\u4f53\u7cfb\u4e2d&#xff0c;Metrics&#xff08;\u6307\u6807&#xff09; \u544a\u8bc9\u6211\u4eec\u7cfb\u7edf\u54ea\u91cc\u51fa\u4e86\u95ee\u9898&#xff0c;Logs&#xff08;\u65e5\u5fd7&#xff09; \u5219\u89e3\u91ca\u95ee\u9898\u53d1\u751f\u7684\u539f\u56e0\u3002Prometheus \u8d1f\u8d23\u6307\u6807&#xff0c;\u800c Grafana Loki \u662f\u4e13\u95e8\u4e3a Prometheus \u751f\u6001\u8bbe\u8ba1\u7684\u8f7b\u91cf\u7ea7\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u3002\u4e8c\u8005\u6700\u5927\u7684\u534f\u540c\u79d8\u5bc6\u5728\u4e8e&#xff1a;Loki \u4f7f\u7528\u4e0e","og_url":"https:\/\/www.wsisp.com\/helps\/94008.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-13T05:25:11+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813052501-6a7d552d3a309.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/94008.html","url":"https:\/\/www.wsisp.com\/helps\/94008.html","name":"Prometheus Loki \u5168\u6808\u5b9e\u6218\uff1a\u6807\u7b7e\u5171\u4eab\u4e0b\u7684\u65e5\u5fd7\u4e0e\u6307\u6807\u878d\u5408\u53ef\u89c2\u6d4b\u6027 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-13T05:25:11+00:00","dateModified":"2026-08-13T05:25:11+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/94008.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/94008.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/94008.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Prometheus Loki \u5168\u6808\u5b9e\u6218\uff1a\u6807\u7b7e\u5171\u4eab\u4e0b\u7684\u65e5\u5fd7\u4e0e\u6307\u6807\u878d\u5408\u53ef\u89c2\u6d4b\u6027"}]},{"@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\/94008","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=94008"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/94008\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/94007"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=94008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=94008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=94008"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=94008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}