|
13 | 13 | %% API |
14 | 14 | -export([new/2]). |
15 | 15 | -export([update/1, update/2]). |
| 16 | +-export([update_or_create/3]). |
16 | 17 | -export([backend/0, backend/1]). |
17 | 18 |
|
18 | 19 | -export([start_link/0]). |
@@ -61,6 +62,12 @@ update(Name) -> |
61 | 62 | update(Name, Probe) -> |
62 | 63 | metrics_mod:update(Name, Probe). |
63 | 64 |
|
| 65 | +%% @doc update a metric and create it if it doesn't exists |
| 66 | +-spec update_or_create(list(), probe(), metric()) -> ok | any(). |
| 67 | +update_or_create(Name, Probe, Type) -> |
| 68 | + metrics_mod:update_or_create(Name, Probe, Type). |
| 69 | + |
| 70 | + |
64 | 71 | %% @doc retrieve the current backend name |
65 | 72 | -spec backend() -> atom(). |
66 | 73 | backend() -> gen_server:call(?MODULE, get_backend). |
@@ -163,9 +170,11 @@ build_metrics_mod(Mod, Config) when is_atom(Mod), is_map(Config) -> |
163 | 170 | [?Q("(Type, Name) -> _@Mod@:new(Type, Name, _@Config@)")]), |
164 | 171 | Update = erl_syntax:function(merl:term('update'), |
165 | 172 | [?Q("(Name, Probe) -> _@Mod@:update(Name, Probe, _@Config@)")]), |
| 173 | + UpdateOrCreate = erl_syntax:function(merl:term('update_or_create'), |
| 174 | + [?Q("(Name, Probe, Type) -> _@Mod@:update_or_create(Name, Probe, Type, _@Config@)")]), |
166 | 175 | Module = ?Q("-module('metrics_mod')."), |
167 | | - Exported = ?Q("-export(['new'/2, 'update'/2])."), |
168 | | - Functions = [ ?Q("'@_F'() -> [].") || F <- [New, Update]], |
| 176 | + Exported = ?Q("-export(['new'/2, 'update'/2, 'update_or_create'/3])."), |
| 177 | + Functions = [ ?Q("'@_F'() -> [].") || F <- [New, Update, UpdateOrCreate]], |
169 | 178 | Forms = lists:flatten([Module, Exported, Functions]), |
170 | 179 | merl:compile_and_load(Forms, [verbose]), |
171 | 180 | ok. |
0 commit comments