comparison mod_log_slow_events/mod_log_slow_events.lua @ 2296:8c0bf3151e37

mod_log_slow_events: Add metric to monitor number of slow events
author Matthew Wild <mwild1@gmail.com>
date Wed, 31 Aug 2016 11:29:26 +0100
parents efc1d674eac0
children 5e74028557dc
comparison
equal deleted inserted replaced
2295:2d90a2b8482e 2296:8c0bf3151e37
1 local time = require "socket".gettime; 1 local time = require "socket".gettime;
2 local base64_decode = require "util.encodings".base64.decode; 2 local base64_decode = require "util.encodings".base64.decode;
3 3
4 local max_seconds = module:get_option_number("log_slow_events_threshold", 0.5); 4 local max_seconds = module:get_option_number("log_slow_events_threshold", 0.5);
5
6 local measure_slow_event = module:measure("slow_events", "rate");
5 7
6 function event_wrapper(handlers, event_name, event_data) 8 function event_wrapper(handlers, event_name, event_data)
7 local start = time(); 9 local start = time();
8 local ret = handlers(event_name, event_data); 10 local ret = handlers(event_name, event_data);
9 local duration = time()-start; 11 local duration = time()-start;
42 end 44 end
43 end 45 end
44 end 46 end
45 end 47 end
46 end 48 end
49 measure_slow_event();
47 module:log("warn", "Slow event '%s' took %0.2fs: %s", event_name, duration, next(data) and table.concat(data, ", ") or "no recognised data"); 50 module:log("warn", "Slow event '%s' took %0.2fs: %s", event_name, duration, next(data) and table.concat(data, ", ") or "no recognised data");
48 end 51 end
49 return ret; 52 return ret;
50 end 53 end
51 54