Skip to content

Commit

Permalink
fix: bps
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
caarlos0 committed Apr 6, 2021
1 parent 2b8b7f8 commit 7cdaf68
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions collector/speedtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,73 +18,72 @@ type speedtestCollector struct {
mutex sync.Mutex
cache *cache.Cache

up *prometheus.Desc
scrapeDuration *prometheus.Desc
latencySeconds *prometheus.Desc
jitterSeconds *prometheus.Desc
downloadSpeedBytes *prometheus.Desc
uploadSpeedBytes *prometheus.Desc
downloadedBytes *prometheus.Desc
uploadedBytes *prometheus.Desc
packetLossPct *prometheus.Desc
up *prometheus.Desc
scrapeDuration *prometheus.Desc
latencySeconds *prometheus.Desc
jitterSeconds *prometheus.Desc
downloadBps *prometheus.Desc
uploadBps *prometheus.Desc
downloadedBytes *prometheus.Desc
uploadedBytes *prometheus.Desc
packetLossPct *prometheus.Desc
}

// NewSpeedtestCollector returns a releases collector
func NewSpeedtestCollector(cache *cache.Cache) prometheus.Collector {
const namespace = "speedtest"
const subsystem = ""
return &speedtestCollector{
cache: cache,
up: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "up"),
prometheus.BuildFQName(namespace, "", "up"),
"Exporter is being able to talk with GitHub API",
nil,
nil,
),
scrapeDuration: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "scrape_duration_seconds"),
prometheus.BuildFQName(namespace, "", "scrape_duration_seconds"),
"Returns how long the probe took to complete in seconds",
nil,
nil,
),
latencySeconds: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "ping_latency_seconds"),
prometheus.BuildFQName(namespace, "ping", "latency_seconds"),
"Ping latency",
nil,
nil,
),
jitterSeconds: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "ping_jitter_seconds"),
prometheus.BuildFQName(namespace, "ping", "jitter_seconds"),
"Ping jitter",
nil,
nil,
),
downloadSpeedBytes: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "download_speed_bytes"),
downloadBps: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "download", "bps"),
"Download speed",
nil,
nil,
),
uploadSpeedBytes: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "upload_speed_bytes"),
uploadBps: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "upload", "bps"),
"Upload speed",
nil,
nil,
),
downloadedBytes: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "downloaded_bytes"),
prometheus.BuildFQName(namespace, "download", "bytes"),
"Downloaded bytes",
nil,
nil,
),
uploadedBytes: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "uploaded_bytes"),
prometheus.BuildFQName(namespace, "upload", "bytes"),
"Uploaded bytes",
nil,
nil,
),
packetLossPct: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "packet_loss_pct"),
prometheus.BuildFQName(namespace, "", "packet_loss_pct"),
"Packet loss percentage",
nil,
nil,
Expand All @@ -98,8 +97,8 @@ func (c *speedtestCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.scrapeDuration
ch <- c.latencySeconds
ch <- c.jitterSeconds
ch <- c.downloadSpeedBytes
ch <- c.uploadSpeedBytes
ch <- c.downloadBps
ch <- c.uploadBps
ch <- c.downloadedBytes
ch <- c.uploadedBytes
ch <- c.packetLossPct
Expand All @@ -123,8 +122,8 @@ func (c *speedtestCollector) Collect(ch chan<- prometheus.Metric) {
log.Errorf("failed to collect: %s", err.Error())
}

ch <- prometheus.MustNewConstMetric(c.downloadSpeedBytes, prometheus.GaugeValue, result.Download.Bandwidth)
ch <- prometheus.MustNewConstMetric(c.uploadSpeedBytes, prometheus.GaugeValue, result.Upload.Bandwidth)
ch <- prometheus.MustNewConstMetric(c.downloadBps, prometheus.GaugeValue, result.Download.Bandwidth)
ch <- prometheus.MustNewConstMetric(c.uploadBps, prometheus.GaugeValue, result.Upload.Bandwidth)
ch <- prometheus.MustNewConstMetric(c.latencySeconds, prometheus.GaugeValue, result.Ping.Latency/1000)
ch <- prometheus.MustNewConstMetric(c.jitterSeconds, prometheus.GaugeValue, result.Ping.Jitter/1000)
ch <- prometheus.MustNewConstMetric(c.uploadedBytes, prometheus.GaugeValue, result.Download.Bytes)
Expand Down

0 comments on commit 7cdaf68

Please sign in to comment.