1
0
Fork 0
mirror of https://github.com/Luzifer/continuous-spark.git synced 2024-12-20 09:41:19 +00:00

Use stathat instead of prometheus

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2017-07-26 13:01:15 +02:00
parent 7945c01bfb
commit 4cdb398080
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 18 additions and 37 deletions

22
main.go
View file

@ -2,21 +2,26 @@ package main
import (
"fmt"
"net/http"
"os"
"time"
"github.com/Luzifer/rconfig"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
stathat "github.com/stathat/go"
)
const (
metricPing = "[CS] Ping"
metricThresholdRX = "[CS] Threshold RX"
metricThresholdTX = "[CS] Threshold TX"
)
var (
cfg struct {
Hostname string `flag:"hostname" default:"" description:"Hostname / IP of the sparkyfish server" validate:"nonzero"`
Interval time.Duration `flag:"interval" default:"15m" description:"Interval to execute test in"`
Listen string `flag:"listen" default:":3000" description:"IP/Port to listen on"`
LogLevel string `flag:"log-level" default:"info" description:"Set log level (debug, info, warning, error)"`
StatHatEZKey string `flag:"stathat-ezkey" default:"" description:"Key to post metrics to" validate:"nonzero"`
Port int `flag:"port" default:"7121" description:"Port the sparkyfish server is running on"`
VersionAndExit bool `flag:"version" default:"false" description:"Print version information and exit"`
}
@ -42,7 +47,6 @@ func init() {
}
func main() {
go func() {
if err := updateStats(execTest()); err != nil {
log.Error(err.Error())
}
@ -53,10 +57,6 @@ func main() {
continue
}
}
}()
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(cfg.Listen, nil)
}
func updateStats(t *testResult, err error) error {
@ -64,9 +64,9 @@ func updateStats(t *testResult, err error) error {
return err
}
pingAvg.Set(t.Ping.Avg)
thresholdAvg.WithLabelValues("recv").Set(t.Receive.Avg)
thresholdAvg.WithLabelValues("send").Set(t.Send.Avg)
stathat.PostEZValue(metricPing, cfg.StatHatEZKey, t.Ping.Avg)
stathat.PostEZValue(metricThresholdRX, cfg.StatHatEZKey, t.Receive.Avg)
stathat.PostEZValue(metricThresholdTX, cfg.StatHatEZKey, t.Send.Avg)
return nil
}

View file

@ -1,19 +0,0 @@
package main
import "github.com/prometheus/client_golang/prometheus"
var (
pingAvg = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "sparkyfish_ping_avg",
Help: "Average ping of the test run (ms)",
})
thresholdAvg = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "sparkyfish_threshold_avg",
Help: "Average threshold of the test run (bps)",
}, []string{"direction"})
)
func init() {
prometheus.MustRegister(pingAvg)
prometheus.MustRegister(thresholdAvg)
}