Skip to content

Commit

Permalink
Add StatHat feature
Browse files Browse the repository at this point in the history
  • Loading branch information
abh committed Mar 8, 2013
1 parent a173bef commit ab821f7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
5 changes: 3 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ func configReader(fileName string) error {

cfg.Flags.HasStatHat = len(cfg.StatHat.ApiKey) > 0

fmt.Println("STATHAT APIKEY:", cfg.StatHat.ApiKey)
fmt.Println("STATHAT FLAG :", cfg.Flags.HasStatHat)
// log.Println("STATHAT APIKEY:", cfg.StatHat.ApiKey)
// log.Println("STATHAT FLAG :", cfg.Flags.HasStatHat)

Config = cfg

return nil
}
1 change: 1 addition & 0 deletions geodns.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func main() {
}

go configWatcher(configFileName)
go statHatPoster()

if *flaginter == "*" {
addrs, _ := net.InterfaceAddrs()
Expand Down
36 changes: 36 additions & 0 deletions stathat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"github.com/stathat/go"
"log"
"runtime"
"strings"
"time"
)

func statHatPoster() {

lastQueryCount := expVarToInt64(qCounter)
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 := expVarToInt64(qCounter)
newQueries := current - lastQueryCount
lastQueryCount = current

stathat.PostEZCount("queries:"+suffix, Config.StatHat.ApiKey, int(newQueries))
stathat.PostEZValue("goroutines "+serverId, Config.StatHat.ApiKey, float64(runtime.NumGoroutine()))

}
}

0 comments on commit ab821f7

Please sign in to comment.