[sheepdog] [PATCH] sheep: make sheep request stat finer
Liu Yuan
namei.unix at gmail.com
Sat Jan 4 17:46:02 CET 2014
With this patch we can poke more information about the node stat:
$ dog node stat -w
...
Client 12 340681 100459 233694 0 6528 44 GB 26 GB 95 MB 0.0 MB
Peer 6 41013 4008 37005 0 0 8.6 GB 3.9 GB 23 MB 0.0 MB
Request Active Total Write Read Remove Flush All WR All RD WRBW RDBW
Client 5 341362 100459 234375 0 6528 44 GB 26 GB 98 MB 0.0 MB
Peer 0 41128 4008 37120 0 0 8.6 GB 3.9 GB 24 MB 0.0 MB
Request Active Total Write Read Remove Flush All WR All RD WRBW RDBW
Client 0 341969 100459 234982 0 6528 44 GB 26 GB 92 MB 0.0 MB
Peer 0 41220 4008 37212 0 0 8.6 GB 3.9 GB 24 MB 0.0 MB
Request Active Total Write Read Remove Flush All WR All RD WRBW RDBW
Client 8 342584 100459 235597 0 6528 44 GB 26 GB 113 MB 0.0 MB
Peer 0 41335 4008 37327 0 0 8.6 GB 3.9 GB 23 MB 0.0 MB
Request Active Total Write Read Remove Flush All WR All RD WRBW RDBW
Client 6 343069 100460 236081 0 6528 44 GB 26 GB 86 MB 4.0 MB
Peer 2 41429 4009 37420 0 0 8.7 GB 3.9 GB 26 MB 1.0 MB
...
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
dog/node.c | 92 +++++++++++++++++++++++++++++++++---------------
include/internal_proto.h | 7 ++++
sheep/request.c | 37 +++++++++++++++++++
3 files changed, 107 insertions(+), 29 deletions(-)
diff --git a/dog/node.c b/dog/node.c
index f896078..695bd1b 100644
--- a/dog/node.c
+++ b/dog/node.c
@@ -275,9 +275,9 @@ static int node_stat(int argc, char **argv)
{
struct sd_req hdr;
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
- struct sd_stat stat;
+ struct sd_stat stat, last;
int ret;
- uint32_t i = node_cmd_data.watch ? UINT32_MAX : 0;
+ bool watch = node_cmd_data.watch ? true : false, first = true;
again:
sd_init_req(&hdr, SD_OP_STAT);
@@ -292,21 +292,55 @@ again:
return EXIT_FAILURE;
}
- printf("%s%"PRIu64"\t%"PRIu64"\t%s\t%s\n",
- raw_output ? "" :
- "Request\tActive\tTotal\tIn\tOut\nClient\t",
- stat.r.gway_active_nr, stat.r.gway_total_nr,
- strnumber(stat.r.gway_total_rx),
- strnumber(stat.r.gway_total_tx));
- printf("%s%"PRIu64"\t%"PRIu64"\t%s\t%s\n",
- raw_output ? "" : "Peer\t",
- stat.r.peer_active_nr, stat.r.peer_total_nr,
- strnumber(stat.r.peer_total_rx),
- strnumber(stat.r.peer_total_tx));
- if (i > 0) {
- clear_screen();
+ if (watch) {
+ if (first) {
+ last = stat;
+ first = false;
+ }
+ printf("%s%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t"
+ "%"PRIu64"\t%"PRIu64"\t%s\t%s\t%s\t%s\n",
+ raw_output ? "" :
+ "Request\tActive\tTotal\tWrite\tRead\tRemove\tFlush\t"
+ "All WR\tAll RD\tWRBW\tRDBW\nClient\t",
+ stat.r.gway_active_nr, stat.r.gway_total_nr,
+ stat.r.gway_total_read_nr, stat.r.gway_total_write_nr,
+ stat.r.gway_total_remove_nr, stat.r.gway_total_flush_nr,
+ strnumber(stat.r.gway_total_rx),
+ strnumber(stat.r.gway_total_tx),
+ strnumber(stat.r.gway_total_rx - last.r.gway_total_rx),
+ strnumber(stat.r.gway_total_tx - last.r.gway_total_tx));
+ printf("%s%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t"
+ "%"PRIu64"\t%"PRIu64"\t%s\t%s\t%s\t%s\n",
+ raw_output ? "" : "Peer\t",
+ stat.r.peer_active_nr, stat.r.peer_total_nr,
+ stat.r.peer_total_read_nr, stat.r.peer_total_write_nr,
+ stat.r.peer_total_remove_nr, 0UL,
+ strnumber(stat.r.peer_total_rx),
+ strnumber(stat.r.peer_total_tx),
+ strnumber(stat.r.peer_total_rx - last.r.peer_total_rx),
+ strnumber(stat.r.peer_total_tx - last.r.peer_total_tx));
+ last = stat;
sleep(1);
goto again;
+ } else {
+ printf("%s%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t"
+ "%"PRIu64"\t%"PRIu64"\t%s\t%s\n",
+ raw_output ? "" :
+ "Request\tActive\tTotal\tWrite\tRead\tRemove\tFlush\t"
+ "All WR\tAll RD\nClient\t",
+ stat.r.gway_active_nr, stat.r.gway_total_nr,
+ stat.r.gway_total_read_nr, stat.r.gway_total_write_nr,
+ stat.r.gway_total_remove_nr, stat.r.gway_total_flush_nr,
+ strnumber(stat.r.gway_total_rx),
+ strnumber(stat.r.gway_total_tx));
+ printf("%s%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t"
+ "%"PRIu64"\t%"PRIu64"\t%s\t%s\n",
+ raw_output ? "" : "Peer\t",
+ stat.r.peer_active_nr, stat.r.peer_total_nr,
+ stat.r.peer_total_read_nr, stat.r.peer_total_write_nr,
+ stat.r.peer_total_remove_nr, 0UL,
+ strnumber(stat.r.peer_total_rx),
+ strnumber(stat.r.peer_total_tx));
}
return EXIT_SUCCESS;
@@ -407,11 +441,11 @@ static int md_unplug(int argc, char **argv)
static struct subcommand node_md_cmd[] = {
{"info", NULL, NULL, "show multi-disk information",
- NULL, CMD_NEED_NODELIST, md_info},
+ NULL, CMD_NEED_NODELIST, md_info},
{"plug", NULL, NULL, "plug more disk(s) into node",
- NULL, CMD_NEED_ARG, md_plug},
+ NULL, CMD_NEED_ARG, md_plug},
{"unplug", NULL, NULL, "unplug disk(s) from node",
- NULL, CMD_NEED_ARG, md_unplug},
+ NULL, CMD_NEED_ARG, md_unplug},
{NULL},
};
@@ -506,11 +540,11 @@ static int node_log_level_list(int argc, char **argv)
static struct subcommand node_log_level_cmd[] = {
{"set", "<log level>", NULL, "set new loglevel",
- NULL, CMD_NEED_ARG, node_log_level_set},
+ NULL, CMD_NEED_ARG, node_log_level_set},
{"get", NULL, NULL, "get current loglevel",
- NULL, 0, node_log_level_get},
+ NULL, 0, node_log_level_get},
{"list", NULL, NULL, "list available loglevels",
- NULL, 0, node_log_level_list},
+ NULL, 0, node_log_level_list},
{NULL},
};
@@ -521,7 +555,7 @@ static int node_log_level(int argc, char **argv)
static struct subcommand node_log_cmd[] = {
{"level", "<subcommand>", NULL, "manipulate loglevel",
- node_log_level_cmd, CMD_NEED_ARG, node_log_level},
+ node_log_level_cmd, CMD_NEED_ARG, node_log_level},
{NULL},
};
@@ -532,19 +566,19 @@ static int node_log(int argc, char **argv)
static struct subcommand node_cmd[] = {
{"kill", "<node id>", "aprh", "kill node", NULL,
- CMD_NEED_ARG | CMD_NEED_NODELIST, node_kill},
+ CMD_NEED_ARG | CMD_NEED_NODELIST, node_kill},
{"list", NULL, "aprh", "list nodes", NULL,
- CMD_NEED_NODELIST, node_list},
+ CMD_NEED_NODELIST, node_list},
{"info", NULL, "aprh", "show information about each node", NULL,
- CMD_NEED_NODELIST, node_info},
+ CMD_NEED_NODELIST, node_info},
{"recovery", NULL, "aphPr", "show recovery information of nodes", NULL,
- CMD_NEED_NODELIST, node_recovery, node_options},
+ CMD_NEED_NODELIST, node_recovery, node_options},
{"md", "[disks]", "apAh", "See 'dog node md' for more information",
- node_md_cmd, CMD_NEED_ARG, node_md, node_options},
+ node_md_cmd, CMD_NEED_ARG, node_md, node_options},
{"stat", NULL, "aprwh", "show stat information about the node", NULL,
- 0, node_stat, node_options},
+ 0, node_stat, node_options},
{"log", NULL, "aph", "show or set log level of the node", node_log_cmd,
- CMD_NEED_ARG, node_log},
+ CMD_NEED_ARG, node_log},
{NULL,},
};
diff --git a/include/internal_proto.h b/include/internal_proto.h
index 2aefb2d..d32cea7 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -250,6 +250,13 @@ struct sd_stat {
uint64_t gway_total_tx; /* Data out */
uint64_t peer_total_rx;
uint64_t peer_total_tx;
+ uint64_t gway_total_remove_nr;
+ uint64_t gway_total_read_nr;
+ uint64_t gway_total_write_nr;
+ uint64_t gway_total_flush_nr;
+ uint64_t peer_total_remove_nr;
+ uint64_t peer_total_read_nr;
+ uint64_t peer_total_write_nr;
} r;
};
diff --git a/sheep/request.c b/sheep/request.c
index e7d6947..57cd29e 100644
--- a/sheep/request.c
+++ b/sheep/request.c
@@ -367,6 +367,19 @@ static main_fn inline void stat_request_begin(struct request *req)
sys->stat.r.peer_total_rx += hdr->data_length;
else
sys->stat.r.peer_total_tx += hdr->data_length;
+
+ switch (hdr->opcode) {
+ case SD_OP_READ_PEER:
+ sys->stat.r.peer_total_read_nr++;
+ break;
+ case SD_OP_WRITE_PEER:
+ case SD_OP_CREATE_AND_WRITE_PEER:
+ sys->stat.r.peer_total_write_nr++;
+ break;
+ case SD_OP_REMOVE_PEER:
+ sys->stat.r.peer_total_remove_nr++;
+ break;
+ }
} else if (is_gateway_op(req->op)) {
sys->stat.r.gway_total_nr++;
sys->stat.r.gway_active_nr++;
@@ -374,11 +387,33 @@ static main_fn inline void stat_request_begin(struct request *req)
sys->stat.r.gway_total_rx += hdr->data_length;
else
sys->stat.r.gway_total_tx += hdr->data_length;
+
+ switch (hdr->opcode) {
+ case SD_OP_READ_OBJ:
+ sys->stat.r.gway_total_read_nr++;
+ break;
+ case SD_OP_WRITE_OBJ:
+ case SD_OP_CREATE_AND_WRITE_OBJ:
+ sys->stat.r.gway_total_write_nr++;
+ break;
+ case SD_OP_DISCARD_OBJ:
+ sys->stat.r.gway_total_remove_nr++;
+ break;
+ case SD_OP_FLUSH_VDI:
+ sys->stat.r.gway_total_flush_nr++;
+ break;
+ }
+ } else if (hdr->opcode == SD_OP_FLUSH_VDI) {
+ sys->stat.r.gway_total_nr++;
+ sys->stat.r.gway_active_nr++;
+ sys->stat.r.gway_total_flush_nr++;
}
}
static main_fn inline void stat_request_end(struct request *req)
{
+ struct sd_req *hdr = &req->rq;
+
if (!req->stat)
return;
@@ -386,6 +421,8 @@ static main_fn inline void stat_request_end(struct request *req)
sys->stat.r.peer_active_nr--;
else if (is_gateway_op(req->op))
sys->stat.r.gway_active_nr--;
+ else if (hdr->opcode == SD_OP_FLUSH_VDI)
+ sys->stat.r.gway_active_nr--;
}
static void queue_request(struct request *req)
--
1.8.1.2
More information about the sheepdog
mailing list