-
Notifications
You must be signed in to change notification settings - Fork 19
/
traceroute.go
47 lines (37 loc) · 1.13 KB
/
traceroute.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-License-Identifier: LGPL-3.0-or-later
package traceroute
import (
"github.com/DNS-OARC/ripeatlas/measurement"
"github.com/czerwonk/atlas_exporter/config"
"github.com/czerwonk/atlas_exporter/exporter"
)
const (
ns = "atlas"
sub = "traceroute"
)
// NewMeasurement returns a new instance of `exorter.Measurement` for a traceroute measurement
func NewMeasurement(id, ipVersion string, cfg *config.Config) *exporter.Measurement {
opts := []exporter.MeasurementOpt{
exporter.WithHistograms(newRttHistogram(id, ipVersion, cfg.HistogramBuckets.Traceroute.Rtt)),
}
if cfg.FilterInvalidResults {
opts = append(opts, exporter.WithValidator(&tracerouteResultValidator{}))
}
return exporter.NewMeasurement(&tracerouteExporter{id}, opts...)
}
func processLastHop(r *measurement.Result) (success float64, rtt float64) {
if len(r.TracerouteResults()) == 0 {
return success, rtt
}
last := r.TracerouteResults()[len(r.TracerouteResults())-1]
for _, rep := range last.Replies() {
if rep.From() == r.DstAddr() {
success = 1
}
repl := last.Replies()
if len(repl) > 0 {
rtt = repl[len(repl)-1].Rtt()
}
}
return success, rtt
}