stats.h
93d87145
 /*
  * $Id$
  *
7dd0b342
  *
53c7e0f1
  * Copyright (C) 2001-2003 FhG Fokus
7dd0b342
  *
  * This file is part of ser, a free SIP server.
  *
  * ser is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
  * For a license to use the ser software under conditions
  * other than those described here, or to purchase support for this
  * software, please contact iptel.org by e-mail at the following addresses:
  *    info@iptel.org
  *
  * ser is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
93d87145
  */
 
7dd0b342
 
5b253cc6
 #ifndef stats_h
 #define stats_h
 
f571aa35
 #include <ctype.h>
 #include <sys/mman.h>
 #include <sys/fcntl.h>
 #include <sys/time.h>
 #include <time.h>
 #include <sys/utsname.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
 
 
dda9dab1
 #define _update_request( method, dir )			\
e3fc93f4
 	do{ if (stat_file!=NULL) switch( method ) {	\
dda9dab1
           	case METHOD_INVITE: stats->dir##_requests_inv++; break;	\
           	case METHOD_ACK: stats->dir##_requests_ack++; break;		\
           	case METHOD_CANCEL: stats->dir##_requests_cnc++; break;	\
           	case METHOD_BYE: stats->dir##_requests_bye++; break;		\
0f0f44c4
 		case METHOD_INFO: stats->dir##_requests_info++; break;		\
dda9dab1
           	case METHOD_OTHER: stats->dir##_requests_other++; break;	\
e3fc93f4
           	default: LOG(L_ERR, "ERROR: unknown method in rq stats (%s)\n", \
 							#dir);	\
dda9dab1
 		}	\
e3fc93f4
 	}while(0)
dda9dab1
 
 
 /*
 #define update_received_request( method ) _update_request( method, received )
 #define update_sent_request( method ) _update_request( method, sent )
 
e3fc93f4
 #define update_received_response( statusclass ) \
 									_update_response( statusclass, received )
 #define update_sent_response( statusclass ) \
 									_update_response( statusclass, sent )
dda9dab1
 #define update_received_drops	{  stats->received_drops++; }
 #define update_fail_on_send	{  stats->failed_on_send++; }
 */
 
e3fc93f4
 #define         _statusline(class, dir )\
 						case class: stats->dir##_responses_##class++; break;
dda9dab1
 
811c8ef0
 /* FIXME: Don't have case for _other (see received_responses_other) */
dda9dab1
 #define _update_response( statusclass, dir )		\
e3fc93f4
         do{ if (stat_file!=NULL)                          \
dda9dab1
                 switch( statusclass ) {                 \
                         _statusline(1, dir)                   \
                         _statusline(2, dir)                   \
                         _statusline(3, dir)                   \
                         _statusline(4, dir)                   \
                         _statusline(5, dir)                   \
                         _statusline(6, dir)                   \
e3fc93f4
                         default: LOG(L_INFO, "ERROR: unusual status code"\
 										 " received in stats (%s)\n", #dir); \
dda9dab1
                 }       \
e3fc93f4
         }while(0)
dda9dab1
 
 #ifdef STATS
 #	define STATS_RX_REQUEST(method) _update_request(method, received)
 #	define STATS_TX_REQUEST(method) _update_request(method, sent )
 #	define STATS_RX_RESPONSE(class) _update_response( class, received )
 #	define STATS_TX_RESPONSE(class) _update_response( class, sent )
 #	define STATS_RX_DROPS {  stats->received_drops++; }
 #	define STATS_TX_DROPS {  stats->failed_on_send++; }
 #else
 #	define STATS_RX_REQUEST(method)
 #	define STATS_TX_REQUEST(method)
 #	define STATS_RX_RESPONSE(class) 
 #	define STATS_TX_RESPONSE(class) 
 #	define STATS_RX_DROPS 
 #	define STATS_TX_DROPS 
 #endif
f571aa35
 
0a974a1d
 #ifdef STATS
 
f571aa35
 
5b253cc6
 struct stats_s {
 
f571aa35
 	unsigned int	process_index;
 	pid_t		pid;
 	time_t		start_time;
 
 	unsigned long 
 
 	/* received packets */
 
 	received_requests_inv, 		/* received_requests */
 	received_requests_ack,
 	received_requests_cnc,
 	received_requests_bye,
 	received_requests_other,
 
811c8ef0
 	received_responses_1, 		/* received_responses */
f571aa35
 	received_responses_2,
 	received_responses_3,
 	received_responses_4,
 	received_responses_5,
 	received_responses_6,
 	received_responses_other,
 
811c8ef0
 	received_drops,	/* all messages we received and did not process
f571aa35
 					   successfully; reasons include SIP sanity checks 
 					   (missing Vias, neither request nor response, 
 					   failed parsing), ser errors (malloc, action
 					   failure)
 					*/
 
 	/* sent */
 
 	/* sent_requests */
 	sent_requests_inv,
 	sent_requests_ack,
 	sent_requests_cnc,
 	sent_requests_bye,
 	sent_requests_other,
 
 	/* sent responses */
 	sent_responses_1,
 	sent_responses_2,
 	sent_responses_3,
 	sent_responses_4,
 	sent_responses_5,
 	sent_responses_6,
811c8ef0
 	/* FIXME: Don't want sent_responses_other?? */
f571aa35
 
4f3faaaf
 	processed_requests,
 	processed_responses,
 	acc_req_time,
 	acc_res_time,
 
f571aa35
 	failed_on_send;			
5b253cc6
 };
 
f571aa35
 extern struct stats_s *stats;
811c8ef0
 extern char *stat_file;
5b253cc6
 
811c8ef0
 int init_stats( int nr_of_processes );
f571aa35
 void setstats( int child_index );
 int dump_all_statistic();
811c8ef0
 int dump_statistic(FILE *fp, struct stats_s *istats, int printheader);
 /* Registers handlers with SNMP module */
 int stats_register(); 
f571aa35
 
 #endif
0a974a1d
 #endif