mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-05 13:37:34 +08:00
fix(prometheus): avoid negative latency caused by inconsistent Nginx metrics (#5150)
Co-authored-by: 罗泽轩 <spacewanderlzx@gmail.com>
This commit is contained in:
parent
d413d77a9e
commit
58d60ca2a2
@ -153,6 +153,14 @@ function _M.log(conf, ctx)
|
||||
metrics.latency:observe(upstream_latency,
|
||||
gen_arr("upstream", route_id, service_id, consumer_name, balancer_ip))
|
||||
apisix_latency = apisix_latency - upstream_latency
|
||||
|
||||
-- The latency might be negative, as Nginx uses different time measurements in
|
||||
-- different metrics.
|
||||
-- See https://github.com/apache/apisix/issues/5146#issuecomment-928919399
|
||||
if apisix_latency < 0 then
|
||||
apisix_latency = 0
|
||||
end
|
||||
|
||||
end
|
||||
metrics.latency:observe(apisix_latency,
|
||||
gen_arr("apisix", route_id, service_id, consumer_name, balancer_ip))
|
||||
@ -165,9 +173,10 @@ function _M.log(conf, ctx)
|
||||
end
|
||||
|
||||
|
||||
local ngx_status_items = {"active", "accepted", "handled", "total",
|
||||
"reading", "writing", "waiting"}
|
||||
local label_values = {}
|
||||
local ngx_status_items = {"active", "accepted", "handled", "total",
|
||||
"reading", "writing", "waiting"}
|
||||
local label_values = {}
|
||||
|
||||
local function nginx_status()
|
||||
local res = ngx_capture("/apisix/nginx_status")
|
||||
if not res or res.status ~= 200 then
|
||||
|
Loading…
Reference in New Issue
Block a user