-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To follow the official Prometheus guidelines [1], as well as comments from Prometheus developers [2], we should be using seconds as the unit for all ping_rtt metrics (e.g. `ping_rtt_best_seconds` instead of `ping_rtt_best_ms`). This adds a flag `--metrics.rttunit=s`, to allow the user to follow those best practices. To keep upgrading users from tripping over this change, the default units will remain millis. [1]: https://prometheus.io/docs/practices/naming/#base-units [2]: https://www.robustperception.io/who-wants-seconds Fixes: #16
- Loading branch information
Showing
4 changed files
with
114 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,17 +8,19 @@ import ( | |
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
const prefix = "ping_" | ||
func newDesc(name, help string, variableLabels []string, constLabels prometheus.Labels) *prometheus.Desc { | ||
return prometheus.NewDesc("ping_"+name, help, variableLabels, constLabels) | ||
} | ||
|
||
var ( | ||
labelNames = []string{"target", "ip", "ip_version"} | ||
rttDesc = prometheus.NewDesc(prefix+"rtt_ms", "Round trip time in millis (deprecated)", append(labelNames, "type"), nil) | ||
bestDesc = prometheus.NewDesc(prefix+"rtt_best_ms", "Best round trip time in millis", labelNames, nil) | ||
worstDesc = prometheus.NewDesc(prefix+"rtt_worst_ms", "Worst round trip time in millis", labelNames, nil) | ||
meanDesc = prometheus.NewDesc(prefix+"rtt_mean_ms", "Mean round trip time in millis", labelNames, nil) | ||
stddevDesc = prometheus.NewDesc(prefix+"rtt_std_deviation_ms", "Standard deviation in millis", labelNames, nil) | ||
lossDesc = prometheus.NewDesc(prefix+"loss_percent", "Packet loss in percent", labelNames, nil) | ||
progDesc = prometheus.NewDesc(prefix+"up", "ping_exporter version", nil, prometheus.Labels{"version": version}) | ||
rttDesc = newScaledDesc("rtt_seconds", "Round trip time", append(labelNames, "type")) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
lapo-luchini
|
||
bestDesc = newScaledDesc("rtt_best_seconds", "Best round trip time", labelNames) | ||
worstDesc = newScaledDesc("rtt_worst_seconds", "Worst round trip time", labelNames) | ||
meanDesc = newScaledDesc("rtt_mean_seconds", "Mean round trip time", labelNames) | ||
stddevDesc = newScaledDesc("rtt_std_deviation_seconds", "Standard deviation", labelNames) | ||
lossDesc = newDesc("loss_percent", "Packet loss in percent", labelNames, nil) | ||
progDesc = newDesc("up", "ping_exporter version", nil, prometheus.Labels{"version": version}) | ||
mutex = &sync.Mutex{} | ||
) | ||
|
||
|
@@ -29,13 +31,13 @@ type pingCollector struct { | |
|
||
func (p *pingCollector) Describe(ch chan<- *prometheus.Desc) { | ||
if enableDeprecatedMetrics { | ||
ch <- rttDesc | ||
rttDesc.Describe(ch) | ||
} | ||
bestDesc.Describe(ch) | ||
worstDesc.Describe(ch) | ||
meanDesc.Describe(ch) | ||
stddevDesc.Describe(ch) | ||
ch <- lossDesc | ||
ch <- bestDesc | ||
ch <- worstDesc | ||
ch <- meanDesc | ||
ch <- stddevDesc | ||
ch <- progDesc | ||
} | ||
|
||
|
@@ -54,16 +56,16 @@ func (p *pingCollector) Collect(ch chan<- prometheus.Metric) { | |
|
||
if metrics.PacketsSent > metrics.PacketsLost { | ||
if enableDeprecatedMetrics { | ||
ch <- prometheus.MustNewConstMetric(rttDesc, prometheus.GaugeValue, float64(metrics.Best), append(l, "best")...) | ||
ch <- prometheus.MustNewConstMetric(rttDesc, prometheus.GaugeValue, float64(metrics.Worst), append(l, "worst")...) | ||
ch <- prometheus.MustNewConstMetric(rttDesc, prometheus.GaugeValue, float64(metrics.Mean), append(l, "mean")...) | ||
ch <- prometheus.MustNewConstMetric(rttDesc, prometheus.GaugeValue, float64(metrics.StdDev), append(l, "std_dev")...) | ||
rttDesc.Collect(ch, metrics.Best, append(l, "best")...) | ||
rttDesc.Collect(ch, metrics.Worst, append(l, "worst")...) | ||
rttDesc.Collect(ch, metrics.Mean, append(l, "mean")...) | ||
rttDesc.Collect(ch, metrics.StdDev, append(l, "std_dev")...) | ||
} | ||
|
||
ch <- prometheus.MustNewConstMetric(bestDesc, prometheus.GaugeValue, float64(metrics.Best), l...) | ||
ch <- prometheus.MustNewConstMetric(worstDesc, prometheus.GaugeValue, float64(metrics.Worst), l...) | ||
ch <- prometheus.MustNewConstMetric(meanDesc, prometheus.GaugeValue, float64(metrics.Mean), l...) | ||
ch <- prometheus.MustNewConstMetric(stddevDesc, prometheus.GaugeValue, float64(metrics.StdDev), l...) | ||
bestDesc.Collect(ch, metrics.Best, l...) | ||
worstDesc.Collect(ch, metrics.Worst, l...) | ||
meanDesc.Collect(ch, metrics.Mean, l...) | ||
stddevDesc.Collect(ch, metrics.StdDev, l...) | ||
} | ||
|
||
loss := float64(metrics.PacketsLost) / float64(metrics.PacketsSent) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
type rttUnit int | ||
|
||
const ( | ||
rttInvalid rttUnit = iota | ||
rttInMills | ||
rttInSeconds | ||
rttBoth | ||
) | ||
|
||
func rttUnitFromString(s string) rttUnit { | ||
switch s { | ||
case "s": | ||
return rttInSeconds | ||
case "ms": | ||
return rttInMills | ||
case "both": | ||
return rttBoth | ||
default: | ||
return rttInvalid | ||
} | ||
} | ||
|
||
type scaledMetrics struct { | ||
Millis *prometheus.Desc | ||
Seconds *prometheus.Desc | ||
} | ||
|
||
func (s *scaledMetrics) Describe(ch chan<- *prometheus.Desc) { | ||
if rttMetricsScale == rttInMills || rttMetricsScale == rttBoth { | ||
ch <- s.Millis | ||
} | ||
if rttMetricsScale == rttInSeconds || rttMetricsScale == rttBoth { | ||
ch <- s.Seconds | ||
} | ||
} | ||
|
||
func (s *scaledMetrics) Collect(ch chan<- prometheus.Metric, value float32, labelValues ...string) { | ||
if rttMetricsScale == rttInMills || rttMetricsScale == rttBoth { | ||
ch <- prometheus.MustNewConstMetric(s.Millis, prometheus.GaugeValue, float64(value), labelValues...) | ||
} | ||
if rttMetricsScale == rttInSeconds || rttMetricsScale == rttBoth { | ||
ch <- prometheus.MustNewConstMetric(s.Seconds, prometheus.GaugeValue, float64(value)/1000, labelValues...) | ||
} | ||
} | ||
|
||
func newScaledDesc(name, help string, variableLabels []string) scaledMetrics { | ||
return scaledMetrics{ | ||
Millis: newDesc(name+"_ms", help+" in millis (deprecated)", variableLabels, nil), | ||
Seconds: newDesc(name+"_seconds", help+" in seconds", variableLabels, nil), | ||
} | ||
} |
Is this no longer deprecated, or was that part removed by mistake?