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: f74cbdd3f3fa786b6c0de96479d8b4df912dadb4 $
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: f74cbdd3f3fa786b6c0de96479d8b4df912dadb4 $")
25
26#include <freeradius-devel/server/client.h>
27#include <freeradius-devel/server/request.h>
28#include <freeradius-devel/server/stats.h>
29#include <freeradius-devel/util/debug.h>
30
31#include <freeradius-devel/util/misc.h>
32#include <freeradius-devel/util/time.h>
33#include <freeradius-devel/radius/defs.h>
34
35
36#define EMA_SCALE (100)
37#define F_EMA_SCALE (1000000)
38
39#define FR_STATS_INIT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
40 { 0, 0, 0, 0, 0, 0, 0, 0 }}
41
44
46{
47 if (request->counted) return;
48
49#if 0
50 if (!request->listener) return;
51 if (!request->client) return;
52 if (!request->packet) return;
53#endif
54
55#if 0
56 if ((request->listener->type != RAD_LISTEN_NONE) &&
57 (request->listener->type != RAD_LISTEN_ACCT) &&
58 (request->listener->type != RAD_LISTEN_AUTH)) return;
59#endif
60 /* don't count statistic requests */
61 if (request->packet->code == FR_RADIUS_CODE_STATUS_SERVER)
62 return;
63
64#undef INC_AUTH
65#define INC_AUTH(_x) do { radius_auth_stats._x++;request->client->auth._x++; } while (0)
66
67#undef INC_ACCT
68#define INC_ACCT(_x) do { radius_acct_stats._x++;request->client->acct._x++; } while (0)
69
70 /*
71 * Update the statistics.
72 *
73 * Note that we do NOT do this in a child thread.
74 * Instead, we update the stats when a request is
75 * deleted, because only the main server thread calls
76 * this function, which makes it thread-safe.
77 */
78 if (request->reply && (request->packet->code != FR_RADIUS_CODE_STATUS_SERVER)) switch (request->reply->code) {
80 INC_AUTH(total_access_accepts);
81
82 auth_stats:
83 INC_AUTH(total_responses);
84
85 /*
86 * FIXME: Do the time calculations once...
87 */
89 request->packet->timestamp,
90 request->reply->timestamp);
91 fr_stats_bins(&request->client->auth,
92 request->packet->timestamp,
93 request->reply->timestamp);
94 break;
95
97 INC_AUTH(total_access_rejects);
98 goto auth_stats;
99
101 INC_AUTH(total_access_challenges);
102 goto auth_stats;
103
105 INC_ACCT(total_responses);
107 request->packet->timestamp,
108 request->reply->timestamp);
109 break;
110
111 /*
112 * No response, it must have been a bad
113 * authenticator.
114 */
115 case 0:
116 switch (request->packet->code) {
118 if (request->reply->id == -1) {
119 INC_AUTH(total_bad_authenticators);
120 } else {
121 INC_AUTH(total_packets_dropped);
122 }
123 break;
124
125
127 if (request->reply->id == -1) {
128 INC_ACCT(total_bad_authenticators);
129 } else {
130 INC_ACCT(total_packets_dropped);
131 }
132 break;
133
134 default:
135 break;
136 }
137 break;
138
139 default:
140 break;
141 }
142
143 request->counted = true;
144}
145
146/** Sort latency times into bins
147 *
148 * This solves the problem of attempting to keep min/max/avg latencies, whilst
149 * not knowing what the polling frequency will be.
150 *
151 * @param[out] stats Holding monotonically increasing stats bins.
152 * @param[in] start of the request.
153 * @param[in] end of the request.
154 */
156{
157 fr_time_delta_t diff;
158 uint32_t delay;
159
160 if (fr_time_lt(end, start)) return; /* bad data */
161 diff = fr_time_sub(end, start);
162
164 stats->elapsed[7]++;
165 } else {
166 int i;
167 uint32_t cmp;
168
169 delay = fr_time_delta_to_usec(diff);
170
171 cmp = 10;
172 for (i = 0; i < 7; i++) {
173 if (delay < cmp) {
174 stats->elapsed[i]++;
175 break;
176 }
177 cmp *= 10;
178 }
179 }
180}
#define RCSID(id)
Definition build.h:483
@ 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:155
void request_stats_final(request_t *request)
Definition stats.c:45
fr_stats_t radius_auth_stats
Definition stats.c:42
#define FR_STATS_INIT
Definition stats.c:39
fr_stats_t radius_acct_stats
Definition stats.c:43
#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