# HG changeset patch # User Matthew Wild # Date 1430227563 -3600 # Node ID a9df1f7e273dfe612d206f2c671e81833b52f5e4 # Parent c77e9522dc66b89ad3b9999ca6ba3b392985c6f3 mod_log_slow_events: Log events that take a long time to process (including stanzas) diff -r c77e9522dc66 -r a9df1f7e273d mod_log_slow_events/mod_log_slow_events.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_log_slow_events/mod_log_slow_events.lua Tue Apr 28 14:26:03 2015 +0100 @@ -0,0 +1,35 @@ +local time = require "socket".gettime; + +local max_seconds = module:get_option_number("log_slow_events_threshold", 0.5); + +module:wrap_event(false, function (handlers, event_name, event_data) + local start = time(); + local ret = handlers(event_name, event_data); + local duration = time()-start; + if duration > max_seconds then + local data = {}; + if event_data then + local function log_data(name, value) + if value then + table.insert(data, ("%s=%q"):format(name, value)); + return true; + end + end + local sess = event_data.origin or event_data.session; + if sess then + log_data("ip", sess.ip); + if not log_data("full_jid", sess.full_jid) then + log_data("username", sess.username); + end + log_data("type", sess.type); + log_data("host", sess.host); + end + local stanza = event_data.stanza; + if stanza then + log_data("stanza", tostring(stanza)); + end + end + module:log("warn", "Slow event '%s' took %0.2f: %s", event_name, duration, next(data) and table.concat(data, ", ") or "no recognised data"); + end + return ret; +end);