r243 - in trunk/varnish-cache: bin/varnishd include
phk at projects.linpro.no
phk at projects.linpro.no
Wed Jun 28 11:21:16 CEST 2006
Author: phk
Date: 2006-06-28 11:21:15 +0200 (Wed, 28 Jun 2006)
New Revision: 243
Added:
trunk/varnish-cache/include/stat_field.h
trunk/varnish-cache/include/stats.h
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_acceptor.c
trunk/varnish-cache/bin/varnishd/cache_shmlog.c
trunk/varnish-cache/bin/varnishd/mgt.h
trunk/varnish-cache/bin/varnishd/varnishd.c
trunk/varnish-cache/include/shmlog.h
Log:
Add statistics counter support.
stat_field.h defines the counter fields with name, type, (printf)format
and description.
stats.h defines a structure with these fields.
shmlog.h makes the structure part of the shared memory logs header.
Implent the "stats" CLI word in the management process.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2006-06-26 19:25:09 UTC (rev 242)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2006-06-28 09:21:15 UTC (rev 243)
@@ -200,6 +200,7 @@
assert(__LINE__ == 0); \
} while (0)
#endif
+extern struct varnish_stats *VSL_stats;
/* cache_vcl.c */
void RelVCL(struct VCL_conf *vc);
Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2006-06-26 19:25:09 UTC (rev 242)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2006-06-28 09:21:15 UTC (rev 243)
@@ -122,6 +122,8 @@
char port[10];
int i;
+ VSL_stats->cli_conn++;
+
(void)arg;
sm = calloc(sizeof *sm, 1);
assert(sm != NULL); /*
Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2006-06-26 19:25:09 UTC (rev 242)
+++ trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2006-06-28 09:21:15 UTC (rev 243)
@@ -3,15 +3,22 @@
*/
#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
#include <assert.h>
#include <string.h>
#include <stdarg.h>
#include <sys/mman.h>
+#include "libvarnish.h"
#include "shmlog.h"
#include "heritage.h"
+struct varnish_stats *VSL_stats;
+
static struct shmloghead *loghead;
static unsigned char *logstart, *logend;
@@ -130,4 +137,45 @@
/* XXX check sanity of loghead */
logstart = (unsigned char *)loghead + loghead->start;
logend = logstart + loghead->size;
+ VSL_stats = &loghead->stats;
}
+
+/*--------------------------------------------------------------------*/
+
+void
+VSL_MgtInit(const char *fn, unsigned size)
+{
+ struct shmloghead slh;
+ int i;
+
+ heritage.vsl_fd = open(fn, O_RDWR | O_CREAT, 0600);
+ if (heritage.vsl_fd < 0) {
+ fprintf(stderr, "Could not open %s: %s\n",
+ fn, strerror(errno));
+ exit (1);
+ }
+ i = read(heritage.vsl_fd, &slh, sizeof slh);
+ if (i != sizeof slh || slh.magic != SHMLOGHEAD_MAGIC) {
+ /* XXX more checks */
+
+ slh.magic = SHMLOGHEAD_MAGIC;
+ slh.size = size;
+ slh.ptr = 0;
+ slh.start = sizeof slh;
+ AZ(lseek(heritage.vsl_fd, 0, SEEK_SET));
+ i = write(heritage.vsl_fd, &slh, sizeof slh);
+ assert(i == sizeof slh);
+ AZ(ftruncate(heritage.vsl_fd, sizeof slh + size));
+ heritage.vsl_size = slh.size + slh.start;
+ } else {
+ heritage.vsl_size = slh.size + slh.start;
+ }
+
+ /*
+ * Call VSL_Init so that we get a VSL_stats pointer in the
+ * management process as well.
+ */
+ VSL_Init();
+ memset(VSL_stats, 0, sizeof *VSL_stats);
+}
+
Modified: trunk/varnish-cache/bin/varnishd/mgt.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt.h 2006-06-26 19:25:09 UTC (rev 242)
+++ trunk/varnish-cache/bin/varnishd/mgt.h 2006-06-28 09:21:15 UTC (rev 243)
@@ -18,3 +18,6 @@
extern struct stevedore sma_stevedore;
extern struct stevedore smf_stevedore;
+
+void VSL_MgtInit(const char *fn, unsigned size);
+extern struct varnish_stats *VSL_stats;
Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c 2006-06-26 19:25:09 UTC (rev 242)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c 2006-06-28 09:21:15 UTC (rev 243)
@@ -27,6 +27,7 @@
#include "mgt.h"
#include "heritage.h"
+#include "shmlog.h"
#include "cli_event.h"
/*--------------------------------------------------------------------*/
@@ -49,7 +50,7 @@
}
static void
-cli_func_passthrough(struct cli *cli, char **av __unused, void *priv)
+m_cli_func_passthrough(struct cli *cli, char **av __unused, void *priv)
{
cli_suspend(cli);
@@ -128,7 +129,7 @@
}
static void
-cli_func_config_inline(struct cli *cli, char **av, void *priv __unused)
+m_cli_func_config_inline(struct cli *cli, char **av, void *priv __unused)
{
char *vf;
struct sbuf *sb;
@@ -193,7 +194,7 @@
/*--------------------------------------------------------------------*/
static void
-cli_func_server_start(struct cli *cli, char **av __unused, void *priv __unused)
+m_cli_func_server_start(struct cli *cli, char **av __unused, void *priv __unused)
{
mgt_child_start();
@@ -202,7 +203,7 @@
/*--------------------------------------------------------------------*/
static void
-cli_func_server_stop(struct cli *cli, char **av __unused, void *priv __unused)
+m_cli_func_server_stop(struct cli *cli, char **av __unused, void *priv __unused)
{
mgt_child_stop();
@@ -211,7 +212,7 @@
/*--------------------------------------------------------------------*/
static void
-cli_func_verbose(struct cli *cli, char **av __unused, void *priv)
+m_cli_func_verbose(struct cli *cli, char **av __unused, void *priv)
{
cli->verbose = !cli->verbose;
@@ -219,7 +220,7 @@
static void
-cli_func_ping(struct cli *cli, char **av, void *priv __unused)
+m_cli_func_ping(struct cli *cli, char **av, void *priv __unused)
{
time_t t;
@@ -232,28 +233,41 @@
/*--------------------------------------------------------------------*/
+static void
+m_cli_func_stats(struct cli *cli, char **av, void *priv __unused)
+{
+
+ assert (VSL_stats != NULL);
+#define MAC_STAT(n,t,f,d) \
+ cli_out(cli, "%12ju " d "\n", (VSL_stats->n));
+#include "stat_field.h"
+#undef MAC_STAT
+}
+
+/*--------------------------------------------------------------------*/
+
static struct cli_proto cli_proto[] = {
/* URL manipulation */
- { CLI_URL_QUERY, cli_func_passthrough, NULL },
- { CLI_URL_PURGE, cli_func_passthrough, NULL },
- { CLI_URL_STATUS, cli_func_passthrough, NULL },
+ { CLI_URL_QUERY, m_cli_func_passthrough, NULL },
+ { CLI_URL_PURGE, m_cli_func_passthrough, NULL },
+ { CLI_URL_STATUS, m_cli_func_passthrough, NULL },
{ CLI_CONFIG_LOAD, m_cli_func_config_load, NULL },
- { CLI_CONFIG_INLINE, cli_func_config_inline, NULL },
- { CLI_CONFIG_UNLOAD, cli_func_passthrough, NULL },
- { CLI_CONFIG_LIST, cli_func_passthrough, NULL },
- { CLI_CONFIG_USE, cli_func_passthrough, NULL },
- { CLI_SERVER_FREEZE, cli_func_passthrough, NULL },
- { CLI_SERVER_THAW, cli_func_passthrough, NULL },
- { CLI_SERVER_SUSPEND, cli_func_passthrough, NULL },
- { CLI_SERVER_RESUME, cli_func_passthrough, NULL },
- { CLI_SERVER_STOP, cli_func_server_stop, NULL },
- { CLI_SERVER_START, cli_func_server_start, NULL },
+ { CLI_CONFIG_INLINE, m_cli_func_config_inline, NULL },
+ { CLI_CONFIG_UNLOAD, m_cli_func_passthrough, NULL },
+ { CLI_CONFIG_LIST, m_cli_func_passthrough, NULL },
+ { CLI_CONFIG_USE, m_cli_func_passthrough, NULL },
+ { CLI_SERVER_FREEZE, m_cli_func_passthrough, NULL },
+ { CLI_SERVER_THAW, m_cli_func_passthrough, NULL },
+ { CLI_SERVER_SUSPEND, m_cli_func_passthrough, NULL },
+ { CLI_SERVER_RESUME, m_cli_func_passthrough, NULL },
+ { CLI_SERVER_STOP, m_cli_func_server_stop, NULL },
+ { CLI_SERVER_START, m_cli_func_server_start, NULL },
{ CLI_SERVER_RESTART },
- { CLI_PING, cli_func_ping, NULL },
- { CLI_STATS },
+ { CLI_PING, m_cli_func_ping, NULL },
+ { CLI_STATS, m_cli_func_stats, NULL },
{ CLI_ZERO },
{ CLI_HELP, cli_func_help, cli_proto },
- { CLI_VERBOSE, cli_func_verbose, NULL },
+ { CLI_VERBOSE, m_cli_func_verbose, NULL },
{ CLI_EXIT },
{ CLI_QUIT },
{ CLI_BYE },
@@ -347,39 +361,6 @@
/*--------------------------------------------------------------------*/
-#include "shmlog.h"
-
-static void
-init_vsl(const char *fn, unsigned size)
-{
- struct shmloghead slh;
- int i;
-
- heritage.vsl_fd = open(fn, O_RDWR | O_CREAT, 0600);
- if (heritage.vsl_fd < 0) {
- fprintf(stderr, "Could not open %s: %s\n",
- fn, strerror(errno));
- exit (1);
- }
- i = read(heritage.vsl_fd, &slh, sizeof slh);
- if (i == sizeof slh && slh.magic == SHMLOGHEAD_MAGIC) {
- /* XXX more checks */
- heritage.vsl_size = slh.size + slh.start;
- return;
- }
- slh.magic = SHMLOGHEAD_MAGIC;
- slh.size = size;
- slh.ptr = 0;
- slh.start = sizeof slh;
- AZ(lseek(heritage.vsl_fd, 0, SEEK_SET));
- i = write(heritage.vsl_fd, &slh, sizeof slh);
- assert(i == sizeof slh);
- AZ(ftruncate(heritage.vsl_fd, sizeof slh + size));
- heritage.vsl_size = slh.size + slh.start;
-}
-
-/*--------------------------------------------------------------------*/
-
/* for development purposes */
#include <printf.h>
#include <err.h>
@@ -459,7 +440,7 @@
*/
open_tcp(portnumber);
- init_vsl(SHMLOG_FILENAME, 1024*1024);
+ VSL_MgtInit(SHMLOG_FILENAME, 1024*1024);
testme();
Modified: trunk/varnish-cache/include/shmlog.h
===================================================================
--- trunk/varnish-cache/include/shmlog.h 2006-06-26 19:25:09 UTC (rev 242)
+++ trunk/varnish-cache/include/shmlog.h 2006-06-28 09:21:15 UTC (rev 243)
@@ -9,21 +9,25 @@
#define SHMLOG_FILENAME "/tmp/_.vsl"
+#include "stats.h"
+
struct shmloghead {
#define SHMLOGHEAD_MAGIC 4185512498U /* From /dev/random */
- unsigned magic;
+ unsigned magic;
/*
* Byte offset into the file where the fifolog starts
* This allows the header to expand later.
*/
- unsigned start;
+ unsigned start;
/* Length of the fifolog area in bytes */
- unsigned size;
+ unsigned size;
/* Current write position relative to the beginning of start */
- unsigned ptr;
+ unsigned ptr;
+
+ struct varnish_stats stats;
};
/*
Added: trunk/varnish-cache/include/stat_field.h
===================================================================
--- trunk/varnish-cache/include/stat_field.h 2006-06-26 19:25:09 UTC (rev 242)
+++ trunk/varnish-cache/include/stat_field.h 2006-06-28 09:21:15 UTC (rev 243)
@@ -0,0 +1,11 @@
+/* $Id$ */
+
+MAC_STAT(cli_conn, uint64_t, "u", "Client connections accepted")
+MAC_STAT(cli_req, uint64_t, "u", "Client requests received")
+
+MAC_STAT(cache_hit, uint64_t, "u", "Cache hits")
+MAC_STAT(cache_miss, uint64_t, "u", "Cache misses")
+
+MAC_STAT(backend_conn, uint64_t, "u", "Backend connections initiated")
+MAC_STAT(backend_req, uint64_t, "u", "Backend requests sent")
+
Added: trunk/varnish-cache/include/stats.h
===================================================================
--- trunk/varnish-cache/include/stats.h 2006-06-26 19:25:09 UTC (rev 242)
+++ trunk/varnish-cache/include/stats.h 2006-06-28 09:21:15 UTC (rev 243)
@@ -0,0 +1,9 @@
+/* $Id$ */
+
+#include <sys/types.h>
+
+struct varnish_stats {
+#define MAC_STAT(n,t,f,e) t n;
+#include "stat_field.h"
+#undef MAC_STAT
+};
More information about the varnish-commit
mailing list