mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-04 04:22:47 +00:00
[MINOR] halog: add support for statisticts on status codes
Using "-st", halog outputs number of requests by status codes.
This commit is contained in:
parent
c3bfeebdb4
commit
0f423a7073
@ -63,6 +63,8 @@ struct timer {
|
||||
#define FILT_INVERT_ERRORS 0x200
|
||||
#define FILT_INVERT_TIME_RESP 0x400
|
||||
|
||||
#define FILT_COUNT_STATUS 0x800
|
||||
|
||||
unsigned int filter = 0;
|
||||
unsigned int filter_invert = 0;
|
||||
const char *line;
|
||||
@ -73,7 +75,7 @@ void die(const char *msg)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%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",
|
||||
msg ? msg : ""
|
||||
);
|
||||
@ -408,6 +410,8 @@ int main(int argc, char **argv)
|
||||
filter |= FILT_GRAPH_TIMERS;
|
||||
else if (strcmp(argv[0], "-pct") == 0)
|
||||
filter |= FILT_PERCENTILE;
|
||||
else if (strcmp(argv[0], "-st") == 0)
|
||||
filter |= FILT_COUNT_STATUS;
|
||||
else if (strcmp(argv[0], "-o") == 0) {
|
||||
if (output_file)
|
||||
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)) {
|
||||
b = field_start(line, ACCEPT_FIELD + skip_fields);
|
||||
if (!*b) {
|
||||
@ -585,9 +593,18 @@ int main(int argc, char **argv)
|
||||
continue;
|
||||
}
|
||||
|
||||
test ^= filter_invert;
|
||||
if (!test)
|
||||
if (filter & FILT_COUNT_STATUS) {
|
||||
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;
|
||||
}
|
||||
|
||||
/* all other cases mean we just want to count lines */
|
||||
tot++;
|
||||
@ -603,9 +620,6 @@ int main(int argc, char **argv)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (filter & FILT_ERRORS_ONLY)
|
||||
exit(0);
|
||||
|
||||
if (filter & (FILT_ACC_COUNT|FILT_ACC_DELAY)) {
|
||||
/* sort and count all timers. Output will look like this :
|
||||
* <accept_date> <delta_ms from previous one> <nb entries>
|
||||
@ -709,6 +723,15 @@ int main(int argc, char **argv)
|
||||
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:
|
||||
if (!(filter & FILT_QUIET))
|
||||
fprintf(stderr, "%d lines in, %d lines out, %d parsing errors\n",
|
||||
|
Loading…
Reference in New Issue
Block a user