Skip to content

Commit

Permalink
Refactor file layout to build releases with plugins, config, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
afternoon committed Apr 26, 2011
1 parent 9fff893 commit c7d5ae4
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -4,7 +4,7 @@
deps
tags
ebin
apps/rolf/priv/data
data
.eunit
logs
TEST-*.xml
Expand Down
1 change: 0 additions & 1 deletion apps/rolf/src/plugins/rolf_loadtime.erl
Expand Up @@ -44,7 +44,6 @@ collect(Service) ->
Config = Service#service.config,
UrlConfig = proplists:get_value(urls, Config, []),
Values = time_urls(UrlConfig),
error_logger:info_report([{where, {node(), rolf_loadtime, collect}}, {values, Values}]),
#sample{node=node(), service=Service, values=Values}.

%% @doc Stop collector.
Expand Down
9 changes: 3 additions & 6 deletions apps/rolf/src/rolf_plugin.erl
Expand Up @@ -26,7 +26,7 @@

-include("rolf.hrl").

-define(PLUGIN_DIR, filename:join(["apps", "rolf", "priv", "plugin.d"])).
-define(PLUGIN_DIR, "plugins").
-define(PLUGIN_DEFAULT_FREQ, 10).
-define(PLUGIN_DEFAULT_TIMEOUT_MULTIPLE, 3).
-define(PLUGIN_DEFAULT_ARCHIVES, [{1, 360}, % 1hr of 10s averages
Expand Down Expand Up @@ -118,10 +118,7 @@ propmerge(L1, L2) ->
%% ===================================================================

configfilename_to_atom_test() ->
?assertEqual(disk, configfilename_to_atom("priv/plugin.d/disk/disk.config")).

list_test() ->
?assertEqual([disk, loadtime], list("../priv/plugin.d")).
?assertEqual(disk, configfilename_to_atom("plugins/disk/disk.config")).

config_path_test() ->
Path = filename:join([?PLUGIN_DIR, "loadtime", "loadtime.config"]),
Expand All @@ -140,7 +137,7 @@ parse_test() ->
Output = parse(loadtime, Input),
?assertEqual(loadtime, Output#service.name),
?assertEqual(10, Output#service.frequency),
?assertEqual("priv/plugin.d/loadtime/loadtime.sh", Output#service.command),
?assertEqual("plugins/loadtime/loadtime.sh", Output#service.command),
?assertEqual(rolf_command, Output#service.module).

parse_options_test() ->
Expand Down
4 changes: 1 addition & 3 deletions apps/rolf/src/rolf_recorder.erl
Expand Up @@ -31,7 +31,7 @@

-include("rolf.hrl").

-define(RECORDER_CONFIG_FILE, filename:join(["apps", "rolf", "priv", "recorder.config"])).
-define(RECORDER_CONFIG_FILE, filename:join("etc", "recorder.config")).

%% ===================================================================
%% API
Expand Down Expand Up @@ -76,7 +76,6 @@ handle_call(_Req, _From, State) ->
{reply, State}.

handle_cast({store, Sample}, #recorder{rrd=RRD}=State) ->
error_logger:info_report([{where, {node(), rolf_recorder, handle_cast, store}}, {sample, Sample}]),
rolf_rrd:update(RRD, Sample),
{noreply, State}.

Expand Down Expand Up @@ -144,7 +143,6 @@ connect_cluster(Config) ->

%% @doc Start collectors on a set of nodes.
start_services(Node, SDefs, RRD) ->
error_logger:info_report([{where, {node(), rolf_recorder, start_services}}, {node, Node}, {servicedefs, SDefs}, {rrd, RRD}]),
Services = [rolf_plugin:load(Name, Opts) || {Name, Opts} <- SDefs],
lists:foreach(fun(S) -> rolf_rrd:ensure(RRD, Node, S) end, Services),
rpc:call(Node, rolf_collector_sup, start_services, [Services]).
4 changes: 2 additions & 2 deletions apps/rolf/src/rolf_rrd.erl
Expand Up @@ -27,7 +27,7 @@
-include_lib("errd/include/errd.hrl").
-include("rolf.hrl").

-define(RRD_DIR, filename:join(["apps", "rolf", "priv", "data"])).
-define(RRD_DIR, "data").
-define(RRD_EXT, "rrd").

%% ===================================================================
Expand Down Expand Up @@ -117,7 +117,7 @@ string_format_test() ->
?assertEqual("X:1:9.5:z", string_format("~s:~b:~.1f:~p", ["X", 1, 9.5, z])).

rrd_path_test() ->
Path = rrd_path(frank@josie, loadtime),
Path = rrd_path(frank@josie, #service{name=loadtime}),
?assertEqual(filename:join([?RRD_DIR, "frank@josie", "loadtime.rrd"]), Path).

make_rrd_create_test() ->
Expand Down
1 change: 0 additions & 1 deletion apps/rolf/src/rolf_service.erl
Expand Up @@ -92,7 +92,6 @@ handle_cast(stop_emitting, Service) ->

handle_cast(publish, Service) ->
Module = Service#service.module,
error_logger:info_report([{where, {node(), rolf_service, handle_cast, publish}}, {service, Service}, {module, Module}]),
Sample = apply(Module, collect, [Service]),
rolf_recorder:store(Sample),
{noreply, Service}.
Expand Down
34 changes: 22 additions & 12 deletions bin/graph.sh
@@ -1,16 +1,26 @@
#!/bin/bash
now=`date +%s`
start=`expr $now - 3600`
rrdtool graph rolf_loadtime.png -s $start -S 10 -w 800 -h 600 -l 0 -u 1.5 \
rrdtool graph rolf_loadtime.png -s $start -S 10 -w 800 -h 600 -l 0 -u 1000 -r \
-c BACK#191919 -c CANVAS#191919 -c SHADEA#191919 -c SHADEB#191919 -c FONT#ffffff \
'DEF:loadtime=priv/data/rolf@josie/loadtime.rrd:loadtime:AVERAGE' \
'AREA:loadtime#0091ff:loadtime'
rrdtool graph rolf_freespace.png -s $start -S 300 -w 800 -h 600 -l 0 -u 100 \
-c BACK#191919 -c CANVAS#191919 -c SHADEA#191919 -c SHADEB#191919 -c FONT#ffffff \
'DEF:freespace=priv/data/rolf@josie/disk.rrd:freespace:AVERAGE' \
'AREA:freespace#0091ff:freespace'
rrdtool graph rolf2_loadtime.png -s $start -S 10 -w 800 -h 600 -l 0 -u 1.5 \
-c BACK#191919 -c CANVAS#191919 -c SHADEA#191919 -c SHADEB#191919 -c FONT#ffffff \
'DEF:loadtime=priv/data/rolf2@josie/loadtime.rrd:loadtime:AVERAGE' \
'AREA:loadtime#0091ff:loadtime'
open rolf_freespace.png rolf_loadtime.png rolf2_loadtime.png
'DEF:bbc=data/rolf@127.0.0.1/loadtime.rrd:bbc:AVERAGE' \
'DEF:guardian=data/rolf@127.0.0.1/loadtime.rrd:guardian:AVERAGE' \
'DEF:lastminute=data/rolf@127.0.0.1/loadtime.rrd:lastminute:AVERAGE' \
'DEF:aws=data/rolf@127.0.0.1/loadtime.rrd:aws:AVERAGE' \
'DEF:appengine=data/rolf@127.0.0.1/loadtime.rrd:appengine:AVERAGE' \
'DEF:twitter=data/rolf@127.0.0.1/loadtime.rrd:twitter:AVERAGE' \
'DEF:argos=data/rolf@127.0.0.1/loadtime.rrd:argos:AVERAGE' \
'DEF:aarouteplanner=data/rolf@127.0.0.1/loadtime.rrd:aarouteplanner:AVERAGE' \
'DEF:ocado=data/rolf@127.0.0.1/loadtime.rrd:ocado:AVERAGE' \
'DEF:dailymail=data/rolf@127.0.0.1/loadtime.rrd:dailymail:AVERAGE' \
'LINE:bbc#0091ff' \
'LINE:guardian#91ff00' \
'LINE:lastminute#9100ff' \
'LINE:aws#91ff00' \
'LINE:appengine#ff0091' \
'LINE:twitter#ff9100' \
'LINE:argos#00ff91' \
'LINE:aarouteplanner#cc0066' \
'LINE:ocado#0066cc' \
'LINE:dailymail#66cc00'
open rolf_loadtime.png
1 change: 1 addition & 0 deletions etc/recorder.config
1 change: 1 addition & 0 deletions plugins
7 changes: 2 additions & 5 deletions rel/files/app.config
@@ -1,11 +1,8 @@
[
%% SASL config
{sasl, [
{sasl_error_logger, {file, "log/sasl-error.log"}},
{sasl, [{sasl_error_logger, {file, "log/sasl-error.log"}},
{errlog_type, error},
{error_logger_mf_dir, "log/sasl"}, % Log directory
{error_logger_mf_maxbytes, 10485760}, % 10 MB max file size
{error_logger_mf_maxfiles, 5} % 5 files max
]}
{error_logger_mf_maxfiles, 5}]} % 5 files max
].

File renamed without changes.
File renamed without changes.
Expand Up @@ -3,27 +3,27 @@
{module, rolf_loadtime}.

%% update frequency in seconds
{frequency, 10}.
{frequency, 5}.

%% number of seconds allowed before service becomes "unknown"
{timeout, 60}.

%% define the RRAs (round robin archives) to be stored for this service
{archives, [{1, 360}, % 1hr of 10s averages
{30, 288}, % 1d of 5m averages
{180, 336}, % 7d of 30m averages
{8640, 365}]}. % 1y of 1d averages
{archives, [{1, 720}, % 1hr of 5s averages
{6, 2880}, % 1d of 30s averages
{360, 336}, % 7d of 30m averages
{17280, 365}]}. % 1y of 1d averages

%% graph parameters
{graph_title, "Load Time"}.
{graph_vlabel, "Secs"}.

%% metric configuration - tricky for this plugin as each url is a metric
{metrics, [{loadtime, [{label, "Load Time"},
{type, gauge},
{draw, areastack},
{min, 0},
{colour, "#0091FF"}]}]}.
{metrics, [{localhost, [{label, "Localhost"},
{type, gauge},
{draw, areastack},
{min, 0},
{colour, "#0091FF"}]}]}.

%% additional options
{urls, [{localhost, "http://localhost/"}]}.
File renamed without changes.
6 changes: 3 additions & 3 deletions apps/rolf/priv/recorder.config → rel/files/recorder.config
@@ -1,12 +1,12 @@
%% vim: ft=erlang
%% configure which node will do the recording
{recorders, [rolf@josie]}.
{recorders, ['rolf@127.0.0.1']}.

%% define which services run on which nodes, customise those services by
%% overriding config.
{service, rolf@josie, disk, []}.
{service, 'rolf@127.0.0.1', disk, []}.
{service, loadtime,
rolf@josie,
'rolf@127.0.0.1',
[{urls, [{bbc, "http://www.bbc.co.uk/"},
{guardian, "http://www.guardian.co.uk/"},
{lastminute, "http://www.lastminute.com/"},
Expand Down
17 changes: 1 addition & 16 deletions rel/files/vm.args
Expand Up @@ -3,19 +3,4 @@
-name rolf@127.0.0.1

## Cookie for distributed erlang
-setcookie rolf

## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive
## (Disabled by default..use with caution!)
##-heart

## Enable kernel poll and a few async threads
+K true
+A 5

## Increase number of concurrent ports/sockets
-env ERL_MAX_PORTS 4096

## Tweak GC to run more often
-env ERL_FULLSWEEP_AFTER 10

-setcookie rolf123
32 changes: 11 additions & 21 deletions rel/reltool.config
@@ -1,30 +1,20 @@
{sys, [
{lib_dirs, []},
{rel, "rolf", "1",
[
kernel,
stdlib,
sasl
]},
{rel, "start_clean", "",
[
kernel,
stdlib
]},
%% vim: ft=erlang
{sys, [{lib_dirs, []},
{rel, "rolf", "1", [kernel, stdlib, sasl]},
{rel, "start_clean", "", [kernel, stdlib]},
{boot_rel, "rolf"},
{profile, embedded},
{excl_sys_filters, ["^bin/.*",
"^erts.*/bin/(dialyzer|typer)"]},
{app, sasl, [{incl_cond, include}]}
]}.
{excl_sys_filters, ["^bin/.*", "^erts.*/bin/(dialyzer|typer)"]},
{app, sasl, [{incl_cond, include}]}]}.

{target_dir, "rolf"}.

{overlay, [
{mkdir, "log/sasl"},
{overlay, [{mkdir, "log/sasl"},
{mkdir, "data"},
{copy, "files/erl", "{{erts_vsn}}/bin/erl"},
{copy, "files/nodetool", "{{erts_vsn}}/bin/nodetool"},
{copy, "files/rolf", "bin/rolf"},
{copy, "files/app.config", "etc/app.config"},
{copy, "files/vm.args", "etc/vm.args"}
]}.
{copy, "files/vm.args", "etc/vm.args"},
{copy, "files/recorder.config", "etc/recorder.config"},
{copy, "files/plugins", "plugins"}]}.

0 comments on commit c7d5ae4

Please sign in to comment.