mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
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).
This commit is contained in:
committed by
Nick Mathewson
parent
3bc235d979
commit
6661e16e7c
@@ -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.
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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."),
|
||||
|
||||
@@ -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)
|
||||
*/
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user