{"id":1866,"date":"2020-07-01T06:53:04","date_gmt":"2020-06-30T22:53:04","guid":{"rendered":"http:\/\/39.97.231.10\/?p=1866"},"modified":"2020-07-01T06:53:04","modified_gmt":"2020-06-30T22:53:04","slug":"prometheus-api%e8%af%b4%e6%98%8e","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=1866","title":{"rendered":"Prometheus API\u8bf4\u660e"},"content":{"rendered":"<div>HTTP API<\/div>\n<div>\n<div id=\\\"cnblogs_post_body\\\">\n<div>\n<div id=\\\"cnblogs_post_body\\\">\n\u5728Prometheus\u670d\u52a1\u5668\u4e0a\u7684\/api\/v1\u4e0b\u53ef\u4ee5\u8bbf\u95ee\u5f53\u524d\u7a33\u5b9a\u7684HTTP API\u3002 \u5c06\u5728\u8be5\u7aef\u70b9\u4e0b\u6dfb\u52a0\u4efb\u4f55\u975e\u4e2d\u65ad\u6dfb\u52a0\u9879\u3002<\/p>\n<div>\n<h3>\u4e00\u3001\u683c\u5f0f\u6982\u8ff0<\/h3>\n<p>API\u8fd4\u56de\u662fJSON\u683c\u5f0f\uff0c\u6bcf\u4e2a\u8bf7\u6c42\u6210\u529f\u7684\u8fd4\u56de\u503c\u90fd\u662f\u4ee52xx\u5f00\u5934\u7684\u7f16\u7801\u3002\u5982\u679cAPI\u5904\u7406\u7684\u662f\u65e0\u6548\u8bf7\u6c42\uff0c\u8fd4\u56de\u4e00\u4e2aJSON\u9519\u8bef\u5bf9\u8c61\uff0c\u5e76\u8fd4\u56de\u4e0b\u9762\u7684\u9519\u8bef\u7801\uff1a<\/p>\n<ul>\n<li>400 Bad Request\u3002\u5f53\u53c2\u6570\u9519\u8bef\u6216\u8005\u4e22\u5931\u65f6\u3002<\/li>\n<li>422 Unprocessable Entity\u3002\u5f53\u4e00\u4e2a\u8868\u8fbe\u5f0f\u4e0d\u80fd\u88ab\u6267\u884c\u65f6\u3002<\/li>\n<li>503 Service Unavailable\u3002\u5f53\u67e5\u8be2\u8d85\u65f6\u6216\u8005\u4e2d\u65ad\u65f6\u3002<\/li>\n<\/ul>\n<p>\u5bf9\u4e8e\u5728API\u7aef\u70b9\u4e4b\u524d\u53d1\u751f\u7684\u9519\u8bef\uff0c\u53ef\u4ee5\u8fd4\u56de\u5176\u4ed6\u975e2xx\u4ee3\u7801\u3002\u5982\u679c\u5b58\u5728\u8bf7\u6c42\u6267\u884c\u7684\u9519\u8bef\uff0c\u5219\u53ef\u80fd\u4f1a\u8fd4\u56de\u4e00\u7cfb\u5217\u8b66\u544a\uff0c\u5e76\u6536\u96c6\u6240\u6709\u7684\u6570\u636e\u5c06\u5728\u6570\u636e\u5b57\u6bb5\u4e2d\u8fd4\u56de\u3002<br \/>\nJSON\u54cd\u5e94\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<div>\n<pre>{\n  \\\"status\\\": \\\"success\\\" | \\\"error\\\",\n  \\\"data\\\": &lt;data&gt;,\n  \/\/ Only set if status is \\\"error\\\". The data field may still hold\n  \/\/ additional data.\n  \\\"errorType\\\": \\\"&lt;string&gt;\\\",\n  \\\"error\\\": \\\"&lt;string&gt;\\\",\n  \/\/ Only if there were warnings while executing the request.\n  \/\/ There will still be data in the data field.\n  \\\"warnings\\\": [\\\"&lt;string&gt;\\\"]\n}<\/pre>\n<div><\/div>\n<\/div>\n<div>\n<div>\n\u8f93\u5165\u65f6\u95f4\u6233\u53ef\u4ee5\u4ee5RFC3339\u683c\u5f0f\u63d0\u4f9b\uff0c\u4e5f\u53ef\u4ee5\u4ee5\u79d2\u4e3a\u5355\u4f4d\u63d0\u4f9b\u7ed9Unix\u65f6\u95f4\u6233\uff0c\u53ef\u9009\u7684\u5c0f\u6570\u4f4d\u6570\u7528\u4e8e\u4e9a\u79d2\u7ea7\u7cbe\u5ea6\u3002 \u8f93\u51fa\u65f6\u95f4\u6233\u59cb\u7ec8\u8868\u793a\u4e3aUnix\u65f6\u95f4\u6233\uff0c\u4ee5\u79d2\u4e3a\u5355\u4f4d\u3002<br \/>\n\u53ef\u4ee5\u4ee5[]\u7ed3\u5c3e\u7684\u67e5\u8be2\u53c2\u6570\u7684\u540d\u79f0\u3002<\/p>\n<ul>\n<li>&lt;series_selector&gt;\u5360\u4f4d\u7b26\uff1a\u6307\u7684\u662fPrometheus\u65f6\u95f4\u5e8f\u5217\u9009\u62e9\u5668\uff0c\u5982http_requests_total\u6216http_requests_total{method =\u301c\\&#8221;(GET|POST)\\&#8221;}\uff0c\u9700\u8981\u8fdb\u884cURL\u7f16\u7801\u3002<\/li>\n<li>&lt;duration&gt;\u5360\u4f4d\u7b26\uff1a\u6307\u7684\u662f[0-9]+[smhdwy]\u5f62\u5f0f\u7684Prometheus\u6301\u7eed\u65f6\u95f4\u5b57\u7b26\u4e32\u3002 \u4f8b\u5982\uff0c5m\u6307\u7684\u662f5\u5206\u949f\u7684\u6301\u7eed\u65f6\u95f4\u3002<\/li>\n<li>&lt;bool&gt;\u5360\u4f4d\u7b26\uff1a\u6307\u7684\u662f\u5f15\u7528\u5e03\u5c14\u503c\uff08\u5b57\u7b26\u4e32true\u548cfalse\uff09\u3002<\/li>\n<\/ul>\n<h3>\u4e8c\u3001\u8868\u8fbe\u5f0f\u67e5\u8be2<\/h3>\n<\/div>\n<p>\u53ef\u4ee5\u5728\u5355\u4e2a\u65f6\u523b\u6216\u5728\u4e00\u6bb5\u65f6\u95f4\u5185\u8bc4\u4f30\u67e5\u8be2\u8bed\u8a00\u8868\u8fbe\u3002 \u4ee5\u4e0b\u90e8\u5206\u63cf\u8ff0\u4e86\u6bcf\u79cd\u8868\u8fbe\u5f0f\u67e5\u8be2\u7684API\u7aef\u70b9\u3002<\/p>\n<h3>2.1 Instant queries(\u5373\u65f6\u67e5\u8be2)<\/h3>\n<p>\u4ee5\u4e0b\u7aef\u70b9\u5728\u5355\u4e2a\u65f6\u95f4\u70b9\u8bc4\u4f30\u5373\u65f6\u67e5\u8be2\uff1a<\/p>\n<div>\n<pre>GET \/api\/v1\/query<\/pre>\n<\/div>\n<div>\nURL\u67e5\u8be2\u53c2\u6570\uff1a<\/p>\n<ul>\n<li>query=&lt;string&gt;: Prometheus\u8868\u8fbe\u5f0f\u67e5\u8be2\u5b57\u7b26\u4e32\u3002<\/li>\n<li>time=&lt;rfc3339 | uninx_timestamp&gt;: \u6267\u884c\u65f6\u95f4\u6233\uff0c\u53ef\u9009\u9879\u3002<\/li>\n<li>timeout=&lt;duration&gt;: \u6267\u884c\u8d85\u65f6\u65f6\u95f4\u8bbe\u7f6e\uff0c\u53ef\u9009\u9879\uff0c\u9ed8\u8ba4\u7531-query.timeout\u6807\u5fd7\u8bbe\u7f6e<\/li>\n<\/ul>\n<p>\u5982\u679ctime\u7f3a\u7701\uff0c\u5219\u7528\u5f53\u524d\u670d\u52a1\u5668\u65f6\u95f4\u8868\u793a\u6267\u884c\u65f6\u523b\u3002\u8fd9\u4e2a\u67e5\u8be2\u7ed3\u679c\u7684data\u90e8\u5206\u6709\u4e0b\u9762\u683c\u5f0f\uff1a<\/p>\n<div>\n<pre>{\n \\\"resultType\\\": \\\"matrix\\\" | \\\"vector\\\" | \\\"scalar\\\" | \\\"string\\\",\n \\\"result\\\": &lt;value&gt;\n}<\/pre>\n<\/div>\n<p>&lt;value&gt;\u662f\u4e00\u4e2a\u67e5\u8be2\u7ed3\u679c\u6570\u636e\uff0c\u4f9d\u8d56\u4e8e\u8fd9\u4e2aresultType\u683c\u5f0f,\u89c1<a href=\\\"https:\/\/prometheus.io\/docs\/prometheus\/latest\/querying\/api\/#expression-query-result-formats\\\" target=\\\"_blank\\\" rel=\\\"noopener noreferrer\\\">\u8868\u8fbe\u5f0f\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f<\/a>\u3002<br \/>\n\u4e0b\u9762\u4f8b\u5b50\u6267\u884c\u4e86\u5728\u65f6\u523b\u662f2015-07-01T20:10:51.781Z\u7684up\u8868\u8fbe\u5f0f\uff1a<\/p>\n<div>\n<pre>$ curl \\'http:\/\/localhost:9090\/api\/v1\/query?query=up&amp;time=2015-07-01T20:10:51.781Z\\'\n{\n \\\"status\\\": \\\"success\\\",\n \\\"data\\\":{\n    \\\"resultType\\\": \\\"vector\\\",\n    \\\"result\\\" : [\n         {\n            \\\"metric\\\" : {\n               \\\"__name__\\\" : \\\"up\\\",\n               \\\"job\\\" : \\\"prometheus\\\",\n               \\\"instance\\\" : \\\"localhost:9090\\\"\n            },\n            \\\"value\\\": [ 1435781451.781, \\\"1\\\" ]\n         },\n         {\n            \\\"metric\\\" : {\n               \\\"__name__\\\" : \\\"up\\\",\n               \\\"job\\\" : \\\"node\\\",\n               \\\"instance\\\" : \\\"localhost:9100\\\"\n            },\n            \\\"value\\\" : [ 1435781451.781, \\\"0\\\" ]\n         }\n    ]\n }\n}<\/pre>\n<div><\/div>\n<\/div>\n<h3>2.2 \u8303\u56f4\u67e5\u8be2<\/h3>\n<p>\u4ee5\u4e0b\u7aef\u70b9\u5728\u4e00\u6bb5\u65f6\u95f4\u5185\u8bc4\u4f30\u8868\u8fbe\u5f0f\u67e5\u8be2\uff1a<\/p>\n<div>\n<pre>GET \/api\/v1\/query_range<\/pre>\n<\/div>\n<div>\nURL\u67e5\u8be2\u53c2\u6570<\/p>\n<ul>\n<li>query=&lt;string&gt;: Prometheus\u8868\u8fbe\u5f0f\u67e5\u8be2\u5b57\u7b26\u4e32\u3002<\/li>\n<li>start=&lt;rfc3339 | unix_timestamp&gt;: \u5f00\u59cb\u65f6\u95f4\u6233\u3002<\/li>\n<li>end=&lt;rfc3339 | unix_timestamp&gt;: \u7ed3\u675f\u65f6\u95f4\u6233\u3002<\/li>\n<li>step=&lt;duration&gt;: \u4ee5\u6301\u7eed\u65f6\u95f4\u683c\u5f0f\u67e5\u8be2\u5206\u8fa8\u7387\u6b65\u957f\u6216\u6d6e\u70b9\u79d2\u6570\u3002<\/li>\n<li>timeout=&lt;duration&gt;:\u8bc4\u4f30\u8d85\u65f6\u3002 \u53ef\u9009\u7684\u3002 \u9ed8\u8ba4\u4e3a-query.timeout\u6807\u5fd7\u7684\u503c\u5e76\u53d7\u5176\u9650\u5236\u3002<\/li>\n<\/ul>\n<p>\u67e5\u8be2\u7ed3\u679c\u7684\u6570\u636e\u90e8\u5206\u5177\u6709\u4ee5\u4e0b\u683c\u5f0f\uff1a<\/p>\n<div>\n<pre>{\n    \\\"resultType\\\": \\\"matrix\\\",\n    \\\"result\\\": &lt;value&gt;\n}<\/pre>\n<\/div>\n<p>\u5bf9\u4e8e&lt;value&gt;\u5360\u4f4d\u7b26\u7684\u683c\u5f0f\uff0c\u8be6\u89c1<a href=\\\"https:\/\/prometheus.io\/docs\/prometheus\/latest\/querying\/api\/#range-vectors\\\" target=\\\"_blank\\\" rel=\\\"noopener noreferrer\\\">\u8303\u56f4\u5411\u91cf\u7ed3\u679c\u683c\u5f0f<\/a>\u3002\u4ee5\u4e0b\u793a\u4f8b\u572830\u79d2\u8303\u56f4\u5185\u8bc4\u4f30\u8868\u8fbe\u5f0f\uff0c\u67e5\u8be2\u5206\u8fa8\u7387\u4e3a15\u79d2\u3002<\/p>\n<div>\n<pre>$ curl \\'http:\/\/localhost:9090\/api\/v1\/query_range?query=up&amp;start=2015-07-01T20:10:30.781Z&amp;end=2015-07-01T20:11:00.781Z&amp;step=15s\\'\n{\n   \\\"status\\\" : \\\"success\\\",\n   \\\"data\\\" : {\n      \\\"resultType\\\" : \\\"matrix\\\",\n      \\\"result\\\" : [\n         {\n            \\\"metric\\\" : {\n               \\\"__name__\\\" : \\\"up\\\",\n               \\\"job\\\" : \\\"prometheus\\\",\n               \\\"instance\\\" : \\\"localhost:9090\\\"\n            },\n            \\\"values\\\" : [\n               [ 1435781430.781, \\\"1\\\" ],\n               [ 1435781445.781, \\\"1\\\" ],\n               [ 1435781460.781, \\\"1\\\" ]\n            ]\n         },\n         {\n            \\\"metric\\\" : {\n               \\\"__name__\\\" : \\\"up\\\",\n               \\\"job\\\" : \\\"node\\\",\n               \\\"instance\\\" : \\\"localhost:9091\\\"\n            },\n            \\\"values\\\" : [\n           [ 1435781430.781, \\\"0\\\" ],\n               [ 1435781445.781, \\\"0\\\" ],\n               [ 1435781460.781, \\\"1\\\" ]\n            ]\n         }\n      ]\n   }\n}<\/pre>\n<div><\/div>\n<\/div>\n<h3>\u4e09\u3001\u67e5\u8be2\u5143\u6570\u636e<\/h3>\n<h3>3.1 \u901a\u8fc7\u6807\u7b7e\u5339\u914d\u5668\u627e\u5230\u5ea6\u91cf\u6307\u6807\u5217\u8868<\/h3>\n<p>\u4ee5\u4e0b\u7aef\u70b9\u8fd4\u56de\u4e0e\u7279\u5b9a\u6807\u7b7e\u96c6\u5339\u914d\u7684\u65f6\u95f4\u7cfb\u5217\u5217\u8868\uff1a<\/p>\n<div>\n<pre>GET \/api\/v1\/series\nPOST \/api\/v1\/series<\/pre>\n<\/div>\n<div>\n<div>\nURL\u67e5\u8be2\u53c2\u6570\uff1a<\/p>\n<ul>\n<li>match[]=&lt;series_selector&gt;: \u9009\u62e9\u5668\u662fseries_selector\uff0c\u8fd9\u4e2a\u53c2\u6570\u4e2a\u6570\u5fc5\u987b\u5927\u4e8e\u7b49\u4e8e1.<\/li>\n<li>start=&lt;rfc3339 | unix_timestamp&gt;: \u5f00\u59cb\u65f6\u95f4\u6233\u3002<\/li>\n<li>end=&lt;rfc3339 | unix_timestamp&gt;: \u7ed3\u675f\u65f6\u95f4\u6233\u3002<\/li>\n<\/ul>\n<p>\u67e5\u8be2\u7ed3\u679c\u7684data\u90e8\u5206\u5305\u542b\u4e00\u4e2a\u5bf9\u8c61\u5217\u8868\uff0c\u8fd9\u4e9b\u5bf9\u8c61\u5305\u542b\u6807\u8bc6\u6bcf\u4e2a\u7cfb\u5217\u7684\u6807\u7b7e\u540d\u79f0\/\u503c\u5bf9\u3002<br \/>\n\u4e0b\u9762\u4f8b\u5b50\u8fd4\u56de\u65f6\u95f4\u5e8f\u5217\u6570\u636e, \u9009\u62e9\u5668\u662fup\u6216\u8005process_start_time_seconds{job=\\&#8221;prometheus\\&#8221;}\uff1a<\/p>\n<div>\n<div><\/div>\n<pre>$ curl -g \\'http:\/\/localhost:9090\/api\/v1\/series?match[]=up&amp;match[]=process_start_time_seconds{job=\\\"prometheus\\\"}\\'\n{\n   \\\"status\\\" : \\\"success\\\",\n   \\\"data\\\" : [\n      {\n         \\\"__name__\\\" : \\\"up\\\",\n         \\\"job\\\" : \\\"prometheus\\\",\n         \\\"instance\\\" : \\\"localhost:9090\\\"\n      },\n      {\n         \\\"__name__\\\" : \\\"up\\\",\n         \\\"job\\\" : \\\"node\\\",\n         \\\"instance\\\" : \\\"localhost:9091\\\"\n      },\n      {\n         \\\"__name__\\\" : \\\"process_start_time_seconds\\\",\n         \\\"job\\\" : \\\"prometheus\\\",\n         \\\"instance\\\" : \\\"localhost:9090\\\"\n      }\n   ]\n}<\/pre>\n<div><\/div>\n<\/div>\n<h3>3.2 \u67e5\u8be2\u6807\u7b7e\u540d<\/h3>\n<p>\u4ee5\u4e0b\u7aef\u70b9\u8fd4\u56de\u6807\u7b7e\u540d\u79f0\u7684\u5217\u8868\uff1a<\/p>\n<div>\n<pre>GET \/api\/v1\/labels\nPOST \/api\/v1\/labels<\/pre>\n<\/div>\n<p>JSON\u54cd\u5e94\u7684data\u90e8\u5206\u662f\u5b57\u7b26\u4e32\u6807\u7b7e\u540d\u79f0\u7684\u5217\u8868\uff1a<\/p>\n<div>\n<pre>$ curl \\'localhost:9090\/api\/v1\/labels\\'\n{\n    \\\"status\\\": \\\"success\\\",\n    \\\"data\\\": [\n        \\\"__name__\\\",\n        \\\"call\\\",\n        \\\"code\\\",\n        \\\"config\\\",\n        \\\"dialer_name\\\",\n        \\\"endpoint\\\",\n        \\\"event\\\",\n        \\\"goversion\\\",\n        \\\"handler\\\",\n        \\\"instance\\\",\n        \\\"interval\\\",\n        \\\"job\\\",\n        \\\"le\\\",\n        \\\"listener_name\\\",\n        \\\"name\\\",\n        \\\"quantile\\\",\n        \\\"reason\\\",\n        \\\"role\\\",\n        \\\"scrape_job\\\",\n        \\\"slice\\\",\n        \\\"version\\\"\n    ]\n}<\/pre>\n<div><\/div>\n<\/div>\n<h3>3.3 \u67e5\u8be2\u6807\u7b7e\u503c<\/h3>\n<p>\u4ee5\u4e0b\u7aef\u70b9\u8fd4\u56de\u63d0\u4f9b\u7684\u6807\u7b7e\u540d\u79f0\u7684\u6807\u7b7e\u503c\u5217\u8868\uff1a\n<\/p><\/div>\n<div>\n<pre>GET \/api\/v1\/label\/&lt;label_name&gt;\/values<\/pre>\n<\/div>\n<p>JSON\u54cd\u5e94\u7684data\u90e8\u5206\u662f\u5b57\u7b26\u4e32\u6807\u7b7e\u503c\u7684\u5217\u8868\u3002\u6b64\u793a\u4f8b\u67e5\u8be2\u4f5c\u4e1a\u6807\u7b7e\u7684\u6240\u6709\u6807\u7b7e\u503c\uff1a<\/p>\n<div>\n<div><\/div>\n<pre>$ curl http:\/\/localhost:9090\/api\/v1\/label\/job\/values\n{\n   \\\"status\\\" : \\\"success\\\",\n   \\\"data\\\" : [\n      \\\"node\\\",\n      \\\"prometheus\\\"\n   ]\n}<\/pre>\n<div><\/div>\n<\/div>\n<div>\n<h3>\u56db\u3001\u8868\u8fbe\u5f0f\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f<\/h3>\n<p>\u8868\u8fbe\u5f0f\u67e5\u8be2\u53ef\u80fd\u4f1a\u5728data\u90e8\u5206\u7684result\u5c5e\u6027\u4e2d\u8fd4\u56de\u4ee5\u4e0b\u54cd\u5e94\u503c\u3002\u00a0&lt;sample_value&gt;\u5360\u4f4d\u7b26\u662f\u6570\u5b57\u6837\u672c\u503c\u3002 JSON\u4e0d\u652f\u6301\u7279\u6b8a\u7684\u6d6e\u70b9\u503c\uff0c\u4f8b\u5982NaN\uff0cInf\u548c-Inf\uff0c\u56e0\u6b64\u6837\u672c\u503c\u5c06\u4f5c\u4e3a\u5e26\u5f15\u53f7\u7684JSON\u5b57\u7b26\u4e32\u800c\u4e0d\u662f\u539f\u59cb\u6570\u5b57\u4f20\u8f93\u3002<\/p>\n<h3>4.1 \u8303\u56f4\u5411\u91cf<\/h3>\n<p>\u8303\u56f4\u5411\u91cf\u8fd4\u56de\u7684result\u7c7b\u578b\u662f\u4e00\u4e2amatrix\u77e9\u9635\u3002\u4e0b\u9762\u8fd4\u56de\u7684\u7ed3\u679c\u662fresult\u90e8\u5206\u7684\u6570\u636e\u683c\u5f0f\uff1a<\/p>\n<div>\n<div><\/div>\n<pre>[\n  {\n    \\\"metric\\\": { \\\"&lt;label_name&gt;\\\": \\\"&lt;label_value&gt;\\\", ... },\n    \\\"values\\\": [ [ &lt;unix_time&gt;, \\\"&lt;sample_value&gt;\\\" ], ... ]\n  },\n  ...\n]<\/pre>\n<div><\/div>\n<\/div>\n<h3>4.2 \u77ac\u65f6\u5411\u91cf<\/h3>\n<p>\u77ac\u65f6\u5411\u91cf\u7684result\u7c7b\u578b\u662fvector\u3002\u4e0b\u9762\u662fresult\u90e8\u5206\u7684\u6570\u636e\u683c\u5f0f\uff1a<\/p>\n<div>\n<pre>[\n  {\n    \\\"metric\\\": { \\\"&lt;label_name&gt;\\\": \\\"&lt;label_value&gt;\\\", ... },\n    \\\"value\\\": [ &lt;unix_time&gt;, \\\"&lt;sample_value&gt;\\\" ]\n  },\n  ...\n]<\/pre>\n<\/div>\n<h3>4.3 Scalars\u6807\u91cf<\/h3>\n<p>\u6807\u91cf\u67e5\u8be2\u8fd4\u56deresult\u7c7b\u578b\u662fscalar\u3002\u4e0b\u9762\u662fresult\u90e8\u5206\u7684\u6570\u636e\u683c\u5f0f\uff1a<\/p>\n<div>\n<pre>[ &lt;unix_time&gt;, \\\"&lt;scalar_value&gt;\\\" ]<\/pre>\n<\/div>\n<h3>4.4 \u5b57\u7b26\u4e32<\/h3>\n<p>\u5b57\u7b26\u4e32\u7684result\u7c7b\u578b\u662fstring\u3002\u4e0b\u9762\u662fresult\u90e8\u5206\u7684\u6570\u636e\u683c\u5f0f\uff1a<\/p>\n<div>\n<pre>[ &lt;unix_time&gt;, \\\"&lt;string_value&gt;\\\" ]<\/pre>\n<\/div>\n<h3>\u4e94\u3001Targets\u76ee\u6807<\/h3>\n<p>\u4ee5\u4e0b\u7aef\u70b9\u8fd4\u56dePrometheus\u76ee\u6807\u53d1\u73b0\u7684\u5f53\u524d\u72b6\u6001\u6982\u8ff0\uff1a<\/p>\n<div>\n<pre>GET \/api\/v1\/targets<\/pre>\n<\/div>\n<p>\u6d3b\u52a8\u76ee\u6807\u548c\u5220\u9664\u76ee\u6807\u90fd\u662f\u54cd\u5e94\u7684\u4e00\u90e8\u5206\u3002\u00a0labels\u8868\u793a\u91cd\u65b0\u6807\u8bb0\u53d1\u751f\u540e\u7684\u6807\u7b7e\u96c6\uff0cdiscoveredLabels\u8868\u793a\u5728\u53d1\u751f\u91cd\u65b0\u6807\u8bb0\u4e4b\u524d\u5728\u670d\u52a1\u53d1\u73b0\u671f\u95f4\u68c0\u7d22\u5230\u7684\u672a\u4fee\u6539\u6807\u7b7e\u3002<\/p>\n<div>\n<pre>$ curl http:\/\/localhost:9090\/api\/v1\/targets\n{\n  \\\"status\\\": \\\"success\\\",\n  \\\"data\\\": {\n    \\\"activeTargets\\\": [\n      {\n        \\\"discoveredLabels\\\": {\n          \\\"__address__\\\": \\\"127.0.0.1:9090\\\",\n          \\\"__metrics_path__\\\": \\\"\/metrics\\\",\n          \\\"__scheme__\\\": \\\"http\\\",\n          \\\"job\\\": \\\"prometheus\\\"\n        },\n        \\\"labels\\\": {\n          \\\"instance\\\": \\\"127.0.0.1:9090\\\",\n          \\\"job\\\": \\\"prometheus\\\"\n        },\n        \\\"scrapeUrl\\\": \\\"http:\/\/127.0.0.1:9090\/metrics\\\",\n        \\\"lastError\\\": \\\"\\\",\n        \\\"lastScrape\\\": \\\"2017-01-17T15:07:44.723715405+01:00\\\",\n        \\\"health\\\": \\\"up\\\"\n      }\n    ],\n    \\\"droppedTargets\\\": [\n      {\n        \\\"discoveredLabels\\\": {\n          \\\"__address__\\\": \\\"127.0.0.1:9100\\\",\n          \\\"__metrics_path__\\\": \\\"\/metrics\\\",\n          \\\"__scheme__\\\": \\\"http\\\",\n          \\\"job\\\": \\\"node\\\"\n        },\n      }\n    ]\n  }\n}<\/pre>\n<\/div>\n<div>\n<h3>\u516d\u3001Rules\u89c4\u5219<\/h3>\n<p>\/rules\u00a0API\u7aef\u70b9\u8fd4\u56de\u5f53\u524d\u52a0\u8f7d\u7684\u8b66\u62a5\u548c\u8bb0\u5f55\u89c4\u5219\u5217\u8868\u3002 \u6b64\u5916\uff0c\u5b83\u8fd8\u8fd4\u56de\u7531\u6bcf\u4e2a\u8b66\u62a5\u89c4\u5219\u7684Prometheus\u5b9e\u4f8b\u89e6\u53d1\u7684\u5f53\u524d\u6d3b\u52a8\u8b66\u62a5\u3002\u7531\u4e8e\/rules\u7aef\u70b9\u76f8\u5f53\u65b0\uff0c\u5b83\u6ca1\u6709\u4e0e\u603b\u4f53API v1\u76f8\u540c\u7684\u7a33\u5b9a\u6027\u4fdd\u8bc1\u3002<\/p>\n<div>\n<pre>GET \/api\/v1\/rules<\/pre>\n<\/div>\n<div>\n<div><\/div>\n<pre>$ curl http:\/\/localhost:9090\/api\/v1\/rules\n{\n    \\\"data\\\": {\n        \\\"groups\\\": [\n            {\n                \\\"rules\\\": [\n                    {\n                        \\\"alerts\\\": [\n                            {\n                                \\\"activeAt\\\": \\\"2018-07-04T20:27:12.60602144+02:00\\\",\n                                \\\"annotations\\\": {\n                                    \\\"summary\\\": \\\"High request latency\\\"\n                                },\n                                \\\"labels\\\": {\n                                    \\\"alertname\\\": \\\"HighRequestLatency\\\",\n                                    \\\"severity\\\": \\\"page\\\"\n                                },\n                                \\\"state\\\": \\\"firing\\\",\n                                \\\"value\\\": 1\n                            }\n                        ],\n                        \\\"annotations\\\": {\n                            \\\"summary\\\": \\\"High request latency\\\"\n                        },\n                        \\\"duration\\\": 600,\n                        \\\"health\\\": \\\"ok\\\",\n                        \\\"labels\\\": {\n                            \\\"severity\\\": \\\"page\\\"\n                        },\n                        \\\"name\\\": \\\"HighRequestLatency\\\",\n                        \\\"query\\\": \\\"job:request_latency_seconds:mean5m{job=\\\\\\\"myjob\\\\\\\"} &gt; 0.5\\\",\n                        \\\"type\\\": \\\"alerting\\\"\n                    },\n                    {\n                        \\\"health\\\": \\\"ok\\\",\n                        \\\"name\\\": \\\"job:http_inprogress_requests:sum\\\",\n                        \\\"query\\\": \\\"sum(http_inprogress_requests) by (job)\\\",\n                        \\\"type\\\": \\\"recording\\\"\n                    }\n                ],\n                \\\"file\\\": \\\"\/rules.yaml\\\",\n                \\\"interval\\\": 60,\n                \\\"name\\\": \\\"example\\\"\n            }\n        ]\n    },\n    \\\"status\\\": \\\"success\\\"\n}<\/pre>\n<div><\/div>\n<\/div>\n<h3>\u4e03\u3001Alerts\u62a5\u8b66<\/h3>\n<p>\/alerts\u7aef\u70b9\u8fd4\u56de\u6240\u6709\u6d3b\u52a8\u8b66\u62a5\u7684\u5217\u8868\u3002\u7531\u4e8e\/alerts\u7aef\u70b9\u76f8\u5f53\u65b0\uff0c\u5b83\u6ca1\u6709\u4e0e\u603b\u4f53API v1\u76f8\u540c\u7684\u7a33\u5b9a\u6027\u4fdd\u8bc1\u3002\n<\/p><\/div>\n<\/div>\n<div>\n<pre>GET \/api\/v1\/alerts<\/pre>\n<\/div>\n<div>\n<div><\/div>\n<pre>$ curl http:\/\/localhost:9090\/api\/v1\/alerts\n{\n    \\\"data\\\": {\n        \\\"alerts\\\": [\n            {\n                \\\"activeAt\\\": \\\"2018-07-04T20:27:12.60602144+02:00\\\",\n                \\\"annotations\\\": {},\n                \\\"labels\\\": {\n                    \\\"alertname\\\": \\\"my-alert\\\"\n                },\n                \\\"state\\\": \\\"firing\\\",\n                \\\"value\\\": 1\n            }\n        ]\n    },\n    \\\"status\\\": \\\"success\\\"\n}<\/pre>\n<div><\/div>\n<\/div>\n<h3>\u516b\u3001\u67e5\u8be2\u76ee\u6807\u5143\u6570\u636e<\/h3>\n<p>\u4ee5\u4e0b\u7aef\u70b9\u8fd4\u56de\u6709\u5173\u76ee\u6807\u6b63\u5728\u522e\u53d6\u7684\u5ea6\u91cf\u6807\u51c6\u7684\u5143\u6570\u636e\u3002 \u8fd9\u662f\u5b9e\u9a8c\u6027\u7684\uff0c\u5c06\u6765\u53ef\u80fd\u4f1a\u53d1\u751f\u53d8\u5316\u3002<\/p>\n<div>\n<pre>GET \/api\/v1\/targets\/metadata<\/pre>\n<\/div>\n<div>\n<div>\nURL\u67e5\u8be2\u53c2\u6570\uff1a<\/p>\n<ul>\n<li>match_target=&lt;label_selectors&gt;\uff1a\u901a\u8fc7\u6807\u7b7e\u96c6\u5339\u914d\u76ee\u6807\u7684\u6807\u7b7e\u9009\u62e9\u5668\u3002 \u5982\u679c\u7559\u7a7a\u5219\u9009\u62e9\u6240\u6709\u76ee\u6807\u3002<\/li>\n<li>metric=&lt;string&gt;\uff1a\u7528\u4e8e\u68c0\u7d22\u5143\u6570\u636e\u7684\u5ea6\u91cf\u6807\u51c6\u540d\u79f0\u3002 \u5982\u679c\u7559\u7a7a\uff0c\u5219\u68c0\u7d22\u6240\u6709\u5ea6\u91cf\u6807\u51c6\u5143\u6570\u636e\u3002<\/li>\n<li>limit=&lt;number&gt;\uff1a\u8981\u5339\u914d\u7684\u6700\u5927\u76ee\u6807\u6570\u3002<\/li>\n<\/ul>\n<p>\u67e5\u8be2\u7ed3\u679c\u7684data\u90e8\u5206\u5305\u542b\u4e00\u4e2a\u5305\u542b\u5ea6\u91cf\u5143\u6570\u636e\u548c\u76ee\u6807\u6807\u7b7e\u96c6\u7684\u5bf9\u8c61\u5217\u8868\u3002\u4ee5\u4e0b\u793a\u4f8b\u4ece\u524d\u4e24\u4e2a\u76ee\u6807\u8fd4\u56dego_goroutines\u6307\u6807\u7684\u6240\u6709\u5143\u6570\u636e\u6761\u76ee\uff0c\u6807\u7b7e\u4e3ajob =\\&#8221;prometheus\\&#8221;\u3002\n<\/p><\/div>\n<div>\n<div><\/div>\n<pre>curl -G http:\/\/localhost:9091\/api\/v1\/targets\/metadata \\\\\n    --data-urlencode \\'metric=go_goroutines\\' \\\\\n    --data-urlencode \\'match_target={job=\\\"prometheus\\\"}\\' \\\\\n    --data-urlencode \\'limit=2\\'\n{\n  \\\"status\\\": \\\"success\\\",\n  \\\"data\\\": [\n    {\n      \\\"target\\\": {\n        \\\"instance\\\": \\\"127.0.0.1:9090\\\",\n        \\\"job\\\": \\\"prometheus\\\"\n      },\n      \\\"type\\\": \\\"gauge\\\",\n      \\\"help\\\": \\\"Number of goroutines that currently exist.\\\",\n      \\\"unit\\\": \\\"\\\"\n    },\n    {\n      \\\"target\\\": {\n        \\\"instance\\\": \\\"127.0.0.1:9091\\\",\n        \\\"job\\\": \\\"prometheus\\\"\n      },\n      \\\"type\\\": \\\"gauge\\\",\n      \\\"help\\\": \\\"Number of goroutines that currently exist.\\\",\n      \\\"unit\\\": \\\"\\\"\n    }\n  ]\n}<\/pre>\n<div><\/div>\n<\/div>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u8fd4\u56de\u6807\u7b7einstance=\\&#8221;127.0.0.1:9090\\&#8221;\u7684\u6240\u6709\u76ee\u6807\u7684\u6240\u6709\u5ea6\u91cf\u6807\u51c6\u7684\u5143\u6570\u636e\uff1a<\/p>\n<div>\n<div><\/div>\n<pre>curl -G http:\/\/localhost:9091\/api\/v1\/targets\/metadata \\\\\n    --data-urlencode \\'match_target={instance=\\\"127.0.0.1:9090\\\"}\\'\n{\n  \\\"status\\\": \\\"success\\\",\n  \\\"data\\\": [\n    \/\/ ...\n    {\n      \\\"target\\\": {\n        \\\"instance\\\": \\\"127.0.0.1:9090\\\",\n        \\\"job\\\": \\\"prometheus\\\"\n      },\n      \\\"metric\\\": \\\"prometheus_treecache_zookeeper_failures_total\\\",\n      \\\"type\\\": \\\"counter\\\",\n      \\\"help\\\": \\\"The total number of ZooKeeper failures.\\\",\n      \\\"unit\\\": \\\"\\\"\n    },\n    {\n      \\\"target\\\": {\n        \\\"instance\\\": \\\"127.0.0.1:9090\\\",\n        \\\"job\\\": \\\"prometheus\\\"\n      },\n      \\\"metric\\\": \\\"prometheus_tsdb_reloads_total\\\",\n      \\\"type\\\": \\\"counter\\\",\n      \\\"help\\\": \\\"Number of times the database reloaded block data from disk.\\\",\n      \\\"unit\\\": \\\"\\\"\n    },\n    \/\/ ...\n  ]\n}<\/pre>\n<\/div>\n<h3>\u4e5d\u3001Altermanagers\u8b66\u62a5\u7ba1\u7406\u5668<\/h3>\n<p>\u4ee5\u4e0b\u7aef\u70b9\u8fd4\u56dePrometheus alertmanager\u53d1\u73b0\u7684\u5f53\u524d\u72b6\u6001\u6982\u8ff0\uff1a<\/p>\n<div>\n<pre>GET \/api\/v1\/alertmanagers<\/pre>\n<\/div>\n<p>\u6d3b\u52a8\u548c\u4e22\u5f03\u7684Alertmanagers\u90fd\u662f\u54cd\u5e94\u7684\u4e00\u90e8\u5206\uff1a<\/p>\n<div>\n<div><\/div>\n<pre>$ curl http:\/\/localhost:9090\/api\/v1\/alertmanagers\n{\n  \\\"status\\\": \\\"success\\\",\n  \\\"data\\\": {\n    \\\"activeAlertmanagers\\\": [\n      {\n        \\\"url\\\": \\\"http:\/\/127.0.0.1:9090\/api\/v1\/alerts\\\"\n      }\n    ],\n    \\\"droppedAlertmanagers\\\": [\n      {\n        \\\"url\\\": \\\"http:\/\/127.0.0.1:9093\/api\/v1\/alerts\\\"\n      }\n    ]\n  }\n}<\/pre>\n<div><\/div>\n<\/div>\n<h3>\u5341\u3001Status\u72b6\u6001<\/h3>\n<p>\u4ee5\u4e0b\u72b6\u6001\u7aef\u70b9\u663e\u793a\u5f53\u524d\u7684Prometheus\u914d\u7f6e\u3002<\/p>\n<h3>10.1 Config\u914d\u7f6e<\/h3>\n<p>\u4ee5\u4e0b\u7aef\u70b9\u8fd4\u56de\u5f53\u524d\u52a0\u8f7d\u7684\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<div>\n<pre>GET \/api\/v1\/status\/config<\/pre>\n<\/div>\n<p>\u914d\u7f6e\u4f5c\u4e3a\u8f6c\u50a8\u7684YAML\u6587\u4ef6\u8fd4\u56de\u3002 \u7531\u4e8eYAML\u5e93\u7684\u9650\u5236\uff0c\u4e0d\u5305\u62ecYAML\u6ce8\u91ca\u3002<\/p>\n<div>\n<div><\/div>\n<pre>$ curl http:\/\/localhost:9090\/api\/v1\/status\/config\n{\n  \\\"status\\\": \\\"success\\\",\n  \\\"data\\\": {\n    \\\"yaml\\\": \\\"&lt;content of the loaded config file in YAML&gt;\\\",\n  }\n}<\/pre>\n<div><\/div>\n<\/div>\n<h3>10.2 Flags\u6807\u5fd7<\/h3>\n<p>\u4ee5\u4e0b\u7aef\u70b9\u8fd4\u56dePrometheus\u914d\u7f6e\u7684\u6807\u5fd7\u503c\uff1a<\/p>\n<div>\n<pre>GET \/api\/v1\/status\/flags<\/pre>\n<\/div>\n<p>\u6240\u6709\u503c\u90fd\u4ee5\u201c\u5b57\u7b26\u4e32\u201d\u7684\u5f62\u5f0f\u51fa\u73b0\u3002<\/p>\n<div>\n<pre>$ curl http:\/\/localhost:9090\/api\/v1\/status\/flags\n{\n  \\\"status\\\": \\\"success\\\",\n  \\\"data\\\": {\n    \\\"alertmanager.notification-queue-capacity\\\": \\\"10000\\\",\n    \\\"alertmanager.timeout\\\": \\\"10s\\\",\n    \\\"log.level\\\": \\\"info\\\",\n    \\\"query.lookback-delta\\\": \\\"5m\\\",\n    \\\"query.max-concurrency\\\": \\\"20\\\",\n    ...\n  }\n}<\/pre>\n<div><\/div>\n<\/div>\n<div>\n<div>\n<h3>10.3 \u8fd0\u884c\u65f6\u4fe1\u606f<\/h3>\n<p>\u4ee5\u4e0b\u7aef\u70b9\u8fd4\u56de\u6709\u5173Prometheus\u670d\u52a1\u5668\u7684\u5404\u79cd\u8fd0\u884c\u65f6\u4fe1\u606f\u5c5e\u6027\uff1a<\/p>\n<div>\n<pre>GET \/api\/v1\/status\/runtimeinfo<\/pre>\n<\/div>\n<p>\u8fd4\u56de\u7684\u503c\u5177\u6709\u4e0d\u540c\u7684\u7c7b\u578b\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u8fd0\u884c\u65f6\u5c5e\u6027\u7684\u6027\u8d28\u3002<\/p>\n<div>\n<div><\/div>\n<pre>$ curl http:\/\/localhost:9090\/api\/v1\/status\/runtimeinfo\n{\n  \\\"status\\\": \\\"success\\\",\n  \\\"data\\\": {\n    \\\"startTime\\\": \\\"2019-11-02T17:23:59.301361365+01:00\\\",\n    \\\"CWD\\\": \\\"\/\\\",\n    \\\"reloadConfigSuccess\\\": true,\n    \\\"lastConfigTime\\\": \\\"2019-11-02T17:23:59+01:00\\\",\n    \\\"chunkCount\\\": 873,\n    \\\"timeSeriesCount\\\": 873,\n    \\\"corruptionCount\\\": 0,\n    \\\"goroutineCount\\\": 48,\n    \\\"GOMAXPROCS\\\": 4,\n    \\\"GOGC\\\": \\\"\\\",\n    \\\"GODEBUG\\\": \\\"\\\",\n    \\\"storageRetention\\\": \\\"15d\\\"\n  }\n}<\/pre>\n<div><\/div>\n<\/div>\n<p>\u6ce8\u610f\uff1a\u5728Prometheus\u7248\u672c\u4e4b\u95f4\uff0c\u786e\u5207\u8fd4\u56de\u7684\u8fd0\u884c\u65f6\u5c5e\u6027\u53ef\u80fd\u4f1a\u66f4\u6539<\/p>\n<h3>10.4 Build\u4fe1\u606f<\/h3>\n<p>\u4ee5\u4e0b\u7aef\u70b9\u8fd4\u56de\u6709\u5173Prometheus\u670d\u52a1\u5668\u7684\u5404\u79cd\u6784\u5efa\u4fe1\u606f\u5c5e\u6027\uff1a<\/p>\n<div>\n<pre>GET \/api\/v1\/status\/buildinfo<\/pre>\n<\/div>\n<p>\u6240\u6709\u503c\u90fd\u7684\u7ed3\u679c\u7c7b\u578b\u662f\u5b57\u7b26\u4e32\uff1a<\/p>\n<div>\n<div><\/div>\n<pre>$ curl http:\/\/localhost:9090\/api\/v1\/status\/buildinfo\n{\n  \\\"status\\\": \\\"success\\\",\n  \\\"data\\\": {\n    \\\"version\\\": \\\"2.13.1\\\",\n    \\\"revision\\\": \\\"cb7cbad5f9a2823a622aaa668833ca04f50a0ea7\\\",\n    \\\"branch\\\": \\\"master\\\",\n    \\\"buildUser\\\": \\\"julius@desktop\\\",\n    \\\"buildDate\\\": \\\"20191102-16:19:59\\\",\n    \\\"goVersion\\\": \\\"go1.13.1\\\"\n  }\n}<\/pre>\n<div><\/div>\n<\/div>\n<p>\u6ce8\u610f\uff1a\u5728Prometheus\u7248\u672c\u4e4b\u95f4\uff0c\u8fd4\u56de\u7684\u786e\u5207\u6784\u5efa\u5c5e\u6027\u53ef\u80fd\u4f1a\u66f4\u6539<\/p>\n<h3>\u5341\u4e00\u3001TSDB Admin APIs\uff0cTSDB\u7ba1\u7406API<\/h3>\n<p>\u8fd9\u4e9b\u662f\u4e3a\u9ad8\u7ea7\u7528\u6237\u516c\u5f00\u6570\u636e\u5e93\u529f\u80fd\u7684API\u3002 \u9664\u975e\u8bbe\u7f6e\u4e86&#8211;web.enable-admin-api\uff0c\u5426\u5219\u4e0d\u4f1a\u542f\u7528\u8fd9\u4e9bAPI\u3002\u6211\u4eec\u8fd8\u516c\u5f00\u4e86\u4e00\u4e2agRPC API\uff0c\u5176\u5b9a\u4e49\u53ef\u4ee5\u5728\u8fd9\u91cc\u627e\u5230\u3002 \u8fd9\u662f\u5b9e\u9a8c\u6027\u7684\uff0c\u5c06\u6765\u53ef\u80fd\u4f1a\u53d1\u751f\u53d8\u5316\u3002\n<\/p><\/div>\n<div>\n<div>\n<h3>11.1 \u5feb\u7167<\/h3>\n<p>\u5feb\u7167\u4f1a\u5c06\u6240\u6709\u5f53\u524d\u6570\u636e\u7684\u5feb\u7167\u521b\u5efa\u5230TSDB\u6570\u636e\u76ee\u5f55\u4e0b\u7684snapshots\/&lt;datetime&gt;-&lt;rand&gt;\u4e2d\uff0c\u5e76\u5c06\u8be5\u76ee\u5f55\u4f5c\u4e3a\u54cd\u5e94\u8fd4\u56de\u3002 \u5b83\u53ef\u4ee5\u9009\u62e9\u8df3\u8fc7\u4ec5\u5b58\u5728\u4e8e\u5934\u5757\u4e2d\u4f46\u5c1a\u672a\u538b\u7f29\u5230\u78c1\u76d8\u7684\u5feb\u7167\u6570\u636e\u3002\n<\/p><\/div>\n<div>\n<pre>POST \/api\/v1\/admin\/tsdb\/snapshot?skip_head=&lt;bool&gt;<\/pre>\n<\/div>\n<div>\n<div><\/div>\n<pre>$ curl -XPOST http:\/\/localhost:9090\/api\/v1\/admin\/tsdb\/snapshot\n{\n  \\\"status\\\": \\\"success\\\",\n  \\\"data\\\": {\n    \\\"name\\\": \\\"20171210T211224Z-2be650b6d019eb54\\\"\n  }\n}<\/pre>\n<div><\/div>\n<\/div>\n<p>\u5feb\u7167\u5df2\u5b58\u5728&lt;data-dir&gt;\/snapshots\/20171210T211224Z-2be650b6d019eb54<\/p>\n<div>\n<h3>11.2 \u5220\u9664\u5e8f\u5217<\/h3>\n<p>DeleteSeries\u5220\u9664\u65f6\u95f4\u8303\u56f4\u5185\u6240\u9009\u7cfb\u5217\u7684\u6570\u636e\u3002 \u5b9e\u9645\u6570\u636e\u4ecd\u7136\u5b58\u5728\u4e8e\u78c1\u76d8\u4e0a\uff0c\u5e76\u5728\u5c06\u6765\u7684\u538b\u7f29\u4e2d\u6e05\u9664\uff0c\u6216\u8005\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fbClean Tombstones\u7aef\u70b9\u6765\u660e\u786e\u6e05\u7406\u3002<br \/>\n\u5982\u679c\u6210\u529f\uff0c\u5219\u8fd4\u56de204\u3002<\/p>\n<div>\n<pre>POST \/api\/v1\/admin\/tsdb\/delete_series<\/pre>\n<\/div>\n<div>\nURL\u67e5\u8be2\u53c2\u6570\uff1a<\/p>\n<ul>\n<li>match[]=&lt;series_selector&gt;\uff1a\u9009\u62e9\u8981\u5220\u9664\u7684\u7cfb\u5217\u7684\u91cd\u590d\u6807\u7b7e\u5339\u914d\u5668\u53c2\u6570\u3002 \u5fc5\u987b\u81f3\u5c11\u63d0\u4f9b\u4e00\u4e2amatch[]\u53c2\u6570\u3002<\/li>\n<li>start= &lt;rfc3339 | unix_timestamp&gt;\uff1a\u5f00\u59cb\u65f6\u95f4\u6233\u3002 \u53ef\u9009\uff0c\u9ed8\u8ba4\u4e3a\u6700\u77ed\u53ef\u80fd\u65f6\u95f4\u3002<\/li>\n<li>end= &lt;rfc3339 | unix_timestamp&gt;\uff1a\u7ed3\u675f\u65f6\u95f4\u6233\u3002 \u53ef\u9009\uff0c\u9ed8\u8ba4\u4e3a\u6700\u957f\u53ef\u80fd\u65f6\u95f4\u3002<\/li>\n<\/ul>\n<p>\u4e0d\u63d0\u53ca\u5f00\u59cb\u548c\u7ed3\u675f\u65f6\u95f4\u5c06\u6e05\u9664\u6570\u636e\u5e93\u4e2d\u5339\u914d\u7cfb\u5217\u7684\u6240\u6709\u6570\u636e\u3002\u4f8b\uff1a<\/p>\n<div>\n<pre>$ curl -X POST \\\\\n  -g \\'http:\/\/localhost:9090\/api\/v1\/admin\/tsdb\/delete_series?match[]=up&amp;match[]=process_start_time_seconds{job=\\\"prometheus\\\"}\\'<\/pre>\n<\/div>\n<h3>11.3 CleanTombstones<\/h3>\n<p>CleanTombstones\u4ece\u78c1\u76d8\u4e2d\u5220\u9664\u5df2\u5220\u9664\u7684\u6570\u636e\u5e76\u6e05\u7406\u73b0\u6709\u7684\u903b\u8f91\u5220\u9664\u3002 \u8fd9\u53ef\u4ee5\u5728\u5220\u9664\u7cfb\u5217\u540e\u4f7f\u7528\u4ee5\u91ca\u653e\u7a7a\u95f4\u3002\u5982\u679c\u6210\u529f\uff0c\u5219\u8fd4\u56de204\u3002\n<\/p><\/div>\n<\/div>\n<\/div>\n<div>\n<pre>POST \/api\/v1\/admin\/tsdb\/clean_tombstones<\/pre>\n<\/div>\n<p>\u8fd9\u4e0d\u9700\u8981\u53c2\u6570\u6216\u6b63\u6587\uff1a<\/p>\n<div>\n<pre>$ curl -XPOST http:\/\/localhost:9090\/api\/v1\/admin\/tsdb\/clean_tombstones<\/pre>\n<\/div>\n<h2>\u7ba1\u7406API<\/h2>\n<p>Prometheus\u63d0\u4f9b\u4e86\u4e00\u7ec4\u7ba1\u7406API\uff0c\u4ee5\u7b80\u5316\u81ea\u52a8\u5316\u548c\u96c6\u6210<\/p>\n<h3>1.1 \u76d1\u63a7\u68c0\u6d4b<\/h3>\n<div>\n<pre>GET \/-\/healthy<\/pre>\n<\/div>\n<p>\u59cb\u7ec8\u8fd4\u56de200\uff0c\u5e94\u7528\u4e8e\u68c0\u67e5Prometheus\u7684\u8fd0\u884c\u72b6\u51b5\u3002<\/p>\n<h3>1.2\u00a0\u51c6\u5907\u68c0\u67e5<\/h3>\n<div>\n<pre>GET \/-\/ready<\/pre>\n<\/div>\n<p>\u5f53Prometheus\u51c6\u5907\u670d\u52a1\u6d41\u91cf\uff08\u5373\u54cd\u5e94\u67e5\u8be2\uff09\u65f6\uff0c\u6b64\u7aef\u70b9\u8fd4\u56de200\u3002<\/p>\n<h3>1.3 \u91cd\u8f7d<\/h3>\n<div>\n<div><\/div>\n<pre>PUT  \/-\/reload\nPOST \/-\/reload\nOR\nkill -HUP pid\ncurl -X POST http:\/\/IP\/-\/reload<\/pre>\n<div><\/div>\n<\/div>\n<p>\u8be5\u7aef\u70b9\u89e6\u53d1Prometheus\u914d\u7f6e\u548c\u89c4\u5219\u6587\u4ef6\u7684\u91cd\u65b0\u52a0\u8f7d\u3002 \u9ed8\u8ba4\u60c5\u51b5\u4e0b\u5b83\u662f\u7981\u7528\u7684\uff0c\u53ef\u4ee5\u901a\u8fc7&#8211;web.enable-lifecycle\u6807\u5fd7\u542f\u7528\u3002\u6216\u8005\uff0c\u53ef\u4ee5\u901a\u8fc7\u5c06SIGHUP\u53d1\u9001\u5230Prometheus\u8fdb\u7a0b\u6765\u89e6\u53d1\u914d\u7f6e\u91cd\u8f7d\u3002<\/p>\n<h3>1.4\u00a0\u9000\u51fa<\/h3>\n<div>\n<pre>PUT  \/-\/quit\nPOST \/-\/quit<\/pre>\n<\/div>\n<p>\u8be5\u7aef\u70b9\u89e6\u53d1Prometheus\u7684\u6b63\u5e38\u5173\u95ed\u3002 \u9ed8\u8ba4\u60c5\u51b5\u4e0b\u5b83\u662f\u7981\u7528\u7684\uff0c\u53ef\u4ee5\u901a\u8fc7&#8211;web.enable-lifecycle\u6807\u5fd7\u542f\u7528\u3002\u6216\u8005\uff0c\u53ef\u4ee5\u901a\u8fc7\u5c06SIGTERM\u53d1\u9001\u5230Prometheus\u8fdb\u7a0b\u6765\u89e6\u53d1\u6b63\u5e38\u5173\u95ed\u3002\n<\/p><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>HTTP API \u5728Prometheus\u670d\u52a1\u5668\u4e0a\u7684\/api\/v1\u4e0b\u53ef\u4ee5\u8bbf\u95ee\u5f53\u524d\u7a33\u5b9a\u7684HTTP API\u3002 \u5c06\u5728\u8be5 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=1866\"> <span class=\"screen-reader-text\">Prometheus API\u8bf4\u660e<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[138,122],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":51,"uagb_excerpt":"HTTP API \u5728Prometheus\u670d\u52a1\u5668\u4e0a\u7684\/api\/v1\u4e0b\u53ef\u4ee5\u8bbf\u95ee\u5f53\u524d\u7a33\u5b9a\u7684HTTP API\u3002 \u5c06\u5728\u8be5&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1866"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1866"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1866\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1866"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1866"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1866"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}