generated from sendnrw/template_golang
exporter.go aktualisiert
All checks were successful
build-binaries / build (, arm, 7, linux) (push) Has been skipped
build-binaries / build (, arm64, linux) (push) Has been skipped
build-binaries / build (.exe, amd64, windows) (push) Has been skipped
build-binaries / build (, amd64, linux) (push) Has been skipped
build-binaries / release (push) Has been skipped
build-binaries / publish-agent (push) Has been skipped
release-tag / release-image (push) Successful in 2m33s
All checks were successful
build-binaries / build (, arm, 7, linux) (push) Has been skipped
build-binaries / build (, arm64, linux) (push) Has been skipped
build-binaries / build (.exe, amd64, windows) (push) Has been skipped
build-binaries / build (, amd64, linux) (push) Has been skipped
build-binaries / release (push) Has been skipped
build-binaries / publish-agent (push) Has been skipped
release-tag / release-image (push) Successful in 2m33s
This commit is contained in:
48
exporter.go
48
exporter.go
@@ -27,7 +27,6 @@ func NewTargetRunner(name, host string, cfg TargetSettings) *TargetRunner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prometheus-Metrics
|
|
||||||
var (
|
var (
|
||||||
pingUp = prometheus.NewGaugeVec(
|
pingUp = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
@@ -37,19 +36,19 @@ var (
|
|||||||
[]string{"target"},
|
[]string{"target"},
|
||||||
)
|
)
|
||||||
pingRTT = prometheus.NewGaugeVec(
|
pingRTT = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "ping_rtt_seconds",
|
Name: "ping_rtt_seconds",
|
||||||
Help: "Last ping round trip time in seconds",
|
Help: "Last ping round trip time in seconds",
|
||||||
},
|
},
|
||||||
[]string{"target"},
|
[]string{"target"},
|
||||||
)
|
)
|
||||||
pingRTTMs = prometheus.NewGaugeVec(
|
pingRTTMs = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "ping_rtt_milliseconds",
|
Name: "ping_rtt_milliseconds",
|
||||||
Help: "Last ping round trip time in milliseconds",
|
Help: "Last ping round trip time in milliseconds",
|
||||||
},
|
},
|
||||||
[]string{"target"},
|
[]string{"target"},
|
||||||
)
|
)
|
||||||
pingRTTAvg = prometheus.NewGaugeVec(
|
pingRTTAvg = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "ping_rtt_seconds_avg",
|
Name: "ping_rtt_seconds_avg",
|
||||||
@@ -57,6 +56,13 @@ var (
|
|||||||
},
|
},
|
||||||
[]string{"target"},
|
[]string{"target"},
|
||||||
)
|
)
|
||||||
|
pingRTTAvgMs = prometheus.NewGaugeVec(
|
||||||
|
prometheus.GaugeOpts{
|
||||||
|
Name: "ping_rtt_milliseconds_avg",
|
||||||
|
Help: "Average ping round trip time in milliseconds (over history)",
|
||||||
|
},
|
||||||
|
[]string{"target"},
|
||||||
|
)
|
||||||
pingPacketsSent = prometheus.NewCounterVec(
|
pingPacketsSent = prometheus.NewCounterVec(
|
||||||
prometheus.CounterOpts{
|
prometheus.CounterOpts{
|
||||||
Name: "ping_packets_sent_total",
|
Name: "ping_packets_sent_total",
|
||||||
@@ -74,7 +80,15 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
prometheus.MustRegister(pingUp, pingRTT, pingRTTMs, pingRTTAvg, pingPacketsSent, pingPacketsRecv)
|
prometheus.MustRegister(
|
||||||
|
pingUp,
|
||||||
|
pingRTT,
|
||||||
|
pingRTTMs,
|
||||||
|
pingRTTAvg,
|
||||||
|
pingRTTAvgMs,
|
||||||
|
pingPacketsSent,
|
||||||
|
pingPacketsRecv,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TargetRunner) Run(stop <-chan struct{}) {
|
func (t *TargetRunner) Run(stop <-chan struct{}) {
|
||||||
@@ -103,13 +117,13 @@ func (t *TargetRunner) Run(stop <-chan struct{}) {
|
|||||||
pingRTT.With(lbl).Set(sec)
|
pingRTT.With(lbl).Set(sec)
|
||||||
pingRTTMs.With(lbl).Set(sec * 1000)
|
pingRTTMs.With(lbl).Set(sec * 1000)
|
||||||
|
|
||||||
avg := t.addToHistoryAndAvg(sec)
|
avgSec := t.addToHistoryAndAvg(sec)
|
||||||
pingRTTAvg.With(lbl).Set(avgSec)
|
pingRTTAvg.With(lbl).Set(avgSec)
|
||||||
pingRTTAvgMs.With(lbl).Set(avgSec * 1000)
|
pingRTTAvgMs.With(lbl).Set(avgSec * 1000)
|
||||||
} else {
|
} else {
|
||||||
pingUp.With(lbl).Set(0)
|
pingUp.With(lbl).Set(0)
|
||||||
// RTT nicht ändern oder auf 0 setzen?
|
|
||||||
pingRTT.With(lbl).Set(0)
|
pingRTT.With(lbl).Set(0)
|
||||||
|
pingRTTMs.With(lbl).Set(0)
|
||||||
log.Printf("ping to %s failed: %v", t.name, res.Err)
|
log.Printf("ping to %s failed: %v", t.name, res.Err)
|
||||||
}
|
}
|
||||||
case <-stop:
|
case <-stop:
|
||||||
|
|||||||
Reference in New Issue
Block a user