diff options
author | Peter Retzlaff <peter.retzlaff@student.hpi.uni-potsdam.de> | 2013-06-12 10:51:39 +0200 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-08-21 13:26:57 -0400 |
commit | a337d4b7cb9ae7f4e4ec4567b9efd64bbed70298 (patch) | |
tree | 43fb710e70706a1de7b02258b1e1170162dee355 /src/or/status.c | |
parent | 28485d33ca64ee3989f6993a1c30f265be9e324f (diff) | |
download | tor-a337d4b7cb9ae7f4e4ec4567b9efd64bbed70298.tar.gz tor-a337d4b7cb9ae7f4e4ec4567b9efd64bbed70298.zip |
Print accounting information in heartbeat messages.
Implements ticket 5526.
Diffstat (limited to 'src/or/status.c')
-rw-r--r-- | src/or/status.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/or/status.c b/src/or/status.c index 577587d452..2fda471947 100644 --- a/src/or/status.c +++ b/src/or/status.c @@ -15,6 +15,7 @@ #include "circuitlist.h" #include "main.h" #include "hibernate.h" +#include "statefile.h" /** Return the total number of circuits. */ static int @@ -111,6 +112,10 @@ log_heartbeat(time_t now) uptime, count_circuits(),bw_sent,bw_rcvd, hibernating?" We are currently hibernating.":""); + if (server_mode(options) && accounting_is_enabled(options) && !hibernating) { + log_accounting(now, options); + } + if (stats_n_data_cells_packaged && !hibernating) log_notice(LD_HEARTBEAT, "Average packaged cell fullness: %2.3f%%", 100*(U64_TO_DBL(stats_n_data_bytes_packaged) / @@ -128,3 +133,26 @@ log_heartbeat(time_t now) return 0; } +void +log_accounting(const time_t now, const or_options_t *options) +{ + or_state_t *state = get_or_state(); + char *acc_rcvd = bytes_to_usage(state->AccountingBytesReadInInterval); + char *acc_sent = bytes_to_usage(state->AccountingBytesWrittenInInterval); + char *acc_max = bytes_to_usage(options->AccountingMax); + time_t interval_end = accounting_get_end_time(); + char end_buf[ISO_TIME_LEN + 1]; + char *remaining = NULL; + format_local_iso_time(end_buf, interval_end); + remaining = secs_to_uptime(interval_end - now); + + log_notice(LD_HEARTBEAT, "Heartbeat: " + "Sent: %s / %s, Received: %s / %s. The " + "current accounting period ends on %s. That's %s left to go.", + acc_sent, acc_max, acc_rcvd, acc_max, end_buf, remaining); + + tor_free(acc_rcvd); + tor_free(acc_sent); + tor_free(acc_max); + tor_free(remaining); +} |