Skip to content

Commit f4282b2

Browse files
authored
feat(sonarr): add series tag metrics (#405)
1 parent 32206e0 commit f4282b2

5 files changed

Lines changed: 71 additions & 0 deletions

File tree

internal/arr/collector/sonarr.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type sonarrCollector struct {
1919
seriesMonitoredMetric *prometheus.Desc // Total number of monitored series
2020
seriesUnmonitoredMetric *prometheus.Desc // Total number of unmonitored series
2121
seriesFileSizeMetric *prometheus.Desc // Total fizesize of all series in bytes
22+
seriesTagsMetric *prometheus.Desc // Total number of series by tag
2223
seasonMetric *prometheus.Desc // Total number of seasons
2324
seasonDownloadedMetric *prometheus.Desc // Total number of downloaded seasons
2425
seasonMonitoredMetric *prometheus.Desc // Total number of monitored seasons
@@ -66,6 +67,12 @@ func NewSonarrCollector(conf *config.ArrConfig) *sonarrCollector {
6667
nil,
6768
prometheus.Labels{"url": conf.URL},
6869
),
70+
seriesTagsMetric: prometheus.NewDesc(
71+
"sonarr_series_tag_total",
72+
"Total number of downloaded series by tag",
73+
[]string{"tag"},
74+
prometheus.Labels{"url": conf.URL},
75+
),
6976
seasonMetric: prometheus.NewDesc(
7077
"sonarr_season_total",
7178
"Total number of seasons",
@@ -147,6 +154,7 @@ func (collector *sonarrCollector) Describe(ch chan<- *prometheus.Desc) {
147154
ch <- collector.seriesMonitoredMetric
148155
ch <- collector.seriesUnmonitoredMetric
149156
ch <- collector.seriesFileSizeMetric
157+
ch <- collector.seriesTagsMetric
150158
ch <- collector.seasonMetric
151159
ch <- collector.seasonDownloadedMetric
152160
ch <- collector.seasonMonitoredMetric
@@ -305,11 +313,25 @@ func (collector *sonarrCollector) Collect(ch chan<- prometheus.Metric) {
305313
return
306314
}
307315

316+
// Get tag details for series
317+
tagObjects := model.TagSeries{}
318+
if err := c.DoRequest("tag/detail", &tagObjects); err != nil {
319+
log.Errorw("Error getting tags",
320+
"error", err)
321+
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
322+
return
323+
}
324+
308325
ch <- prometheus.MustNewConstMetric(collector.seriesMetric, prometheus.GaugeValue, float64(len(series)))
309326
ch <- prometheus.MustNewConstMetric(collector.seriesDownloadedMetric, prometheus.GaugeValue, float64(seriesDownloaded))
310327
ch <- prometheus.MustNewConstMetric(collector.seriesMonitoredMetric, prometheus.GaugeValue, float64(seriesMonitored))
311328
ch <- prometheus.MustNewConstMetric(collector.seriesUnmonitoredMetric, prometheus.GaugeValue, float64(seriesUnmonitored))
312329
ch <- prometheus.MustNewConstMetric(collector.seriesFileSizeMetric, prometheus.GaugeValue, float64(seriesFileSize))
330+
for _, tag := range tagObjects {
331+
ch <- prometheus.MustNewConstMetric(collector.seriesTagsMetric, prometheus.GaugeValue, float64(len(tag.SeriesIds)),
332+
tag.Label,
333+
)
334+
}
313335
ch <- prometheus.MustNewConstMetric(collector.seasonMetric, prometheus.GaugeValue, float64(seasons))
314336
ch <- prometheus.MustNewConstMetric(collector.seasonDownloadedMetric, prometheus.GaugeValue, float64(seasonsDownloaded))
315337
ch <- prometheus.MustNewConstMetric(collector.seasonMonitoredMetric, prometheus.GaugeValue, float64(seasonsMonitored))

internal/arr/model/sonarr.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,11 @@ type Episode []struct {
7070
HasFile bool `json:"hasFile"`
7171
Monitored bool `json:"monitored"`
7272
}
73+
74+
// TagSeries - Stores struct of JSON response for tag details
75+
// https://sonarr.tv/docs/api/#/TagDetails/get_api_v3_tag_detail
76+
type TagSeries []struct {
77+
ID int `json:"id"`
78+
Label string `json:"label"`
79+
SeriesIds []int `json:"seriesIds"`
80+
}

internal/arr/test_fixtures/sonarr/expected_metrics.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ sonarr_series_downloaded_total{url="SOMEURL"} 5
2828
# HELP sonarr_series_filesize_bytes Total fizesize of all series in bytes
2929
# TYPE sonarr_series_filesize_bytes gauge
3030
sonarr_series_filesize_bytes{url="SOMEURL"} 7.91293980833e+11
31+
# HELP sonarr_series_tag_total Total number of downloaded series by tag
32+
# TYPE sonarr_series_tag_total gauge
33+
sonarr_series_tag_total{tag="comedy",url="SOMEURL"} 3
34+
sonarr_series_tag_total{tag="drama",url="SOMEURL"} 2
3135
# HELP sonarr_series_monitored_total Total number of monitored series
3236
# TYPE sonarr_series_monitored_total gauge
3337
sonarr_series_monitored_total{url="SOMEURL"} 5

internal/arr/test_fixtures/sonarr/expected_metrics_extended.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ sonarr_series_downloaded_total{url="SOMEURL"} 5
3838
# HELP sonarr_series_filesize_bytes Total fizesize of all series in bytes
3939
# TYPE sonarr_series_filesize_bytes gauge
4040
sonarr_series_filesize_bytes{url="SOMEURL"} 7.91293980833e+11
41+
# HELP sonarr_series_tag_total Total number of downloaded series by tag
42+
# TYPE sonarr_series_tag_total gauge
43+
sonarr_series_tag_total{tag="comedy",url="SOMEURL"} 3
44+
sonarr_series_tag_total{tag="drama",url="SOMEURL"} 2
4145
# HELP sonarr_series_monitored_total Total number of monitored series
4246
# TYPE sonarr_series_monitored_total gauge
4347
sonarr_series_monitored_total{url="SOMEURL"} 5
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[
2+
{
3+
"label": "comedy",
4+
"delayProfileIds": [],
5+
"importListIds": [],
6+
"notificationIds": [],
7+
"restrictionIds": [],
8+
"indexerIds": [],
9+
"downloadClientIds": [],
10+
"autoTagIds": [],
11+
"seriesIds": [
12+
37,
13+
21,
14+
46
15+
],
16+
"id": 14
17+
},
18+
{
19+
"label": "drama",
20+
"delayProfileIds": [],
21+
"importListIds": [],
22+
"notificationIds": [],
23+
"restrictionIds": [],
24+
"indexerIds": [],
25+
"downloadClientIds": [],
26+
"autoTagIds": [],
27+
"seriesIds": [
28+
371,
29+
464
30+
],
31+
"id": 196
32+
}
33+
]

0 commit comments

Comments
 (0)