Skip to content
Browse files

make folsom an application, have folsom:start/0 use it

  • Loading branch information...
1 parent 9be36cb commit 4355aece58ef7e7a7c338949ade63fa4e3021c9b @etrepum committed Apr 30, 2012
Showing with 79 additions and 34 deletions.
  1. +21 −3 README.md
  2. +6 −2 src/folsom.app.src
  3. +32 −2 src/folsom.erl
  4. +20 −27 test/folsom_tests.erl
View
24 README.md
@@ -8,13 +8,31 @@ First, regarding using folsom and folsom_webmachine together. To make sure you h
You need a (preferably recent) version of Erlang installed but that should be it.
- ./rebar compile
+ ./rebar get-deps compile
folsom can be run standalone or embedded in an Erlang application.
- $ erl -pa ebin
+ $ erl -pa ebin deps/*/ebin
- > folsom_sup:start_link(). % this creates the needed ETS tables and starts a gen_server
+ > folsom:start(). % this creates the needed ETS tables and starts a gen_server
+
+You can also start it as an application:
+
+ $ erl -pa ebin deps/*/ebin
+ > application:start(folsom).
+
+ $ erl -pa ebin deps/*/ebin -s folsom
+
+The application can be configured to create individual or lists of metrics at
+startup on the command line or in an application config file:
+
+ $ erl -pa ebin deps/*/ebin -s folsom \
+ -folsom history '[hist1,hist2]' \
+ -folsom gauge gauge1
+
+ $ echo '[{folsom, [{history, [hist1, hist2]}, {gauge, gauge1}]}].' \
+ > myapp.config
+ $ erl -pa ebin deps/*/ebin -config myapp.config -s folsom
#### Metrics API
View
8 src/folsom.app.src
@@ -1,11 +1,15 @@
+%% -*- mode: erlang -*-
{application, folsom,
[
{description, ""},
{vsn, git},
- {registered, []},
+ {registered, [folsom_meter_timer_server,
+ folsom_metrics_histogram_ets,
+ folsom_sup]},
{applications, [
kernel,
stdlib
]},
- {env, []}
+ {env, []},
+ {mod, {folsom, []}}
]}.
View
34 src/folsom.erl
@@ -23,7 +23,37 @@
%%%------------------------------------------------------------------
-module(folsom).
--export([start/0]).
+-export([start/0, stop/0]).
+-export([start/2, stop/1]).
+-behaviour(application).
+-define(APP, ?MODULE).
start() ->
- folsom_sup:start_link().
+ application:start(?APP).
+
+stop() ->
+ application:stop(?APP).
+
+start(_Type, _Args) ->
+ {ok, Pid} = folsom_sup:start_link(),
+ lists:foreach(
+ fun ({K, New}) ->
+ case application:get_env(?APP, K) of
+ {ok, Name} when is_atom(Name) ->
+ New(Name);
+ {ok, Names} when is_list(Names) ->
+ lists:foreach(New, Names);
+ undefined ->
+ ok
+ end
+ end,
+ [{counter, fun folsom_metrics:new_counter/1},
+ {gauge, fun folsom_metrics:new_gauge/1},
+ {histogram, fun folsom_metrics:new_histogram/1},
+ {history, fun folsom_metrics:new_history/1},
+ {meter, fun folsom_metrics:new_meter/1},
+ {meter_reader, fun folsom_metrics:new_meter_reader/1}]),
+ {ok, Pid}.
+
+stop(?APP) ->
+ ok.
View
47 test/folsom_tests.erl
@@ -26,30 +26,23 @@
-include_lib("eunit/include/eunit.hrl").
-run_test() ->
- folsom:start(),
-
- ?debugFmt("creating metrics", []),
- folsom_erlang_checks:create_metrics(),
-
- ?debugFmt("populating metrics", []),
- folsom_erlang_checks:populate_metrics(),
-
- ?debugFmt("checking metrics", []),
- folsom_erlang_checks:check_metrics(),
-
- ?debugFmt("checking counter metric", []),
- folsom_erlang_checks:counter_metric(10000, testcounter),
-
- ?debugFmt("checking erlang vm metrics", []),
- folsom_erlang_checks:vm_metrics(),
-
- ?debugFmt("deleting metrics", []),
- folsom_erlang_checks:delete_metrics(),
-
- ?debugFmt("cpu topology test", []),
- folsom_erlang_checks:cpu_topology().
-
-
-
-
+run_test_() ->
+ {setup,
+ fun () -> folsom:start() end,
+ fun (_) -> folsom:stop() end,
+ [{"creating metrics",
+ fun folsom_erlang_checks:create_metrics/0},
+ {"populating metrics",
+ {timeout, 30, fun folsom_erlang_checks:populate_metrics/0}},
+ {"checking metrics",
+ fun folsom_erlang_checks:check_metrics/0},
+ {"checking counter metric",
+ fun () ->
+ folsom_erlang_checks:counter_metric(10000, testcounter)
+ end},
+ {"checking erlang vm metrics",
+ fun folsom_erlang_checks:vm_metrics/0},
+ {"deleting metrics",
+ fun folsom_erlang_checks:delete_metrics/0},
+ {"cpu topology test",
+ fun folsom_erlang_checks:cpu_topology/0}]}.

0 comments on commit 4355aec

Please sign in to comment.
Something went wrong with that request. Please try again.