Mercurial > prosody-modules
comparison mod_prometheus/mod_prometheus.lua @ 6381:268220ce0625
mod_prometheus: Switch to prosody.util.time.now() to get the current time
| author | Link Mauve <linkmauve@linkmauve.fr> |
|---|---|
| date | Fri, 30 Jan 2026 15:04:25 +0100 |
| parents | c406e4bf7ee5 |
| children | 00511ded133d |
comparison
equal
deleted
inserted
replaced
| 6380:919f26901b51 | 6381:268220ce0625 |
|---|---|
| 9 module:set_global(); | 9 module:set_global(); |
| 10 | 10 |
| 11 local tostring = tostring; | 11 local tostring = tostring; |
| 12 local t_insert = table.insert; | 12 local t_insert = table.insert; |
| 13 local t_concat = table.concat; | 13 local t_concat = table.concat; |
| 14 local socket = require "socket"; | 14 local time_now = require "prosody.util.time".now; |
| 15 local statsman = require "core.statsmanager"; | 15 local statsman = require "core.statsmanager"; |
| 16 local get_stats = statsman.get_stats; | 16 local get_stats = statsman.get_stats; |
| 17 local get_metric_registry = statsman.get_metric_registry; | 17 local get_metric_registry = statsman.get_metric_registry; |
| 18 local collect = statsman.collect; | 18 local collect = statsman.collect; |
| 19 | 19 |
| 24 local function escape_name(name) | 24 local function escape_name(name) |
| 25 return name:gsub("/", "__"):gsub("[^A-Za-z0-9_]", "_"):gsub("^[^A-Za-z_]", "_%1"); | 25 return name:gsub("/", "__"):gsub("[^A-Za-z0-9_]", "_"):gsub("^[^A-Za-z_]", "_%1"); |
| 26 end | 26 end |
| 27 | 27 |
| 28 local function get_timestamp() | 28 local function get_timestamp() |
| 29 -- Using LuaSocket for that because os.time() only has second precision. | 29 -- In milliseconds. |
| 30 return math.floor(socket.gettime() * 1000); | 30 return math.floor(time_now() * 1000); |
| 31 end | 31 end |
| 32 | 32 |
| 33 local function repr_help(metric, docstring) | 33 local function repr_help(metric, docstring) |
| 34 docstring = docstring:gsub("\\", "\\\\"):gsub("\n", "\\n"); | 34 docstring = docstring:gsub("\\", "\\\\"):gsub("\n", "\\n"); |
| 35 return "# HELP "..escape_name(metric).." "..docstring.."\n"; | 35 return "# HELP "..escape_name(metric).." "..docstring.."\n"; |
