diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-09-12 16:53:24 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-09-12 16:53:24 +0200 |
commit | 7ebbe05f46e1b8530a61dd144a4bf36a1c63a4a3 (patch) | |
tree | b06313240468ccee6923366d66eebf583e029162 /src | |
parent | d116950984d78392e1daf0adfd89f6cdb4fe8076 (diff) | |
download | fastd-7ebbe05f46e1b8530a61dd144a4bf36a1c63a4a3.tar fastd-7ebbe05f46e1b8530a61dd144a4bf36a1c63a4a3.zip |
Add per-peer stats
Diffstat (limited to 'src')
-rw-r--r-- | src/fastd.h | 11 | ||||
-rw-r--r-- | src/peer.c | 2 | ||||
-rw-r--r-- | src/peer.h | 16 | ||||
-rw-r--r-- | src/status.c | 31 |
4 files changed, 38 insertions, 22 deletions
diff --git a/src/fastd.h b/src/fastd.h index 94c9fc7..f38b9e8 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -393,17 +393,6 @@ static inline size_t fastd_max_payload(void) { } } -/** Adds statistics for a single packet of a given size */ -static inline void fastd_stats_add(UNUSED fastd_peer_t *peer, UNUSED fastd_stat_type_t stat, UNUSED size_t bytes) { -#ifdef WITH_STATUS_SOCKET - if (!bytes) - return; - - ctx.stats.packets[stat]++; - ctx.stats.bytes[stat] += bytes; -#endif -} - /** Checks if a fastd_peer_address_t is an IPv6 link-local address */ static inline bool fastd_peer_address_is_v6_ll(const fastd_peer_address_t *addr) { return (addr->sa.sa_family == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&addr->in6.sin6_addr)); @@ -321,6 +321,8 @@ static void reset_peer(fastd_peer_t *peer) { fastd_peer_hashtable_remove(peer); + memset(&peer->stats, 0, sizeof(peer->stats)); + peer->address.sa.sa_family = AF_UNSPEC; peer->local_address.sa.sa_family = AF_UNSPEC; peer->state = STATE_INACTIVE; @@ -72,6 +72,8 @@ struct fastd_peer { fastd_timeout_t timeout; /**< The timeout after which the peer is reset */ fastd_timeout_t keepalive_timeout; /**< The timeout after which a keepalive is sent to the peer */ + fastd_stats_t stats; /**< Traffic statistics */ + const fastd_peer_group_t *group; /**< The peer group the peer belongs to */ VECTOR(fastd_remote_t) remotes; /**< The vector of the peer's remotes */ @@ -270,3 +272,17 @@ fastd_peer_t * fastd_peer_find_by_eth_addr(fastd_eth_addr_t addr); void fastd_peer_handle_handshake_queue(void); void fastd_peer_maintenance(void); + +/** Adds statistics for a single packet of a given size */ +static inline void fastd_stats_add(UNUSED fastd_peer_t *peer, UNUSED fastd_stat_type_t stat, UNUSED size_t bytes) { +#ifdef WITH_STATUS_SOCKET + if (!bytes) + return; + + ctx.stats.packets[stat]++; + ctx.stats.bytes[stat] += bytes; + + peer->stats.packets[stat]++; + peer->stats.bytes[stat] += bytes; +#endif +} 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); |