Permalink
Browse files

Merge remote-tracking branch 'vagabond/master'

Merging with vagabond's errd branch.

Still removing make/emake build cruft, killing cl_calendar with fire etc.

Conflicts:
	Makefile
	src/cl_calendar.erl
	src/errd.app.src
	src/errd_info.erl
	src/errd_server.erl
  • Loading branch information...
2 parents 8d4dd5c + 8562fce commit e88239c20852aaa01cb0794993c41b3b7cc8d1cf @archaelus committed Mar 31, 2011
Showing with 111 additions and 35 deletions.
  1. +6 −0 .gitignore
  2. +26 −24 include/errd.hrl
  3. +2 −0 include/errd_internal.hrl
  4. BIN rebar
  5. +2 −0 src/errd_app.erl
  6. +36 −2 src/errd_command.erl
  7. +4 −3 src/errd_info.erl
  8. +23 −0 src/errd_server.erl
  9. +2 −0 src/errd_server_sup.erl
  10. +3 −1 src/errd_sup.erl
  11. +7 −5 src/errdb.erl
View
@@ -3,3 +3,9 @@ ebin/*.beam
src/TAGS
priv/log/*
erl_crash.dump
+*.swp
+doc/*.html
+doc/edoc-info
+doc/*.png
+doc/*.css
+ebin/*.beam
View
@@ -1,30 +1,32 @@
--record(rrd_create, {file,
- start_time,
- step = 300,
- ds_defs = [],
- rra_defs = []}).
+-record(rrd_ds_update, {name :: string(),
+ value = unknown :: any()}).
--record(rrd_update, {file,
- updates}).
+-record(rrd_ds, {name :: string(),
+ type :: 'gauge' | 'counter' | 'derive' | 'absolute',
+ heartbeat :: integer(),
+ min :: integer(),
+ max :: integer(),
+ args = [] :: string()}).
--record(rrd_ds_update, {name,
- time = now,
- value = unknown}).
+-record(rrd_rra, {cf :: 'average' | 'min' | 'max' | 'last',
+ args :: string()}).
--record(rrd_ds, {name,
- type,
- heartbeat,
- min,
- max,
- args = []}).
+-record(rrd_create, {file :: string(),
+ start_time :: any(), %% TODO
+ step = 300 :: pos_integer(),
+ ds_defs = [] :: [#rrd_ds{}],
+ rra_defs = [] :: [#rrd_rra{}]}).
--record(rrd_rra, {cf,
- args}).
+-record(rrd_update, {file :: string(),
+ time = now :: 'now' | string(),
+ updates :: [#rrd_ds_update{}]}).
--record(rrd, {file,
- ds = [],
- rra = [],
- version,
- step,
- last_update}).
+-record(rrd, {file :: string(),
+ ds = [] :: [#rrd_ds{}],
+ rra = [] :: [any()],
+ version :: string(),
+ step :: integer(),
+ last_update :: integer()}).
+
+% vim: set ts=4 sw=4 expandtab:
@@ -11,3 +11,5 @@
-define(ERR(Format, Args),
error_logger:error_report([{where, lists:flatten(io_lib:format("(~p:~p ~p)", [?MODULE, ?LINE, self()]))},
lists:flatten(io_lib:format(Format, Args))])).
+
+% vim: set ts=4 sw=4 expandtab:
View
BIN rebar
Binary file not shown.
View
@@ -40,3 +40,5 @@ stop(_State) ->
%%====================================================================
%% Internal functions
%%====================================================================
+
+% vim: set ts=4 sw=4 expandtab:
View
@@ -28,13 +28,27 @@ format(#rrd_create{file=File,start_time=undefined,
step=Step,ds_defs=DSs,rra_defs=RRAs}) when is_integer(Step) ->
Dstr = lists:flatten(string:join(lists:map(fun (D) -> format(D) end, DSs), " ")),
RRAstr = lists:flatten(string:join(lists:map(fun (D) -> format(D) end, RRAs), " ")),
- lists:flatten(io_lib:format("create ~s --step ~p ~s ~s", [File, Step, Dstr, RRAstr]));
+ lists:flatten(io_lib:format("create ~s --step ~p ~s ~s~n", [File, Step, Dstr, RRAstr]));
format(#rrd_ds{name=Name,type=Type,args=Args}) when is_atom(Type) ->
io_lib:format("DS:~s:~s:~s", [Name, to_list(Type), Args]);
format(#rrd_rra{cf=CF,args=Args}) when is_atom(CF) ->
- io_lib:format("RRA:~s:~s", [to_list(CF), Args]).
+ io_lib:format("RRA:~s:~s", [to_list(CF), Args]);
+
+format(#rrd_update{file=File, time=Time, updates=Updates}) when is_list(File) ->
+ TimeFmt = case Time of
+ now ->
+ "N";
+ _ ->
+ Time
+ end,
+ {Template, Update} = format(Updates),
+ lists:flatten(io_lib:format("update ~s -t ~s ~s:~s~n", [File, Template, TimeFmt, Update]));
+
+format([#rrd_ds_update{} | _Tail] = List) ->
+ format_updates(List, [], []).
+
%% @spec (File::string(), DSName::string(), Type) -> #rrd_create{}
%% Type = guage | counter | derive | absolute
@@ -100,6 +114,26 @@ one_week_test() ->
to_list(S) when is_atom(S) ->
string:to_upper(atom_to_list(S)).
+format_updates([], Template, Update) ->
+ {string:join(lists:reverse(Template), ":"), string:join(lists:reverse(Update), ":")};
+format_updates([#rrd_ds_update{name=Name, value=Value} | Tail], Template, Update) ->
+ format_updates(Tail, [Name | Template], [value_to_list(Value) | Update]).
+
+value_to_list(unknown) ->
+ "U";
+value_to_list(Value) when is_list(Value) ->
+ Value;
+value_to_list(Value) when is_atom(Value) ->
+ atom_to_list(Value);
+value_to_list(Value) when is_integer(Value) ->
+ integer_to_list(Value);
+value_to_list(Value) when is_float(Value) ->
+ float_to_list(Value);
+value_to_list(Value) when is_binary(Value) ->
+ binary_to_list(Value).
+
join_test() ->
?assert(string:join(["This", "is", "a", "test."], " ") == "This is a test."),
?assert(string:join(["test."], " ") == "test.").
+
+% vim: set ts=4 sw=4 expandtab:
View
@@ -49,8 +49,7 @@ parse_rra(Rrd, _) ->
Rrd. %% Not implemented.
parse_ds_name(Rrd, Ds, [Line|Lines]) ->
- {match, _,_,
- {{_,_,Name},{_,_,Type}}} = re:first_smatch(Line, "ds\\[(.*)\\].type = \"(.*)\""),
+ {match, [Name, Type]} = re:run(Line, "ds\\[(.*)\\].type = \"(.*)\"", [{capture, all_but_first, list}]),
parse_ds_min_heartbeat(Rrd, Ds#rrd_ds{name=Name,type=Type},
Lines).
@@ -86,7 +85,7 @@ parse_ds_unknown_sec(Rrd, Ds, [Line|Lines]) ->
re_find(String, Re) ->
- {match, [Match]} = re:run(String, Re, [{capture, first, list}]),
+ {match, [Match]} = re:run(String, Re, [{capture, all_but_first, list}]),
Match.
re_find_float(String, Re) ->
@@ -100,3 +99,5 @@ re_find_float(String, Re) ->
%%====================================================================
%% Internal functions
%%====================================================================
+
+% vim: set ts=4 sw=4 expandtab:
View
@@ -18,9 +18,11 @@
%% External exports
%%--------------------------------------------------------------------
-export([start_link/0
+ ,start/0
,stop/1
,cd/2
,raw/2
+ ,info/2
,format_raw/3
,command/2
]).
@@ -53,6 +55,14 @@
start_link() ->
gen_server:start_link(?MODULE, [], []).
+%%--------------------------------------------------------------------
+%% @doc Starts the server.
+%% @spec start() -> {ok, pid()} | {error, Reason}
+%% @end
+%%--------------------------------------------------------------------
+start() ->
+ gen_server:start(?MODULE, [], []).
+
%%--------------------------------------------------------------------
%% @doc Stops the server.
%% @spec stop(Pid::pid()) -> ok
@@ -64,6 +74,14 @@ stop(Server) ->
cd(Server, Directory) ->
gen_server:call(Server, {cd, Directory}).
+info(Server, Filename) ->
+ case gen_server:call(Server, {info, Filename}) of
+ {ok, Data} ->
+ errd_info:parse(Data);
+ Other ->
+ Other
+ end.
+
raw(Server, Str) ->
gen_server:call(Server, {raw, Str}).
@@ -114,6 +132,9 @@ handle_call({raw, Cmd}, _From, State=#state{rrd_port=Port}) ->
handle_call({cd, Directory}, _From, State=#state{rrd_port=Port}) ->
Result = rrd_command(Port, "cd ~s~n", [Directory]),
{reply, Result, State};
+handle_call({info, Filename}, _From, State=#state{rrd_port=Port}) ->
+ Result = rrd_command(Port, "info ~s~n", [Filename]),
+ {reply, Result, State};
handle_call(stop, _From, State) ->
{stop, normal, ok, State};
handle_call(Request, _From, State) ->
@@ -199,3 +220,5 @@ rrd_cmd_test() ->
{ok, Pid} = ?MODULE:start_link(),
?assertMatch({ok, []}, gen_server:call(Pid, {cd, "/"})),
?MODULE:stop(Pid).
+
+% vim: set ts=4 sw=4 expandtab:
View
@@ -52,3 +52,5 @@ init([]) ->
%%====================================================================
%% Internal functions
%%====================================================================
+
+% vim: set ts=4 sw=4 expandtab:
View
@@ -35,7 +35,7 @@
%%====================================================================
%%--------------------------------------------------------------------
%% @doc Starts the supervisor.
-%% @spec start_link(StartArgs) -> {ok, pid()} | Error
+%% @spec start_link() -> {ok, pid()} | Error
%% @end
%%--------------------------------------------------------------------
start_link() ->
@@ -70,3 +70,5 @@ init([]) ->
%%====================================================================
%% Internal functions
%%====================================================================
+
+% vim: set ts=4 sw=4 expandtab:
View
@@ -65,9 +65,11 @@ delete(PathName) ->
%%====================================================================
errdb_test() ->
- ?assertMatch(false, filelib:is_dir("priv/test")),
- ?assertMatch(ok, create("priv/test", [test])),
- ?assertMatch({ok, {"priv/test/data.rrd",
+ ?assertMatch(false, filelib:is_dir("../priv/test")),
+ ?assertMatch(ok, create("../priv/test", [test])),
+ ?assertMatch({ok, {"../priv/test/data.rrd",
[test]}},
- read("priv/test")),
- ?assertMatch(ok, delete("priv/test")).
+ read("../priv/test")),
+ ?assertMatch(ok, delete("../priv/test")).
+
+% vim: set ts=4 sw=4 expandtab:

0 comments on commit e88239c

Please sign in to comment.