The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
stats.c
Go to the documentation of this file.
1/*
2 * stats.c Internal statistics handling.
3 *
4 * Version: $Id: 5cb9b36b70a66f0ce5c61c20bbbe9e86fd6666e1 $
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 *
20 * @copyright 2008 The FreeRADIUS server project
21 * @copyright 2008 Alan DeKok (aland@deployingradius.com)
22 */
23
24RCSID("$Id: 5cb9b36b70a66f0ce5c61c20bbbe9e86fd6666e1 $")
25
26#include <freeradius-devel/server/client.h>
27
28#include <freeradius-devel/util/misc.h>
29#include <freeradius-devel/radius/defs.h>
30
31
32#define EMA_SCALE (100)
33#define F_EMA_SCALE (1000000)
34
35#define FR_STATS_INIT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
36 { 0, 0, 0, 0, 0, 0, 0, 0 }}
37
40
42{
43 if (request->counted) return;
44
45#if 0
46 if (!request->listener) return;
47 if (!request->client) return;
48 if (!request->packet) return;
49#endif
50
51#if 0
52 if ((request->listener->type != RAD_LISTEN_NONE) &&
53 (request->listener->type != RAD_LISTEN_ACCT) &&
54 (request->listener->type != RAD_LISTEN_AUTH)) return;
55#endif
56 /* don't count statistic requests */
57 if (request->packet->code == FR_RADIUS_CODE_STATUS_SERVER)
58 return;
59
60#undef INC_AUTH
61#define INC_AUTH(_x) do { radius_auth_stats._x++;request->client->auth._x++; } while (0)
62
63#undef INC_ACCT
64#define INC_ACCT(_x) do { radius_acct_stats._x++;request->client->acct._x++; } while (0)
65
66 /*
67 * Update the statistics.
68 *
69 * Note that we do NOT do this in a child thread.
70 * Instead, we update the stats when a request is
71 * deleted, because only the main server thread calls
72 * this function, which makes it thread-safe.
73 */
74 if (request->reply && (request->packet->code != FR_RADIUS_CODE_STATUS_SERVER)) switch (request->reply->code) {
76 INC_AUTH(total_access_accepts);
77
78 auth_stats:
79 INC_AUTH(total_responses);
80
81 /*
82 * FIXME: Do the time calculations once...
83 */
85 request->packet->timestamp,
86 request->reply->timestamp);
87 fr_stats_bins(&request->client->auth,
88 request->packet->timestamp,
89 request->reply->timestamp);
90 break;
91
93 INC_AUTH(total_access_rejects);
94 goto auth_stats;
95
97 INC_AUTH(total_access_challenges);
98 goto auth_stats;
99
101 INC_ACCT(total_responses);
103 request->packet->timestamp,
104 request->reply->timestamp);
105 break;
106
107 /*
108 * No response, it must have been a bad
109 * authenticator.
110 */
111 case 0:
112 switch (request->packet->code) {
114 if (request->reply->id == -1) {
115 INC_AUTH(total_bad_authenticators);
116 } else {
117 INC_AUTH(total_packets_dropped);
118 }
119 break;
120
121
123 if (request->reply->id == -1) {
124 INC_ACCT(total_bad_authenticators);
125 } else {
126 INC_ACCT(total_packets_dropped);
127 }
128 break;
129
130 default:
131 break;
132 }
133 break;
134
135 default:
136 break;
137 }
138
139 request->counted = true;
140}
141
142/** Sort latency times into bins
143 *
144 * This solves the problem of attempting to keep min/max/avg latencies, whilst
145 * not knowing what the polling frequency will be.
146 *
147 * @param[out] stats Holding monotonically increasing stats bins.
148 * @param[in] start of the request.
149 * @param[in] end of the request.
150 */
152{
153 fr_time_delta_t diff;
154 uint32_t delay;
155
156 if (fr_time_lt(end, start)) return; /* bad data */
157 diff = fr_time_sub(end, start);
158
160 stats->elapsed[7]++;
161 } else {
162 int i;
163 uint32_t cmp;
164
165 delay = fr_time_delta_to_usec(diff);
166
167 cmp = 10;
168 for (i = 0; i < 7; i++) {
169 if (delay < cmp) {
170 stats->elapsed[i]++;
171 break;
172 }
173 cmp *= 10;
174 }
175 }
176}
#define RCSID(id)
Definition build.h:485
@ FR_RADIUS_CODE_ACCESS_CHALLENGE
RFC2865 - Access-Challenge.
Definition defs.h:43
@ FR_RADIUS_CODE_ACCESS_REQUEST
RFC2865 - Access-Request.
Definition defs.h:33
@ FR_RADIUS_CODE_STATUS_SERVER
RFC2865/RFC5997 - Status Server (request)
Definition defs.h:44
@ FR_RADIUS_CODE_ACCESS_ACCEPT
RFC2865 - Access-Accept.
Definition defs.h:34
@ FR_RADIUS_CODE_ACCOUNTING_RESPONSE
RFC2866 - Accounting-Response.
Definition defs.h:37
@ FR_RADIUS_CODE_ACCOUNTING_REQUEST
RFC2866 - Accounting-Request.
Definition defs.h:36
@ FR_RADIUS_CODE_ACCESS_REJECT
RFC2865 - Access-Reject.
Definition defs.h:35
unsigned int uint32_t
@ RAD_LISTEN_ACCT
Definition listen.h:48
@ RAD_LISTEN_AUTH
Definition listen.h:47
@ RAD_LISTEN_NONE
Definition listen.h:45
void fr_stats_bins(fr_stats_t *stats, fr_time_t start, fr_time_t end)
Sort latency times into bins.
Definition stats.c:151
void request_stats_final(request_t *request)
Definition stats.c:41
fr_stats_t radius_auth_stats
Definition stats.c:38
#define FR_STATS_INIT
Definition stats.c:35
fr_stats_t radius_acct_stats
Definition stats.c:39
#define INC_AUTH(_x)
#define INC_ACCT(_x)
uint64_t elapsed[8]
Definition stats.h:49
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
Definition time.h:590
static int64_t fr_time_delta_to_usec(fr_time_delta_t delta)
Definition time.h:632
#define fr_time_delta_gteq(_a, _b)
Definition time.h:284
#define fr_time_sub(_a, _b)
Subtract one time from another.
Definition time.h:229
#define fr_time_lt(_a, _b)
Definition time.h:239
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
"server local" time.
Definition time.h:69