diff options
author | Damian Johnson <atagar@torproject.org> | 2011-01-06 21:53:48 -0800 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-01-07 12:15:14 -0500 |
commit | 6661e16e7ca677cc6063b5aaf25da512d7cda8ad (patch) | |
tree | 907f911566d075f7cfa6d93309f06ade64f8945c /src | |
parent | 3bc235d97975dfa17ca6732a930b28124b92eef5 (diff) | |
download | tor-6661e16e7ca677cc6063b5aaf25da512d7cda8ad.tar.gz tor-6661e16e7ca677cc6063b5aaf25da512d7cda8ad.zip |
GETINFO options for querying traffic usage
This was originally a patch provided by pipe
(http://www.mail-archive.com/or-talk@freehaven.net/msg13085.html) to
provide a method for controllers to query the total amount of traffic
tor has handled (this is a frequently requested piece of information
by relay operators).
Diffstat (limited to 'src')
-rw-r--r-- | src/or/control.c | 6 | ||||
-rw-r--r-- | src/or/main.c | 14 | ||||
-rw-r--r-- | src/or/main.h | 2 |
3 files changed, 22 insertions, 0 deletions
diff --git a/src/or/control.c b/src/or/control.c index 58f4135c82..c895a70a80 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -1350,6 +1350,10 @@ getinfo_helper_misc(control_connection_t *conn, const char *question, return -1; } *answer = tor_dup_ip(addr); + } else if (!strcmp(question, "traffic/read")) { + tor_asprintf(answer, U64_FORMAT, U64_PRINTF_ARG(get_bytes_read())); + } else if (!strcmp(question, "traffic/written")) { + tor_asprintf(answer, U64_FORMAT, U64_PRINTF_ARG(get_bytes_written())); } else if (!strcmp(question, "process/pid")) { int myPid = -1; @@ -1958,6 +1962,8 @@ static const getinfo_item_t getinfo_items[] = { "Number of versioning authorities agreeing on the status of the " "current version"), ITEM("address", misc, "IP address of this Tor host, if we can guess it."), + ITEM("traffic/read", misc, "Bytes read since the process was started."), + ITEM("traffic/written", misc, "Bytes written since the process was started."), ITEM("process/pid", misc, "Process id belonging to the main tor process."), ITEM("process/uid", misc, "User id running the tor process."), ITEM("process/user", misc,"Username under which the tor process is running."), diff --git a/src/or/main.c b/src/or/main.c index 4fcc7156e3..aa97609442 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -398,6 +398,20 @@ get_connection_array(void) return connection_array; } +/** Provides the traffic read and written over the life of the process. */ + +uint64_t +get_bytes_read(void) +{ + return stats_n_bytes_read; +} + +uint64_t +get_bytes_written(void) +{ + return stats_n_bytes_written; +} + /** Set the event mask on <b>conn</b> to <b>events</b>. (The event * mask is a bitmask whose bits are READ_EVENT and WRITE_EVENT) */ diff --git a/src/or/main.h b/src/or/main.h index 550f993bfa..4e15d4dacb 100644 --- a/src/or/main.h +++ b/src/or/main.h @@ -24,6 +24,8 @@ void add_connection_to_closeable_list(connection_t *conn); int connection_is_on_closeable_list(connection_t *conn); smartlist_t *get_connection_array(void); +uint64_t get_bytes_read(void); +uint64_t get_bytes_written(void); typedef enum watchable_events { /* Yes, it is intentional that these match Libevent's EV_READ and EV_WRITE */ |