Selaa lähdekoodia

Add StatHat feature

Ask Bjørn Hansen 12 vuotta sitten
vanhempi
commit
ab821f7061
3 muutettua tiedostoa jossa 40 lisäystä ja 2 poistoa
  1. 3 2
      config.go
  2. 1 0
      geodns.go
  3. 36 0
      stathat.go

+ 3 - 2
config.go

@@ -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 - 0
geodns.go

@@ -112,6 +112,7 @@ func main() {
 	}
 
 	go configWatcher(configFileName)
+	go statHatPoster()
 
 	if *flaginter == "*" {
 		addrs, _ := net.InterfaceAddrs()

+ 36 - 0
stathat.go

@@ -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()))
+
+	}
+}