1%%%
2%%% Copyright 2011, Boundary
3%%%
4%%% Licensed under the Apache License, Version 2.0 (the "License");
5%%% you may not use this file except in compliance with the License.
6%%% You may obtain a copy of the License at
7%%%
8%%%     http://www.apache.org/licenses/LICENSE-2.0
9%%%
10%%% Unless required by applicable law or agreed to in writing, software
11%%% distributed under the License is distributed on an "AS IS" BASIS,
12%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13%%% See the License for the specific language governing permissions and
14%%% limitations under the License.
15%%%
16
17
18%%%-------------------------------------------------------------------
19%%% File:      folsom.erl
20%%% @author    joe williams <j@boundary.com>
21%%% @doc
22%%% @end
23%%%------------------------------------------------------------------
24
25-module(folsom).
26-export([start/0, stop/0]).
27-export([start/2, stop/1]).
28-behaviour(application).
29-define(APP, ?MODULE).
30
31start() ->
32    application:start(?APP).
33
34stop() ->
35    application:stop(?APP).
36
37start(_Type, _Args) ->
38    {ok, Pid} = folsom_sup:start_link(),
39    lists:foreach(fun configure/1,
40      [{counter, new_counter},
41       {gauge, new_gauge},
42       {histogram, new_histogram},
43       {history, new_history},
44       {meter, new_meter},
45       {spiral, new_spiral},
46       {meter_reader, new_meter_reader}]),
47    {ok, Pid}.
48
49stop(_State) ->
50    ok.
51
52%% internal
53configure({K, New}) ->
54    case application:get_env(?APP, K) of
55        {ok, Specs} when is_list(Specs) ->
56            [configure_metric(New, Spec) || Spec <- Specs];
57        {ok, Spec} ->
58            configure_metric(New, Spec);
59        undefined -> ok
60    end.
61
62configure_metric(New, Spec) when is_list(Spec) ->
63    apply(folsom_metrics, New, Spec);
64configure_metric(New, Name) ->
65    folsom_metrics:New(Name).
66