View Source CozyTelemetry.Spec behaviour (cozy_telemetry v0.5.1)
A behaviour for declaring spec.
Any module that wants to exposing metrics or periodic measurements should implement this behaviour.
defmodule MyApp.Cache.TelemetrySpec do
use CozyTelemetry.Spec
@impl true
def metrics(meta) do
[
summary("cache.duration",
unit: {:native, :second},
tags: [:type, :key]
),
# ...
]
end
@impl true
def measurements(meta) do
[
{__MODULE__, :dispatch_stats, []},
# ...
]
end
end
Then, the declared metrics in above module can be loaded with following configuration:
config :my_app, CozyTelemetry,
meta: [],
specs: [
MyApp.Cache.TelemetrySpec
],
# ...
Summary
Functions
Load measurements.
Loads the measurements from given module.
Same as load_measurements_from_module/2
but raises if the module cannot be loaded.
Load metrics.
Loads the metrics from given module.
Same as load_metrics_from_module/2
but raises if the module cannot be loaded.
Types
@type meta() :: keyword()
Callbacks
@callback measurements(meta()) :: [:telemetry_poller.measurement()]
Declares measurements.
@callback metrics(meta()) :: [Telemetry.Metrics.t()]
Declares metrics.
Functions
Load measurements.
Loads the measurements from given module.
Same as load_measurements_from_module/2
but raises if the module cannot be loaded.
Load metrics.
Loads the metrics from given module.
Same as load_metrics_from_module/2
but raises if the module cannot be loaded.