Skip to content

Commit

Permalink
Add more data to status json
Browse files Browse the repository at this point in the history
Fix another potential race
  • Loading branch information
abh committed Sep 7, 2015
1 parent ddbc8ef commit f958820
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions monitor.go
Expand Up @@ -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())
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions zone.go
Expand Up @@ -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"
Expand Down Expand Up @@ -59,6 +60,8 @@ type Zone struct {
Options ZoneOptions
Logging *ZoneLogging
Metrics ZoneMetrics

sync.RWMutex
}

type qTypes []uint16
Expand All @@ -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
}
Expand Down

0 comments on commit f958820

Please sign in to comment.