[master] eeef8c2 Add management shared memory counters. Add MGT.uptime management process uptime counter.
Martin Blix Grydeland
martin at varnish-cache.org
Wed May 15 14:46:13 CEST 2013
commit eeef8c2bff79590237e362b8d8dc9263854d97b8
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Mon Jan 7 15:01:54 2013 +0100
Add management shared memory counters. Add MGT.uptime management
process uptime counter.
diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index 8f0fd3b..eb729de 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -30,6 +30,7 @@
#include <stdint.h>
+#include "vapi/vsc_int.h"
#include "common/common.h"
struct cli;
@@ -62,6 +63,8 @@ void mgt_cli_secret(const char *S_arg);
void mgt_cli_close_all(void);
/* mgt_main.c */
+extern struct VSC_C_mgt *VSC_C_mgt;
+extern struct VSC_C_mgt static_VSC_C_mgt;
struct choice {
const char *name;
const void *ptr;
diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c
index 6c4780d..2c971fb 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -86,6 +86,7 @@ static struct vev *ev_listen;
static struct vlu *child_std_vlu;
static struct vsb *child_panic = NULL;
+static double mgt_uptime_t0 = 0.;
/* XXX: Doesn't really belong here, but only place we use it */
static inline int
@@ -649,6 +650,20 @@ mgt_sigint(const struct vev *e, int what)
exit (2);
}
+/*--------------------------------------------------------------------*/
+
+static int __match_proto__(vev_cb_f)
+mgt_uptime(const struct vev *e, int what)
+{
+
+ (void)e;
+ (void)what;
+ AN(VSC_C_mgt);
+ VSC_C_mgt->uptime = static_VSC_C_mgt.uptime =
+ VTIM_mono() - mgt_uptime_t0;
+ return (0);
+}
+
/*=====================================================================
* This thread is the master thread in the management process.
* The relatively simple task is to start and stop the child process
@@ -662,6 +677,14 @@ MGT_Run(void)
struct vev *e;
int i;
+ mgt_uptime_t0 = VTIM_mono();
+ e = vev_new();
+ XXXAN(e);
+ e->callback = mgt_uptime;
+ e->timeout = 1.0;
+ e->name = "mgt_uptime";
+ AZ(vev_add(mgt_evb, e));
+
e = vev_new();
XXXAN(e);
e->sig = SIGTERM;
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index a111481..5031eab 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -69,6 +69,8 @@ pid_t mgt_pid;
struct vev_base *mgt_evb;
int exit_status = 0;
struct vsb *vident;
+struct VSC_C_mgt static_VSC_C_mgt;
+struct VSC_C_mgt *VSC_C_mgt;
/*--------------------------------------------------------------------*/
@@ -330,6 +332,10 @@ main(int argc, char * const *argv)
char **av;
unsigned clilim;
+ /* Set up the mgt counters */
+ memset(&static_VSC_C_mgt, 0, sizeof static_VSC_C_mgt);
+ VSC_C_mgt = &static_VSC_C_mgt;
+
/*
* Start out by closing all unwanted file descriptors we might
* have inherited from sloppy process control daemons.
diff --git a/bin/varnishd/mgt/mgt_shmem.c b/bin/varnishd/mgt/mgt_shmem.c
index 2e92df6..a0aaa9d 100644
--- a/bin/varnishd/mgt/mgt_shmem.c
+++ b/bin/varnishd/mgt/mgt_shmem.c
@@ -45,7 +45,6 @@
#include "common/params.h"
#include "flopen.h"
-#include "vapi/vsc_int.h"
#include "vapi/vsm_int.h"
#include "vmb.h"
@@ -240,6 +239,12 @@ mgt_SHM_Create(void)
heritage.panic_str_len, PAN_CLASS, "", "");
AN(heritage.panic_str);
+ /* Copy management counters to shm and update pointer */
+ VSC_C_mgt = VSM_common_alloc(heritage.vsm,
+ sizeof *VSC_C_mgt, VSC_CLASS, VSC_TYPE_MGT, "");
+ AN(VSC_C_mgt);
+ *VSC_C_mgt = static_VSC_C_mgt;
+
if (rename(fnbuf, VSM_FILENAME)) {
fprintf(stderr, "Rename failed %s -> %s: %s\n",
fnbuf, VSM_FILENAME, strerror(errno));
@@ -261,6 +266,9 @@ void
mgt_SHM_Destroy(int keep)
{
+ /* Point mgt counters back at static version */
+ VSC_C_mgt = &static_VSC_C_mgt;
+
AN(heritage.vsm);
if (keep)
(void)rename(VSM_FILENAME, VSM_FILENAME ".keep");
diff --git a/include/tbl/vsc_all.h b/include/tbl/vsc_all.h
index ae42507..e1ccb52 100644
--- a/include/tbl/vsc_all.h
+++ b/include/tbl/vsc_all.h
@@ -28,6 +28,11 @@
*/
+VSC_DO(MGT, mgt, VSC_TYPE_MGT)
+#define VSC_DO_MGT
+#include "tbl/vsc_fields.h"
+#undef VSC_DO_MGT
+VSC_DONE(MGT, mgt, VSC_TYPE_MGT)
VSC_DO(LCK, lck, VSC_TYPE_LCK)
#define VSC_DO_LCK
diff --git a/include/tbl/vsc_fields.h b/include/tbl/vsc_fields.h
index 1ab16ff..e763225 100644
--- a/include/tbl/vsc_fields.h
+++ b/include/tbl/vsc_fields.h
@@ -59,6 +59,17 @@
/**********************************************************************/
+#ifdef VSC_DO_MGT
+
+VSC_F(uptime, uint64_t, 0, 'c',
+ "Management process uptime",
+ "Uptime in seconds of the management process"
+)
+
+#endif
+
+/**********************************************************************/
+
#ifdef VSC_DO_LCK
VSC_F(creat, uint64_t, 0, 'a',
diff --git a/include/vapi/vsc_int.h b/include/vapi/vsc_int.h
index 95346e3..b98df57 100644
--- a/include/vapi/vsc_int.h
+++ b/include/vapi/vsc_int.h
@@ -30,6 +30,7 @@
#define VSC_CLASS "Stat"
+#define VSC_TYPE_MGT "MGT"
#define VSC_TYPE_MAIN ""
#define VSC_TYPE_SMA "SMA"
#define VSC_TYPE_SMF "SMF"
More information about the varnish-commit
mailing list