1.首先本地需要安裝好prometheus已經nginx,注意nginx在編譯的時候需要帶with-http_stub_status_module模塊
#檢查nginx是否安裝nginx模塊
./nginx -V 2>&1 |grep -o with_http_stub_status_module
如果有輸出則證明安裝了,沒有的話就重新編譯一下nginx
2.修改nginx的配置文件
#新增location
location /nginx_status {
stub_status on;
}
#新增后重新加載nginx配置
/usr/local/nginx/sbin/nginx -s reload
3.安裝 並啟動nginx_prometheus插件
#安裝
tar -zxf nginx-prometheus-exporter_0.10.0_linux_amd64.tar.gz -C /usr/local/
#啟動
nohup ./nginx-prometheus-exporter -nginx.scrape-uri=http://127.0.0.1:80/nginx_status &
4.添加prometheus監聽配置文件
- targets: ["10.50.161.161:9113"] #9113是nginx_prometheus的服務端口
labels:
instance: "10.50.161.161"
env: "cdrb-nginx"
5.重啟prometheus