Adding statistics to varnish

The Ixos theixos at gmail.com
Thu Mar 7 16:53:50 CET 2013


Hi,

I would like to add to Varnish some statistics (which are not available in
the VCL).
They will be logged by calling syslog in cnt_done after the end of each
request.
I am just beginning the adventure of varnish and therefore I have a few
questions:
1) where to put the statistics variable (int, char *) so that they won't be
overwritten by another thread - the struct sess, sessmem or somewhere else?
2) where to put initialization of variables that they will be initialized
before each request - VCA_Prep?

When I view logs I see that Content-Lengt << clinet_out, I mean
Content-Length is couple times smaller then client_out.
It looks like clinet_out isn't cleared at the beggining of request or
another thread add something to it between sending data and saving logs.
While the same time backend_in, backend_out and client_in data seems to be
correct.
This error occurs in about 5-10% of requests and I'm not able to reproduce
it on a machine.

Here's how I'm doing it now:
/* cache.h */
struct conn_stat{
    unsigned        magic;
#define CONN_STAT_MAGIC     0xf6d1bf
    char    *host;
    char    *addr;

    unsigned long long  client_in;
    unsigned long long  client_out;

    unsigned long long  backend_in;
    unsigned long long  backend_out;
};

struct sess {
    /* ... */
    struct conn_stat    conn_stat;
    unsigned long long  *wbytes; /* Where to put number of bytes written */
    unsigned long long  *rbytes; /* Where to put number of bytes read */
    /* ... */
};

/* cache_session.c: */
struct sessmem {
    /* ... */
    struct conn_stat    *conn_stat;
    /* ... */
};
//ses_sm_alloc()
    sm = (void*)p;
    p += sizeof *sm;
    sm->magic = SESSMEM_MAGIC;
    sm->workspace = nws;
    sm->conn_stat = p;
    p += cl;
    sm->http[0] = HTTP_create(p, nhttp);
    p += hl;
    sm->http[1] = HTTP_create(p, nhttp);
    p += hl;
    sm->wsp = p;
    p += nws;

/* cache_center.c */
static int
cnt_streamdeliver(struct sess *sp)
{
    struct busyobj *bo;

    bo = sp->stream_busyobj;
    CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);

    sp->wbytes = &sp->conn_stat.client_out;
    *sp->wbytes = 0;

    RES_StreamStart(sp);
    sp->wrk->h_content_length = NULL;

    if (sp->wantbody)
        RES_StreamBody(sp);

    RES_StreamEnd(sp);

    sp->wbytes = NULL;
    /* ... */

static int
cnt_done(struct sess *sp)
{
    double dh, dp, da;
    int i;

    CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
    CHECK_OBJ_ORNULL(sp->vcl, VCL_CONF_MAGIC);

    if(sp->vcl != NULL) {
        syslog(LOG_INFO, "%llu", sp->conn_stat->client_out);
    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-dev/attachments/20130307/725f625f/attachment.html>


More information about the varnish-dev mailing list