Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Folsom as an application #18

Merged
merged 2 commits into from about 2 years ago

2 participants

Bob Ippolito Joe Williams
Bob Ippolito

This pull request makes folsom an application that can be started with application:start/1 and stopped with application:stop/1. I also made some changes to the test suite so they pass on a slower machine, and some fixes to the docs near the area where it talks about application startup, and picked some nits in the .app.src.

The other thing is that you can now create metrics from the command line or application config at startup (see the doc changes).

Bob Ippolito

The only thing that I would consider to be controversial is the change of folsom:start/0 to call application:start/1 instead of folsom_sup:start_link/0. The previous function did the wrong thing, since functions called start shouldn't actually do start_link (I've made this mistake myself). This "fix" would also take care of #17

Joe Williams joewilliams merged commit c42bd7a into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
2  .gitignore
... ... @@ -1,3 +1,5 @@
  1 +/deps
  2 +/.eunit
1 3 ebin/*
2 4 *#
3 5 *~
24 README.md
Source Rendered
@@ -8,13 +8,31 @@ First, regarding using folsom and folsom_webmachine together. To make sure you h
8 8
9 9 You need a (preferably recent) version of Erlang installed but that should be it.
10 10
11   - ./rebar compile
  11 + ./rebar get-deps compile
12 12
13 13 folsom can be run standalone or embedded in an Erlang application.
14 14
15   - $ erl -pa ebin
  15 + $ erl -pa ebin deps/*/ebin
16 16
17   - > folsom_sup:start_link(). % this creates the needed ETS tables and starts a gen_server
  17 + > folsom:start(). % this creates the needed ETS tables and starts a gen_server
  18 +
  19 +You can also start it as an application:
  20 +
  21 + $ erl -pa ebin deps/*/ebin
  22 + > application:start(folsom).
  23 +
  24 + $ erl -pa ebin deps/*/ebin -s folsom
  25 +
  26 +The application can be configured to create individual or lists of metrics at
  27 +startup on the command line or in an application config file:
  28 +
  29 + $ erl -pa ebin deps/*/ebin -s folsom \
  30 + -folsom history '[hist1,hist2]' \
  31 + -folsom gauge gauge1
  32 +
  33 + $ echo '[{folsom, [{history, [hist1, hist2]}, {gauge, gauge1}]}].' \
  34 + > myapp.config
  35 + $ erl -pa ebin deps/*/ebin -config myapp.config -s folsom
18 36
19 37 #### Metrics API
20 38
8 src/folsom.app.src
... ... @@ -1,11 +1,15 @@
  1 +%% -*- mode: erlang -*-
1 2 {application, folsom,
2 3 [
3 4 {description, ""},
4 5 {vsn, git},
5   - {registered, []},
  6 + {registered, [folsom_meter_timer_server,
  7 + folsom_metrics_histogram_ets,
  8 + folsom_sup]},
6 9 {applications, [
7 10 kernel,
8 11 stdlib
9 12 ]},
10   - {env, []}
  13 + {env, []},
  14 + {mod, {folsom, []}}
11 15 ]}.
34 src/folsom.erl
@@ -23,7 +23,37 @@
23 23 %%%------------------------------------------------------------------
24 24
25 25 -module(folsom).
26   --export([start/0]).
  26 +-export([start/0, stop/0]).
  27 +-export([start/2, stop/1]).
  28 +-behaviour(application).
  29 +-define(APP, ?MODULE).
27 30
28 31 start() ->
29   - folsom_sup:start_link().
  32 + application:start(?APP).
  33 +
  34 +stop() ->
  35 + application:stop(?APP).
  36 +
  37 +start(_Type, _Args) ->
  38 + {ok, Pid} = folsom_sup:start_link(),
  39 + lists:foreach(
  40 + fun ({K, New}) ->
  41 + case application:get_env(?APP, K) of
  42 + {ok, Name} when is_atom(Name) ->
  43 + New(Name);
  44 + {ok, Names} when is_list(Names) ->
  45 + lists:foreach(New, Names);
  46 + undefined ->
  47 + ok
  48 + end
  49 + end,
  50 + [{counter, fun folsom_metrics:new_counter/1},
  51 + {gauge, fun folsom_metrics:new_gauge/1},
  52 + {histogram, fun folsom_metrics:new_histogram/1},
  53 + {history, fun folsom_metrics:new_history/1},
  54 + {meter, fun folsom_metrics:new_meter/1},
  55 + {meter_reader, fun folsom_metrics:new_meter_reader/1}]),
  56 + {ok, Pid}.
  57 +
  58 +stop(?APP) ->
  59 + ok.
47 test/folsom_tests.erl
@@ -26,30 +26,23 @@
26 26
27 27 -include_lib("eunit/include/eunit.hrl").
28 28
29   -run_test() ->
30   - folsom:start(),
31   -
32   - ?debugFmt("creating metrics", []),
33   - folsom_erlang_checks:create_metrics(),
34   -
35   - ?debugFmt("populating metrics", []),
36   - folsom_erlang_checks:populate_metrics(),
37   -
38   - ?debugFmt("checking metrics", []),
39   - folsom_erlang_checks:check_metrics(),
40   -
41   - ?debugFmt("checking counter metric", []),
42   - folsom_erlang_checks:counter_metric(10000, testcounter),
43   -
44   - ?debugFmt("checking erlang vm metrics", []),
45   - folsom_erlang_checks:vm_metrics(),
46   -
47   - ?debugFmt("deleting metrics", []),
48   - folsom_erlang_checks:delete_metrics(),
49   -
50   - ?debugFmt("cpu topology test", []),
51   - folsom_erlang_checks:cpu_topology().
52   -
53   -
54   -
55   -
  29 +run_test_() ->
  30 + {setup,
  31 + fun () -> folsom:start() end,
  32 + fun (_) -> folsom:stop() end,
  33 + [{"creating metrics",
  34 + fun folsom_erlang_checks:create_metrics/0},
  35 + {"populating metrics",
  36 + {timeout, 30, fun folsom_erlang_checks:populate_metrics/0}},
  37 + {"checking metrics",
  38 + fun folsom_erlang_checks:check_metrics/0},
  39 + {"checking counter metric",
  40 + fun () ->
  41 + folsom_erlang_checks:counter_metric(10000, testcounter)
  42 + end},
  43 + {"checking erlang vm metrics",
  44 + fun folsom_erlang_checks:vm_metrics/0},
  45 + {"deleting metrics",
  46 + fun folsom_erlang_checks:delete_metrics/0},
  47 + {"cpu topology test",
  48 + fun folsom_erlang_checks:cpu_topology/0}]}.

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.