-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatistics.h
390 lines (292 loc) · 10 KB
/
statistics.h
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/*
* statistics.h
*
* 2006-2007 Copyright (c)
* Robert Iakobashvili, <coroberti@gmail.com>
* Michael Moser, <moser.michael@gmail.com>
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef STATISTICS_H
#define STATISTICS_H
#include <stdio.h>
#include "timer_tick.h"
typedef enum reporting_way{
CONSOLE_REPORTING=0,
REDIS_REPORTING,
CONSOLE_AND_REDIS,
}reporting_way;
/*
stat_point -the structure is used to collect loading statistics.
Two instances of the structure are kept by each batch context.
One object is used for the latest snapshot interval stats and another
for the total summary values.
*/
typedef struct stat_point
{
/* Inbound bytes number */
unsigned long long data_in;
/* Outbound bytes number */
unsigned long long data_out;
/* Number of requests received */
unsigned long requests;
/* Number of 1xx responses */
unsigned long resp_1xx;
/* Number of 2xx responses */
unsigned long resp_2xx;
/* Number of 3xx redirections */
unsigned long resp_3xx;
/* Number of 4xx responses */
unsigned long resp_4xx;
/* Number of 5xx responses */
unsigned long resp_5xx;
/* Errors of resolving, connecting, internal errors, etc. */
unsigned long other_errs;
/*
URL Timeout errors of not accomplishing url fetch prior to the
url-completion timer being expired .
*/
unsigned long url_timeout_errs;
/* Num of data points used to calculate average application delay */
int appl_delay_points;
/* Average delay in msec between request and response */
unsigned long appl_delay;
/*
Num of data points used to calculate average application delay
for 2xx-OK responses.
*/
int appl_delay_2xx_points;
/* Average delay in msec between request and 2xx-OK response */
unsigned long appl_delay_2xx;
} stat_point;
/*
op_stat_point - operation statistics point.
Two instances are residing in each batch context and used:
- one for the latest snapshot interval;
- another for the total summary values.
*/
typedef struct op_stat_point
{
/* Number of url-counters in the below arrays */
unsigned long url_num;
/* Array of url counters for successful fetches */
unsigned long* url_ok;
/* Array of url counters for failed fetches */
unsigned long* url_failed;
/* Array of url counters for timeouted fetches */
unsigned long* url_timeouted;
/* Used for CAPS calculation */
unsigned long call_init_count;
} op_stat_point;
typedef struct redis_statistics_output
{
int d_redis_keepalive_secs;
char *s_redis_keepalive_secs;
int d_total_client;
char *s_total_client;
int d_cycle_interval;
char *s_cycle_interval;
int d_http_request_num;
char *s_http_request_num;
int d_hf_1xx;
char *s_hf_1xx;
int d_hf_2xx;
char *s_hf_2xx;
int d_hf_3xx;
char *s_hf_3xx;
int d_hf_4xx;
char *s_hf_4xx;
int d_hf_5xx;
char *s_hf_5xx;
int d_hf_err;
char *s_hf_err;
int d_hf_t_err;
char *s_hf_t_err;
int d_hf_delay;
char *s_hf_delay;
int d_hf_delay_2xx;
char *s_hf_delay_2xx;
int d_hf_input_traffic;
char *s_hf_input_traffic;
int d_hf_output_traffic;
char *s_hf_output_traffic;
int d_https_request_num;
char *s_https_request_num;
int d_hfs_1xx;
char *s_hfs_1xx;
int d_hfs_2xx;
char *s_hfs_2xx;
int d_hfs_3xx;
char *s_hfs_3xx;
int d_hfs_4xx;
char *s_hfs_4xx;
int d_hfs_5xx;
char *s_hfs_5xx;
int d_hfs_err;
char *s_hfs_err;
int d_hfs_t_err;
char *s_hfs_t_err;
int d_hfs_delay;
char *s_hfs_delay;
int d_hfs_delay_2xx;
char *s_hfs_delay_2xx;
int d_hfs_input_traffic;
char *s_hfs_input_traffic;
int d_hfs_output_traffic;
char *s_hfs_output_traffic;
int d_caps_current;
char *s_caps_current;
int d_total_duration;
char *s_total_duration;
int d_total_http_request_num;
char *s_total_http_request_num;
int d_total_hf_1xx;
char *s_total_hf_1xx;
int d_total_hf_2xx;
char *s_total_hf_2xx;
int d_total_hf_3xx;
char *s_total_hf_3xx;
int d_total_hf_4xx;
char *s_total_hf_4xx;
int d_total_hf_5xx;
char *s_total_hf_5xx;
int d_total_hf_err;
char *s_total_hf_err;
int d_total_hf_t_err;
char *s_total_hf_t_err;
int d_average_hf_delay;
char *s_average_hf_delay;
int d_average_hf_delay_2xx;
char *s_average_hf_delay_2xx;
int d_average_hf_input_traffic;
char *s_average_hf_input_traffic;
int d_average_hf_output_traffic;
char *s_average_hf_output_traffic;
int d_total_https_request_num;
char *s_total_https_request_num;
int d_total_hfs_1xx;
char *s_total_hfs_1xx;
int d_total_hfs_2xx;
char *s_total_hfs_2xx;
int d_total_hfs_3xx;
char *s_total_hfs_3xx;
int d_total_hfs_4xx;
char *s_total_hfs_4xx;
int d_total_hfs_5xx;
char *s_total_hfs_5xx;
int d_total_hfs_err;
char *s_total_hfs_err;
int d_total_hfs_t_err;
char *s_total_hfs_t_err;
int d_average_hfs_delay;
char *s_average_hfs_delay;
int d_average_hfs_delay_2xx;
char *s_average_hfs_delay_2xx;
int d_average_hfs_input_traffic;
char *s_average_hfs_input_traffic;
int d_average_hfs_output_traffic;
char *s_average_hfs_output_traffic;
int d_average_caps;
char *s_average_caps;
}redis_statistics_output;
/*******************************************************************************
* Function name - stat_point_add
*
* Description - Adds counters of one stat_point object to another
* Input - *left - pointer to the stat_point, where counter will be added
* *right - pointer to the stat_point, which counter will be added
* to the <left>
* Return Code/Output - None
********************************************************************************/
void stat_point_add (stat_point* left, stat_point* right);
/******************************************************************************
* Function name - stat_point_reset
*
* Description - Nulls counters of a stat_point structure
*
* Input - *point - pointer to the stat_point
* Return Code/Output - None
*******************************************************************************/
void stat_point_reset (stat_point* point);
/*******************************************************************************
* Function name - op_stat_point_add
*
* Description - Adds counters of one op_stat_point object to another
* Input - *left - pointer to the op_stat_point, where counter will be added
* *right - pointer to the op_stat_point, which counter will be
* added to the <left>
* Return Code/Output - None
********************************************************************************/
void op_stat_point_add (op_stat_point* left, op_stat_point* right);
/*******************************************************************************
* Function name - op_stat_point_reset
*
* Description - Nulls counters of an op_stat_point structure
*
* Input - *point - pointer to the op_stat_point
* Return Code/Output - None
********************************************************************************/
void op_stat_point_reset (op_stat_point* point);
/*******************************************************************************
* Function name - op_stat_point_init
*
* Description - Initializes an allocated op_stat_point by allocating relevant
* pointer fields for counters
*
* Input - *point -pointer to the op_stat_point, where counter will be added
* url_num -number of urls
* Return Code/Output - None
********************************************************************************/
int op_stat_point_init (op_stat_point* point, size_t url_num);
/*******************************************************************************
* Function name - op_stat_point_release
*
* Description - Releases memory allocated by op_stat_point_init ()
*
* Input - *point - pointer to the op_stat_point, where counter will be added
* Return Code/Output - None
********************************************************************************/
void op_stat_point_release (op_stat_point* point);
/*******************************************************************************
* Function name - op_stat_update
*
* Description - Updates operation statistics using information from client context
*
* Input - *point - pointer to the op_stat_point, where counters
* to be updated
* current_state - current state of a client
* prev_state - previous state of a client
* current_url_index - current url index of a the client
* prev_uas_url_index - previous url index of a the client
* Return Code/Output - None
*********************************************************************************/
void op_stat_update (op_stat_point* op_stat,
int current_state,
int prev_state,
size_t current_url_index,
size_t prev_url_index);
void op_stat_timeouted (op_stat_point* op_stat, size_t url_index);
void op_stat_call_init_count_inc (op_stat_point* op_stat);
struct client_context;
struct batch_context;
char *ascii_time (char *tbuf);
void print_statistics_header (FILE* file);
extern void generate_cycle_log (struct batch_context* bctx, unsigned long now_time, int clients_total_num);
extern void generate_final_log (struct batch_context* bctx);
extern int connect_redis_server(struct batch_context* bctx);
extern void generate_cycle_reporting(struct batch_context* bctx, unsigned long now);
extern int disconnect_redis_server (struct batch_context* bctx);
#endif /* STATISTICS_H */