Skip to content

Commit

Permalink
feat: packet loss
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Apr 6, 2021
1 parent dfe72ef commit 2b8b7f8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion collector/speedtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type speedtestCollector struct {
uploadSpeedBytes *prometheus.Desc
downloadedBytes *prometheus.Desc
uploadedBytes *prometheus.Desc
packetLossPct *prometheus.Desc
}

// NewSpeedtestCollector returns a releases collector
Expand Down Expand Up @@ -82,6 +83,12 @@ func NewSpeedtestCollector(cache *cache.Cache) prometheus.Collector {
nil,
nil,
),
packetLossPct: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "packet_loss_pct"),
"Packet loss percentage",
nil,
nil,
),
}
}

Expand All @@ -95,6 +102,7 @@ func (c *speedtestCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.uploadSpeedBytes
ch <- c.downloadedBytes
ch <- c.uploadedBytes
ch <- c.packetLossPct
}

// Collect all metrics
Expand All @@ -121,6 +129,7 @@ func (c *speedtestCollector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(c.jitterSeconds, prometheus.GaugeValue, result.Ping.Jitter/1000)
ch <- prometheus.MustNewConstMetric(c.uploadedBytes, prometheus.GaugeValue, result.Download.Bytes)
ch <- prometheus.MustNewConstMetric(c.downloadedBytes, prometheus.GaugeValue, result.Upload.Bytes)
ch <- prometheus.MustNewConstMetric(c.packetLossPct, prometheus.GaugeValue, result.PacketLoss)
}

func (c *speedtestCollector) cachedOrCollect() (SpeedtestResult, error) {
Expand Down Expand Up @@ -162,7 +171,7 @@ type SpeedtestResult struct {
Ping Ping `json:"ping"`
Download Download `json:"download"`
Upload Upload `json:"upload"`
PacketLoss int `json:"packetLoss"`
PacketLoss float64 `json:"packetLoss"`
Isp string `json:"isp"`
Interface Interface `json:"interface"`
Server Server `json:"server"`
Expand Down

0 comments on commit 2b8b7f8

Please sign in to comment.