Software /
code /
prosody-modules
Comparison
mod_log_slow_events/mod_log_slow_events.lua @ 1680:a9df1f7e273d
mod_log_slow_events: Log events that take a long time to process (including stanzas)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 28 Apr 2015 14:26:03 +0100 |
child | 1695:78b3b3add19c |
comparison
equal
deleted
inserted
replaced
1679:c77e9522dc66 | 1680:a9df1f7e273d |
---|---|
1 local time = require "socket".gettime; | |
2 | |
3 local max_seconds = module:get_option_number("log_slow_events_threshold", 0.5); | |
4 | |
5 module:wrap_event(false, function (handlers, event_name, event_data) | |
6 local start = time(); | |
7 local ret = handlers(event_name, event_data); | |
8 local duration = time()-start; | |
9 if duration > max_seconds then | |
10 local data = {}; | |
11 if event_data then | |
12 local function log_data(name, value) | |
13 if value then | |
14 table.insert(data, ("%s=%q"):format(name, value)); | |
15 return true; | |
16 end | |
17 end | |
18 local sess = event_data.origin or event_data.session; | |
19 if sess then | |
20 log_data("ip", sess.ip); | |
21 if not log_data("full_jid", sess.full_jid) then | |
22 log_data("username", sess.username); | |
23 end | |
24 log_data("type", sess.type); | |
25 log_data("host", sess.host); | |
26 end | |
27 local stanza = event_data.stanza; | |
28 if stanza then | |
29 log_data("stanza", tostring(stanza)); | |
30 end | |
31 end | |
32 module:log("warn", "Slow event '%s' took %0.2f: %s", event_name, duration, next(data) and table.concat(data, ", ") or "no recognised data"); | |
33 end | |
34 return ret; | |
35 end); |