Add "extern C {...} to header files for C++ builds.
[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 __cplusplus
30 extern "C" {
31 #endif
32
33 #ifdef WITH_STATS_64BIT
34 typedef uint64_t fr_uint_t;
35 #else
36 typedef uint32_t fr_uint_t;
37 #endif
38
39 #ifdef WITH_STATS
40 typedef struct fr_stats_t {
41         fr_uint_t               total_requests;
42         fr_uint_t               total_invalid_requests;
43         fr_uint_t               total_dup_requests;
44         fr_uint_t               total_responses;
45         fr_uint_t               total_access_accepts;
46         fr_uint_t               total_access_rejects;
47         fr_uint_t               total_access_challenges;
48         fr_uint_t               total_malformed_requests;
49         fr_uint_t               total_bad_authenticators;
50         fr_uint_t               total_packets_dropped;
51         fr_uint_t               total_no_records;
52         fr_uint_t               total_unknown_types;
53 } fr_stats_t;
54
55 typedef struct fr_stats_ema_t {
56         int             window;
57
58         int             f1, f10;
59         int             ema1, ema10;
60
61 } fr_stats_ema_t;
62
63 extern fr_stats_t       radius_auth_stats;
64 extern fr_stats_t       radius_acct_stats;
65 #ifdef WITH_PROXY
66 extern fr_stats_t       proxy_auth_stats;
67 extern fr_stats_t       proxy_acct_stats;
68 #endif
69
70 void radius_stats_init(int flag);
71 void request_stats_final(REQUEST *request);
72 void request_stats_reply(REQUEST *request);
73 void radius_stats_ema(fr_stats_ema_t *ema,
74                       struct timeval *start, struct timeval *end);
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                                      } else if (_listener->type == RAD_LISTEN_ACCT) { \
81                                        radius_acct_stats._x++; } \
82                                        _listener->stats._x++
83
84 #define RAD_STATS_CLIENT_INC(_listener, _client, _x) if (_listener->type == RAD_LISTEN_AUTH) \
85                                        _client->auth->_x++; \
86                                      else if (_listener->type == RAD_LISTEN_ACCT) \
87                                        _client->acct->_x++
88
89 #else  /* WITH_ACCOUNTING */
90
91 #define RAD_STATS_TYPE_INC(_listener, _x) { radius_auth_stats._x++; _listener->stats._x++; }
92
93 #define RAD_STATS_CLIENT_INC(_listener, _client, _x) _client->auth->_x++
94
95 #endif /* WITH_ACCOUNTING */
96
97
98 #else  /* WITH_STATS */
99 #define request_stats_init(_x)
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 #ifdef __cplusplus
109 }
110 #endif
111
112 #endif /* FR_STATS_H */