From: Alan T. DeKok Date: Thu, 21 Jan 2010 10:37:21 +0000 (+0100) Subject: Add statistics for detail listeners, too X-Git-Tag: release_2_1_9~97 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3619e70d4d852fa2796663f89961dacd3ec6c1b;p=thirdparty%2Ffreeradius-server.git Add statistics for detail listeners, too --- diff --git a/src/include/detail.h b/src/include/detail.h index 4c164d7194e..92d9f3e51b7 100644 --- a/src/include/detail.h +++ b/src/include/detail.h @@ -28,6 +28,7 @@ typedef struct listen_detail_t { char *filename_work; VALUE_PAIR *vps; FILE *fp; + off_t offset; detail_state_t state; time_t timestamp; time_t running; @@ -36,6 +37,8 @@ typedef struct listen_detail_t { int signal; int poll_interval; int retry_interval; + int packets; + int tries; int has_rtt; int srtt; diff --git a/src/main/command.c b/src/main/command.c index 146cfb3aa30..a7a86c67324 100644 --- a/src/main/command.c +++ b/src/main/command.c @@ -1499,6 +1499,69 @@ static int command_print_stats(rad_listen_t *listener, fr_stats_t *stats, } +#ifdef WITH_DETAIL +static FR_NAME_NUMBER state_names[] = { + { "unopened", STATE_UNOPENED }, + { "unlocked", STATE_UNLOCKED }, + { "header", STATE_HEADER }, + { "reading", STATE_READING }, + { "queued", STATE_QUEUED }, + { "running", STATE_RUNNING }, + { "no-reply", STATE_NO_REPLY }, + { "replied", STATE_REPLIED }, + + { NULL, 0 } +}; + +static int command_stats_detail(rad_listen_t *listener, int argc, char *argv[]) +{ + rad_listen_t *this; + listen_detail_t *data; + struct stat buf; + + if (argc == 0) { + cprintf(listener, "ERROR: Must specify \n"); + return 0; + } + + data = NULL; + for (this = mainconfig.listen; this != NULL; this = this->next) { + if (this->type != RAD_LISTEN_DETAIL) continue; + + data = this->data; + if (strcmp(argv[1], data->filename) != 0) continue; + + break; + } + + cprintf(listener, "\tstate\t%s\n", + fr_int2str(state_names, data->state, "?")); + + if ((data->state == STATE_UNOPENED) || + (data->state == STATE_UNLOCKED)) { + return 1; + } + + /* + * Race conditions: file might not exist. + */ + if (stat(data->filename_work, &buf) < 0) { + cprintf(listener, "packets\t0\n"); + cprintf(listener, "tries\t0\n"); + cprintf(listener, "offset\t0\n"); + cprintf(listener, "size\t0\n"); + return 1; + } + + cprintf(listener, "packets\t%d\n", data->packets); + cprintf(listener, "tries\t%d\n", data->tries); + cprintf(listener, "offset\t%u\n", (unsigned int) data->offset); + cprintf(listener, "size\t%u\n", (unsigned int) buf.st_size); + + return 1; +} +#endif + #ifdef WITH_PROXY static int command_stats_home_server(rad_listen_t *listener, int argc, char *argv[]) { @@ -1684,6 +1747,12 @@ static fr_command_table_t command_table_stats[] = { command_stats_home_server, NULL }, #endif +#ifdef WITH_DETAIL + { "detail", FR_READ, + "stats detail - show statistics for the given detail file", + command_stats_detail, NULL }, +#endif + { NULL, 0, NULL, NULL, NULL } }; diff --git a/src/main/detail.c b/src/main/detail.c index 75d7f7bced8..91f9503d14d 100644 --- a/src/main/detail.c +++ b/src/main/detail.c @@ -272,6 +272,9 @@ static int detail_open(rad_listen_t *this) data->client_ip.af = AF_UNSPEC; data->timestamp = 0; + data->offset = 0; + data->packets = 0; + data->tries = 0; return 1; } @@ -457,6 +460,8 @@ int detail_recv(rad_listen_t *listener, * Read a header, OR a value-pair. */ while (fgets(buffer, sizeof(buffer), data->fp)) { + data->offset = ftell(data->fp); /* for statistics */ + /* * Badly formatted file: delete it. * @@ -566,10 +571,15 @@ int detail_recv(rad_listen_t *listener, */ if (ferror(data->fp)) goto cleanup; + data->tries = 0; + data->packets++; + /* * Process the packet. */ alloc_packet: + data->tries++; + rad_assert(data->state == STATE_QUEUED); /*