create monitor bucket

This commit is contained in:
anlicheng 2025-04-08 11:09:19 +08:00
parent 856072a9f2
commit f8f659a957

View File

@ -76,6 +76,11 @@ init([]) ->
%% 线
{ok, PoolPid} = poolboy:start_link([{size, PoolSize}, {max_overflow, PoolSize}, {worker_module, influx_client}], WorkerArgs),
%% bucket
poolboy:transaction(PoolPid, fun(ClientPid) ->
Result = create_bucket(ClientPid),
lager:debug("[influx_monitor_client_pool] org_name: ~p, create bucket result: ~p", [?DEFAULT_ORG, Result])
end),
%%
erlang:start_timer(5000, self(), flush_ticker),
@ -152,4 +157,12 @@ code_change(_OldVsn, State = #state{}, _Extra) ->
%%%===================================================================
%%% Internal functions
%%%===================================================================
%%%===================================================================
%% buckets
-spec create_bucket(ClientPid :: pid()) -> no_return().
create_bucket(ClientPid) when is_pid(ClientPid) ->
{ok, Orgs} = influx_client:get_orgs(ClientPid),
OrgMap = maps:from_list(lists:map(fun(#{<<"name">> := Name, <<"id">> := Id}) -> {Name, Id} end, Orgs)),
OrgId = maps:get(?DEFAULT_ORG, OrgMap, <<"">>),
influx_client:create_bucket(ClientPid, OrgId, ?DEFAULT_BUCKET).