diff --git a/src/command.c b/src/command.c index 60745d5..d8a1ac0 100644 --- a/src/command.c +++ b/src/command.c @@ -185,6 +185,8 @@ static int cmd_format_stats(char *dest, size_t n, struct stats *stats, char *lat "remote_latency:%.6f\r\n" "total_latency:%.6f\r\n" "last_command_latency:%s\r\n" + "ask_recv:%lld\r\n" + "moved_recv:%lld\r\n" "remotes:%s\r\n", config.cluster, VERSION, getpid(), config.thread, CV_MALLOC_LIB, @@ -195,6 +197,8 @@ static int cmd_format_stats(char *dest, size_t n, struct stats *stats, char *lat stats->basic.recv_bytes, stats->basic.send_bytes, stats->basic.remote_latency / 1000000.0, stats->basic.total_latency / 1000000.0, latency, + stats->basic.ask_recv, + stats->basic.moved_recv, stats->remote_nodes); } diff --git a/src/server.c b/src/server.c index 89f8a52..820ad81 100644 --- a/src/server.c +++ b/src/server.c @@ -209,10 +209,12 @@ int server_read_reply(struct connection *server, struct command *cmd) } switch (info.type) { case CMD_ERR_MOVED: + ATOMIC_INC(cmd->ctx->stats.moved_recv, 1); slot_create_job(SLOT_UPDATE); CHECK_REDIRECTED(cmd, info.addr, rep_redirect_err); return server_redirect(cmd, &info); case CMD_ERR_ASK: + ATOMIC_INC(cmd->ctx->stats.ask_recv, 1); CHECK_REDIRECTED(cmd, info.addr, rep_redirect_err); cmd->asking = 1; return server_redirect(cmd, &info); diff --git a/src/stats.c b/src/stats.c index 6205983..65530cb 100644 --- a/src/stats.c +++ b/src/stats.c @@ -54,6 +54,8 @@ static inline void stats_copy_basic_fields(struct basic_stats *dst, struct basic dst->total_latency = ATOMIC_GET(src->total_latency); dst->recv_bytes = ATOMIC_GET(src->recv_bytes); dst->send_bytes = ATOMIC_GET(src->send_bytes); + dst->ask_recv = ATOMIC_GET(src->ask_recv); + dst->moved_recv = ATOMIC_GET(src->moved_recv); } static inline void stats_cumulate(struct stats *stats) @@ -64,6 +66,8 @@ static inline void stats_cumulate(struct stats *stats) ATOMIC_INC(cumulation.basic.total_latency, stats->basic.total_latency); ATOMIC_INC(cumulation.basic.recv_bytes, stats->basic.recv_bytes); ATOMIC_INC(cumulation.basic.send_bytes, stats->basic.send_bytes); + ATOMIC_INC(cumulation.basic.ask_recv, stats->basic.ask_recv); + ATOMIC_INC(cumulation.basic.moved_recv, stats->basic.moved_recv); } static void stats_send(char *metric, double value) @@ -143,6 +147,8 @@ void stats_get_simple(struct stats *stats, bool reset) STATS_ASSIGN(total_latency); STATS_ASSIGN(recv_bytes); STATS_ASSIGN(send_bytes); + STATS_ASSIGN(ask_recv); + STATS_ASSIGN(moved_recv); stats->basic.connected_clients += ATOMIC_GET(contexts[i].stats.connected_clients); } diff --git a/src/stats.h b/src/stats.h index ba93a5b..3f79412 100644 --- a/src/stats.h +++ b/src/stats.h @@ -28,6 +28,9 @@ struct basic_stats { long long remote_latency; long long total_latency; + + long long ask_recv; + long long moved_recv; }; struct stats { diff --git a/tests/test_stats.c b/tests/test_stats.c index 31bbcb9..f13e7d8 100644 --- a/tests/test_stats.c +++ b/tests/test_stats.c @@ -11,6 +11,8 @@ void set_stats(struct context *ctx) ctx->stats.recv_bytes = 16; ctx->stats.send_bytes = 32; ctx->stats.connected_clients = 5; + ctx->stats.ask_recv = 233; + ctx->stats.moved_recv = 600; } TEST(test_stats_get_simple_reset) { @@ -29,12 +31,16 @@ TEST(test_stats_get_simple_reset) { ASSERT(stats.basic.recv_bytes == 16); ASSERT(stats.basic.send_bytes == 32); ASSERT(stats.basic.connected_clients == 5); + ASSERT(stats.basic.ask_recv == 233); + ASSERT(stats.basic.moved_recv == 600); ASSERT(ctxs[0].stats.completed_commands == 0); ASSERT(ctxs[0].stats.remote_latency == 0); ASSERT(ctxs[0].stats.total_latency == 0); ASSERT(ctxs[0].stats.recv_bytes == 0); ASSERT(ctxs[0].stats.send_bytes == 0); + ASSERT(ctxs[0].stats.ask_recv == 0); + ASSERT(ctxs[0].stats.moved_recv == 0); PASS(NULL); } @@ -54,6 +60,8 @@ TEST(test_stats_get_simple_cumulative) { ASSERT(stats.basic.recv_bytes == 32); ASSERT(stats.basic.send_bytes == 64); ASSERT(stats.basic.connected_clients == 5); + ASSERT(stats.basic.ask_recv == 466); + ASSERT(stats.basic.moved_recv == 1200); ASSERT(ctxs[0].stats.completed_commands == 10); ASSERT(ctxs[0].stats.remote_latency == 1000); @@ -61,6 +69,8 @@ TEST(test_stats_get_simple_cumulative) { ASSERT(ctxs[0].stats.recv_bytes == 16); ASSERT(ctxs[0].stats.send_bytes == 32); ASSERT(ctxs[0].stats.connected_clients == 5); + ASSERT(ctxs[0].stats.ask_recv == 233); + ASSERT(ctxs[0].stats.moved_recv == 600); PASS(NULL); }