{"id":31,"date":"2021-01-08T16:23:50","date_gmt":"2021-01-08T08:23:50","guid":{"rendered":"https:\/\/similiaotian.com\/?p=31"},"modified":"2021-01-08T16:23:50","modified_gmt":"2021-01-08T08:23:50","slug":"010801","status":"publish","type":"post","link":"https:\/\/99.feige5.com\/?p=31","title":{"rendered":"\u5982\u4f55\u7528LogQL\u5728\u51e0\u79d2\u5185\u5feb\u901f\u67e5\u8be2TB\u7ea7\u7684\u65e5\u5fd7"},"content":{"rendered":"\n<p>LogQL\u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u53d7Prometheus\u7684PromQL\u542f\u53d1\u3002\u4f46\u662f\uff0c\u5f53\u6d89\u53ca\u5230\u5728\u8fc7\u6ee4\u6d77\u91cf\u65e5\u5fd7\u65f6\uff0c\u6211\u4eec\u5c31\u50cf\u9762\u4e34\u5728\u5927\u6d77\u635e\u9488\u4e00\u6837\u590d\u6742\u3002LogQL\u662fLoki\u7279\u6709\u7684\u8bed\u53e5\uff0c\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u63d0\u4f9bLogQL\u7684\u5feb\u901f\u8fc7\u6ee4\u5668\u67e5\u8be2\u6280\u5de7\uff0c\u8fd9\u4e9b\u67e5\u8be2\u53ef\u4ee5\u5728\u51e0\u79d2\u949f\u5185\u8fc7\u6ee4\u6389\u6570TB\u7684\u6570\u636e\u3002<\/p>\n\n\n\n<p>\u5728Loki\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e09\u79cd\u7c7b\u578b\u7684\u8fc7\u6ee4\u5668\uff1a <img decoding=\"async\" alt=\"\" src=\"https:\/\/p6-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/46a47822ff5141baa6ba84201fde5e03~tplv-k3u1fbpfcp-watermark.image\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Label matchers<\/h2>\n\n\n\n<p>Label matchers\uff08\u6807\u7b7e\u5339\u914d\u5668\uff09\u662f\u4f60\u7684\u7b2c\u4e00\u9053\u9632\u7ebf\uff0c\u662f\u5927\u5e45\u51cf\u5c11\u4f60\u641c\u7d22\u7684\u65e5\u5fd7\u6570\u91cf\uff08\u4f8b\u5982\uff0c\u4ece100TB\u52301TB\uff09\u7684\u6700\u597d\u65b9\u6cd5\u3002\u5f53\u7136\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u9700\u8981\u5728\u7684\u65e5\u5fd7\u91c7\u96c6\u7aef\u4e0a\u6709\u826f\u597d\u7684\u6807\u7b7e\u5b9a\u4e49\u89c4\u8303\u3002\u57fa\u672c\u4e0a\uff0c\u6807\u7b7e\u5e94\u8be5\u5b9a\u4e49\u7684\u7c7b\u578b\u5305\u62ec\uff0c\u5de5\u4f5c\u8d1f\u8f7d\u3001\u96c6\u7fa4\u3001\u547d\u540d\u7a7a\u95f4\u548c\u5bb9\u5668\u7b49\uff0c\u8fd9\u6837\u4f60\u5c31\u53ef\u4ee5\u5728\u591a\u4e2a\u4e0d\u540c\u7684\u7ef4\u5ea6\u4e0a\u5bf9\u6570\u636e\u8fdb\u884c\u5207\u5206\u3002\u6bd4\u5982\u8bf4<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4e00\u4e2a\u5e94\u7528\u5728\u591a\u4e2a\u96c6\u7fa4\u4e0a\u8fd0\u884c<\/li><li>\u843d\u5728\u591a\u4e2ak8s\u96c6\u7fa4\u547d\u540d\u7a7a\u95f4\u7684\u5f00\u53d1\u73af\u5883<\/li><li>\u751f\u4ea7\u73af\u5883\u7684\u547d\u540d\u7a7a\u95f4<\/li><\/ul>\n\n\n\n<p>\u4e00\u4e2a\u6709\u6548\u7684\u7ecf\u9a8c\u6cd5\u5219\u662f\uff1a\u4f60\u81f3\u5c11\u9700\u8981\u4e00\u4e2a<code>=<\/code>\u5339\u914d\u5668<code>\uff08\u4f8b\u5982\uff0c{cluster=\"us-central1\"}\uff09<\/code>\u3002\u5426\u5219\uff0c\u4f60\u5c06\u4e0d\u5f97\u4e0d\u63d0\u53d6\u6574\u4e2a\u7d22\u5f15\u6570\u636e\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u4f46\u6709\u4e00\u4e2a\u4f8b\u5916\u3002\u5982\u679c\u5339\u914d\u5668\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u5b57\u5143\uff0c\u6bd4\u5982{container=~&#8221;promtail|agent&#8221;}\uff0c\u540c\u65f6\u53ea\u6709\u4e00\u4e2a\u5355\u4e00\u7684regex\u5339\u914d\u5668\uff0cLoki\u53ef\u4ee5\u81ea\u884c\u4f18\u5316\u67e5\u8be2<\/p><\/blockquote>\n\n\n\n<p>\u4e0b\u9762\u5c31\u662f\u4e00\u4e9b\u5b9e\u7528\u7684\u6837\u4f8b\uff1a<\/p>\n\n\n\n<p>\u597d\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{cluster=\"us-central1\"}\n\n{container=\"istio\"}\n\n{cluster=\"us-central1\", container=~\"agent|promtail\"}\n\u590d\u5236\u4ee3\u7801<\/code><\/pre>\n\n\n\n<p>\u574f\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{job=~\".*\/queue\"}\n\n{namespace!~\"dev-.*\"}\n\u590d\u5236\u4ee3\u7801<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Line filters<\/h2>\n\n\n\n<p>Line filters\uff08\u884c\u8fc7\u6ee4\u5668\uff09\u662f\u60a8\u7684\u7b2c\u4e8c\u4e2a\u597d\u670b\u53cb\uff0c\u56e0\u4e3a\u5b83\u4eec\u6267\u884c\u8fc7\u7a0b\u8d85\u7ea7\u5feb\u3002\u5b83\u5141\u8bb8\u4f60\u8fc7\u6ee4\u5305\u542b(<code>|=<\/code>)\u6216\u4e0d\u5305\u542b(<code>!=<\/code>)\u5b57\u7b26\u4e32\u7684\u65e5\u5fd7\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u6765\u5339\u914d(<code>|~<\/code>)\u6216\u4e0d\u5339\u914d(<code>!~<\/code>)\u65e5\u5fd7\uff0c\u4f46\u4f60<code>\u5e94\u8be5\u628a\u5b83\u4eec\u653e\u5728\u6807\u7b7e\u5339\u914d\u5668\u4e4b\u540e<\/code>\u3002<\/p>\n\n\n\n<p>\u73b0\u5728\uff0c\u5f53\u6211\u4eec\u5c06\u8fd9\u4e9b\u8fc7\u6ee4\u5668\u8fde\u8d77\u6765\u4f7f\u7528\u65f6\uff0c\u8981\u6ce8\u610f<code>\u8fc7\u6ee4\u5668\u7684\u987a\u5e8f<\/code>\u3002\u5148\u7528\u90a3\u4e9b\u80fd\u8fc7\u6ee4\u6700\u591a\u65e5\u5fd7\u7684\u8fc7\u6ee4\u5668\uff0c\u7136\u540e\u518d\u4f7f\u7528\u6b63\u5219\uff0c\u5b83\u6bd4<code>=<\/code>\u548c<code>!=<\/code>\u6162\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u4f46\u6709\u4e00\u4e2a\u4f8b\u5916\u3002<code>|~ \"error|fatal \"<\/code>\u53ef\u4ee5\u88abLoki\u4f18\u5316\u6389 \u5b9e\u9645\u4e0a\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u88abloki\u81ea\u52a8\u8fc7\u6ee4\u6389\u4e86\uff0c\u6240\u4ee5\u4e0d\u4f1a\u6267\u884c\u6b63\u5219\u5339\u914d<\/p><\/blockquote>\n\n\n\n<p>\u4e00\u4e2a\u597d\u7684\u65b9\u6cd5\u662f\u5148\u6dfb\u52a0\u4e00\u4e2a\u7b26\u5408\u4f60\u8981\u627e\u7684\u4e1c\u897f\u7684\u8fc7\u6ee4\u5668\uff0c\u4f8b\u5982\uff0c<code>|= \"err\"<\/code>\u3002\u7136\u540e\u518d\u6dfb\u52a0\u8d8a\u6765\u8d8a\u591a\u7684\u4e0d\u7b49\u5f0f\u6765\u8fc7\u6ee4\u4f60\u4e0d\u60f3\u8981\u7684\u4e1c\u897f\uff0c\u76f4\u5230\u6700\u7ec8\u5f97\u5230\u7c7b\u4f3c\u4e8e\u4e0b\u9762\u8fd9\u6837\u7684\u7ed3\u679c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>|= \"err\" != \"timeout\" != \"cancelled\" |~ \"failed.*\" != \"memcached\"\n\u590d\u5236\u4ee3\u7801<\/code><\/pre>\n\n\n\n<p>\u73b0\u5728\uff0c\u5982\u679c\u4f60\u610f\u8bc6\u5230\u4f60\u7684\u5927\u90e8\u5206\u9519\u8bef\u6765\u81eamemcached\uff0c\u90a3\u4e48\u5c31\u628a\u5b83\u79fb\u5230\u7b2c\u4e00\u4e2a\u4f4d\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>!= \"memcached\" |= \"err\" != \"timeout\" != \"cancelled\" |~ \"failed.*\"\n\u590d\u5236\u4ee3\u7801<\/code><\/pre>\n\n\n\n<p>\u8fd9\u6837\u4e00\u6765\uff0c\u540e\u7eed\u8fc7\u6ee4\u5668\u7684\u6267\u884c\u6b21\u6570\u5c31\u4f1a\u51cf\u5c11\u3002<\/p>\n\n\n\n<p>\u9664\u6b64\u4e4b\u5916\uff0c\u884c\u8fc7\u6ee4\u5668\u4e5f\u5f88\u9002\u5408\u67e5\u627eIP\u3001TraceID\u3001UUID\u7b49\u7c7b\u578b\u7684\u65e5\u5fd7\u3002\u6bd4\u5982\u4e0b\u9762\u8fd9\u4e2a\u4e5f\u4e00\u4e2a\u5f88\u597d\u7684\u67e5\u8be2\u65b9\u5f0f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{namespace=\"prod\"} |= \"traceID=2e2er8923100\"\n\u590d\u5236\u4ee3\u7801<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u4f60\u60f3\u8ba9\u8fd9\u4e2atraceID\u7684\u6240\u6709\u65e5\u5fd7\u90fd\u7b26\u5408\u67d0\u4e2aregex\uff0c\u53ef\u4ee5\u5728ID\u8fc7\u6ee4\u5668\u540e\u9762\u52a0\u4e0a<code>|~ \"\/api\/v.+\/query\"<\/code>\uff0c\u8fd9\u6837\u5c31\u4e0d\u4f1a\u5bf9prod\u547d\u540d\u7a7a\u95f4\u7684\u6bcf\u4e2apod\u4e2d\u53bb\u6dfb\u52a0\u67e5\u8be2\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Label filters<\/h2>\n\n\n\n<p>Label filters\uff08\u6807\u7b7e\u8fc7\u6ee4\u5668\uff09\u63d0\u4f9b\u4e86\u66f4\u590d\u6742\u7684\u8ba1\u7b97\u529f\u80fd\uff08duration\uff0cnumerical\u7b49\uff09\uff0c\u4f46\u662f\u5b83\u4eec\u901a\u5e38\u9700\u8981\u5148\u63d0\u53d6\u6807\u7b7e\uff0c\u7136\u540e\u518d\u5c06\u6807\u7b7e\u503c\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u7c7b\u578b\u3002\u8fd9\u610f\u5473\u7740\u5b83\u4eec\u901a\u5e38\u662f\u6700\u6162\u7684\uff0c\u56e0\u6b64\u6211\u4eec\u5e94\u8be5<strong>\u6700\u540e\u4f7f\u7528\u5b83\u4eec<\/strong>\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u5b9e\u9645\u4e0a\u6211\u4eec\u53ef\u4ee5\u5728\u4e0d\u63d0\u53d6\u6807\u7b7e\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u6807\u7b7e\u8fc7\u6ee4\u5668\uff08\u4f7f\u7528<code>|json<\/code>\u6216<code>|logfmt<\/code>\u7b49\u89e3\u6790\u5668\uff09\u3002\u6807\u7b7e\u8fc7\u6ee4\u5668\u4e5f\u53ef\u4ee5\u5728\u7d22\u5f15\u6807\u7b7e\u4e0a\u5de5\u4f5c\u3002\u4f8b\u5982\uff0c<code>{job=\"ingress\/nginx\"}\u3002| status_code &gt;= 400 and cluster=\"us-central2\"<\/code>\u53ef\u4ee5\u6b63\u5e38\u5de5\u4f5c\uff0c\u4f46\u4f60\u771f\u6b63\u5e94\u8be5\u95ee\u81ea\u5df1\u7684\u662f\uff0c\u4f60\u662f\u5426\u9700\u8981\u5c06 status_code \u4f5c\u4e3a\u7d22\u5f15\u6807\u7b7e\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u4f60\u4e0d\u5e94\u8be5\uff0c\u4f46\u4f60\u53ef\u4ee5\u8003\u8651\u63d0\u53d6 status_code \u4f5c\u4e3a\u6807\u7b7e\uff0c\u8fd9\u53ef\u4ee5\u5c06\u5927\u6279\u91cf\u7684\u6d41\uff08\u6bcf\u79d2\u8d85\u8fc7\u4e00\u5343\u884c\uff09\u5206\u89e3\u6210\u72ec\u7acb\u7684\u6d41\u3002<\/p><\/blockquote>\n\n\n\n<p>\u5c3d\u7ba1<code>| json<\/code> \u548c<code>| logfmt<\/code>\u89e3\u6790\u5668\u5f88\u5feb\uff0c\u4f46\u662f\u89e3\u6790<code>| regex<\/code>\u5374\u5f88\u6162\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u5728\u4f7f\u7528\u89e3\u6790\u5668\u65f6\uff0c\u6211\u603b\u662f\u5728\u5b83\u524d\u9762\u52a0\u4e0a\u4e00\u4e2a\u884c\u8fc7\u6ee4\u5668\u3002\u4f8b\u5982\uff0c\u5728\u6211\u7684Go\u5e94\u7528\u7a0b\u5e8f\uff08\u5305\u62ecLoki\uff09\u4e2d\uff0c\u6211\u7684\u6240\u6709\u65e5\u5fd7\u5747\u652f\u6301\u663e\u793a\u6587\u4ef6\u540d\u548c\u884c\u53f7\uff08\u6b64\u5904\u4e3a<code>caller=metrics.go:83<\/code>)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>level=info ts=2020-12-07T21:03:22.885781801Z caller=metrics.go:83 org_id=29 traceID=4078dafcbc079822 latency=slow query=\"{cluster=\\\"ops-tools1\\\",job=\\\"loki-ops\/querier\\\"} != \\\"logging.go\\\" != \\\"metrics.go\\\" |= \\\"recover\\\"\" query_type=filter range_type=range length=168h0m1s step=5m0s duration=54.82511258s status=200 throughput=8.3GB total_bytes=454GB\n\u590d\u5236\u4ee3\u7801<\/code><\/pre>\n\n\n\n<p>\u56e0\u6b64\uff0c\u5f53\u6211\u4eec\u60f3\u8fc7\u6ee4\u7f13\u6162\u7684\u8bf7\u6c42\u65f6\uff0c\u5e94\u8be5\u5148\u5bf9<code>\u8bb0\u5f55\u6587\u4ef6\u548c\u884c\u53f7<\/code>\u8fdb\u884c\u8fc7\u6ee4\uff0c\u7136\u540e\u518d\u8fdb\u884c\u89e3\u6790\uff0c\u6700\u540e\u518d\u5c06\u63d0\u53d6\u7684\u6807\u7b7e\u8fdb\u884c\u6bd4\u8f83\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{namespace=\"loki-ops\",container=\"query-frontend\"} \n|= \"caller=metrics.go:83\" \n| logfmt \n| throughput &gt; 1GB and duration &gt; 10s and org_id=29\n\u590d\u5236\u4ee3\u7801<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u7ed3\u8bba<\/h2>\n\n\n\n<p>\u8fd9\u4e09\u4e2a\u8fc7\u6ee4\u5668\uff08Label matchers\uff0cLine filters\u548cLabel filters\uff09\u5c31\u50cf\u4e00\u4e2a\u7ba1\u9053\uff0c\u5c06\u9010\u6b65\u5904\u7406\u65e5\u5fd7\u3002\u6211\u4eec\u5e94\u8be5\u5c1d\u8bd5\u5728\u6bcf\u4e2a\u6b65\u9aa4\u4e0a\u5c3d\u53ef\u80fd\u51cf\u5c11\u64cd\u4f5c\uff0c\u56e0\u4e3a\u5bf9\u4e8e\u6bcf\u4e2a\u884c\uff0c\u6bcf\u4e2a\u540e\u7eed\u6b65\u9aa4\u6267\u884c\u7684\u901f\u5ea6\u90fd\u53ef\u80fd\u66f4\u6162\u3002<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>LogQL\u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u53d7Prometheus\u7684PromQL\u542f\u53d1\u3002\u4f46\u662f\uff0c\u5f53\u6d89\u53ca\u5230\u5728\u8fc7\u6ee4\u6d77\u91cf\u65e5\u5fd7\u65f6\uff0c\u6211\u4eec&hellip; <a href=\"https:\/\/99.feige5.com\/?p=31\" class=\"more-link read-more\" rel=\"bookmark\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">\u5982\u4f55\u7528LogQL\u5728\u51e0\u79d2\u5185\u5feb\u901f\u67e5\u8be2TB\u7ea7\u7684\u65e5\u5fd7<\/span><i class=\"fa fa-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":{"0":"post-31","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-uncategorized","7":"h-entry","9":"h-as-article"},"_links":{"self":[{"href":"https:\/\/99.feige5.com\/index.php?rest_route=\/wp\/v2\/posts\/31","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/99.feige5.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/99.feige5.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/99.feige5.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/99.feige5.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=31"}],"version-history":[{"count":0,"href":"https:\/\/99.feige5.com\/index.php?rest_route=\/wp\/v2\/posts\/31\/revisions"}],"wp:attachment":[{"href":"https:\/\/99.feige5.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/99.feige5.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/99.feige5.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}