mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-02-10 08:46:58 +08:00
print the per-user RX and TX bytes from occtl
This commit is contained in:
@@ -39,6 +39,8 @@ message user_info_rep
|
||||
repeated string nbns = 19;
|
||||
repeated string routes = 20;
|
||||
repeated string iroutes = 21;
|
||||
optional uint64 rx_bytes = 22;
|
||||
optional uint64 tx_bytes = 23;
|
||||
}
|
||||
|
||||
message user_list_rep
|
||||
|
||||
@@ -329,6 +329,8 @@ static int append_user_info(method_ctx *ctx,
|
||||
|
||||
rep->tls_ciphersuite = ctmp->tls_ciphersuite;
|
||||
rep->dtls_ciphersuite = ctmp->dtls_ciphersuite;
|
||||
rep->rx_bytes = ctmp->bytes_in;
|
||||
rep->tx_bytes = ctmp->bytes_out;
|
||||
|
||||
if (single > 0) {
|
||||
if (ctmp->config.rx_per_sec > 0)
|
||||
|
||||
@@ -560,6 +560,7 @@ int common_info_cmd(UserListRep * args)
|
||||
unsigned at_least_one = 0;
|
||||
int ret = 1, r;
|
||||
unsigned i;
|
||||
char buf[32];
|
||||
|
||||
out = pager_start();
|
||||
|
||||
@@ -605,7 +606,6 @@ int common_info_cmd(UserListRep * args)
|
||||
|
||||
if (args->user[i]->rx_per_sec > 0 || args->user[i]->tx_per_sec > 0) {
|
||||
/* print limits */
|
||||
char buf[32];
|
||||
|
||||
if (args->user[i]->rx_per_sec > 0 && args->user[i]->tx_per_sec > 0) {
|
||||
bytes2human(args->user[i]->rx_per_sec, buf, sizeof(buf), NULL);
|
||||
@@ -624,6 +624,12 @@ int common_info_cmd(UserListRep * args)
|
||||
|
||||
print_iface_stats(args->user[i]->tun, args->user[i]->conn_time, out);
|
||||
|
||||
bytes2human(args->user[i]->rx_bytes, buf, sizeof(buf), NULL);
|
||||
fprintf(out, "\tRX data: %s ", buf);
|
||||
|
||||
bytes2human(args->user[i]->tx_bytes, buf, sizeof(buf), NULL);
|
||||
fprintf(out, "\tTX data: %s\n", buf);
|
||||
|
||||
if (args->user[i]->hostname != NULL && args->user[i]->hostname[0] != 0)
|
||||
fprintf(out, "\tHostname: %s\n", args->user[i]->hostname);
|
||||
|
||||
|
||||
@@ -630,25 +630,31 @@ static void http_req_deinit(worker_st * ws)
|
||||
ws->req.body = NULL;
|
||||
}
|
||||
|
||||
static int send_stats_msg(worker_st * ws)
|
||||
{
|
||||
CliStatsMsg msg = CLI_STATS_MSG__INIT;
|
||||
int ret;
|
||||
|
||||
msg.bytes_in = ws->tun_bytes_in;
|
||||
msg.bytes_out = ws->tun_bytes_out;
|
||||
|
||||
ret = send_msg_to_main(ws, CMD_CLI_STATS, &msg,
|
||||
(pack_size_func)
|
||||
cli_stats_msg__get_packed_size,
|
||||
(pack_func) cli_stats_msg__pack);
|
||||
oclog(ws, LOG_DEBUG,
|
||||
"sending stats (in: %lu, out: %lu) to main",
|
||||
(unsigned long)msg.bytes_in,
|
||||
(unsigned long)msg.bytes_out);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static
|
||||
void exit_worker(worker_st * ws)
|
||||
{
|
||||
/* send statistics to parent */
|
||||
if (ws->auth_state == S_AUTH_COMPLETE) {
|
||||
CliStatsMsg msg = CLI_STATS_MSG__INIT;
|
||||
|
||||
msg.bytes_in = ws->tun_bytes_in;
|
||||
msg.bytes_out = ws->tun_bytes_out;
|
||||
|
||||
send_msg_to_main(ws, CMD_CLI_STATS, &msg,
|
||||
(pack_size_func)
|
||||
cli_stats_msg__get_packed_size,
|
||||
(pack_func) cli_stats_msg__pack);
|
||||
|
||||
oclog(ws, LOG_DEBUG,
|
||||
"sending stats (in: %lu, out: %lu) to main",
|
||||
(unsigned long)msg.bytes_in,
|
||||
(unsigned long)msg.bytes_out);
|
||||
send_stats_msg(ws);
|
||||
}
|
||||
talloc_free(ws->main_pool);
|
||||
closelog();
|
||||
@@ -1027,6 +1033,11 @@ int periodic_check(worker_st * ws, unsigned mtu_overhead, time_t now,
|
||||
}
|
||||
}
|
||||
|
||||
ret = send_stats_msg(ws);
|
||||
if (ret < 0) {
|
||||
oclog(ws, LOG_INFO, "error in sending stats");
|
||||
}
|
||||
|
||||
cleanup:
|
||||
ws->last_periodic_check = now;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user