Skip to content

Commit

Permalink
Remove deprecated metrics
Browse files Browse the repository at this point in the history
This commit removes the deprecated metrics (as marked as such via 7cd5e4f).
In addition, `-flag.deprecatedMetrics` is removed as it serves no
function any longer.
  • Loading branch information
mgumz committed Oct 31, 2024
1 parent 7a1ee58 commit 3372848
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 36 deletions.
2 changes: 0 additions & 2 deletions cmd/mtr-exporter/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type mteFlags struct {
doPrintVersion bool
doPrintUsage bool
doTimeStampLogs bool
doRenderDeprecatedMetrics bool
}

func newFlags() *mteFlags {
Expand All @@ -29,7 +28,6 @@ func newFlags() *mteFlags {
flag.BoolVar(&mte.doPrintUsage, "version", false, "show version")
flag.BoolVar(&mte.doPrintUsage, "h", false, "show help")
flag.BoolVar(&mte.doTimeStampLogs, "tslogs", false, "use timestamps in logs")
flag.BoolVar(&mte.doTimeStampLogs, "flag.deprecatedMetrics", false, "show deprecated metrics")

return mte
}
1 change: 0 additions & 1 deletion cmd/mtr-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func main() {
}

collector := job.NewCollector()
collector.SetRenderDeprecatedMetrics(mtef.doRenderDeprecatedMetrics)

jobs := job.Jobs{}

Expand Down
14 changes: 1 addition & 13 deletions pkg/job/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,12 @@ func (c *Collector) ServeHTTP(w http.ResponseWriter, r *http.Request) {

l := labels2Prom(labels)

// FIXME: remove deprecated metrics with mtr-exporter:0.4
fmt.Fprintf(w, "mtr_report_duration_seconds{%s} %f %d\n",
l, float64(d)/float64(time.Second), tsMs)

if c.opts.doRenderDeprecatedMetrics {
fmt.Fprintln(w, "# deprecated metric name, use mtr_report_duration_seconds")
fmt.Fprintf(w, "mtr_report_duration_ms_gauge{%s} %d %d\n",
l, d/time.Millisecond, tsMs)
}
fmt.Fprintf(w, "mtr_report_count_hubs{%s} %d %d\n",
l, len(report.Hubs), tsMs)

if c.opts.doRenderDeprecatedMetrics {
fmt.Fprintln(w, "# deprecated metric, use mtr_report_count_hubs")
fmt.Fprintf(w, "mtr_report_count_hubs_gauge{%s} %d %d\n",
l, len(report.Hubs), tsMs)
}

lh := len(report.Hubs) - 1
for i, hub := range report.Hubs {
labels["host"] = hub.Host
Expand All @@ -92,7 +80,7 @@ func (c *Collector) ServeHTTP(w http.ResponseWriter, r *http.Request) {
labels["last"] = "true"
}

hub.WriteMetrics(w, labels2Prom(labels), tsMs, c.opts.doRenderDeprecatedMetrics)
hub.WriteMetrics(w, labels2Prom(labels), tsMs)

delete(labels, "last")
}
Expand Down
21 changes: 1 addition & 20 deletions pkg/mtr/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,17 @@ import (
"io"
)

func (hub *Hub) WriteMetrics(w io.Writer, labels string, ts int64, doRenderDeprecatedMetrics bool) {
func (hub *Hub) WriteMetrics(w io.Writer, labels string, ts int64) {
fmt.Fprintf(w, "mtr_report_snt{%s} %d %d\n", labels, hub.Snt, ts)
fmt.Fprintf(w, "mtr_report_loss{%s} %f %d\n", labels, hub.Loss, ts)
fmt.Fprintf(w, "mtr_report_best{%s} %f %d\n", labels, hub.Best, ts)
fmt.Fprintf(w, "mtr_report_wrst{%s} %f %d\n", labels, hub.Wrst, ts)
fmt.Fprintf(w, "mtr_report_avg{%s} %f %d\n", labels, hub.Avg, ts)
fmt.Fprintf(w, "mtr_report_last{%s} %f %d\n", labels, hub.Last, ts)
fmt.Fprintf(w, "mtr_report_stdev{%s} %f %d\n", labels, hub.StDev, ts)

// FIXME: remove deprecated metrics with mtr-exporter:0.4
if doRenderDeprecatedMetrics {
fmt.Fprintln(w, "# deprecated metric name, use mtr_report_snt")
fmt.Fprintf(w, "mtr_report_snt_gauge{%s} %d %d\n", labels, hub.Snt, ts)
fmt.Fprintln(w, "# deprecated metric name, use mtr_report_loss")
fmt.Fprintf(w, "mtr_report_loss_gauge{%s} %f %d\n", labels, hub.Loss, ts)
fmt.Fprintln(w, "# deprecated metric name, use mtr_report_best")
fmt.Fprintf(w, "mtr_report_best_gauge{%s} %f %d\n", labels, hub.Best, ts)
fmt.Fprintln(w, "# deprecated metric name, use mtr_report_wrst")
fmt.Fprintf(w, "mtr_report_wrst_gauge{%s} %f %d\n", labels, hub.Wrst, ts)
fmt.Fprintln(w, "# deprecated metric name, use mtr_report_avg")
fmt.Fprintf(w, "mtr_report_avg_gauge{%s} %f %d\n", labels, hub.Avg, ts)
fmt.Fprintln(w, "# deprecated metric name, use mtr_report_last")
fmt.Fprintf(w, "mtr_report_last_gauge{%s} %f %d\n", labels, hub.Last, ts)
fmt.Fprintln(w, "# deprecated metric name, use mtr_report_stdev")
fmt.Fprintf(w, "mtr_report_stdev_gauge{%s} %f %d\n", labels, hub.StDev, ts)
}
}

func WriteMetricsHelpType(w io.Writer) {
// FIXME: remove deprecated metrics with mtr-exporter:0.4
fmt.Fprintln(w, "# HELP mtr_report_snt number of packets sent via mtr towards dst-host (see man mtr '-c')")
fmt.Fprintln(w, "# TYPE mtr_report_snt gauge")
fmt.Fprintln(w, "# HELP mtr_report_loss packet loss (percentage) of packets sent in last cycle")
Expand Down

0 comments on commit 3372848

Please sign in to comment.