summaryrefslogtreecommitdiffstats
path: root/src/status.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-09-12 16:53:24 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-09-12 16:53:24 +0200
commit7ebbe05f46e1b8530a61dd144a4bf36a1c63a4a3 (patch)
treeb06313240468ccee6923366d66eebf583e029162 /src/status.c
parentd116950984d78392e1daf0adfd89f6cdb4fe8076 (diff)
downloadfastd-7ebbe05f46e1b8530a61dd144a4bf36a1c63a4a3.tar
fastd-7ebbe05f46e1b8530a61dd144a4bf36a1c63a4a3.zip
Add per-peer stats
Diffstat (limited to 'src/status.c')
-rw-r--r--src/status.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/status.c b/src/status.c
index e36c2af..0e688a5 100644
--- a/src/status.c
+++ b/src/status.c
@@ -75,8 +75,8 @@ static void * dump_thread(void *p) {
}
-/** Dumps a fastd_stats_t as a JSON object */
-static json_object * dump_stats(const fastd_stats_t *stats, fastd_stat_type_t type) {
+/** Dumps a single traffic stat as a JSON object */
+static json_object * dump_stat(const fastd_stats_t *stats, fastd_stat_type_t type) {
struct json_object *ret = json_object_new_object();
json_object_object_add(ret, "packets", json_object_new_int64(stats->packets[type]));
@@ -85,6 +85,21 @@ static json_object * dump_stats(const fastd_stats_t *stats, fastd_stat_type_t ty
return ret;
}
+/** Dumps a fastd_stats_t as a JSON object */
+static json_object * dump_stats(const fastd_stats_t *stats) {
+ struct json_object *statistics = json_object_new_object();
+
+ json_object_object_add(statistics, "rx", dump_stat(stats, STAT_RX));
+ json_object_object_add(statistics, "rx_reordered", dump_stat(stats, STAT_RX_REORDERED));
+
+ json_object_object_add(statistics, "tx", dump_stat(stats, STAT_TX));
+ json_object_object_add(statistics, "tx_dropped", dump_stat(stats, STAT_TX_DROPPED));
+ json_object_object_add(statistics, "tx_error", dump_stat(stats, STAT_TX_ERROR));
+
+ return statistics;
+}
+
+
/** Dumps a peer's status as a JSON object */
static json_object * dump_peer(const fastd_peer_t *peer) {
struct json_object *ret = json_object_new_object();
@@ -109,6 +124,8 @@ static json_object * dump_peer(const fastd_peer_t *peer) {
json_object_object_add(connection, "method", method);
+ json_object_object_add(connection, "statistics", dump_stats(&peer->stats));
+
if (conf.mode == MODE_TAP) {
struct json_object *mac_addresses = json_object_new_array();
json_object_object_add(connection, "mac_addresses", mac_addresses);
@@ -141,15 +158,7 @@ static json_object * dump_peer(const fastd_peer_t *peer) {
static void dump_status(int fd) {
struct json_object *json = json_object_new_object();
- struct json_object *statistics = json_object_new_object();
- json_object_object_add(json, "statistics", statistics);
-
- json_object_object_add(statistics, "rx", dump_stats(&ctx.stats, STAT_RX));
- json_object_object_add(statistics, "rx_reordered", dump_stats(&ctx.stats, STAT_RX_REORDERED));
-
- json_object_object_add(statistics, "tx", dump_stats(&ctx.stats, STAT_TX));
- json_object_object_add(statistics, "tx_dropped", dump_stats(&ctx.stats, STAT_TX_DROPPED));
- json_object_object_add(statistics, "tx_error", dump_stats(&ctx.stats, STAT_TX_ERROR));
+ json_object_object_add(json, "statistics", dump_stats(&ctx.stats));
struct json_object *peers = json_object_new_object();
json_object_object_add(json, "peers", peers);