fix: generate topic metrics api & delayed message api path
This commit is contained in:
parent
a1ae4457df
commit
bf67fa1be1
|
@ -93,7 +93,7 @@ status_api() ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{"/mqtt/delayed_messages/status", Metadata, status}.
|
{"/mqtt/delayed", Metadata, status}.
|
||||||
|
|
||||||
delayed_messages_api() ->
|
delayed_messages_api() ->
|
||||||
Metadata = #{
|
Metadata = #{
|
||||||
|
@ -104,7 +104,7 @@ delayed_messages_api() ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{"/mqtt/delayed_messages", Metadata, delayed_messages}.
|
{"/mqtt/delayed/messages", Metadata, delayed_messages}.
|
||||||
|
|
||||||
delayed_message_api() ->
|
delayed_message_api() ->
|
||||||
Metadata = #{
|
Metadata = #{
|
||||||
|
@ -124,7 +124,7 @@ delayed_message_api() ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{"/mqtt/delayed_messages/:id", Metadata, delayed_message}.
|
{"/mqtt/delayed/messages/:id", Metadata, delayed_message}.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% HTTP API
|
%% HTTP API
|
||||||
|
|
|
@ -27,8 +27,7 @@
|
||||||
|
|
||||||
-export([api_spec/0]).
|
-export([api_spec/0]).
|
||||||
|
|
||||||
-export([ list_topic/2
|
-export([ list_topic_metrics/2
|
||||||
, list_topic_metrics/2
|
|
||||||
, operate_topic_metrics/2
|
, operate_topic_metrics/2
|
||||||
, reset_all_topic_metrics/2
|
, reset_all_topic_metrics/2
|
||||||
, reset_topic_metrics/2
|
, reset_topic_metrics/2
|
||||||
|
@ -43,7 +42,6 @@
|
||||||
api_spec() ->
|
api_spec() ->
|
||||||
{
|
{
|
||||||
[
|
[
|
||||||
list_topic_api(),
|
|
||||||
list_topic_metrics_api(),
|
list_topic_metrics_api(),
|
||||||
get_topic_metrics_api(),
|
get_topic_metrics_api(),
|
||||||
reset_all_topic_metrics_api(),
|
reset_all_topic_metrics_api(),
|
||||||
|
@ -77,17 +75,6 @@ properties() ->
|
||||||
{'messages.qos2.out.rate', number}]}
|
{'messages.qos2.out.rate', number}]}
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
|
||||||
list_topic_api() ->
|
|
||||||
Props = properties([{topic, string}]),
|
|
||||||
MetaData = #{
|
|
||||||
get => #{
|
|
||||||
description => <<"List topic">>,
|
|
||||||
responses => #{<<"200">> => object_array_schema(Props, <<"List topic">>)}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{"/mqtt/topic_metrics", MetaData, list_topic}.
|
|
||||||
|
|
||||||
list_topic_metrics_api() ->
|
list_topic_metrics_api() ->
|
||||||
MetaData = #{
|
MetaData = #{
|
||||||
get => #{
|
get => #{
|
||||||
|
@ -97,7 +84,7 @@ list_topic_metrics_api() ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{"/mqtt/topic_metrics/metrics", MetaData, list_topic_metrics}.
|
{"/mqtt/topic_metrics", MetaData, list_topic_metrics}.
|
||||||
|
|
||||||
get_topic_metrics_api() ->
|
get_topic_metrics_api() ->
|
||||||
MetaData = #{
|
MetaData = #{
|
||||||
|
@ -121,7 +108,7 @@ get_topic_metrics_api() ->
|
||||||
responses => #{ <<"200">> => schema(<<"Deregister topic metrics">>)}
|
responses => #{ <<"200">> => schema(<<"Deregister topic metrics">>)}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{"/mqtt/topic_metrics/metrics/:topic", MetaData, operate_topic_metrics}.
|
{"/mqtt/topic_metrics/:topic", MetaData, operate_topic_metrics}.
|
||||||
|
|
||||||
reset_all_topic_metrics_api() ->
|
reset_all_topic_metrics_api() ->
|
||||||
MetaData = #{
|
MetaData = #{
|
||||||
|
@ -133,7 +120,7 @@ reset_all_topic_metrics_api() ->
|
||||||
{"/mqtt/topic_metrics/reset", MetaData, reset_all_topic_metrics}.
|
{"/mqtt/topic_metrics/reset", MetaData, reset_all_topic_metrics}.
|
||||||
|
|
||||||
reset_topic_metrics_api() ->
|
reset_topic_metrics_api() ->
|
||||||
Path = "/mqtt/topic_metrics/reset/:topic",
|
Path = "/mqtt/topic_metrics/:topic/reset",
|
||||||
MetaData = #{
|
MetaData = #{
|
||||||
put => #{
|
put => #{
|
||||||
description => <<"Reset topic metrics">>,
|
description => <<"Reset topic metrics">>,
|
||||||
|
@ -148,18 +135,17 @@ topic_param() ->
|
||||||
name => topic,
|
name => topic,
|
||||||
in => path,
|
in => path,
|
||||||
required => true,
|
required => true,
|
||||||
|
description => <<"Notice: Topic string url must encode">>,
|
||||||
schema => #{type => string}
|
schema => #{type => string}
|
||||||
}.
|
}.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% api callback
|
%% api callback
|
||||||
list_topic(get, _) ->
|
|
||||||
list_topics().
|
|
||||||
|
|
||||||
list_topic_metrics(get, _) ->
|
list_topic_metrics(get, _) ->
|
||||||
list_metrics().
|
list_metrics().
|
||||||
|
|
||||||
operate_topic_metrics(Method, #{bindings := #{topic := Topic}}) ->
|
operate_topic_metrics(Method, #{bindings := #{topic := Topic0}}) ->
|
||||||
|
Topic = decode_topic(Topic0),
|
||||||
case Method of
|
case Method of
|
||||||
get ->
|
get ->
|
||||||
get_metrics(Topic);
|
get_metrics(Topic);
|
||||||
|
@ -172,14 +158,15 @@ operate_topic_metrics(Method, #{bindings := #{topic := Topic}}) ->
|
||||||
reset_all_topic_metrics(put, _) ->
|
reset_all_topic_metrics(put, _) ->
|
||||||
reset().
|
reset().
|
||||||
|
|
||||||
reset_topic_metrics(put, #{bindings := #{topic := Topic}}) ->
|
reset_topic_metrics(put, #{bindings := #{topic := Topic0}}) ->
|
||||||
|
Topic = decode_topic(Topic0),
|
||||||
reset(Topic).
|
reset(Topic).
|
||||||
|
|
||||||
|
decode_topic(Topic) ->
|
||||||
|
uri_string:percent_decode(Topic).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% api apply
|
%% api apply
|
||||||
list_topics() ->
|
|
||||||
{200, emqx_topic_metrics:all_registered_topics()}.
|
|
||||||
|
|
||||||
list_metrics() ->
|
list_metrics() ->
|
||||||
{200, emqx_topic_metrics:metrics()}.
|
{200, emqx_topic_metrics:metrics()}.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue