Added more stats
authorJiri Kuthan <jiri@iptel.org>
Tue, 20 Aug 2002 00:19:05 +0000 (00:19 +0000)
committerJiri Kuthan <jiri@iptel.org>
Tue, 20 Aug 2002 00:19:05 +0000 (00:19 +0000)
15 files changed:
Makefile.defs
fifo_server.c
fifo_server.h
main.c
modules/tm/t_msgbuilder.c
modules/tm/t_stats.c
modules/tm/t_stats.h
modules/tm/tm_mod.c
scripts/sc
test/message02.sip
test/message03.sip
test/register03.sip
test/register04.sip
test/stress.cfg
test/transaction.fifo

index 28b5141..e16da55 100644 (file)
@@ -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 \
index 7571c73..0871b14 100644 (file)
@@ -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;
+}
index d304aa3..bd47ebd 100644 (file)
 
 #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
diff --git a/main.c b/main.c
index b36a1cb..7c96a50 100644 (file)
--- a/main.c
+++ b/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;
        }
 
index 6d3739f..4612405 100644 (file)
                        (_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
index 0123fb2..784f92b 100644 (file)
@@ -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;
 }
index db2042a..43d90c4 100644 (file)
@@ -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
index b87dcc9..e68b9a8 100644 (file)
@@ -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;
        }
index ef3c79e..208fb6c 100755 (executable)
@@ -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
index 6c9ffcd..512806b 100644 (file)
@@ -1,11 +1,10 @@
 MESSAGE sip:756843@iptel.org SIP/2.0
-Via: SIP/2.0/UDP fox.iptel.org:5060
+Via: SIP/2.0/UDP bat.iptel.org:9
 From: "bogdan" <sip:bogdan@iptel.org>;tag=0e99b1e7-ff50-4875-94ef-4ca5c27e2705
-To: 
-Call-ID: 02b1191c-447e-4bd0-b771-c039fc0d9d84@195.37.78.169
+xCall-ID: 02b1191c-447e-4bd0-b771-c039fc0d9d84@195.37.78.169
 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
 
index f503cab..a70d712 100644 (file)
@@ -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:msilo@iptel.org;tag=16df4fe56e8782ecaa5d53ae36fb9240
 To: sip:dcm@iptel.org
 Call-ID: 02b1191c-447e-4bd0-b771-c039fc0d9d84@195.37.78.169
index f8bf741..1cd00d0 100644 (file)
@@ -3,7 +3,7 @@ To: <sip:jiri@iptel.org>
 From: <sip:jiri@iptel.org>
 Call-ID: 7138115741688223740@195.37.78.226
 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
index 9a12203..9471826 100644 (file)
@@ -1,5 +1,5 @@
 REGISTER sip:iptel.org:5060 SIP/2.0
-To:poo bear@iptel.org
+To:poo <bear@iptel.org>
 From: <sip:jiri@iptel.org>
 Call-ID: 7138115741688223740@195.37.78.226
 CSeq: 4 REGISTER
index c6a57a8..3777628 100644 (file)
@@ -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:bla@bat.iptel.org:5088");
+       append_branch("sip:blb@bat.iptel.org:5088");
+       t_on_negative("1");
        t_relay_to("bat.iptel.org","5088");
 }
 
+reply_route[1] {
+       append_branch("sip:mrx@bat.iptel.org:5088");
+}
+
index 709d4cc..2b59d60 100644 (file)
@@ -1,6 +1,6 @@
 :t_uac:hh
 MESSAGE
-sip:jiri@iptel.org
+sip:jirim@iptel.org
 foo: bar
 x: y
 p_header: p_value