Skip to content

Commit

Permalink
fix: use correct metric names (#78)
Browse files Browse the repository at this point in the history
* satisfy promql warning on metric name

* Add dl-ul total as new metric, mark orig deprecated

* refactor: name new metric in help message

---------

Co-authored-by: Gregory O'Neill <[email protected]>
  • Loading branch information
thde and gsoneill authored Jun 13, 2024
1 parent 7fed9f4 commit e79ce42
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import (
const namespace = "rtorrent"

var (
rtorrentInfo = prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "info"), "rtorrent info.", []string{"name", "ip"}, nil)
rtorrentUp = prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "up"), "Was the last scrape of rTorrent successful.", nil, nil)
rtorrentDownloaded = prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "downloaded_bytes"), "Total downloaded bytes.", nil, nil)
rtorrentUploaded = prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "uploaded_bytes"), "Total uploaded bytes.", nil, nil)
rtorrentTorrents = prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "torrents_total"), "Torrent count by view.", []string{"view", "label"}, nil)
rtorrentInfo = prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "info"), "rtorrent info.", []string{"name", "ip"}, nil)
rtorrentUp = prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "up"), "Was the last scrape of rTorrent successful.", nil, nil)
rtorrentDownloadedTotal = prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "downloaded_bytes_total"), "Total downloaded bytes", nil, nil)
rtorrentUploadedTotal = prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "uploaded_bytes_total"), "Total uploaded bytes", nil, nil)
rtorrentTorrents = prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "torrents_total"), "Torrent count by view.", []string{"view", "label"}, nil)

rtorrentDownloadedDeprecated = prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "downloaded_bytes"), "DEPRECATED: use downloaded_bytes_total", nil, nil)
rtorrentUploadedDeprecated = prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "uploaded_bytes"), "DEPRECATED: use uploaded_bytes_total", nil, nil)
)

// Exporter returns a prometheus.Collector that gathers rTorrent metrics.
Expand Down Expand Up @@ -62,14 +65,16 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) (up float64) {
return 1

}
ch <- prometheus.MustNewConstMetric(rtorrentDownloaded, prometheus.CounterValue, float64(downloaded))
ch <- prometheus.MustNewConstMetric(rtorrentDownloadedDeprecated, prometheus.CounterValue, float64(downloaded))
ch <- prometheus.MustNewConstMetric(rtorrentDownloadedTotal, prometheus.CounterValue, float64(downloaded))

uploaded, err := e.Client.UpTotal()
if err != nil {
level.Error(e.Logger).Log("msg", "Can't scrape rTorrent", "err", err)
return 1
}
ch <- prometheus.MustNewConstMetric(rtorrentUploaded, prometheus.CounterValue, float64(uploaded))
ch <- prometheus.MustNewConstMetric(rtorrentUploadedDeprecated, prometheus.CounterValue, float64(uploaded))
ch <- prometheus.MustNewConstMetric(rtorrentUploadedTotal, prometheus.CounterValue, float64(uploaded))

for name, view := range map[string]rtorrent.View{
"main": rtorrent.ViewMain,
Expand Down

0 comments on commit e79ce42

Please sign in to comment.