diff options
-rw-r--r-- | agni.c | 39 | ||||
-rw-r--r-- | cmd/cmd_stat.c | 55 | ||||
-rw-r--r-- | cmd/cmd_stat.h | 13 | ||||
-rw-r--r-- | config_cmds.h | 1 | ||||
-rw-r--r-- | stat.c | 43 | ||||
-rw-r--r-- | stat.h | 28 |
6 files changed, 174 insertions, 5 deletions
@@ -30,6 +30,7 @@ #include "sock_conn.h" #include "irc_parse.h" #include "mmm.h" +#include "stat.h" #include "arg.h" @@ -233,6 +234,10 @@ int th_start_client(void *data) nb_resp = malloc(sizeof(netbyte_store)); + //collect stats + stat_server stats; + memset(&stats, 0, sizeof(stat_server)); + atomic_fetch_add(&cfg->running,1); printf("Start client\n"); printf("Server %d\n",cfg->tid); @@ -283,12 +288,14 @@ int th_start_client(void *data) ENL(); } //PRINT("SERVER:%s PORT:%s USER:%s\n", cfg->server, cfg->port, cfg->user); + PRINT("out_attr.mq_msgsize %d\n", out_attr.mq_msgsize); out_buf = malloc(out_attr.mq_msgsize); - memset(out_buf, 0, out_attr.mq_msgsize); + if (out_buf == NULL) { - ENL(); + ERROR("Can allocate out_buf, size of %d\n", out_attr.mq_msgsize); } + memset(out_buf, 0, out_attr.mq_msgsize); //PRINT("SERVER:%s PORT:%s USER:%s\n", cfg->server, cfg->port, cfg->user); if (mq_ntf_getattr(mq, MQ_IN, &ptr_in_attr) == -1) @@ -659,7 +666,9 @@ int th_event_manager(void *data) PERM(); } - + //collect stats + stat_event stats; + memset(&stats, 0, sizeof(stat_event)); //load predefined/precompiled command list { @@ -788,7 +797,21 @@ int th_event_manager(void *data) if (tbl_exec_in_s(etbl, req->params+1)>=0) { void *ret_msg = NULL; - if (tbl_exec_run(etbl, req->params+1, &ret_msg)>=0) + + //special set of commands + sds exec_params; + exec_params = sdsempty(); + + exec_params = sdscat(exec_params, req->params+1); + if (0 == strncmp(exec_params,"STAT",4)) + { + char *stat_str = stat_event2str(&stats); + exec_params = sdscat(exec_params, " "); + exec_params = sdscat(exec_params, stat_str); + FREE(stat_str); + } + + if (tbl_exec_run(etbl, exec_params, &ret_msg)>=0) { if (ret_msg != NULL) { @@ -800,17 +823,23 @@ int th_event_manager(void *data) buf_nb = nb_create(nb_resp); mq_ntf_write(mq_cur, MQ_IN, buf_nb, nb_resp->size > in_attr.mq_msgsize ? in_attr.mq_msgsize : nb_resp->size); + stats.cnt_ipc_tx += nb_resp->size > in_attr.mq_msgsize ? in_attr.mq_msgsize : nb_resp->size; FREE(buf_nb); printf("EVENT-Write %d bytes\n", nb_resp->size > in_attr.mq_msgsize ? in_attr.mq_msgsize : nb_resp->size); FREE(ret_msg); nb_free(nb_resp); rpc_resp_free(resp); + + stats.cnt_cmd_succ += 1; } } else { ERROR("Command execution error\n"); - } + stats.cnt_cmd_err += 1; + } + + sdsfree(exec_params); } else { PRINT("Command not in a table\n"); diff --git a/cmd/cmd_stat.c b/cmd/cmd_stat.c new file mode 100644 index 0000000..ce19085 --- /dev/null +++ b/cmd/cmd_stat.c @@ -0,0 +1,55 @@ +#include "cmd_stat.h" + +void *cmd_stat(void *data) +{ + char *param = (char *)data; + char *ret = NULL; + + int i; + int count; + sds params; + sds out_result; + sds *tokens; + + const int buf_size = 128; + char buf[buf_size+1]; + + printf("STAT\n"); + + params = sdsnew(param); + out_result = sdsempty(); + tokens = sdssplitargs(params, &count); + + out_result = sdscat(out_result,"+----------+----------+\n"); + out_result = sdscat(out_result,"| STAT | VAL |\n"); + out_result = sdscat(out_result,"+----------+----------+\n"); + + //cmd_success + snprintf(buf,buf_size,"| CMD_SUCC | %08s |\n", tokens[0]); + out_result = sdscat(out_result, buf); + //cmd_err + snprintf(buf,buf_size,"| CMD_ERR | %08s |\n", tokens[1]); + out_result = sdscat(out_result, buf); + //ipc tx + snprintf(buf,buf_size,"| IPC_TX | %08s |\n", tokens[2]); + out_result = sdscat(out_result, buf); + //ipc rx + snprintf(buf,buf_size,"| IPC_RX | %08s |\n", tokens[3]); + out_result = sdscat(out_result, buf); + + out_result = sdscat(out_result,"+----------+----------+\n"); + + sdsfreesplitres(tokens, count); + + + //snprintf(buf, buf_size, "%s\n", param); + + + ret = alloc_new_str(out_result); + printf("%s",ret); + + sdsfree(out_result); + sdsfree(params); + + return ret; +} diff --git a/cmd/cmd_stat.h b/cmd/cmd_stat.h new file mode 100644 index 0000000..91d30ff --- /dev/null +++ b/cmd/cmd_stat.h @@ -0,0 +1,13 @@ +#ifndef __CMD_STAT_H +#define __CMD_STAT_H + +#include <stdlib.h> +#include <stdio.h> + +#include "sds.h" +#include "util.h" +#include "debug.h" + +void *cmd_stat(void *data); + +#endif
\ No newline at end of file diff --git a/config_cmds.h b/config_cmds.h index e3ce369..a123ec8 100644 --- a/config_cmds.h +++ b/config_cmds.h @@ -31,6 +31,7 @@ single_cmd_def confgi_cmd_list[] = {"FIR",cmd_fir}, {"HELP",cmd_help}, {"SPI",cmd_spi}, + {"STAT",cmd_stat}, {NULL,NULL} }; @@ -0,0 +1,43 @@ +#include "stat.h" + +char* stat_server2str(stat_server *st) +{ + const int sz = 128; + char *str = calloc(sz, 1); + + if (str == NULL) + { + return NULL; + } + + memset(str, 0, sz); + snprintf(str,sz,"%d,%d,%d,%d,%d", + st->cnt_ping, + st->cnt_serv_tx, + st->cnt_serv_rx, + st->cnt_ipc_tx, + st->cnt_ipc_rx); + + return str; +} + + +char* stat_event2str(stat_event *st) +{ + const int sz = 128; + char *str = calloc(sz, 1); + + if (str == NULL) + { + return NULL; + } + + memset(str, 0, sz); + snprintf(str,sz,"%d %d %d %d", + st->cnt_cmd_succ, + st->cnt_cmd_err, + st->cnt_ipc_tx, + st->cnt_ipc_rx); + + return str; +}
\ No newline at end of file @@ -0,0 +1,28 @@ +#ifndef __AGNI_STAT_H +#define __AGNI_STAT_H + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +typedef struct stat_server +{ + int cnt_ping; + int cnt_serv_tx; + int cnt_serv_rx; + int cnt_ipc_tx; + int cnt_ipc_rx; +} stat_server; + +typedef struct stat_event +{ + int cnt_cmd_succ; + int cnt_cmd_err; + int cnt_ipc_tx; + int cnt_ipc_rx; +} stat_event; + +char* stat_server2str(stat_server *st); +char* stat_event2str(stat_event *st); + +#endif
\ No newline at end of file |