Browse code

Added more stats

Jiri Kuthan authored on 20/08/2002 00:19:05
Showing 15 changed files
... ...
@@ -99,10 +99,10 @@ DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
99 99
 	 -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 \
100 100
 	 -DUSE_IPV6 \
101 101
 	 -DEXTRA_DEBUG \
102
-	 -DDBG_QM_MALLOC \
102
+	 -DVQ_MALLOC  -DDBG_QM_MALLOC \
103
+	 #-DF_MALLOC \
103 104
 	 #-DVQ_MALLOC  
104 105
 	 #-DCONTACT_BUG
105
-	 #-DF_MALLOC \
106 106
 	 #-DDBG_LOCK
107 107
 	 #-DNO_DEBUG \
108 108
 	 #-DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=0 \
... ...
@@ -18,6 +18,7 @@
18 18
 #include <fcntl.h>
19 19
 #include <signal.h>
20 20
 #include <string.h>
21
+#include <time.h>
21 22
 #include "dprint.h"
22 23
 #include "ut.h"
23 24
 #include "error.h"
... ...
@@ -38,6 +39,9 @@ static FILE *fifo_stream;
38 38
 /* list of fifo command */
39 39
 static struct fifo_command *cmd_list=0;
40 40
 
41
+/* up time */
42
+static time_t up_since;
43
+
41 44
 static struct fifo_command *lookup_fifo_cmd( char *name )
42 45
 {
43 46
 	struct fifo_command *c;
... ...
@@ -188,12 +192,30 @@ static char *trim_filename( char * file )
188 188
 	return new_fn;
189 189
 }
190 190
 
191
+FILE *open_reply_pipe( char *pipe_name )
192
+{
193
+	FILE *file_handle;
194
+
195
+	if (!pipe_name) {
196
+		DBG("DEBUG: open_reply_pipe: no file to write to about missing cmd\n");
197
+		return 0;
198
+	}
199
+	file_handle=fopen( pipe_name, "w");
200
+	if (file_handle==NULL) {
201
+		LOG(L_ERR, "ERROR: open_reply_pipe: open error (%s): %s\n",
202
+			pipe_name, strerror(errno));
203
+		return 0;
204
+	}
205
+	return file_handle;
206
+}
207
+
191 208
 static void fifo_server(FILE *fifo_stream)
192 209
 {
193 210
 	char buf[MAX_FIFO_COMMAND];
194 211
 	int line_len;
195 212
 	char *file_sep, *command, *file;
196 213
 	struct fifo_command *f;
214
+	FILE *file_handle;
197 215
 
198 216
 	file_sep=command=file=0;
199 217
 
... ...
@@ -208,7 +230,7 @@ static void fifo_server(FILE *fifo_stream)
208 208
 			goto consume;
209 209
 		}
210 210
 		if (line_len==0) {
211
-			LOG(L_ERR, "ERROR: fifo_server: command empty\n");
211
+			LOG(L_INFO, "INFO: fifo_server: command empty\n");
212 212
 			continue;
213 213
 		}
214 214
 		if (line_len<3) {
... ...
@@ -246,11 +268,31 @@ static void fifo_server(FILE *fifo_stream)
246 246
 		if (f==0) {
247 247
 			LOG(L_ERR, "ERROR: fifo_server: command %s is not available\n",
248 248
 				command);
249
+			file_handle=open_reply_pipe(file);
250
+			if (file_handle==0) {
251
+				LOG(L_ERR, "ERROR: fifo_server: no reply pipe\n");
252
+				goto consume;
253
+			}
254
+			if (fprintf(file_handle, "[%s not available]\n", command)<=0) {
255
+				LOG(L_ERR, "ERROR: fifo_server: write error: %s\n",
256
+				 	strerror(errno));
257
+			}
258
+			fclose(file_handle);
249 259
 			goto consume;
250 260
 		}
251 261
 		if (f->f(fifo_stream, file)<0) {
252 262
 			LOG(L_ERR, "ERROR: fifo_server: command (%s) "
253 263
 				"processing failed\n", command );
264
+			file_handle=open_reply_pipe(file);
265
+			if (file_handle==0) {
266
+				LOG(L_ERR, "ERROR: fifo_server: no reply pipe\n");
267
+				goto consume;
268
+			}
269
+			if (fprintf(file_handle, "[%s failed]\n", command)<=0) {
270
+				LOG(L_ERR, "ERROR: fifo_server: write error: %s\n",
271
+				strerror(errno));
272
+			}
273
+			fclose(file_handle);
254 274
 			goto consume;
255 275
 		}
256 276
 
... ...
@@ -273,6 +315,7 @@ int open_fifo_server()
273 273
 			strerror(errno));
274 274
 		return -1;
275 275
 	}
276
+	time(&up_since);
276 277
 	process_no++;
277 278
 	fifo_pid=fork();
278 279
 	if (fifo_pid<0) {
... ...
@@ -311,7 +354,7 @@ int open_fifo_server()
311 311
 }
312 312
 
313 313
 /* diagnostic and hello-world FIFO command */
314
-int print_fifo_cmd( FILE *stream, char *response_file )
314
+static int print_fifo_cmd( FILE *stream, char *response_file )
315 315
 {
316 316
 	char text[MAX_PRINT_TEXT];
317 317
 	int text_len;
... ...
@@ -343,3 +386,42 @@ int print_fifo_cmd( FILE *stream, char *response_file )
343 343
 	}
344 344
 	return 1;
345 345
 }
346
+
347
+static int uptime_fifo_cmd( FILE *stream, char *response_file )
348
+{
349
+	FILE *file;
350
+	time_t now;
351
+
352
+	if (response_file==0 || *response_file==0 ) { 
353
+		LOG(L_ERR, "ERROR: uptime_fifo_cmd: null file\n");
354
+		return -1;
355
+	}
356
+	file=fopen(response_file, "w" );
357
+	if (file==NULL) {
358
+		LOG(L_ERR, "ERROR: uptime_fifo_cmd: file %s bad: %s\n",
359
+			response_file, strerror(errno) );
360
+		return -1;
361
+	}
362
+
363
+	time(&now);
364
+	fprintf(file, "Now: %s", ctime(&now) );
365
+	fprintf(file, "Up since: %s", ctime(&up_since) );
366
+	fprintf(file, "Up time: %.0f [sec]\n", difftime(now, up_since));
367
+
368
+	fclose(file);
369
+	return 1;
370
+}
371
+
372
+
373
+int register_core_fifo()
374
+{
375
+	if (register_fifo_cmd(print_fifo_cmd, FIFO_PRINT, 0)<0) {
376
+		LOG(L_CRIT, "unable to register 'print' FIFO cmd\n");
377
+		return -1;
378
+	}
379
+	if (register_fifo_cmd(uptime_fifo_cmd, FIFO_UPTIME, 0)<0) {
380
+		LOG(L_CRIT, "unable to register 'print' FIFO cmd\n");
381
+		return -1;
382
+	}
383
+	return 1;
384
+}
... ...
@@ -10,6 +10,10 @@
10 10
 
11 11
 #define CMD_SEPARATOR ':'
12 12
 
13
+/* core FIFO command set */
14
+#define FIFO_PRINT "print"
15
+#define FIFO_UPTIME "uptime"
16
+
13 17
 typedef int (fifo_cmd)( FILE *fifo_stream, char *response_file );
14 18
 
15 19
 struct fifo_command{
... ...
@@ -30,5 +34,9 @@ int read_line_set(char *buf, int max_len, FILE *fifo, int *len);
30 30
 
31 31
 int open_fifo_server();
32 32
 
33
-int print_fifo_cmd( FILE *stream, char *response_file );
33
+/* regsiter core FIFO command set */
34
+int register_core_fifo();
35
+
36
+FILE *open_reply_pipe( char *pipe_name );
37
+
34 38
 #endif
... ...
@@ -874,8 +874,8 @@ int main(int argc, char** argv)
874 874
 	}
875 875
 
876 876
 	/* register a diagnostic FIFO command */
877
-	if (register_fifo_cmd(print_fifo_cmd, "print", 0)<0) {
878
-		LOG(L_CRIT, "unable to register 'print' FIFO cmd\n");
877
+	if (register_core_fifo()<0) {
878
+		LOG(L_CRIT, "unable to register core FIFO commands\n");
879 879
 		goto error;
880 880
 	}
881 881
 
... ...
@@ -23,6 +23,11 @@
23 23
 			(_d) += (_len);\
24 24
 		}while(0);
25 25
 
26
+#define append_str(_p,_str) \
27
+	do{  \
28
+		memcpy((_p), (_str).s, (_str).len); \
29
+		(_p)+=(_str).len;  \
30
+ 	} while(0);
26 31
 
27 32
 /* Build a local request based on a previous request; main
28 33
    customers of this function are local ACK and local CANCEL
... ...
@@ -20,41 +20,33 @@ struct t_stats *cur_stats, *acc_stats;
20 20
   
21 21
 int print_stats(  FILE *f )
22 22
 {
23
-	time_t now;
24
-
25
-	time(&now);
26
-
27
-	fprintf(f, "Time:\n----------------\n");
28
-	fprintf(f, "Now: %s", ctime(&now));
29
-	fprintf(f, "Up since: %s", ctime(&acc_stats->up_since));
30
-	fprintf(f, "Up time: %.0f [sec]\n", difftime(now, acc_stats->up_since));
31
-	fprintf(f, "\nCurrent values:\n----------------\n");
32
-	fprintf(f, "# of transactions: %d\n", 
23
+	fprintf(f, "Current:\n");
24
+	fprintf(f, "# of transactions: %d, ", 
33 25
 		cur_stats->transactions );
34
-	fprintf(f, "    - local: %d\n",
26
+	fprintf(f, "local: %d, ",
35 27
 		cur_stats->client_transactions );
36
-	fprintf(f, "    - waiting: %d\n",
28
+	fprintf(f, "waiting: %d\n",
37 29
 		cur_stats->waiting );
38 30
 
39
-	fprintf(f, "\nCummulative values:\n----------------\n");
40
-	fprintf(f, "# of transactions: %d\n",	
31
+	fprintf(f, "Total:\n");
32
+	fprintf(f, "# of transactions: %d,",
41 33
 		acc_stats->transactions );
42
-	fprintf(f, "    - local: %d\n",
34
+	fprintf(f, " local: %d,",
43 35
 		acc_stats->client_transactions );
44
-	fprintf(f, "    - waiting: %d\n",
36
+	fprintf(f, " waiting: %d\n",
45 37
 		acc_stats->waiting );
46 38
 
47 39
 	fprintf(f, "Replied localy: %d\n",
48 40
 		acc_stats->replied_localy );
49
-	fprintf(f, "Completion status 6xx: %d\n",
41
+	fprintf(f, "Completion status 6xx: %d,",
50 42
 		acc_stats->completed_6xx );
51
-	fprintf(f, "Completion status 5xx: %d\n",
43
+	fprintf(f, " 5xx: %d,",
52 44
 		acc_stats->completed_5xx );
53
-	fprintf(f, "Completion status 4xx: %d\n",
45
+	fprintf(f, " 4xx: %d,",
54 46
 		acc_stats->completed_4xx );
55
-	fprintf(f, "Completion status 3xx: %d\n",
47
+	fprintf(f, " 3xx: %d,",
56 48
 		acc_stats->completed_3xx );
57
-	fprintf(f, "Completion status 2xx: %d\n",
49
+	fprintf(f, "2xx: %d\n",
58 50
 		acc_stats->completed_2xx );
59 51
 	
60 52
 	return 1;
... ...
@@ -82,7 +74,7 @@ int static fifo_stats( FILE *pipe, char *response_file )
82 82
 
83 83
 }
84 84
 
85
-int init_stats(void)
85
+int init_tm_stats(void)
86 86
 {
87 87
 	cur_stats=shm_malloc(sizeof(struct t_stats));
88 88
 	if (cur_stats==0) {
... ...
@@ -103,6 +95,5 @@ int init_stats(void)
103 103
 
104 104
 	memset(cur_stats, 0, sizeof(struct t_stats) );
105 105
 	memset(acc_stats, 0, sizeof(struct t_stats) );
106
-	time(&acc_stats->up_since);
107 106
 	return 1;
108 107
 }
... ...
@@ -7,7 +7,6 @@
7 7
 #ifndef _T_STATS_H
8 8
 #define _T_STATS_H
9 9
 
10
-#include <time.h>
11 10
 
12 11
 extern struct t_stats *cur_stats, *acc_stats;
13 12
 
... ...
@@ -22,9 +21,8 @@ struct t_stats {
22 22
 	unsigned int completed_3xx, completed_4xx, completed_5xx, 
23 23
 		completed_6xx, completed_2xx;
24 24
 	unsigned int replied_localy;
25
-	time_t up_since;
26 25
 };
27 26
 
28
-int init_stats(void);
27
+int init_tm_stats(void);
29 28
 
30 29
 #endif
... ...
@@ -238,7 +238,7 @@ static int mod_init(void)
238 238
 		return -1;
239 239
 	}
240 240
 	
241
-	if (init_stats()<0) {
241
+	if (init_tm_stats()<0) {
242 242
 		LOG(L_CRIT, "ERROR: mod_init: failed to init stats\n");
243 243
 		return -1;
244 244
 	}
... ...
@@ -105,12 +105,42 @@ prompt_pw() {
105 105
 
106 106
 # $1 = name $2=path $3=attempt
107 107
 print_stats() {
108
-echo "[cycle: $3; if screen empty, make sure server is alive]"
108
+
109
+echo "[cycle: $3; if screen empty, make sure server is alive and option fifo is set]"
110
+
111
+echo Up Time
112
+cat > $SER_FIFO <<EOF
113
+
114
+:uptime:$1
115
+EOF
116
+cat < $2
117
+echo
118
+
119
+echo Transaction Statistics
109 120
 cat > $SER_FIFO <<EOF
110 121
 
111 122
 :t_stats:$1
112 123
 EOF
113 124
 cat < $2
125
+echo
126
+
127
+echo Stateless Server Statistics
128
+cat > $SER_FIFO <<EOF
129
+
130
+:sl_stats:$1
131
+EOF
132
+cat < $2
133
+echo
134
+
135
+echo UsrLoc Stats
136
+cat > $SER_FIFO <<EOF
137
+
138
+:ul_stats:$1
139
+EOF
140
+cat < $2
141
+echo
142
+
143
+
114 144
 }
115 145
 
116 146
 
... ...
@@ -385,7 +415,7 @@ case $1 in
385 385
 		fi
386 386
 		;;
387 387
 
388
-	stats)
388
+	monitor|console|moni|con)
389 389
 		name=ser_receiver_$$
390 390
 		path=/tmp/$name
391 391
 		if [ ! -w $SER_FIFO ]; then
... ...
@@ -399,9 +429,11 @@ case $1 in
399 399
 			exit 1
400 400
 		fi
401 401
 		attempt=0
402
+		clear
402 403
 		while [ 1 -eq 1 ]; do
403 404
 			attempt=`expr $attempt + 1`
404
-			clear
405
+			#clear
406
+			tput cup 0 0
405 407
 			print_stats $name $path $attempt
406 408
 			sleep $WATCH_PERIOD
407 409
 		done
... ...
@@ -1,11 +1,10 @@
1 1
 MESSAGE sip:756843@iptel.org SIP/2.0
2
-Via: SIP/2.0/UDP fox.iptel.org:5060
2
+Via: SIP/2.0/UDP bat.iptel.org:9
3 3
 From: "bogdan" <sip:bogdan@iptel.org>;tag=0e99b1e7-ff50-4875-94ef-4ca5c27e2705
4
-To: 
5
-Call-ID: 02b1191c-447e-4bd0-b771-c039fc0d9d84@195.37.78.169
4
+xCall-ID: 02b1191c-447e-4bd0-b771-c039fc0d9d84@195.37.78.169
6 5
 CSeq: 7 MESSAGE
7 6
 Contact: <sip:195.37.78.169:11457>
8 7
 User-Agent: Windows RTC/1.0
9
-Content-Type: text/plain
8
+text/plain
10 9
 Content-Length: 4
11 10
 
... ...
@@ -1,5 +1,5 @@
1
-MESSAGE sip:jiri@iptel.org SIP/2.0
2
-Via: SIP/2.0/UDP fox.iptel.org:5060
1
+MESSAGE sip:x@bat.iptel.org SIP/2.0
2
+Via: SIP/2.0/UDP bat.iptel.org:9
3 3
 From: sip:msilo@iptel.org;tag=16df4fe56e8782ecaa5d53ae36fb9240
4 4
 To: sip:dcm@iptel.org
5 5
 Call-ID: 02b1191c-447e-4bd0-b771-c039fc0d9d84@195.37.78.169
... ...
@@ -3,7 +3,7 @@ To: <sip:jiri@iptel.org>
3 3
 From: <sip:jiri@iptel.org>
4 4
 Call-ID: 7138115741688223740@195.37.78.226
5 5
 CSeq: 4 REGISTER
6
-Via: SIP/2.0/UDP iptel.org:5060
6
+Via: SIP/2.0/UDP bat.iptel.org:5060
7 7
 User-Agent:  UbiquityUserAgent/4
8 8
 Expires: 0
9 9
 Content-Length: 0
... ...
@@ -1,5 +1,5 @@
1 1
 REGISTER sip:iptel.org:5060 SIP/2.0
2
-To:poo bear@iptel.org
2
+To:poo <bear@iptel.org>
3 3
 From: <sip:jiri@iptel.org>
4 4
 Call-ID: 7138115741688223740@195.37.78.226
5 5
 CSeq: 4 REGISTER
... ...
@@ -6,13 +6,14 @@
6 6
 
7 7
 # ----------- global configuration parameters ------------------------
8 8
 
9
-debug=3
10
-fork=no
9
+debug=0
10
+fork=1
11 11
 log_stderror=yes	# (cmd line: -E)
12 12
 check_via=no # (cmd. line: -v)
13 13
 dns=no # (cmd. line: -r)
14 14
 syn_branch=1
15 15
 reply_to_via=0
16
+fifo="/tmp/ser_fifo"
16 17
 
17 18
 # advertise IP address in Via (as opposed to advertising DNS name
18 19
 # which is annoying for downstream servers and some phones can
... ...
@@ -23,7 +24,7 @@ listen=195.37.77.100
23 23
 
24 24
 loadmodule "../sip_router/modules/sl/sl.so"
25 25
 loadmodule "../sip_router/modules/print/print.so"
26
-#loadmodule "../sip_router/modules/tm/tm.so"
26
+#loadmodule "../sip_router/modules/tm/tm_mod.so"
27 27
 loadmodule "../sip_router/modules/usrloc/usrloc.so"
28 28
 
29 29
 # ----------------- setting module-specific parameters ---------------
... ...
@@ -34,14 +35,22 @@ modparam("usrloc", "use_database",   0)
34 34
 modparam("usrloc", "flush_interval", 3600)
35 35
 
36 36
 # -- tm params --
37
-modparam("tm", "fr_timer", 10 )
37
+modparam("tm", "fr_timer", 5 )
38 38
 modparam("tm", "fr_inv_timer", 5 )
39
+modparam("tm", "wt_timer", 5 )
39 40
 
40 41
 # -------------------------  request routing logic -------------------
41 42
 
42 43
 # main routing logic
43 44
 
44 45
 route{
46
+	append_branch("sip:bla@bat.iptel.org:5088");
47
+	append_branch("sip:blb@bat.iptel.org:5088");
48
+	t_on_negative("1");
45 49
 	t_relay_to("bat.iptel.org","5088");
46 50
 }
47 51
 
52
+reply_route[1] {
53
+	append_branch("sip:mrx@bat.iptel.org:5088");
54
+}
55
+
... ...
@@ -1,6 +1,6 @@
1 1
 :t_uac:hh
2 2
 MESSAGE
3
-sip:jiri@iptel.org
3
+sip:jirim@iptel.org
4 4
 foo: bar
5 5
 x: y
6 6
 p_header: p_value