From e79ce427fd812cb1e9d1b0e3be0a9180f8e69cca Mon Sep 17 00:00:00 2001 From: Demian Date: Thu, 13 Jun 2024 11:54:19 +0100 Subject: [PATCH] fix: use correct metric names (#78) * 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 --- exporter/exporter.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/exporter/exporter.go b/exporter/exporter.go index 6f6ff35..8396059 100644 --- a/exporter/exporter.go +++ b/exporter/exporter.go @@ -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. @@ -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,