Commit 4e69924f authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Introduce the first per-backend stats counter: number of VCLs referencing

this set of counters.

Backend stats counters are indexed purely by the backend name,
across all VCLs:  If you redefine or have conflicting definitions
of a backend with a given name, in different VCLs loaded at the
same time, they will share stats counters.

Not optimal, but I think the alternative would be worse.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4966 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent e11ab7f4
......@@ -455,6 +455,73 @@ VBE_Healthy(double now, const struct director *d, uintptr_t target)
return (d->healthy(now, d, target));
}
/*--------------------------------------------------------------------
* Backend VSC counters
*
* We use a private list, because we do not trust the content of the
* VSM (to hold our refcount).
*
* Backend stats are indexed purely by name, across all VCLs.
*/
struct vbe_cnt {
unsigned magic;
#define CNT_PRIV_MAGIC 0x1acda1f5
VTAILQ_ENTRY(vbe_cnt) list;
char *name;
int refcnt;
struct vsc_vbe *vsc_vbe;
};
static VTAILQ_HEAD(, vbe_cnt) vbe_cnt_head =
VTAILQ_HEAD_INITIALIZER(vbe_cnt_head);
static struct vsc_vbe *
vbe_stat_ref(const char *name)
{
struct vbe_cnt *vc;
ASSERT_CLI();
VTAILQ_FOREACH(vc, &vbe_cnt_head, list) {
if (!strcmp(vc->name, name)) {
vc->refcnt++;
vc->vsc_vbe->vcls = vc->refcnt;
return (vc->vsc_vbe);
}
}
ALLOC_OBJ(vc, CNT_PRIV_MAGIC);
AN(vc);
REPLACE(vc->name, name);
VTAILQ_INSERT_HEAD(&vbe_cnt_head, vc, list);
vc->vsc_vbe = VSM_Alloc(sizeof *vc->vsc_vbe,
VSC_CLASS, VSC_TYPE_VBE, name);
AN(vc->vsc_vbe);
vc->refcnt = 1;
vc->vsc_vbe->vcls = vc->refcnt;
return (vc->vsc_vbe);
}
static void
vbe_stat_deref(const char *name)
{
struct vbe_cnt *vc;
ASSERT_CLI();
VTAILQ_FOREACH(vc, &vbe_cnt_head, list)
if (!strcmp(vc->name, name))
break;
AN(vc);
vc->refcnt--;
vc->vsc_vbe->vcls = vc->refcnt;
if (vc->refcnt > 0)
return;
AZ(vc->refcnt);
VTAILQ_REMOVE(&vbe_cnt_head, vc, list);
VSM_Free(vc->vsc_vbe);
FREE_OBJ(vc);
}
/*--------------------------------------------------------------------
* The "simple" director really isn't, since thats where all the actual
* connections happen. Nontheless, pretend it is simple by sequestering
......@@ -466,6 +533,7 @@ struct vdi_simple {
#define VDI_SIMPLE_MAGIC 0x476d25b7
struct director dir;
struct backend *backend;
struct vsc_vbe *stats;
};
static struct vbe_conn *
......@@ -507,6 +575,7 @@ vdi_simple_fini(struct director *d)
CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
VBE_DropRef(vs->backend);
vbe_stat_deref(vs->dir.vcl_name);
free(vs->dir.vcl_name);
vs->dir.magic = 0;
FREE_OBJ(vs);
......@@ -534,6 +603,7 @@ VRT_init_dir_simple(struct cli *cli, struct director **bp, int idx,
vs->dir.healthy = vdi_simple_healthy;
vs->backend = VBE_AddBackend(cli, t);
vs->stats = vbe_stat_ref(t->vcl_name);
bp[idx] = &vs->dir;
}
......@@ -48,3 +48,11 @@ struct vsc_sma {
#include "vsc_fields.h"
#undef VSC_F_SMA
};
#define VSC_TYPE_VBE "VBE"
struct vsc_vbe {
#define VSC_F_VBE(n, t, l, f, e) t n;
#include "vsc_fields.h"
#undef VSC_F_VBE
};
......@@ -32,12 +32,12 @@
* stats structure.
*/
/**********************************************************************/
#ifndef VSC_F_MAIN
#define VSC_F_MAIN(a, b, c, d, e)
#define __VSC_F_MAIN
#endif
VSC_F_MAIN(client_conn, uint64_t, 0, 'a', "Client connections accepted")
VSC_F_MAIN(client_drop, uint64_t, 0, 'a',
"Connection dropped, no sess/wrk")
......@@ -161,6 +161,8 @@ VSC_F_MAIN(critbit_cooler, uint64_t, 0, 'i', "Objhdr's on cool list")
#undef __VSC_F_MAIN
#endif
/**********************************************************************/
#ifndef VSC_F_SMA
#define VSC_F_SMA(a, b, c, d, e)
#define __VSC_F_SMA
......@@ -176,3 +178,17 @@ VSC_F_SMA(sma_bfree, uint64_t, 0, 'i', "Bytes free")
#undef VSC_F_SMA
#undef __VSC_F_SMA
#endif
/**********************************************************************/
#ifndef VSC_F_VBE
#define VSC_F_VBE(a, b, c, d, e)
#define __VSC_F_VBE
#endif
VSC_F_VBE(vcls, uint64_t, 0, 'i', "VCL references")
#ifdef __VSC_F_VBE
#undef VSC_F_VBE
#undef __VSC_F_VBE
#endif
......@@ -339,6 +339,34 @@ iter_sma(const struct vsc *vsc, struct vsm_chunk *sha, vsc_iter_f *func,
return (0);
}
static int
iter_vbe(const struct vsc *vsc, struct vsm_chunk *sha, vsc_iter_f *func,
void *priv)
{
struct vsc_vbe *st;
struct vsc_point sp;
int i;
CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
st = VSM_PTR(sha);
sp.class = VSC_TYPE_VBE;
sp.ident = sha->ident;
#define VSC_F_VBE(nn, tt, ll, ff, dd) \
sp.name = #nn; \
sp.fmt = #tt; \
sp.flag = ff; \
sp.desc = dd; \
sp.ptr = &st->nn; \
i = iter_call(vsc, func, priv, &sp); \
if (i) \
return(i);
#include "vsc_fields.h"
#undef VSC_F_VBE
return (0);
}
int
VSC_Iter(struct VSM_data *vd, vsc_iter_f *func, void *priv)
{
......@@ -359,6 +387,8 @@ VSC_Iter(struct VSM_data *vd, vsc_iter_f *func, void *priv)
i = iter_main(vsc, sha, func, priv);
else if (!strcmp(sha->type, VSC_TYPE_SMA))
i = iter_sma(vsc, sha, func, priv);
else if (!strcmp(sha->type, VSC_TYPE_VBE))
i = iter_vbe(vsc, sha, func, priv);
else
i = -1;
if (i != 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment