mirror of
https://github.com/steinhobelgruen/netatmo-exporter.git
synced 2024-11-21 17:03:56 +00:00
Add metric for refresh duration
This commit is contained in:
parent
1eda093550
commit
73f4c697da
|
@ -20,6 +20,10 @@ var (
|
|||
refreshPrefix+"_time",
|
||||
"Contains the time of the last refresh try, successful or not.",
|
||||
nil, nil)
|
||||
refreshDurationDesc = prometheus.NewDesc(
|
||||
refreshPrefix+"_duration_seconds",
|
||||
"Contains the time it took for the last refresh to complete, even if it was unsuccessful.",
|
||||
nil, nil)
|
||||
|
||||
cacheTimestampDesc = prometheus.NewDesc(
|
||||
prefix+"cache_updated_time",
|
||||
|
@ -111,6 +115,7 @@ type NetatmoCollector struct {
|
|||
Client *netatmo.Client
|
||||
lastRefresh time.Time
|
||||
lastRefreshError error
|
||||
lastRefreshDuration time.Duration
|
||||
cacheLock sync.RWMutex
|
||||
cacheTimestamp time.Time
|
||||
cachedData *netatmo.DeviceCollection
|
||||
|
@ -135,6 +140,7 @@ func (c *NetatmoCollector) Collect(mChan chan<- prometheus.Metric) {
|
|||
}
|
||||
c.sendMetric(mChan, netatmoUpDesc, prometheus.GaugeValue, upValue)
|
||||
c.sendMetric(mChan, refreshTimestampDesc, prometheus.GaugeValue, convertTime(c.lastRefresh))
|
||||
c.sendMetric(mChan, refreshDurationDesc, prometheus.GaugeValue, c.lastRefreshDuration.Seconds())
|
||||
|
||||
c.cacheLock.RLock()
|
||||
defer c.cacheLock.RUnlock()
|
||||
|
@ -156,6 +162,10 @@ func (c *NetatmoCollector) refreshData(now time.Time) {
|
|||
c.Log.Debugf("Refresh interval elapsed: %s > %s", now.Sub(c.lastRefresh), c.RefreshInterval)
|
||||
c.lastRefresh = now
|
||||
|
||||
defer func(start time.Time) {
|
||||
c.lastRefreshDuration = time.Since(start)
|
||||
}(time.Now())
|
||||
|
||||
devices, err := c.Client.Read()
|
||||
if err != nil {
|
||||
c.Log.Errorf("Error during refresh: %s", err)
|
||||
|
|
Loading…
Reference in a new issue