Skip to content

Commit

Permalink
Add late packets metric (#22)
Browse files Browse the repository at this point in the history
* Add late packets metric

* Rise golang to 1.14
  • Loading branch information
takt authored Jul 17, 2020
1 parent 9f0c352 commit 2ec2df1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ addons:
language: go

go:
- 1.11.1
- 1.14

script:
- mkdir -p $HOME/gopath/src/github.com/exaring/
Expand Down
8 changes: 8 additions & 0 deletions pkg/prober/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package prober

import (
"strings"
"sync/atomic"
"time"

"github.com/exaring/matroschka-prober/pkg/measurement"
Expand Down Expand Up @@ -31,6 +32,7 @@ func (p *Prober) Collect(ch chan<- prometheus.Metric) {
p.collectRTTMin(ch, m)
p.collectRTTMax(ch, m)
p.collectRTTAvg(ch, m)
p.collectLatePackets(ch, m)
}

func (p *Prober) labels() []string {
Expand Down Expand Up @@ -94,6 +96,12 @@ func (p *Prober) collectRTTAvg(ch chan<- prometheus.Metric, m *measurement.Measu
ch <- prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, v, p.labelValues()...)
}

func (p *Prober) collectLatePackets(ch chan<- prometheus.Metric, m *measurement.Measurement) {
desc := prometheus.NewDesc(metricPrefix+"late_packets_total", "Timedout but received packets", p.labels(), nil)
n := atomic.LoadUint64(&p.latePackets)
ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, float64(n), p.labelValues()...)
}

func (p *Prober) lastFinishedMeasurement() int64 {
measurementLengthNS := int64(p.cfg.MeasurementLengthMS) * int64(time.Millisecond)
timeoutNS := int64(p.cfg.TimeoutMS) * int64(time.Millisecond)
Expand Down
1 change: 1 addition & 0 deletions pkg/prober/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Prober struct {
transitProbes *transitProbes // Keeps track of in-flight packets
udpConn udpSocket // Used to receive returning packets
measurements *measurement.MeasurementsDB
latePackets uint64
}

// Config is the configuration of a prober
Expand Down
1 change: 1 addition & 0 deletions pkg/prober/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (p *Prober) receiver() {
rtt := now - pkt.Ts
if p.timedOut(rtt) {
// Probe arrived late. rttTimoutChecker() will clean up after it. So we ignore it from here on
atomic.AddUint64(&p.latePackets, 1)
continue
}

Expand Down

0 comments on commit 2ec2df1

Please sign in to comment.