pkg: fix wrong package name, closes FS#148, reported from Andrew Pogrebennyk
[sip-router] / stats.h
1 /*
2  * $Id$
3  *
4  *
5  * Copyright (C) 2001-2003 FhG Fokus
6  *
7  * This file is part of ser, a free SIP server.
8  *
9  * ser is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version
13  *
14  * For a license to use the ser software under conditions
15  * other than those described here, or to purchase support for this
16  * software, please contact iptel.org by e-mail at the following addresses:
17  *    info@iptel.org
18  *
19  * ser is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License 
25  * along with this program; if not, write to the Free Software 
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27  */
28
29
30 #ifndef stats_h
31 #define stats_h
32
33 #include <ctype.h>
34 #include <sys/mman.h>
35 #include <sys/fcntl.h>
36 #include <sys/time.h>
37 #include <time.h>
38 #include <sys/utsname.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <errno.h>
42
43
44 #define _update_request( method, dir )                  \
45         do{ if (stat_file!=NULL) switch( method ) {     \
46                 case METHOD_INVITE: stats->dir##_requests_inv++; break; \
47                 case METHOD_ACK: stats->dir##_requests_ack++; break;            \
48                 case METHOD_CANCEL: stats->dir##_requests_cnc++; break; \
49                 case METHOD_BYE: stats->dir##_requests_bye++; break;            \
50                 case METHOD_INFO: stats->dir##_requests_info++; break;          \
51                 case METHOD_OTHER: stats->dir##_requests_other++; break;        \
52                 default: LOG(L_ERR, "ERROR: unknown method in rq stats (%s)\n", \
53                                                         #dir);  \
54                 }       \
55         }while(0)
56
57
58 /*
59 #define update_received_request( method ) _update_request( method, received )
60 #define update_sent_request( method ) _update_request( method, sent )
61
62 #define update_received_response( statusclass ) \
63                                                                         _update_response( statusclass, received )
64 #define update_sent_response( statusclass ) \
65                                                                         _update_response( statusclass, sent )
66 #define update_received_drops   {  stats->received_drops++; }
67 #define update_fail_on_send     {  stats->failed_on_send++; }
68 */
69
70 #define         _statusline(class, dir )\
71                                                 case class: stats->dir##_responses_##class++; break;
72
73 /* FIXME: Don't have case for _other (see received_responses_other) */
74 #define _update_response( statusclass, dir )            \
75         do{ if (stat_file!=NULL)                          \
76                 switch( statusclass ) {                 \
77                         _statusline(1, dir)                   \
78                         _statusline(2, dir)                   \
79                         _statusline(3, dir)                   \
80                         _statusline(4, dir)                   \
81                         _statusline(5, dir)                   \
82                         _statusline(6, dir)                   \
83                         default: LOG(L_INFO, "ERROR: unusual status code"\
84                                                                                  " received in stats (%s)\n", #dir); \
85                 }       \
86         }while(0)
87
88 #ifdef STATS
89 #       define STATS_RX_REQUEST(method) _update_request(method, received)
90 #       define STATS_TX_REQUEST(method) _update_request(method, sent )
91 #       define STATS_RX_RESPONSE(class) _update_response( class, received )
92 #       define STATS_TX_RESPONSE(class) _update_response( class, sent )
93 #       define STATS_RX_DROPS {  stats->received_drops++; }
94 #       define STATS_TX_DROPS {  stats->failed_on_send++; }
95 #else
96 #       define STATS_RX_REQUEST(method)
97 #       define STATS_TX_REQUEST(method)
98 #       define STATS_RX_RESPONSE(class) 
99 #       define STATS_TX_RESPONSE(class) 
100 #       define STATS_RX_DROPS 
101 #       define STATS_TX_DROPS 
102 #endif
103
104 #ifdef STATS
105
106
107 struct stats_s {
108
109         unsigned int    process_index;
110         pid_t           pid;
111         time_t          start_time;
112
113         unsigned long 
114
115         /* received packets */
116
117         received_requests_inv,          /* received_requests */
118         received_requests_ack,
119         received_requests_cnc,
120         received_requests_bye,
121         received_requests_other,
122
123         received_responses_1,           /* received_responses */
124         received_responses_2,
125         received_responses_3,
126         received_responses_4,
127         received_responses_5,
128         received_responses_6,
129         received_responses_other,
130
131         received_drops, /* all messages we received and did not process
132                                            successfully; reasons include SIP sanity checks 
133                                            (missing Vias, neither request nor response, 
134                                            failed parsing), ser errors (malloc, action
135                                            failure)
136                                         */
137
138         /* sent */
139
140         /* sent_requests */
141         sent_requests_inv,
142         sent_requests_ack,
143         sent_requests_cnc,
144         sent_requests_bye,
145         sent_requests_other,
146
147         /* sent responses */
148         sent_responses_1,
149         sent_responses_2,
150         sent_responses_3,
151         sent_responses_4,
152         sent_responses_5,
153         sent_responses_6,
154         /* FIXME: Don't want sent_responses_other?? */
155
156         processed_requests,
157         processed_responses,
158         acc_req_time,
159         acc_res_time,
160
161         failed_on_send;                 
162 };
163
164 extern struct stats_s *stats;
165 extern char *stat_file;
166
167 int init_stats( int nr_of_processes );
168 void setstats( int child_index );
169 int dump_all_statistic();
170 int dump_statistic(FILE *fp, struct stats_s *istats, int printheader);
171 /* Registers handlers with SNMP module */
172 int stats_register(); 
173
174 #endif
175 #endif