instrument_metrics_exporter behaviour (instrument v1.0.0)

View Source

Metrics exporter manager for periodic metrics collection and export.

This module manages metrics exporters and handles periodic collection and export of metrics to registered backends.

Example Usage

  %% Register console exporter for metrics
  instrument_metrics_exporter:register(instrument_metrics_exporter_console:new()),
 
  %% Register OTLP exporter
  instrument_metrics_exporter:register(instrument_metrics_exporter_otlp:new(#{
      endpoint => "http://localhost:4318"
  })),
 
  %% Metrics are collected and exported periodically

Summary

Functions

Behaviour callbacks for metrics exporters

Collects all metrics.

Triggers an immediate export.

Forces a flush of metrics to all exporters.

Lists all registered exporters.

Registers a metrics exporter.

Shuts down all exporters.

Starts the metrics exporter manager.

Unregisters a metrics exporter.

Types

data_point/0

-type data_point() ::
          #{attributes := map(), value := number() | histogram_value(), timestamp := integer()}.

exporter/0

-type exporter() :: #{module := module(), config := map(), state := term()}.

histogram_value/0

-type histogram_value() ::
          #{count := integer(), sum := number(), buckets := [#{bound := number(), count := integer()}]}.

metric_data/0

-type metric_data() ::
          #{name := binary(),
            description := binary(),
            unit := binary(),
            type := counter | gauge | histogram,
            data_points := [data_point()]}.

Functions

behaviour_info(_)

Behaviour callbacks for metrics exporters

code_change(OldVsn, State, Extra)

collect()

-spec collect() -> [metric_data()].

Collects all metrics.

export()

-spec export() -> ok.

Triggers an immediate export.

flush()

-spec flush() -> ok.

Forces a flush of metrics to all exporters.

handle_call(Request, From, State)

handle_cast(Msg, State)

handle_info(Info, State)

init(_)

list()

-spec list() -> [module()].

Lists all registered exporters.

register(Exporter)

-spec register(#{module := module(), config => map()}) -> ok | {error, term()}.

Registers a metrics exporter.

shutdown()

-spec shutdown() -> ok.

Shuts down all exporters.

start_link()

-spec start_link() -> {ok, pid()} | {error, term()}.

Starts the metrics exporter manager.

terminate(Reason, State)

unregister(Module)

-spec unregister(module()) -> ok.

Unregisters a metrics exporter.