{"id":241586,"date":"2022-05-08T10:59:22","date_gmt":"2022-05-08T02:59:22","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=241586"},"modified":"2022-04-29T10:00:36","modified_gmt":"2022-04-29T02:00:36","slug":"go-all-prometheus","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/go-all-prometheus.html","title":{"rendered":"\u5165\u95e8Prometheus"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u5b66\u4e60\u5b89\u88c5 Prometheus \u76d1\u63a7\u548c\u8b66\u62a5\u7cfb\u7edf\u5e76\u7f16\u5199\u5b83\u7684\u67e5\u8be2\u3002 \n<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n Prometheus \u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u76d1\u63a7\u548c\u8b66\u62a5\u7cfb\u7edf\uff0c\u5b83\u76f4\u63a5\u4ece\u76ee\u6807\u4e3b\u673a\u4e0a\u8fd0\u884c\u7684\u4ee3\u7406\u7a0b\u5e8f\u4e2d\u6293\u53d6\u6307\u6807\uff0c\u5e76\u5c06\u6536\u96c6\u7684\u6837\u672c\u96c6\u4e2d\u5b58\u50a8\u5728\u5176\u670d\u52a1\u5668\u4e0a\u3002\u4e5f\u53ef\u4ee5\u4f7f\u7528\u50cf collectd_exporter \u8fd9\u6837\u7684\u63d2\u4ef6\u63a8\u9001\u6307\u6807\uff0c\u5c3d\u7ba1\u8fd9\u4e0d\u662f Promethius \u7684\u9ed8\u8ba4\u884c\u4e3a\uff0c\u4f46\u5728\u4e3b\u673a\u4f4d\u4e8e\u9632\u706b\u5899\u540e\u9762\u6216\u4f4d\u4e8e\u5b89\u5168\u7b56\u7565\u7981\u6b62\u6253\u5f00\u7aef\u53e3\u7684\u67d0\u4e9b\u73af\u5883\u4e2d\u5b83\u53ef\u80fd\u5f88\u6709\u7528\u3002<\/p>\n Prometheus \u662f\u4e91\u539f\u751f\u8ba1\u7b97\u57fa\u91d1\u4f1a\uff08CNCF\uff09\u7684\u4e00\u4e2a\u9879\u76ee\u3002\u5b83\u4f7f\u7528\u8054\u5408\u6a21\u578bfederation model\u8fdb\u884c\u6269\u5c55\uff0c\u8be5\u6a21\u578b\u4f7f\u5f97\u4e00\u4e2a Prometheus \u670d\u52a1\u5668\u80fd\u591f\u6293\u53d6\u53e6\u4e00\u4e2a Prometheus \u670d\u52a1\u5668\u7684\u6570\u636e\u3002\u8fd9\u5141\u8bb8\u521b\u5efa\u5206\u5c42\u62d3\u6251\uff0c\u5176\u4e2d\u4e2d\u592e\u7cfb\u7edf\u6216\u66f4\u9ad8\u7ea7\u522b\u7684 Prometheus \u670d\u52a1\u5668\u53ef\u4ee5\u6293\u53d6\u5df2\u4ece\u4e0b\u7ea7\u5b9e\u4f8b\u6536\u96c6\u7684\u805a\u5408\u6570\u636e\u3002<\/p>\n \u9664 Prometheus \u670d\u52a1\u5668\u5916\uff0c\u5176\u6700\u5e38\u89c1\u7684\u7ec4\u4ef6\u662f\u8b66\u62a5\u7ba1\u7406\u5668\u53ca\u5176\u8f93\u51fa\u5668\u3002<\/p>\n \u8b66\u62a5\u89c4\u5219\u53ef\u4ee5\u5728 Prometheus \u4e2d\u521b\u5efa\uff0c\u5e76\u914d\u7f6e\u4e3a\u5411\u8b66\u62a5\u7ba1\u7406\u5668\u53d1\u9001\u81ea\u5b9a\u4e49\u8b66\u62a5\u3002\u7136\u540e\uff0c\u8b66\u62a5\u7ba1\u7406\u5668\u5904\u7406\u548c\u7ba1\u7406\u8fd9\u4e9b\u8b66\u62a5\uff0c\u5305\u62ec\u901a\u8fc7\u7535\u5b50\u90ae\u4ef6\u6216\u7b2c\u4e09\u65b9\u670d\u52a1\uff08\u5982 PagerDuty\uff09\u7b49\u4e0d\u540c\u673a\u5236\u53d1\u9001\u901a\u77e5\u3002<\/p>\n Prometheus \u7684\u8f93\u51fa\u5668\u53ef\u4ee5\u662f\u5e93\u3001\u8fdb\u7a0b\u3001\u8bbe\u5907\u6216\u4efb\u4f55\u5176\u4ed6\u80fd\u5c06 Prometheus \u6293\u53d6\u7684\u6307\u6807\u516c\u5f00\u51fa\u53bb\u7684\u4e1c\u897f\u3002 \u8fd9\u4e9b\u6307\u6807\u53ef\u5728\u7aef\u70b9 \/metrics \u4e2d\u83b7\u5f97\uff0c\u5b83\u5141\u8bb8 Prometheus \u65e0\u9700\u4ee3\u7406\u76f4\u63a5\u6293\u53d6\u5b83\u4eec\u3002\u672c\u6587\u4e2d\u7684\u6559\u7a0b\u4f7f\u7528 node_exporter \u6765\u516c\u5f00\u76ee\u6807\u4e3b\u673a\u7684\u786c\u4ef6\u548c\u64cd\u4f5c\u7cfb\u7edf\u6307\u6807\u3002\u8f93\u51fa\u5668\u7684\u8f93\u51fa\u662f\u660e\u6587\u7684\u3001\u9ad8\u5ea6\u53ef\u8bfb\u7684\uff0c\u8fd9\u662f Prometheus \u7684\u4f18\u52bf\u4e4b\u4e00\u3002<\/p>\n \u6b64\u5916\uff0c\u4f60\u53ef\u4ee5\u5c06 Prometheus \u4f5c\u4e3a\u540e\u7aef\uff0c\u914d\u7f6e Grafana \u6765\u63d0\u4f9b\u6570\u636e\u53ef\u89c6\u5316\u548c\u4eea\u8868\u677f\u529f\u80fd\u3002<\/p>\n \u7406\u89e3 Prometheus \u7684\u914d\u7f6e\u6587\u4ef6<\/strong><\/div>\n \u6293\u53d6 \/metrics \u7684\u95f4\u9694\u79d2\u6570\u63a7\u5236\u4e86\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u5e93\u7684\u7c92\u5ea6\u3002\u8fd9\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u5b9a\u4e49\u4e3a scrape_interval \u53c2\u6570\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u8bbe\u7f6e\u4e3a 60 \u79d2\u3002<\/p>\n \u5728 scrape_configs \u90e8\u5206\u4e2d\u4e3a\u6bcf\u4e2a\u6293\u53d6\u4f5c\u4e1a\u8bbe\u7f6e\u4e86\u76ee\u6807\u3002\u6bcf\u4e2a\u4f5c\u4e1a\u90fd\u6709\u81ea\u5df1\u7684\u540d\u79f0\u548c\u4e00\u7ec4\u6807\u7b7e\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u8fc7\u6ee4\u3001\u5206\u7c7b\u5e76\u66f4\u8f7b\u677e\u5730\u8bc6\u522b\u76ee\u6807\u3002\u4e00\u9879\u4f5c\u4e1a\u53ef\u4ee5\u6709\u5f88\u591a\u76ee\u6807\u3002<\/p>\n \u5b89\u88c5 Prometheus<\/strong><\/div>\n \u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u4e3a\u7b80\u5355\u8d77\u89c1\uff0c\u6211\u4eec\u5c06\u4f7f\u7528 Docker \u5b89\u88c5 Prometheus \u670d\u52a1\u5668\u548c node_exporter\u3002Docker \u5e94\u8be5\u5df2\u7ecf\u5728\u4f60\u7684\u7cfb\u7edf\u4e0a\u6b63\u786e\u5b89\u88c5\u548c\u914d\u7f6e\u3002\u5bf9\u4e8e\u66f4\u6df1\u5165\u3001\u81ea\u52a8\u5316\u7684\u65b9\u6cd5\uff0c\u6211\u63a8\u8350 Steve Ovens \u7684\u6587\u7ae0\u300a\u5982\u4f55\u4f7f\u7528 Ansible \u4e0e Prometheus \u5efa\u7acb\u7cfb\u7edf\u76d1\u63a7\u300b\u3002<\/p>\n \u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u5728\u5de5\u4f5c\u76ee\u5f55\u4e2d\u521b\u5efa Prometheus \u914d\u7f6e\u6587\u4ef6 prometheus.yml\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n \r\nglobal:\r\n scrape_interval: 15s\r\n evaluation_interval: 15s\r\nscrape_configs:\r\n - job_name: 'prometheus'\r\n static_configs:\r\n - targets: ['localhost:9090']\r\n - job_name: 'webservers'\r\n static_configs:\r\n - targets: [' |