diff mod_statsd/mod_statsd.lua @ 1452:097c6af98d0a

Merge
author Kim Alvefur <zash@zash.se>
date Wed, 25 Jun 2014 20:46:35 +0200
parents d31ace5b1175
children 26c68a5f432f
line wrap: on
line diff
--- a/mod_statsd/mod_statsd.lua	Wed Jun 25 20:45:01 2014 +0200
+++ b/mod_statsd/mod_statsd.lua	Wed Jun 25 20:46:35 2014 +0200
@@ -15,22 +15,25 @@
 sock:setpeername(options.hostname or "127.0.0.1", options.port or 8125)
 
 -- Metrics are namespaced by ".", and seperated by newline
-function clean(s) return (s:gsub("[%.\n]", "_")) end
+function clean(s) return (s:gsub("[%.:\n]", "_")) end
 
 -- A 'safer' send function to expose
 function send(s) return sock:send(s) end
 
 -- prefix should end in "."
-local prefix = (options.prefix or ("prosody." .. clean(module.host))) .. "."
+local prefix = (options.prefix or "prosody") .. "."
+if not options.no_host then
+	prefix = prefix .. clean(module.host) .. "."
+end
 
 -- Track users as they bind/unbind
 -- count bare sessions every time, as we have no way to tell if it's a new bare session or not
 module:hook("resource-bind", function(event)
-	send(prefix.."bare_sessions:"..iterators.count(bare_sessions).."|g")
+	send(prefix.."bare_sessions:"..iterators.count(pairs(bare_sessions)).."|g")
 	send(prefix.."full_sessions:+1|g")
 end, 1)
 module:hook("resource-unbind", function(event)
-	send(prefix.."bare_sessions:"..iterators.count(bare_sessions).."|g")
+	send(prefix.."bare_sessions:"..iterators.count(pairs(bare_sessions)).."|g")
 	send(prefix.."full_sessions:-1|g")
 end, 1)
 
@@ -53,9 +56,20 @@
 	send(prefix..clean(room_node)..".broadcast-message:1|c")
 end)
 module:hook("muc-invite", function(event)
+	-- Total count
 	send(prefix.."invite:1|c")
 	local room_node = jid.split(event.room.jid)
+	-- Counts per room
 	send(prefix..clean(room_node)..".invite:1|c")
-	local to_node, to_host, to_resource = jid.split(event.stanza.attr.to)
-	send(prefix..clean(to_node)..".invites:1|c")
+	-- Counts per recipient
+	send(prefix..clean(event.stanza.attr.to)..".invited:1|c")
 end)
+module:hook("muc-decline", function(event)
+	-- Total count
+	send(prefix.."decline:1|c")
+	local room_node = jid.split(event.room.jid)
+	-- Counts per room
+	send(prefix..clean(room_node)..".decline:1|c")
+	-- Counts per sender
+	send(prefix..clean(event.incoming.attr.from)..".declined:1|c")
+end)