Prometheus 监控 NGINX
Prometheus 监控 NGINX
yum -y install pcre pcre-devel openssl openssl-devel gcc gcc-c++ -y
mkdir /usr/local/nginx/
wget https://github.com/vozlt/nginx-module-vts/archive/refs/tags/v0.2.1.tar.gz
tar fx v0.2.1.tar.gz -C /usr/local/nginx/wget -c http://nginx.org/download/nginx-1.21.1.tar.gz
tar fx nginx-1.21.1.tar.gz
cd nginx-1.21.1
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --add-module=/usr/local/nginx/nginx-module-vts-0.2.1
make && make install # 如果源码添加插件,不用 make install# vi /usr/local/nginx/conf/nginx.conf
http {
vhost_traffic_status_zone;
vhost_traffic_status_filter_by_host on;
server {
listen 80;
vhost_traffic_status off;
vhost_traffic_status_filter_by_set_key $uri uri::$server_name; #每个uri访问量
#vhost_traffic_status_filter_by_set_key $geoip_country_code country::$server_name; #不同国家/区域请求量
vhost_traffic_status_filter_by_set_key $status $server_name; #http code统计
vhost_traffic_status_filter_by_set_key $upstream_addr upstream::backend; #后端转发统计
vhost_traffic_status_filter_by_set_key $remote_port client::ports::$server_name; #请求端口统计
vhost_traffic_status_filter_by_set_key $remote_addr client::addr::$server_name; #请求IP统计
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
}
}下载部署
项目地址:https://github.com/hnlq715/nginx-vts-exporter/tree/v0.10.3
在需要被监控的Nginx服务器上,下载并上传Nginx exporter
wget https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.10.3/nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
tar -zxvf nginx-vts-exporter-0.10.3.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/ mv nginx-vts-exporter-0.10.3.linux-amd64 nginx-vts-exporter
启动服务
查看
输入IP+端口9913后面跟/metrics
配置Prometheus
Grafana 模板
2949
Last updated