Add start && hup time
authoraland <aland>
Sat, 21 Jun 2008 16:14:07 +0000 (16:14 +0000)
committeraland <aland>
Sat, 21 Jun 2008 16:14:07 +0000 (16:14 +0000)
share/dictionary.freeradius
src/include/stats.h
src/main/radiusd.c
src/main/stats.c

index e858bde..add7072 100644 (file)
@@ -15,27 +15,9 @@ BEGIN-VENDOR FreeRADIUS
 
 ATTRIBUTE      FreeRADIUS-Proxied-To                   1       ipaddr
 
+
 #
-#      If you send a Status-Server packet from localhost to localhost
-#      containing a FreeRADIUS-Statistics-Type attribute, the
-#      response will contain relevant statistics.
-#
-#      The FreeRADIUS-Statistics-Type attribute is ignored for ALL
-#      other packet types, and for ALL other IP addresses.  This will
-#      not be changed.
-#
-#      Statistics can be queried by a number of methods:
-#
-#      Globally - all sockets auth/acct/proxy-auth/proxy-acct
-#      By server IP/port - return auth or acct statistics for that port
-#      By home server IP/port - return proxied auth and acct statistics
-#      By client - send IP, return auth & acct statistics
-#      By client for a server IP/port - return auth & acct statistics
-#
-#      Just send FreeRADIUS-Statistics-Type, and client IP, and/or
-#      server IP/port, using the attributes defined below.
-#
-#  This is really a bitmask.
+#  This attribute is really a bitmask.
 #
 ATTRIBUTE      FreeRADIUS-Statistics-Type              127     integer
 
@@ -44,7 +26,7 @@ VALUE FreeRADIUS-Statistics-Type      Authentication          1
 VALUE  FreeRADIUS-Statistics-Type      Accounting              2
 VALUE  FreeRADIUS-Statistics-Type      Proxy-Authentication    4
 VALUE  FreeRADIUS-Statistics-Type      Proxy-Accounting        8
-VALUE  FreeRADIUS-Statistics-Type      Request-Queue           0x10
+VALUE  FreeRADIUS-Statistics-Type      Internal                0x10
 VALUE  FreeRADIUS-Statistics-Type      Client                  0x20
 VALUE  FreeRADIUS-Statistics-Type      Server                  0x40
 VALUE  FreeRADIUS-Statistics-Type      Home-Server             0x80
@@ -127,8 +109,17 @@ VALUE      FreeRADIUS-Stats-Server-State   Alive   0
 VALUE  FreeRADIUS-Stats-Server-State   Zombie  1
 VALUE  FreeRADIUS-Stats-Server-State   Dead    2
 
+#
+#  When a home server is marked "dead" or "alive"
+#
 ATTRIBUTE      FreeRADIUS-Stats-Server-Time-Of-Death   174     date
 ATTRIBUTE      FreeRADIUS-Stats-Server-Time-Of-Life    175     date
 
+#
+#  When this server was started.  If start == hup, it hasn't been
+#  hup'd yet.  This is friendlier than having hup == 0 on start.
+#
+ATTRIBUTE      FreeRADIUS-Stats-Start-Time             176     date
+ATTRIBUTE      FreeRADIUS-Stats-HUP-Time               177     date
 
 END-VENDOR FreeRADIUS
index e96c81d..b3613f4 100644 (file)
@@ -51,6 +51,7 @@ typedef struct fr_stats_t {
 extern fr_stats_t      radius_auth_stats;
 extern fr_stats_t      radius_acct_stats;
 
+void radius_stats_init(int flag);
 void request_stats_final(REQUEST *request);
 void request_stats_reply(REQUEST *request);
 
@@ -77,6 +78,7 @@ void request_stats_reply(REQUEST *request);
 
 
 #else  /* WITH_STATS */
+#define request_stats_init(_x)
 #define request_stats_final(_x)
 
 #define  RAD_STATS_INC(_x)
index 429bb42..49dfef0 100644 (file)
@@ -29,7 +29,6 @@
 RCSID("$Id$")
 
 #include <freeradius-devel/radiusd.h>
-#include <freeradius-devel/radius_snmp.h>
 #include <freeradius-devel/modules.h>
 #include <freeradius-devel/rad_assert.h>
 
@@ -68,7 +67,6 @@ int check_config = FALSE;
 
 const char *radiusd_version = "FreeRADIUS Version " RADIUSD_VERSION ", for host " HOSTINFO ", built on " __DATE__ " at " __TIME__;
 
-time_t time_now;
 pid_t radius_pid;
 
 static int debug_memory = 0;
@@ -388,10 +386,13 @@ int main(int argc, char *argv[])
                exit(0);
        }
 
+       radius_stats_init(0);
+
        /*
         *      Process requests until HUP or exit.
         */
        while ((rcode = radius_event_process()) == 0x80) {
+               radius_stats_init(1);
                radlog(L_INFO, "Received HUP.");
                module_hup(cf_section_sub_find(mainconfig.config, "modules"));
        }
index f39b9c7..ddd89aa 100644 (file)
@@ -29,6 +29,9 @@ RCSID("$Id$")
 
 #ifdef WITH_STATS
 
+static struct timeval  start_time;
+static struct timeval  hup_time;
+
 fr_stats_t radius_auth_stats = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 #ifdef WITH_ACCOUNTING
 fr_stats_t radius_acct_stats = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
@@ -346,8 +349,15 @@ void request_stats_reply(REQUEST *request)
 #endif
 #endif
 
-#ifdef HAVE_PTHREAD_H
        if ((flag->vp_integer & 0x10) != 0) {
+               vp = radius_paircreate(request, &request->reply->vps,
+                                      FR2ATTR(176), PW_TYPE_DATE);
+               if (vp) vp->vp_date = start_time.tv_sec;
+               vp = radius_paircreate(request, &request->reply->vps,
+                                      FR2ATTR(177), PW_TYPE_DATE);
+               if (vp) vp->vp_date = hup_time.tv_sec;
+               
+#ifdef HAVE_PTHREAD_H
                int i, array[RAD_LISTEN_MAX];
 
                thread_pool_queue_stats(array);
@@ -360,8 +370,8 @@ void request_stats_reply(REQUEST *request)
                        if (!vp) continue;
                        vp->vp_integer = array[i];
                }
-       }
 #endif
+       }
 
        if ((flag->vp_integer & 0x20) != 0) {
                fr_ipaddr_t ipaddr;
@@ -579,4 +589,14 @@ void request_stats_reply(REQUEST *request)
        }
 }
 
+void radius_stats_init(int flag)
+{
+       if (!flag) {
+               gettimeofday(&start_time, NULL);
+               hup_time = start_time; /* it's just nicer this way */
+       } else {
+               gettimeofday(&hup_time, NULL);
+       }
+}
+
 #endif /* WITH_STATS */