chore(HTTP): prometheus or json format by accept header
This commit is contained in:
parent
25c4f4aa4e
commit
f6c61189c4
|
@ -52,7 +52,13 @@ prometheus_data_api() ->
|
||||||
Metadata = #{
|
Metadata = #{
|
||||||
get => #{
|
get => #{
|
||||||
description => <<"Get Prometheus Data">>,
|
description => <<"Get Prometheus Data">>,
|
||||||
responses => #{<<"200">> => schema(#{type => object})}
|
responses => #{<<"200">> =>
|
||||||
|
#{content =>
|
||||||
|
#{
|
||||||
|
'application/json' => #{schema => #{type => object}},
|
||||||
|
'text/plain' => #{schema => #{type => string}}
|
||||||
|
}}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{"/prometheus/stats", Metadata, stats}.
|
{"/prometheus/stats", Metadata, stats}.
|
||||||
|
@ -72,8 +78,12 @@ prometheus(put, #{body := Body}) ->
|
||||||
end,
|
end,
|
||||||
{200, emqx:get_raw_config([<<"prometheus">>], #{})}.
|
{200, emqx:get_raw_config([<<"prometheus">>], #{})}.
|
||||||
|
|
||||||
stats(get, #{query_string := Qs}) ->
|
stats(get, #{headers := Headers}) ->
|
||||||
Type = maps:get(<<"format_type">>, Qs, <<"json">>),
|
Type =
|
||||||
|
case maps:get(<<"accept">>, Headers, <<"text/plain">>) of
|
||||||
|
<<"application/json">> -> <<"json">>;
|
||||||
|
_ -> <<"prometheus">>
|
||||||
|
end,
|
||||||
Data = emqx_prometheus:collect(Type),
|
Data = emqx_prometheus:collect(Type),
|
||||||
case Type of
|
case Type of
|
||||||
<<"json">> -> {200, Data};
|
<<"json">> -> {200, Data};
|
||||||
|
|
Loading…
Reference in New Issue