mirror of
https://github.com/onedr0p/exportarr.git
synced 2026-02-06 10:57:32 +00:00
[Refactor] (2/2) Convert remaining collector Fatals to InvalidMetrics (#107)
This commit is contained in:
parent
72a913e175
commit
5abd638cbf
3
go.sum
3
go.sum
@ -202,14 +202,11 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/urfave/cli/v2 v2.11.1 h1:UKK6SP7fV3eKOefbS87iT9YHefv7iB/53ih6e+GNAsE=
|
||||
github.com/urfave/cli/v2 v2.11.1/go.mod h1:f8iq5LtQ/bLxafbdBSLPPNsgaW0l/2fYYEHhAyPlwvo=
|
||||
github.com/urfave/cli/v2 v2.25.0 h1:ykdZKuQey2zq0yin/l7JOm9Mh+pg72ngYMeB0ABn6q8=
|
||||
github.com/urfave/cli/v2 v2.25.0/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
||||
|
||||
@ -25,6 +25,7 @@ type lidarrCollector struct {
|
||||
songsDownloadedMetric *prometheus.Desc // Total number of downloaded songs
|
||||
songsMissingMetric *prometheus.Desc // Total number of missing songs
|
||||
songsQualitiesMetric *prometheus.Desc // Total number of songs by quality
|
||||
errorMetric *prometheus.Desc // Error Description for use with InvalidMetric
|
||||
}
|
||||
|
||||
func NewLidarrCollector(c *cli.Context, cf *model.Config) *lidarrCollector {
|
||||
@ -103,6 +104,12 @@ func NewLidarrCollector(c *cli.Context, cf *model.Config) *lidarrCollector {
|
||||
[]string{"quality"},
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
errorMetric: prometheus.NewDesc(
|
||||
"lidarr_collector_error",
|
||||
"Error while collecting metrics",
|
||||
nil,
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,14 +131,8 @@ func (collector *lidarrCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
func (collector *lidarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
c, err := client.NewClient(collector.config, collector.configFile)
|
||||
if err != nil {
|
||||
log.Errorf("Error creating client: %w", err)
|
||||
ch <- prometheus.NewInvalidMetric(
|
||||
prometheus.NewDesc(
|
||||
"lidarr_collector_error",
|
||||
"Error Collecting from Lidarr",
|
||||
nil,
|
||||
prometheus.Labels{"url": collector.config.String("url")}),
|
||||
err)
|
||||
log.Errorf("Error creating client: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
var artistsFileSize int64
|
||||
@ -148,7 +149,9 @@ func (collector *lidarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
|
||||
artists := model.Artist{}
|
||||
if err := c.DoRequest("artist", &artists); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error creating client: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, s := range artists {
|
||||
@ -168,7 +171,9 @@ func (collector *lidarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
songFile := model.SongFile{}
|
||||
params := map[string]string{"artistid": fmt.Sprintf("%d", s.Id)}
|
||||
if err := c.DoRequest("trackfile", &songFile, params); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error getting trackfile: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
for _, e := range songFile {
|
||||
if e.Quality.Quality.Name != "" {
|
||||
@ -179,7 +184,9 @@ func (collector *lidarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
album := model.Album{}
|
||||
params = map[string]string{"artistid": fmt.Sprintf("%d", s.Id)}
|
||||
if err := c.DoRequest("album", &album, params); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error getting album: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
for _, a := range album {
|
||||
if a.Monitored {
|
||||
@ -194,7 +201,9 @@ func (collector *lidarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
|
||||
songMissing := model.Missing{}
|
||||
if err := c.DoRequest("wanted/missing", &songMissing); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error getting missing: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(collector.artistsMetric, prometheus.GaugeValue, float64(len(artists)))
|
||||
|
||||
@ -112,6 +112,8 @@ type prowlarrCollector struct {
|
||||
userAgentMetric *prometheus.Desc // Total number of active user agents
|
||||
userAgentQueriesMetric *prometheus.Desc // Total number of queries
|
||||
userAgentGrabsMetric *prometheus.Desc // Total number of grabs
|
||||
errorMetric *prometheus.Desc // Error Description for use with InvalidMetric
|
||||
|
||||
}
|
||||
|
||||
func NewProwlarrCollector(c *cli.Context, cf *model.Config) *prowlarrCollector {
|
||||
@ -218,6 +220,12 @@ func NewProwlarrCollector(c *cli.Context, cf *model.Config) *prowlarrCollector {
|
||||
[]string{"user_agent"},
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
errorMetric: prometheus.NewDesc(
|
||||
"prowlarr_collector_error",
|
||||
"Error while collecting metrics",
|
||||
nil,
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,14 +249,8 @@ func (collector *prowlarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
total := time.Now()
|
||||
c, err := client.NewClient(collector.config, collector.configFile)
|
||||
if err != nil {
|
||||
log.Errorf("Error creating client: %w", err)
|
||||
ch <- prometheus.NewInvalidMetric(
|
||||
prometheus.NewDesc(
|
||||
"prowlarr_collector_error",
|
||||
"Error Collecting from Prowlarr",
|
||||
nil,
|
||||
prometheus.Labels{"url": collector.config.String("url")}),
|
||||
err)
|
||||
log.Errorf("Error creating client: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -256,7 +258,9 @@ func (collector *prowlarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
|
||||
indexers := model.Indexer{}
|
||||
if err := c.DoRequest("indexer", &indexers); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error getting indexers: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
for _, indexer := range indexers {
|
||||
if indexer.Enabled {
|
||||
@ -267,7 +271,9 @@ func (collector *prowlarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
if field.Name == "vipExpiration" && field.Value != "" {
|
||||
t, err := time.Parse("2006-01-02", field.Value.(string))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Couldn't parse VIP Expiration: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
expirationSeconds := t.Unix() - time.Now().Unix()
|
||||
ch <- prometheus.MustNewConstMetric(collector.indexerVipExpirationMetric, prometheus.GaugeValue, float64(expirationSeconds), indexer.Name)
|
||||
@ -283,7 +289,9 @@ func (collector *prowlarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
"endDate": endDate.Format(time.RFC3339),
|
||||
}
|
||||
if err := c.DoRequest("indexerstats", &stats, params); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error getting indexer stats: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
collector.lastStatUpdate = endDate
|
||||
|
||||
@ -316,7 +324,7 @@ func (collector *prowlarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
ch <- prometheus.MustNewConstMetric(collector.userAgentMetric, prometheus.GaugeValue, float64(len(stats.UserAgents)))
|
||||
ch <- prometheus.MustNewConstMetric(collector.indexerEnabledMetric, prometheus.GaugeValue, float64(enabledIndexers))
|
||||
|
||||
log.Debug("TIME :: total took %s ",
|
||||
time.Since(total),
|
||||
log.Debugf("TIME :: total took %s ",
|
||||
time.Since(total).String(),
|
||||
)
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@ type radarrCollector struct {
|
||||
movieMissingMetric *prometheus.Desc // Total number of missing movies
|
||||
movieQualitiesMetric *prometheus.Desc // Total number of movies by quality
|
||||
movieFileSizeMetric *prometheus.Desc // Total fizesize of all movies in bytes
|
||||
errorMetric *prometheus.Desc // Error Description for use with InvalidMetric
|
||||
}
|
||||
|
||||
func NewRadarrCollector(c *cli.Context, cf *model.Config) *radarrCollector {
|
||||
@ -73,6 +74,12 @@ func NewRadarrCollector(c *cli.Context, cf *model.Config) *radarrCollector {
|
||||
[]string{"quality"},
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
errorMetric: prometheus.NewDesc(
|
||||
"radarr_collector_error",
|
||||
"Error while collecting metrics",
|
||||
nil,
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,14 +97,8 @@ func (collector *radarrCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
func (collector *radarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
c, err := client.NewClient(collector.config, collector.configFile)
|
||||
if err != nil {
|
||||
log.Errorf("Error creating client: %w", err)
|
||||
ch <- prometheus.NewInvalidMetric(
|
||||
prometheus.NewDesc(
|
||||
"radarr_collector_error",
|
||||
"Error Collecting from Radarr",
|
||||
nil,
|
||||
prometheus.Labels{"url": collector.config.String("url")}),
|
||||
err)
|
||||
log.Errorf("Error creating client: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
var fileSize int64
|
||||
@ -112,7 +113,9 @@ func (collector *radarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
movies := model.Movie{}
|
||||
// https://radarr.video/docs/api/#/Movie/get_api_v3_movie
|
||||
if err := c.DoRequest("movie", &movies); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error getting movies: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
for _, s := range movies {
|
||||
if s.HasFile {
|
||||
|
||||
@ -24,6 +24,7 @@ type readarrCollector struct {
|
||||
bookMonitoredMetric *prometheus.Desc // Total number of monitored books
|
||||
bookUnmonitoredMetric *prometheus.Desc // Total number of unmonitored books
|
||||
bookMissingMetric *prometheus.Desc // Total number of missing books
|
||||
errorMetric *prometheus.Desc // Error Description for use with InvalidMetric
|
||||
}
|
||||
|
||||
func NewReadarrCollector(c *cli.Context, cf *model.Config) *readarrCollector {
|
||||
@ -96,6 +97,12 @@ func NewReadarrCollector(c *cli.Context, cf *model.Config) *readarrCollector {
|
||||
nil,
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
errorMetric: prometheus.NewDesc(
|
||||
"readarr_collector_error",
|
||||
"Error while collecting metrics",
|
||||
nil,
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,14 +123,8 @@ func (collector *readarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
total := time.Now()
|
||||
c, err := client.NewClient(collector.config, collector.configFile)
|
||||
if err != nil {
|
||||
log.Errorf("Error creating client: %w", err)
|
||||
ch <- prometheus.NewInvalidMetric(
|
||||
prometheus.NewDesc(
|
||||
"readarr_collector_error",
|
||||
"Error Collecting from Readarr",
|
||||
nil,
|
||||
prometheus.Labels{"url": collector.config.String("url")}),
|
||||
err)
|
||||
log.Errorf("Error creating client: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
tauthors := []time.Duration{}
|
||||
@ -142,7 +143,9 @@ func (collector *readarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
|
||||
authors := model.Author{}
|
||||
if err := c.DoRequest("author", &authors); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error getting authors: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, a := range authors {
|
||||
@ -163,12 +166,14 @@ func (collector *readarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
}
|
||||
b := time.Since(tauthor)
|
||||
tauthors = append(tauthors, b)
|
||||
log.Debug("TIME :: author %s took %s", a.AuthorName, b)
|
||||
log.Debugf("TIME :: author %s took %s", a.AuthorName, b)
|
||||
}
|
||||
|
||||
books := model.Book{}
|
||||
if err := c.DoRequest("book", &books); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error getting books: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
for _, b := range books {
|
||||
if !b.Monitored {
|
||||
@ -196,7 +201,7 @@ func (collector *readarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
ch <- prometheus.MustNewConstMetric(collector.bookUnmonitoredMetric, prometheus.GaugeValue, float64(booksUnmonitored))
|
||||
ch <- prometheus.MustNewConstMetric(collector.bookMissingMetric, prometheus.GaugeValue, float64(booksMissing))
|
||||
|
||||
log.Debug("TIME :: total took %s with author timings as %s",
|
||||
log.Debugf("TIME :: total took %s with author timings as %s",
|
||||
time.Since(total),
|
||||
tauthors,
|
||||
)
|
||||
|
||||
@ -14,6 +14,7 @@ type systemHealthCollector struct {
|
||||
config *cli.Context // App configuration
|
||||
configFile *model.Config // *arr configuration from config.xml
|
||||
systemHealthMetric *prometheus.Desc // Total number of health issues
|
||||
errorMetric *prometheus.Desc // Error Description for use with InvalidMetric
|
||||
}
|
||||
|
||||
func NewSystemHealthCollector(c *cli.Context, cf *model.Config) *systemHealthCollector {
|
||||
@ -26,6 +27,12 @@ func NewSystemHealthCollector(c *cli.Context, cf *model.Config) *systemHealthCol
|
||||
[]string{"source", "type", "message", "wikiurl"},
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
errorMetric: prometheus.NewDesc(
|
||||
fmt.Sprintf("%s_health_collector_error", c.Command.Name),
|
||||
"Error while collecting metrics",
|
||||
nil,
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,19 +43,15 @@ func (collector *systemHealthCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
func (collector *systemHealthCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
c, err := client.NewClient(collector.config, collector.configFile)
|
||||
if err != nil {
|
||||
log.Errorf("Error creating client: %w", err)
|
||||
ch <- prometheus.NewInvalidMetric(
|
||||
prometheus.NewDesc(
|
||||
fmt.Sprintf("%s_collector_error", collector.config.Command.Name),
|
||||
"Error Collecting metrics",
|
||||
nil,
|
||||
prometheus.Labels{"url": collector.config.String("url")}),
|
||||
err)
|
||||
log.Errorf("Error creating client: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
systemHealth := model.SystemHealth{}
|
||||
if err := c.DoRequest("health", &systemHealth); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error getting health: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
// Group metrics by source, type, message and wikiurl
|
||||
if len(systemHealth) > 0 {
|
||||
|
||||
@ -14,6 +14,7 @@ type historyCollector struct {
|
||||
config *cli.Context // App configuration
|
||||
configFile *model.Config // *arr configuration from config.xml
|
||||
historyMetric *prometheus.Desc // Total number of history items
|
||||
errorMetric *prometheus.Desc // Error Description for use with InvalidMetric
|
||||
}
|
||||
|
||||
func NewHistoryCollector(c *cli.Context, cf *model.Config) *historyCollector {
|
||||
@ -26,6 +27,12 @@ func NewHistoryCollector(c *cli.Context, cf *model.Config) *historyCollector {
|
||||
nil,
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
errorMetric: prometheus.NewDesc(
|
||||
fmt.Sprintf("%s_history_collector_error", c.Command.Name),
|
||||
"Error while collecting metrics",
|
||||
nil,
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,19 +43,15 @@ func (collector *historyCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
func (collector *historyCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
c, err := client.NewClient(collector.config, collector.configFile)
|
||||
if err != nil {
|
||||
log.Errorf("Error creating client: %w", err)
|
||||
ch <- prometheus.NewInvalidMetric(
|
||||
prometheus.NewDesc(
|
||||
fmt.Sprintf("%s_collector_error", collector.config.Command.Name),
|
||||
"Error Collecting metrics",
|
||||
nil,
|
||||
prometheus.Labels{"url": collector.config.String("url")}),
|
||||
err)
|
||||
log.Errorf("Error creating client: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
history := model.History{}
|
||||
if err := c.DoRequest("history", &history); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error getting history: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
ch <- prometheus.MustNewConstMetric(collector.historyMetric, prometheus.GaugeValue, float64(history.TotalRecords))
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ type queueCollector struct {
|
||||
config *cli.Context // App configuration
|
||||
configFile *model.Config // *arr configuration from config.xml
|
||||
queueMetric *prometheus.Desc // Total number of queue items
|
||||
errorMetric *prometheus.Desc // Error Description for use with InvalidMetric
|
||||
}
|
||||
|
||||
func NewQueueCollector(c *cli.Context, cf *model.Config) *queueCollector {
|
||||
@ -26,6 +27,12 @@ func NewQueueCollector(c *cli.Context, cf *model.Config) *queueCollector {
|
||||
[]string{"status", "download_status", "download_state"},
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
errorMetric: prometheus.NewDesc(
|
||||
fmt.Sprintf("%s_queue_collector_error", c.Command.Name),
|
||||
"Error while collecting metrics",
|
||||
nil,
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,14 +43,8 @@ func (collector *queueCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
func (collector *queueCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
c, err := client.NewClient(collector.config, collector.configFile)
|
||||
if err != nil {
|
||||
log.Errorf("Error creating client: %w", err)
|
||||
ch <- prometheus.NewInvalidMetric(
|
||||
prometheus.NewDesc(
|
||||
fmt.Sprintf("%s_collector_error", collector.config.Command.Name),
|
||||
"Error Collecting metrics",
|
||||
nil,
|
||||
prometheus.Labels{"url": collector.config.String("url")}),
|
||||
err)
|
||||
log.Errorf("Error creating client: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -58,7 +59,9 @@ func (collector *queueCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
|
||||
queue := model.Queue{}
|
||||
if err := c.DoRequest("queue", &queue, params); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error getting queue: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
// Calculate total pages
|
||||
var totalPages = (queue.TotalRecords + queue.PageSize - 1) / queue.PageSize
|
||||
@ -69,7 +72,9 @@ func (collector *queueCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
for page := 2; page <= totalPages; page++ {
|
||||
params["page"] = fmt.Sprintf("%d", page)
|
||||
if err := c.DoRequest("queue", &queue, params); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error getting queue (page %d): %s", page, err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
queueStatusAll = append(queueStatusAll, queue.Records...)
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ type rootFolderCollector struct {
|
||||
config *cli.Context // App configuration
|
||||
configFile *model.Config // *arr configuration from config.xml
|
||||
rootFolderMetric *prometheus.Desc // Total number of root folders
|
||||
errorMetric *prometheus.Desc // Error Description for use with InvalidMetric
|
||||
}
|
||||
|
||||
func NewRootFolderCollector(c *cli.Context, cf *model.Config) *rootFolderCollector {
|
||||
@ -26,6 +27,12 @@ func NewRootFolderCollector(c *cli.Context, cf *model.Config) *rootFolderCollect
|
||||
[]string{"path"},
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
errorMetric: prometheus.NewDesc(
|
||||
fmt.Sprintf("%s_rootfolder_collector_error", c.Command.Name),
|
||||
"Error while collecting metrics",
|
||||
nil,
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,19 +43,15 @@ func (collector *rootFolderCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
func (collector *rootFolderCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
c, err := client.NewClient(collector.config, collector.configFile)
|
||||
if err != nil {
|
||||
log.Errorf("Error creating client: %w", err)
|
||||
ch <- prometheus.NewInvalidMetric(
|
||||
prometheus.NewDesc(
|
||||
fmt.Sprintf("%s_collector_error", collector.config.Command.Name),
|
||||
"Error Collecting metrics",
|
||||
nil,
|
||||
prometheus.Labels{"url": collector.config.String("url")}),
|
||||
err)
|
||||
log.Errorf("Error creating client: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
rootFolders := model.RootFolder{}
|
||||
if err := c.DoRequest("rootfolder", &rootFolders); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error getting rootfolder: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
// Group metrics by path
|
||||
if len(rootFolders) > 0 {
|
||||
|
||||
@ -14,6 +14,7 @@ type systemStatusCollector struct {
|
||||
config *cli.Context // App configuration
|
||||
configFile *model.Config // *arr configuration from config.xml
|
||||
systemStatus *prometheus.Desc // Total number of system statuses
|
||||
errorMetric *prometheus.Desc // Error Description for use with InvalidMetric
|
||||
}
|
||||
|
||||
func NewSystemStatusCollector(c *cli.Context, cf *model.Config) *systemStatusCollector {
|
||||
@ -26,6 +27,12 @@ func NewSystemStatusCollector(c *cli.Context, cf *model.Config) *systemStatusCol
|
||||
nil,
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
errorMetric: prometheus.NewDesc(
|
||||
fmt.Sprintf("%s_status_collector_error", c.Command.Name),
|
||||
"Error while collecting metrics",
|
||||
nil,
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,14 +43,8 @@ func (collector *systemStatusCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
func (collector *systemStatusCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
c, err := client.NewClient(collector.config, collector.configFile)
|
||||
if err != nil {
|
||||
log.Errorf("Error creating client: %w", err)
|
||||
ch <- prometheus.NewInvalidMetric(
|
||||
prometheus.NewDesc(
|
||||
fmt.Sprintf("%s_collector_error", collector.config.Command.Name),
|
||||
"Error Collecting metrics",
|
||||
nil,
|
||||
prometheus.Labels{"url": collector.config.String("url")}),
|
||||
err)
|
||||
log.Errorf("Error creating client: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
systemStatus := model.SystemStatus{}
|
||||
|
||||
@ -29,6 +29,7 @@ type sonarrCollector struct {
|
||||
episodeDownloadedMetric *prometheus.Desc // Total number of downloaded episodes
|
||||
episodeMissingMetric *prometheus.Desc // Total number of missing episodes
|
||||
episodeQualitiesMetric *prometheus.Desc // Total number of episodes by quality
|
||||
errorMetric *prometheus.Desc // Error Description for use with InvalidMetric
|
||||
}
|
||||
|
||||
func NewSonarrCollector(c *cli.Context, cf *model.Config) *sonarrCollector {
|
||||
@ -125,6 +126,12 @@ func NewSonarrCollector(c *cli.Context, cf *model.Config) *sonarrCollector {
|
||||
[]string{"quality"},
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
errorMetric: prometheus.NewDesc(
|
||||
"sonarr_collector_error",
|
||||
"Error while collecting metrics",
|
||||
nil,
|
||||
prometheus.Labels{"url": c.String("url")},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,14 +157,8 @@ func (collector *sonarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
total := time.Now()
|
||||
c, err := client.NewClient(collector.config, collector.configFile)
|
||||
if err != nil {
|
||||
log.Errorf("Error creating client: %w", err)
|
||||
ch <- prometheus.NewInvalidMetric(
|
||||
prometheus.NewDesc(
|
||||
"sonarr_collector_error",
|
||||
"Error Collecting from Lidarr",
|
||||
nil,
|
||||
prometheus.Labels{"url": collector.config.String("url")}),
|
||||
err)
|
||||
log.Errorf("Error creating client: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
var seriesFileSize int64
|
||||
@ -179,7 +180,9 @@ func (collector *sonarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
cseries := []time.Duration{}
|
||||
series := model.Series{}
|
||||
if err := c.DoRequest("series", &series); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error getting series: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, s := range series {
|
||||
@ -217,7 +220,9 @@ func (collector *sonarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
episodeFile := model.EpisodeFile{}
|
||||
params := map[string]string{"seriesId": fmt.Sprintf("%d", s.Id)}
|
||||
if err := c.DoRequest("episodefile", &episodeFile, params); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error getting episodefile: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
for _, e := range episodeFile {
|
||||
if e.Quality.Quality.Name != "" {
|
||||
@ -227,7 +232,9 @@ func (collector *sonarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
|
||||
episode := model.Episode{}
|
||||
if err := c.DoRequest("episode", &episode, params); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error getting episode: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
for _, e := range episode {
|
||||
if !e.Monitored {
|
||||
@ -236,17 +243,19 @@ func (collector *sonarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
episodesMonitored++
|
||||
}
|
||||
}
|
||||
log.Debug("TIME :: Extra options took %s", time.Since(textra))
|
||||
log.Debugf("TIME :: Extra options took %s", time.Since(textra))
|
||||
}
|
||||
e := time.Since(tseries)
|
||||
cseries = append(cseries, e)
|
||||
log.Debug("TIME :: series %s took %s", s.Id, e)
|
||||
log.Debugf("TIME :: series %d took %s", s.Id, e)
|
||||
}
|
||||
|
||||
episodesMissing := model.Missing{}
|
||||
params := map[string]string{"sortKey": "airDateUtc"}
|
||||
if err := c.DoRequest("wanted/missing", &episodesMissing, params); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorf("Error getting missing: %s", err)
|
||||
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
|
||||
return
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(collector.seriesMetric, prometheus.GaugeValue, float64(len(series)))
|
||||
@ -274,7 +283,7 @@ func (collector *sonarrCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
}
|
||||
}
|
||||
}
|
||||
log.Debug("TIME :: total took %s with series timings as %s",
|
||||
log.Debugf("TIME :: total took %s with series timings as %s",
|
||||
time.Since(total),
|
||||
cseries,
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user