Prometheus.ex v1.0.0-alpha10 Prometheus.Collector
A collector for a set of metrics.
Normal users should use Prometheus.Metric.Gauge
, Prometheus.Metric.Counter
, Prometheus.Metric.Summary
and Prometheus.Metric.Histogram
.
Implementing :prometheus_collector
behaviour is for advanced uses such as proxying metrics from another monitoring system.
It is it the responsibility of the implementer to ensure produced metrics are valid.
You will be working with Prometheus data model directly (see Prometheus.Model
).
Callbacks:
collect_mf(registry, callback)
- called by exporters and formats. Should callcallback
for eachMetricFamily
of this collector;collect_metrics(name, data)
- called byMetricFamily
constructor. Should return Metric list for each MetricFamily identified byname
.data
is a term associated with MetricFamily by collect_mf.deregister_cleanup(registry)
- called when collector unregistered byregistry
. If collector is stateful you can put cleanup code here.
Example (simplified :prometheus_vm_memory_collector
):
defmodule Prometheus.VMMemoryCollector do
use Prometheus.Collector
def collect_mf(_registry, callback) do
memory = :erlang.memory()
callback.(create_gauge(
:erlang_vm_bytes_total,
'''
The total amount of memory currently allocated.
This is the same as the sum of the memory size
for processes and system."
''',
memory))
:ok
end
def collect_metrics(:erlang_vm_bytes_total, memory) do
Prometheus.Model.gauge_metrics(
[
{[kind: :system], memory.system},
{[kind: :processes], memory.processes}
])
end
defp create_gauge(name, help, data) do
Prometheus.Model.create_mf(name, help, :gauge, __MODULE__, data)
end
end
Summary
Macros
Calls callback
for each MetricFamily of this collector