feat(prometheus): Update the configuration file to hocon

This commit is contained in:
Turtle 2021-06-25 14:49:25 +08:00 committed by zhanghongtong
parent cc1f57ff01
commit c9ac851d27
6 changed files with 40 additions and 49 deletions

View File

@ -55,7 +55,7 @@
structs() -> ["cluster", "node", "rpc", "log", "lager",
"acl", "mqtt", "zone", "listener", "module", "broker",
"plugins", "sysmon", "os_mon", "vm_mon", "alarm", "telemetry"]
"plugins", "sysmon", "os_mon", "vm_mon", "alarm"]
++ includes().
-ifdef(TEST).
@ -477,12 +477,6 @@ fields("alarm") ->
, {"validity_period", t(duration_s(), undefined, "24h")}
];
fields("telemetry") ->
[ {"enabled", t(boolean(), undefined, false)}
, {"url", t(string(), undefined, "https://telemetry-emqx-io.bigpar.vercel.app/api/telemetry")}
, {"report_interval", t(duration_s(), undefined, "7d")}
];
fields(ExtraField) ->
Mod = list_to_atom(ExtraField++"_schema"),
Mod:fields(ExtraField).
@ -513,7 +507,6 @@ translation("emqx") ->
, {"os_mon", fun tr_os_mon/1}
, {"vm_mon", fun tr_vm_mon/1}
, {"alarm", fun tr_alarm/1}
, {"telemetry", fun tr_telemetry/1}
].
tr_cluster__discovery(Conf) ->
@ -668,7 +661,7 @@ tr_zones(Conf) ->
tr_listeners(Conf) ->
Atom = fun(undefined) -> undefined;
(B) when is_binary(B)-> binary_to_atom(B);
(B) when is_binary(B)-> binary_to_atom(B, utf8);
(S) when is_list(S) -> list_to_atom(S) end,
Access = fun(S) ->
@ -836,7 +829,7 @@ tr_modules(Conf) ->
tr_sysmon(Conf) ->
Keys = maps:to_list(conf_get("sysmon", Conf, #{})),
[{binary_to_atom(K), maps:get(value, V)} || {K, V} <- Keys].
[{binary_to_atom(K, utf8), maps:get(value, V)} || {K, V} <- Keys].
tr_os_mon(Conf) ->
[{cpu_check_interval, conf_get("os_mon.cpu_check_interval", Conf)}
@ -859,12 +852,6 @@ tr_alarm(Conf) ->
, {validity_period, conf_get("alarm.validity_period", Conf)}
].
tr_telemetry(Conf) ->
[ {enabled, conf_get("telemetry.enabled", Conf)}
, {url, conf_get("telemetry.url", Conf)}
, {report_interval, conf_get("telemetry.report_interval", Conf)}
].
%% helpers
options(static, Conf) ->

View File

@ -1,13 +1,7 @@
##--------------------------------------------------------------------
## emqx_prometheus for EMQ X
##--------------------------------------------------------------------
## The Prometheus Push Gateway URL address
##
## Note: You can comment out this line to disable it
prometheus.push.gateway.server = "http://127.0.0.1:9091"
## The metrics data push interval (millisecond)
##
## Default: 15000
prometheus.interval = 15000
emqx_prometheus:{
push_gateway_server: "http://127.0.0.1:9091"
interval: "15s"
}

View File

@ -1,20 +0,0 @@
%% -*-: erlang -*-
%% emqx_prometheus config
{mapping, "prometheus.push.gateway.server", "emqx_prometheus.push_gateway", [
{datatype, string}
]}.
{mapping, "prometheus.interval", "emqx_prometheus.interval", [
{default, 5000},
{datatype, integer}
]}.
{mapping, "prometheus.collector.$name", "prometheus.collectors", [
{datatype, atom}
]}.
{translation, "prometheus.collectors", fun(Conf) ->
Collectors = cuttlefish_variable:filter_by_prefix("prometheus.collector", Conf),
lists:map(fun({_, Collector}) -> Collector end, Collectors)
end}.

View File

@ -1,6 +1,6 @@
{application, emqx_prometheus,
[{description, "Prometheus for EMQ X"},
{vsn, "4.3.0"}, % strict semver, bump manually!
{vsn, "5.0.0"}, % strict semver, bump manually!
{modules, []},
{registered, [emqx_prometheus_sup]},
{applications, [kernel,stdlib,prometheus]},

View File

@ -28,8 +28,8 @@
-define(APP, emqx_prometheus).
start(_StartType, _StartArgs) ->
PushGateway = application:get_env(?APP, push_gateway, undefined),
Interval = application:get_env(?APP, interval, 5000),
PushGateway = emqx_config:get([?APP, push_gateway_server], undefined),
Interval = emqx_config:get([?APP, interval], 15000),
emqx_prometheus_sup:start_link(PushGateway, Interval).
stop(_State) ->

View File

@ -0,0 +1,30 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%--------------------------------------------------------------------
-module(emqx_prometheus_schema).
-include_lib("typerefl/include/types.hrl").
-behaviour(hocon_schema).
-export([ structs/0
, fields/1]).
structs() -> ["emqx_prometheus"].
fields("emqx_prometheus") ->
[ {push_gateway_server, emqx_schema:t(string())}
, {interval, emqx_schema:t(emqx_schema:duration_ms(), undefined, "15s")}
].