diff --git a/doc/monitoring/plugins.rst b/doc/monitoring/plugins.rst index 8a7dcd6c..724f6708 100644 --- a/doc/monitoring/plugins.rst +++ b/doc/monitoring/plugins.rst @@ -260,17 +260,23 @@ Include the following in your main export function: .. code-block:: lua - -- Invoke all callbacks registered via `metrics.register_callback()` - metrics.invoke_callbacks() + local metrics = require('metrics') + local string_utils = require('metrics.string_utils') - -- Loop over collectors - for _, c in pairs(metrics.collectors()) do - ... + -- Collect up-to-date metrics with extended format. + local output = metrics.collect{invoke_callbacks = true, extended_format = true} - -- Loop over instant observations in the collector - for _, obs in pairs(c:collect()) do - -- Export observation `obs` - ... - end + for _, coll_obs in pairs(output) do + -- Serialize collector info like coll_obs.name, coll_obs.help, + -- coll_obs.kind and coll_obs.timestamp + + for group_name, obs_group in pairs(coll_obs.observations) do + -- Common way to build metric name. + local metric_name = string_utils.build_name(coll_obs.name, group_name) + + for _, obs in pairs(obs_group) do + -- Serialize observation info: obs.value and obs.label_pairs + end + end end