Skip to content

Commit

Permalink
Rename probe up metric to success to follow blackbox standard
Browse files Browse the repository at this point in the history
  • Loading branch information
edgard committed May 30, 2019
1 parent d1f043c commit 99c6c83
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions iperf3_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type Exporter struct {
timeout time.Duration
mutex sync.RWMutex

up *prometheus.Desc
success *prometheus.Desc
sentSeconds *prometheus.Desc
sentBytes *prometheus.Desc
receivedSeconds *prometheus.Desc
Expand All @@ -81,7 +81,7 @@ func NewExporter(target string, period time.Duration, timeout time.Duration) *Ex
target: target,
period: period,
timeout: timeout,
up: prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "up"), "Was the last iperf3 probe successful.", nil, nil),
success: prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "success"), "Was the last iperf3 probe successful.", nil, nil),
sentSeconds: prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "sent_seconds"), "Total seconds spent sending packets.", nil, nil),
sentBytes: prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "sent_bytes"), "Total sent bytes.", nil, nil),
receivedSeconds: prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "received_seconds"), "Total seconds spent receiving packets.", nil, nil),
Expand All @@ -92,7 +92,7 @@ func NewExporter(target string, period time.Duration, timeout time.Duration) *Ex
// Describe describes all the metrics exported by the iperf3 exporter. It
// implements prometheus.Collector.
func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
ch <- e.up
ch <- e.success
ch <- e.sentSeconds
ch <- e.sentBytes
ch <- e.receivedSeconds
Expand All @@ -110,21 +110,21 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {

out, err := exec.CommandContext(ctx, iperfCmd, "-J", "-t", strconv.FormatFloat(e.period.Seconds(), 'f', 0, 64), "-c", e.target).Output()
if err != nil {
ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 0)
ch <- prometheus.MustNewConstMetric(e.success, prometheus.GaugeValue, 0)
iperfErrors.Inc()
log.Errorf("Failed to run iperf3: %s", err)
return
}

stats := iperfResult{}
if err := json.Unmarshal(out, &stats); err != nil {
ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 0)
ch <- prometheus.MustNewConstMetric(e.success, prometheus.GaugeValue, 0)
iperfErrors.Inc()
log.Errorf("Failed to parse iperf3 result: %s", err)
return
}

ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 1)
ch <- prometheus.MustNewConstMetric(e.success, prometheus.GaugeValue, 1)
ch <- prometheus.MustNewConstMetric(e.sentSeconds, prometheus.GaugeValue, stats.End.SumSent.Seconds)
ch <- prometheus.MustNewConstMetric(e.sentBytes, prometheus.GaugeValue, stats.End.SumSent.Bytes)
ch <- prometheus.MustNewConstMetric(e.receivedSeconds, prometheus.GaugeValue, stats.End.SumReceived.Seconds)
Expand Down

0 comments on commit 99c6c83

Please sign in to comment.