{"id":186638,"date":"2020-10-18T17:25:11","date_gmt":"2020-10-18T09:25:11","guid":{"rendered":"http:\/\/4563.org\/?p=186638"},"modified":"2020-10-18T17:25:11","modified_gmt":"2020-10-18T09:25:11","slug":"grafana-loki-%e5%bc%80%e6%ba%90%e6%97%a5%e5%bf%97%e8%81%9a%e5%90%88%e7%b3%bb%e7%bb%9f%e4%bb%a3%e6%9b%bf-elk-%e6%88%96-efk","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=186638","title":{"rendered":"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wsgzao <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201108_5fa832ff488a7.png\" alt=\"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK\" \/><\/p>\n<h2>\u524d\u8a00<\/h2>\n<p>\u5728\u5bf9\u516c\u53f8\u5bb9\u5668\u4e91\u7684\u65e5\u5fd7\u65b9\u6848\u8fdb\u884c\u8bbe\u8ba1\u7684\u65f6\u5019\uff0c\u53d1\u73b0\u4e3b\u6d41\u7684 ELK (Elasticsearch, <code>Logstash<\/code>, Kibana) \u6216\u8005 EFK (Elasticsearch, <code>Filebeat<\/code> or <code>Fluentd<\/code>, Kibana) \u6bd4\u8f83\u91cd\uff0c\u518d\u52a0\u4e0a\u73b0\u9636\u6bb5\u5bf9\u4e8e ES \u590d\u6742\u7684\u641c\u7d22\u529f\u80fd\u5f88\u591a\u90fd\u7528\u4e0d\u4e0a\uff0c\u6700\u7ec8\u9009\u62e9\u4e86 Grafana \u5f00\u6e90\u7684 Loki \u65e5\u5fd7\u7cfb\u7edf\u3002\u4e0b\u9762\u6211\u4eec\u6765\u4ecb\u7ecd\u4e0b Loki \u7684\u4e00\u4e9b\u57fa\u672c\u6982\u5ff5\u548c\u67b6\u6784\uff0c\u5f53\u7136 EFK \u4f5c\u4e3a\u4e1a\u754c\u6210\u719f\u7684\u65e5\u5fd7\u805a\u5408\u89e3\u51b3\u65b9\u6848\u4e5f\u662f\u5927\u5bb6\u5e94\u8be5\u9700\u8981\u719f\u6089\u548c\u638c\u63e1\u7684\u3002<\/p>\n<p>Loki 2.0 released: Transform logs as you\u2019re querying them, and set up alerts within Loki, Loki 2.0 \u5927\u7248\u672c\u66f4\u65b0\u540e\u66f4\u597d\u7528\u4e86<\/p>\n<h2>\u66f4\u65b0\u5386\u53f2<\/h2>\n<p>2020 \u5e74 10 \u6708 02 \u65e5 &#8211; \u521d\u7a3f<\/p>\n<p>\u9605\u8bfb\u539f\u6587 &#8211; https:\/\/wsgzao.github.io\/post\/loki\/<\/p>\n<h2>Loki \u7b80\u4ecb<\/h2>\n<p>Grafana Loki is a set of components that can be composed into a fully featured logging stack.<\/p>\n<p>Unlike other logging systems, Loki is built around the idea of only indexing metadata about your logs: labels (just like Prometheus labels). Log data itself is then compressed and stored in chunks in object stores such as S3 or GCS, or even locally on the filesystem. A small index and highly compressed chunks simplifies the operation and significantly lowers the cost of Loki.<\/p>\n<p>Loki \u662f Grafana Labs \u56e2\u961f\u6700\u65b0\u7684\u5f00\u6e90\u9879\u76ee\uff0c\u662f\u4e00\u4e2a\u6c34\u5e73\u53ef\u6269\u5c55\uff0c\u9ad8\u53ef\u7528\u6027\uff0c\u591a\u79df\u6237\u7684\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u3002\u5b83\u7684\u8bbe\u8ba1\u975e\u5e38\u7ecf\u6d4e\u9ad8\u6548\u4e14\u6613\u4e8e\u64cd\u4f5c\uff0c\u56e0\u4e3a\u5b83\u4e0d\u4f1a\u4e3a\u65e5\u5fd7\u5185\u5bb9\u7f16\u5236\u7d22\u5f15\uff0c\u800c\u662f\u4e3a\u6bcf\u4e2a\u65e5\u5fd7\u6d41\u7f16\u5236\u4e00\u7ec4\u6807\u7b7e\uff0c\u4e13\u95e8\u4e3a Prometheus \u548c Kubernetes \u7528\u6237\u505a\u4e86\u76f8\u5173\u4f18\u5316\u3002\u8be5\u9879\u76ee\u53d7 Prometheus \u542f\u53d1\uff0c\u5b98\u65b9\u7684\u4ecb\u7ecd\u5c31\u662f\uff1a <code>Like Prometheus,But For Logs.<\/code>\uff0c\u7c7b\u4f3c\u4e8e Prometheus \u7684\u65e5\u5fd7\u7cfb\u7edf\u3002<\/p>\n<p>\u9879\u76ee\u5730\u5740\uff1ahttps:\/\/github.com\/grafana\/loki\/<\/p>\n<p>\u4e0e\u5176\u4ed6\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u76f8\u6bd4\uff0cLoki \u5177\u6709\u4e0b\u9762\u7684\u4e00\u4e9b\u7279\u6027\uff1a<\/p>\n<ul>\n<li>\n<p>\u4e0d\u5bf9\u65e5\u5fd7\u8fdb\u884c\u5168\u6587\u7d22\u5f15\u3002\u901a\u8fc7\u5b58\u50a8\u538b\u7f29\u975e\u7ed3\u6784\u5316\u65e5\u5fd7\u548c\u4ec5\u7d22\u5f15\u5143\u6570\u636e\uff0cLoki \u64cd\u4f5c\u8d77\u6765\u4f1a\u66f4\u7b80\u5355\uff0c\u66f4\u7701\u6210\u672c\u3002<\/p>\n<\/li>\n<li>\n<p>\u901a\u8fc7\u4f7f\u7528\u4e0e Prometheus \u76f8\u540c\u7684\u6807\u7b7e\u8bb0\u5f55\u6d41\u5bf9\u65e5\u5fd7\u8fdb\u884c\u7d22\u5f15\u548c\u5206\u7ec4\uff0c\u8fd9\u4f7f\u5f97\u65e5\u5fd7\u7684\u6269\u5c55\u548c\u64cd\u4f5c\u6548\u7387\u66f4\u9ad8\u3002<\/p>\n<\/li>\n<li>\n<p>\u7279\u522b\u9002\u5408\u50a8\u5b58 Kubernetes Pod \u65e5\u5fd7; \u8bf8\u5982 Pod \u6807\u7b7e\u4e4b\u7c7b\u7684\u5143\u6570\u636e\u4f1a\u88ab\u81ea\u52a8\u5220\u9664\u548c\u7f16\u5165\u7d22\u5f15\u3002<\/p>\n<\/li>\n<li>\n<p>\u53d7 Grafana \u539f\u751f\u652f\u6301\u3002<\/p>\n<\/li>\n<\/ul>\n<h2>\u80cc\u666f\u548c\u52a8\u673a<\/h2>\n<p>\u5f53\u6211\u4eec\u7684\u5bb9\u5668\u4e91\u8fd0\u884c\u7684\u5e94\u7528\u6216\u8005\u67d0\u4e2a\u8282\u70b9\u51fa\u73b0\u95ee\u9898\u4e86\uff0c\u89e3\u51b3\u601d\u8def\u5e94\u8be5\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201108_5fa83303e8b27.png\" alt=\"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK\" \/><\/p>\n<p>\u6211\u4eec\u7684\u76d1\u63a7\u4f7f\u7528\u7684\u662f\u57fa\u4e8e Prometheus \u4f53\u7cfb\u8fdb\u884c\u6539\u9020\u7684\uff0cPrometheus \u4e2d\u6bd4\u8f83\u91cd\u8981\u7684\u662f Metric \u548c Alert\uff0cMetric \u662f\u6765\u8bf4\u660e\u5f53\u524d\u6216\u8005\u5386\u53f2\u8fbe\u5230\u4e86\u67d0\u4e2a\u503c\uff0cAlert \u8bbe\u7f6e Metric \u8fbe\u5230\u67d0\u4e2a\u7279\u5b9a\u7684\u57fa\u6570\u89e6\u53d1\u4e86\u544a\u8b66\uff0c\u4f46\u662f\u8fd9\u4e9b\u4fe1\u606f\u660e\u663e\u662f\u4e0d\u591f\u7684\u3002<\/p>\n<p>\u6211\u4eec\u90fd\u77e5\u9053\uff0cKubernetes \u7684\u57fa\u672c\u5355\u4f4d\u662f Pod\uff0cPod \u628a\u65e5\u5fd7\u8f93\u51fa\u5230 Stdout \u548c Stderr\uff0c\u5e73\u65f6\u6709\u4ec0\u4e48\u95ee\u9898\u6211\u4eec\u901a\u5e38\u5728\u754c\u9762\u6216\u8005\u901a\u8fc7\u547d\u4ee4\u67e5\u770b\u76f8\u5173\u7684\u65e5\u5fd7\u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff1a\u5f53\u6211\u4eec\u7684\u67d0\u4e2a Pod \u7684\u5185\u5b58\u53d8\u5f97\u5f88\u5927\uff0c\u89e6\u53d1\u4e86\u6211\u4eec\u7684 Alert \u3002\u8fd9\u65f6\u7ba1\u7406\u5458\uff0c\u53bb\u9875\u9762\u67e5\u8be2\u786e\u8ba4\u662f\u54ea\u4e2a Pod \u6709\u95ee\u9898\uff0c\u7136\u540e\u8981\u786e\u8ba4 Pod \u5185\u5b58\u53d8\u5927\u7684\u539f\u56e0\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u53bb\u67e5\u8be2 Pod \u7684\u65e5\u5fd7\uff0c\u5982\u679c\u6ca1\u6709\u65e5\u5fd7\u7cfb\u7edf\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u9700\u8981\u5230\u9875\u9762\u6216\u8005\u4f7f\u7528\u547d\u4ee4\u8fdb\u884c\u67e5\u8be2\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201108_5fa833079e92c.png\" alt=\"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK\" \/><\/p>\n<p>\u5982\u679c\uff0c\u8fd9\u4e2a\u65f6\u5019\u5e94\u7528\u7a81\u7136\u6302\u4e86\uff0c\u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u5c31\u65e0\u6cd5\u67e5\u5230\u76f8\u5173\u7684\u65e5\u5fd7\u4e86\u3002\u6240\u4ee5\u9700\u8981\u5f15\u5165\u65e5\u5fd7\u7cfb\u7edf\uff0c\u7edf\u4e00\u6536\u96c6\u65e5\u5fd7\u3002\u800c\u4f7f\u7528 ELK \u7684\u8bdd\uff0c\u5c31\u9700\u8981\u5728 Kibana \u548c Grafana \u4e4b\u95f4\u5207\u6362\uff0c\u5f71\u54cd\u7528\u6237\u4f53\u9a8c\u3002\u6240\u4ee5 \uff0cLoki \u7684\u7b2c\u4e00\u76ee\u7684\u5c31\u662f\u6700\u5c0f\u5316\u5ea6\u91cf\u548c\u65e5\u5fd7\u7684\u5207\u6362\u6210\u672c\uff0c\u6709\u52a9\u4e8e\u51cf\u5c11\u5f02\u5e38\u4e8b\u4ef6\u7684\u54cd\u5e94\u65f6\u95f4\u548c\u63d0\u9ad8\u7528\u6237\u7684\u4f53\u9a8c\u3002<\/p>\n<h2>ELK \u5b58\u5728\u7684\u95ee\u9898<\/h2>\n<p>\u73b0\u6709\u7684\u5f88\u591a\u65e5\u5fd7\u91c7\u96c6\u7684\u65b9\u6848\u90fd\u662f\u91c7\u7528\u5168\u6587\u68c0\u7d22\u5bf9\u65e5\u5fd7\u8fdb\u884c\u7d22\u5f15\uff08\u5982 ELK \u65b9\u6848\uff09\uff0c\u4f18\u70b9\u662f\u529f\u80fd\u4e30\u5bcc\uff0c\u5141\u8bb8\u590d\u6742\u7684\u64cd\u4f5c\u3002\u4f46\u662f\uff0c\u8fd9\u4e9b\u65b9\u6848\u5f80\u5f80\u89c4\u6a21\u590d\u6742\uff0c\u8d44\u6e90\u5360\u7528\u9ad8\uff0c\u64cd\u4f5c\u82e6\u96be\u3002\u5f88\u591a\u529f\u80fd\u5f80\u5f80\u7528\u4e0d\u4e0a\uff0c\u5927\u591a\u6570\u67e5\u8be2\u53ea\u5173\u6ce8\u4e00\u5b9a\u65f6\u95f4\u8303\u56f4\u548c\u4e00\u4e9b\u7b80\u5355\u7684\u53c2\u6570\uff08\u5982\uff1ahost \u3001service \u7b49\uff09\uff0c\u4f7f\u7528\u8fd9\u4e9b\u89e3\u51b3\u65b9\u6848\u5c31\u6709\u70b9\u6740\u9e21\u7528\u725b\u5200\u7684\u611f\u89c9\u4e86\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201108_5fa8330abacce.png\" alt=\"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK\" \/><\/p>\n<p>\u56e0\u6b64\uff0cLoki \u7684\u7b2c\u4e8c\u4e2a\u76ee\u7684\u662f\uff0c\u5728\u67e5\u8be2\u8bed\u8a00\u7684\u6613\u64cd\u4f5c\u6027\u548c\u590d\u6742\u6027\u4e4b\u95f4\u53ef\u4ee5\u8fbe\u5230\u4e00\u4e2a\u6743\u8861\u3002<\/p>\n<h2>\u6210\u672c\u8003\u91cf<\/h2>\n<p>\u5168\u6587\u68c0\u7d22\u7684\u65b9\u6848\u4e5f\u5e26\u6765\u6210\u672c\u95ee\u9898\uff0c\u7b80\u5355\u7684\u8bf4\u5c31\u662f\u5168\u6587\u641c\u7d22\uff08\u5982\uff1aES \uff09\u7684\u5012\u6392\u7d22\u5f15\u7684\u5207\u5206\u548c\u5171\u4eab\u7684\u6210\u672c\u8f83\u9ad8\u3002\u540e\u6765\u51fa\u73b0\u4e86\u5176\u4ed6\u4e0d\u540c\u7684\u8bbe\u8ba1\u65b9\u6848\uff0c\u5982\uff1a<\/p>\n<ul>\n<li>OKlog<\/li>\n<\/ul>\n<p>\u9879\u76ee\u5730\u5740\uff1ahttps:\/\/github.com\/oklog\/oklog<\/p>\n<p>\u91c7\u7528\u6700\u7ec8\u4e00\u81f4\u7684\u3001\u57fa\u4e8e\u7f51\u683c\u7684\u5206\u5e03\u7b56\u7565\u3002\u8fd9\u4e24\u4e2a\u8bbe\u8ba1\u51b3\u7b56\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u6210\u672c\u964d\u4f4e\u548c\u975e\u5e38\u7b80\u5355\u7684\u64cd\u4f5c\uff0c\u4f46\u662f\u67e5\u8be2\u4e0d\u591f\u65b9\u4fbf\u3002\u56e0\u6b64\uff0cLoki \u7684\u7b2c\u4e09\u4e2a\u76ee\u7684\u662f\uff0c\u63d0\u4f9b\u4e00\u4e2a\u66f4\u5177\u6210\u672c\u6548\u76ca\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<h2>\u6574\u4f53\u67b6\u6784<\/h2>\n<p>Loki \u7684\u67b6\u6784\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201108_5fa8331034b66.png\" alt=\"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK\" \/><\/p>\n<p>\u4e0d\u96be\u770b\u51fa\uff0cLoki \u7684\u67b6\u6784\u975e\u5e38\u7b80\u5355\uff0c\u4e3b\u8981\u7531\u4ee5\u4e0b 3 \u4e2a\u90e8\u5206\u7ec4\u6210\uff1a<\/p>\n<ul>\n<li>\n<p>Loki \u662f\u4e3b\u670d\u52a1\u5668\uff0c\u8d1f\u8d23\u5b58\u50a8\u65e5\u5fd7\u548c\u5904\u7406\u67e5\u8be2\u3002<\/p>\n<\/li>\n<li>\n<p>Promtail \u662f\u4ee3\u7406\uff0c\u8d1f\u8d23\u6536\u96c6\u65e5\u5fd7\u5e76\u5c06\u5176\u53d1\u9001\u7ed9 Loki \u3002<\/p>\n<\/li>\n<li>\n<p>Grafana \u7528\u4e8e UI \u5c55\u793a\u3002<\/p>\n<\/li>\n<\/ul>\n<p>Loki \u4f7f\u7528\u4e86\u548c Prometheus \u4e00\u6837\u7684\u6807\u7b7e\u6765\u4f5c\u4e3a\u7d22\u5f15\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4f60\u901a\u8fc7\u8fd9\u4e9b\u6807\u7b7e\u65e2\u53ef\u4ee5\u67e5\u8be2\u65e5\u5fd7\u7684\u5185\u5bb9\u4e5f\u53ef\u4ee5\u67e5\u8be2\u5230\u76d1\u63a7\u7684\u6570\u636e\uff0c\u4e0d\u4f46\u51cf\u5c11\u4e86\u4e24\u79cd\u67e5\u8be2\u4e4b\u95f4\u7684\u5207\u6362\u6210\u672c\uff0c\u4e5f\u6781\u5927\u5730\u964d\u4f4e\u4e86\u65e5\u5fd7\u7d22\u5f15\u7684\u5b58\u50a8\u3002<\/p>\n<p>Loki \u4f7f\u7528\u4e0e Prometheus \u76f8\u540c\u7684\u670d\u52a1\u53d1\u73b0\u548c\u6807\u7b7e\u91cd\u65b0\u6807\u8bb0\u5e93\uff0c\u7f16\u5199\u4e86 Pormtail \u3002\u5728 Kubernetes \u4e2d Promtail \u4ee5 DaemonSet \u65b9\u5f0f\u8fd0\u884c\u5728\u6bcf\u4e2a\u8282\u70b9\u4e2d\uff0c\u901a\u8fc7 Kubernetes API \u5f97\u5230\u65e5\u5fd7\u7684\u6b63\u786e\u5143\u6570\u636e\uff0c\u5e76\u5c06\u5b83\u4eec\u53d1\u9001\u5230 Loki \u3002\u4e0b\u9762\u662f\u65e5\u5fd7\u7684\u5b58\u50a8\u67b6\u6784\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201108_5fa833153054c.png\" alt=\"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK\" \/><\/p>\n<h3>\u8bfb\u5199<\/h3>\n<p>\u65e5\u5fd7\u6570\u636e\u7684\u5199\u4e3b\u8981\u4f9d\u6258\u7684\u662f Distributor \u548c Ingester \u4e24\u4e2a\u7ec4\u4ef6\uff0c\u6574\u4f53\u7684\u6d41\u7a0b\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201108_5fa8331919e11.png\" alt=\"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK\" \/><\/p>\n<h3>Distributor<\/h3>\n<p>\u4e00\u65e6 Promtail \u6536\u96c6\u65e5\u5fd7\u5e76\u5c06\u5176\u53d1\u9001\u7ed9 Loki\uff0cDistributor \u5c31\u662f\u7b2c\u4e00\u4e2a\u63a5\u6536\u65e5\u5fd7\u7684\u7ec4\u4ef6\u3002\u7531\u4e8e\u65e5\u5fd7\u7684\u5199\u5165\u91cf\u53ef\u80fd\u5f88\u5927\uff0c\u6240\u4ee5\u4e0d\u80fd\u5728\u5b83\u4eec\u4f20\u5165\u65f6\u5c06\u5b83\u4eec\u5199\u5165\u6570\u636e\u5e93\u3002\u8fd9\u4f1a\u6bc1\u6389\u6570\u636e\u5e93\u3002\u6211\u4eec\u9700\u8981\u6279\u5904\u7406\u548c\u538b\u7f29\u6570\u636e\u3002<\/p>\n<p>Loki \u901a\u8fc7\u6784\u5efa\u538b\u7f29\u6570\u636e\u5757\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\uff0c\u65b9\u6cd5\u662f\u5728\u65e5\u5fd7\u8fdb\u5165\u65f6\u5bf9\u5176\u8fdb\u884c Gzip \u64cd\u4f5c\u3002\u7ec4\u4ef6 Ingester \u662f\u4e00\u4e2a\u6709\u72b6\u6001\u7684\u7ec4\u4ef6\uff0c\u8d1f\u8d23\u6784\u5efa\u548c\u5237\u65b0 Chunck\uff0c\u5f53 Chunk \u8fbe\u5230\u4e00\u5b9a\u7684\u6570\u91cf\u6216\u8005\u65f6\u95f4\u540e\uff0c\u5237\u65b0\u5230\u5b58\u50a8\u4e2d\u53bb\u3002\u6bcf\u4e2a\u6d41\u7684\u65e5\u5fd7\u5bf9\u5e94\u4e00\u4e2a Ingester\uff0c\u5f53\u65e5\u5fd7\u5230\u8fbe Distributor \u540e\uff0c\u6839\u636e\u5143\u6570\u636e\u548c Hash \u7b97\u6cd5\u8ba1\u7b97\u51fa\u5e94\u8be5\u5230\u54ea\u4e2a Ingester \u4e0a\u9762\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201108_5fa8331e1cca1.png\" alt=\"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK\" \/><\/p>\n<p>\u6b64\u5916\uff0c\u4e3a\u4e86\u5197\u4f59\u548c\u5f39\u6027\uff0c\u6211\u4eec\u5c06\u5176\u590d\u5236 n \uff08\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4e3a 3 \uff09\u6b21\u3002<\/p>\n<h3>Ingester<\/h3>\n<p>Ingester \u63a5\u6536\u5230\u65e5\u5fd7\u5e76\u5f00\u59cb\u6784\u5efa Chunk\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201108_5fa83322700d1.png\" alt=\"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK\" \/><\/p>\n<p>\u57fa\u672c\u4e0a\u5c31\u662f\u5c06\u65e5\u5fd7\u8fdb\u884c\u538b\u7f29\u5e76\u9644\u52a0\u5230 Chunk \u4e0a\u9762\u3002\u4e00\u65e6 Chunk \u586b\u6ee1\uff08\u6570\u636e\u8fbe\u5230\u4e00\u5b9a\u6570\u91cf\u6216\u8005\u8fc7\u4e86\u4e00\u5b9a\u671f\u9650\uff09\uff0cIngester \u5c06\u5176\u5237\u65b0\u5230\u6570\u636e\u5e93\u3002\u6211\u4eec\u5bf9\u5757\u548c\u7d22\u5f15\u4f7f\u7528\u5355\u72ec\u7684\u6570\u636e\u5e93\uff0c\u56e0\u4e3a\u5b83\u4eec\u5b58\u50a8\u7684\u6570\u636e\u7c7b\u578b\u4e0d\u540c\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201108_5fa83327616fb.png\" alt=\"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK\" \/><\/p>\n<p>\u5237\u65b0\u4e00\u4e2a Chunk \u4e4b\u540e\uff0cIngester \u7136\u540e\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7a7a Chunk \u5e76\u5c06\u65b0\u6761\u76ee\u6dfb\u52a0\u5230\u8be5 Chunk \u4e2d\u3002<\/p>\n<h3>Querier<\/h3>\n<p>\u8bfb\u53d6\u5c31\u975e\u5e38\u7b80\u5355\u4e86\uff0c\u7531 Querier \u8d1f\u8d23\u7ed9\u5b9a\u4e00\u4e2a\u65f6\u95f4\u8303\u56f4\u548c\u6807\u7b7e\u9009\u62e9\u5668\uff0cQuerier \u67e5\u770b\u7d22\u5f15\u4ee5\u786e\u5b9a\u54ea\u4e9b\u5757\u5339\u914d\uff0c\u5e76\u901a\u8fc7 Greps \u5c06\u7ed3\u679c\u663e\u793a\u51fa\u6765\u3002\u5b83\u8fd8\u4ece Ingester \u83b7\u53d6\u5c1a\u672a\u5237\u65b0\u7684\u6700\u65b0\u6570\u636e\u3002<\/p>\n<p>\u5bf9\u4e8e\u6bcf\u4e2a\u67e5\u8be2\uff0c\u4e00\u4e2a\u67e5\u8be2\u5668\u5c06\u4e3a\u60a8\u663e\u793a\u6240\u6709\u76f8\u5173\u65e5\u5fd7\u3002\u5b9e\u73b0\u4e86\u67e5\u8be2\u5e76\u884c\u5316\uff0c\u63d0\u4f9b\u5206\u5e03\u5f0f Grep\uff0c\u4f7f\u5373\u4f7f\u662f\u5927\u578b\u67e5\u8be2\u4e5f\u662f\u8db3\u591f\u7684\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201108_5fa8332bb379c.png\" alt=\"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK\" \/><\/p>\n<h3>\u53ef\u6269\u5c55\u6027<\/h3>\n<p>Loki \u7684\u7d22\u5f15\u5b58\u50a8\u53ef\u4ee5\u662f Cassandra\/Bigtable\/Dynamodb\uff0c\u800c Chuncks \u53ef\u4ee5\u662f\u5404\u79cd\u5bf9\u8c61\u5b58\u50a8\uff0cQuerier \u548c Distributor \u90fd\u662f\u65e0\u72b6\u6001\u7684\u7ec4\u4ef6\u3002<\/p>\n<p>\u5bf9\u4e8e Ingester\uff0c\u5b83\u867d\u7136\u662f\u6709\u72b6\u6001\u7684\u3002\u4f46\u662f\uff0c\u5f53\u65b0\u7684\u8282\u70b9\u52a0\u5165\u6216\u8005\u51cf\u5c11\uff0c\u6574\u8282\u70b9\u95f4\u7684 Chunk \u4f1a\u91cd\u65b0\u5206\u914d\uff0c\u5df2\u9002\u5e94\u65b0\u7684\u6563\u5217\u73af\u3002\u800c Loki \u5e95\u5c42\u5b58\u50a8\u7684\u5b9e\u73b0 Cortex \u5df2\u7ecf\u5728\u5b9e\u9645\u7684\u751f\u4ea7\u4e2d\u6295\u5165\u4f7f\u7528\u591a\u5e74\u4e86\u3002<\/p>\n<h2>\u5b89\u88c5 Loki<\/h2>\n<h3>Installation methods<\/h3>\n<p>Instructions for different methods of installing Loki and Promtail.<\/p>\n<ul>\n<li>Install using Tanka (recommended)<\/li>\n<li>Install through Helm<\/li>\n<li>Install through Docker or Docker Compose<\/li>\n<li>Install and run locally<\/li>\n<li>Install from source<\/li>\n<\/ul>\n<h3>General process<\/h3>\n<p>In order to run Loki, you must:<\/p>\n<ol>\n<li>Download and install both Loki and Promtail.<\/li>\n<li>Download config files for both programs.<\/li>\n<li>Start Loki.<\/li>\n<li>Update the Promtail config file to get your logs into Loki.<\/li>\n<li>Start Promtail.<\/li>\n<\/ol>\n<blockquote>\n<p>Loki \u5b98\u65b9\u5df2\u7ecf\u5199\u5f97\u5f88\u8be6\u7ec6\u4e86\uff0c\u6211\u4ee5 docker-compose \u4e3a\u4f8b\u505a\u4e2a\u7b80\u5355\u7684\u6f14\u793a<\/p>\n<\/blockquote>\n<p>Install with Docker Compose<\/p>\n<pre><code>version: \"3\"  networks:   loki:  services:   loki:     image: grafana\/loki:latest     ports:       - \"3100:3100\"     command: -config.file=\/etc\/loki\/local-config.yaml     networks:       - loki    promtail:     image: grafana\/promtail:latest     volumes:       - \/var\/log:\/var\/log     command: -config.file=\/etc\/promtail\/config.yml     networks:       - loki    grafana:     image: grafana\/grafana:latest     ports:       - \"3000:3000\"     networks:       - loki <\/code><\/pre>\n<p>Run the following commands in your command line. They work for Windows or Linux systems.<\/p>\n<pre><code>wget https:\/\/raw.githubusercontent.com\/grafana\/loki\/v2.0.0\/production\/docker-compose.yaml -O docker-compose.yaml docker-compose -f docker-compose.yaml up -d  [[email&#160;protected] loki]# docker-compose ps      Name                    Command               State           Ports --------------------------------------------------------------------------------- loki_grafana_1    \/run.sh                          Up      0.0.0.0:3000-&gt;3000\/tcp loki_loki_1       \/usr\/bin\/loki -config.file ...   Up      0.0.0.0:3100-&gt;3100\/tcp loki_promtail_1   \/usr\/bin\/promtail -config. ...   Up <\/code><\/pre>\n<h2>Loki \u4f7f\u7528<\/h2>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u8bbf\u95ee\u4e0a\u9762\u8282\u70b9\u7684 3000 \u7aef\u53e3\u8bbf\u95ee grafana\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f7f\u7528(admin:admin)\u8bbf\u95ee -&gt; \u9009\u62e9\u6dfb\u52a0\u6570\u636e\u6e90\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201108_5fa833301ef17.png\" alt=\"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK\" \/><\/p>\n<p>grafana-loki-dashsource<\/p>\n<p>\u5728\u6570\u636e\u6e90\u5217\u8868\u4e2d\u9009\u62e9<code>Loki<\/code>\uff0c\u914d\u7f6e Loki \u6e90\u5730\u5740\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201108_5fa83333cd875.png\" alt=\"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK\" \/><\/p>\n<p>grafana-loki-dashsource-config<\/p>\n<p>\u6e90\u5730\u5740\u914d\u7f6e<code>http:\/\/loki:3100<\/code>\u5373\u53ef\uff0c\u4fdd\u5b58\u3002<\/p>\n<p>\u4fdd\u5b58\u5b8c\u6210\u540e\uff0c\u5207\u6362\u5230 grafana \u5de6\u4fa7\u533a\u57df\u7684<code>Explore<\/code>\uff0c\u5373\u53ef\u8fdb\u5165\u5230<code>Loki<\/code>\u7684\u9875\u9762\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201108_5fa8333882394.png\" alt=\"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK\" \/><\/p>\n<p>grafana-loki<\/p>\n<p>\u7136\u540e\u6211\u4eec\u70b9\u51fb<code>Log labels<\/code>\u5c31\u53ef\u4ee5\u628a\u5f53\u524d\u7cfb\u7edf\u91c7\u96c6\u7684\u65e5\u5fd7\u6807\u7b7e\u7ed9\u663e\u793a\u51fa\u6765\uff0c\u53ef\u4ee5\u6839\u636e\u8fd9\u4e9b\u6807\u7b7e\u8fdb\u884c\u65e5\u5fd7\u7684\u8fc7\u6ee4\u67e5\u8be2\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201108_5fa8333cd3dd9.png\" alt=\"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK\" \/><\/p>\n<p>grafana-loki-log-labels<\/p>\n<p>\u6bd4\u5982\u6211\u4eec\u8fd9\u91cc\u9009\u62e9<code>\/var\/log\/messages<\/code>\uff0c\u5c31\u4f1a\u628a\u8be5\u6587\u4ef6\u4e0b\u9762\u7684\u65e5\u5fd7\u8fc7\u6ee4\u5c55\u793a\u51fa\u6765\uff0c\u4e0d\u8fc7\u7531\u4e8e\u65f6\u533a\u7684\u95ee\u9898\uff0c\u53ef\u80fd\u8fd8\u9700\u8981\u8bbe\u7f6e\u4e0b\u65f6\u95f4\u624d\u53ef\u4ee5\u770b\u5230\u6570\u636e\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201108_5fa83340c634f.png\" alt=\"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK\" \/><\/p>\n<p>grafana-loki-logs<\/p>\n<h3>\u9009\u62e9\u5668<\/h3>\n<p>\u5bf9\u4e8e\u67e5\u8be2\u8868\u8fbe\u5f0f\u7684\u6807\u7b7e\u90e8\u5206\uff0c\u5c06\u5176\u5305\u88c5\u5728\u82b1\u62ec\u53f7\u4e2d<code>{}<\/code>\uff0c\u7136\u540e\u4f7f\u7528\u952e\u503c\u5bf9\u7684\u8bed\u6cd5\u6765\u9009\u62e9\u6807\u7b7e\uff0c\u591a\u4e2a\u6807\u7b7e\u8868\u8fbe\u5f0f\u7528\u9017\u53f7\u5206\u9694\uff0c\u6bd4\u5982\uff1a<\/p>\n<pre><code>{app=\"mysql\",name=\"mysql-backup\"} <\/code><\/pre>\n<p>\u76ee\u524d\u652f\u6301\u4ee5\u4e0b\u6807\u7b7e\u5339\u914d\u8fd0\u7b97\u7b26\uff1a<\/p>\n<ul>\n<li><code>=<\/code>\u7b49\u4e8e<\/li>\n<li><code>!=<\/code>\u4e0d\u76f8\u7b49<\/li>\n<li><code>=~<\/code>\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d<\/li>\n<li><code>!~<\/code>\u4e0d\u5339\u914d\u6b63\u5219\u8868\u8fbe\u5f0f<\/li>\n<\/ul>\n<p>\u6bd4\u5982\uff1a<\/p>\n<pre><code>{name=~\"mysql.+\"} {name!~\"mysql.+\"} <\/code><\/pre>\n<p>\u9002\u7528\u4e8e<code>Prometheus<\/code>\u6807\u7b7e\u9009\u62e9\u5668\u89c4\u5219\u540c\u6837\u4e5f\u9002\u7528\u4e8e<code>Loki<\/code>\u65e5\u5fd7\u6d41\u9009\u62e9\u5668\u3002<\/p>\n<p>\u60f3\u8981\u4e86\u89e3<code>Loki<\/code>\u7684\u539f\u59cb\u8bbe\u8ba1\u6587\u6863\u7684\u53ef\u4ee5\u70b9\u51fb\u67e5\u770b\u8fd9\u91cc\u7684\u6587\u6863\uff1a<code>Loki<\/code>\u8bbe\u8ba1\u6587\u6863<\/p>\n<h3>Loki Cheat Sheet<\/h3>\n<p>See your logs<\/p>\n<p>Start by selecting a log stream from the Log labels selector.<\/p>\n<p>Alternatively, you can write a stream selector into the query field:<\/p>\n<p><code>{job=\"default\/prometheus\"}<\/code><\/p>\n<p>Here are some example streams from your logs:<\/p>\n<p><code>{job=\"varlogs\"}<\/code><\/p>\n<p>Combine stream selectors<\/p>\n<p><code>{app=\"cassandra\",namespace=\"prod\"}<\/code><\/p>\n<p>Returns all log lines from streams that have both labels.<\/p>\n<p>Filtering for search terms.<\/p>\n<p><code>{app=\"cassandra\"} |~ \"(duration|latency)s*(=|is|of)s*[d.]+\"<\/code><\/p>\n<p><code>{app=\"cassandra\"} |= \"exact match\"<\/code><\/p>\n<p><code>{app=\"cassandra\"} != \"do not match\"<\/code><\/p>\n<p>LogQL supports exact and regular expression filters.<\/p>\n<p>Count over time<\/p>\n<p><code>count_over_time({job=\"mysql\"}[5m])<\/code><\/p>\n<p>This query counts all the log lines within the last five minutes for the MySQL job.<\/p>\n<p>Rate<\/p>\n<p><code>rate(({job=\"mysql\"} |= \"error\" != \"timeout\")[10s])<\/code><\/p>\n<p>This query gets the per-second rate of all non-timeout errors within the last ten seconds for the MySQL job.<\/p>\n<p>Aggregate, count, and group<\/p>\n<p><code>sum(count_over_time({job=\"mysql\"}[5m])) by (level)<\/code><\/p>\n<p>Get the count of logs during the last five minutes, grouping by level.<\/p>\n<h2>LogQL<\/h2>\n<blockquote>\n<p>Loki \u4f7f\u7528\u4e00\u79cd\u79f0\u4e3a LogQL \u7684\u8bed\u6cd5\u6765\u8fdb\u884c\u65e5\u5fd7\u68c0\u7d22\uff0c\u8bed\u6cd5\u7c7b\u4f3c PromQL<\/p>\n<\/blockquote>\n<p>LogQL: Log Query Language<\/p>\n<p>Loki comes with its own PromQL-inspired language for queries called <em>LogQL<\/em>. LogQL can be considered a distributed <code>grep<\/code> that aggregates log sources. LogQL uses labels and operators for filtering.<\/p>\n<p>There are two types of LogQL queries:<\/p>\n<ul>\n<li><em>Log queries<\/em> return the contents of log lines.<\/li>\n<li><em>Metric queries<\/em> extend log queries and calculate sample values based on the content of logs from a log query.<\/li>\n<\/ul>\n<p>\u53d7 PromQL \u7684\u542f\u53d1\uff0cLoki \u4e5f\u6709\u81ea\u5df1\u7684 LogQL \u67e5\u8be2\u8bed\u53e5\u3002\u6839\u636e\u5b98\u65b9\u7684\u8bf4\u6cd5\uff0c\u5b83\u5c31\u50cf\u4e00\u4e2a<code>\u5206\u5e03\u5f0f\u7684 grep \u65e5\u5fd7\u805a\u5408\u67e5\u770b\u5668<\/code>\u3002\u548c PromeQL \u4e00\u6837\uff0cLogQL \u4e5f\u662f\u4f7f\u7528\u6807\u7b7e\u548c\u8fd0\u7b97\u7b26\u8fdb\u884c\u8fc7\u6ee4\uff0c\u5b83\u4e3b\u8981\u5206\u4e3a\u4e24\u4e2a\u90e8\u5206\uff1a<\/p>\n<ul>\n<li>log stream selector \uff08\u65e5\u5fd7\u6d41\u9009\u62e9\u5668\uff09<\/li>\n<li>filter expression \uff08\u8fc7\u6ee4\u5668\u8868\u8fbe\u5f0f\uff09<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201108_5fa83344cb425.png\" alt=\"Grafana Loki \u5f00\u6e90\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\u4ee3\u66ff ELK \u6216 EFK\" \/><\/p>\n<p>\u6211\u4eec\u7528\u8fd9\u4e24\u90e8\u5206\u5c31\u53ef\u4ee5\u5728 Loki \u4e2d\u7ec4\u5408\u51fa\u6211\u4eec\u60f3\u8981\u7684\u529f\u80fd\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u6211\u4eec\u53ef\u4ee5\u62ff\u6765\u505a\u5982\u4e0b\u529f\u80fd<\/p>\n<ul>\n<li>\u6839\u636e\u65e5\u5fd7\u6d41\u9009\u62e9\u5668\u67e5\u770b\u65e5\u5fd7\u5185\u5bb9<\/li>\n<li>\u901a\u8fc7\u8fc7\u6ee4\u89c4\u5219\u5728\u65e5\u5fd7\u6d41\u4e2d\u8ba1\u7b97\u76f8\u5173\u7684\u5ea6\u91cf\u6307\u6807<\/li>\n<\/ul>\n<h3>Log Stream Selector<\/h3>\n<p>\u65e5\u5fd7\u6d41\u9009\u62e9\u5668\u8fd9\u90e8\u5206\u548c PromQL \u7684\u8bed\u6cd5\u4e00\u6837\uff0c\u4e3b\u8981\u4e5f\u662f\u901a\u8fc7\u91c7\u96c6\u4e0a\u6765\u7684\u65e5\u5fd7 label \u6765\u786e\u5b9a\u4f60\u8981\u67e5\u8be2\u7684\u65e5\u5fd7\u6d41\u3002\u901a\u5e38 label \u7684\u5339\u914d\u8fd0\u7b97\u652f\u6301\u4ee5\u4e0b\u51e0\u79cd\uff1a<\/p>\n<ul>\n<li>\n<p>=: \u5b8c\u5168\u5339\u914d<\/p>\n<\/li>\n<li>\n<p>!=: \u4e0d\u5339\u914d<\/p>\n<\/li>\n<li>\n<p>=~: \u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d<\/p>\n<\/li>\n<li>\n<p>!~: \u6b63\u5219\u8868\u8fbe\u5f0f\u4e0d\u5339\u914d<\/p>\n<p>{app=&#8221;mysql&#8221;,name=~&#8221;mysql-backup.+&#8221;}<\/p>\n<\/li>\n<\/ul>\n<ul>\n<li><code>=<\/code>: exactly equal.<\/li>\n<li><code>!=<\/code>: not equal.<\/li>\n<li><code>=~<\/code>: regex matches.<\/li>\n<li><code>!~<\/code>: regex does not match.<\/li>\n<\/ul>\n<h3>Filter Expression<\/h3>\n<pre><code>{instance=~\"kafka-[23]\",name=\"kafka\"} != \"kafka.server:type=ReplicaManager\" <\/code><\/pre>\n<ul>\n<li><code>|=<\/code>: Log line contains string.<\/li>\n<li><code>!=<\/code>: Log line does not contain string.<\/li>\n<li><code>|~<\/code>: Log line matches regular expression.<\/li>\n<li><code>!~<\/code>: Log line does not match regular expression.<\/li>\n<\/ul>\n<h3>Metric Queries<\/h3>\n<p>\u8fd9\u4e2a\u5176\u5b9e\u5c31\u8ddf prometheus \u4e2d\u7684\u5f88\u60f3\u50cf\u4e86.<\/p>\n<pre><code>rate({job=\"mysql\"} |= \"error\" != \"timeout\" [5m]) <\/code><\/pre>\n<ul>\n<li><code>rate<\/code>: calculates the number of entries per second<\/li>\n<li><code>count_over_time<\/code>: counts the entries for each log stream within the given range.<\/li>\n<li><code>bytes_rate<\/code>: calculates the number of bytes per second for each stream.<\/li>\n<li><code>bytes_over_time<\/code>: counts the amount of bytes used by each log stream for a given range.<\/li>\n<\/ul>\n<h3>Aggregation operators<\/h3>\n<p>\u5f53\u7136\u8fd8\u652f\u6301\u4e00\u4e9b\u805a\u5408\u64cd\u4f5c\uff0c\u6bd4\u5982<\/p>\n<pre><code>avg(rate(({job=\"nginx\"} |= \"GET\")[10s])) by (region) <\/code><\/pre>\n<ul>\n<li><code>sum<\/code>: Calculate sum over labels<\/li>\n<li><code>min<\/code>: Select minimum over labels<\/li>\n<li><code>max<\/code>: Select maximum over labels<\/li>\n<li><code>avg<\/code>: Calculate the average over labels<\/li>\n<li><code>stddev<\/code>: Calculate the population standard deviation over labels<\/li>\n<li><code>stdvar<\/code>: Calculate the population standard variance over labels<\/li>\n<li><code>count<\/code>: Count number of elements in the vector<\/li>\n<li><code>bottomk<\/code>: Select smallest k elements by sample value<\/li>\n<li><code>topk<\/code>: Select largest k elements by sample value<\/li>\n<\/ul>\n<p>\u8fd8\u6709\u5f88\u591a\u6bd4\u5982\u2019and, or\u2019\u7684\u64cd\u4f5c\u90fd\u662f\u652f\u6301, \u5c31\u4e0d\u4e00\u4e00\u642c\u8fd0\u4e86<\/p>\n<p>https:\/\/grafana.com\/docs\/loki\/latest\/logql\/<\/p>\n<p>\u4e94\u5206\u949f\u4e86\u89e3 LogQL<\/p>\n<h2>\u53c2\u8003\u6587\u7ae0<\/h2>\n<p>Loki Documentation<\/p>\n<p>Loki Posts<\/p>\n<p>Loki: Prometheus-inspired, open source logging for cloud natives<\/p>\n<p>Loki \u65e5\u5fd7\u7cfb\u7edf\u8be6\u89e3<\/p>\n<p>Grafana \u65e5\u5fd7\u805a\u5408\u5de5\u5177 Loki<\/p>\n<p>Grafana Loki \u7b80\u660e\u6559\u7a0b<\/p>\n<p>Loki \u6700\u4f73\u5b9e\u8df5\uff08\u8bd1\uff09<\/p>\n<p>Loki \u8fce\u6765 2.0 \u91cd\u5927\u66f4\u65b0\uff0cLogQL \u8bed\u6cd5\u5927\u5e45\u589e\u5f3a\u200b\uff01<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>8<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4027182\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : d0m2o08 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             grafana \u7528 exploer \u770b\u65e5\u5fd7,\u8c8c\u4f3c\u6ca1\u529e\u6cd5\u63a7\u5236\u6bcf\u4e2a\u7528\u6237\u7684\u6743\u9650,\u6bd4\u5982\u6211\u7684 loki \u91cc\u6709\u5f88\u591a app<br \/>app1 \u53ea\u6709 user1 \u80fd\u770b app2 \u53ea\u6709 user2 \u80fd\u770b<\/p>\n<p>\u8bf7\u95ee\u5927\u4f6c\u8fd9\u4e2a\u5e94\u8be5\u548b\u505a\u5230\u5462?                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4027183\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Sasasu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &gt; \u800c Loki \u5e95\u5c42\u5b58\u50a8\u7684\u5b9e\u73b0 Cortex \u5df2\u7ecf\u5728\u5b9e\u9645\u7684\u751f\u4ea7\u4e2d\u6295\u5165\u4f7f\u7528\u591a\u5e74\u4e86\u3002<\/p>\n<p>\u7136\u800c\u8fd9\u4e2a cortex \u5c31\u662f\u95ee\u9898\u3002\u5b83\u672c\u8d28\u662f\u4e2a\u65f6\u5e8f\u5e93\uff0c\u800c\u4e14\u6709 prometheus \u7684\u6240\u6709\u9650\u5236\uff08 64G \u6587\u4ef6\u5927\u5c0f\uff0c5M series \u6253\u7206\u5185\u5b58\u7b49\uff09<\/p>\n<p>\u5982\u679c\u4e00\u4e2a\u65f6\u5e8f\u5e93\u80fd\u6ee1\u8db3\u4f60\u5b58\u65e5\u5fd7\u7684\u9700\u6c42\u7684\u8bdd\uff0c\u8fd8\u4e0d\u5982\u9009\u62e9\u66f4\u4e13\u4e1a\u7684\u65f6\u5e8f\u5e93\u3002<\/p>\n<p>\u6bd4\u5982 influxdb \u548c timescale \u3002\u6216\u8005\u5176\u4ed6\u79c1\u6709\u7684\u5e26\u538b\u7f29\u65f6\u5e8f\u5e93\u662f\u66f4\u597d\u7684\u9009\u62e9\uff0c\u65e5\u5fd7\u7684 xz zstd \u63a5\u53e3\u548c\u6d6e\u70b9\u6570\u538b\u7f29\u6ca1\u591a\u5927\u533a\u522b\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4027184\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wsgzao <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Sasasu #2 \u55ef\u55ef\uff0c\u611f\u8c22\u63d0\u9192\uff0c\u76ee\u524d\u7ebf\u4e0a K8S \u73af\u5883\u4f7f\u7528\u7684\u662f EFK \u548c Prometheus\uff0cGrafana Loki \u76ee\u524d\u4e5f\u5904\u4e8e\u63a2\u7d22\u9636\u6bb5\uff0c\u56e0\u4e3a\u6d89\u53ca\u7684\u5408\u4f5c\u9879\u76ee\u8f83\u591a\u65e0\u6cd5\u50cf\u4e4b\u524d\u4e00\u6837\u4e13\u6ce8\u4e8e\u7ba1\u7406\u5185\u90e8\u5e73\u53f0\uff0c\u6253\u7b97 EFK \u548c Loki \u5e76\u884c\u505a\u4e0b\u6d4b\u8bd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4027185\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : borivosky <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             loki \u786e\u5b9e\u8f7b\u91cf\uff0c\u4e0d\u8fc7\u5c11\u4e86\u805a\u5408\u67e5\u8be2\u611f\u89c9\u6709\u70b9\u9e21\u808b\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4027186\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Rwing <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e3b\u8981\u662f\u770b\u67e5\u8be2\u529f\u80fd\u5982\u4f55\uff0c\u6bd5\u7adf\u65e5\u5fd7\u66f4\u591a\u662f\u7528\u6765\u67e5\u8be2\u7684\u3002\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4027187\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : aec4d <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5927\u591a\u6570\u67e5\u8be2\u53ea\u5173\u6ce8\u4e00\u5b9a\u65f6\u95f4\u8303\u56f4\u548c\u4e00\u4e9b\u7b80\u5355\u7684\u53c2\u6570\uff08\u5982\uff1ahost \u3001service \u7b49\uff09<br \/>\u4ee5\u4e0a\u5047\u8bbe\u662f\u5b8c\u5168\u9519\u8bef\u7684,\u4f5c\u4e3a\u4e00\u4e2a\u67e5\u8be2\u5e73\u53f0\uff0c\u76f4\u63a5\u9650\u5236\u67e5\u8be2\u80fd\u529b\uff0c\u7136\u540e\u5ba3\u79f0\u5404\u79cd\u597d\u5904\u7ad9\u4e0d\u4f4f\u811a<br \/>\u6bd4\u5982\u65e5\u5fd7\u91cc\u9762\u8bb0\u5f55\u4e86\u8ba2\u5355\u53f7, \u9700\u8981\u4f7f\u7528\u8ba2\u5355\u53f7\u67e5\u8be2\u5168\u90e8\u76f8\u5173\u65e5\u5fd7                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4027188\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : joesonw <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @aec4d \u8ba2\u5355\u53f7\u8fd9\u79cd\u4e1c\u897f\u4f5c\u4e3a meta, \u7528 key=value \u6253\u51fa\u6765\u5440. \u53ea\u662f\u4e0d\u7d22\u5f15\u65e5\u5fd7\u5168\u6587\u800c\u5df2. \u9700\u8981\u7d22\u5f15\u7684\u81ea\u5df1\u8fbe\u6210 kv \u5c31\u597d\u4e86.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4027189\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : aec4d <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @joesonw \u65f6\u5e8f\u6570\u636e\u5e93\u5f53\u4e0d\u4e86 kv, \u5bb9\u7eb3\u4e0d\u4e86\u9ad8\u7eac\u6570\u636e\uff0c\u6bcf\u4e2a\u9700\u8981\u8fc7\u6ee4\u7684\u4fe1\u606f\u90fd\u653e\u5230 meta \u91cc\u9762\u662f\u4e0d\u53ef\u80fd\u7684\u3002https:\/\/prometheus.io\/docs\/practices\/naming\/#labels                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Grafana Loki \u5f00\u6e90\u65e5\u5fd7&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/186638"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=186638"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/186638\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=186638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=186638"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=186638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}