View Source prometheus_model_helpers (prometheus v4.13.0)

Helpers for working with Prometheus data model. For advanced users.

Probably will be used with prometheus_collector.

Summary

Functions

Creates boolean metric with Labels and Value.

Equivalent to lists:map(fun boolean_metric/1, Values).

Creates counter metric with Labels and Value.

Equivalent to lists:map(fun counter_metric/1, Values).

Create Metric Family of Type, Name and Help.

Create Metric Family of Type, Name and Help.

Creates gauge metric with Labels and Value.

Equivalent to lists:map(fun gauge_metrics/1, Values).

Creates histogram metric with Labels, Buckets, Count and Sum.

Equivalent to lists:map(fun histogram_metric/1, Specs).

Creates prometheus_model:LabelPair'()' from {Name, Value} tuple.

Label pairs sequentially.

If Name is a list, looks for atoms and converts them to binaries. Why iolists do not support atoms?

Creates summary metric with Labels, Count and Sum.

Equivalent to lists:map(fun summary_metric/1, Specs).

Creates untyped metric with Labels and Value.

Equivalent to lists:map(fun untyped_metric/1, Values).

Functions

boolean_metric(Boolean)

-spec boolean_metric(Boolean) -> prometheus_model:'Metric'() when Boolean :: prometheus:pbool().

Equivalent to boolean_metric(Labels, Value).

boolean_metric(Labels, Value)

-spec boolean_metric(Labels, Value) -> prometheus_model:'Metric'()
                        when Labels :: prometheus:labels(), Value :: prometheus:prometheus_boolean().

Creates boolean metric with Labels and Value.

boolean_metrics(Values)

-spec boolean_metrics(Values) -> [prometheus_model:'Metric'()] when Values :: [prometheus:pbool()].

Equivalent to lists:map(fun boolean_metric/1, Values).

counter_metric(Spec)

-spec counter_metric(Spec) -> prometheus_model:'Metric'() when Spec :: prometheus:counter().

Equivalent to counter_metric(Labels, Value).

counter_metric(Labels, Value)

-spec counter_metric(Labels, Value) -> prometheus_model:'Metric'()
                        when Labels :: prometheus:labels(), Value :: prometheus:value().

Creates counter metric with Labels and Value.

counter_metrics(Specs)

-spec counter_metrics(Specs) -> [prometheus_model:'Metric'()] when Specs :: [prometheus:counter()].

Equivalent to lists:map(fun counter_metric/1, Values).

create_mf(Name, Help, Type, Metrics)

-spec create_mf(Name, Help, Type, Metrics) -> MetricFamily
                   when
                       Name :: prometheus_metric:name(),
                       Help :: prometheus_metric:help(),
                       Type :: atom(),
                       Metrics ::
                           [prometheus_model:'Metric'()] |
                           prometheus_model:'Metric'() |
                           prometheus:metrics(),
                       MetricFamily :: prometheus_model:'MetricFamily'().

Create Metric Family of Type, Name and Help.

Collector:collect_metrics/2 callback will be called and expected to return individual metrics list.

create_mf(Name, Help, Type, Collector, CollectorData)

-spec create_mf(Name, Help, Type, Collector, CollectorData) -> MetricFamily
                   when
                       Name :: prometheus_metric:name(),
                       Help :: prometheus_metric:help(),
                       Type :: atom(),
                       Collector :: prometheus_collector:collector(),
                       CollectorData :: prometheus_collector:data(),
                       MetricFamily :: prometheus_model:'MetricFamily'().

Create Metric Family of Type, Name and Help.

Collector:collect_metrics/2 callback will be called and expected to return individual metrics list.

gauge_metric(Gauge)

-spec gauge_metric(Gauge) -> prometheus_model:'Metric'() when Gauge :: prometheus:gauge().

Equivalent to gauge_metric(Labels, Value).

gauge_metric(Labels, Value)

-spec gauge_metric(Labels, Value) -> prometheus_model:'Metric'()
                      when Labels :: prometheus:labels(), Value :: prometheus:value().

Creates gauge metric with Labels and Value.

gauge_metrics(Values)

-spec gauge_metrics(Values) -> [prometheus_model:'Metric'()] when Values :: [prometheus:gauge()].

Equivalent to lists:map(fun gauge_metrics/1, Values).

histogram_metric(Histogram)

-spec histogram_metric(Histogram) -> prometheus_model:'Metric'()
                          when Histogram :: prometheus:histogram().

Equivalent to histogram_metric(Labels, Buckets, Count, Sum).

histogram_metric(Buckets, Count, Sum)

-spec histogram_metric(Buckets, Count, Sum) -> prometheus_model:'Metric'()
                          when
                              Buckets :: prometheus:buckets(),
                              Count :: non_neg_integer(),
                              Sum :: prometheus:value().

Equivalent to histogram_metric([], Buckets, Count, Sum).

histogram_metric(Labels, Buckets, Count, Sum)

-spec histogram_metric(Labels, Buckets, Count, Sum) -> Metric
                          when
                              Labels :: prometheus:labels(),
                              Buckets :: [{Bound, Count}],
                              Bound :: prometheus_buckets:bucket_bound(),
                              Count :: non_neg_integer(),
                              Sum :: prometheus:value(),
                              Metric :: prometheus_model:'Metric'().

Creates histogram metric with Labels, Buckets, Count and Sum.

histogram_metrics(Specs)

-spec histogram_metrics(Specs) -> [prometheus_model:'Metric'()] when Specs :: [prometheus:histogram()].

Equivalent to lists:map(fun histogram_metric/1, Specs).

label_pair/1

-spec label_pair(prometheus:label()) -> prometheus_model:'LabelPair'().

Creates prometheus_model:LabelPair'()' from {Name, Value} tuple.

label_pairs(Labels)

-spec label_pairs(Labels) -> [prometheus_model:'LabelPair'()] when Labels :: prometheus:labels().

Label pairs sequentially.

NB is_binary' clause here is for a special optimization for text format only: client code can pre-generate final labels string, e.g. when it knows when character escaping is not needed. This avoids direct performance cost of character escaping, and also reduces garabage collection pressure, as intermediate lists of tuples/records are not created at all. This optimization is used by RabbitMQ prometheus plugin (which callscreate_mf/5', and it ends here).

WARNING Works only for text format, protobuf format export will fail with an error.

metric_name(Name)

-spec metric_name(Name) -> binary()
                     when Name :: atom() | binary() | [char() | iolist() | binary() | atom()].

If Name is a list, looks for atoms and converts them to binaries. Why iolists do not support atoms?

summary_metric(Summary)

-spec summary_metric(Summary) -> prometheus_model:'Metric'() when Summary :: prometheus:summary().

Equivalent to summary_metric(Labels, Count, Sum).

summary_metric(Count, Sum)

-spec summary_metric(Count, Sum) -> prometheus_model:'Metric'()
                        when Count :: non_neg_integer(), Sum :: prometheus:value().

Equivalent to summary_metric([], Count, Sum).

summary_metric(Labels, Count, Sum)

-spec summary_metric(Labels, Count, Sum) -> prometheus_model:'Metric'()
                        when
                            Labels :: prometheus:labels(),
                            Count :: non_neg_integer(),
                            Sum :: prometheus:value().

Equivalent to summary_metric([], Count, Sum, []).

summary_metric(Labels, Count, Sum, Quantiles)

-spec summary_metric(Labels, Count, Sum, Quantiles) -> prometheus_model:'Metric'()
                        when
                            Labels :: prometheus:labels(),
                            Count :: non_neg_integer(),
                            Sum :: prometheus:value(),
                            Quantiles :: list().

Creates summary metric with Labels, Count and Sum.

summary_metrics(Specs)

-spec summary_metrics(Specs) -> [prometheus_model:'Metric'()] when Specs :: [prometheus:summary()].

Equivalent to lists:map(fun summary_metric/1, Specs).

untyped_metric(Untyped)

-spec untyped_metric(Untyped) -> prometheus_model:'Metric'() when Untyped :: prometheus:untyped().

Equivalent to untyped_metric(Labels, Value).

untyped_metric(Labels, Value)

-spec untyped_metric(Labels, Value) -> prometheus_model:'Metric'()
                        when Labels :: prometheus:labels(), Value :: prometheus:value().

Creates untyped metric with Labels and Value.

untyped_metrics(Values)

-spec untyped_metrics(Values) -> [prometheus_model:'Metric'()] when Values :: [prometheus:untyped()].

Equivalent to lists:map(fun untyped_metric/1, Values).