From 186f9ee295dbb4435e396e705674410194f28372 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 20 Jan 2015 11:29:38 +0000 Subject: certmanager: Make global variable access explicit --- core/certmanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/certmanager.lua b/core/certmanager.lua index 7ad7b034..b2c358fe 100644 --- a/core/certmanager.lua +++ b/core/certmanager.lua @@ -8,7 +8,7 @@ local configmanager = require "core.configmanager"; local log = require "util.logger".init("certmanager"); -local ssl = ssl; +local ssl = _G.ssl; local ssl_newcontext = ssl and ssl.newcontext; local new_config = require"util.sslconfig".new; -- cgit v1.2.3 From 3e62ff58706798955799740543394cc2d3e5e6e6 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 20 Jan 2015 11:30:07 +0000 Subject: hostmanager: Remove unused import of util.uuid --- core/hostmanager.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'core') diff --git a/core/hostmanager.lua b/core/hostmanager.lua index d10ecd30..7f9d1610 100644 --- a/core/hostmanager.lua +++ b/core/hostmanager.lua @@ -13,7 +13,6 @@ local disco_items = require "util.multitable".new(); local NULL = {}; local jid_split = require "util.jid".split; -local uuid_gen = require "util.uuid".generate; local log = require "util.logger".init("hostmanager"); -- cgit v1.2.3 From 322aa3c9c3b64c9df4d12f57b784961fceb23452 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 20 Jan 2015 11:31:04 +0000 Subject: portmanager: Remove unused import of pairs() --- core/portmanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/portmanager.lua b/core/portmanager.lua index bc2d4264..eab2412a 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -9,7 +9,7 @@ local set = require "util.set"; local table = table; local setmetatable, rawset, rawget = setmetatable, rawset, rawget; -local type, tonumber, tostring, ipairs, pairs = type, tonumber, tostring, ipairs, pairs; +local type, tonumber, tostring, ipairs = type, tonumber, tostring, ipairs; local prosody = prosody; local fire_event = prosody.events.fire_event; -- cgit v1.2.3 From 7ebf4fa4c28fb0cda37c4ce62100bb59f102d185 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 20 Jan 2015 11:31:30 +0000 Subject: rostermanager: Access bare_sessions through prosody.bare_sessions --- core/rostermanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/rostermanager.lua b/core/rostermanager.lua index 5266afb5..8c7612b4 100644 --- a/core/rostermanager.lua +++ b/core/rostermanager.lua @@ -15,7 +15,7 @@ local pairs = pairs; local tostring = tostring; local hosts = hosts; -local bare_sessions = bare_sessions; +local bare_sessions = prosody.bare_sessions; local datamanager = require "util.datamanager" local um_user_exists = require "core.usermanager".user_exists; -- cgit v1.2.3 From 79dfda0f225e20597c97f5b22c2547ecd5a2b6ec Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 20 Jan 2015 11:31:58 +0000 Subject: sessionmanager: Access bare_session and full_sessions through 'prosody' --- core/sessionmanager.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 65e5156c..09920b7d 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -10,8 +10,8 @@ local tostring, setmetatable = tostring, setmetatable; local pairs, next= pairs, next; local hosts = hosts; -local full_sessions = full_sessions; -local bare_sessions = bare_sessions; +local full_sessions = prosody.full_sessions; +local bare_sessions = prosody.bare_sessions; local logger = require "util.logger"; local log = logger.init("sessionmanager"); -- cgit v1.2.3 From fc6578a114ec5cae2a4c33f1dd3f4e8f39557701 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 20 Jan 2015 11:32:14 +0000 Subject: storagemanager: Remove unused import of error() --- core/storagemanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/storagemanager.lua b/core/storagemanager.lua index 5674ff32..ad31eb80 100644 --- a/core/storagemanager.lua +++ b/core/storagemanager.lua @@ -1,5 +1,5 @@ -local error, type, pairs = error, type, pairs; +local type, pairs = type, pairs; local setmetatable = setmetatable; local config = require "core.configmanager"; -- cgit v1.2.3 From a88d04d1c41f710bac967ddeb5558263ab73da53 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 20 Jan 2015 12:33:20 +0000 Subject: statsmanager, prosody: New core module and API for gathering statistics about the running server --- core/statsmanager.lua | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 core/statsmanager.lua (limited to 'core') diff --git a/core/statsmanager.lua b/core/statsmanager.lua new file mode 100644 index 00000000..83df6181 --- /dev/null +++ b/core/statsmanager.lua @@ -0,0 +1,75 @@ + +local stats = require "util.statistics".new(); +local config = require "core.configmanager"; +local log = require "util.logger".init("stats"); +local timer = require "util.timer"; +local fire_event = prosody.events.fire_event; + +local stats_config = config.get("*", "statistics_interval"); +local stats_interval = tonumber(stats_config); +if stats_config and not stats_interval then + log("error", "Invalid 'statistics_interval' setting, statistics will be disabled"); +end + +local measure, collect; +local latest_stats = {}; +local changed_stats = {}; +local stats_extra = {}; + +if stats_interval then + log("debug", "Statistics collection is enabled every %d seconds", stats_interval); + function measure(type, name) + local f = assert(stats[type], "unknown stat type: "..type); + return f(name); + end + + local mark_collection_start = measure("duration", "stats.collection_time"); + local mark_processing_start = measure("duration", "stats.processing_time"); + + function collect() + local mark_collection_done = mark_collection_start(); + changed_stats, stats_extra = {}, {}; + for name, getter in pairs(stats.get_stats()) do + local type, value, extra = getter(); + local stat_name = name..":"..type; + local old_value = latest_stats[stat_name]; + latest_stats[stat_name] = value; + if value ~= old_value then + changed_stats[stat_name] = value; + end + if extra then + print(stat_name, extra) + stats_extra[stat_name] = extra; + if type == "duration" then + local rate = extra.rate; + local rate_name = name..":rate"; + latest_stats[rate_name] = rate; + changed_stats[rate_name] = rate; + end + end + end + mark_collection_done(); + local mark_processing_done = mark_processing_start(); + fire_event("stats-updated", { stats = latest_stats, changed_stats = changed_stats, stats_extra = stats_extra }); + mark_processing_done(); + return stats_interval; + end + + timer.add_task(stats_interval, collect); +else + log("debug", "Statistics collection is disabled"); + -- nop + function measure() + return measure; + end + function collect() + end +end + +return { + measure = measure; + collect = collect; + get_stats = function () + return latest_stats, changed_stats, stats_extra; + end; +}; -- cgit v1.2.3 From 6790b2a0ba6b2b10ad327334296b48544e2c6553 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 21 Jan 2015 01:26:06 +0000 Subject: statsmanager, util.statistics: API changes, remove debugging --- core/statsmanager.lua | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'core') diff --git a/core/statsmanager.lua b/core/statsmanager.lua index 83df6181..62d217ef 100644 --- a/core/statsmanager.lua +++ b/core/statsmanager.lua @@ -23,29 +23,21 @@ if stats_interval then return f(name); end - local mark_collection_start = measure("duration", "stats.collection_time"); - local mark_processing_start = measure("duration", "stats.processing_time"); + local mark_collection_start = measure("times", "stats.collection"); + local mark_processing_start = measure("times", "stats.processing"); function collect() local mark_collection_done = mark_collection_start(); changed_stats, stats_extra = {}, {}; - for name, getter in pairs(stats.get_stats()) do + for stat_name, getter in pairs(stats.get_stats()) do local type, value, extra = getter(); - local stat_name = name..":"..type; local old_value = latest_stats[stat_name]; latest_stats[stat_name] = value; if value ~= old_value then changed_stats[stat_name] = value; end if extra then - print(stat_name, extra) stats_extra[stat_name] = extra; - if type == "duration" then - local rate = extra.rate; - local rate_name = name..":rate"; - latest_stats[rate_name] = rate; - changed_stats[rate_name] = rate; - end end end mark_collection_done(); -- cgit v1.2.3 From e0c0cffcc27601ec9e4dd3d6fcb556baa21f1e21 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 21 Jan 2015 01:28:12 +0000 Subject: moduleapi: Module API for statsmanager --- core/moduleapi.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'core') diff --git a/core/moduleapi.lua b/core/moduleapi.lua index c30a8936..e32c116a 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -14,6 +14,7 @@ local logger = require "util.logger"; local pluginloader = require "util.pluginloader"; local timer = require "util.timer"; local resolve_relative_path = require"util.paths".resolve_relative_path; +local measure = require "core.statsmanager".measure; local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat; local error, setmetatable, type = error, setmetatable, type; @@ -370,6 +371,10 @@ function api:open_store(name, type) return require"core.storagemanager".open(self.host, name or self.name, type); end +function api:measure(name, type) + return measure(type, "/"..self.host.."/mod_"..self.name.."/"..name); +end + function api.init(mm) modulemanager = mm; return api; -- cgit v1.2.3