【发布时间】:2021-09-06 17:24:11
【问题描述】:
我刚刚开始使用 prometheus-nginxlog-exporter
https://github.com/martin-helmich/prometheus-nginxlog-exporter
我的 nginx.conf 只有一处改动
log_format custom '$remote_addr - $remote_user [$time_local] $request_method "$request_uri " $status';
access_log /var/log/nginx/access.log custom;
我有两个简单的网站
server {
listen 82;
server_name localhost;
access_log /var/log/nginx/access_default_site.log custom;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
upstream prom {
server 127.0.0.1:9090;
keepalive 15;
}
server {
listen 80;
location / {
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/htpasswd.prom;
proxy_pass http://prom;
proxy_redirect off;
proxy_buffering off;
proxy_http_version 1.1;
proxy_set_header Connection "Keep-Alive";
proxy_set_header Proxy-Connection "Keep-Alive";
}
}
etc/prometheus-nginxlog-exporter.hcl
listen {
port = 4040
}
namespace "nginx" {
source = {
files = [
"/var/log/nginx/access.log"
]
}
metrics_override = { prefix = "allnginx" }
namespace_label = "vhost"
format = "$remote_addr - $remote_user [$time_local] $request_method \"$request_uri\" $status"
labels {
app = "prod"
}
}
namespace "default" {
source = {
files = [
"/var/log/nginx/access_default_site.log"
]
}
metrics_override = { prefix = "allnginx" }
namespace_label = "vhost"
format = "$remote_addr - $remote_user [$time_local] $request_method \"$request_uri\" $status"
labels {
app = "test"
}
}
如果检查 prometheus 指标curl http://localhost:4040/metrics
输出是
# HELP allnginx_http_response_count_total Amount of processed HTTP requests
# TYPE allnginx_http_response_count_total counter
allnginx_http_response_count_total{app="prod",method="",status="200",vhost="nginx"} 28
allnginx_http_response_count_total{app="prod",method="",status="302",vhost="nginx"} 7
allnginx_http_response_count_total{app="prod",method="",status="400",vhost="nginx"} 30
# HELP allnginx_parse_errors_total Total number of log file lines that could not be parsed
# TYPE allnginx_parse_errors_total counter
allnginx_parse_errors_total{vhost="default"} 0
allnginx_parse_errors_total{vhost="nginx"} 0
allnginx_http_response_count_total{app="prod",method="",status="200",vhost="nginx"} 28
为什么方法是空的?如何正确配置?
如何获取有关位置请求的统计信息,例如对“/”、“/api”有多少请求
【问题讨论】:
标签: nginx prometheus