Skip to content

Commit

Permalink
Add newrelic_scrape_duration_seconds metric
Browse files Browse the repository at this point in the history
  • Loading branch information
diogonicoleti committed Nov 30, 2017
1 parent 151be34 commit 551caee
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package collector

import (
"sync"
"time"

"github.com/ContaAzul/newrelic_exporter/newrelic"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -14,7 +15,8 @@ type newRelicCollector struct {
mutex sync.RWMutex
client *newrelic.Client

up *prometheus.Desc
up *prometheus.Desc
scrapeDuration *prometheus.Desc
}

// NewNewRelicCollector returns a prometheus collector which exports
Expand All @@ -28,6 +30,12 @@ func NewNewRelicCollector(apiKey string) prometheus.Collector {
nil,
nil,
),
scrapeDuration: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "scrape_duration_seconds"),
"Time NewRelic scrape took in seconds",
nil,
nil,
),
}
}

Expand All @@ -44,6 +52,7 @@ func (c *newRelicCollector) Collect(ch chan<- prometheus.Metric) {
c.mutex.Lock()
defer c.mutex.Unlock()

start := time.Now()
//TODO: Use correct application ID to scrape data
_, err := c.client.ListInstances(0)
if err != nil {
Expand All @@ -53,4 +62,8 @@ func (c *newRelicCollector) Collect(ch chan<- prometheus.Metric) {
}

ch <- prometheus.MustNewConstMetric(c.up, prometheus.GaugeValue, 1)
ch <- prometheus.MustNewConstMetric(
c.scrapeDuration,
prometheus.GaugeValue,
float64(time.Since(start).Seconds()))
}

0 comments on commit 551caee

Please sign in to comment.