mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 19:01:54 +00:00
38 lines
1.3 KiB
Plaintext
38 lines
1.3 KiB
Plaintext
# Central nginx metrics endpoint — scraped ONCE by Prometheus from this domain.
|
|
# Exposes HTTP request counts, latency histograms, bytes in/out, TLS handshakes,
|
|
# and stack_up gauge for all vhosts via lua-resty-prometheus shared memory.
|
|
# All metrics carry 'host' and 'app' labels so one scrape covers all 70+ apps.
|
|
# NOT included in other app vhosts — only the prometheus domain exposes this.
|
|
location = /metricz {
|
|
access_log off;
|
|
content_by_lua_block {
|
|
-- Mirror the /healthz/live logic: a container is "up" only when BOTH
|
|
-- Docker says it is healthy AND the HTTP backend is reachable.
|
|
-- Stack is up only when both Docker health and HTTP probe pass.
|
|
local up = 1
|
|
|
|
-- Step 1: Docker HEALTHCHECK state (same source as /healthz/live).
|
|
local cname = ngx.var.container_name
|
|
if cname and cname ~= "" then
|
|
local dict = ngx.shared.health_containers
|
|
if dict then
|
|
local status = dict:get(cname)
|
|
if status == "down" then
|
|
up = 0
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Step 2: HTTP reachability.
|
|
if up == 1 then
|
|
local res = ngx.location.capture("/_live_probe")
|
|
if not res or res.status >= 500 then
|
|
up = 0
|
|
end
|
|
end
|
|
|
|
metric_stack_up:set(up, {ngx.var.host, ngx.var.app_id})
|
|
prometheus:collect()
|
|
}
|
|
}
|