Allow more slicing && dicing of statistics.
[freeradius.git] / src / include / stats.h
1 #ifndef FR_STATS_H
2 #define FR_STATS_H
3
4 /*
5  * stats.h      Structures and functions for statistics.
6  *
7  * Version:     $Id$
8  *
9  *   This program 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  *   This program is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with this program; if not, write to the Free Software
21  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  *
23  * Copyright 2005,2006,2007,2008  The FreeRADIUS server project
24  */
25
26 #include <freeradius-devel/ident.h>
27 RCSIDH(stats_h, "$Id$")
28
29 #ifdef WITH_STATS_64BIT
30 typedef uint64_t fr_uint_t;
31 #else
32 typedef uint32_t fr_uint_t;
33 #endif
34
35 #ifdef WITH_STATS
36 typedef struct fr_stats_t {
37         fr_uint_t               total_requests;
38         fr_uint_t               total_invalid_requests;
39         fr_uint_t               total_dup_requests;
40         fr_uint_t               total_responses;
41         fr_uint_t               total_access_accepts;
42         fr_uint_t               total_access_rejects;
43         fr_uint_t               total_access_challenges;
44         fr_uint_t               total_malformed_requests;
45         fr_uint_t               total_bad_authenticators;
46         fr_uint_t               total_packets_dropped;
47         fr_uint_t               total_no_records;
48         fr_uint_t               total_unknown_types;
49 } fr_stats_t;
50
51 /*
52  *  Taken from RFC 2619 and RFC 2621
53  */
54 typedef struct fr_client_stats_t {
55         /* IP address */
56         /* Client ID (string ) */
57         fr_uint_t               requests;
58         fr_uint_t       dup_requests;
59         fr_uint_t       responses;
60         fr_uint_t       accepts;
61         fr_uint_t       rejects;
62         fr_uint_t       challenges;
63         fr_uint_t       malformed_requests;
64         fr_uint_t       bad_authenticators;
65         fr_uint_t       packets_dropped;
66         fr_uint_t       unknown_types;
67 } fr_client_stats_t;
68
69
70 extern fr_stats_t       radius_auth_stats;
71 extern fr_stats_t       radius_acct_stats;
72
73 void request_stats_final(REQUEST *request);
74 void request_stats_reply(REQUEST *request);
75
76 #define RAD_STATS_INC(_x) _x++
77 #ifdef WITH_ACCOUNTING
78 #define RAD_STATS_TYPE_INC(_listener, _x) if (_listener->type == RAD_LISTEN_AUTH) { \
79                                        radius_auth_stats._x++; \
80                                        _listener->auth._x++; \
81                                      } else if (_listener->type == RAD_LISTEN_ACCT) { \
82                                        radius_acct_stats._x++; \
83                                        _listener->acct._x++; }
84
85 #define RAD_STATS_CLIENT_INC(_listener, _client, _x) if (_listener->type == RAD_LISTEN_AUTH) \
86                                        _client->auth->_x++; \
87                                      else if (_listener->type == RAD_LISTEN_ACCT) \
88                                        _client->acct->_x++
89
90 #else  /* WITH_ACCOUNTING */
91
92 #define RAD_STATS_TYPE_INC(_listener, _x) { radius_auth_stats._x++; _listener->auth._x++; }
93
94 #define RAD_STATS_CLIENT_INC(_listener, _client, _x) _client->auth->_x++
95
96 #endif /* WITH_ACCOUNTING */
97
98
99 #else  /* WITH_STATS */
100 #define request_stats_final(_x)
101
102 #define  RAD_STATS_INC(_x)
103 #define RAD_STATS_TYPE_INC(_listener, _x)
104 #define RAD_STATS_CLIENT_INC(_listener, _client, _x)
105
106 #endif
107
108 #endif /* FR_STATS_H */