de382fafcb52bfba7bf67dbbe37d2618dd4aded3
[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 /* FIXME: Don't have case for _other (see received_responses_other) */
40 #define _update_response( statusclass, dir )            \
41         { if (stat_file!=NULL)                          \
42                 switch( statusclass ) {                 \
43                         _statusline(1, dir)                   \
44                         _statusline(2, dir)                   \
45                         _statusline(3, dir)                   \
46                         _statusline(4, dir)                   \
47                         _statusline(5, dir)                   \
48                         _statusline(6, dir)                   \
49                         default: LOG(L_INFO, "ERROR: unusual status code received in stats (%s)\n", #dir);    \
50                 }       \
51         }
52
53 #ifdef STATS
54 #       define STATS_RX_REQUEST(method) _update_request(method, received)
55 #       define STATS_TX_REQUEST(method) _update_request(method, sent )
56 #       define STATS_RX_RESPONSE(class) _update_response( class, received )
57 #       define STATS_TX_RESPONSE(class) _update_response( class, sent )
58 #       define STATS_RX_DROPS {  stats->received_drops++; }
59 #       define STATS_TX_DROPS {  stats->failed_on_send++; }
60 #else
61 #       define STATS_RX_REQUEST(method)
62 #       define STATS_TX_REQUEST(method)
63 #       define STATS_RX_RESPONSE(class) 
64 #       define STATS_TX_RESPONSE(class) 
65 #       define STATS_RX_DROPS 
66 #       define STATS_TX_DROPS 
67 #endif
68
69 #ifdef STATS
70
71
72 struct stats_s {
73
74         unsigned int    process_index;
75         pid_t           pid;
76         time_t          start_time;
77
78         unsigned long 
79
80         /* received packets */
81
82         received_requests_inv,          /* received_requests */
83         received_requests_ack,
84         received_requests_cnc,
85         received_requests_bye,
86         received_requests_other,
87
88         received_responses_1,           /* received_responses */
89         received_responses_2,
90         received_responses_3,
91         received_responses_4,
92         received_responses_5,
93         received_responses_6,
94         received_responses_other,
95
96         received_drops, /* all messages we received and did not process
97                                            successfully; reasons include SIP sanity checks 
98                                            (missing Vias, neither request nor response, 
99                                            failed parsing), ser errors (malloc, action
100                                            failure)
101                                         */
102
103         /* sent */
104
105         /* sent_requests */
106         sent_requests_inv,
107         sent_requests_ack,
108         sent_requests_cnc,
109         sent_requests_bye,
110         sent_requests_other,
111
112         /* sent responses */
113         sent_responses_1,
114         sent_responses_2,
115         sent_responses_3,
116         sent_responses_4,
117         sent_responses_5,
118         sent_responses_6,
119         /* FIXME: Don't want sent_responses_other?? */
120
121         processed_requests,
122         processed_responses,
123         acc_req_time,
124         acc_res_time,
125
126         failed_on_send;                 
127 };
128
129 extern struct stats_s *stats;
130 extern char *stat_file;
131
132 int init_stats( int nr_of_processes );
133 void setstats( int child_index );
134 int dump_all_statistic();
135 int dump_statistic(FILE *fp, struct stats_s *istats, int printheader);
136 /* Registers handlers with SNMP module */
137 int stats_register(); 
138
139 #endif
140 #endif