Current section
Files
Jump to
Current section
Files
src/themis@gauge.erl
-module(themis@gauge).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/themis/gauge.gleam").
-export([print/0, new/2, observe/3]).
-export_type([gauge_error/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type gauge_error() :: {metric_error, themis@internal@metric:metric_error()} |
{store_error, themis@internal@store:store_error()} |
{label_error, themis@internal@label:label_error()}.
-file("src/themis/gauge.gleam", 66).
-spec print() -> {ok, binary()} | {error, gauge_error()}.
print() ->
gleam@result:'try'(
begin
_pipe = themis@internal@store:match_metrics(<<"gauge"/utf8>>),
gleam@result:try_recover(
_pipe,
fun(E) -> {error, {store_error, E}} end
)
end,
fun(Metrics) ->
R = begin
gleam@list:try_fold(
Metrics,
[],
fun(Metrics_strings, _use1) ->
{Name_string, Description, _} = _use1,
gleam@result:'try'(
begin
_pipe@1 = themis@internal@metric:new_name(
Name_string,
[]
),
gleam@result:map_error(
_pipe@1,
fun(E@1) -> {metric_error, E@1} end
)
end,
fun(Name) ->
gleam@result:'try'(
begin
_pipe@2 = themis@internal@store:match_records(
Name
),
gleam@result:map_error(
_pipe@2,
fun(E@2) -> {store_error, E@2} end
)
end,
fun(Metric_records) ->
Help_string = <<<<<<<<"# HELP "/utf8,
Name_string/binary>>/binary,
" "/utf8>>/binary,
Description/binary>>/binary,
"\n"/utf8>>,
Type_string = <<<<<<"# TYPE "/utf8,
Name_string/binary>>/binary,
" "/utf8>>/binary,
"gauge\n"/utf8>>,
Records_strings = begin
_pipe@3 = maps:to_list(
Metric_records
),
gleam@list:map(
_pipe@3,
fun(Record) ->
{Labels, Value} = Record,
<<<<<<<<Name_string/binary,
(themis@internal@label:print(
Labels
))/binary>>/binary,
" "/utf8>>/binary,
(themis@number:print(
Value
))/binary>>/binary,
"\n"/utf8>>
end
)
end,
{ok,
[<<"\n"/utf8>>,
Type_string,
Help_string |
lists:append(
Records_strings,
Metrics_strings
)]}
end
)
end
)
end
)
end,
gleam@result:map(
R,
fun(Metrics_strings@1) -> _pipe@4 = Metrics_strings@1,
_pipe@5 = gleam_stdlib:identity(_pipe@4),
unicode:characters_to_binary(_pipe@5) end
)
end
).
-file("src/themis/gauge.gleam", 21).
?DOC(
" Registers a new gauge metric to the store.\n"
" Will return an error if the metric name is invalid\n"
" or already used by another metric.\n"
).
-spec new(binary(), binary()) -> {ok, nil} | {error, gauge_error()}.
new(Name, Description) ->
gleam@result:'try'(
begin
_pipe = themis@internal@metric:new_name(Name, [<<"gauge"/utf8>>]),
gleam@result:try_recover(
_pipe,
fun(E) -> {error, {metric_error, E}} end
)
end,
fun(Name@1) ->
Buckets = [],
gleam@result:try_recover(
themis@internal@store:new_metric(
Name@1,
Description,
<<"gauge"/utf8>>,
Buckets
),
fun(Store_error) -> {error, {store_error, Store_error}} end
)
end
).
-file("src/themis/gauge.gleam", 45).
?DOC(
" Sets a gauge value for the given metric name.\n"
" Will return an error if the name is invalid, not a registered metric\n"
" or not of the correct metric type.\n"
" Will return an error if any of the labels have an invalid key.\n"
" NaN, PosInf and NegInf values are valid but not recommended.\n"
).
-spec observe(
binary(),
gleam@dict:dict(binary(), binary()),
themis@number:number_()
) -> {ok, nil} | {error, gauge_error()}.
observe(Name, Labels, Value) ->
gleam@result:'try'(
begin
_pipe = themis@internal@metric:new_name(Name, [<<"gauge"/utf8>>]),
gleam@result:map_error(_pipe, fun(E) -> {metric_error, E} end)
end,
fun(Name@1) ->
gleam@result:'try'(
begin
_pipe@1 = themis@internal@store:find_metric(
Name@1,
<<"gauge"/utf8>>
),
gleam@result:map_error(
_pipe@1,
fun(E@1) -> {store_error, E@1} end
)
end,
fun(_) ->
gleam@result:'try'(
begin
_pipe@2 = themis@internal@label:from_dict(Labels),
gleam@result:map_error(
_pipe@2,
fun(E@2) -> {label_error, E@2} end
)
end,
fun(Labels@1) ->
gleam@result:map_error(
themis@internal@store:insert_record(
Name@1,
Labels@1,
Value
),
fun(Store_error) ->
{store_error, Store_error}
end
)
end
)
end
)
end
).