diff options
author | Karsten Loesing <karsten.loesing@gmx.net> | 2009-08-19 15:41:12 +0200 |
---|---|---|
committer | Karsten Loesing <karsten.loesing@gmx.net> | 2009-08-19 15:41:12 +0200 |
commit | 4e29f3342754fa8802c364b58f7b2f98e983a291 (patch) | |
tree | f570d879362bf688ab1da6290689d1d099656df1 /src/or/main.c | |
parent | 10fbc998e146b271508066e7680cb0cd00a70c63 (diff) | |
download | tor-4e29f3342754fa8802c364b58f7b2f98e983a291.tar tor-4e29f3342754fa8802c364b58f7b2f98e983a291.tar.gz |
Write all statistics to disk exactly every 24 hours.
Diffstat (limited to 'src/or/main.c')
-rw-r--r-- | src/or/main.c | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/src/or/main.c b/src/or/main.c index 403ae9362..16136cb27 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -830,7 +830,7 @@ run_scheduled_events(time_t now) static time_t time_to_clean_caches = 0; static time_t time_to_recheck_bandwidth = 0; static time_t time_to_check_for_expired_networkstatus = 0; - static time_t time_to_dump_buffer_stats = 0; + static time_t time_to_write_stats_files = 0; static time_t time_to_retry_dns_init = 0; or_options_t *options = get_options(); int i; @@ -958,10 +958,44 @@ run_scheduled_events(time_t now) time_to_check_for_expired_networkstatus = now + CHECK_EXPIRED_NS_INTERVAL; } - if (time_to_dump_buffer_stats < now) { - if (get_options()->CellStatistics && time_to_dump_buffer_stats) - dump_buffer_stats(); - time_to_dump_buffer_stats = now + DUMP_BUFFER_STATS_INTERVAL; + /* 1g. Check whether we should write statistics to disk. + */ + if (time_to_write_stats_files >= 0 && time_to_write_stats_files < now) { +#define WRITE_STATS_INTERVAL (24*60*60) + or_options_t *options = get_options(); + if (options->CellStatistics || options->DirReqStatistics || + options->EntryStatistics || options->ExitPortStatistics) { + if (!time_to_write_stats_files) { + /* Initialize stats. */ + if (options->CellStatistics) + rep_hist_buffer_stats_init(now); + if (options->DirReqStatistics) + geoip_dirreq_stats_init(now); + if (options->EntryStatistics) + geoip_entry_stats_init(now); + if (options->ExitPortStatistics) + rep_hist_exit_stats_init(now); + log_notice(LD_CONFIG, "Configured to measure statistics. Look for " + "the *-stats files that will first be written to the " + "data directory in %d hours from now.", + WRITE_STATS_INTERVAL / (60 * 60)); + time_to_write_stats_files = now + WRITE_STATS_INTERVAL; + } else { + /* Write stats to disk. */ + time_to_write_stats_files += WRITE_STATS_INTERVAL; + if (options->CellStatistics) + rep_hist_buffer_stats_write(time_to_write_stats_files); + if (options->DirReqStatistics) + geoip_dirreq_stats_write(time_to_write_stats_files); + if (options->EntryStatistics) + geoip_entry_stats_write(time_to_write_stats_files); + if (options->ExitPortStatistics) + rep_hist_exit_stats_write(time_to_write_stats_files); + } + } else { + /* Never write stats to disk */ + time_to_write_stats_files = -1; + } } /* Remove old information from rephist and the rend cache. */ |