Skip to content

Commit d170bda

Browse files
author
Christian Roessner
committed
Fix: Update Prometheus gauge handling in HTTP client plugins
Add increment calls at the beginning and change misplaced increment to decrement after HTTP requests in various plugins. This ensures proper tracking of active requests. Signed-off-by: Christian Roessner <[email protected]>
1 parent e97845b commit d170bda

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

server/lua-plugins.d/actions/haveibeenpwnd.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ function nauthilus_call_action(request)
9090
nauthilus_prometheus.create_gauge_vec(HCCR, "Measure the number of total concurrent HTTP client requests", { "service" })
9191
nauthilus_prometheus.create_histogram_vec(N .. "_duration_seconds", "HTTP request to the haveibeenpwnd network", { "http" })
9292

93+
nauthilus_prometheus.increment_gauge(HCCR, { service = N })
94+
9395
local timer = nauthilus_prometheus.start_histogram_timer(N .. "_duration_seconds", { http = "get" })
9496
local result, err = http.get("https://api.pwnedpasswords.com/range/" .. hash:sub(1, 5), {
9597
timeout = "10s",
@@ -100,7 +102,7 @@ function nauthilus_call_action(request)
100102
})
101103
nauthilus_prometheus.stop_timer(timer)
102104
nauthilus_util.if_error_raise(err)
103-
nauthilus_prometheus.increment_gauge(HCCR, { service = N })
105+
nauthilus_prometheus.decrement_gauge(HCCR, { service = N })
104106

105107
if result.status_code ~= 200 then
106108
nauthilus_util.if_error_raise(N .. "_status_code=" .. tostring(result.status_code))

server/lua-plugins.d/actions/telegram.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,16 @@ function nauthilus_call_action(request)
156156
nauthilus_prometheus.create_gauge_vec(HCCR, "Measure the number of total concurrent HTTP client requests", { "service" })
157157
nauthilus_prometheus.create_histogram_vec(N .. "_duration_seconds", "HTTP request to the telegram network", { "bot" })
158158

159+
nauthilus_prometheus.increment_gauge(HCCR, { service = N })
160+
159161
local timer = nauthilus_prometheus.start_histogram_timer(N .. "_duration_seconds", { bot = "send" })
160162
local _, err_bat = bot:sendMessage({
161163
chat_id = tonumber(os.getenv("TELEGRAM_CHAT_ID")),
162164
text = headline .. mustache:render(":\n\nSESSION {{session}}\nTS {{ts}}\nIP {{client_ip}}\nHOSTNAME {{hostname}}\nPROTOCOL {{proto}}\nDISPLAY_NAME {{display_name}}\nACCOUNT {{account}}\nUNIQUE ID {{unique_user_id}}\nUSERNAME {{username}}\nPWND INFO {{pwnd_info}}", values)
163165
})
164166
nauthilus_prometheus.stop_timer(timer)
165167
nauthilus_util.if_error_raise(err_bat)
166-
nauthilus_prometheus.increment_gauge(HCCR, { service = N })
168+
nauthilus_prometheus.decrement_gauge(HCCR, { service = N })
167169
end
168170

169171
rt.post_telegram = true

server/lua-plugins.d/features/blocklist.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ function nauthilus_call_feature(request)
5252
nauthilus_prometheus.create_gauge_vec(HCCR, "Measure the number of total concurrent HTTP client requests", { "service" })
5353
nauthilus_prometheus.create_histogram_vec(N .. "_duration_seconds", "HTTP request to the blocklist service", { "http" })
5454

55+
nauthilus_prometheus.increment_gauge(HCCR, { service = N })
56+
5557
local timer = nauthilus_prometheus.start_histogram_timer(N .. "_duration_seconds", { http = "post" })
5658
local result, request_err = http.post(os.getenv("BLOCKLIST_URL"), {
5759
timeout = "10s",
@@ -64,7 +66,7 @@ function nauthilus_call_feature(request)
6466
})
6567
nauthilus_prometheus.stop_timer(timer)
6668
nauthilus_util.if_error_raise(request_err)
67-
nauthilus_prometheus.increment_gauge(HCCR, { service = N })
69+
nauthilus_prometheus.decrement_gauge(HCCR, { service = N })
6870

6971
if result.status_code ~= 200 then
7072
nauthilus_util.if_error_raise(N .. "_status_code=" .. tostring(result.status_code))

server/lua-plugins.d/filters/geoip.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ function nauthilus_call_filter(request)
8585
nauthilus_prometheus.create_histogram_vec(N .. "_duration_seconds", "HTTP request to the geoip-policyd service", { "http" })
8686
nauthilus_prometheus.create_counter_vec(N .. "_count", "Count GeoIP countries", { "country", "status" })
8787

88+
nauthilus_prometheus.increment_gauge(HCCR, { service = N })
89+
8890
local timer = nauthilus_prometheus.start_histogram_timer(N .. "_duration_seconds", { http = "post" })
8991
local result, request_err = http.post(os.getenv("GEOIP_POLICY_URL"), {
9092
timeout = "10s",
@@ -97,7 +99,7 @@ function nauthilus_call_filter(request)
9799
})
98100
nauthilus_prometheus.stop_timer(timer)
99101
nauthilus_util.if_error_raise(request_err)
100-
nauthilus_prometheus.increment_gauge(HCCR, { service = N })
102+
nauthilus_prometheus.decrement_gauge(HCCR, { service = N })
101103

102104
if result.status_code ~= 202 then
103105
nauthilus_util.if_error_raise(N .. "_status_code=" .. tostring(result.code))

0 commit comments

Comments
 (0)