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 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 call `callback` for each `MetricFamily` of this collector;
- `collect_metrics(name, data)` - called by `MetricFamily` constructor.
Should return Metric list for each MetricFamily identified by `name`.
`data` is a term associated with MetricFamily by collect_mf.
- `deregister_cleanup(registry)` - called when collector unregistered by
`registry`. If collector is stateful you can put cleanup code here.
- Example (simplified `:prometheus_vm_memory_collector`):
+ Example (simplified [`:prometheus_vm_memory_collector`](https://github.com/deadtrickster/prometheus.erl/blob/master/doc/prometheus_vm_memory_collector.md)):
```
- 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