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