Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,865 +0,0 @@
1
-/* 
2
- * Stats reporting code. It reports through SIG_USR1 and if loaded
3
- * through the SNMP module
4
- *
5
- * Copyright (C) 2001-2003 FhG Fokus
6
- *
7
- * This file is part of Kamailio, a free SIP server.
8
- *
9
- * Kamailio is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version
13
- *
14
- * Kamailio is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
- * GNU General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU General Public License 
20
- * along with this program; if not, write to the Free Software 
21
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
- *
23
- */
24
-
25
-/*!
26
- * \file
27
- * \brief Kamailio core :: Stats reporting code
28
- * Stats reporting code. It reports through SIG_USR1 and if loaded
29
- * through the SNMP module
30
- * \ingroup core
31
- * Module: \ref core
32
- */
33
-
34
-
35
-#ifdef STATS
36
-#include "stats.h"
37
-#include <stdio.h>
38
-#include <stdlib.h>
39
-#include <string.h>
40
-#include <time.h>
41
-#include <sys/types.h>
42
-#include <unistd.h>
43
-#include "dprint.h"
44
-#include "mem/shm_mem.h"
45
-#include "sr_module.h"
46
-
47
-/* SNMP includes */
48
-#include "modules/snmp/snmp_handler.h"
49
-#include "modules/snmp/sipCommonStatsMethod.h"
50
-#include "modules/snmp/sipCommonStatusCode.h"
51
-
52
-struct stats_s *stats;		/* per process stats structure */ 
53
-char *stat_file = NULL;		/* set by the parser */
54
-
55
-/* private variables */
56
-static struct stats_s *global_stats=NULL;
57
-static int stats_segments=-1;	/*used also to determine if we've been init'ed*/
58
-
59
-/* adds up global statistics and puts them into passed struct.
60
- * -1 returned on failure */
61
-static int collect_stats(struct stats_s *s);
62
-
63
-/***********************8 SNMP Stuff **************************/
64
-/* a small structure we use to pass around the functions needed by
65
- * all the registration functions */
66
-struct stats_funcs {
67
-	int (*reg_func)(const char *, struct sip_snmp_handler*);
68
-	struct sip_snmp_handler* (*new_func)(size_t);
69
-	void (*free_func)(struct sip_snmp_handler*);
70
-};
71
-
72
-/* SNMP Handler registration functions */
73
-static int sipSummaryStatsTable_register(const struct stats_funcs *f);
74
-static int sipMethodStatsTable_register(const struct stats_funcs *f);
75
-static int sipStatusCodesTable_register(const struct stats_funcs *f);
76
-
77
-/* the handlers */
78
-static int collect_InReqs(struct sip_snmp_obj *, enum handler_op);
79
-static int collect_OutReqs(struct sip_snmp_obj *, enum handler_op);
80
-static int collect_InResp(struct sip_snmp_obj *, enum handler_op);
81
-static int collect_OutResp(struct sip_snmp_obj *, enum handler_op);
82
-static int sipStatsMethod_handler(struct sip_snmp_obj *o, enum handler_op op);
83
-static int sipStatusCodes_handler(struct sip_snmp_obj *o, enum handler_op op);
84
-
85
-int init_stats(int nr_of_processes)
86
-{
87
-	LM_DBG("initializing stats for %d processes\n", 
88
-		nr_of_processes);
89
-
90
-
91
-	global_stats = shm_malloc(nr_of_processes*sizeof(struct stats_s));
92
-	if(!global_stats) {
93
-		LM_ERR("Out of memory\n");
94
-		return -1;
95
-	}
96
-	stats_segments = nr_of_processes;
97
-
98
-	if(stats_register() == -1)
99
-		LM_WARN("Couldn't register stats with snmp module\n");
100
-
101
-
102
-	return 0;
103
-}
104
-
105
-/* sets the stats pointer for the passed process */
106
-void setstats(int child_index)
107
-{
108
-	if(stats_segments == -1 || !global_stats) {
109
-		LM_ERR("Stats not initialized. Cannot set them\n");
110
-		stats = NULL;
111
-		return;
112
-	}
113
-	if(child_index < 0 || child_index >= stats_segments) {
114
-		stats = NULL;
115
-		LM_ERR("Invalid index %d while setting statistics. Only have "
116
-			"space for %d processes\n", child_index, stats_segments);
117
-		return;
118
-	}
119
-	stats = global_stats+child_index;
120
-	stats->process_index = child_index;
121
-	/* can't use pids[] because we may be called before the corresponding
122
-	 * slot in pids[] is initialized (chk main_loop()) */
123
-	stats->pid = getpid();
124
-	stats->start_time = time(NULL);
125
-}
126
-
127
-/* printheader is used to print pid, date and index */
128
-int dump_statistic(FILE *fp, struct stats_s *istats, int printheader)
129
-{
130
-	struct tm res;
131
-	char t[256];
132
-	if(stats_segments == -1 || !global_stats) {
133
-		LM_ERR("Stats \"engine\" not initialized\n");
134
-		return -1;
135
-	}
136
-
137
-	if(printheader) {
138
-		localtime_r(&istats->start_time, &res);
139
-		strftime(t, 255, "%c", &res);
140
-		
141
-		fprintf(fp, "stats for process %d (pid %d) started at %s\n", 
142
-				istats->process_index, istats->pid, t);
143
-	}
144
-
145
-	fprintf(fp, "received requests:\ninv: %ld\tack: %ld\tcnc: %ld\t"
146
-		"bye: %ld\tother: %ld\n",
147
-		istats->received_requests_inv,
148
-		istats->received_requests_ack,
149
-		istats->received_requests_cnc,
150
-		istats->received_requests_bye,
151
-		istats->received_requests_other);
152
-	fprintf(fp, "sent requests:\n"
153
-		"inv: %ld\tack: %ld\tcnc: %ld\tbye: %ld\tother: %ld\n",
154
-		istats->sent_requests_inv,
155
-		istats->sent_requests_ack,
156
-		istats->sent_requests_cnc,
157
-		istats->sent_requests_bye,
158
-		istats->sent_requests_other);
159
-	fprintf(fp, "received responses:\n"
160
-		"1: %ld\t2: %ld\t3: %ld\t4: %ld\t5: %ld\t6: %ld\tother: %ld\t"
161
-		"drops: %ld\n",
162
-		istats->received_responses_1,
163
-		istats->received_responses_2,
164
-		istats->received_responses_3,
165
-		istats->received_responses_4,
166
-		istats->received_responses_5,
167
-		istats->received_responses_6,
168
-		istats->received_responses_other,
169
-		istats->received_drops);
170
-	fprintf(fp, "sent responses:\n"
171
-		"1: %ld\t2: %ld\t3: %ld\t4: %ld\t5: %ld\t6: %ld\n",
172
-		istats->sent_responses_1,
173
-		istats->sent_responses_2,
174
-		istats->sent_responses_3,
175
-		istats->sent_responses_4,
176
-		istats->sent_responses_5,
177
-		istats->sent_responses_6);
178
-	fprintf(fp, "processed requests: %ld\t\tprocessed responses: %ld\n"
179
-		"acc req time: %ld\t\t\tacc res time: %ld\nfailed on send: %ld\n\n",
180
-		istats->processed_requests,
181
-		istats->processed_responses,
182
-		istats->acc_req_time,
183
-		istats->acc_res_time,
184
-		istats->failed_on_send);
185
-	return 0;
186
-}
187
-
188
-int dump_all_statistic()
189
-{
190
-	register int i;
191
-	register struct stats_s *c;
192
-	static struct stats_s *g = NULL;
193
-	struct tm res;
194
-	char t[256];
195
-	time_t ts;
196
-	FILE *stat_fp = NULL;
197
-
198
-	if(stats_segments == -1 || !global_stats) {
199
-		LM_ERR("%s: Can't dump statistics, not initialized!\n", __func__);
200
-		return -1;
201
-	}
202
-
203
-	if(!stat_file) {
204
-		LM_ERR("%s: Can't dump statistics, invalid stats file\n", __func__);
205
-		return -1;
206
-	}
207
-
208
-	stat_fp = fopen(stat_file, "a");
209
-	if(!stat_fp) {
210
-		LM_ERR("%s: Couldn't open stats file %s: %s\n", __func__, stat_file,
211
-				strerror(errno));
212
-		return -1;
213
-	}
214
-
215
-	/* time stamp them since we're appending to the file */
216
-	ts = time(NULL);
217
-	localtime_r(&ts, &res);
218
-	strftime(t, 255, "%c", &res);
219
-	fprintf(stat_fp, "#### stats @ %s #####\n", t); 
220
-
221
-	c = global_stats;
222
-	for(i=0; i<stats_segments; i++) {
223
-		if(dump_statistic(stat_fp, c, 1) == -1) {
224
-			LM_ERR("Error dumping statistics for process %d\n", i);
225
-			goto end;
226
-		}
227
-		c++;
228
-	}
229
-
230
-	fprintf(stat_fp, "## Global Stats ##\n");
231
-	if(!g)
232
-		g = calloc(1, sizeof(struct stats_s));
233
-	if(!g) {
234
-		LM_ERR("Couldn't dump global stats: %s\n", strerror(errno));
235
-		goto end;
236
-	}
237
-	
238
-	if(collect_stats(g) == -1) {
239
-		LM_ERR("%s: Couldn't dump global stats\n", __func__);
240
-		goto end;
241
-	}
242
-	if(dump_statistic(stat_fp, g, 0) == -1) {
243
-		LM_ERR("Couldn't dump global stats\n");
244
-		goto end;
245
-	}
246
-end:
247
-	fprintf(stat_fp, "\n");
248
-	fclose(stat_fp);
249
-
250
-	return 0;
251
-}
252
-
253
-static int collect_stats(struct stats_s *s)
254
-{
255
-	register int i;
256
-	register struct stats_s *c;
257
-	if(!s) {
258
-		LM_ERR("Invalid stats pointer passed\n");
259
-		return -1;
260
-	}
261
-	if(!global_stats || stats_segments == -1) {
262
-		LM_ERR("Can't collect statistics, not initialized!!\n");
263
-		return -1;
264
-	}
265
-
266
-	c = global_stats;
267
-	memset(s, '\0', sizeof(struct stats_s));
268
-	for(i=0; i<stats_segments; i++) {
269
-		s->received_requests_inv += c->received_requests_inv;
270
-		s->received_requests_ack += c->received_requests_ack;
271
-		s->received_requests_cnc += c->received_requests_cnc;
272
-		s->received_requests_bye += c->received_requests_bye;
273
-		s->received_requests_other += c->received_requests_other;
274
-		s->received_responses_1 += c->received_responses_1;
275
-		s->received_responses_2 += c->received_responses_2;
276
-		s->received_responses_3 += c->received_responses_3;
277
-		s->received_responses_4 += c->received_responses_4;
278
-		s->received_responses_5 += c->received_responses_5;
279
-		s->received_responses_6 += c->received_responses_6;
280
-		s->received_responses_other += c->received_responses_other;
281
-		s->received_drops += c->received_drops;
282
-		s->sent_requests_inv += c->sent_requests_inv;
283
-		s->sent_requests_ack += c->sent_requests_ack;
284
-		s->sent_requests_cnc += c->sent_requests_cnc;
285
-		s->sent_requests_bye += c->sent_requests_bye;
286
-		s->sent_requests_other += c->sent_requests_other;
287
-		s->sent_responses_1 += c->sent_responses_1;
288
-		s->sent_responses_2 += c->sent_responses_2;
289
-		s->sent_responses_3 += c->sent_responses_3;
290
-		s->sent_responses_4 += c->sent_responses_4;
291
-		s->sent_responses_5 += c->sent_responses_5;
292
-		s->sent_responses_6 += c->sent_responses_6;
293
-		s->processed_requests += c->processed_requests;
294
-		s->processed_responses += c->processed_responses;
295
-		s->acc_req_time += c->acc_req_time;
296
-		s->acc_res_time += c->acc_res_time;
297
-		s->failed_on_send += c->failed_on_send;
298
-
299
-		c++; /* next, please... */
300
-	}
301
-
302
-	return 0;
303
-}
304
-
305
-/*************************** SNMP Stuff ***********************/
306
-
307
-/* ##### Registration Functions ####### */
308
-
309
-/* Registers the handlers for:
310
- * - sipSummaryStatsTable
311
- * - sipMethodStatsTable
312
- * - sipStatusCodesTable
313
- * - sipCommonStatusCodeTable
314
- *
315
- * Returns 0 if snmp module not present, -1 on error, 1 on successful
316
- * registration
317
- */
318
-
319
-#define reg(t) \
320
-	if(t##_register(&f) == -1) {	\
321
-		LM_ERR("%s: Failed registering SNMP handlers\n", func);	\
322
-		return -1;	\
323
-	}
324
-
325
-int stats_register()
326
-{
327
-	const char *func = __FUNCTION__;
328
-	struct stats_funcs f;
329
-
330
-	f.reg_func = (void*) find_export("snmp_register_handler", 2, 0);
331
-	f.new_func = (void*) find_export("snmp_new_handler", 1, 0);
332
-	f.free_func = (void*) find_export("snmp_free_handler", 1, 0);
333
-	if(!f.reg_func || !f.new_func || !f.free_func) {
334
-		LM_INFO("%s: Couldn't find SNMP module\n", func);
335
-		LM_INFO("%s: Not reporting stats through SNMP\n", func);
336
-		return 0;
337
-	}
338
-
339
-	reg(sipSummaryStatsTable);
340
-	reg(sipMethodStatsTable);
341
-	reg(sipStatusCodesTable);
342
-
343
-	return 0;
344
-}
345
-
346
-/* Receives the function used to register SNMP handlers. Returns 0
347
- * on success, -1 on error */
348
-/* Registers:
349
- * - sipSummaryInRequests
350
- * - sipSummaryOutRequests
351
- * - sipSummaryInResponses
352
- * - sipSummaryOutResponses
353
- * => sipSummaryTotalTransactions is handled by the tm module */
354
-static int sipSummaryStatsTable_register(const struct stats_funcs *f)
355
-{
356
-	register struct sip_snmp_handler *h;
357
-	register struct sip_snmp_obj *o;
358
-	const char *func = __FUNCTION__;
359
-
360
-	h = f->new_func(sizeof(unsigned long));
361
-	if(!h) {
362
-		LM_ERR("%s: Error creating handler\n", func);
363
-		return -1;
364
-	}
365
-	o = h->sip_obj;
366
-
367
-	/* this is the same for all of our objects */
368
-	o->type = SER_COUNTER;
369
-	*o->value.integer = 0;	/* default value. The real one is computed on
370
-							   request */
371
-	o->val_len = sizeof(unsigned long);
372
-
373
-	/* sipSummaryInRequests */
374
-	h->on_get = collect_InReqs;
375
-	h->on_set = h->on_end = NULL;
376
-	if(f->reg_func("sipSummaryInRequests", h) == -1) {
377
-		LM_ERR("%s: Error registering sipSummaryInRequests\n", func);
378
-		f->free_func(h);
379
-		return -1;
380
-	}
381
-
382
-	/* sipSummaryOutRequests */
383
-	h->on_get = collect_OutReqs;
384
-	if(f->reg_func("sipSummaryOutRequests", h) == -1) {
385
-		LM_ERR("%s: Error registering sipSummaryOutRequests\n", func);
386
-		f->free_func(h);
387
-		return -1;
388
-	}
389
-
390
-	/* sipSummaryInResponses */
391
-	h->on_get = collect_InResp;
392
-	if(f->reg_func("sipSummaryInResponses", h) == -1) {
393
-		LM_ERR("%s: Error registering sipSummaryInResponses\n", func);
394
-		f->free_func(h);
395
-		return -1;
396
-	}
397
-	
398
-	/* sipSummaryOutResponses */
399
-	h->on_get = collect_OutResp;
400
-	if(f->reg_func("sipSummaryOutResponses", h) == -1) {
401
-		LM_ERR("%s: Error registering sipSummaryOutResponses\n", func);
402
-		f->free_func(h);
403
-		return -1;
404
-	}
405
-
406
-	f->free_func(h);
407
-
408
-	return 0;
409
-}
410
-
411
-static int sipMethodStatsTable_register(const struct stats_funcs *f)
412
-{
413
-	const char* objs[] = {
414
-		"sipStatsInviteIns",
415
-		"sipStatsInviteOuts",
416
-		"sipStatsAckIns",
417
-		"sipStatsAckOuts",
418
-		"sipStatsByeIns",
419
-		"sipStatsByeOuts",
420
-		"sipStatsCancelIns",
421
-		"sipStatsCancelOuts"
422
-#if 0	/* we don't know about these */
423
-		"sipStatsOptionsIns",
424
-		"sipStatsOptionsOuts",
425
-		"sipStatsRegisterIns",
426
-		"sipStatsRegisterOuts",
427
-		"sipStatsInfoIns",
428
-		"sipStatsInfoOuts"
429
-#endif
430
-	};
431
-	int i, num = 8;
432
-	const char *func = __FUNCTION__;
433
-	register struct sip_snmp_handler *h;
434
-	register struct sip_snmp_obj *o;
435
-
436
-	h = f->new_func(sizeof(unsigned long));
437
-	if(!h) {
438
-		LM_ERR("%s: Error creating handler\n", func);
439
-		return -1;
440
-	}
441
-	o = h->sip_obj;
442
-	o->type = SER_COUNTER;
443
-	*o->value.integer = 0;
444
-	o->val_len = sizeof(unsigned long);
445
-
446
-	h->on_get = sipStatsMethod_handler;
447
-	h->on_set = h->on_end = NULL;
448
-
449
-	for(i=0; i<num; i++) {
450
-		if(f->reg_func(objs[i], h) == -1) {
451
-			LM_ERR("%s: Error registering %s\n", func, objs[i]);
452
-			f->free_func(h);
453
-			return -1;
454
-		}
455
-	}
456
-
457
-	f->free_func(h);
458
-
459
-	return 0;
460
-}
461
-
462
-static int sipStatusCodesTable_register(const struct stats_funcs *f)
463
-{
464
-	const char *objs[] = {
465
-		"sipStatsInfoClassIns",
466
-		"sipStatsInfoClassOuts",
467
-		"sipStatsSuccessClassIns",
468
-		"sipStatsSuccessClassOuts",
469
-		"sipStatsRedirClassIns",
470
-		"sipStatsRedirClassOuts",
471
-		"sipStatsReqFailClassIns",
472
-		"sipStatsReqFailClassOuts",
473
-		"sipStatsServerFailClassIns",
474
-		"sipStatsServerFailClassOuts",
475
-		"sipStatsGlobalFailClassIns",
476
-		"sipStatsGlobalFailClassOuts",
477
-		"sipStatsOtherClassesIns",
478
-		"sipStatsOtherClassesOuts"
479
-	};
480
-	int i, num = 14;
481
-	const char *func = __FUNCTION__;
482
-	register struct sip_snmp_handler *h;
483
-	register struct sip_snmp_obj *o;
484
-
485
-	h = f->new_func(sizeof(unsigned long));
486
-	if(!h) {
487
-		LM_ERR("%s: Error creating handler\n", func);
488
-		return -1;
489
-	}
490
-	o = h->sip_obj;
491
-	o->type = SER_COUNTER;
492
-	*o->value.integer = 0;
493
-	o->val_len = sizeof(unsigned long);
494
-
495
-	h->on_get = sipStatusCodes_handler;
496
-	h->on_set = h->on_end = NULL;
497
-
498
-	for(i=0; i<num; i++) {
499
-		if(f->reg_func(objs[i], h) == -1) {
500
-			LM_ERR("%s: Error registering %s\n", func, objs[i]);
501
-			f->free_func(h);
502
-			return -1;
503
-		}
504
-	}
505
-
506
-	f->free_func(h);
507
-
508
-	return 0;}
509
-
510
-/* ########################## SNMP Handlers ######################### */
511
-
512
-/*** Handlers for sipSummaryStatsTable */
513
-static int collect_InReqs(struct sip_snmp_obj *o, enum handler_op op)
514
-{
515
-	register int i;
516
-	register struct stats_s *c;
517
-	register unsigned long t1, t2, t3, t4, t5;
518
-	const char *func = __FUNCTION__;
519
-
520
-	if(!global_stats || stats_segments == -1) {
521
-		LM_ERR("%s: Can't collect stats, they have not been initialized."
522
-			"Did you call init_stats()?\n", func);
523
-		return -1;
524
-	}
525
-
526
-	if(op != SER_GET) {
527
-		LM_ERR("%s: Invalid handler operation passed\n", func);
528
-		return -1;
529
-	}
530
-
531
-	if(!o->value.integer) {
532
-		o->value.integer = calloc(1, sizeof(unsigned long));
533
-		if(!o->value.integer) {
534
-			LM_ERR("%s: %s\n", func, strerror(errno));
535
-			return -1;
536
-		}
537
-	}
538
-
539
-	c = global_stats;
540
-	t1 = t2 = t3 = t4 = t5 = 0;
541
-	for(i=0; i<stats_segments; i++, c++) {
542
-		t1 += c->received_requests_inv;
543
-		t2 += c->received_requests_ack;
544
-		t3 += c->received_requests_cnc;
545
-		t4 += c->received_requests_bye;
546
-		t5 += c->received_requests_other;
547
-	}
548
-
549
-	*o->value.integer = t1 + t2 + t3 + t4 + t5; 
550
-	o->val_len = sizeof(unsigned long);
551
-	o->type = SER_COUNTER;
552
-	
553
-	return 0;
554
-}
555
-
556
-static int collect_OutReqs(struct sip_snmp_obj *o, enum handler_op op)
557
-{
558
-	register int i;
559
-	register struct stats_s *c;
560
-	register unsigned long t1, t2, t3, t4, t5;
561
-	const char *func = __FUNCTION__;
562
-
563
-	if(!global_stats || stats_segments == -1) {
564
-		LM_ERR("%s: Can't collect stats, they have not been initialized."
565
-			"Did you call init_stats()?\n", func);
566
-		return -1;
567
-	}
568
-
569
-	if(op != SER_GET) {
570
-		LM_ERR("%s: Invalid handler operation passed\n", func);
571
-		return -1;
572
-	}
573
-
574
-	if(!o->value.integer) {
575
-		o->value.integer = calloc(1, sizeof(unsigned long));
576
-		if(!o->value.integer) {
577
-			LM_ERR("%s: %s\n", func, strerror(errno));
578
-			return -1;
579
-		}
580
-	}
581
-
582
-	c = global_stats;
583
-	t1 = t2 = t3 = t4 = t5 = 0;
584
-	for(i=0; i<stats_segments; i++, c++) {
585
-		t1 += c->sent_requests_inv;
586
-		t2 += c->sent_requests_ack;
587
-		t3 += c->sent_requests_cnc;
588
-		t4 += c->sent_requests_bye;
589
-		t5 += c->sent_requests_other;
590
-	}
591
-
592
-	*o->value.integer = t1 + t2 + t3 + t4 + t5; 
593
-	o->val_len = sizeof(unsigned long);
594
-	o->type = SER_COUNTER;
595
-	
596
-	return 0;
597
-}
598
-
599
-static int collect_InResp(struct sip_snmp_obj *o, enum handler_op op)
600
-{
601
-	register int i;
602
-	register struct stats_s *c;
603
-	register unsigned long t1, t2, t3, t4, t5, t6, t7;
604
-	const char *func = __FUNCTION__;
605
-
606
-	if(!global_stats || stats_segments == -1) {
607
-		LM_ERR("%s: Can't collect stats, they have not been initialized."
608
-			"Did you call init_stats()?\n", func);
609
-		return -1;
610
-	}
611
-
612
-	if(op != SER_GET) {
613
-		LM_ERR("%s: Invalid handler operation passed\n", func);
614
-		return -1;
615
-	}
616
-
617
-	if(!o->value.integer) {
618
-		o->value.integer = calloc(1, sizeof(unsigned long));
619
-		if(!o->value.integer) {
620
-			LM_ERR("%s: %s\n", func, strerror(errno));
621
-			return -1;
622
-		}
623
-	}
624
-
625
-	c = global_stats;
626
-	t1 = t2 = t3 = t4 = t5 = t6 = t7 = 0;
627
-	for(i=0; i<stats_segments; i++, c++) {
628
-		t1 += c->received_responses_1;
629
-		t2 += c->received_responses_2;
630
-		t3 += c->received_responses_3;
631
-		t4 += c->received_responses_4;
632
-		t5 += c->received_responses_5;
633
-		t6 += c->received_responses_6;
634
-		t7 += c->received_responses_other;
635
-	}
636
-
637
-	*o->value.integer = t1 + t2 + t3 + t4 + t5 + t6 + t7; 
638
-	o->val_len = sizeof(unsigned long);
639
-	o->type = SER_COUNTER;
640
-	
641
-	return 0;
642
-}
643
-
644
-static int collect_OutResp(struct sip_snmp_obj *o, enum handler_op op)
645
-{
646
-	register int i;
647
-	register struct stats_s *c;
648
-	register unsigned long t1, t2, t3, t4, t5, t6, t7;
649
-	const char *func = __FUNCTION__;
650
-
651
-	if(!global_stats || stats_segments == -1) {
652
-		LM_ERR("%s: Can't collect stats, they have not been initialized\n",
653
-			func);
654
-		return -1;
655
-	}
656
-
657
-	if(op != SER_GET) {
658
-		LM_ERR("%s: Invalid handler operation passed\n", func);
659
-		return -1;
660
-	}
661
-
662
-	if(!o->value.integer) {
663
-		o->value.integer = calloc(1, sizeof(unsigned long));
664
-		if(!o->value.integer) {
665
-			LM_ERR("%s: %s\n", func, strerror(errno));
666
-			return -1;
667
-		}
668
-	}
669
-
670
-	c = global_stats;
671
-	t1 = t2 = t3 = t4 = t5 = t6 = t7 = 0;
672
-	for(i=0; i<stats_segments; i++, c++) {
673
-		t1 += c->sent_responses_1;
674
-		t2 += c->sent_responses_2;
675
-		t3 += c->sent_responses_3;
676
-		t4 += c->sent_responses_4;
677
-		t5 += c->sent_responses_5;
678
-		t6 += c->sent_responses_6;
679
-		/* XXX: Not in stats struct 
680
-		t7 += c->sent_responses_other;
681
-		*/
682
-	}
683
-
684
-	*o->value.integer = t1 + t2 + t3 + t4 + t5 + t6 + t7; 
685
-	o->val_len = sizeof(unsigned long);
686
-	o->type = SER_COUNTER;
687
-	
688
-	return 0;
689
-}
690
-
691
-/***** Handlers for sipMethodStatsTable ******/
692
-/* Collects the specified stat and puts the result in total. s defines
693
- * the starting point in the stats array, normally global_stats */
694
-#define collect_this_stat(stat, total, s) \
695
-	for(i=0; i<stats_segments; i++)	\
696
-		total += s++->stat;
697
-
698
-static int sipStatsMethod_handler(struct sip_snmp_obj *o, enum handler_op op)
699
-{
700
-	register struct stats_s *c;
701
-	register unsigned long total;
702
-	register int i;
703
-	const char *func = __FUNCTION__;
704
-
705
-	if(!o) {
706
-		LM_ERR("%s: Invalid sip SNMP object passed\n", func);
707
-		return -1;
708
-	}
709
-
710
-	if(!global_stats || stats_segments == -1) {
711
-		LM_ERR("%s: Can't collect stats, they have not been initialized\n",
712
-			func);
713
-		return -1;
714
-	}
715
-
716
-	if(op != SER_GET) {
717
-		LM_ERR("%s: Invalid handler operation passed\n", func);
718
-		return -1;
719
-	}
720
-
721
-	if(!o->value.integer) {
722
-		o->value.integer = calloc(1, sizeof(unsigned long));
723
-		if(!o->value.integer) {
724
-			LM_ERR("%s: %s\n", func, strerror(errno));
725
-			return -1;
726
-		}
727
-	}
728
-
729
-	c = global_stats;
730
-	total = 0;
731
-	switch(o->col) {
732
-		/* these definitions are taken from sipMethodStatsHandler */
733
-		case COLUMN_SIPSTATSINVITEINS: 
734
-			collect_this_stat(received_requests_inv, total, c);
735
-			break;
736
-		case COLUMN_SIPSTATSINVITEOUTS: 
737
-			collect_this_stat(sent_requests_inv, total, c);
738
-			break;
739
-		case COLUMN_SIPSTATSACKINS: 
740
-			collect_this_stat(received_requests_ack, total, c);
741
-			break;
742
-		case COLUMN_SIPSTATSACKOUTS: 
743
-			collect_this_stat(sent_requests_ack, total, c);
744
-			break;
745
-		case COLUMN_SIPSTATSBYEINS: 
746
-			collect_this_stat(received_requests_bye, total, c);
747
-			break;
748
-		case COLUMN_SIPSTATSBYEOUTS: 
749
-			collect_this_stat(sent_requests_bye, total, c);
750
-			break;
751
-		case COLUMN_SIPSTATSCANCELINS: 
752
-			collect_this_stat(received_requests_cnc, total, c);
753
-			break;
754
-		case COLUMN_SIPSTATSCANCELOUTS: 
755
-			collect_this_stat(sent_requests_cnc, total, c);
756
-			break;
757
-		/* ser doesn't have notion for these. We don't
758
-		 * register them with snmp. Here just as remainder */
759
-#if 0
760
-		case COLUMN_SIPSTATSOPTIONSINS:
761
-		case COLUMN_SIPSTATSOPTIONSOUTS:
762
-		case COLUMN_SIPSTATSREGISTERINS:
763
-		case COLUMN_SIPSTATSREGISTEROUTS:
764
-		case COLUMN_SIPSTATSINFOINS:
765
-		case COLUMN_SIPSTATSINFOOUTS:
766
-			break;
767
-#endif
768
-	}
769
-
770
-	*o->value.integer = total;
771
-	o->val_len = sizeof(unsigned long);
772
-	o->type = SER_COUNTER;
773
-
774
-	return 0;
775
-}
776
-
777
-static int sipStatusCodes_handler(struct sip_snmp_obj *o, enum handler_op op)
778
-{
779
-	register struct stats_s *c;
780
-	register unsigned long total;
781
-	register int i;
782
-	const char *func = __FUNCTION__;
783
-
784
-	if(!o) {
785
-		LM_ERR("%s: Invalid sip SNMP object passed\n", func);
786
-		return -1;
787
-	}
788
-
789
-	if(!global_stats || stats_segments == -1) {
790
-		LM_ERR("%s: Can't collect stats, they have not been initialized\n",
791
-			func);
792
-		return -1;
793
-	}
794
-
795
-	if(op != SER_GET) {
796
-		LM_ERR("%s: Invalid handler operation passed\n", func);
797
-		return -1;
798
-	}
799
-
800
-	if(!o->value.integer) {
801
-		o->value.integer = calloc(1, sizeof(unsigned long));
802
-		if(!o->value.integer) {
803
-			LM_ERR("%s: %s\n", func, strerror(errno));
804
-			return -1;
805
-		}
806
-	}
807
-
808
-	c = global_stats;
809
-	total = 0;
810
-	switch(o->col) {
811
-		case COLUMN_SIPSTATSINFOCLASSINS:
812
-			collect_this_stat(received_responses_1, total, c);
813
-			break;
814
-		case COLUMN_SIPSTATSINFOCLASSOUTS:
815
-			collect_this_stat(sent_responses_1, total, c);
816
-			break;
817
-		case COLUMN_SIPSTATSSUCCESSCLASSINS:
818
-			collect_this_stat(received_responses_2, total, c);
819
-			break;
820
-		case COLUMN_SIPSTATSSUCCESSCLASSOUTS:
821
-			collect_this_stat(sent_responses_2, total, c);
822
-			break;
823
-		case COLUMN_SIPSTATSREDIRCLASSINS:
824
-			collect_this_stat(received_responses_3, total, c);
825
-			break;
826
-		case COLUMN_SIPSTATSREDIRCLASSOUTS:
827
-			collect_this_stat(sent_responses_3, total, c);
828
-			break;
829
-		case COLUMN_SIPSTATSREQFAILCLASSINS:
830
-			collect_this_stat(received_responses_4, total, c);
831
-			break;
832
-		case COLUMN_SIPSTATSREQFAILCLASSOUTS:
833
-			collect_this_stat(sent_responses_4, total, c);
834
-			break;
835
-		case COLUMN_SIPSTATSSERVERFAILCLASSINS:
836
-			collect_this_stat(received_responses_5, total, c);
837
-			break;
838
-		case COLUMN_SIPSTATSSERVERFAILCLASSOUTS:
839
-			collect_this_stat(sent_responses_5, total, c);
840
-			break;
841
-		case COLUMN_SIPSTATSGLOBALFAILCLASSINS:
842
-			collect_this_stat(received_responses_6, total, c);
843
-			break;
844
-		case COLUMN_SIPSTATSGLOBALFAILCLASSOUTS:
845
-			collect_this_stat(sent_responses_6, total, c);
846
-			break;
847
-		case COLUMN_SIPSTATSOTHERCLASSESINS:
848
-			collect_this_stat(received_responses_other, total, c);
849
-			break;
850
-		case COLUMN_SIPSTATSOTHERCLASSESOUTS:
851
-			/* FIXME: For some reason this is not defined in
852
-			 * struct stats_s... */
853
-			/* collect_this_stat(sent_responses_other, total, c); */
854
-			total = 0;
855
-			break;
856
-	}
857
-
858
-	*o->value.integer = total;
859
-	o->val_len = sizeof(unsigned long);
860
-	o->type = SER_COUNTER;
861
-
862
-	return 0;
863
-}
864
-
865
-#endif
Browse code

core Update headers, change "SIP-router" to "Kamailio", update doxygen file headers

Olle E. Johansson authored on 03/01/2015 14:15:58
Showing 1 changed files
... ...
@@ -11,11 +11,6 @@
11 11
  * the Free Software Foundation; either version 2 of the License, or
12 12
  * (at your option) any later version
13 13
  *
14
- * For a license to use the ser software under conditions
15
- * other than those described here, or to purchase support for this
16
- * software, please contact iptel.org by e-mail at the following addresses:
17
- *    info@iptel.org
18
- *
19 14
  * Kamailio is distributed in the hope that it will be useful,
20 15
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 16
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Browse code

Core Removed history, svn $id$ and doxygen udpates on the .c files

Olle E. Johansson authored on 03/01/2015 09:53:17
Showing 1 changed files
... ...
@@ -1,14 +1,12 @@
1 1
 /* 
2
- * $Id$
3
- *
4 2
  * Stats reporting code. It reports through SIG_USR1 and if loaded
5 3
  * through the SNMP module
6 4
  *
7 5
  * Copyright (C) 2001-2003 FhG Fokus
8 6
  *
9
- * This file is part of ser, a free SIP server.
7
+ * This file is part of Kamailio, a free SIP server.
10 8
  *
11
- * ser is free software; you can redistribute it and/or modify
9
+ * Kamailio is free software; you can redistribute it and/or modify
12 10
  * it under the terms of the GNU General Public License as published by
13 11
  * the Free Software Foundation; either version 2 of the License, or
14 12
  * (at your option) any later version
... ...
@@ -18,7 +16,7 @@
18 16
  * software, please contact iptel.org by e-mail at the following addresses:
19 17
  *    info@iptel.org
20 18
  *
21
- * ser is distributed in the hope that it will be useful,
19
+ * Kamailio is distributed in the hope that it will be useful,
22 20
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 21
  * MERCHANTABILITY or FITNES