瀏覽代碼

Added more stats

Jiri Kuthan 23 年之前
父節點
當前提交
90b0b10dd4
共有 15 個文件被更改,包括 174 次插入50 次删除
  1. 2 2
      Makefile.defs
  2. 84 2
      fifo_server.c
  3. 9 1
      fifo_server.h
  4. 2 2
      main.c
  5. 5 0
      modules/tm/t_msgbuilder.c
  6. 14 23
      modules/tm/t_stats.c
  7. 1 3
      modules/tm/t_stats.h
  8. 1 1
      modules/tm/tm_mod.c
  9. 35 3
      scripts/sc
  10. 3 4
      test/message02.sip
  11. 2 2
      test/message03.sip
  12. 1 1
      test/register03.sip
  13. 1 1
      test/register04.sip
  14. 13 4
      test/stress.cfg
  15. 1 1
      test/transaction.fifo

+ 2 - 2
Makefile.defs

@@ -99,10 +99,10 @@ DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
 	 -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 \
 	 -DUSE_IPV6 \
 	 -DEXTRA_DEBUG \
-	 -DDBG_QM_MALLOC \
+	 -DVQ_MALLOC  -DDBG_QM_MALLOC \
+	 #-DF_MALLOC \
 	 #-DVQ_MALLOC  
 	 #-DCONTACT_BUG
-	 #-DF_MALLOC \
 	 #-DDBG_LOCK
 	 #-DNO_DEBUG \
 	 #-DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=0 \

+ 84 - 2
fifo_server.c

@@ -18,6 +18,7 @@
 #include <fcntl.h>
 #include <signal.h>
 #include <string.h>
+#include <time.h>
 #include "dprint.h"
 #include "ut.h"
 #include "error.h"
@@ -38,6 +39,9 @@ static FILE *fifo_stream;
 /* list of fifo command */
 static struct fifo_command *cmd_list=0;
 
+/* up time */
+static time_t up_since;
+
 static struct fifo_command *lookup_fifo_cmd( char *name )
 {
 	struct fifo_command *c;
@@ -188,12 +192,30 @@ static char *trim_filename( char * file )
 	return new_fn;
 }
 
+FILE *open_reply_pipe( char *pipe_name )
+{
+	FILE *file_handle;
+
+	if (!pipe_name) {
+		DBG("DEBUG: open_reply_pipe: no file to write to about missing cmd\n");
+		return 0;
+	}
+	file_handle=fopen( pipe_name, "w");
+	if (file_handle==NULL) {
+		LOG(L_ERR, "ERROR: open_reply_pipe: open error (%s): %s\n",
+			pipe_name, strerror(errno));
+		return 0;
+	}
+	return file_handle;
+}
+
 static void fifo_server(FILE *fifo_stream)
 {
 	char buf[MAX_FIFO_COMMAND];
 	int line_len;
 	char *file_sep, *command, *file;
 	struct fifo_command *f;
+	FILE *file_handle;
 
 	file_sep=command=file=0;
 
@@ -208,7 +230,7 @@ static void fifo_server(FILE *fifo_stream)
 			goto consume;
 		}
 		if (line_len==0) {
-			LOG(L_ERR, "ERROR: fifo_server: command empty\n");
+			LOG(L_INFO, "INFO: fifo_server: command empty\n");
 			continue;
 		}
 		if (line_len<3) {
@@ -246,11 +268,31 @@ static void fifo_server(FILE *fifo_stream)
 		if (f==0) {
 			LOG(L_ERR, "ERROR: fifo_server: command %s is not available\n",
 				command);
+			file_handle=open_reply_pipe(file);
+			if (file_handle==0) {
+				LOG(L_ERR, "ERROR: fifo_server: no reply pipe\n");
+				goto consume;
+			}
+			if (fprintf(file_handle, "[%s not available]\n", command)<=0) {
+				LOG(L_ERR, "ERROR: fifo_server: write error: %s\n",
+				 	strerror(errno));
+			}
+			fclose(file_handle);
 			goto consume;
 		}
 		if (f->f(fifo_stream, file)<0) {
 			LOG(L_ERR, "ERROR: fifo_server: command (%s) "
 				"processing failed\n", command );
+			file_handle=open_reply_pipe(file);
+			if (file_handle==0) {
+				LOG(L_ERR, "ERROR: fifo_server: no reply pipe\n");
+				goto consume;
+			}
+			if (fprintf(file_handle, "[%s failed]\n", command)<=0) {
+				LOG(L_ERR, "ERROR: fifo_server: write error: %s\n",
+				strerror(errno));
+			}
+			fclose(file_handle);
 			goto consume;
 		}
 
@@ -273,6 +315,7 @@ int open_fifo_server()
 			strerror(errno));
 		return -1;
 	}
+	time(&up_since);
 	process_no++;
 	fifo_pid=fork();
 	if (fifo_pid<0) {
@@ -311,7 +354,7 @@ int open_fifo_server()
 }
 
 /* diagnostic and hello-world FIFO command */
-int print_fifo_cmd( FILE *stream, char *response_file )
+static int print_fifo_cmd( FILE *stream, char *response_file )
 {
 	char text[MAX_PRINT_TEXT];
 	int text_len;
@@ -343,3 +386,42 @@ int print_fifo_cmd( FILE *stream, char *response_file )
 	}
 	return 1;
 }
+
+static int uptime_fifo_cmd( FILE *stream, char *response_file )
+{
+	FILE *file;
+	time_t now;
+
+	if (response_file==0 || *response_file==0 ) { 
+		LOG(L_ERR, "ERROR: uptime_fifo_cmd: null file\n");
+		return -1;
+	}
+	file=fopen(response_file, "w" );
+	if (file==NULL) {
+		LOG(L_ERR, "ERROR: uptime_fifo_cmd: file %s bad: %s\n",
+			response_file, strerror(errno) );
+		return -1;
+	}
+
+	time(&now);
+	fprintf(file, "Now: %s", ctime(&now) );
+	fprintf(file, "Up since: %s", ctime(&up_since) );
+	fprintf(file, "Up time: %.0f [sec]\n", difftime(now, up_since));
+
+	fclose(file);
+	return 1;
+}
+
+
+int register_core_fifo()
+{
+	if (register_fifo_cmd(print_fifo_cmd, FIFO_PRINT, 0)<0) {
+		LOG(L_CRIT, "unable to register 'print' FIFO cmd\n");
+		return -1;
+	}
+	if (register_fifo_cmd(uptime_fifo_cmd, FIFO_UPTIME, 0)<0) {
+		LOG(L_CRIT, "unable to register 'print' FIFO cmd\n");
+		return -1;
+	}
+	return 1;
+}

+ 9 - 1
fifo_server.h

@@ -10,6 +10,10 @@
 
 #define CMD_SEPARATOR ':'
 
+/* core FIFO command set */
+#define FIFO_PRINT "print"
+#define FIFO_UPTIME "uptime"
+
 typedef int (fifo_cmd)( FILE *fifo_stream, char *response_file );
 
 struct fifo_command{
@@ -30,5 +34,9 @@ int read_line_set(char *buf, int max_len, FILE *fifo, int *len);
 
 int open_fifo_server();
 
-int print_fifo_cmd( FILE *stream, char *response_file );
+/* regsiter core FIFO command set */
+int register_core_fifo();
+
+FILE *open_reply_pipe( char *pipe_name );
+
 #endif

+ 2 - 2
main.c

@@ -874,8 +874,8 @@ int main(int argc, char** argv)
 	}
 
 	/* register a diagnostic FIFO command */
-	if (register_fifo_cmd(print_fifo_cmd, "print", 0)<0) {
-		LOG(L_CRIT, "unable to register 'print' FIFO cmd\n");
+	if (register_core_fifo()<0) {
+		LOG(L_CRIT, "unable to register core FIFO commands\n");
 		goto error;
 	}
 

+ 5 - 0
modules/tm/t_msgbuilder.c

@@ -23,6 +23,11 @@
 			(_d) += (_len);\
 		}while(0);
 
+#define append_str(_p,_str) \
+	do{  \
+		memcpy((_p), (_str).s, (_str).len); \
+		(_p)+=(_str).len;  \
+ 	} while(0);
 
 /* Build a local request based on a previous request; main
    customers of this function are local ACK and local CANCEL

+ 14 - 23
modules/tm/t_stats.c

@@ -20,41 +20,33 @@ struct t_stats *cur_stats, *acc_stats;
   
 int print_stats(  FILE *f )
 {
-	time_t now;
-
-	time(&now);
-
-	fprintf(f, "Time:\n----------------\n");
-	fprintf(f, "Now: %s", ctime(&now));
-	fprintf(f, "Up since: %s", ctime(&acc_stats->up_since));
-	fprintf(f, "Up time: %.0f [sec]\n", difftime(now, acc_stats->up_since));
-	fprintf(f, "\nCurrent values:\n----------------\n");
-	fprintf(f, "# of transactions: %d\n", 
+	fprintf(f, "Current:\n");
+	fprintf(f, "# of transactions: %d, ", 
 		cur_stats->transactions );
-	fprintf(f, "    - local: %d\n",
+	fprintf(f, "local: %d, ",
 		cur_stats->client_transactions );
-	fprintf(f, "    - waiting: %d\n",
+	fprintf(f, "waiting: %d\n",
 		cur_stats->waiting );
 
-	fprintf(f, "\nCummulative values:\n----------------\n");
-	fprintf(f, "# of transactions: %d\n",	
+	fprintf(f, "Total:\n");
+	fprintf(f, "# of transactions: %d,",
 		acc_stats->transactions );
-	fprintf(f, "    - local: %d\n",
+	fprintf(f, " local: %d,",
 		acc_stats->client_transactions );
-	fprintf(f, "    - waiting: %d\n",
+	fprintf(f, " waiting: %d\n",
 		acc_stats->waiting );
 
 	fprintf(f, "Replied localy: %d\n",
 		acc_stats->replied_localy );
-	fprintf(f, "Completion status 6xx: %d\n",
+	fprintf(f, "Completion status 6xx: %d,",
 		acc_stats->completed_6xx );
-	fprintf(f, "Completion status 5xx: %d\n",
+	fprintf(f, " 5xx: %d,",
 		acc_stats->completed_5xx );
-	fprintf(f, "Completion status 4xx: %d\n",
+	fprintf(f, " 4xx: %d,",
 		acc_stats->completed_4xx );
-	fprintf(f, "Completion status 3xx: %d\n",
+	fprintf(f, " 3xx: %d,",
 		acc_stats->completed_3xx );
-	fprintf(f, "Completion status 2xx: %d\n",
+	fprintf(f, "2xx: %d\n",
 		acc_stats->completed_2xx );
 	
 	return 1;
@@ -82,7 +74,7 @@ int static fifo_stats( FILE *pipe, char *response_file )
 
 }
 
-int init_stats(void)
+int init_tm_stats(void)
 {
 	cur_stats=shm_malloc(sizeof(struct t_stats));
 	if (cur_stats==0) {
@@ -103,6 +95,5 @@ int init_stats(void)
 
 	memset(cur_stats, 0, sizeof(struct t_stats) );
 	memset(acc_stats, 0, sizeof(struct t_stats) );
-	time(&acc_stats->up_since);
 	return 1;
 }

+ 1 - 3
modules/tm/t_stats.h

@@ -7,7 +7,6 @@
 #ifndef _T_STATS_H
 #define _T_STATS_H
 
-#include <time.h>
 
 extern struct t_stats *cur_stats, *acc_stats;
 
@@ -22,9 +21,8 @@ struct t_stats {
 	unsigned int completed_3xx, completed_4xx, completed_5xx, 
 		completed_6xx, completed_2xx;
 	unsigned int replied_localy;
-	time_t up_since;
 };
 
-int init_stats(void);
+int init_tm_stats(void);
 
 #endif

+ 1 - 1
modules/tm/tm_mod.c

@@ -238,7 +238,7 @@ static int mod_init(void)
 		return -1;
 	}
 	
-	if (init_stats()<0) {
+	if (init_tm_stats()<0) {
 		LOG(L_CRIT, "ERROR: mod_init: failed to init stats\n");
 		return -1;
 	}

+ 35 - 3
scripts/sc

@@ -105,12 +105,42 @@ prompt_pw() {
 
 # $1 = name $2=path $3=attempt
 print_stats() {
-echo "[cycle: $3; if screen empty, make sure server is alive]"
+
+echo "[cycle: $3; if screen empty, make sure server is alive and option fifo is set]"
+
+echo Up Time
+cat > $SER_FIFO <<EOF
+
+:uptime:$1
+EOF
+cat < $2
+echo
+
+echo Transaction Statistics
 cat > $SER_FIFO <<EOF
 
 :t_stats:$1
 EOF
 cat < $2
+echo
+
+echo Stateless Server Statistics
+cat > $SER_FIFO <<EOF
+
+:sl_stats:$1
+EOF
+cat < $2
+echo
+
+echo UsrLoc Stats
+cat > $SER_FIFO <<EOF
+
+:ul_stats:$1
+EOF
+cat < $2
+echo
+
+
 }
 
 
@@ -385,7 +415,7 @@ case $1 in
 		fi
 		;;
 
-	stats)
+	monitor|console|moni|con)
 		name=ser_receiver_$$
 		path=/tmp/$name
 		if [ ! -w $SER_FIFO ]; then
@@ -399,9 +429,11 @@ case $1 in
 			exit 1
 		fi
 		attempt=0
+		clear
 		while [ 1 -eq 1 ]; do
 			attempt=`expr $attempt + 1`
-			clear
+			#clear
+			tput cup 0 0
 			print_stats $name $path $attempt
 			sleep $WATCH_PERIOD
 		done

+ 3 - 4
test/message02.sip

@@ -1,11 +1,10 @@
 MESSAGE sip:[email protected] SIP/2.0
-Via: SIP/2.0/UDP fox.iptel.org:5060
+Via: SIP/2.0/UDP bat.iptel.org:9
 From: "bogdan" <sip:[email protected]>;tag=0e99b1e7-ff50-4875-94ef-4ca5c27e2705
-To: 
-Call-ID: [email protected]
+xCall-ID: [email protected]
 CSeq: 7 MESSAGE
 Contact: <sip:195.37.78.169:11457>
 User-Agent: Windows RTC/1.0
-Content-Type: text/plain
+text/plain
 Content-Length: 4
 

+ 2 - 2
test/message03.sip

@@ -1,5 +1,5 @@
-MESSAGE sip:jiri@iptel.org SIP/2.0
-Via: SIP/2.0/UDP fox.iptel.org:5060
+MESSAGE sip:x@bat.iptel.org SIP/2.0
+Via: SIP/2.0/UDP bat.iptel.org:9
 From: sip:[email protected];tag=16df4fe56e8782ecaa5d53ae36fb9240
 To: sip:[email protected]
 Call-ID: [email protected]

+ 1 - 1
test/register03.sip

@@ -3,7 +3,7 @@ To: <sip:[email protected]>
 From: <sip:[email protected]>
 Call-ID: [email protected]
 CSeq: 4 REGISTER
-Via: SIP/2.0/UDP iptel.org:5060
+Via: SIP/2.0/UDP bat.iptel.org:5060
 User-Agent:  UbiquityUserAgent/4
 Expires: 0
 Content-Length: 0

+ 1 - 1
test/register04.sip

@@ -1,5 +1,5 @@
 REGISTER sip:iptel.org:5060 SIP/2.0
-To:poo [email protected]
+To:poo <[email protected]>
 From: <sip:[email protected]>
 Call-ID: [email protected]
 CSeq: 4 REGISTER

+ 13 - 4
test/stress.cfg

@@ -6,13 +6,14 @@
 
 # ----------- global configuration parameters ------------------------
 
-debug=3
-fork=no
+debug=0
+fork=1
 log_stderror=yes	# (cmd line: -E)
 check_via=no # (cmd. line: -v)
 dns=no # (cmd. line: -r)
 syn_branch=1
 reply_to_via=0
+fifo="/tmp/ser_fifo"
 
 # advertise IP address in Via (as opposed to advertising DNS name
 # which is annoying for downstream servers and some phones can
@@ -23,7 +24,7 @@ listen=195.37.77.100
 
 loadmodule "../sip_router/modules/sl/sl.so"
 loadmodule "../sip_router/modules/print/print.so"
-#loadmodule "../sip_router/modules/tm/tm.so"
+#loadmodule "../sip_router/modules/tm/tm_mod.so"
 loadmodule "../sip_router/modules/usrloc/usrloc.so"
 
 # ----------------- setting module-specific parameters ---------------
@@ -34,14 +35,22 @@ modparam("usrloc", "use_database",   0)
 modparam("usrloc", "flush_interval", 3600)
 
 # -- tm params --
-modparam("tm", "fr_timer", 10 )
+modparam("tm", "fr_timer", 5 )
 modparam("tm", "fr_inv_timer", 5 )
+modparam("tm", "wt_timer", 5 )
 
 # -------------------------  request routing logic -------------------
 
 # main routing logic
 
 route{
+	append_branch("sip:[email protected]:5088");
+	append_branch("sip:[email protected]:5088");
+	t_on_negative("1");
 	t_relay_to("bat.iptel.org","5088");
 }
 
+reply_route[1] {
+	append_branch("sip:[email protected]:5088");
+}
+

+ 1 - 1
test/transaction.fifo

@@ -1,6 +1,6 @@
 :t_uac:hh
 MESSAGE
-sip:[email protected]
+sip:jirim@iptel.org
 foo: bar
 x: y
 p_header: p_value