From d5353964d9e835478c3b10c6d9b0fd96e505f47b Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Sat, 20 Jul 2013 18:22:45 -0400 Subject: [PATCH] add connection count to stats --- src/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index dffb65b..86b4ed3 100644 --- a/src/main.c +++ b/src/main.c @@ -9,11 +9,13 @@ static const char* VERSION = "0.0.1"; static sig_atomic_t misses = 0; static sig_atomic_t hits = 0; +static sig_atomic_t connections = 0; static KCDB* db; static int sd; const char* STATS_FORMAT = + "STAT connections %d\r\n" "STAT hits %d\r\n" "STAT misses %d\r\n" "STAT hit_ratio %2.4f\r\n" @@ -173,7 +175,7 @@ void handle_stats(KCLIST* tokens, FILE* client){ kclistdel(parts); strcat(status_buf, buf); } - sprintf(out, STATS_FORMAT, hits, misses, hit_ratio, status_buf); + sprintf(out, STATS_FORMAT, connections, hits, misses, hit_ratio, status_buf); fputs(out, client); } @@ -264,7 +266,7 @@ void* worker(void* arg){ FILE* fp = (FILE*) arg; char buffer[100]; - + ++connections; int status; while(fgets(buffer, sizeof(buffer), fp)){ int last = strlen(buffer) - 1; @@ -281,6 +283,7 @@ void* worker(void* arg){ } } + --connections; fclose(fp); return 0; }