Packages
prometheus
6.1.1
6.1.3
6.1.2
6.1.1
6.1.0
6.0.3
6.0.2
6.0.1
6.0.0
5.1.1
5.1.0
5.0.0
4.13.0
retired
4.12.0
4.11.0
4.10.0
4.9.1
4.9.0
4.8.2
4.8.1
4.8.0
4.6.0
4.5.0
4.4.1
4.4.0
4.3.0
4.2.2
4.2.0
4.1.0
4.0.1
4.0.0
3.5.1
3.5.0
3.4.6
3.4.5
3.4.4
3.4.3
3.4.2
3.4.1
3.4.0
3.3.2
3.3.1
3.3.0
3.2.3
3.2.2
3.2.1
3.1.1
3.1.0
3.0.1
3.0.0
3.0.0-rc1
3.0.0-alpha9
3.0.0-alpha8
3.0.0-alpha7
3.0.0-alpha6
3.0.0-alpha5
3.0.0-alpha4
3.0.0-alpha3
3.0.0-alpha2
3.0.0-alpha10
3.0.0-alpha1
2.2.0
2.1.0
2.0.0
1.7.0
1.6.0
1.5.0
1.0.2
1.0.1
1.0.0
0.2.0
0.1.3
0.1.2
0.1.1
0.1.0
Prometheus.io client in Erlang
Current section
Files
Jump to
Current section
Files
src/contrib/prometheus_http.erl
-module(prometheus_http).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC("HTTP instrumentation helpers").
-export([microseconds_duration_buckets/0, status_class/1]).
-export_type([status_code/0, status_class/0]).
-type status_code() :: pos_integer().
-type status_class() :: prometheus:label_value().
?DOC("""
Returns default microseconds buckets for measuring http requests duration.
```erlang
1> prometheus_http:microseconds_duration_buckets().
[10, 25, 50, 100, 250, 500,
1000, 2500, 5000, 10000, 25000, 50000, 100000, 250000, 500000,
1000000, 2500000, 5000000, 10000000]
```
""").
-spec microseconds_duration_buckets() -> prometheus_buckets:buckets().
microseconds_duration_buckets() ->
[
10,
25,
50,
100,
250,
500,
1000,
2500,
5000,
10000,
25000,
50000,
100000,
250000,
500000,
1000000,
2500000,
5000000,
10000000
].
?DOC("""
Returns status class for the http status code `SCode`.
```erlang
2> prometheus_http:status_class(202).
\"success\"
```
Raises `{invalid_value_error, SCode, Message}` error if `SCode` isn't a positive integer.
""").
-spec status_class(SCode) -> StatusClass when
SCode :: status_code(),
StatusClass :: status_class().
status_class(SCode) when
is_integer(SCode) andalso
SCode > 0 andalso
SCode < 100
->
"unknown";
status_class(SCode) when
is_integer(SCode) andalso
SCode > 0 andalso
SCode < 200
->
"informational";
status_class(SCode) when
is_integer(SCode) andalso
SCode > 0 andalso
SCode < 300
->
"success";
status_class(SCode) when
is_integer(SCode) andalso
SCode > 0 andalso
SCode < 400
->
"redirection";
status_class(SCode) when
is_integer(SCode) andalso
SCode > 0 andalso
SCode < 500
->
"client-error";
status_class(SCode) when
is_integer(SCode) andalso
SCode > 0 andalso
SCode < 600
->
"server-error";
status_class(SCode) when
is_integer(SCode) andalso
SCode > 0 andalso
SCode >= 600
->
"unknown";
status_class(C) ->
erlang:error({invalid_value, C, "status code must be a positive integer"}).