mirror of
https://github.com/btdig/dhtcrawler2.git
synced 2025-01-19 04:31:37 +00:00
add torrent download stats in hash reader, to debug something
This commit is contained in:
parent
9d8c60f0da
commit
84ec8fd9dc
@ -46,9 +46,11 @@ handle_info({got_torrent, failed, _Hash}, State) ->
|
|||||||
Conn = db_conn(State),
|
Conn = db_conn(State),
|
||||||
try_next_download(Conn),
|
try_next_download(Conn),
|
||||||
?T(?FMT("got torrent failed ~s", [_Hash])),
|
?T(?FMT("got torrent failed ~s", [_Hash])),
|
||||||
|
hash_reader_stats:handle_download_failed(),
|
||||||
{noreply, State#state{downloading = D - 1}};
|
{noreply, State#state{downloading = D - 1}};
|
||||||
|
|
||||||
handle_info({got_torrent, ok, Hash, Content}, State) ->
|
handle_info({got_torrent, ok, Hash, Content}, State) ->
|
||||||
|
hash_reader_stats:handle_download_ok(),
|
||||||
Conn = db_conn(State),
|
Conn = db_conn(State),
|
||||||
true = is_binary(Content),
|
true = is_binary(Content),
|
||||||
% save the torrent file
|
% save the torrent file
|
||||||
|
@ -17,8 +17,12 @@
|
|||||||
handle_update/0,
|
handle_update/0,
|
||||||
handle_insert/0,
|
handle_insert/0,
|
||||||
handle_used_cache/0,
|
handle_used_cache/0,
|
||||||
|
handle_download_ok/0,
|
||||||
|
handle_download_failed/0,
|
||||||
dump/0]).
|
dump/0]).
|
||||||
-record(state, {tref, count, start, name, cache_used = 0, updated = 0, inserted = 0}).
|
-record(state, {tref, count, start, name, cache_used = 0,
|
||||||
|
updated = 0, inserted = 0,
|
||||||
|
download_ok = 0, download_failed = 0}).
|
||||||
-define(STATS_INTERVAL, 10*60*1000).
|
-define(STATS_INTERVAL, 10*60*1000).
|
||||||
-define(TEXT(Fmt, Arg), lists:flatten(io_lib:format(Fmt, Arg))).
|
-define(TEXT(Fmt, Arg), lists:flatten(io_lib:format(Fmt, Arg))).
|
||||||
|
|
||||||
@ -43,6 +47,12 @@ handle_insert() ->
|
|||||||
handle_used_cache() ->
|
handle_used_cache() ->
|
||||||
gen_server:cast(srv_name(), inc_cache_used).
|
gen_server:cast(srv_name(), inc_cache_used).
|
||||||
|
|
||||||
|
handle_download_ok() ->
|
||||||
|
gen_server:cast(srv_name(), inc_download_ok).
|
||||||
|
|
||||||
|
handle_download_failed() ->
|
||||||
|
gen_server:cast(srv_name(), inc_download_failed).
|
||||||
|
|
||||||
srv_name() ->
|
srv_name() ->
|
||||||
?MODULE.
|
?MODULE.
|
||||||
|
|
||||||
@ -82,6 +92,14 @@ handle_cast(inc_cache_used, State) ->
|
|||||||
#state{cache_used = C} = State,
|
#state{cache_used = C} = State,
|
||||||
{noreply, State#state{cache_used = C + 1}};
|
{noreply, State#state{cache_used = C + 1}};
|
||||||
|
|
||||||
|
handle_cast(inc_download_ok, State) ->
|
||||||
|
#state{download_ok = D} = State,
|
||||||
|
{noreply, State#state{download_ok = D + 1}};
|
||||||
|
|
||||||
|
handle_cast(inc_download_failed, State) ->
|
||||||
|
#state{download_failed = D} = State,
|
||||||
|
{noreply, State#state{download_failed = D + 1}};
|
||||||
|
|
||||||
handle_cast(stop, State) ->
|
handle_cast(stop, State) ->
|
||||||
{stop, normal, State}.
|
{stop, normal, State}.
|
||||||
|
|
||||||
@ -112,7 +130,9 @@ date_string() ->
|
|||||||
[Year, Month, Day, Hour, Min, Sec])).
|
[Year, Month, Day, Hour, Min, Sec])).
|
||||||
|
|
||||||
format_stats(State) ->
|
format_stats(State) ->
|
||||||
#state{count = C, start = Start, cache_used = Cache, updated = U, inserted = I} = State,
|
#state{count = C, start = Start, cache_used = Cache,
|
||||||
|
download_ok = DO, download_failed = DF,
|
||||||
|
updated = U, inserted = I} = State,
|
||||||
{Day, {H, M, S}} = stats_time(Start),
|
{Day, {H, M, S}} = stats_time(Start),
|
||||||
Mins = Day * 24 * 60 + H * 60 + M,
|
Mins = Day * 24 * 60 + H * 60 + M,
|
||||||
TotalMins = if Mins > 0 -> Mins; true -> 1 end,
|
TotalMins = if Mins > 0 -> Mins; true -> 1 end,
|
||||||
@ -124,6 +144,8 @@ format_stats(State) ->
|
|||||||
?TEXT(" Reader count ~p~n", [C]) ++
|
?TEXT(" Reader count ~p~n", [C]) ++
|
||||||
?TEXT(" Process speed ~p req/min~n", [Speed]) ++
|
?TEXT(" Process speed ~p req/min~n", [Speed]) ++
|
||||||
?TEXT(" Download torrents speed ~p tor/min~n", [I div TotalMins]) ++
|
?TEXT(" Download torrents speed ~p tor/min~n", [I div TotalMins]) ++
|
||||||
|
?TEXT(" Download success ~p~n", [DO]) ++
|
||||||
|
?TEXT(" Download failed ~p~n", [DF]) ++
|
||||||
?TEXT(" Updated ~p~n", [U]) ++
|
?TEXT(" Updated ~p~n", [U]) ++
|
||||||
?TEXT(" Inserted ~p~n", [I]) ++
|
?TEXT(" Inserted ~p~n", [I]) ++
|
||||||
?TEXT(" Inserted percentage ~.2f%~n", [InsertPercent]) ++
|
?TEXT(" Inserted percentage ~.2f%~n", [InsertPercent]) ++
|
||||||
@ -145,5 +167,3 @@ format_download_stats() ->
|
|||||||
?TEXT(" Download speed ~p tor/secs~n", [TorSpeed]) ++
|
?TEXT(" Download speed ~p tor/secs~n", [TorSpeed]) ++
|
||||||
?TEXT(" Current wait requests ~p~n", [CurrentReqCount]).
|
?TEXT(" Current wait requests ~p~n", [CurrentReqCount]).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user