Current section
Files
Jump to
Current section
Files
src/themis@internal@metric@gauge.erl
-module(themis@internal@metric@gauge).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([observe/3, delete_record/2, print/2, new_name/1, new/2]).
-export_type([gauge/0, gauge_error/0]).
-type gauge() :: any().
-type gauge_error() :: {name_error, themis@internal@metric:metric_error()}.
-file("/git/Themis/src/themis/internal/metric/gauge.gleam", 25).
-spec observe(
themis@internal@metric:metric(gauge(), themis@number:number_(), nil),
themis@internal@label:label_set(),
themis@number:number_()
) -> themis@internal@metric:metric(gauge(), themis@number:number_(), nil).
observe(To, Labels, Value) ->
erlang:setelement(
3,
To,
gleam@dict:insert(erlang:element(3, To), Labels, Value)
).
-file("/git/Themis/src/themis/internal/metric/gauge.gleam", 33).
-spec delete_record(
themis@internal@metric:metric(gauge(), themis@number:number_(), nil),
themis@internal@label:label_set()
) -> themis@internal@metric:metric(gauge(), themis@number:number_(), nil).
delete_record(From, Labels) ->
erlang:setelement(
3,
From,
gleam@dict:delete(erlang:element(3, From), Labels)
).
-file("/git/Themis/src/themis/internal/metric/gauge.gleam", 40).
-spec print(
themis@internal@metric:metric(gauge(), themis@number:number_(), nil),
themis@internal@metric:metric_name()
) -> binary().
print(Metric, Name) ->
Name@1 = themis@internal@metric:name_to_string(Name),
Help = <<<<<<"# HELP "/utf8, Name@1/binary>>/binary, " "/utf8>>/binary,
(erlang:element(2, Metric))/binary>>,
Type_ = <<<<"# TYPE "/utf8, Name@1/binary>>/binary, " gauge"/utf8>>,
_pipe = (gleam@dict:fold(
erlang:element(3, Metric),
[<<<<<<Help/binary, "\n"/utf8>>/binary, Type_/binary>>/binary,
"\n"/utf8>>],
fun(Current, Labels, Value) ->
[<<<<<<<<Name@1/binary,
(themis@internal@label:print(Labels))/binary>>/binary,
" "/utf8>>/binary,
(themis@number:print(Value))/binary>>/binary,
"\n"/utf8>> |
Current]
end
)),
_pipe@1 = lists:reverse(_pipe),
_pipe@2 = gleam_stdlib:identity(_pipe@1),
unicode:characters_to_binary(_pipe@2).
-file("/git/Themis/src/themis/internal/metric/gauge.gleam", 61).
-spec new_name(binary()) -> {ok, themis@internal@metric:metric_name()} |
{error, themis@internal@metric:metric_error()}.
new_name(Name) ->
_pipe = Name,
themis@internal@metric:new_name(_pipe, [<<"gauge"/utf8>>]).
-file("/git/Themis/src/themis/internal/metric/gauge.gleam", 17).
-spec new(binary(), binary()) -> {ok,
{themis@internal@metric:metric_name(),
themis@internal@metric:metric(gauge(), themis@number:number_(), nil)}} |
{error, themis@internal@metric:metric_error()}.
new(Name, Description) ->
gleam@result:map(
new_name(Name),
fun(Name@1) -> {Name@1, {metric, Description, maps:new(), nil}} end
).