-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprometheus.conf
65 lines (53 loc) · 1.86 KB
/
prometheus.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
tcp_nodelay on;
lua_shared_dict prometheus_metrics 10M;
error_log stderr;
map $upstream_cache_status $cache_status {
default $upstream_cache_status;
'' "NONE";
}
init_worker_by_lua_block {
prometheus = require("prometheus").init("prometheus_metrics",{sync_interval=0.4})
metric_requests = prometheus:counter("nginx_http_requests_total","Number of HTTP requests", {"host", "status", "request_method", "cache_status"})
metric_latency = prometheus:histogram("nginx_http_request_duration_seconds","HTTP request latency", {"host"})
metric_connections = prometheus:gauge("nginx_http_connections","Number of HTTP connections", {"state"})
}
log_by_lua_block {
local excluded_uris = "^/(health|metrics|stub_status)$"
if not ngx.re.match(ngx.var.request_uri, excluded_uris) then
metric_requests:inc(1, {ngx.var.server_name, ngx.var.status, ngx.var.request_method, ngx.var.cache_status})
metric_latency:observe(tonumber(ngx.var.request_time),{ngx.var.server_name})
end
}
header_filter_by_lua_block {
ngx.header["server"] = nil
}
server {
listen 8080;
access_log off;
# Allow all RFC 1918 address blocks
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
deny all;
location /stub_status {
stub_status;
}
}
server {
listen 9145;
access_log off;
# Allow all RFC 1918 address blocks
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
deny all;
location /metrics {
content_by_lua_block {
metric_connections:set(ngx.var.connections_active, {"active"})
metric_connections:set(ngx.var.connections_reading, {"reading"})
metric_connections:set(ngx.var.connections_waiting, {"waiting"})
metric_connections:set(ngx.var.connections_writing, {"writing"})
prometheus:collect()
}
}
}