Comparison

mod_nodeinfo2/mod_nodeinfo2.lua @ 3710:7f5ce667d93e

mod_nodeinfo2: Store and restore the total message count.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 10 Oct 2019 21:07:45 +0200
parent 3708:0a800463bc08
child 3781:263f5f1ee71f
comparison
equal deleted inserted replaced
3709:d3d27f2558fb 3710:7f5ce667d93e
35 half_year_users = nil; 35 half_year_users = nil;
36 month_users = nil; 36 month_users = nil;
37 week_users = nil; 37 week_users = nil;
38 end 38 end
39 39
40 local message_count_store = module:open_store("message_count");
41 local message_count = message_count_store:get("message_count");
42
40 module:provides("http", { 43 module:provides("http", {
41 default_path = "/.well-known/x-nodeinfo2"; 44 default_path = "/.well-known/x-nodeinfo2";
42 route = { 45 route = {
43 GET = function (event) 46 GET = function (event)
44 local stats, changed_only, extras = get_stats(); 47 local stats, changed_only, extras = get_stats();
45 local message_count = nil;
46 for stat, _ in pairs(stats) do 48 for stat, _ in pairs(stats) do
47 if stat == "/*/mod_measure_message_e2ee/message:rate" then 49 if stat == "/*/mod_measure_message_e2ee/message:rate" then
48 message_count = extras[stat].total; 50 local new_message_count = extras[stat].total;
51 if new_message_count ~= message_count then
52 message_count = new_message_count;
53 message_count_store:set("message_count", message_count);
54 end
49 end 55 end
50 end 56 end
51 57
52 event.response.headers.content_type = "application/json"; 58 event.response.headers.content_type = "application/json";
53 return json.encode({ 59 return json.encode({