Skip to content
Browse files

Emit first value immediately on start, tidy up logging

  • Loading branch information...
1 parent 027faf7 commit 58ca48203f8c0abb11b5e935e54a38060355fe44 @afternoon committed Apr 3, 2011
Showing with 13 additions and 21 deletions.
  1. +1 −6 src/rolf_recorder.erl
  2. +4 −4 src/rolf_rrd.erl
  3. +8 −11 src/rolf_service.erl
View
7 src/rolf_recorder.erl
@@ -54,7 +54,6 @@ store(Sample) -> gen_server:cast({global, ?MODULE}, {store, Sample}).
init([]) ->
process_flag(trap_exit, true),
- error_logger:info_report({rolf_recorder, init}),
% start errd_server
case errd_server:start_link() of
@@ -75,16 +74,12 @@ handle_cast({store, Sample}, #recorder{rrd=RRD}=State) ->
{noreply, State};
handle_cast(Msg, State) ->
- error_logger:info_report({rolf_recorder, handle_cast, Msg}),
{noreply, State}.
handle_info(Info, State) ->
- error_logger:info_report({rolf_recorder, handle_info, Info}),
{noreply, State}.
terminate(Reason, #recorder{rrd=RRD}) ->
- error_logger:info_report({rolf_recorder, terminate, Reason}),
- errd_server:stop(RRD),
- ok.
+ errd_server:stop(RRD).
code_change(_OldVsn, State, _Extra) -> {ok, State}.
View
8 src/rolf_rrd.erl
@@ -37,7 +37,6 @@
%% @doc Ensure data dir and RRD file for Service on Node exist.
ensure(RRD, Node, Service) ->
Path = rrd_path(Node, Service#service.name),
- error_logger:info_report({rolf_rrd, ensure, path, Path}),
case filelib:ensure_dir(Path) of
{error, Reason} ->
error_logger:error_report({rolf_rrd, ensure, Reason}),
@@ -66,12 +65,13 @@ update(RRD, #sample{node=Node, service=Service, values=Values}) ->
%% @doc Send command to RRD server, return ok or {error, Reason}.
send_command(RRD, Cmd) ->
- case errd_server:command(RRD, Cmd) of
+ FormattedCmd = errd_command:format(Cmd),
+ error_logger:info_report({rolf_rrd, send_command, Cmd, FormattedCmd}),
+ case errd_server:raw(RRD, FormattedCmd) of
{error, Reason} ->
error_logger:error_report({rolf_rrd, send_command, Reason}),
{error, Reason};
- {ok, Lines} ->
- error_logger:info_report({rolf_rrd, send_command, Lines}),
+ {ok, _Lines} ->
ok
end.
View
19 src/rolf_service.erl
@@ -54,29 +54,23 @@ publish(Name) -> gen_server:cast({global, server_name(Name)}, publish).
%% publish them to the recorder.
init([Service]) ->
process_flag(trap_exit, true),
- error_logger:info_report({rolf_service, node(), init, Service}),
rolf_recorder:ensure_rrd(node(), Service),
start_emitting(Service).
handle_call(stop, _From, Service) ->
- error_logger:info_report({rolf_service, node(), stop}),
{stop, normal, stopped, Service}.
handle_cast(publish, Service) ->
{M, F, A} = Service#service.mfa,
FullArgs = [Service|A],
- error_logger:info_report({rolf_service, node(), applying, M, F, FullArgs}),
Sample = apply(M, F, FullArgs),
- error_logger:info_report({rolf_service, node(), sending, Sample}),
rolf_recorder:store(Sample),
{noreply, Service}.
-handle_info(Info, Ref) ->
- error_logger:info_report({rolf_service, node(), handle_info, Info}),
+handle_info(_Info, Ref) ->
{noreply, Ref}.
-terminate(Reason, Service) ->
- error_logger:info_report({rolf_service, node(), terminate, Reason}),
+terminate(_Reason, Service) ->
stop_emitting(Service).
code_change(_OldVsn, Service, _Extra) -> {ok, Service}.
@@ -124,11 +118,13 @@ list_to_num(S) ->
end
end.
-%% @doc Start emitting samples.
+%% @doc Start emitting samples. Emit one straight away and then set a timer to
+%% emit regularly.
start_emitting(Service) ->
- error_logger:info_report({rolf_service, node(), start_emitting}),
Name = Service#service.name,
Freq = Service#service.frequency * 1000,
+ error_logger:info_report({rolf_service, node(), start_emitting, Name, Freq}),
+ apply(?MODULE, publish, [Name]),
case timer:apply_interval(Freq, ?MODULE, publish, [Name]) of
{ok, TRef} ->
{ok, Service#service{tref=TRef}};
@@ -138,7 +134,8 @@ start_emitting(Service) ->
%% @doc Stop emitting samples.
stop_emitting(Service) ->
- error_logger:info_report({rolf_service, node(), stop_emitting}),
+ Name = Service#service.name,
+ error_logger:info_report({rolf_service, node(), stop_emitting, Name}),
timer:cancel(Service#service.tref).
%% ===================================================================

0 comments on commit 58ca482

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