• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • Directories
  • File List
  • Globals

stats.h

00001 /*
00002  * $Id$
00003  *
00004  *
00005  * Copyright (C) 2001-2003 FhG Fokus
00006  *
00007  * This file is part of ser, a free SIP server.
00008  *
00009  * ser is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version
00013  *
00014  * For a license to use the ser software under conditions
00015  * other than those described here, or to purchase support for this
00016  * software, please contact iptel.org by e-mail at the following addresses:
00017  *    info@iptel.org
00018  *
00019  * ser is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU General Public License 
00025  * along with this program; if not, write to the Free Software 
00026  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027  */
00028 
00029 
00030 #ifndef stats_h
00031 #define stats_h
00032 
00033 #include <ctype.h>
00034 #include <sys/mman.h>
00035 #include <sys/fcntl.h>
00036 #include <sys/time.h>
00037 #include <time.h>
00038 #include <sys/utsname.h>
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include <errno.h>
00042 
00043 
00044 #define _update_request( method, dir )                  \
00045         do{ if (stat_file!=NULL) switch( method ) {     \
00046                 case METHOD_INVITE: stats->dir##_requests_inv++; break; \
00047                 case METHOD_ACK: stats->dir##_requests_ack++; break;            \
00048                 case METHOD_CANCEL: stats->dir##_requests_cnc++; break; \
00049                 case METHOD_BYE: stats->dir##_requests_bye++; break;            \
00050                 case METHOD_INFO: stats->dir##_requests_info++; break;          \
00051                 case METHOD_OTHER: stats->dir##_requests_other++; break;        \
00052                 default: LOG(L_ERR, "ERROR: unknown method in rq stats (%s)\n", \
00053                                                         #dir);  \
00054                 }       \
00055         }while(0)
00056 
00057 
00058 /*
00059 #define update_received_request( method ) _update_request( method, received )
00060 #define update_sent_request( method ) _update_request( method, sent )
00061 
00062 #define update_received_response( statusclass ) \
00063                                                                         _update_response( statusclass, received )
00064 #define update_sent_response( statusclass ) \
00065                                                                         _update_response( statusclass, sent )
00066 #define update_received_drops   {  stats->received_drops++; }
00067 #define update_fail_on_send     {  stats->failed_on_send++; }
00068 */
00069 
00070 #define         _statusline(class, dir )\
00071                                                 case class: stats->dir##_responses_##class++; break;
00072 
00073 /* FIXME: Don't have case for _other (see received_responses_other) */
00074 #define _update_response( statusclass, dir )            \
00075         do{ if (stat_file!=NULL)                          \
00076                 switch( statusclass ) {                 \
00077                         _statusline(1, dir)                   \
00078                         _statusline(2, dir)                   \
00079                         _statusline(3, dir)                   \
00080                         _statusline(4, dir)                   \
00081                         _statusline(5, dir)                   \
00082                         _statusline(6, dir)                   \
00083                         default: LOG(L_INFO, "ERROR: unusual status code"\
00084                                                                                  " received in stats (%s)\n", #dir); \
00085                 }       \
00086         }while(0)
00087 
00088 #ifdef STATS
00089 #       define STATS_RX_REQUEST(method) _update_request(method, received)
00090 #       define STATS_TX_REQUEST(method) _update_request(method, sent )
00091 #       define STATS_RX_RESPONSE(class) _update_response( class, received )
00092 #       define STATS_TX_RESPONSE(class) _update_response( class, sent )
00093 #       define STATS_RX_DROPS {  stats->received_drops++; }
00094 #       define STATS_TX_DROPS {  stats->failed_on_send++; }
00095 #else
00096 #       define STATS_RX_REQUEST(method)
00097 #       define STATS_TX_REQUEST(method)
00098 #       define STATS_RX_RESPONSE(class) 
00099 #       define STATS_TX_RESPONSE(class) 
00100 #       define STATS_RX_DROPS 
00101 #       define STATS_TX_DROPS 
00102 #endif
00103 
00104 #ifdef STATS
00105 
00106 
00107 struct stats_s {
00108 
00109         unsigned int    process_index;
00110         pid_t           pid;
00111         time_t          start_time;
00112 
00113         unsigned long 
00114 
00115         /* received packets */
00116 
00117         received_requests_inv,          /* received_requests */
00118         received_requests_ack,
00119         received_requests_cnc,
00120         received_requests_bye,
00121         received_requests_other,
00122 
00123         received_responses_1,           /* received_responses */
00124         received_responses_2,
00125         received_responses_3,
00126         received_responses_4,
00127         received_responses_5,
00128         received_responses_6,
00129         received_responses_other,
00130 
00131         received_drops, /* all messages we received and did not process
00132                                            successfully; reasons include SIP sanity checks 
00133                                            (missing Vias, neither request nor response, 
00134                                            failed parsing), ser errors (malloc, action
00135                                            failure)
00136                                         */
00137 
00138         /* sent */
00139 
00140         /* sent_requests */
00141         sent_requests_inv,
00142         sent_requests_ack,
00143         sent_requests_cnc,
00144         sent_requests_bye,
00145         sent_requests_other,
00146 
00147         /* sent responses */
00148         sent_responses_1,
00149         sent_responses_2,
00150         sent_responses_3,
00151         sent_responses_4,
00152         sent_responses_5,
00153         sent_responses_6,
00154         /* FIXME: Don't want sent_responses_other?? */
00155 
00156         processed_requests,
00157         processed_responses,
00158         acc_req_time,
00159         acc_res_time,
00160 
00161         failed_on_send;                 
00162 };
00163 
00164 extern struct stats_s *stats;
00165 extern char *stat_file;
00166 
00167 int init_stats( int nr_of_processes );
00168 void setstats( int child_index );
00169 int dump_all_statistic();
00170 int dump_statistic(FILE *fp, struct stats_s *istats, int printheader);
00171 /* Registers handlers with SNMP module */
00172 int stats_register(); 
00173 
00174 #endif
00175 #endif

Generated on Tue May 22 2012 13:10:16 for SIP Router by  doxygen 1.7.1