From 09d48c719292057ce98ef727030c7778c86b7b6d Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Thu, 2 Apr 2015 21:22:11 -0700 Subject: [PATCH] Move expvar under the registry section For consistency with other systems, the redis and caching monitoring data has been moved under the "registry" section in expvar. This ensures the entire registry state is kept to a single section. Signed-off-by: Stephen J Day --- registry/handlers/app.go | 9 +++++++-- registry/storage/layercache.go | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/registry/handlers/app.go b/registry/handlers/app.go index 0863732c5..fac93382f 100644 --- a/registry/handlers/app.go +++ b/registry/handlers/app.go @@ -272,13 +272,18 @@ func (app *App) configureRedis(configuration *configuration.Configuration) { app.redis = pool - expvar.Publish("redis", expvar.Func(func() interface{} { + // setup expvar + registry := expvar.Get("registry") + if registry == nil { + registry = expvar.NewMap("registry") + } + + registry.(*expvar.Map).Set("redis", expvar.Func(func() interface{} { return map[string]interface{}{ "Config": configuration.Redis, "Active": app.redis.ActiveCount(), } })) - } func (app *App) ServeHTTP(w http.ResponseWriter, r *http.Request) { diff --git a/registry/storage/layercache.go b/registry/storage/layercache.go index c7ee9b27a..b9732f203 100644 --- a/registry/storage/layercache.go +++ b/registry/storage/layercache.go @@ -174,7 +174,26 @@ var layerInfoCacheMetrics struct { } func init() { - expvar.Publish("layerinfocache", expvar.Func(func() interface{} { + registry := expvar.Get("registry") + if registry == nil { + registry = expvar.NewMap("registry") + } + + cache := registry.(*expvar.Map).Get("cache") + if cache == nil { + cache = &expvar.Map{} + cache.(*expvar.Map).Init() + registry.(*expvar.Map).Set("cache", cache) + } + + storage := cache.(*expvar.Map).Get("storage") + if storage == nil { + storage = &expvar.Map{} + storage.(*expvar.Map).Init() + cache.(*expvar.Map).Set("storage", storage) + } + + storage.(*expvar.Map).Set("layerinfo", expvar.Func(func() interface{} { // no need for synchronous access: the increments are atomic and // during reading, we don't care if the data is up to date. The // numbers will always *eventually* be reported correctly.