组件性能数据采集--nginx数据采集
组件性能数据采集--nginx数据采集
配置nginx_vts_exporter
下载安装openresty
wget -c https://openresty.org/download/openresty-1.19.3.1.tar.gz
tar zxvf openresty-1.19.3.1.tar.gz -C ./openresty
下载nginx_vts_exporter
wget -c https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.10.3/nginx-vts-exporter-0.10.3.linux-386.tar.gz
tar zxvf nginx-vts-exporter-0.10.3.linux-386.tar.gz -C ./openresty
下载nginx-module-vts
git clone git://github.com/vozlt/nginx-module-vts.git
mv nginx-module-vts ./openresty
下载openssl
wget -c https://github.com/openssl/openssl/archive/OpenSSL_1_0_2u.tar.gz
tar zxvf OpenSSL_1_0_2u.tar.gz -C ./openresty
安装pcre包
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
配置编译文件
cd openresty-1.19.3.1/
./configure --prefix=/opt/packages/openresty --with-luajit --with-pcre --with-http_iconv_module --with-http_realip_module --with-http_sub_module --with-http_stub_status_module --with-stream --with-stream_ssl_module --add-module=/opt/packages/openresty/nginx-module-vts --with-openssl=/opt/packages/openresty/openssl-OpenSSL_1_0_2u
make build install
配置vts
-
nginx.conf 配置添加日志和 vhost_traffic_status_zone;
-
要监控的站点添加配置 /vts-status.
-
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; log_format graylog2_json escape=json'{"timestamp":"$time_iso8601",' '"remote_addr":"$remote_addr",' '"body_bytes_sent":$body_bytes_sent,' '"request_time":$request_time,' '"response_status":$status,' '"request":"$request",' '"request_method":"$request_method",' '"host":"$host",' '"upstream_cache_status":"$upstream_cache_status",' '"upstream_addr":"$upstream_addr",' '"http_x_forwarded_for":"$http_x_forwarded_for",' '"http_referrer":"$http_referrer",' '"http_usr_agent":"$http_usr_agent"}'; access_log logs/access.log graylog2_json; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; vhost_traffic_status_zone; upstream blog_test{ server 120.48.31.148:8080 weight=10 max_fails=2 fail_timeout=30s; keepalive 30; } server { listen 82; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; vhost_traffic_status_filter_by_set_key $uri uri::$server_name; #这是用于显示uri的信息 location / { #root html; #index index.html index.htm; proxy_http_version 1.1; proxy_set_headerConnection ""; proxy_pass http://blog_test; } location / { vhost_traffic_status_display; vhost_traffic_status_display_format html; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
启动nginx
cd /opt/packages/openresty/nginx/sbin
./nginx
启动Nginx_vts_exporter
cd /opt/packages/openresty/nginx-vts-exporter-0.10.3.linux-386
nohup ./nginx-vts-exporter -nginx.scrape_timeout 10 -nginx.scrape_uri http://120.48.31.148:82/vts-status/format/json &
将数据配置到prometheus
添加prometheus.yml配置
- job_name: "nginx"
static_configs:
- targets: ['120.48.31.148:9913']
添加bashboard
ID:2949

浙公网安备 33010602011771号