Skip to content
Snippets Groups Projects
Unverified Commit 19a0b6e1 authored by Leijurv's avatar Leijurv
Browse files

more metrics

parent 45bd7776
No related branches found
No related tags found
No related merge requests found
Pipeline #104406 canceled
......@@ -8,3 +8,8 @@ Summary of changes made in this fork:
* Fields for files, peers, and trackers are all removed. **These metrics are no longer exported,** and they are no longer requested as fields in RPC calls. So, **this fork has less functionality**, but it's faster. Those metrics aren't interesting anyway. :)
* New exported metric `uploaded_ever_bytes`. Technically you could compute this by multiplying the ratio by the size, but I would rather just export the actual integer. Transmission will tell you this if you ask, so `uploadedEver` was added to the list of fields requested from its RPC.
* `lastScrapeTimedOut` issue fixed by simply changing datatype in JSON struct from bool to int
* Also added a bunch more exported metrics: `downloaded_ever_bytes`, `peers_connected`, `peers_getting_from_us`, `peers_sending_to_us`
TODO (not implemented yet)
* As per https://github.com/transmission/transmission/blob/main/docs/rpc-spec.md, when using this `recently-active` thing, there is an additional reply called `removed` which is a list of torrents that were removed. I currently ignore this, because I virtually never remove torrents. But just saying, this exporter will not remove torrents, because it doesn't parse this reply. I guess you could restart the exporter after removing torrents?
......@@ -53,7 +53,7 @@ func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Node Exporter</title></head>
<head><title>Transmission Exporter</title></head>
<body>
<h1>Transmission Exporter</h1>
<p><a href="` + c.WebPath + `">Metrics</a></p>
......
......@@ -17,14 +17,18 @@ const (
type TorrentCollector struct {
client *transmission.Client
Status *prometheus.Desc
Added *prometheus.Desc
Finished *prometheus.Desc
Done *prometheus.Desc
Ratio *prometheus.Desc
Download *prometheus.Desc
Upload *prometheus.Desc
UploadedEver *prometheus.Desc
Status *prometheus.Desc
Added *prometheus.Desc
Finished *prometheus.Desc
Done *prometheus.Desc
Ratio *prometheus.Desc
Download *prometheus.Desc
Upload *prometheus.Desc
UploadedEver *prometheus.Desc
DownloadedEver *prometheus.Desc
PeersConnected *prometheus.Desc
PeersGettingFromUs *prometheus.Desc
PeersSendingToUs *prometheus.Desc
recentlyActiveOnly bool
......@@ -82,10 +86,33 @@ func NewTorrentCollector(client *transmission.Client) *TorrentCollector {
[]string{"id", "name"},
nil,
),
UploadedEver: prometheus.NewDesc(
namespace+collectorNamespace+"uploaded_ever_bytes",
"The amount of bytes that have been uploaded from this torrent ever",
"The amount of bytes that have been uploaded from a torrent ever",
[]string{"id", "name"},
nil,
),
DownloadedEver: prometheus.NewDesc(
namespace+collectorNamespace+"downloaded_ever_bytes",
"The amount of bytes that have been downloaded from a torrent ever",
[]string{"id", "name"},
nil,
),
PeersConnected: prometheus.NewDesc(
namespace+collectorNamespace+"peers_connected",
"The quantity of peers connected on a torrent",
[]string{"id", "name"},
nil,
),
PeersGettingFromUs: prometheus.NewDesc(
namespace+collectorNamespace+"peers_getting_from_us",
"The quantity of peers getting pieces of a torrent from us",
[]string{"id", "name"},
nil,
),
PeersSendingToUs: prometheus.NewDesc(
namespace+collectorNamespace+"peers_sending_to_us",
"The quantity of peers sending pieces of a torrent to us",
[]string{"id", "name"},
nil,
),
......@@ -102,6 +129,10 @@ func (tc *TorrentCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- tc.Download
ch <- tc.Upload
ch <- tc.UploadedEver
ch <- tc.DownloadedEver
ch <- tc.PeersConnected
ch <- tc.PeersGettingFromUs
ch <- tc.PeersSendingToUs
}
// Collect implements the prometheus.Collector interface
......@@ -176,12 +207,35 @@ func (tc *TorrentCollector) Collect(ch chan<- prometheus.Metric) {
float64(t.RateUpload),
id, t.Name,
)
ch <- prometheus.MustNewConstMetric(
tc.UploadedEver,
prometheus.GaugeValue,
float64(t.UploadedEver),
id, t.Name,
)
ch <- prometheus.MustNewConstMetric(
tc.DownloadedEver,
prometheus.GaugeValue,
float64(t.DownloadedEver),
id, t.Name,
)
ch <- prometheus.MustNewConstMetric(
tc.PeersConnected,
prometheus.GaugeValue,
float64(t.PeersConnected),
id, t.Name,
)
ch <- prometheus.MustNewConstMetric(
tc.PeersGettingFromUs,
prometheus.GaugeValue,
float64(t.PeersGettingFromUs),
id, t.Name,
)
ch <- prometheus.MustNewConstMetric(
tc.PeersSendingToUs,
prometheus.GaugeValue,
float64(t.PeersSendingToUs),
id, t.Name,
)
}
}
......@@ -27,24 +27,26 @@ type (
// Torrent represents a transmission torrent
Torrent struct {
ID int `json:"id"`
Name string `json:"name"`
Status int `json:"status"`
Added int `json:"addedDate"`
LeftUntilDone int64 `json:"leftUntilDone"`
Eta int `json:"eta"`
UploadRatio float64 `json:"uploadRatio"`
RateDownload int `json:"rateDownload"`
RateUpload int `json:"rateUpload"`
DownloadDir string `json:"downloadDir"`
IsFinished bool `json:"isFinished"`
PercentDone float64 `json:"percentDone"`
SeedRatioMode int `json:"seedRatioMode"`
HashString string `json:"hashString"`
Error int `json:"error"`
ErrorString string `json:"errorString"`
UploadedEver int `json:"uploadedEver"`
ID int `json:"id"`
Name string `json:"name"`
Status int `json:"status"`
Added int64 `json:"addedDate"`
LeftUntilDone int64 `json:"leftUntilDone"`
Eta int `json:"eta"`
UploadRatio float64 `json:"uploadRatio"`
RateDownload int `json:"rateDownload"`
RateUpload int `json:"rateUpload"`
DownloadDir string `json:"downloadDir"`
IsFinished bool `json:"isFinished"`
PercentDone float64 `json:"percentDone"`
HashString string `json:"hashString"`
Error int `json:"error"`
ErrorString string `json:"errorString"`
UploadedEver int64 `json:"uploadedEver"`
DownloadedEver int64 `json:"downloadedEver"`
PeersConnected int `json:"peersConnected"`
PeersGettingFromUs int `json:"peersGettingFromUs"`
PeersSendingToUs int `json:"peersSendingToUs"`
}
// ByID implements the sort Interface to sort by ID
......
......@@ -128,11 +128,13 @@ func (c *Client) GetTorrents(recentlyActiveOnly bool) ([]Torrent, error) {
"downloadDir",
"isFinished",
"percentDone",
"seedRatioMode",
"error",
"errorString",
"uploadedEver",
"downloadedEver",
"peersConnected",
"peersGettingFromUs",
"peersSendingToUs",
},
},
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment