Skip to content

Commit

Permalink
add error and api fetch counters
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall committed May 24, 2023
1 parent 6d43770 commit d301392
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pkg/unpackerr/lidarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ func (u *Unpackerr) getLidarrQueue() {

queue, err := server.GetQueue(DefaultQueuePageSize, DefaultQueuePageSize)
if err != nil {
u.Errorf("Lidarr (%s): %v", server.URL, err)
u.saveQueueMetrics(0, start, starr.Lidarr, server.URL, err)
return
}

// Only update if there was not an error fetching.
server.Queue = queue
u.saveQueueMetrics(server.Queue.TotalRecords, start, starr.Lidarr, server.URL)
u.saveQueueMetrics(server.Queue.TotalRecords, start, starr.Lidarr, server.URL, nil)

if !u.Activity || queue.TotalRecords > 0 {
u.Printf("[Lidarr] Updated (%s): %d Items Queued, %d Retrieved", server.URL, queue.TotalRecords, len(queue.Records))
Expand Down
21 changes: 20 additions & 1 deletion pkg/unpackerr/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

// metrics holds the non-custom Prometheus collector metrics for the app.
type metrics struct {
AppQueueErr *prometheus.CounterVec
AppQueueGet *prometheus.CounterVec
AppQueues *prometheus.GaugeVec
AppRequests *prometheus.GaugeVec
ArchivesRead *prometheus.CounterVec
Expand Down Expand Up @@ -72,11 +74,20 @@ func (u *Unpackerr) updateMetrics(resp *xtractr.Response, app starr.App, url str
}

// saveQueueMetrics observes metrics for each starr app queue request.
func (u *Unpackerr) saveQueueMetrics(size int, start time.Time, app starr.App, url string) {
func (u *Unpackerr) saveQueueMetrics(size int, start time.Time, app starr.App, url string, err error) {
if err != nil {
u.Errorf("%s (%s): %v", app, url, err)
}

if u.metrics == nil {
return
}

if err != nil {
u.metrics.AppQueueErr.WithLabelValues(string(app), url).Inc()
}

u.metrics.AppQueueGet.WithLabelValues(string(app), url).Inc()
u.metrics.AppQueues.WithLabelValues(string(app), url).Set(float64(size))
u.metrics.AppRequests.WithLabelValues(string(app), url).Set(time.Since(start).Seconds())
}
Expand All @@ -91,6 +102,14 @@ func (u *Unpackerr) setupMetrics() {
})

u.metrics = &metrics{
AppQueueErr: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "unpackerr_app_queue_fetch_errors_total",
Help: "Total times the starr activity queue fetch returned an error",
}, []string{"app", "url"}),
AppQueueGet: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "unpackerr_app_queue_fetch_total",
Help: "Total times the starr activity queue was fetched",
}, []string{"app", "url"}),
AppQueues: promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "unpackerr_app_queue_size",
Help: "The total number of items queued in a Starr app",
Expand Down
4 changes: 2 additions & 2 deletions pkg/unpackerr/radarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ func (u *Unpackerr) getRadarrQueue() {

queue, err := server.GetQueue(DefaultQueuePageSize, 1)
if err != nil {
u.Errorf("Radarr (%s): %v", server.URL, err)
u.saveQueueMetrics(0, start, starr.Radarr, server.URL, err)
return
}

// Only update if there was not an error fetching.
server.Queue = queue
u.saveQueueMetrics(server.Queue.TotalRecords, start, starr.Radarr, server.URL)
u.saveQueueMetrics(server.Queue.TotalRecords, start, starr.Radarr, server.URL, nil)

if !u.Activity || queue.TotalRecords > 0 {
u.Printf("[Radarr] Updated (%s): %d Items Queued, %d Retrieved", server.URL, queue.TotalRecords, len(queue.Records))
Expand Down
4 changes: 2 additions & 2 deletions pkg/unpackerr/readarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ func (u *Unpackerr) getReadarrQueue() {

queue, err := server.GetQueue(DefaultQueuePageSize, DefaultQueuePageSize)
if err != nil {
u.Errorf("Readarr (%s): %v", server.URL, err)
u.saveQueueMetrics(0, start, starr.Readarr, server.URL, err)
return
}

// Only update if there was not an error fetching.
server.Queue = queue
u.saveQueueMetrics(server.Queue.TotalRecords, start, starr.Readarr, server.URL)
u.saveQueueMetrics(server.Queue.TotalRecords, start, starr.Readarr, server.URL, nil)

if !u.Activity || queue.TotalRecords > 0 {
u.Printf("[Readarr] Updated (%s): %d Items Queued, %d Retrieved", server.URL, queue.TotalRecords, len(queue.Records))
Expand Down
4 changes: 2 additions & 2 deletions pkg/unpackerr/sonarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ func (u *Unpackerr) getSonarrQueue() {

queue, err := server.GetQueue(DefaultQueuePageSize, 1)
if err != nil {
u.Errorf("Sonarr (%s): %v", server.URL, err)
u.saveQueueMetrics(0, start, starr.Sonarr, server.URL, err)
return
}

// Only update if there was not an error fetching.
server.Queue = queue
u.saveQueueMetrics(server.Queue.TotalRecords, start, starr.Sonarr, server.URL)
u.saveQueueMetrics(server.Queue.TotalRecords, start, starr.Sonarr, server.URL, nil)

if !u.Activity || queue.TotalRecords > 0 {
u.Printf("[Sonarr] Updated (%s): %d Items Queued, %d Retrieved", server.URL, queue.TotalRecords, len(queue.Records))
Expand Down
4 changes: 2 additions & 2 deletions pkg/unpackerr/whisparr.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ func (u *Unpackerr) getWhisparrQueue() {

queue, err := server.GetQueue(DefaultQueuePageSize, 1)
if err != nil {
u.Printf("Whisparr (%s): %v", server.URL, err)
u.saveQueueMetrics(0, start, starr.Whisparr, server.URL, err)
return
}

// Only update if there was not an error fetching.
server.Queue = queue
u.saveQueueMetrics(server.Queue.TotalRecords, start, starr.Whisparr, server.URL)
u.saveQueueMetrics(server.Queue.TotalRecords, start, starr.Whisparr, server.URL, nil)

if !u.Activity || queue.TotalRecords > 0 {
u.Printf("[Whisparr] Updated (%s): %d Items Queued, %d Retrieved",
Expand Down

0 comments on commit d301392

Please sign in to comment.