comparison 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
comparison
equal deleted inserted replaced
1446:843769eb40c3 1452:097c6af98d0a
13 -- Create UDP socket to statsd server 13 -- Create UDP socket to statsd server
14 local sock = socket.udp() 14 local sock = socket.udp()
15 sock:setpeername(options.hostname or "127.0.0.1", options.port or 8125) 15 sock:setpeername(options.hostname or "127.0.0.1", options.port or 8125)
16 16
17 -- Metrics are namespaced by ".", and seperated by newline 17 -- Metrics are namespaced by ".", and seperated by newline
18 function clean(s) return (s:gsub("[%.\n]", "_")) end 18 function clean(s) return (s:gsub("[%.:\n]", "_")) end
19 19
20 -- A 'safer' send function to expose 20 -- A 'safer' send function to expose
21 function send(s) return sock:send(s) end 21 function send(s) return sock:send(s) end
22 22
23 -- prefix should end in "." 23 -- prefix should end in "."
24 local prefix = (options.prefix or ("prosody." .. clean(module.host))) .. "." 24 local prefix = (options.prefix or "prosody") .. "."
25 if not options.no_host then
26 prefix = prefix .. clean(module.host) .. "."
27 end
25 28
26 -- Track users as they bind/unbind 29 -- Track users as they bind/unbind
27 -- count bare sessions every time, as we have no way to tell if it's a new bare session or not 30 -- count bare sessions every time, as we have no way to tell if it's a new bare session or not
28 module:hook("resource-bind", function(event) 31 module:hook("resource-bind", function(event)
29 send(prefix.."bare_sessions:"..iterators.count(bare_sessions).."|g") 32 send(prefix.."bare_sessions:"..iterators.count(pairs(bare_sessions)).."|g")
30 send(prefix.."full_sessions:+1|g") 33 send(prefix.."full_sessions:+1|g")
31 end, 1) 34 end, 1)
32 module:hook("resource-unbind", function(event) 35 module:hook("resource-unbind", function(event)
33 send(prefix.."bare_sessions:"..iterators.count(bare_sessions).."|g") 36 send(prefix.."bare_sessions:"..iterators.count(pairs(bare_sessions)).."|g")
34 send(prefix.."full_sessions:-1|g") 37 send(prefix.."full_sessions:-1|g")
35 end, 1) 38 end, 1)
36 39
37 -- Track MUC occupants as they join/leave 40 -- Track MUC occupants as they join/leave
38 module:hook("muc-occupant-joined", function(event) 41 module:hook("muc-occupant-joined", function(event)
51 send(prefix.."broadcast-message:1|c") 54 send(prefix.."broadcast-message:1|c")
52 local room_node = jid.split(event.room.jid) 55 local room_node = jid.split(event.room.jid)
53 send(prefix..clean(room_node)..".broadcast-message:1|c") 56 send(prefix..clean(room_node)..".broadcast-message:1|c")
54 end) 57 end)
55 module:hook("muc-invite", function(event) 58 module:hook("muc-invite", function(event)
59 -- Total count
56 send(prefix.."invite:1|c") 60 send(prefix.."invite:1|c")
57 local room_node = jid.split(event.room.jid) 61 local room_node = jid.split(event.room.jid)
62 -- Counts per room
58 send(prefix..clean(room_node)..".invite:1|c") 63 send(prefix..clean(room_node)..".invite:1|c")
59 local to_node, to_host, to_resource = jid.split(event.stanza.attr.to) 64 -- Counts per recipient
60 send(prefix..clean(to_node)..".invites:1|c") 65 send(prefix..clean(event.stanza.attr.to)..".invited:1|c")
61 end) 66 end)
67 module:hook("muc-decline", function(event)
68 -- Total count
69 send(prefix.."decline:1|c")
70 local room_node = jid.split(event.room.jid)
71 -- Counts per room
72 send(prefix..clean(room_node)..".decline:1|c")
73 -- Counts per sender
74 send(prefix..clean(event.incoming.attr.from)..".declined:1|c")
75 end)