feat(sonarr): add series tag metrics (#405)

This commit is contained in:
Gavin McFall 2025-12-10 02:15:32 +13:00 committed by GitHub
parent 32206e0195
commit f4282b23cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 71 additions and 0 deletions

View File

@ -19,6 +19,7 @@ type sonarrCollector struct {
seriesMonitoredMetric *prometheus.Desc // Total number of monitored series
seriesUnmonitoredMetric *prometheus.Desc // Total number of unmonitored series
seriesFileSizeMetric *prometheus.Desc // Total fizesize of all series in bytes
seriesTagsMetric *prometheus.Desc // Total number of series by tag
seasonMetric *prometheus.Desc // Total number of seasons
seasonDownloadedMetric *prometheus.Desc // Total number of downloaded seasons
seasonMonitoredMetric *prometheus.Desc // Total number of monitored seasons
@ -66,6 +67,12 @@ func NewSonarrCollector(conf *config.ArrConfig) *sonarrCollector {
nil,
prometheus.Labels{"url": conf.URL},
),
seriesTagsMetric: prometheus.NewDesc(
"sonarr_series_tag_total",
"Total number of downloaded series by tag",
[]string{"tag"},
prometheus.Labels{"url": conf.URL},
),
seasonMetric: prometheus.NewDesc(
"sonarr_season_total",
"Total number of seasons",
@ -147,6 +154,7 @@ func (collector *sonarrCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- collector.seriesMonitoredMetric
ch <- collector.seriesUnmonitoredMetric
ch <- collector.seriesFileSizeMetric
ch <- collector.seriesTagsMetric
ch <- collector.seasonMetric
ch <- collector.seasonDownloadedMetric
ch <- collector.seasonMonitoredMetric
@ -305,11 +313,25 @@ func (collector *sonarrCollector) Collect(ch chan<- prometheus.Metric) {
return
}
// Get tag details for series
tagObjects := model.TagSeries{}
if err := c.DoRequest("tag/detail", &tagObjects); err != nil {
log.Errorw("Error getting tags",
"error", err)
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
return
}
ch <- prometheus.MustNewConstMetric(collector.seriesMetric, prometheus.GaugeValue, float64(len(series)))
ch <- prometheus.MustNewConstMetric(collector.seriesDownloadedMetric, prometheus.GaugeValue, float64(seriesDownloaded))
ch <- prometheus.MustNewConstMetric(collector.seriesMonitoredMetric, prometheus.GaugeValue, float64(seriesMonitored))
ch <- prometheus.MustNewConstMetric(collector.seriesUnmonitoredMetric, prometheus.GaugeValue, float64(seriesUnmonitored))
ch <- prometheus.MustNewConstMetric(collector.seriesFileSizeMetric, prometheus.GaugeValue, float64(seriesFileSize))
for _, tag := range tagObjects {
ch <- prometheus.MustNewConstMetric(collector.seriesTagsMetric, prometheus.GaugeValue, float64(len(tag.SeriesIds)),
tag.Label,
)
}
ch <- prometheus.MustNewConstMetric(collector.seasonMetric, prometheus.GaugeValue, float64(seasons))
ch <- prometheus.MustNewConstMetric(collector.seasonDownloadedMetric, prometheus.GaugeValue, float64(seasonsDownloaded))
ch <- prometheus.MustNewConstMetric(collector.seasonMonitoredMetric, prometheus.GaugeValue, float64(seasonsMonitored))

View File

@ -70,3 +70,11 @@ type Episode []struct {
HasFile bool `json:"hasFile"`
Monitored bool `json:"monitored"`
}
// TagSeries - Stores struct of JSON response for tag details
// https://sonarr.tv/docs/api/#/TagDetails/get_api_v3_tag_detail
type TagSeries []struct {
ID int `json:"id"`
Label string `json:"label"`
SeriesIds []int `json:"seriesIds"`
}

View File

@ -28,6 +28,10 @@ sonarr_series_downloaded_total{url="SOMEURL"} 5
# HELP sonarr_series_filesize_bytes Total fizesize of all series in bytes
# TYPE sonarr_series_filesize_bytes gauge
sonarr_series_filesize_bytes{url="SOMEURL"} 7.91293980833e+11
# HELP sonarr_series_tag_total Total number of downloaded series by tag
# TYPE sonarr_series_tag_total gauge
sonarr_series_tag_total{tag="comedy",url="SOMEURL"} 3
sonarr_series_tag_total{tag="drama",url="SOMEURL"} 2
# HELP sonarr_series_monitored_total Total number of monitored series
# TYPE sonarr_series_monitored_total gauge
sonarr_series_monitored_total{url="SOMEURL"} 5

View File

@ -38,6 +38,10 @@ sonarr_series_downloaded_total{url="SOMEURL"} 5
# HELP sonarr_series_filesize_bytes Total fizesize of all series in bytes
# TYPE sonarr_series_filesize_bytes gauge
sonarr_series_filesize_bytes{url="SOMEURL"} 7.91293980833e+11
# HELP sonarr_series_tag_total Total number of downloaded series by tag
# TYPE sonarr_series_tag_total gauge
sonarr_series_tag_total{tag="comedy",url="SOMEURL"} 3
sonarr_series_tag_total{tag="drama",url="SOMEURL"} 2
# HELP sonarr_series_monitored_total Total number of monitored series
# TYPE sonarr_series_monitored_total gauge
sonarr_series_monitored_total{url="SOMEURL"} 5

View File

@ -0,0 +1,33 @@
[
{
"label": "comedy",
"delayProfileIds": [],
"importListIds": [],
"notificationIds": [],
"restrictionIds": [],
"indexerIds": [],
"downloadClientIds": [],
"autoTagIds": [],
"seriesIds": [
37,
21,
46
],
"id": 14
},
{
"label": "drama",
"delayProfileIds": [],
"importListIds": [],
"notificationIds": [],
"restrictionIds": [],
"indexerIds": [],
"downloadClientIds": [],
"autoTagIds": [],
"seriesIds": [
371,
464
],
"id": 196
}
]