{"id":11119,"date":"2022-11-16T17:17:32","date_gmt":"2022-11-16T09:17:32","guid":{"rendered":"https:\/\/www.lwops.cn\/?p=11119"},"modified":"2022-11-16T17:17:33","modified_gmt":"2022-11-16T09:17:33","slug":"prometheus%e6%8a%80%e6%9c%af%e5%88%86%e4%ba%ab-%e7%9b%91%e6%8e%a7%e5%90%84%e4%b8%aa%e6%8c%87%e6%a0%87%e7%9a%84%e5%90%ab%e4%b9%89%ef%bc%8c%e7%b1%bb%e5%9e%8b%ef%bc%8c%e4%bb%a5%e5%8f%8a","status":"publish","type":"post","link":"https:\/\/www.lwops.cn\/index.php\/prometheus\/prometheus-artisan\/11119","title":{"rendered":"Prometheus\u6280\u672f\u5206\u4eab\u2014\u2014\u76d1\u63a7\u5404\u4e2a\u6307\u6807\u7684\u542b\u4e49\uff0c\u7c7b\u578b\uff0c\u4ee5\u53ca\u683c\u5f0f"},"content":{"rendered":"\n
\u524d\u9762\u51e0\u671f\u4e50\u7ef4\u541b\u5df2\u7ecf\u8ddf\u5927\u5bb6\u4ecb\u7ecd\u4e86prometheus\u7684\u5b89\u88c5\u914d\u7f6e\u3001\u544a\u8b66\u89c4\u5219\u7b49\u7b49\uff0c\u672c\u671f\u5c06\u91cd\u70b9\u4ecb\u7ecdprometheus\u76d1\u63a7\u5404\u4e2a\u6307\u6807\u7684\u542b\u4e49\u3001\u7c7b\u578b\u4ee5\u53ca\u683c\u5f0f\u3002<\/p>\n\n\n\n
prometheus\u4e3b\u8981\u6709\u56db\u79cd\u7c7b\u578b\u7684\u76d1\u63a7\u6307\u6807\uff1a<\/p>\n\n\n\n
1.Counter\u7c7b\u578b\u7684\u6307\u6807\uff1a\u5176\u5de5\u4f5c\u65b9\u5f0f\u548c\u8ba1\u6570\u5668\u4e00\u6837\uff0c\u53ea\u589e\u4e0d\u51cf\uff08\u9664\u975e\u7cfb\u7edf\u53d1\u751f\u91cd\u7f6e\uff09\u3002\u5e38\u89c1\u7684\u76d1\u63a7\u6307\u6807\uff0c\u5982\u673a\u5668\u7684\u542f\u52a8\u65f6\u95f4\uff08node_cpu\uff09\uff0cHTTP\u8bbf\u95ee\u91cf\uff08http_requests_total\uff09\u7b49\u3002\u53ef\u4ee5\u901a\u8fc7PromQL\u8bed\u53e5\u5bf9\u8fd9\u4e9b\u6307\u6807\u8fdb\u884c\u5206\u6790\uff0c\u5982\uff1a
\u67e5\u8be2\u5f53\u524d\u7cfb\u7edf\u4e2d\uff0c\u8bbf\u95ee\u91cf\u524d10\u7684HTTP\u5730\u5740\uff1a<\/p>\n\n\n\n
topk(10, http_requests_total)<\/code><\/pre>\n\n\n\n2.Gauge\u5373\u4eea\u8868\u7c7b\u578b\u7684\u6307\u6807\uff0c\u4fa7\u91cd\u4e8e\u53cd\u5e94\u7cfb\u7edf\u7684\u5f53\u524d\u72b6\u6001\uff0c\u6837\u672c\u6570\u636e\u53ef\u589e\u53ef\u51cf\u3002\u5982CPU\u4f7f\u7528\u7387\uff08node_memory_MemFree\uff0c\u4e3b\u673a\u5f53\u524d\u7a7a\u95f2\u7684\u5185\u5bb9\u5927\u5c0f\uff09\uff0c\u5185\u5b58\u4f7f\u7528\u7387\uff08node_memory_MemAvailable\uff0c\u53ef\u7528\u5185\u5b58\u5927\u5c0f\uff09\uff0c\u96c6\u7fa4\u8282\u70b9\u4e2a\u6570\uff0c\u5927\u90e8\u5206\u76d1\u63a7\u6570\u636e\u90fd\u662f\u8fd9\u79cd\u7c7b\u578b\u7684\u3002 \u5982\u53ef\u901a\u8fc7PromQL\u5185\u7f6e\u51fd\u6570delta()\u53ef\u4ee5\u83b7\u53d6\u6837\u672c\u5728\u4e00\u6bb5\u65f6\u95f4\u8fd4\u56de\u5185\u7684\u53d8\u5316\u60c5\u51b5\u3002\u4f8b\u5982\uff0c\u8ba1\u7b97CPU\u6e29\u5ea6\u5728\u4e24\u4e2a\u5c0f\u65f6\u5185\u7684\u5dee\u5f02\uff1a<\/p>\n\n\n\n
delta(cpu_temp_celsius{host=\"zeus\"}[2h])\r<\/code><\/pre>\n\n\n\n3.Histogram\uff1a\u4e5f\u5c31\u662f\u76f4\u65b9\u56fe\u7c7b\u578b\u7684metric, \u80fd\u591f\u5206\u7ec4\u5206\u533a\u95f4\u663e\u793a\u6307\u6807\u7684\u4fe1\u606f\u3002\u4f8b\u5982\uff0c\u7edf\u8ba1\u5ef6\u8fdf\u57280 ~ 10ms\u4e4b\u95f4\u7684\u8bf7\u6c42\u6570\u6709\u591a\u5c11\u800c10~20ms\u4e4b\u95f4\u7684\u8bf7\u6c42\u6570\u5c31\u53ef\u91c7\u7528\u8fd9\u79cd\u65b9\u5f0f\u3002\u6ce8\u610f\u4ed6\u4e0esummary\u7684\u533a\u522b\u3002<\/p>\n\n\n\n
4.summary\uff1a\u597d\u50cf\u4e0d\u662f\u5f88\u597d\u7ffb\u8bd1\uff0c\u4e2a\u4eba\u8ba4\u4e3a\u662f\u8868\u793a\u5206\u4f4d\u6570\uff08quantile\uff09\u7684\u4fe1\u606f\u3002\u5206\u4f4d\u65700.5\u8868\u793a\u524d50%\u7684\u6570\u636e\u662f\u4ec0\u4e48\u6c34\u5e73\uff0c\u73b0\u5b9e\u751f\u6d3b\u4e2d\u7684\u4f8b\u5b50\u6bd4\u5982\u73ed\u4e0a\u6240\u6709\u5b66\u751f\u8eab\u9ad8\u7684\u4e2d\u4f4d\u6570\uff0c\u540c\u6837\u7684\u5206\u4f4d\u65700.9\u8868\u793a\u524d90%\u8eab\u9ad8\u7684\u5212\u5206\u4f4d\u7f6e\u3002 \u8fd9\u4e2a\u53ef\u4ee5\u53c2\u8003\u5b98\u65b9\u6587\u6863\u4e0a\u7684\u4f8b\u5b50\uff1a<\/p>\n\n\n\n
HELP prometheus_tsdb_wal_fsync_duration_seconds Duration of WAL fsync.\nTYPE prometheus_tsdb_wal_fsync_duration_seconds summary\nprometheus_tsdb_wal_fsync_duration_seconds{quantile=\u201c0.5\u201d} 0.012352463\nprometheus_tsdb_wal_fsync_duration_seconds{quantile=\u201c0.9\u201d} 0.014458005\nprometheus_tsdb_wal_fsync_duration_seconds{quantile=\u201c0.99\u201d} 0.017316173\nprometheus_tsdb_wal_fsync_duration_seconds_sum 2.888716127000002\nprometheus_tsdb_wal_fsync_duration_seconds_count 216\n\u4ece\u4e0a\u9762\u7684\u6837\u672c\u4e2d\u53ef\u4ee5\u5f97\u77e5\u5f53\u524dPrometheus Server\u8fdb\u884cwal_fsync\u64cd\u4f5c\u7684\u603b\u6b21\u6570\u4e3a216\u6b21\uff0c\u8017\u65f62.888716127000002s\u3002\u5176\u4e2d\u4e2d\u4f4d\u6570\uff08quantile=0.5\uff09\u7684\u8017\u65f6\u4e3a0.012352463\uff0c9\u5206\u4f4d\u6570\uff08quantile=0.9\uff09\u7684\u8017\u65f6\u4e3a0.014458005s\u3002\r<\/code><\/pre>\n\n\n\n2. Prometheus \u76d1\u63a7\u6307\u6807\u7684\u683c\u5f0f<\/h3>\n\n\n\n2. 1 \u65f6\u95f4\u5e8f\u5217<\/h2>\n\n\n\n
\u8fd9\u5c31\u6d89\u53ca\u5230Prometheus\u5b58\u50a8\u6570\u636e\u7684\u65b9\u5f0f\u662f\u65f6\u95f4\u5e8f\u5217\u7684\uff0c\u6240\u8c13\u7684\u65f6\u95f4\u5e8f\u5217\u5176\u5b9e\u5c31\u662f\u5173\u4e8e\u6307\u6807\u7684\u96c6\u5408\uff0c\u53ea\u4e0d\u8fc7\u8fd9\u4e9b\u6307\u6807\u662f\u6309\u7167\u65f6\u95f4\u987a\u5e8f\u6392\u5217\u7684\u3002<\/p>\n\n\n\n
\u6bcf\u6761time-series\u901a\u8fc7\u6307\u6807\u540d\u79f0(metrics name)\u548c\u4e00\u7ec4\u6807\u7b7e\u96c6(labelset)\u547d\u540d\u3002\u5982\u4e0b\u6240\u793a\uff0c\u53ef\u4ee5\u5c06time-series\u7406\u89e3\u4e3a\u4e00\u4e2a\u4ee5\u65f6\u95f4\u4e3aY\u8f74\u7684\u6570\u5b57\u77e9\u9635\uff1a\n^\n\u2502 . . . . . . . . . . . . . . . . . . . node_cpu{cpu=\u201ccpu0\u201d,mode=\u201cidle\u201d}\n\u2502 . . . . . . . . . . . . . . . . . . . node_cpu{cpu=\u201ccpu0\u201d,mode=\u201csystem\u201d}\n\u2502 . . . . . . . . . . . . . . . . . . node_load1{}\n\u2502 . . . . . . . . . . . . . . . . . .\nv\n<------------------ \u65f6\u95f4 ---------------->\n\u5728time-series\u4e2d\u7684\u6bcf\u4e00\u4e2a\u70b9\u79f0\u4e3a\u4e00\u4e2a\u6837\u672c\uff08sample\uff09\uff0c\u6837\u672c\u7531\u4ee5\u4e0b\u4e09\u90e8\u5206\u7ec4\u6210\uff1a\n\u6307\u6807(metric)\uff1ametric name\u548c\u63cf\u8ff0\u5f53\u524d\u6837\u672c\u7279\u5f81\u7684labelsets;\n\u65f6\u95f4\u6233(timestamp)\uff1a\u4e00\u4e2a\u7cbe\u786e\u5230\u6beb\u79d2\u7684\u65f6\u95f4\u6233;\n\u6837\u672c\u503c(value)\uff1a \u4e00\u4e2afloat64\u7684\u6d6e\u70b9\u578b\u6570\u636e\u8868\u793a\u5f53\u524d\u6837\u672c\u7684\u503c\u3002\n\u5982\uff1ahttp_request_total{status=\u201c200\u201d, method=\u201cGET\u201d}@1434417561287 => 94334<\/code><\/pre>\n\n\n\n2.2 metric\u683c\u5f0f<\/h2>\n\n\n\n
\u6bcf\u4e00\u6761metric\u7684\u683c\u5f0f\u662f\uff1a<\/p>\n\n\n\n
< metric name>{< label name>=< label value>, ...}\r<\/code><\/pre>\n\n\n\n\u5176\u4e2d\u4ee5__\u4f5c\u4e3a\u524d\u7f00\u7684\u6807\u7b7e\uff0c\u662f\u7cfb\u7edf\u4fdd\u7559\u7684\u5173\u952e\u5b57\uff0c\u53ea\u80fd\u5728\u7cfb\u7edf\u5185\u90e8\u4f7f\u7528\u3002
\u6ce8\u610f: \u5b9e\u9645\u83b7\u53d6\u7684\u4fe1\u606f\u53ef\u80fd\u4e0d\u4ec5\u4ec5\u5305\u542bmetric\uff0c\u8fd8\u6709\u4e00\u4e9b\u6ce8\u91ca<\/strong>\uff0c\u4ed6\u4eec\u90fd\u4ee5#\u5f00\u5934\uff0c\u5176\u4e2dHELP\u7528\u4e8e\u89e3\u91ca\u5f53\u524d\u6307\u6807\u7684\u542b\u4e49\uff0cTYPE\u5219\u8bf4\u660e\u5f53\u524d\u6307\u6807\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n\n\n\n\u5982\u4e0b\u9762\u8fd9\u6761\u4fe1\u606f\uff0c\u5c31\u5305\u542b\u4e86\u4e24\u6761metric\u3002<\/p>\n\n\n\n
# HELP node_cpu Seconds the cpus spent in each mode.\r\n# TYPE node_cpu counter\r\nnode_cpu{cpu=\"cpu0\",mode=\"idle\"} 362812.7890625\r\n# HELP node_load1 1m load average.\r\n# TYPE node_load1 gauge\r\nnode_load1 3.0703125\r<\/code><\/pre>\n\n\n\n\u8fd9\u4e00\u671f\u7684Prometheus\u6280\u672f\u5206\u4eab\u5230\u8fd9\u5c31\u7ed3\u675f\u4e86\uff0c\u66f4\u591a\u5f00\u6e90\u76d1\u63a7\u6280\u672f\u5206\u4eab\u8bf7\u6301\u7eed\u5173\u6ce8\u4e50\u7ef4\u5b98\u7f51<\/a>\u6216\u4e50\u7ef4\u793e\u533a<\/a>\uff08https:\/\/forum.lwops.cn\/\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"\u524d\u9762\u51e0\u671f\u4e50\u7ef4\u541b\u5df2\u7ecf\u8ddf\u5927\u5bb6\u4ecb\u7ecd\u4e86prometheus\u7684\u5b89\u88c5\u914d\u7f6e\u3001\u544a\u8b66\u89c4\u5219\u7b49\u7b49\uff0c\u672c\u671f\u5c06\u91cd\u70b9\u4ecb\u7ecdprometheus […]<\/p>\n","protected":false},"author":1,"featured_media":11061,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"themepark_post_bcolor":"#f5f5f5","themepark_post_width":"1022px","themepark_post_img":"","themepark_post_img_po":"left","themepark_post_img_re":false,"themepark_post_img_cover":false,"themepark_post_img_fixed":false,"themepark_post_hide_title":false,"themepark_post_main_b":"","themepark_post_main_p":100,"themepark_paddingblock":false,"footnotes":""},"categories":[246],"tags":[260,261,259],"class_list":["post-11119","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-prometheus-artisan","tag-prometheusjkzb","tag-prometheusjkgs","tag-prometheusjklx"],"metadata":{"_edit_lock":["1668590832:1"],"_thumbnail_id":["11061"],"_edit_last":["1"],"themepark_seo_title":["Prometheus\u76d1\u63a7\u5404\u4e2a\u6307\u6807\u7684\u542b\u4e49\uff0c\u7c7b\u578b\uff0c\u4ee5\u53ca\u683c\u5f0f"],"themepark_seo_description":["\u524d\u9762\u51e0\u671f\u4e50\u7ef4\u541b\u5df2\u7ecf\u8ddf\u5927\u5bb6\u4ecb\u7ecd\u4e86prometheus\u7684\u5b89\u88c5\u914d\u7f6e\u3001\u544a\u8b66\u89c4\u5219\u7b49\u7b49\uff0c\u672c\u671f\u5c06\u91cd\u70b9\u4ecb\u7ecdprometheus\u76d1\u63a7\u5404\u4e2a\u6307\u6807\u7684\u542b\u4e49\u3001\u7c7b\u578b\u4ee5\u53ca\u683c\u5f0f\u3002"],"themepark_seo_keyword":["Prometheus\u76d1\u63a7\u7c7b\u578b,Prometheus\u76d1\u63a7\u6307\u6807,Prometheus\u76d1\u63a7\u683c\u5f0f"],"catce":["sidebar-widgets4"],"_yoast_wpseo_primary_category":["246"],"_yoast_wpseo_focuskw":["prometheus\u76d1\u63a7\u6307\u6807"],"_yoast_wpseo_linkdex":["41"],"_yoast_wpseo_content_score":["90"],"_yoast_wpseo_estimated-reading-time-minutes":[""],"_yoast_wpseo_wordproof_timestamp":[""],"views":["8812"],"ig_es_is_post_notified":["1"]},"yoast_head":"\n
Prometheus\u6280\u672f\u5206\u4eab\u2014\u2014\u76d1\u63a7\u5404\u4e2a\u6307\u6807\u7684\u542b\u4e49\uff0c\u7c7b\u578b\uff0c\u4ee5\u53ca\u683c\u5f0f - \u4e50\u7ef4\u5b98\u7f51<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n