Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
David Goulet
Tor
Commits
2fe0322f
Commit
2fe0322f
authored
Oct 20, 2020
by
David Goulet
🔆
Browse files
hs: Collect service traffic metrics
Related to #40063 Signed-off-by:
David Goulet
<
dgoulet@torproject.org
>
parent
69595751
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/core/mainloop/connection.c
View file @
2fe0322f
...
...
@@ -99,6 +99,7 @@
#include
"feature/hibernate/hibernate.h"
#include
"feature/hs/hs_common.h"
#include
"feature/hs/hs_ident.h"
#include
"feature/hs/hs_metrics.h"
#include
"feature/metrics/metrics.h"
#include
"feature/nodelist/nodelist.h"
#include
"feature/nodelist/routerlist.h"
...
...
@@ -4149,6 +4150,14 @@ connection_buf_read_from_socket(connection_t *conn, ssize_t *max_to_read,
/* change *max_to_read */
*
max_to_read
=
at_most
-
n_read
;
/* Onion service application connection. Note read bytes for metrics. */
if
(
CONN_IS_EDGE
(
conn
)
&&
TO_EDGE_CONN
(
conn
)
->
hs_ident
)
{
edge_connection_t
*
edge_conn
=
TO_EDGE_CONN
(
conn
);
hs_metrics_app_read_bytes
(
&
edge_conn
->
hs_ident
->
identity_pk
,
edge_conn
->
hs_ident
->
orig_virtual_port
,
n_read
);
}
/* Update edge_conn->n_read */
if
(
conn
->
type
==
CONN_TYPE_AP
)
{
edge_connection_t
*
edge_conn
=
TO_EDGE_CONN
(
conn
);
...
...
src/core/or/relay.c
View file @
2fe0322f
...
...
@@ -83,6 +83,7 @@
#include
"feature/nodelist/describe.h"
#include
"feature/nodelist/routerlist.h"
#include
"core/or/scheduler.h"
#include
"feature/hs/hs_metrics.h"
#include
"core/or/cell_st.h"
#include
"core/or/cell_queue_st.h"
...
...
@@ -1689,6 +1690,13 @@ handle_relay_cell_command(cell_t *cell, circuit_t *circ,
circuit_read_valid_data
(
TO_ORIGIN_CIRCUIT
(
circ
),
rh
->
length
);
}
/* For onion service connection, update the metrics. */
if
(
conn
->
hs_ident
)
{
hs_metrics_app_write_bytes
(
&
conn
->
hs_ident
->
identity_pk
,
conn
->
hs_ident
->
orig_virtual_port
,
rh
->
length
);
}
stats_n_data_bytes_received
+=
rh
->
length
;
connection_buf_add
((
char
*
)(
cell
->
payload
+
RELAY_HEADER_SIZE
),
rh
->
length
,
TO_CONN
(
conn
));
...
...
src/feature/hs/hs_metrics.h
View file @
2fe0322f
...
...
@@ -35,4 +35,12 @@ void hs_metrics_update_by_service(const hs_metrics_key_t key,
#define hs_metrics_new_introduction(s) \
hs_metrics_update_by_service(HS_METRICS_NUM_INTRODUCTIONS, (s), 0, 1)
/** Number of bytes written to the application from the service. */
#define hs_metrics_app_write_bytes(i, port, n) \
hs_metrics_update_by_ident(HS_METRICS_APP_WRITE_BYTES, (i), (port), (n))
/** Number of bytes read from the application to the service. */
#define hs_metrics_app_read_bytes(i, port, n) \
hs_metrics_update_by_ident(HS_METRICS_APP_READ_BYTES, (i), (port), (n))
#endif
/* !defined(TOR_FEATURE_HS_HS_METRICS_H) */
src/feature/hs/hs_metrics_entry.c
View file @
2fe0322f
...
...
@@ -27,6 +27,20 @@ const hs_metrics_entry_t base_metrics[] =
.
help
=
"Total number of introduction received"
,
.
port_as_label
=
false
,
},
{
.
key
=
HS_METRICS_APP_WRITE_BYTES
,
.
type
=
METRICS_TYPE_COUNTER
,
.
name
=
"hs_app_write_bytes_total"
,
.
help
=
"Total number of bytes written to the application"
,
.
port_as_label
=
true
,
},
{
.
key
=
HS_METRICS_APP_READ_BYTES
,
.
type
=
METRICS_TYPE_COUNTER
,
.
name
=
"hs_app_read_bytes_total"
,
.
help
=
"Total number of bytes read from the application"
,
.
port_as_label
=
true
,
},
};
/** Size of base_metrics array that is number of entries. */
...
...
src/feature/hs/hs_metrics_entry.h
View file @
2fe0322f
...
...
@@ -17,6 +17,10 @@
typedef
enum
{
/** Number of introduction requests. */
HS_METRICS_NUM_INTRODUCTIONS
=
0
,
/** Number of bytes written from onion service to application. */
HS_METRICS_APP_WRITE_BYTES
=
1
,
/** Number of bytes read from application to onion service. */
HS_METRICS_APP_READ_BYTES
=
2
,
}
hs_metrics_key_t
;
/** The metadata of an HS metrics. */
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment