[MINOR] halog: add support for statisticts on status codes

Using "-st", halog outputs number of requests by status codes.
This commit is contained in:
Willy Tarreau 2010-05-03 10:50:54 +02:00
parent c3bfeebdb4
commit 0f423a7073

View File

@ -63,6 +63,8 @@ struct timer {
#define FILT_INVERT_ERRORS 0x200 #define FILT_INVERT_ERRORS 0x200
#define FILT_INVERT_TIME_RESP 0x400 #define FILT_INVERT_TIME_RESP 0x400
#define FILT_COUNT_STATUS 0x800
unsigned int filter = 0; unsigned int filter = 0;
unsigned int filter_invert = 0; unsigned int filter_invert = 0;
const char *line; const char *line;
@ -73,7 +75,7 @@ void die(const char *msg)
{ {
fprintf(stderr, fprintf(stderr,
"%s" "%s"
"Usage: halog [-c] [-v] [-gt] [-pct] [-s <skip>] [-e|-E] [-rt|-RT <time>] [-ad <delay>] [-ac <count>] < file.log\n" "Usage: halog [-c] [-v] [-gt] [-pct] [-st] [-s <skip>] [-e|-E] [-rt|-RT <time>] [-ad <delay>] [-ac <count>] < file.log\n"
"\n", "\n",
msg ? msg : "" msg ? msg : ""
); );
@ -408,6 +410,8 @@ int main(int argc, char **argv)
filter |= FILT_GRAPH_TIMERS; filter |= FILT_GRAPH_TIMERS;
else if (strcmp(argv[0], "-pct") == 0) else if (strcmp(argv[0], "-pct") == 0)
filter |= FILT_PERCENTILE; filter |= FILT_PERCENTILE;
else if (strcmp(argv[0], "-st") == 0)
filter |= FILT_COUNT_STATUS;
else if (strcmp(argv[0], "-o") == 0) { else if (strcmp(argv[0], "-o") == 0) {
if (output_file) if (output_file)
die("Fatal: output file name already specified.\n"); die("Fatal: output file name already specified.\n");
@ -484,6 +488,10 @@ int main(int argc, char **argv)
} }
} }
test ^= filter_invert;
if (!test)
continue;
if (filter & (FILT_ACC_COUNT|FILT_ACC_DELAY)) { if (filter & (FILT_ACC_COUNT|FILT_ACC_DELAY)) {
b = field_start(line, ACCEPT_FIELD + skip_fields); b = field_start(line, ACCEPT_FIELD + skip_fields);
if (!*b) { if (!*b) {
@ -585,9 +593,18 @@ int main(int argc, char **argv)
continue; continue;
} }
test ^= filter_invert; if (filter & FILT_COUNT_STATUS) {
if (!test) b = field_start(line, STATUS_FIELD + skip_fields);
if (!*b) {
truncated_line(linenum, line);
continue;
}
val = str2ic(b);
t2 = insert_value(&timers[0], &t, val);
t2->count++;
continue; continue;
}
/* all other cases mean we just want to count lines */ /* all other cases mean we just want to count lines */
tot++; tot++;
@ -603,9 +620,6 @@ int main(int argc, char **argv)
exit(0); exit(0);
} }
if (filter & FILT_ERRORS_ONLY)
exit(0);
if (filter & (FILT_ACC_COUNT|FILT_ACC_DELAY)) { if (filter & (FILT_ACC_COUNT|FILT_ACC_DELAY)) {
/* sort and count all timers. Output will look like this : /* sort and count all timers. Output will look like this :
* <accept_date> <delta_ms from previous one> <nb entries> * <accept_date> <delta_ms from previous one> <nb entries>
@ -709,6 +723,15 @@ int main(int argc, char **argv)
step += 1; step += 1;
} }
} }
else if (filter & FILT_COUNT_STATUS) {
/* output all statuses in the form of <status> <occurrences> */
n = eb32_first(&timers[0]);
while (n) {
t = container_of(n, struct timer, node);
printf("%d %d\n", n->key, t->count);
n = eb32_next(n);
}
}
empty: empty:
if (!(filter & FILT_QUIET)) if (!(filter & FILT_QUIET))
fprintf(stderr, "%d lines in, %d lines out, %d parsing errors\n", fprintf(stderr, "%d lines in, %d lines out, %d parsing errors\n",