Software /
code /
prosody
Comparison
core/statsmanager.lua @ 7524:b6f32bb3b584
statsmanager: If provider doesn't offer a get_stats method, still fire the stats-update event if stats_interval is specified (however stats-updated will not fire)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 27 Jul 2016 15:01:28 +0100 |
parent | 7522:ebf2e77ac8a7 |
child | 7533:4ef37ac69562 |
comparison
equal
deleted
inserted
replaced
7522:ebf2e77ac8a7 | 7524:b6f32bb3b584 |
---|---|
54 return f(name); | 54 return f(name); |
55 end | 55 end |
56 end | 56 end |
57 | 57 |
58 if stats_interval then | 58 if stats_interval then |
59 if stats.get_stats then | 59 log("debug", "Statistics collection is enabled every %d seconds", stats_interval); |
60 log("debug", "Statistics collection is enabled every %d seconds", stats_interval); | |
61 | 60 |
62 local mark_collection_start = measure("times", "stats.collection"); | 61 local mark_collection_start = measure("times", "stats.collection"); |
63 local mark_processing_start = measure("times", "stats.processing"); | 62 local mark_processing_start = measure("times", "stats.processing"); |
64 | 63 |
65 function collect() | 64 function collect() |
66 local mark_collection_done = mark_collection_start(); | 65 local mark_collection_done = mark_collection_start(); |
67 fire_event("stats-update"); | 66 fire_event("stats-update"); |
67 mark_collection_done(); | |
68 | |
69 if stats.get_stats then | |
68 changed_stats, stats_extra = {}, {}; | 70 changed_stats, stats_extra = {}, {}; |
69 for stat_name, getter in pairs(stats.get_stats()) do | 71 for stat_name, getter in pairs(stats.get_stats()) do |
70 local type, value, extra = getter(); | 72 local type, value, extra = getter(); |
71 local old_value = latest_stats[stat_name]; | 73 local old_value = latest_stats[stat_name]; |
72 latest_stats[stat_name] = value; | 74 latest_stats[stat_name] = value; |
75 end | 77 end |
76 if extra then | 78 if extra then |
77 stats_extra[stat_name] = extra; | 79 stats_extra[stat_name] = extra; |
78 end | 80 end |
79 end | 81 end |
80 mark_collection_done(); | |
81 local mark_processing_done = mark_processing_start(); | 82 local mark_processing_done = mark_processing_start(); |
82 fire_event("stats-updated", { stats = latest_stats, changed_stats = changed_stats, stats_extra = stats_extra }); | 83 fire_event("stats-updated", { stats = latest_stats, changed_stats = changed_stats, stats_extra = stats_extra }); |
83 mark_processing_done(); | 84 mark_processing_done(); |
84 return stats_interval; | |
85 end | 85 end |
86 timer.add_task(stats_interval, collect); | 86 return stats_interval; |
87 prosody.events.add_handler("server-started", function () collect() end, -1); | |
88 else | |
89 log("error", "statistics_interval specified, but the selected statistics_provider (%s) does not support statistics collection", stats_provider_config or "internal"); | |
90 end | 87 end |
88 timer.add_task(stats_interval, collect); | |
89 prosody.events.add_handler("server-started", function () collect() end, -1); | |
91 end | 90 end |
92 | 91 |
93 if not stats_interval and stats_provider == "util.statistics" then | 92 if not stats_interval and stats_provider == "util.statistics" then |
94 log("debug", "Statistics collection is disabled"); | 93 log("debug", "Statistics collection is disabled"); |
95 -- nop | 94 -- nop |