forked from webdevops/azure-resourcemanager-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collector_base.go
63 lines (48 loc) · 1.33 KB
/
collector_base.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions"
log "github.com/sirupsen/logrus"
"time"
)
type CollectorBase struct {
Name string
scrapeTime *time.Duration
LastScrapeDuration *time.Duration
collectionStartTime time.Time
AzureSubscriptions []subscriptions.Subscription
AzureLocations []string
logger *log.Entry
isHidden bool
}
func (c *CollectorBase) Init() {
c.isHidden = false
c.logger = log.WithField("collector", c.Name)
}
func (c *CollectorBase) SetScrapeTime(scrapeTime time.Duration) {
c.scrapeTime = &scrapeTime
}
func (c *CollectorBase) GetScrapeTime() *time.Duration {
return c.scrapeTime
}
func (c *CollectorBase) SetIsHidden(v bool) {
c.isHidden = v
}
func (c *CollectorBase) collectionStart() {
c.collectionStartTime = time.Now()
if !c.isHidden {
c.logger.Info("starting metrics collection")
}
}
func (c *CollectorBase) collectionFinish() {
duration := time.Since(c.collectionStartTime)
c.LastScrapeDuration = &duration
if !c.isHidden {
c.logger.WithField("duration", c.LastScrapeDuration.Seconds()).Infof("finished metrics collection (duration: %v)", c.LastScrapeDuration)
}
}
func (c *CollectorBase) sleepUntilNextCollection() {
if !c.isHidden {
c.logger.Debugf("sleeping %v", c.GetScrapeTime().String())
}
time.Sleep(*c.GetScrapeTime())
}