Преглед изворни кода

Add more data to status json

Fix another potential race
Ask Bjørn Hansen пре 10 година
родитељ
комит
f9588208d4
2 измењених фајлова са 16 додато и 2 уклоњено
  1. 10 2
      monitor.go
  2. 6 0
      zone.go

+ 10 - 2
monitor.go

@@ -271,15 +271,20 @@ func StatusJSONHandler(zones Zones) func(http.ResponseWriter, *http.Request) {
 		zonemetrics := make(map[string]metrics.Registry)
 
 		for name, zone := range zones {
+			zone.Lock()
 			zonemetrics[name] = zone.Metrics.Registry
+			zone.Unlock()
 		}
 
 		type statusData struct {
 			Version  string
 			Uptime   int64
 			Platform string
-			Metrics  map[string]metrics.Registry
+			Zones    map[string]metrics.Registry
 			Global   metrics.Registry
+			ID       string
+			IP       string
+			Groups   []string
 		}
 
 		uptime := int64(time.Since(timeStarted).Seconds())
@@ -288,8 +293,11 @@ func StatusJSONHandler(zones Zones) func(http.ResponseWriter, *http.Request) {
 			Version:  VERSION,
 			Uptime:   uptime,
 			Platform: runtime.GOARCH + "-" + runtime.GOOS,
-			Metrics:  zonemetrics,
+			Zones:    zonemetrics,
 			Global:   metrics.DefaultRegistry,
+			ID:       serverID,
+			IP:       serverIP,
+			Groups:   serverGroups,
 		}
 
 		b, err := json.Marshal(status)

+ 6 - 0
zone.go

@@ -2,6 +2,7 @@ package main
 
 import (
 	"strings"
+	"sync"
 
 	"github.com/abh/geodns/Godeps/_workspace/src/github.com/miekg/dns"
 	"github.com/abh/geodns/Godeps/_workspace/src/github.com/rcrowley/go-metrics"
@@ -59,6 +60,8 @@ type Zone struct {
 	Options    ZoneOptions
 	Logging    *ZoneLogging
 	Metrics    ZoneMetrics
+
+	sync.RWMutex
 }
 
 type qTypes []uint16
@@ -79,6 +82,9 @@ func NewZone(name string) *Zone {
 }
 
 func (z *Zone) SetupMetrics(old *Zone) {
+	z.Lock()
+	defer z.Unlock()
+
 	if old != nil {
 		z.Metrics = old.Metrics
 	}