diff options
-rw-r--r-- | changes/feature2345 | 4 | ||||
-rw-r--r-- | doc/spec/control-spec.txt | 4 | ||||
-rw-r--r-- | src/or/control.c | 6 | ||||
-rw-r--r-- | src/or/main.c | 14 | ||||
-rw-r--r-- | src/or/main.h | 2 |
5 files changed, 30 insertions, 0 deletions
diff --git a/changes/feature2345 b/changes/feature2345 new file mode 100644 index 0000000000..5ab6a0f013 --- /dev/null +++ b/changes/feature2345 @@ -0,0 +1,4 @@ + o Minor features (controller) + - Add GETINFO options to get total bytes read and written. Patch + from pipe, revised by atagar. Resolves ticket 2345. + diff --git a/doc/spec/control-spec.txt b/doc/spec/control-spec.txt index 45fa3e7c84..bd327dba7f 100644 --- a/doc/spec/control-spec.txt +++ b/doc/spec/control-spec.txt @@ -517,6 +517,10 @@ with a $. This is an implementation error. It would be nice to add the $ back in if we can do so without breaking compatibility.] + "traffic/read" -- Total bytes read (downloaded). + + "traffic/written" -- Total bytes written (uploaded). + "accounting/enabled" "accounting/hibernating" "accounting/bytes" 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 */ |