{"id":1854,"date":"2020-07-01T06:40:42","date_gmt":"2020-06-30T22:40:42","guid":{"rendered":"http:\/\/39.97.231.10\/?p=1854"},"modified":"2020-07-01T06:40:42","modified_gmt":"2020-06-30T22:40:42","slug":"prometheus-%e5%ae%89%e8%a3%85%e9%83%a8%e7%bd%b2","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=1854","title":{"rendered":"Prometheus \u5b89\u88c5\u90e8\u7f72"},"content":{"rendered":"<h1>\u8bf4\u660e<\/h1>\n<div>\n<div id=\\\"cnblogs_post_body\\\">\n<div>Prometheus\u662f\u4e00\u4e2a\u76d1\u63a7\u5e73\u53f0\uff0c\u901a\u8fc7\u5728\u76d1\u63a7\u76ee\u6807\u4e0a\u7684HTTP\u7aef\u70b9\u6765\u6536\u96c6\u53d7\u76d1\u63a7\u76ee\u6807\u7684\u6307\u6807\u3002\u672c\u6307\u5357\u5c06\u5411\u60a8\u5c55\u793a\u5982\u4f55\u4f7f\u7528Prometheus\u5b89\u88c5\uff0c\u914d\u7f6e\u548c\u76d1\u63a7\u6211\u4eec\u7684\u7b2c\u4e00\u4e2a\u8d44\u6e90\u3002 \u60a8\u5c06\u4e0b\u8f7d\uff0c\u5b89\u88c5\u5e76\u8fd0\u884cPrometheus\u3002\u60a8\u8fd8\u5c06\u4e0b\u8f7d\u5e76\u5b89\u88c5exporter\uff0c\u8fd9\u4e9b\u5de5\u5177\u53ef\u5728\u4e3b\u673a\u548c\u670d\u52a1\u4e0a\u516c\u5f00\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u3002\u6211\u4eec\u7684\u7b2c\u4e00\u4e2aexporter\u5c06\u662fPrometheus\u672c\u8eab\uff0c\u5b83\u63d0\u4f9b\u4e86\u6709\u5173\u5185\u5b58\u4f7f\u7528\uff0c\u5783\u573e\u6536\u96c6\u7b49\u7684\u5404\u79cd\u4e3b\u673a\u7ea7\u6307\u6807\u3002<\/div>\n<div>\n<h3 id=\\\"downloading-prometheus\\\">\u4e0b\u8f7d Prometheus<\/h3>\n<p>\u5728\u4f60\u7684\u5e73\u53f0\u4e0a\u4e0b\u8f7d<a href=\\\"https:\/\/prometheus.io\/download\/\\\" target=\\\"_blank\\\" rel=\\\"noopener noreferrer\\\">\u6700\u65b0\u7684\u7248\u672c<\/a>\uff0c\u7136\u540e\u89e3\u538b\u5b83\uff1a<\/p>\n<div>\n<pre>tar xvfz prometheus-*.tar.gz\ncd prometheus-*<\/pre>\n<\/div>\n<p>Prometheus\u670d\u52a1\u5668\u662f\u4e00\u4e2a\u79f0\u4e3aprometheus\uff08\u6216Microsoft Windows\u4e0a\u7684prometheus.exe\uff09\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002 \u6211\u4eec\u53ef\u4ee5\u8fd0\u884c\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u5e76\u901a\u8fc7\u4f20\u9012&#8211;help\u6807\u5fd7\u6765\u67e5\u770b\u6709\u5173\u5176\u9009\u9879\u7684\u5e2e\u52a9\u3002<\/p>\n<div>\n<div><\/div>\n<pre>\/usr\/local\/bin# .\/prometheus --help\nusage: prometheus [&lt;flags&gt;]\nThe Prometheus monitoring server\nFlags:\n#\u5e2e\u52a9\n  -h, --help                     Show context-sensitive help (also try --help-long and --help-man).\n#\u7248\u672c\n      --version                  Show application version.\n#\u914d\u7f6e\u6587\u4ef6\n      --config.file=\\\"prometheus.yml\\\"\n                                 Prometheus configuration file path.\n#\u76d1\u542c\u7aef\u53e3\n      --web.listen-address=\\\"0.0.0.0:9090\\\"\n                                 Address to listen on for UI, API, and telemetry.\n#\u7a7a\u95f2\u8fde\u63a5\u7684\u8d85\u65f6\u65f6\u95f4\n      --web.read-timeout=5m      Maximum duration before timing out read of the request, and closing idle connections.\n#\u6700\u5927\u8fde\u63a5\u6570\n      --web.max-connections=512  Maximum number of simultaneous connections.\n#\u53ef\u4ece\u5916\u90e8\u8bbf\u95eePrometheus\u7684URL\uff08\u4f8b\u5982\uff0c\u5982\u679cPrometheus\u662f\u901a\u8fc7\u53cd\u5411\u4ee3\u7406\u63d0\u4f9b\u7684\uff09\u3002 \u7528\u4e8e\u751f\u6210\u8fd4\u56de\u5230Prometheus\u672c\u8eab\u7684\u76f8\u5bf9\u548c\u7edd\u5bf9\u94fe\u63a5\u3002 \u5982\u679cURL\u5305\u542b\u8def\u5f84\u90e8\u5206\uff0c\u5b83\u5c06\u88ab\u7528\u4f5cPrometheus\u670d\u52a1\u7684\u6240\u6709HTTP\u7aef\u70b9\u7684\u524d\u7f00\u3002 \u5982\u679c\u7701\u7565\uff0c\u5219\u4f1a\u81ea\u52a8\u6d3e\u751f\u76f8\u5173\u7684URL\u7ec4\u4ef6\u3002\n      --web.external-url=&lt;URL&gt;   The URL under which Prometheus is externally reachable (for example, if Prometheus is served via a reverse proxy). Used for generating relative and absolute links back to\n                                 Prometheus itself. If the URL has a path portion, it will be used to prefix all HTTP endpoints served by Prometheus. If omitted, relevant URL components will be derived\n                                 automatically.\n#\u5185\u90e8\u8def\u7531\u7684\u524d\u7f00\u3002 \u9ed8\u8ba4\u4e3a--web.external-url\u7684\u8def\u5f84\u3002\n      --web.route-prefix=&lt;path&gt;  Prefix for the internal routes of web endpoints. Defaults to path of --web.external-url.\n#\u9759\u6001\u8d44\u6e90\u76ee\u5f55\u7684\u8def\u5f84\uff0c\u4f4d\u4e8e\/ user\n      --web.user-assets=&lt;path&gt;   Path to static asset directory, available at \/user.\n#\u542f\u7528\u662f\u5426\u901a\u8fc7HTTP\u8bf7\u6c42\u91cd\u65b0\u52a0\u8f7d\n      --web.enable-lifecycle     Enable shutdown and reload via HTTP request.\n#\u7ba1\u7406\u63a7\u5236\u64cd\u4f5c\u542f\u7528API\u7aef\u70b9\n      --web.enable-admin-api     Enable API endpoints for admin control actions.\n#\u6a21\u677f\u76ee\u5f55\u7684\u8def\u5f84\uff0c\u4f4d\u4e8e\/consoles\n      --web.console.templates=\\\"consoles\\\"\n                                 Path to the console template directory, available at \/consoles.\n#\u63a7\u5236\u53f0\u5e93\u76ee\u5f55\u7684\u8def\u5f84\n      --web.console.libraries=\\\"console_libraries\\\"\n                                 Path to the console library directory.\n#Prometheus\u5b9e\u4f8b\u9875\u9762\u7684\u6587\u6863\u6807\u9898\n      --web.page-title=\\\"Prometheus Time Series Collection and Processing Server\\\"\n                                 Document title of Prometheus instance.\n#\u7528\u4e8eCORS\u6765\u6e90\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\n      --web.cors.origin=\\\".*\\\"     Regex for CORS origin. It is fully anchored. Example: \\'https?:\/\/(domain1|domain2)\\\\.com\\'\n#\u6307\u6807(\u6570\u636e\uff09\u5b58\u50a8\u7684\u57fa\u672c\u8def\u5f84\n      --storage.tsdb.path=\\\"data\/\\\"\n                                 Base path for metrics storage.\n#\u5c06\u6570\u636e\u4fdd\u7559\u591a\u957f\u65f6\u95f4\u3002 \u6b64\u6807\u5fd7\u5df2\u88ab\u5f03\u7528\uff0c\u8bf7\u6539\u7528\u201c storage.tsdb.retention.time\u201d\u3002\n      --storage.tsdb.retention=STORAGE.TSDB.RETENTION\n                                 [DEPRECATED] How long to retain samples in storage. This flag has been deprecated, use \\\"storage.tsdb.retention.time\\\" instead.\n#\u5c06\u6570\u636e\u4fdd\u7559\u591a\u957f\u65f6\u95f4\u3002\u9ed8\u8ba415\u5929\n      --storage.tsdb.retention.time=STORAGE.TSDB.RETENTION.TIME\n                                 How long to retain samples in storage. When this flag is set it overrides \\\"storage.tsdb.retention\\\". If neither this flag nor \\\"storage.tsdb.retention\\\" nor\n                                 \\\"storage.tsdb.retention.size\\\" is set, the retention time defaults to 15d.\n#\u53ef\u4ee5\u4e3a\u5757\u5b58\u50a8\u7684\u6700\u5927\u5b57\u8282\u6570\u3002 \u652f\u6301\u7684\u5355\u4f4d\uff1aKB\uff0cMB\uff0cGB\uff0cTB\uff0cPB\u3002\n      --storage.tsdb.retention.size=STORAGE.TSDB.RETENTION.SIZE\n                                 [EXPERIMENTAL] Maximum number of bytes that can be stored for blocks. Units supported: KB, MB, GB, TB, PB. This flag is experimental and can be changed in future releases.\n#\u4e0d\u5728\u6570\u636e\u76ee\u5f55\u4e2d\u521b\u5efa\u9501\u6587\u4ef6\n      --storage.tsdb.no-lockfile\n                                 Do not create lockfile in data directory.\n#\u5141\u8bb8\u91cd\u53e0\u7684\u5757\uff0c\u4ece\u800c\u542f\u7528\u5782\u76f4\u538b\u7f29\u548c\u5782\u76f4\u67e5\u8be2\u5408\u5e76\u3002\n      --storage.tsdb.allow-overlapping-blocks\n                                 [EXPERIMENTAL] Allow overlapping blocks, which in turn enables vertical compaction and vertical query merge.\n#\u538b\u7f29tsdb WAL\n      --storage.tsdb.wal-compression\n                                 Compress the tsdb WAL.\n#\u5173\u95ed\u6216\u914d\u7f6e\u91cd\u65b0\u52a0\u8f7d\u65f6\u7b49\u5f85\u5237\u5199\u6570\u636e\u7684\u65f6\u95f4\n      --storage.remote.flush-deadline=&lt;duration&gt;\n                                 How long to wait flushing sample on shutdown or config reload.\n#\u5728\u5355\u4e2a\u67e5\u8be2\u4e2d\u901a\u8fc7\u8fdc\u7a0b\u8bfb\u53d6\u63a5\u53e3\u8fd4\u56de\u7684\u6700\u5927\u6837\u672c\u603b\u6570\u3002 0\u8868\u793a\u6ca1\u6709\u9650\u5236\u3002 \u5bf9\u4e8e\u6d41\u5f0f\u54cd\u5e94\u7c7b\u578b\uff0c\u5c06\u5ffd\u7565\u6b64\u9650\u5236\u3002\n      --storage.remote.read-sample-limit=5e7\n                                 Maximum overall number of samples to return via the remote read interface, in a single query. 0 means no limit. This limit is ignored for streamed response types.\n#\u5e76\u53d1\u8fdc\u7a0b\u8bfb\u53d6\u8c03\u7528\u7684\u6700\u5927\u6570\u76ee\u3002 0\u8868\u793a\u6ca1\u6709\u9650\u5236\u3002\n      --storage.remote.read-concurrent-limit=10\n                                 Maximum number of concurrent remote read calls. 0 means no limit.\n#\u7528\u4e8e\u6d41\u5f0f\u4f20\u8f93\u8fdc\u7a0b\u8bfb\u53d6\u54cd\u5e94\u7c7b\u578b\u7684\u5355\u4e2a\u5e27\u4e2d\u7684\u6700\u5927\u5b57\u8282\u6570\u3002 \u8bf7\u6ce8\u610f\uff0c\u5ba2\u6237\u7aef\u4e5f\u53ef\u80fd\u4f1a\u9650\u5236\u5e27\u5927\u5c0f\u3002 1MB\u4e3a\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u7531protobuf\u63a8\u8350<\/pre>\n<pre>--storage.remote.read-max-bytes-in-frame=1048576\n                                 Maximum number of bytes in a single frame for streaming remote read response types before marshalling. Note that client might have limit on frame size as well. 1MB as\n                                 recommended by protobuf by default.\n#\u5bb9\u5fcd\u4e2d\u65ad\u4ee5\u6062\u590d\u8b66\u62a5\u201c for\u201d\u72b6\u6001\u7684\u6700\u957f\u65f6\u95f4\u3002\n      --rules.alert.for-outage-tolerance=1h\n                                 Max time to tolerate prometheus outage for restoring \\\"for\\\" state of alert.\n#\u8b66\u62a5\u548c\u6062\u590d\u7684\u201c for\u201d\u72b6\u6001\u4e4b\u95f4\u7684\u6700\u77ed\u6301\u7eed\u65f6\u95f4\u3002 \u4ec5\u5bf9\u4e8e\u914d\u7f6e\u7684\u201c for\u201d\u65f6\u95f4\u5927\u4e8e\u5bbd\u9650\u671f\u7684\u8b66\u62a5\uff0c\u624d\u4fdd\u6301\u6b64\u72b6\u6001\u3002\n      --rules.alert.for-grace-period=10m\n                                 Minimum duration between alert and restored \\\"for\\\" state. This is maintained only for alerts with configured \\\"for\\\" time greater than grace period.\n#\u5c06\u8b66\u62a5\u91cd\u65b0\u53d1\u9001\u5230Alertmanager\u4e4b\u524d\u7b49\u5f85\u7684\u6700\u77ed\u65f6\u95f4\u3002\n      --rules.alert.resend-delay=1m\n                                 Minimum amount of time to wait before resending an alert to Alertmanager.\n#\u7b49\u5f85\u7684Alertmanager\u901a\u77e5\u7684\u961f\u5217\u5bb9\u91cf\u3002\n      --alertmanager.notification-queue-capacity=10000\n                                 The capacity of the queue for pending Alertmanager notifications.\n#\u5411Alertmanager\u53d1\u9001\u8b66\u62a5\u7684\u8d85\u65f6\u3002\n      --alertmanager.timeout=10s\n                                 Timeout for sending alerts to Alertmanager.\n#\u5728\u8868\u8fbe\u5f0f\u6c42\u503c\u671f\u95f4\u68c0\u7d22\u6307\u6807\u7684\u6700\u5927\u56de\u6eaf\u6301\u7eed\u65f6\u95f4\u3002\n      --query.lookback-delta=5m  The maximum lookback duration for retrieving metrics during expression evaluations.\n#\u6700\u5927\u67e5\u8be2\u65f6\u95f4\u3002\n      --query.timeout=2m         Maximum time a query may take before being aborted.\n#\u6700\u5927\u67e5\u8be2\u5e76\u53d1\u6570\n      --query.max-concurrency=20\n                                 Maximum number of queries executed concurrently.\n#\u5355\u4e2a\u67e5\u8be2\u53ef\u4ee5\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u7684\u6700\u5927\u6837\u672c\u6570\u3002 \u8bf7\u6ce8\u610f\uff0c\u5982\u679c\u67e5\u8be2\u5c1d\u8bd5\u5c06\u66f4\u591a\u7684\u6837\u672c\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u5219\u67e5\u8be2\u5c06\u5931\u8d25\uff0c\u56e0\u6b64\u8fd9\u4e5f\u9650\u5236\u4e86\u67e5\u8be2\u53ef\u4ee5\u8fd4\u56de\u7684\u6837\u672c\u6570\u3002<\/pre>\n<pre>      --query.max-samples=50000000\n                                 Maximum number of samples a single query can load into memory. Note that queries will fail if they try to load more samples than this into memory, so this also limits the\n                                 number of samples a query can return.\n#\u65e5\u5fd7\u7ea7\u522b\n      --log.level=info           Only log messages with the given severity or above. One of: [debug, info, warn, error]\n#\u65e5\u5fd7\u683c\u5f0f\n      --log.format=logfmt        Output format of log messages. One of: [logfmt, json]<\/pre>\n<div><\/div>\n<\/div>\n<p>\u5728\u542f\u52a8Prometheus\u4e4b\u524d\uff0c\u8ba9\u6211\u4eec\u5bf9\u5176\u8fdb\u884c\u914d\u7f6e\u3002<\/p>\n<h3 id=\\\"configuring-prometheus\\\">\u914d\u7f6e Prometheus<\/h3>\n<div>\nPrometheus\u914d\u7f6e\u662fYAML\uff0cPrometheus\u4e0b\u8f7d\u5305\u91cc\u9644\u5e26\u4e00\u4e2a\u540d\u4e3aprometheus.yml\u7684\u6587\u4ef6\u4e2d\u7684\u793a\u4f8b\u914d\u7f6e\uff0c\u8fd9\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u5165\u95e8\u4e4b\u5904\u3002\u6211\u4eec\u5220\u9664\u4e86\u793a\u4f8b\u6587\u4ef6\u4e2d\u7684\u5927\u90e8\u5206\u6ce8\u91ca\uff0c\u4f7f\u5176\u66f4\u7b80\u6d01\uff08\u6ce8\u91ca\u662f\u4ee5\uff03\u4e3a\u524d\u7f00\u7684\u884c\uff09\u3002\n<\/div>\n<\/div>\n<div>\n<div><\/div>\n<pre>global:\n  scrape_interval:     15s  #\u6293\u53d6\u9891\u7387\n  scrape_timeout:      10s  #\u6293\u53d6\u8d85\u65f6\n  evaluation_interval: 15s  #\u8bc4\u4f30\u89c4\u5219\u8bc4\u7387\nrule_files:\n  # - \\\"first.rules\\\"\n  # - \\\"second.rules\\\"\nscrape_configs:\n  - job_name: prometheus\n    static_configs:\n      - targets: [\\'localhost:9090\\']<\/pre>\n<div><\/div>\n<\/div>\n<div>\n\u793a\u4f8b\u914d\u7f6e\u6587\u4ef6\u4e2d\u6709\u4e09\u4e2a\u914d\u7f6e\u5757\uff1aglobal\uff0crule_files\u548cscrape_configs\u3002<\/p>\n<ul>\n<li>global\uff1a\u63a7\u5236Prometheus\u670d\u52a1\u5668\u7684\u5168\u5c40\u914d\u7f6e\u3002\u7b2c\u4e00\u4e2a\u662fscrape_interval\uff0c\u5b83\u63a7\u5236Prometheus\u6293\u53d6\u76ee\u6807\u7684\u9891\u7387\uff0c\u4e5f\u53ef\u4ee5\u4e3a\u5355\u4e2a\u76ee\u6807\u91cd\u5199\u6b64\u503c\u3002\u5728\u8fd9\u79cd\u4f8b\u5b50\u4e0b\uff0c\u5168\u5c40\u8bbe\u7f6e\u662f\u6bcf15s\u6293\u53d6\u4e00\u6b21\u3002\u00a0evaluation_interval\u9009\u9879\u63a7\u5236Prometheus\u8bc4\u4f30\u89c4\u5219\u7684\u9891\u7387\u3002 Prometheus\u4f7f\u7528\u89c4\u5219\u521b\u5efa\u65b0\u7684\u65f6\u95f4\u5e8f\u5217\u5e76\u751f\u6210\u8b66\u62a5\u3002<\/li>\n<li>rule_files\uff1aPrometheus\u670d\u52a1\u5668\u52a0\u8f7d\u7684\u4efb\u4f55\u89c4\u5219\u7684\u4f4d\u7f6e\u3002 \u73b0\u5728\u6211\u4eec\u6ca1\u6709\u89c4\u5219\u3002<\/li>\n<li>scrape_configs\uff1aPrometheus\u76d1\u89c6\u7684\u8d44\u6e90\u3002 \u7531\u4e8ePrometheus\u8fd8\u5c06\u81ea\u5df1\u7684\u6570\u636e\u516c\u5f00\u4e3aHTTP\u7aef\u70b9\uff0c\u56e0\u6b64\u5b83\u53ef\u4ee5\u6293\u53d6\u5e76\u76d1\u63a7\u81ea\u8eab\u7684\u5065\u5eb7\u72b6\u51b5\u3002 \u5728\u9ed8\u8ba4\u914d\u7f6e\u4e2d\uff0c\u6709\u4e00\u4e2a\u540d\u4e3aprometheus\u7684\u4f5c\u4e1a\uff0c\u5b83\u4f1a\u6293\u53d6Prometheus\u670d\u52a1\u5668\u516c\u5f00\u7684\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u3002 \u5305\u542b\u4e00\u4e2a\u9759\u6001\u914d\u7f6e\u7684\u76ee\u6807\uff0c\u5373\u7aef\u53e39090\u4e0a\u7684localhost\u3002Prometheus\u5e0c\u671b\u6307\u6807\u5728\/metrics\u8def\u5f84\u4e0a\u7684\u76ee\u6807\u4e0a\u53ef\u7528\u3002 \u6240\u4ee5\u8fd9\u4e2a\u9ed8\u8ba4\u7684\u5de5\u4f5c\u662f\u901a\u8fc7URL\u6293\u53d6\uff1a<a href=\\\"https:\/\/links.jianshu.com\/go?to=http%2F%2Flocalhost%3A9090%2Fmetrics\\\" target=\\\"_blank\\\" rel=\\\"noopener noreferrer\\\">http\/\/localhost:9090\/metrics<\/a>\u3002\u8fd4\u56de\u7684\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u5c06\u8be6\u7ec6\u8bf4\u660ePrometheus\u670d\u52a1\u5668\u7684\u72b6\u6001\u548c\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p>\u6709\u5173\u914d\u7f6e\u9009\u9879\u7684\u5b8c\u6574\u89c4\u8303\uff0c\u8bf7\u53c2\u9605<a href=\\\"https:\/\/links.jianshu.com\/go?to=https%3A%2F%2Fprometheus.io%2Fdocs%2Fprometheus%2Flatest%2Fconfiguration%2Fconfiguration%2F\\\" target=\\\"_blank\\\" rel=\\\"noopener noreferrer\\\">\u914d\u7f6e\u6587\u6863<\/a>\u3002<\/p>\n<h3 id=\\\"downloading-prometheus\\\">\u542f\u52a8 Prometheus<\/h3>\n<p>\u8981\u4f7f\u7528\u6211\u4eec\u65b0\u521b\u5efa\u7684\u914d\u7f6e\u6587\u4ef6\u542f\u52a8Prometheus\uff0c\u8bf7\u5207\u6362\u5230\u5305\u542bPrometheus\u4e8c\u8fdb\u5236\u6587\u4ef6\u7684\u76ee\u5f55\u5e76\u8fd0\u884c\uff1a<\/p>\n<div>\n<pre>.\/prometheus --config.file = prometheus.yml<\/pre>\n<\/div>\n<div>\n<div>\nPrometheus\u542f\u52a8\u540e\u5e94\u8be5\u80fd\u591f\u5728<a href=\\\"https:\/\/links.jianshu.com\/go?to=http%2F%2Flocalhost%3A9090\\\" target=\\\"_blank\\\" rel=\\\"noopener noreferrer\\\">http\/\/localhost:9090<\/a>\u6d4f\u89c8\u5230\u72b6\u6001\u9875\u9762\uff0c\u7ed9\u5b83\u5927\u7ea630\u79d2\u7684\u65f6\u95f4\u4ece\u81ea\u5df1\u7684HTTP\u6307\u6807\u7aef\u70b9\u6536\u96c6\u6709\u5173\u81ea\u5df1\u7684\u6570\u636e\u3002\u8fd8\u53ef\u4ee5\u901a\u8fc7\u5bfc\u822a\u5230\u5176\u81ea\u5df1\u7684\u6307\u6807\u7aef\u70b9\u6765\u9a8c\u8bc1\u662f\u5426\u6b63\u5728\u63d0\u4f9b\u6709\u5173\u81ea\u8eab\u7684\u6307\u6807\uff1a<a href=\\\"https:\/\/links.jianshu.com\/go?to=http%2F%2Flocalhost%3A9090%2Fmetrics\\\" target=\\\"_blank\\\" rel=\\\"noopener noreferrer\\\">http\/\/localhost:9090\/metrics<\/a>\u3002\n<\/div>\n<div>\n<h3>\u4f7f\u7528\u8868\u8fbe\u5f0f\u6d4f\u89c8\u5668<\/h3>\n<p>\u8ba9\u6211\u4eec\u8bd5\u7740\u770b\u4e00\u4e0bPrometheus\u6536\u96c6\u7684\u5173\u4e8e\u81ea\u5df1\u7684\u4e00\u4e9b\u6570\u636e\u3002 \u8981\u4f7f\u7528Prometheus\u7684\u5185\u7f6e\u8868\u8fbe\u5f0f\u6d4f\u89c8\u5668\uff0c\u8bf7\u5bfc\u822a\u5230<a href=\\\"https:\/\/links.jianshu.com\/go?to=http%2F%2Flocalhost%3A9090%2Fgraph\\\" target=\\\"_blank\\\" rel=\\\"noopener noreferrer\\\">http\/\/localhost:9090\/graph<\/a>\u5e76\u5728\u201cGraph\u201d\u9009\u9879\u5361\u4e2d\u9009\u62e9\u201cConsole\u201d\u89c6\u56fe\u3002<br \/>\nPrometheus\u5bfc\u51fa\u7684\u4e00\u4e2a\u5ea6\u91cf\u6807\u51c6\u79f0\u4e3apromhttp_metric_handler_requests_total\uff08Prometheus\u670d\u52a1\u5668\u5df2\u670d\u52a1\u7684\/metrics\u8bf7\u6c42\u7684\u603b\u6570\uff09\u3002 \u7ee7\u7eed\u5e76\u5c06\u5176\u8f93\u5165\u8868\u8fbe\u5f0f\u63a7\u5236\u53f0\uff1a<\/p>\n<div>\n<pre>promhttp_metric_handler_requests_total<\/pre>\n<\/div>\n<div>\n\u8fd9\u5e94\u8be5\u8fd4\u56de\u8bb8\u591a\u4e0d\u540c\u7684\u65f6\u95f4\u5e8f\u5217\uff08\u4ee5\u53ca\u4e3a\u6bcf\u4e2a\u8bb0\u5f55\u7684\u6700\u65b0\u503c\uff09\uff0c\u6240\u6709\u65f6\u95f4\u5e8f\u5217\u90fd\u4f7f\u7528\u5ea6\u91cf\u6807\u51c6\u540d\u79f0promhttp_metric_handler_requests_total\uff0c\u4f46\u5177\u6709\u4e0d\u540c\u7684\u6807\u7b7e\u3002 \u8fd9\u4e9b\u6807\u7b7e\u6307\u5b9a\u4e0d\u540c\u7684\u8bf7\u6c42\u72b6\u6001\u3002<br \/>\n\u5982\u679c\u6211\u4eec\u53ea\u5bf9\u5bfc\u81f4HTTP\u4ee3\u7801200\u7684\u8bf7\u6c42\u611f\u5174\u8da3\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6b64\u67e5\u8be2\u6765\u68c0\u7d22\u8be5\u4fe1\u606f\uff1a<\/p>\n<div>\n<pre>promhttp_metric_handler_requests_total{code=\\\"200\\\"}<\/pre>\n<\/div>\n<p>\u8981\u8ba1\u7b97\u8fd4\u56de\u7684\u65f6\u95f4\u5e8f\u5217\u603b\u6570\uff0c\u60a8\u53ef\u4ee5\u5199\uff1a<\/p>\n<div>\n<pre>count(promhttp_metric_handler_requests_total)<\/pre>\n<\/div>\n<p>\u6709\u5173\u8868\u8fbe\u5f0f\u8bed\u8a00\u7684\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605<a href=\\\"https:\/\/links.jianshu.com\/go?to=https%3A%2F%2Fprometheus.io%2Fdocs%2Fprometheus%2Flatest%2Fquerying%2Fbasics%2F\\\" target=\\\"_blank\\\" rel=\\\"noopener noreferrer\\\">\u8868\u8fbe\u5f0f\u8bed\u8a00\u6587\u6863<\/a>\u3002<\/p>\n<div>\n<h3>\u9002\u7528\u56fe\u8868\u63a5\u53e3<\/h3>\n<p>\u8981\u7ed8\u5236\u8868\u8fbe\u5f0f\u56fe\u8868\uff0c\u8bf7\u5bfc\u822a\u5230<a href=\\\"https:\/\/links.jianshu.com\/go?to=http%2F%2Flocalhost%3A9090%2Fmgraph\\\" target=\\\"_blank\\\" rel=\\\"noopener noreferrer\\\">http\/\/localhost:9090\/graph<\/a>\u00a0graph\u5e76\u4f7f\u7528\u201c\u56fe\u8868\u201d\u9009\u9879\u5361\u3002<br \/>\n\u4f8b\u5982\uff0c\u8f93\u5165\u4ee5\u4e0b\u8868\u8fbe\u5f0f\u6765\u7ed8\u5236\u5728\u81ea\u6211\u6293\u53d6\u7684Prometheus\u4e2d\u53d1\u751f\u7684\u8fd4\u56de\u72b6\u6001\u4ee3\u7801200\u7684\u6bcf\u79d2HTTP\u8bf7\u6c42\u7387\uff1a\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div>\n<pre>rate(promhttp_metric_handler_requests_total{code=\\\"200\\\"}[1m])<\/pre>\n<\/div>\n<p>\u60a8\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528\u56fe\u5f62\u8303\u56f4\u53c2\u6570\u548c\u5176\u4ed6\u8bbe\u7f6e\u3002<\/p>\n<div>\n<div>\n<h3>\u76d1\u63a7\u5176\u4ed6\u76ee\u6807<\/h3>\n<p>\u4ec5\u4ecePrometheus\u90a3\u91cc\u6536\u96c6\u6307\u6807\u5e76\u4e0d\u80fd\u5f88\u597d\u5730\u53cd\u6620Prometheus\u7684\u80fd\u529b\u3002 \u4e3a\u4e86\u66f4\u597d\u5730\u4e86\u89e3Prometheus\u53ef\u4ee5\u505a\u4ec0\u4e48\uff0c\u6211\u4eec\u5efa\u8bae\u60a8\u6d4f\u89c8\u6709\u5173\u5176\u4ed6exporter\u7684\u6587\u6863\u3002 \u4f7f\u7528node exporter\u6307\u5357<a href=\\\"https:\/\/links.jianshu.com\/go?to=https%3A%2F%2Fprometheus.io%2Fdocs%2Fguides%2Fnode-exporter%2F\\\" target=\\\"_blank\\\" rel=\\\"noopener noreferrer\\\">\u76d1\u63a7Linux\u6216macOS\u4e3b\u673a\u6307\u6807<\/a>\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u8d77\u70b9\u3002\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf4\u660e Prometheus\u662f\u4e00\u4e2a\u76d1\u63a7\u5e73\u53f0\uff0c\u901a\u8fc7\u5728\u76d1\u63a7\u76ee\u6807\u4e0a\u7684HTTP\u7aef\u70b9\u6765\u6536\u96c6\u53d7\u76d1\u63a7\u76ee\u6807\u7684\u6307\u6807\u3002\u672c\u6307\u5357\u5c06\u5411\u60a8\u5c55 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=1854\"> <span class=\"screen-reader-text\">Prometheus \u5b89\u88c5\u90e8\u7f72<\/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":0,"uagb_excerpt":"\u8bf4\u660e Prometheus\u662f\u4e00\u4e2a\u76d1\u63a7\u5e73\u53f0\uff0c\u901a\u8fc7\u5728\u76d1\u63a7\u76ee\u6807\u4e0a\u7684HTTP\u7aef\u70b9\u6765\u6536\u96c6\u53d7\u76d1\u63a7\u76ee\u6807\u7684\u6307\u6807\u3002\u672c\u6307\u5357\u5c06\u5411\u60a8\u5c55&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1854"}],"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=1854"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1854\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1854"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}