- ipv6 support (-DUSE_IPV6)
[sip-router] / stats.h
1 #ifndef stats_h
2 #define stats_h
3
4 #include <ctype.h>
5 #include <sys/mman.h>
6 #include <sys/fcntl.h>
7 #include <sys/time.h>
8 #include <time.h>
9 #include <sys/utsname.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <errno.h>
13
14
15 #define _update_request( method, dir )                  \
16         { if (stat_file!=NULL) switch( method ) {       \
17                 case METHOD_INVITE: stats->dir##_requests_inv++; break; \
18                 case METHOD_ACK: stats->dir##_requests_ack++; break;            \
19                 case METHOD_CANCEL: stats->dir##_requests_cnc++; break; \
20                 case METHOD_BYE: stats->dir##_requests_bye++; break;            \
21                 case METHOD_OTHER: stats->dir##_requests_other++; break;        \
22                 default: LOG(L_ERR, "ERROR: unknown method in rq stats (%s)\n", #dir);  \
23                 }       \
24         }
25
26
27 /*
28 #define update_received_request( method ) _update_request( method, received )
29 #define update_sent_request( method ) _update_request( method, sent )
30
31 #define update_received_response( statusclass ) _update_response( statusclass, received )
32 #define update_sent_response( statusclass ) _update_response( statusclass, sent )
33 #define update_received_drops   {  stats->received_drops++; }
34 #define update_fail_on_send     {  stats->failed_on_send++; }
35 */
36
37 #define         _statusline(class, dir )       case class: stats->dir##_responses_##class++; break;
38
39 #define _update_response( statusclass, dir )            \
40         { if (stat_file!=NULL)                          \
41                 switch( statusclass ) {                 \
42                         _statusline(1, dir)                   \
43                         _statusline(2, dir)                   \
44                         _statusline(3, dir)                   \
45                         _statusline(4, dir)                   \
46                         _statusline(5, dir)                   \
47                         _statusline(6, dir)                   \
48                         default: LOG(L_INFO, "ERROR: unusual status code received in stats (%s)\n", #dir);    \
49                 }       \
50         }
51
52 #ifdef STATS
53 #       define STATS_RX_REQUEST(method) _update_request(method, received)
54 #       define STATS_TX_REQUEST(method) _update_request(method, sent )
55 #       define STATS_RX_RESPONSE(class) _update_response( class, received )
56 #       define STATS_TX_RESPONSE(class) _update_response( class, sent )
57 #       define STATS_RX_DROPS {  stats->received_drops++; }
58 #       define STATS_TX_DROPS {  stats->failed_on_send++; }
59 #else
60 #       define STATS_RX_REQUEST(method)
61 #       define STATS_TX_REQUEST(method)
62 #       define STATS_RX_RESPONSE(class) 
63 #       define STATS_TX_RESPONSE(class) 
64 #       define STATS_RX_DROPS 
65 #       define STATS_TX_DROPS 
66 #endif
67
68 #ifdef STATS
69
70
71 struct stats_s {
72
73         unsigned int    process_index;
74         pid_t           pid;
75         time_t          start_time;
76
77         unsigned long 
78
79         /* received packets */
80
81         received_requests_inv,          /* received_requests */
82         received_requests_ack,
83         received_requests_cnc,
84         received_requests_bye,
85         received_requests_other,
86
87         received_responses_1,           /* received_requests */
88         received_responses_2,
89         received_responses_3,
90         received_responses_4,
91         received_responses_5,
92         received_responses_6,
93         received_responses_other,
94
95         received_drops,                 /* all messages we received and did not process
96                                            successfully; reasons include SIP sanity checks 
97                                            (missing Vias, neither request nor response, 
98                                            failed parsing), ser errors (malloc, action
99                                            failure)
100                                         */
101
102         /* sent */
103
104         /* sent_requests */
105         sent_requests_inv,
106         sent_requests_ack,
107         sent_requests_cnc,
108         sent_requests_bye,
109         sent_requests_other,
110
111         /* sent responses */
112         sent_responses_1,
113         sent_responses_2,
114         sent_responses_3,
115         sent_responses_4,
116         sent_responses_5,
117         sent_responses_6,
118
119         processed_requests,
120         processed_responses,
121         acc_req_time,
122         acc_res_time,
123
124         failed_on_send;                 
125                           
126 };
127
128
129 extern struct stats_s *stats;
130
131 void setstats( int child_index );
132 void dump_statistic( FILE *fp, struct stats_s *istats );
133 int dump_all_statistic();
134 int init_stats( int nr_of_processes );
135
136
137
138 #endif
139 #endif