Skip to content

Commit

Permalink
Add conn/stats commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsonkey committed May 2, 2018
1 parent 2e8de1d commit 7a83be0
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
64 changes: 64 additions & 0 deletions core/lb_proto_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <rte_ip.h>
#include <rte_log.h>
#include <rte_mbuf.h>
#include <rte_mempool.h>
#include <rte_tcp.h>

#include <unixctl_command.h>
Expand Down Expand Up @@ -718,3 +719,66 @@ tcp_conn_dump_cmd_cb(int fd, __attribute__((unused)) char *argv[],

UNIXCTL_CMD_REGISTER("tcp/conn/dump", "", "Dump TCP connections.", 0, 0,
tcp_conn_dump_cmd_cb);

static void
tcp_conn_stats_normal(int fd) {
uint32_t lcore_id;
struct lb_conn_table *ct;

unixctl_command_reply(fd, " ");
RTE_LCORE_FOREACH_SLAVE(lcore_id) {
unixctl_command_reply(fd, "lcore%-5u ", lcore_id);
}
unixctl_command_reply(fd, "\n");

unixctl_command_reply(fd, "avail_conns ");
RTE_LCORE_FOREACH_SLAVE(lcore_id) {
ct = &lb_conn_tbls[lcore_id];
unixctl_command_reply(fd, "%-10u ", rte_mempool_avail_count(ct->mp));
}
unixctl_command_reply(fd, "\n");

unixctl_command_reply(fd, "inuse_conns ");
RTE_LCORE_FOREACH_SLAVE(lcore_id) {
ct = &lb_conn_tbls[lcore_id];
unixctl_command_reply(fd, "%-10u ", rte_mempool_in_use_count(ct->mp));
}
unixctl_command_reply(fd, "\n");
}

static void
tcp_conn_stats_json(int fd) {
uint32_t lcore_id;
struct lb_conn_table *ct;
uint8_t json_first_obj = 1;

unixctl_command_reply(fd, "[");
RTE_LCORE_FOREACH_SLAVE(lcore_id) {
ct = &lb_conn_tbls[lcore_id];
if (json_first_obj) {
json_first_obj = 0;
unixctl_command_reply(fd, "{");
} else {
unixctl_command_reply(fd, ",{");
}
unixctl_command_reply(fd, JSON_KV_32_FMT("lcore", ","), lcore_id);
unixctl_command_reply(fd, JSON_KV_32_FMT("avail_conns", ","),
rte_mempool_avail_count(ct->mp));
unixctl_command_reply(fd, JSON_KV_32_FMT("inuse_conns", ""),
rte_mempool_in_use_count(ct->mp));
unixctl_command_reply(fd, "}");
}
unixctl_command_reply(fd, "]\n");
}

static void
tcp_conn_stats_cmd_cb(int fd, char *argv[], int argc) {
if (argc > 0 && strcmp(argv[0], "--json") == 0)
tcp_conn_stats_json(fd);
else
tcp_conn_stats_normal(fd);
}

UNIXCTL_CMD_REGISTER("tcp/conn/stats", "[--json].",
"Show the number of TCP connections.", 0, 1,
tcp_conn_stats_cmd_cb);
64 changes: 64 additions & 0 deletions core/lb_proto_udp.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* Copyright (c) 2018. TIG developer. */

#include <rte_ip.h>
#include <rte_mempool.h>
#include <rte_udp.h>

#include <unixctl_command.h>
Expand Down Expand Up @@ -220,3 +221,66 @@ udp_conn_dump_cmd_cb(int fd, __attribute__((unused)) char *argv[],

UNIXCTL_CMD_REGISTER("udp/conn/dump", "", "Dump UDP connections.", 0, 0,
udp_conn_dump_cmd_cb);

static void
udp_conn_stats_normal(int fd) {
uint32_t lcore_id;
struct lb_conn_table *ct;

unixctl_command_reply(fd, " ");
RTE_LCORE_FOREACH_SLAVE(lcore_id) {
unixctl_command_reply(fd, "lcore%-5u ", lcore_id);
}
unixctl_command_reply(fd, "\n");

unixctl_command_reply(fd, "avail_conns ");
RTE_LCORE_FOREACH_SLAVE(lcore_id) {
ct = &lb_conn_tbls[lcore_id];
unixctl_command_reply(fd, "%-10u ", rte_mempool_avail_count(ct->mp));
}
unixctl_command_reply(fd, "\n");

unixctl_command_reply(fd, "inuse_conns ");
RTE_LCORE_FOREACH_SLAVE(lcore_id) {
ct = &lb_conn_tbls[lcore_id];
unixctl_command_reply(fd, "%-10u ", rte_mempool_in_use_count(ct->mp));
}
unixctl_command_reply(fd, "\n");
}

static void
udp_conn_stats_json(int fd) {
uint32_t lcore_id;
struct lb_conn_table *ct;
uint8_t json_first_obj = 1;

unixctl_command_reply(fd, "[");
RTE_LCORE_FOREACH_SLAVE(lcore_id) {
ct = &lb_conn_tbls[lcore_id];
if (json_first_obj) {
json_first_obj = 0;
unixctl_command_reply(fd, "{");
} else {
unixctl_command_reply(fd, ",{");
}
unixctl_command_reply(fd, JSON_KV_32_FMT("lcore", ","), lcore_id);
unixctl_command_reply(fd, JSON_KV_32_FMT("avail_conns", ","),
rte_mempool_avail_count(ct->mp));
unixctl_command_reply(fd, JSON_KV_32_FMT("inuse_conns", ""),
rte_mempool_in_use_count(ct->mp));
unixctl_command_reply(fd, "}");
}
unixctl_command_reply(fd, "]\n");
}

static void
udp_conn_stats_cmd_cb(int fd, char *argv[], int argc) {
if (argc > 0 && strcmp(argv[0], "--json") == 0)
udp_conn_stats_json(fd);
else
udp_conn_stats_normal(fd);
}

UNIXCTL_CMD_REGISTER("udp/conn/stats", "[--json].",
"Show the number of UDP connections.", 0, 1,
udp_conn_stats_cmd_cb);

0 comments on commit 7a83be0

Please sign in to comment.