{"id":11261,"date":"2022-12-14T15:36:07","date_gmt":"2022-12-14T07:36:07","guid":{"rendered":"https:\/\/www.lwops.cn\/?p=11261"},"modified":"2022-12-14T15:36:07","modified_gmt":"2022-12-14T07:36:07","slug":"prometheus%e6%8a%80%e6%9c%af%e5%88%86%e4%ba%ab-%e5%a6%82%e4%bd%95%e7%9b%91%e6%8e%a7%e5%ae%bf%e4%b8%bb%e6%9c%ba%e5%92%8c%e5%ae%b9%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.lwops.cn\/index.php\/prometheus\/prometheus-artisan\/11261","title":{"rendered":"Prometheus\u6280\u672f\u5206\u4eab\u2014\u2014\u5982\u4f55\u76d1\u63a7\u5bbf\u4e3b\u673a\u548c\u5bb9\u5668"},"content":{"rendered":"\n

\u8fd9\u4e00\u671f\u4e3b\u8981\u6765\u8ddf\u5927\u5bb6\u804a\u4e00\u4e0b\uff0c\u4f7f\u7528node_exporter\u5de5\u5177\u6765\u66b4\u9732\u4e3b\u673a\u548c\u56e0\u516c\u7a0b\u5e8f\u4e0a\u7684\u6307\u6807\uff0c\u5229\u7528prometheus\u6765\u76d1\u63a7\u5bbf\u4e3b\u673a\uff1b\u4ee5\u53ca\u901a\u8fc7\u901a\u8fc7Cadvisor\u76d1\u63a7docker\u5bb9\u5668\u3002<\/p>\n\n\n\n

\u4e00\u3001\u90e8\u7f72node_exporter\u76d1\u63a7\u5bbf\u4e3b\u673a<\/h2>\n\n\n\n
# 1 \u4e0b\u8f7d\u8f6f\u4ef6\u5305\nwget https:\/\/github.com\/prometheus\/node_exporter\/releases\/download\/v1.4.0\/node_exporter-1.4.0.linux-amd64.tar.gz\n# \u521b\u5efanode exporter\u8fd0\u884c\u76ee\u5f55\nmkdir -p \/usr\/local\/node_exporter\ntar -xf node_exporter-1.4.0.linux-amd64.tar.gz\ncd node_exporter-1.4.0.linux-amd64 && mv .\/* \/usr\/local\/node_exporter\n#\u9a8c\u8bc1\n.\/node_exporter --version<\/code><\/pre>\n\n\n\n

\u67e5\u770bnode_exporter\u914d\u7f6e <\/strong><\/h2>\n\n\n\n

.\/node_expoter –help <\/p>\n\n\n\n

#\u9ed8\u8ba4\u8fd0\u884c\u7aef\u53e3 <\/p>\n\n\n\n

–web.listen-address=”:9100″ <\/p>\n\n\n\n

# \u66b4\u9732\u6307\u6807\u7684\u8def\u5f84 <\/p>\n\n\n\n

–web.telemetry-path=”\/metrics” <\/p>\n\n\n\n

#\u6ce8\u610f\uff1a\u901a\u8fc7\u914d\u7f6e\u53c2\u6570\uff0c\u53ef\u4ee5\u51b3\u5b9a\u542f\u7528\u54ea\u4e9b\u6536\u96c6\u5668\u3002 <\/p>\n\n\n\n

#\u542f\u52a8node_exporter\uff0c\u53ef\u4ee5\u6307\u5b9a\u53c2\u6570\u8fdb\u884c\u8986\u76d6 <\/p>\n\n\n\n

nohup .\/node_exporter –web.listen-address=”:9600″ <\/p>\n\n\n\n

–web.telemetry-path=”\/metrics” & <\/p>\n\n\n\n

#\u67e5\u770b\u662f\u5426\u542f\u52a8\u5b8c\u6210 ps -ef | grep node_exporter<\/p>\n\n\n\n

\u90e8\u7f72\u914d\u7f6etextfile\u6536\u96c6\u5668<\/h2>\n\n\n\n

\u8bf4\u660e\uff1a textfile\u6536\u96c6\u5668\u5141\u8bb8\u6211\u4eec\u66b4\u9732\u81ea\u5b9a\u4e49\u6307\u6807\uff0c\u8fd9\u4e9b\u81ea\u5b9a\u4e49\u6307\u6807\u53ef\u80fd\u662f\u6279\u5904\u7406\u6216cron\u4f5c\u4e1a\u65e0\u6cd5\u6293\u53d6\u7684\uff0c\u6216\u8005\u662f\u6ca1\u6709\u53ef\u7528\u7684exporter<\/p>\n\n\n\n

\u539f\u7406\uff1a\u6536\u96c6\u5668\u901a\u8fc7\u626b\u63cf\u6307\u5b9a\u76ee\u5f55\u4e2d\u7684\u95ee\u6d25\uff0c\u63d0\u53d6\u6240\u6709\u683c\u5f0f\u4e3aprometheus\u6307\u6807\u7684\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u66b4\u9732\u4ed6\u4eec\u4ee5\u4fbf\u88abprometheus sever\u6293\u53d6<\/p>\n\n\n\n

1\uff09 \u521b\u5efa\u6536\u96c6\u5668\u76ee\u5f55<\/p>\n\n\n\n

mkdir \/usr\/local\/node_exporter\/textfile_collector<\/p>\n\n\n\n

2) \u521b\u5efa\u65b0\u6307\u6807\uff0c\u6ce8\u610f\u6307\u6807\u5728\u4ee5.prom\u7ed3\u5c3e\u7684\u6587\u4ef6\u5185\u5b9a\u4e49<\/p>\n\n\n\n

echo ‘metadata{role=”docker”,data_center=”ShangHai”} 2’ >metadata.prom<\/p>\n\n\n\n

3) \u542f\u52a8textfile\u6536\u96c6\u5668<\/p>\n\n\n\n

textfile\u6536\u96c6\u5668\u4e0d\u9700\u8981\u914d\u7f6e\u53c2\u6570\uff0c\u9ed8\u8ba4\u5c31\u4f1a\u88ab\u52a0\u8f7d\uff0c\u6211\u4eec\u5728\u542f\u52a8node_exporter\u7684\u65f6\u5019\uff0c\u6307\u5b9atextfile\u6536\u96c6\u5668\u7684\u76ee\u5f55\u5373\u53ef<\/p>\n\n\n\n

\u53c2\u6570\uff1a<\/p>\n\n\n\n

collector.textfile.directory<\/p>\n\n\n\n

\u542f\u52a8<\/p>\n\n\n\n

nohup .\/node_exporter –web.listen-address=”:9600″ –web.telemetry-path=”\/metrics” –collector.textfile.directory=”\/usr\/local\/node_exporter\/textfile_collector” &
<\/p>\n\n\n\n

\u90e8\u7f72\u914d\u7f6esystemd\u6536\u96c6\u5668<\/h2>\n\n\n\n

\u8bf4\u660e\uff1a systemd\u6536\u96c6\u5668\u8bb0\u5f55\u4e86systemd\u7ba1\u7406\u7684\u670d\u52a1\uff0c\u901a\u8fc7–collector.systemd.unit-whitelist\u53c2\u6570\u6307\u5b9a\u9700\u8981\u6536\u96c6\u7684\u670d\u52a1\uff0c\u6309\u9700\u6536\u96c6<\/p>\n\n\n\n

\u542f\u52a8\uff1a<\/p>\n\n\n\n

nohup .\/node_exporter –web.listen-address=”:9600″ –web.telemetry-path=”\/metrics” –collector.textfile.directory=”\/usr\/local\/node_exporter\/textfile_collector” –collector.systemd –collector.systemd.unit-whitelist=”(docker|sshd|rsyslog).service” &<\/p>\n\n\n\n

\u914d\u7f6eprometheus\u5bf9node_exporter\u8fdb\u884c\u6307\u6807\u91c7\u96c6<\/p>\n\n\n\n

\u00a0 – job_name: “node_exporter”
\u00a0 \u00a0 static_configs:
\u00a0 \u00a0 \u00a0 – targets: [“192.168.161.118:9600”]\u00a0 \u00a0 \u00a0 \u00a0 #\u8fd9\u4e2a\u7aef\u53e3\u5c3d\u91cf\u4f7f\u7528\u9ed8\u8ba4\u7aef\u53e39100\uff0c\u65b9\u4fbf\u8fa8\u8ba4<\/p>\n\n\n\n

\u4e8c\u3001\u90e8\u7f72Cadvisor\u76d1\u63a7\u5bb9\u5668<\/h2>\n\n\n\n

docker run<\/p>\n\n\n\n

-v \/:\/rootfs:ro<\/p>\n\n\n\n

-v \/var\/run:\/var\/run\/:rw<\/p>\n\n\n\n

-v \/sys:\/sys:ro<\/p>\n\n\n\n

-v \/dev\/disk:\/dev\/disk:ro<\/p>\n\n\n\n

-v \/home\/docker:\/var\/lib\/docker:ro<\/p>\n\n\n\n

-p 8080:8080<\/p>\n\n\n\n

–detach=true –name=cadvisor –net=host google\/cadvisor<\/p>\n\n\n\n

#\u6ce8\u610f\uff1a\/home\/docker\u4e3a\u5b9e\u9645\u90e8\u7f72\u7684docker\u6570\u636e\u76ee\u5f55\uff0c\u9ed8\u8ba4\u5e94\u8be5\u4e3a\/var\/lib\/docker<\/p>\n\n\n\n

\u00a0\u9a8c\u8bc1\uff1a<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

 \u67e5\u770b\u6307\u6807\uff1a<\/p>\n\n\n\n

http:\/\/192.168.161.118:8080\/metrics<\/p>\n\n\n\n

\u914d\u7f6eprometheus server\u6293\u53d6CAdvisor<\/p>\n\n\n\n

\u914d\u7f6eprometheus.yml\u914d\u7f6e\u6587\u4ef6<\/p>\n\n\n\n