mirror of
https://github.com/Luzifer/continuous-spark.git
synced 2024-12-20 17:51:22 +00:00
Use stathat instead of prometheus
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
7945c01bfb
commit
4cdb398080
2 changed files with 18 additions and 37 deletions
36
main.go
36
main.go
|
@ -2,21 +2,26 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Luzifer/rconfig"
|
"github.com/Luzifer/rconfig"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
stathat "github.com/stathat/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
metricPing = "[CS] Ping"
|
||||||
|
metricThresholdRX = "[CS] Threshold RX"
|
||||||
|
metricThresholdTX = "[CS] Threshold TX"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cfg struct {
|
cfg struct {
|
||||||
Hostname string `flag:"hostname" default:"" description:"Hostname / IP of the sparkyfish server" validate:"nonzero"`
|
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"`
|
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)"`
|
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"`
|
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"`
|
VersionAndExit bool `flag:"version" default:"false" description:"Print version information and exit"`
|
||||||
}
|
}
|
||||||
|
@ -42,21 +47,16 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
go func() {
|
if err := updateStats(execTest()); err != nil {
|
||||||
|
log.Error(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
for range time.Tick(cfg.Interval) {
|
||||||
if err := updateStats(execTest()); err != nil {
|
if err := updateStats(execTest()); err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for range time.Tick(cfg.Interval) {
|
|
||||||
if err := updateStats(execTest()); err != nil {
|
|
||||||
log.Error(err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
http.Handle("/metrics", promhttp.Handler())
|
|
||||||
http.ListenAndServe(cfg.Listen, nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateStats(t *testResult, err error) error {
|
func updateStats(t *testResult, err error) error {
|
||||||
|
@ -64,9 +64,9 @@ func updateStats(t *testResult, err error) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
pingAvg.Set(t.Ping.Avg)
|
stathat.PostEZValue(metricPing, cfg.StatHatEZKey, t.Ping.Avg)
|
||||||
thresholdAvg.WithLabelValues("recv").Set(t.Receive.Avg)
|
stathat.PostEZValue(metricThresholdRX, cfg.StatHatEZKey, t.Receive.Avg)
|
||||||
thresholdAvg.WithLabelValues("send").Set(t.Send.Avg)
|
stathat.PostEZValue(metricThresholdTX, cfg.StatHatEZKey, t.Send.Avg)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
19
metrics.go
19
metrics.go
|
@ -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)
|
|
||||||
}
|
|
Loading…
Reference in a new issue