1 From b4d12bdacf6ff4cc96abaffb8c3e801f94a84de2 Mon Sep 17 00:00:00 2001
2 From: Willy Tarreau <w@1wt.eu>
3 Date: Wed, 10 Oct 2012 10:26:22 +0200
4 Subject: MINOR: halog: sort output by cookie code
6 It's sometimes useful to have the output sorted by cookie code to see
7 the ratios of NI vs VN for example. This is now possible with -cc.
8 (cherry picked from commit 8a09b663a829f7012c50743adaf3d29cc81700c5)
10 contrib/halog/halog.c | 36 +++++++++++++++++++++++++++++++++---
11 1 files changed, 33 insertions(+), 3 deletions(-)
13 diff --git a/contrib/halog/halog.c b/contrib/halog/halog.c
14 index 274b7f3..e4d62e9 100644
15 --- a/contrib/halog/halog.c
16 +++ b/contrib/halog/halog.c
19 * haproxy log statistics reporter
21 - * Copyright 2000-2010 Willy Tarreau <w@1wt.eu>
22 + * Copyright 2000-2012 Willy Tarreau <w@1wt.eu>
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 @@ -113,6 +113,8 @@ struct url_stat {
27 FILT_COUNT_URL_TTOT|FILT_COUNT_URL_TAVG|FILT_COUNT_URL_TTOTO|FILT_COUNT_URL_TAVGO| \
28 FILT_COUNT_URL_BAVG|FILT_COUNT_URL_BTOT)
30 +#define FILT_COUNT_COOK_CODES 0x40000000
32 unsigned int filter = 0;
33 unsigned int filter_invert = 0;
35 @@ -124,6 +126,7 @@ const char *fgets2(FILE *stream);
37 void filter_count_url(const char *accept_field, const char *time_field, struct timer **tptr);
38 void filter_count_srv_status(const char *accept_field, const char *time_field, struct timer **tptr);
39 +void filter_count_cook_codes(const char *accept_field, const char *time_field, struct timer **tptr);
40 void filter_count_term_codes(const char *accept_field, const char *time_field, struct timer **tptr);
41 void filter_count_status(const char *accept_field, const char *time_field, struct timer **tptr);
42 void filter_graphs(const char *accept_field, const char *time_field, struct timer **tptr);
43 @@ -136,7 +139,7 @@ void usage(FILE *output, const char *msg)
45 "Usage: halog [-h|--help] for long help\n"
47 - " {-gt|-pct|-st|-tc|-srv|-u|-uc|-ue|-ua|-ut|-uao|-uto|-uba|-ubt}\n"
48 + " {-cc|-gt|-pct|-st|-tc|-srv|-u|-uc|-ue|-ua|-ut|-uao|-uto|-uba|-ubt}\n"
49 " [-s <skip>] [-e|-E] [-H] [-rt|-RT <time>] [-ad <delay>] [-ac <count>]\n"
50 " [-v] [-Q|-QS] [-tcn|-TCN <termcode>] [ -hs|-HS [min][:[max]] ] < log\n"
52 @@ -172,6 +175,7 @@ void help()
53 " -c only report the number of lines that would have been printed\n"
54 " -pct output connect and response times percentiles\n"
55 " -st output number of requests per HTTP status code\n"
56 + " -cc output number of requests per cookie code (2 chars)\n"
57 " -tc output number of requests per termination code (2 chars)\n"
58 " -srv output statistics per server (time, requests, errors)\n"
59 " -u* output statistics per URL (time, requests, errors)\n"
60 @@ -595,6 +599,8 @@ int main(int argc, char **argv)
61 filter |= FILT_COUNT_STATUS;
62 else if (strcmp(argv[0], "-srv") == 0)
63 filter |= FILT_COUNT_SRV_STATUS;
64 + else if (strcmp(argv[0], "-cc") == 0)
65 + filter |= FILT_COUNT_COOK_CODES;
66 else if (strcmp(argv[0], "-tc") == 0)
67 filter |= FILT_COUNT_TERM_CODES;
68 else if (strcmp(argv[0], "-tcn") == 0) {
69 @@ -676,6 +682,8 @@ int main(int argc, char **argv)
70 line_filter = filter_graphs;
71 else if (filter & FILT_COUNT_STATUS)
72 line_filter = filter_count_status;
73 + else if (filter & FILT_COUNT_COOK_CODES)
74 + line_filter = filter_count_cook_codes;
75 else if (filter & FILT_COUNT_TERM_CODES)
76 line_filter = filter_count_term_codes;
77 else if (filter & FILT_COUNT_SRV_STATUS)
78 @@ -1005,7 +1013,7 @@ int main(int argc, char **argv)
82 - else if (filter & FILT_COUNT_TERM_CODES) {
83 + else if (filter & (FILT_COUNT_TERM_CODES|FILT_COUNT_COOK_CODES)) {
84 /* output all statuses in the form of <code> <occurrences> */
85 n = eb32_first(&timers[0]);
87 @@ -1129,6 +1137,28 @@ void filter_count_status(const char *accept_field, const char *time_field, struc
91 +void filter_count_cook_codes(const char *accept_field, const char *time_field, struct timer **tptr)
98 + b = field_start(time_field, TERM_CODES_FIELD - TIME_FIELD + 1);
100 + b = field_start(accept_field, TERM_CODES_FIELD - ACCEPT_FIELD + 1);
102 + if (unlikely(!*b)) {
103 + truncated_line(linenum, line);
107 + val = 256 * b[2] + b[3];
109 + t2 = insert_value(&timers[0], tptr, val);
113 void filter_count_term_codes(const char *accept_field, const char *time_field, struct timer **tptr)