aboutsummaryrefslogtreecommitdiffstats
path: root/agni.c
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2017-09-07 22:37:43 +0100
committerFreeArtMan <dos21h@gmail.com>2017-09-07 22:37:43 +0100
commit08f96759f9b1d5e8b1dd300971d23f833b819e7c (patch)
treeaa3a4010910b7a0b70e6f551a82911708c001547 /agni.c
parentd8d0925669d1e015f7290caf1a34ad756895b151 (diff)
downloadagni-08f96759f9b1d5e8b1dd300971d23f833b819e7c.tar.gz
agni-08f96759f9b1d5e8b1dd300971d23f833b819e7c.zip
Added stat command
Diffstat (limited to 'agni.c')
-rw-r--r--agni.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/agni.c b/agni.c
index 8b2b704..fa16b31 100644
--- a/agni.c
+++ b/agni.c
@@ -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");