-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.c
130 lines (97 loc) · 2.53 KB
/
stats.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// stats.c
#include "queue.h"
#include "server.h"
#include "stats.h"
#include "system_data.h"
#include <assert.h>
#include <event.h>
#include <evlogging.h>
#include <stdio.h>
#include "event-compat.h"
void stats_init(stats_t *stats)
{
assert(stats != NULL);
stats->out_bytes = 0;
stats->in_bytes = 0;
stats->requests = 0;
stats->replies = 0;
stats->broadcasts = 0;
stats->re = 0;
stats->we = 0;
stats->te = 0;
stats->shutdown = 0;
stats->sysdata = NULL;
stats->stats_event = NULL;
}
static void stats_handler(int fd, short int flags, void *arg)
{
stats_t *stats;
system_data_t *sysdata;
int clients;
int queues;
int msg_pending, msg_proc;
queue_t *q;
assert(fd < 0);
assert((flags & EV_TIMEOUT) == EV_TIMEOUT);
assert(arg);
stats = arg;
// clear the stats event.
assert(stats->stats_event);
event_free(stats->stats_event);
stats->stats_event = NULL;
assert(stats->sysdata);
sysdata = stats->sysdata;
// assert(stats->sysdata->server != NULL);
// server = stats->sysdata->server;
assert(sysdata->nodelist);
clients = ll_count(sysdata->nodelist);
queues = 0;
msg_pending = 0;
msg_proc = 0;
ll_start(sysdata->queues);
while ((q = ll_next(sysdata->queues))) {
queues ++;
msg_pending += ll_count(&q->msg_pending);
msg_proc += ll_count(&q->msg_proc);
}
ll_finish(sysdata->queues);
assert(stats != NULL);
if (stats->in_bytes || stats->out_bytes || stats->requests || stats->replies || stats->broadcasts || stats->re || stats->we) {
logger(sysdata->logging, 1, "Bytes[%u/%u], Clients[%u], Requests[%u], Replies[%u], Broadcasts[%u], Queues[%u], Msgs[%d/%d], MsgPool[%u/%u], Events[%u/%u/%u]",
stats->in_bytes,
stats->out_bytes,
clients,
stats->requests,
stats->replies,
stats->broadcasts,
queues,
msg_pending, msg_proc,
sysdata->msg_used, sysdata->msg_max,
stats->re, stats->we, stats->te);
stats->in_bytes = 0;
stats->out_bytes = 0;
stats->requests = 0;
stats->replies = 0;
stats->broadcasts = 0;
stats->re = 0;
stats->we = 0;
stats->te = 0;
}
// if we are not shutting down, then schedule the stats event again.
if (stats->shutdown == 0) {
stats_start(stats);
}
}
void stats_start(stats_t *stats)
{
struct timeval t = {.tv_sec = 1, .tv_usec = 0};
system_data_t *sysdata;
assert(stats);
assert(stats->stats_event == NULL);
assert(stats->sysdata);
sysdata = stats->sysdata;
assert(sysdata->evbase);
stats->stats_event = evtimer_new(sysdata->evbase, stats_handler, (void *) stats);
evtimer_add(stats->stats_event, &t);
assert(stats->stats_event);
}