]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cache: report the number of cache lookups and cache hits
authorWilly Tarreau <w@1wt.eu>
Fri, 14 Dec 2018 13:00:25 +0000 (14:00 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 14 Dec 2018 13:00:25 +0000 (14:00 +0100)
The cache lookups and hits is now accounted per frontend and per backend,
and reported on the stats page.

include/types/counters.h
include/types/stats.h
src/cache.c
src/stats.c

index 79dd6d437607353a119db710eae7e57ee299ee34..1898548741382961b2b307a99da9cbea26197148 100644 (file)
@@ -56,6 +56,8 @@ struct fe_counters {
                        long long comp_rsp;     /* number of compressed responses */
                        unsigned int rps_max;   /* maximum of new HTTP requests second observed */
                        long long rsp[6];       /* http response codes */
+                       long long cache_lookups;/* cache lookups */
+                       long long cache_hits;   /* cache hits */
                } http;
        } p;                                    /* protocol-specific stats */
 };
@@ -105,6 +107,8 @@ struct be_counters {
                        long long comp_rsp;     /* number of compressed responses */
                        unsigned int rps_max;   /* maximum of new HTTP requests second observed */
                        long long rsp[6];       /* http response codes */
+                       long long cache_lookups;/* cache lookups */
+                       long long cache_hits;   /* cache hits */
                } http;
        } p;                                    /* protocol-specific stats */
 };
index c3b9fc8fc7a0606dc9ea502a65728b7726b32a20..ec29c786b0f790b09f71cf6d267377f751641155 100644 (file)
@@ -394,6 +394,8 @@ enum stat_field {
        ST_F_WREW,
        ST_F_CONNECT,
        ST_F_REUSE,
+       ST_F_CACHE_LOOKUPS,
+       ST_F_CACHE_HITS,
 
        /* must always be the last one */
        ST_F_TOTAL_FIELDS
index 74743f2b51c9c3ccb68fda3223cdba3a8906a391..199b8656352ee0ab6dba1fc4157b5c6202a4032e 100644 (file)
@@ -1389,6 +1389,11 @@ enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy *p
        if (s->txn->flags & TX_CACHE_IGNORE)
                return ACT_RET_CONT;
 
+       if (px == strm_fe(s))
+               HA_ATOMIC_ADD(&px->fe_counters.p.http.cache_lookups, 1);
+       else
+               HA_ATOMIC_ADD(&px->be_counters.p.http.cache_lookups, 1);
+
        shctx_lock(shctx_ptr(cache));
        res = entry_exist(cache, s->txn->cache_hash);
        if (res) {
@@ -1402,6 +1407,11 @@ enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy *p
                        appctx->ctx.cache.entry = res;
                        appctx->ctx.cache.next = NULL;
                        appctx->ctx.cache.sent = 0;
+
+                       if (px == strm_fe(s))
+                               HA_ATOMIC_ADD(&px->fe_counters.p.http.cache_hits, 1);
+                       else
+                               HA_ATOMIC_ADD(&px->be_counters.p.http.cache_hits, 1);
                        return ACT_RET_CONT;
                } else {
                        shctx_lock(shctx_ptr(cache));
index 823502ff36f502a02c096e69c4bdd83c0a8ac69c..3ee168912584a8ecaa8e80fd81c4e3be2cee99db 100644 (file)
@@ -230,6 +230,8 @@ const char *stat_field_names[ST_F_TOTAL_FIELDS] = {
        [ST_F_WREW]           = "wrew",
        [ST_F_CONNECT]        = "connect",
        [ST_F_REUSE]          = "reuse",
+       [ST_F_CACHE_LOOKUPS]  = "cache_lookups",
+       [ST_F_CACHE_HITS]     = "cache_hits",
 };
 
 /* one line of info */
@@ -724,6 +726,8 @@ static int stats_dump_fields_html(struct buffer *out,
                                      "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>"
                                      "<tr><th>- other responses:</th><td>%s</td></tr>"
                                      "<tr><th>Intercepted requests:</th><td>%s</td></tr>"
+                                     "<tr><th>Cache lookups:</th><td>%s</td></tr>"
+                                     "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>"
                                      "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>"
                                      "",
                                      U2H(stats[ST_F_REQ_TOT].u.u64),
@@ -737,6 +741,10 @@ static int stats_dump_fields_html(struct buffer *out,
                                      U2H(stats[ST_F_HRSP_5XX].u.u64),
                                      U2H(stats[ST_F_HRSP_OTHER].u.u64),
                                      U2H(stats[ST_F_INTERCEPTED].u.u64),
+                                     U2H(stats[ST_F_CACHE_LOOKUPS].u.u64),
+                                     U2H(stats[ST_F_CACHE_HITS].u.u64),
+                                     stats[ST_F_CACHE_LOOKUPS].u.u64 ?
+                                     (int)(100 * stats[ST_F_CACHE_HITS].u.u64 / stats[ST_F_CACHE_LOOKUPS].u.u64) : 0,
                                      U2H(stats[ST_F_WREW].u.u64));
                }
 
@@ -1198,6 +1206,8 @@ static int stats_dump_fields_html(struct buffer *out,
                                      "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>"
                                      "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>"
                                      "<tr><th>- other responses:</th><td>%s</td></tr>"
+                                     "<tr><th>Cache lookups:</th><td>%s</td></tr>"
+                                     "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>"
                                      "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>"
                                      "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"
                                      "",
@@ -1215,6 +1225,10 @@ static int stats_dump_fields_html(struct buffer *out,
                                      U2H(stats[ST_F_HRSP_4XX].u.u64),
                                      U2H(stats[ST_F_HRSP_5XX].u.u64),
                                      U2H(stats[ST_F_HRSP_OTHER].u.u64),
+                                     U2H(stats[ST_F_CACHE_LOOKUPS].u.u64),
+                                     U2H(stats[ST_F_CACHE_HITS].u.u64),
+                                     stats[ST_F_CACHE_LOOKUPS].u.u64 ?
+                                     (int)(100 * stats[ST_F_CACHE_HITS].u.u64 / stats[ST_F_CACHE_LOOKUPS].u.u64) : 0,
                                      U2H(stats[ST_F_WREW].u.u64));
                }
 
@@ -1363,6 +1377,8 @@ int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len)
                stats[ST_F_HRSP_5XX]    = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]);
                stats[ST_F_HRSP_OTHER]  = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]);
                stats[ST_F_INTERCEPTED] = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req);
+               stats[ST_F_CACHE_LOOKUPS] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups);
+               stats[ST_F_CACHE_HITS]    = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits);
        }
 
        /* requests : req_rate, req_rate_max, req_tot, */
@@ -1839,6 +1855,8 @@ int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int le
                stats[ST_F_HRSP_4XX]    = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]);
                stats[ST_F_HRSP_5XX]    = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]);
                stats[ST_F_HRSP_OTHER]  = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]);
+               stats[ST_F_CACHE_LOOKUPS] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups);
+               stats[ST_F_CACHE_HITS]    = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits);
        }
 
        stats[ST_F_CLI_ABRT]     = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts);