]> err.no Git - varnish/commitdiff
Update the backend->healty state based on the window/threshold
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 18 Aug 2008 09:10:11 +0000 (09:10 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 18 Aug 2008 09:10:11 +0000 (09:10 +0000)
paramters.

Log each polls result in the SHMlog

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3100 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_backend.h
varnish-cache/bin/varnishd/cache_backend_poll.c
varnish-cache/bin/varnishd/cache_backend_poll.h
varnish-cache/include/shmlog_tags.h

index 3bb00a062559e569285f2268a01fc69b6b7e864f..2abdf35376c6fbb457066b78190a8ea8519f1a21 100644 (file)
@@ -95,7 +95,7 @@ struct backend {
        VTAILQ_HEAD(, vbe_conn) connlist;
 
        struct vbp_target       *probe;
-       int                     health;
+       unsigned                healthy;
 };
 
 /* cache_backend.c */
index 3cfc08f12149b71596d1ba7f98c3fbf860b2c12b..0590699fa50ae2cb15ea08bc31c0df869b449aed 100644 (file)
@@ -62,6 +62,8 @@ struct vbp_target {
        struct vrt_backend_probe        probe;
        int                             stop;
        int                             req_len;
+
+       unsigned                        good;
        
        /* Collected statistics */
 #define BITMAP(n, c, t, b)     uint64_t        n;
@@ -203,6 +205,8 @@ vbp_poke(struct vbp_target *vt)
        TCP_close(&s);
        t_now = TIM_real();
        vt->good_recv |= 1;
+       /* XXX: Check reponse status */
+       vt->happy |= 1;
        return (1);
 }
 
@@ -214,18 +218,29 @@ static void *
 vbp_wrk_poll_backend(void *priv)
 {
        struct vbp_target *vt;
+       unsigned i, j;
+       uint64_t u;
+       const char *logmsg;
+       char bits[10];
 
        THR_SetName("backend poll");
 
        CAST_OBJ_NOTNULL(vt, priv, VBP_TARGET_MAGIC);
 
-       /* Establish defaults (XXX: Should they go in VCC instead ?) */
+       /*
+        * Establish defaults
+        * XXX: we could make these defaults parameters
+        */
        if (vt->probe.request == NULL)
                vt->probe.request = default_request;
        if (vt->probe.timeout == 0.0)
                vt->probe.timeout = 2.0;
        if (vt->probe.interval == 0.0)
                vt->probe.timeout = 5.0;
+       if (vt->probe.window == 0)
+               vt->probe.window = 8;
+       if (vt->probe.threshold == 0)
+               vt->probe.threshold = 3;
 
        printf("Probe(\"%s\", %g, %g)\n",
            vt->probe.request,
@@ -240,6 +255,38 @@ vbp_wrk_poll_backend(void *priv)
 #include "cache_backend_poll.h"
 #undef BITMAP
                vbp_poke(vt);
+
+               i = 0;
+#define BITMAP(n, c, t, b)     bits[i++] = (vt->n & 1) ? c : '-';
+#include "cache_backend_poll.h"
+#undef BITMAP
+               bits[i] = '\0';
+
+               u = vt->happy;
+               for (i = j = 0; i < vt->probe.window; i++) {
+                       if (u & 1)
+                               j++;
+                       u >>= 1;
+               }
+               vt->good = j;
+
+               if (vt->good >= vt->probe.threshold) {
+                       if (vt->backend->healthy)
+                               logmsg = "Still healthy";
+                       else
+                               logmsg = "Back healthy";
+                       vt->backend->healthy = 1;
+               } else {
+                       if (vt->backend->healthy)
+                               logmsg = "Went sick";
+                       else
+                               logmsg = "Still sick";
+                       vt->backend->healthy = 0;
+               }
+               VSL(SLT_Backend_health, 0, "%s %s %s %u %u %u",
+                   vt->backend->vcl_name, logmsg, bits,
+                   vt->good, vt->probe.threshold, vt->probe.window);
+                       
                if (!vt->stop)
                        dsleep(vt->probe.interval);
        }
@@ -251,14 +298,14 @@ vbp_wrk_poll_backend(void *priv)
  */
 
 static void
-vbp_bitmap(struct cli *cli, const char *s, uint64_t map, const char *lbl)
+vbp_bitmap(struct cli *cli, char c, uint64_t map, const char *lbl)
 {
        int i;
        uint64_t u = (1ULL << 63);
 
        for (i = 0; i < 64; i++) {
                if (map & u)
-                       cli_out(cli, s);
+                       cli_out(cli, "%c", c);
                else
                        cli_out(cli, "-");
                map <<= 1;
@@ -272,11 +319,17 @@ static void
 vbp_health_one(struct cli *cli, const struct vbp_target *vt)
 {
 
-       cli_out(cli, "Health stats for backend %s\n",
-           vt->backend->vcl_name);
+       cli_out(cli, "Backend %s is %s\n",
+           vt->backend->vcl_name,
+           vt->backend->healthy ? "Healthy" : "Sick");
+       cli_out(cli, "Current states  good: %2u threshold: %2u window: %2u\n",
+           vt->good, vt->probe.threshold, vt->probe.window);
+       cli_out(cli, 
+           "Oldest                       "
+           "                             Newest\n");
        cli_out(cli, 
-           "Oldest ______________________"
-           "____________________________ Newest\n");
+           "============================="
+           "===================================\n");
 
 #define BITMAP(n, c, t, b)                                     \
                if ((vt->n != 0) || (b))                                \
index e183689a7f26c66e142fa283a7355f6e0db42c5f..0f52be3612733c8f385ca4f121f56371320dc92c 100644 (file)
  *
  */
 
-BITMAP(good_ipv4, "4", "Good IPv4", 0)
-BITMAP(good_ipv6, "6", "Good IPv4", 0)
-BITMAP( err_xmit, "x", "Error Xmit", 0)
-BITMAP(good_xmit, "X", "Good Xmit", 0)
-BITMAP( err_shut, "s", "Error Shut", 0)
-BITMAP(good_shut, "S", "Good Shut", 0)
-BITMAP( err_recv, "r", "Error Recv", 0)
-BITMAP(good_recv, "R", "Good Recv", 1)
+BITMAP(good_ipv4, '4', "Good IPv4", 0)
+BITMAP(good_ipv6, '6', "Good IPv4", 0)
+BITMAP( err_xmit, 'x', "Error Xmit", 0)
+BITMAP(good_xmit, 'X', "Good Xmit", 0)
+BITMAP( err_shut, 's', "Error Shut", 0)
+BITMAP(good_shut, 'S', "Good Shut", 0)
+BITMAP( err_recv, 'r', "Error Recv", 0)
+BITMAP(good_recv, 'R', "Good Recv", 0)
+BITMAP(happy,     'H', "Happy", 1)
index 55022b81e6cd46ceb1a694466928a031d771ab88..c589806585f768f3e8e1674367e15d7571e9cba9 100644 (file)
@@ -99,3 +99,5 @@ SLTM(ESItrace)
 SLTM(ESI_xmlerror)
 
 SLTM(Hash)
+
+SLTM(Backend_health)