Changeset

11573:cb5748f94840

mod_csi_simple: convert to use new metric interface for flush reasons
author Jonas Schäfer <jonas@wielicki.name>
date Thu, 20 May 2021 14:00:54 +0200
parents 11572:e06dba5e99b9
children 11574:21217f7e82b9
files plugins/mod_csi_simple.lua
diffstat 1 files changed, 7 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_csi_simple.lua	Wed May 19 23:39:56 2021 +0200
+++ b/plugins/mod_csi_simple.lua	Thu May 20 14:00:54 2021 +0200
@@ -107,14 +107,11 @@
 
 local measure_buffer_hold = module:measure("buffer_hold", "times");
 
-local flush_reasons = setmetatable({}, {
-		__index = function (t, reason)
-			local m = module:measure("flush_reason."..reason:gsub("%W", "_"), "rate");
-			t[reason] = m;
-			return m;
-		end;
-	});
-
+local flush_reasons = module:metric(
+	"counter", "flushes", "",
+	"CSI queue flushes",
+	{ "reason" }
+);
 
 local function manage_buffer(stanza, session)
 	local ctr = session.csi_counter or 0;
@@ -124,7 +121,7 @@
 			session.csi_measure_buffer_hold();
 			session.csi_measure_buffer_hold = nil;
 		end
-		flush_reasons[why or "important"]();
+		flush_reasons:with_labels(why or "important"):add(1);
 		session.log("debug", "Flushing buffer (%s; queue size is %d)", why or "important", session.csi_counter);
 		session.conn:resume_writes();
 		session.state = "flushing";
@@ -139,7 +136,7 @@
 
 local function flush_buffer(data, session)
 	session.log("debug", "Flushing buffer (%s; queue size is %d)", "client activity", session.csi_counter);
-	flush_reasons["client activity"]();
+	flush_reasons:with_labels("client activity"):add(1);
 	if session.csi_measure_buffer_hold then
 		session.csi_measure_buffer_hold();
 		session.csi_measure_buffer_hold = nil;