{"id":1217,"date":"2021-07-30T13:56:32","date_gmt":"2021-07-30T05:56:32","guid":{"rendered":"https:\/\/egonlin.com\/?p=1217"},"modified":"2021-07-30T13:56:32","modified_gmt":"2021-07-30T05:56:32","slug":"%e7%9b%91%e6%8e%a7%e9%9d%9e%e6%90%ba%e5%b8%a6metrics%e6%9c%8d%e5%8a%a1","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=1217","title":{"rendered":"\u76d1\u63a7\u975e\u643a\u5e26metrics\u670d\u52a1"},"content":{"rendered":"<h1>\u76d1\u63a7\u975e\u643a\u5e26metrics\u670d\u52a1<\/h1>\n<h2>\u4e00\u3001\u600e\u4e48\u76d1\u63a7\uff1f<\/h2>\n<h3>1\u3001expertor<\/h3>\n<pre><code class=\"language-bash\">    \u524d\u9762\u7684\u7cfb\u5217\u4e2d\uff0c\u6211\u4eec\u5728\u4e3b\u673a\u4e0a\u9762\u5b89\u88c5\u4e86node_exporter\u7a0b\u5e8f\uff0c\u8be5\u7a0b\u5e8f\u5bf9\u5916\u66b4\u9732\u4e00\u4e2a\u7528\u4e8e\u83b7\u53d6\u5f53\u524d\u76d1\u63a7\u6837\u672c\u6570\u636e\u7684http\u7684\u8bbf\u95ee\u5730\u5740\uff0c \u8fd9\u4e2a\u7684\u4e00\u4e2a\u7a0b\u5e8f\u6210\u4e3aexporter,Exporter\u7684\u5b9e\u4f8b\u79f0\u4e3a\u4e00\u4e2atarget\uff0c prometheus\u901a\u8fc7\u8f6e\u8bad\u7684\u65b9\u5f0f\u5b9a\u65f6\u4ece\u8fd9\u4e9btarget\u4e2d\u83b7\u53d6\u76d1\u63a7\u6570\u636e\u3002<\/code><\/pre>\n<h3>2\u3001\u4ec0\u4e48\u662fexpertor\uff1f<\/h3>\n<pre><code class=\"language-bash\">    \u5e7f\u4e49\u4e0a\u5411prometheus\u63d0\u4f9b\u76d1\u63a7\u6570\u636e\u7684\u7a0b\u5e8f\u90fd\u53ef\u4ee5\u6210\u4e3a\u4e00\u4e2aexporter\u7684\uff0c\u4e00\u4e2aexporter\u7684\u5b9e\u4f8b\u79f0\u4e3atarget, exporter\u6765\u6e90\u4e3b\u89812\u4e2a\u65b9\u9762\uff0c\u4e00\u4e2a\u662f\u793e\u533a\u63d0\u4f9b\u7684\uff0c\u4e00\u79cd\u662f\u7528\u6237\u81ea\u5b9a\u4e49\u7684\u3002<\/code><\/pre>\n<h3>3\u3001\u5e38\u7528exporter<\/h3>\n<pre><code class=\"language-bash\">\u5b98\u65b9\u7684exporter\u5730\u5740\uff1a https:\/\/prometheus.io\/docs\/instrumenting\/exporters\/<\/code><\/pre>\n<h3>4\u3001nginx\u76d1\u63a7<\/h3>\n<pre><code class=\"language-bash\">prometheus\u76d1\u63a7nginx\u4f7f\u7528nginx-vts-exporter\u91c7\u96c6\u6570\u636e\u3002\u540c\u65f6\uff0c\u9700\u8981nginx\u652f\u6301nginx-module-vts\u6a21\u5757\u83b7\u53d6nginx\u81ea\u8eab\u7684\u4e00\u4e9b\u6570\u636e\u3002<\/code><\/pre>\n<h2>\u4e8c\u3001\u76d1\u63a7\u6d41\u7a0b<\/h2>\n<pre><code class=\"language-bash\">1\u3001\u90e8\u7f72nginx\u6dfb\u52a0nginx-module-vts\n2\u3001\u90e8\u7f72EndPrints\uff0c\u94fe\u63a5expertor\u66b4\u9732\u51fa\u6765\u7684metrics\u63a5\u53e3\n3\u3001\u90e8\u7f72Service\uff0c\u57fa\u4e8eServiceMonitor\u4f7f\u7528\n4\u3001\u521b\u5efaServiceMonitor\uff0c\u6ce8\u5165promethues\n5\u3001\u6d4b\u8bd5\n6\u3001\u52a0\u5165grafana\uff0c\u505a\u5927\u5c4f\u5c55\u793a<\/code><\/pre>\n<h2>\u4e09\u3001\u90e8\u7f72nginx-module-vts<\/h2>\n<h3>1\u3001\u83b7\u53d6\u7b2c\u4e09\u65b9\u6a21\u5757\u4ee3\u7801<\/h3>\n<pre><code class=\"language-bash\">[root@web02 ~]# mkdir \/nginx_module\n[root@web02 ~]# cd \/nginx_module\/\n[root@web02 \/nginx_module]# wget https:\/\/github.com\/vozlt\/nginx-module-vts\/archive\/refs\/heads\/master.zip<\/code><\/pre>\n<h3>2\u3001\u89e3\u538b<\/h3>\n<pre><code class=\"language-bash\">[root@web02 \/nginx_module]# unzip nginx-module-vts-master.zip<\/code><\/pre>\n<h3>3\u3001\u4e0b\u8f7d\u5b89\u88c5\u5305<\/h3>\n<pre><code class=\"language-bash\">[root@web02 ~]# wget https:\/\/nginx.org\/download\/nginx-1.18.0.tar.gz<\/code><\/pre>\n<h3>4\u3001\u89e3\u538b\u6e90\u7801\u5305<\/h3>\n<pre><code class=\"language-bash\">tar xf nginx-1.18.0.tar.gz <\/code><\/pre>\n<h3>5\u3001\u914d\u7f6e\u5b89\u88c5\u7684\u73af\u5883\uff08\u8fd0\u884c\u7528\u6237\u3001\u5b89\u88c5\u76ee\u5f55\u7b49\uff09<\/h3>\n<pre><code class=\"language-bash\">1.\u521b\u5efa\u7528\u6237\u548c\u7ec4\uff0c\u4e14\u4e0d\u521b\u5efa\u7528\u6237\u7684\u5bb6\u76ee\u5f55\n[root@web03 ~]# groupadd www -g 666\n[root@web03 ~]# useradd www -u 666 -g 666 -s \/sbin\/nologin -M\n\n2.\u521b\u5efa\u4e00\u4e2a\u5b89\u88c5\u76ee\u5f55\n\u516c\u53f8\u4e0d\u6307\u5b9a\u5b89\u88c5\u76ee\u5f55\u65f6\uff0c\u9ed8\u8ba4\u5b89\u88c5\u5230\/usr\/local\/\u8f6f\u4ef6\u540d\/\n\u516c\u53f8\u6307\u5b9a\u7684\u8bdd\uff0c\u5c31\u8981\u6309\u7167\u516c\u53f8\u8981\u6c42\u6765<\/code><\/pre>\n<h3>6\u3001\u751f\u6210Makefile<\/h3>\n<pre><code class=\"language-bash\">[root@web02 ~\/nginx-1.18.0]# .\/configure --prefix=\/usr\/local\/nginx-1.18.0 --user=www --group=www --without-http_gzip_module --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --add-module=\/nginx_module\/nginx-module-vts-master --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt=&#039;-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC&#039; --with-ld-opt=&#039;-Wl,-z,relro -Wl,-z,now -pie&#039;<\/code><\/pre>\n<h3>7\u3001\u7f16\u8bd1\u5b89\u88c5<\/h3>\n<pre><code class=\"language-bash\">[root@web02 ~\/nginx-1.18.0]# make &amp;&amp; make install<\/code><\/pre>\n<h3>8\u3001\u67e5\u770b\u5b89\u88c5\u7ed3\u679c<\/h3>\n<pre><code class=\"language-bash\">[root@web02 ~\/nginx-1.18.0]# ll \/usr\/local\/nginx-1.18.0\/\ntotal 0\ndrwxr-xr-x 2 root root 333 Apr 26 16:21 conf\ndrwxr-xr-x 2 root root  40 Apr 26 16:21 html\ndrwxr-xr-x 2 root root   6 Apr 26 16:21 logs\ndrwxr-xr-x 2 root root  19 Apr 26 16:21 sbin\n\n[root@web02 ~]# cd \/usr\/local\/nginx-1.18.0\/sbin\n[root@web02 \/usr\/local\/nginx-1.18.0\/sbin]# .\/nginx -V\n...\n--add-module=\/nginx_module\/nginx-module-vts-master\n...<\/code><\/pre>\n<h3>9\u3001\u505a\u8f6f\u8fde\u63a5<\/h3>\n<pre><code class=\"language-bash\">[root@web02 \/usr\/local]# ln -s \/usr\/local\/nginx-1.18.0 \/usr\/local\/nginx<\/code><\/pre>\n<h3>10\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/h3>\n<pre><code class=\"language-bash\">[root@web02 \/usr\/local]# vim \/etc\/profile.d\/nginx.sh\nexport PATH=$PATH:\/usr\/local\/nginx\/sbin\n\n[root@web02 \/usr\/local]# source \/etc\/profile    #\u5728\u5f53\u524dbash\u73af\u5883\u4e0b\u8bfb\u53d6\u5e76\u6267\u884c\/etc\/profile\u4e2d\u7684\u547d\u4ee4<\/code><\/pre>\n<h3>11\u3001\u52a0\u5165system\u7ba1\u7406\u914d\u7f6e<\/h3>\n<pre><code class=\"language-bash\">[root@web02 \/usr\/local]# cat \/usr\/lib\/systemd\/system\/nginx.service\n[Unit]\nDescription=nginx - high performance web server\nDocumentation=http:\/\/nginx.org\/en\/docs\/\nAfter=network-online.target remote-fs.target nss-lookup.target\nWants=network-online.target\n\n[Service]\nType=forking\nPIDFile=\/usr\/local\/nginx\/logs\/nginx.pid\nExecStart=\/usr\/local\/nginx\/sbin\/nginx -c \/usr\/local\/nginx\/conf\/nginx.conf\nExecReload=\/usr\/local\/nginx\/sbin\/nginx -s reload\nExecStop=\/usr\/local\/nginx\/sbin\/nginx -s stop\n\n[Install]\nWantedBy=multi-user.target\n\n#\u91cd\u8f7d\n[root@web02 \/usr\/local]# systemctl daemon-reload<\/code><\/pre>\n<h3>12\u3001\u6dfb\u52a0\u5b50\u914d\u7f6e\u6587\u4ef6\u5939<\/h3>\n<pre><code class=\"language-bash\">[root@web02 ~]# cd \/usr\/local\/nginx\/conf\n[root@web02 \/usr\/local\/nginx\/conf]# mkdir conf.d<\/code><\/pre>\n<h3>13\u3001\u4fee\u6539\u4e3b\u914d\u7f6e\u6587\u4ef6<\/h3>\n<pre><code class=\"language-bash\">[root@web02 \/usr\/local\/nginx\/conf]# vim nginx.conf\n...\nuser  nginx;\n...\ninclude \/usr\/local\/nginx\/conf\/conf.d\/*.conf;\n...:<\/code><\/pre>\n<h3>14\u3001\u914d\u7f6e\u4e1a\u52a1\u914d\u7f6e\u6587\u4ef6<\/h3>\n<blockquote>\n<p>\u8fd9\u91cc\u6211\u7528\u4e86\u4ee5\u524d\u505a\u7684php\u4e1a\u52a1\uff0c\u968f\u4fbf\u627e\u4e2a\u670d\u52a1\u6216\u8005\u9759\u6001\u9875\u9762\u4ee3\u66ff\u5373\u53ef<\/p>\n<\/blockquote>\n<pre><code class=\"language-bash\">server {\n    listen       80;\n    server_name  localhost;\n        root \/code\/;\n\n    location \/ {\n        index  index.php index.html index.htm;\n        root \/code\/;\n    }\n\n    location ~ \\.php$ {\n        fastcgi_pass  127.0.0.1:9000;\n        fastcgi_index index.php;\n        fastcgi_param SCRIPT_FILENAME \/code$fastcgi_script_name;\n        include       fastcgi_params;\n    }\n}<\/code><\/pre>\n<h3>15\u3001\u914d\u7f6e\u76d1\u63a7\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p><\/p><div id=\"rml_readmorelogin_placeholder\" style=\"position:relative;\"><div id=\"rml_fade_content\" style=\"position: absolute;\r\ntop:-10em;\r\nwidth:100%;\r\nheight:10em;\r\nbackground: -webkit-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -moz-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -o-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -ms-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\"><\/div><div class=\"wpf-controller aru_rml_from_in_post\" style=\"background-color:#eeeeee;border:5px solid #cce6ff;\" id=\"ARU_ReadMoreLogin_ReadMoreLoginController\"><h2 id=\"Header\">\u67e5\u770b\u66f4\u591a<\/h2><div id=\"Message\"><p>\u8054\u7cfb\u7ba1\u7406\u5458\u5fae\u4fe1tutu19192010\uff0c\u6ce8\u518c\u8d26\u53f7<\/p>\n<\/div><div id=\"StatusBarHeader\"><\/div><form id=\"ARU_ReadMoreLogin_ReadMoreLoginController\"><input name=\"post_id\" value=\"1217\" type=\"hidden\"\/><input name=\"_init_callback\" value=\"InitLogin\" type=\"hidden\"\/><input name=\"post_id\" value=\"1217\" type=\"hidden\"\/><input name=\"rt_ype\" value=\"1\" type=\"hidden\"\/><input name=\"nonce\" value=\"94f6069f7a\" type=\"hidden\"\/><input name=\"_wpnonce\" value=\"52f7091102\" type=\"hidden\"\/><input name=\"_controller\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginController\" type=\"hidden\"\/><input name=\"_proxy_controller\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginController\" type=\"hidden\"\/><input name=\"_view\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginView\" type=\"hidden\"\/><table class=\"wpf-table-placeholder\"><tbody class=\"wpf-table-placeholder\"><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\" width=\"400px\"><table class=\"wpf-table-placeholder\"><tbody class=\"wpf-table-placeholder\"><tr class=\"wpf-table-placeholder\"><th class=\"wpf-table-placeholder-input\"><label class=\"wpf-label\">Username:<\/label><\/th><\/tr><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\"><input class=\"regular-text text_input\" name=\"username\" value=\"\" type=\"text\"\/><\/td><\/tr><tr class=\"wpf-table-placeholder\"><th class=\"wpf-table-placeholder-input\"><label class=\"wpf-label\">Password:<\/label><\/th><\/tr><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\"><input class=\"regular-text text_input\" name=\"password\" value=\"\" type=\"password\"\/><\/td><\/tr><\/tbody><\/table><p class=\"wpf-table-placeholder submit\"><button class=\"wp_plugin_framework_ajax_button\" type=\"button\" style=\"background-color:#4D90FE;;color:#ffffff;;border:1px solid #3079ed;\" name=\"_event\" value=\"ButtonLogin\">Log in<\/button><\/p><\/td><td class=\"wpf-table-placeholder-input\"><\/td><\/tr><\/tbody><\/table><\/form><div id=\"ButtonStartRegister\"><a href=\"https:\/\/egonlin.com\/wp-login.php?action=register\">Register<\/a><\/div><div id=\"Link1\"><a href=\"https:\/\/egonlin.com\/wp-login.php?action=lostpassword\">Forgotten username or password?<\/a><\/div><div id=\"StatusBarFooter\"><\/div><\/div><\/div><div id=aru_remaining_content><\/div>","protected":false},"excerpt":{"rendered":"<p>\u76d1\u63a7\u975e\u643a\u5e26metrics\u670d\u52a1 \u4e00\u3001\u600e\u4e48\u76d1\u63a7\uff1f 1\u3001expertor \u524d\u9762\u7684\u7cfb\u5217\u4e2d\uff0c\u6211\u4eec\u5728\u4e3b\u673a\u4e0a\u9762\u5b89\u88c5\u4e86node [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":1222,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[145],"tags":[21,133,134,135,19,58,147,22,132,20],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/1217"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1217"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/1217\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/media\/1222"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}