Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
update healthcheck api with additional checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jkvor committed Dec 14, 2010
1 parent d6f1cad commit b488f03
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/logplex_api.erl
Expand Up @@ -72,8 +72,15 @@ loop(Req) ->
handlers() ->
[{['GET', "/healthcheck"], fun(Req, _Match) ->
authorize(Req),

[throw({500, io_lib:format("Zero ~p child processes running", [Worker])}) || {Worker, 0} <- logplex_stats:workers()],

RegisteredMods = [logplex_grid, logplex_rate_limit, logplex_realtime, logplex_stats, logplex_channel, logplex_token, logplex_drain, logplex_session, logplex_tail, logplex_shard, syslog_acceptor],
[(whereis(Name) == undefined orelse not is_process_alive(whereis(Name))) andalso throw({500, io_lib:format("Process dead: ~p", [Name])}) || Name <- RegisteredMods],

Count = logplex_stats:healthcheck(),
not is_integer(Count) andalso exit({expected_integer, Count}),
not is_integer(Count) andalso throw({500, io_lib:format("Increment healthcheck counter failed: ~p", [Count])}),

{200, integer_to_list(Count)}
end},

Expand Down
2 changes: 1 addition & 1 deletion src/logplex_app.erl
Expand Up @@ -44,7 +44,7 @@ init([]) ->
{ok, {{one_for_one, 5, 10}, [
{logplex_grid, {logplex_grid, start_link, []}, permanent, 2000, worker, [logplex_grid]},
{logplex_rate_limit, {logplex_rate_limit, start_link, []}, permanent, 2000, worker, [logplex_rate_limit]},
%{logplex_realtime, {logplex_realtime, start_link, []}, permanent, 2000, worker, [logplex_realtime]},
{logplex_realtime, {logplex_realtime, start_link, []}, permanent, 2000, worker, [logplex_realtime]},
{logplex_stats, {logplex_stats, start_link, []}, permanent, 2000, worker, [logplex_stats]},

{logplex_channel, {logplex_channel, start_link, []}, permanent, 2000, worker, [logplex_channel]},
Expand Down
8 changes: 4 additions & 4 deletions src/logplex_realtime.erl
Expand Up @@ -35,7 +35,7 @@
message_received=0,
message_processed=0,
message_routed=0,
queue_dropped=0,
work_queue_dropped=0,
drain_buffer_dropped=0,
redis_buffer_dropped=0
}).
Expand Down Expand Up @@ -96,8 +96,8 @@ handle_cast({incr, message_processed, Incr}, #state{message_processed=Count}=Sta
handle_cast({incr, message_routed, Incr}, #state{message_routed=Count}=State) ->
{noreply, State#state{message_routed=Count+Incr}};

handle_cast({incr, queue_dropped, Incr}, #state{queue_dropped=Count}=State) ->
{noreply, State#state{queue_dropped=Count+Incr}};
handle_cast({incr, work_queue_dropped, Incr}, #state{work_queue_dropped=Count}=State) ->
{noreply, State#state{work_queue_dropped=Count+Incr}};

handle_cast({incr, drain_buffer_dropped, Incr}, #state{drain_buffer_dropped=Count}=State) ->
{noreply, State#state{drain_buffer_dropped=Count+Incr}};
Expand All @@ -121,7 +121,7 @@ handle_info(flush, State) ->
{message_received, State#state.message_received},
{message_processed, State#state.message_processed},
{message_routed, State#state.message_routed},
{queue_dropped, State#state.queue_dropped},
{work_queue_dropped, State#state.work_queue_dropped},
{drain_buffer_dropped, State#state.drain_buffer_dropped},
{redis_buffer_dropped, State#state.redis_buffer_dropped}
]})),
Expand Down

0 comments on commit b488f03

Please sign in to comment.