-
Notifications
You must be signed in to change notification settings - Fork 193
/
stathat.go
88 lines (66 loc) · 2.06 KB
/
stathat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"log"
"runtime"
"strings"
"time"
"github.com/abh/geodns/Godeps/_workspace/src/github.com/rcrowley/go-metrics"
"github.com/abh/geodns/Godeps/_workspace/src/github.com/stathat/go"
)
func (zs *Zones) statHatPoster() {
if len(Config.StatHat.ApiKey) == 0 {
return
}
stathatGroups := append(serverGroups, "total", serverID)
suffix := strings.Join(stathatGroups, ",")
lastCounts := map[string]int64{}
lastEdnsCounts := map[string]int64{}
for name, zone := range *zs {
if zone.Logging.StatHat == true {
lastCounts[name] = zone.Metrics.Queries.Count()
lastEdnsCounts[name] = zone.Metrics.EdnsQueries.Count()
}
}
for {
time.Sleep(60 * time.Second)
for name, zone := range *zs {
count := zone.Metrics.Queries.Count()
newCount := count - lastCounts[name]
lastCounts[name] = count
if zone.Logging != nil && zone.Logging.StatHat == true {
apiKey := zone.Logging.StatHatAPI
if len(apiKey) == 0 {
apiKey = Config.StatHat.ApiKey
}
if len(apiKey) == 0 {
continue
}
stathat.PostEZCount("zone "+name+" queries~"+suffix, Config.StatHat.ApiKey, int(newCount))
ednsCount := zone.Metrics.EdnsQueries.Count()
newEdnsCount := ednsCount - lastEdnsCounts[name]
lastEdnsCounts[name] = ednsCount
stathat.PostEZCount("zone "+name+" edns queries~"+suffix, Config.StatHat.ApiKey, int(newEdnsCount))
}
}
}
}
func statHatPoster() {
qCounter := metrics.Get("queries").(metrics.Meter)
lastQueryCount := qCounter.Count()
stathatGroups := append(serverGroups, "total", serverID)
suffix := strings.Join(stathatGroups, ",")
// stathat.Verbose = true
for {
time.Sleep(60 * time.Second)
if !Config.Flags.HasStatHat {
log.Println("No stathat configuration")
continue
}
log.Println("Posting to stathat")
current := qCounter.Count()
newQueries := current - lastQueryCount
lastQueryCount = current
stathat.PostEZCount("queries~"+suffix, Config.StatHat.ApiKey, int(newQueries))
stathat.PostEZValue("goroutines "+serverID, Config.StatHat.ApiKey, float64(runtime.NumGoroutine()))
}
}