Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use anonymous table for history (like histogram reservoir)

In multi-app environments (like riak) naming stats with a 2 tuple
is useful. It makes querying stats by app e.g. {riak_kv, _} much simpler.
History metrics use the name of the metric as the name of the data table,
this commit uses an anonympus table and stores a record in the
?HISTORY_TABLE. Since that table is already defined and created
maybe this was the original intent?
  • Loading branch information...
commit a7235c15019094f2e87585c868d67ba7e27fe8da 1 parent f130f73
@russelldb russelldb authored
View
4 include/folsom.hrl
@@ -40,6 +40,10 @@
sample = #uniform{}
}).
+-record(history, {
+ tid
+ }).
+
-define(SYSTEM_INFO, [
allocated_areas,
allocator,
View
14 src/folsom_ets.erl
@@ -210,13 +210,9 @@ maybe_add_handler(Type, _, _, _, _, false) ->
maybe_add_handler(_, Name, _, _, _, true) ->
{error, Name, metric_already_exists}.
-delete_metric(Name, history) when is_binary(Name) ->
- true = ets:delete(folsom_utils:to_atom(Name)),
- true = ets:delete(?FOLSOM_TABLE, Name),
- ok;
delete_metric(Name, history) ->
- true = ets:delete(Name),
- true = ets:delete(?FOLSOM_TABLE, Name),
+ History = folsom_metrics_history:get_value(Name),
+ ok = delete_history(Name, History),
ok;
delete_metric(Name, histogram) ->
Metric = folsom_metrics_histogram:get_value(Name),
@@ -254,6 +250,12 @@ delete_histogram(Name, #histogram{type = exdec}) ->
true = ets:delete(?FOLSOM_TABLE, Name),
ok.
+delete_history(Name, #history{tid = Tid}) ->
+ true = ets:delete(?HISTORY_TABLE, Name),
+ true = ets:delete(?FOLSOM_TABLE, Name),
+ true = ets:delete(Tid),
+ ok.
+
notify(Name, {inc, Value}, counter, true) ->
folsom_metrics_counter:inc(Name, Value),
ok;
View
27 src/folsom_metrics_history.erl
@@ -27,44 +27,41 @@
-export([new/1,
update/3,
get_events/1,
- get_events/2
+ get_events/2,
+ get_value/1
]).
-include("folsom.hrl").
-define(ETSOPTS, [
- named_table,
ordered_set,
public,
{write_concurrency, true}
]).
-new(Name) when is_binary(Name) ->
- new(folsom_utils:to_atom(Name));
new(Name) ->
- Name = ets:new(Name, ?ETSOPTS),
+ Tid = ets:new(history, ?ETSOPTS),
+ ets:insert(?HISTORY_TABLE, {Name, #history{tid=Tid}}),
ok.
-update(Name, Size, Value) when is_binary(Name) ->
- update(folsom_utils:to_atom(Name), Size, Value);
update(Name, Size, Value) ->
+ #history{tid=Tid} = get_value(Name),
Key = folsom_utils:now_epoch_micro(),
- insert(Name, Key, Size, Value, ets:info(Name, size)).
+ insert(Tid, Key, Size, Value, ets:info(Tid, size)).
+
+get_value(Name) ->
+ [{_, Value}] = ets:lookup(?HISTORY_TABLE, Name),
+ Value.
-get_events(Name) when is_binary(Name) ->
- get_events(folsom_utils:to_atom(Name));
get_events(Name) ->
get_events(Name, ?DEFAULT_LIMIT).
-get_events(Name, Count) when is_binary(Name) ->
- get_events(folsom_utils:to_atom(Name, Count));
get_events(Name, Count) ->
- get_last_events(Name, Count).
+ #history{tid=Tid} = get_value(Name),
+ get_last_events(Tid, Count).
% Internal API
-insert(Name, Key, Size, Value, Count) when is_list(Value) ->
- insert(Name, Key, Size, list_to_binary(Value), Count);
insert(Name, Key, Size, Value, Count) when Count < Size ->
true = ets:insert(Name, {Key, [{event, Value}]});
insert(Name, Key, _, Value, _) ->
Please sign in to comment.
Something went wrong with that request. Please try again.