comparison mod_nodeinfo2/mod_nodeinfo2.lua @ 3707:3248295e1b16

mod_nodeinfo2: Retrieve message count from mod_measure_message_e2ee for localPosts and localComments.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 10 Oct 2019 17:59:32 +0200
parents 36b645e94325
children 0a800463bc08
comparison
equal deleted inserted replaced
3706:36b645e94325 3707:3248295e1b16
1 local json = require "util.json"; 1 local json = require "util.json";
2 local array = require "util.array"; 2 local array = require "util.array";
3 local get_stats = require "core.statsmanager".get_stats;
3 4
4 module:depends("http"); 5 module:depends("http");
6 module:depends("measure_message_e2ee");
5 7
6 local total_users = 0; 8 local total_users = 0;
7 for _ in require "core.usermanager".users(module.host) do -- TODO refresh at some interval? 9 for _ in require "core.usermanager".users(module.host) do -- TODO refresh at some interval?
8 total_users = total_users + 1; 10 total_users = total_users + 1;
9 end 11 end
10 12
11 module:provides("http", { 13 module:provides("http", {
12 default_path = "/.well-known/x-nodeinfo2"; 14 default_path = "/.well-known/x-nodeinfo2";
13 route = { 15 route = {
14 GET = function (event) 16 GET = function (event)
17 local stats, changed_only, extras = get_stats();
18 local message_count = nil;
19 for stat, value in pairs(stats) do
20 if stat == "/*/mod_measure_message_e2ee/message:rate" then
21 message_count = extras[stat].total;
22 end
23 end
24
15 event.response.headers.content_type = "application/json"; 25 event.response.headers.content_type = "application/json";
16 return json.encode({ 26 return json.encode({
17 version = "1.0"; 27 version = "1.0";
18 server = { 28 server = {
19 baseUrl = module:http_url("","/"); 29 baseUrl = module:http_url("","/");
47 -- TODO how would one calculate these? 57 -- TODO how would one calculate these?
48 -- activeHalfyear = 1; 58 -- activeHalfyear = 1;
49 -- activeMonth = 1; 59 -- activeMonth = 1;
50 -- activeWeek = 1; 60 -- activeWeek = 1;
51 }; 61 };
52 -- localPosts = 0; 62 localPosts = message_count;
53 -- localComments = 0; 63 localComments = message_count;
54 }; 64 };
55 }); 65 });
56 end; 66 end;
57 } 67 }
58 }); 68 });