Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
i've just started to work with prometheus-nginxlog-exporter
https://github.com/martin-helmich/prometheus-nginxlog-exporter
my nginx.conf has only one change
log_format custom '$remote_addr - $remote_user [$time_local] $request_method "$request_uri " $status';
access_log /var/log/nginx/access.log custom;
I have two simple site
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"
if check prometheus metrics
curl http://localhost:4040/metrics
output is
# 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
Why is method empty? How to configure it correct?
How to get statistics about requests to location e.g. how many requests to "/", "/api"
as mentions in documentations
https://github.com/martin-helmich/prometheus-nginxlog-exporter#custom-labels-pass-through
we should you relabel
my working config is
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"
relabel "method" { from = "request_method" }
relabel "request_uri" { from = "request_uri" }
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"
relabel "method" { from = "request_method" }
relabel "request_uri" { from = "request_uri" }
labels {
app = "test"
in metrics we can see somthing like this
allnginx_http_response_count_total{app="prod", instance="localhost:4040", job="nginx", method="DELETE", request_uri="/api/dashboards/uid/GLEY_3g7k", status="200", vhost="nginx"}
allnginx_http_response_count_total{app="prod", instance="localhost:4040", job="nginx", method="GET", request_uri="/", status="302", vhost="nginx"}
allnginx_http_response_count_total{app="prod", instance="localhost:4040", job="nginx", method="GET", request_uri="/", status="401", vhost="nginx"}
allnginx_http_response_count_total{app="prod", instance="localhost:4040", job="nginx", method="GET", request_uri="/api/alerts/states-for-dashboard?dashboardId=2", status="200", vhost="nginx"}
allnginx_http_response_count_total{app="prod", instance="localhost:4040", job="nginx", method="GET", request_uri="/api/alerts/states-for-dashboard?dashboardId=3", status="200", vhost="nginx"}
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.