Feuerlabs/exometer — pull request #58 by uwiger (2014-05-03 21:48:14+00:00)
Title: Uw function eval

Added exometer_function:eval_exprs/2 and expr evaluation in metrics

An abstract expression language, similar to Abstract Erlang, but slightly more compact, is introduced for complex handling of function call results. The language is described in the docs for exometer_function:eval_exprs/2. Note below that `{t, Elems}` and `{l, Elems}` are shorthand for lists and tuples, and integers and atoms can be used untagged as long as they don't collide with reserved atoms (like `'nil'`).

Example:

```erlang
% Create a metric which counts the number of running processes
2> exometer:new([p], {function,erlang,processes,[],eval,
{[{l,[{t,[value,{call,length,[{v,'Value'}]}]}]}],
[value]}}, []).
ok
3> exometer:get_value([p]).
{ok,[{value,41}]}

% Create a metric which simulates a list of datapoints
4> exometer:new([p], {function,{eval,[{l,[{t,[a,1]},{t,[b,2]}]}], [a,b]}}, []).
ok
5> exometer:get_value([p]).
{ok,[{a,1},{b,2}]}

% Evaluate a fold over a list of integers I, adding each value to Acc.
6> exometer_function:eval_exprs(
[{fold,'I','Acc',[{op,'+',{v,'I'},{v,'Acc'}}],0,{l,[1,2,3,4]}}], []).
{value,10,[]}

% case 12 of I when I rem 2 == 0 -> {I} end
7> exometer_function:eval_exprs(
[{'case',[12],[{{v,'I'},[[{op,'==',0,{op,'rem',{v,'I'},2}}]],[{t,[{v,'I'}]}]}]}], []).
{value,{12},[{'I',12}]}
```