forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
66 lines (57 loc) · 1.83 KB
/
config.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
64
65
66
package gce
import (
"fmt"
"time"
"github.com/influxdata/influxdb/toml"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/config"
)
// Config is GCE service discovery configuration
type Config struct {
Enabled bool `toml:"enabled" override:"enabled"`
ID string `toml:"id" override:"id"`
Project string `toml:"project" override:"project"`
Zone string `toml:"zone" override:"zone"`
Filter string `toml:"filter" override:"filter"`
RefreshInterval toml.Duration `toml:"refresh-interval" override:"refresh-interval"`
Port int `toml:"port" override:"port"`
TagSeparator string `toml:"tag-separator" override:"tag-separator"`
}
// Init adds defaults to existing GCE configuration
func (g *Config) Init() {
g.Port = 80
g.TagSeparator = ","
g.RefreshInterval = toml.Duration(60 * time.Second)
}
// Validate validates the GCE configuration values
func (g Config) Validate() error {
if g.ID == "" {
return fmt.Errorf("gce discovery must be given a ID")
}
return nil
}
// Prom writes the prometheus configuration for discoverer into ScrapeConfig
func (g Config) Prom(c *config.ScrapeConfig) {
c.ServiceDiscoveryConfig.GCESDConfigs = []*config.GCESDConfig{
g.PromConfig(),
}
}
// PromConfig returns the prometheus configuration for this discoverer
func (g Config) PromConfig() *config.GCESDConfig {
return &config.GCESDConfig{
Project: g.Project,
Zone: g.Zone,
Filter: g.Filter,
RefreshInterval: model.Duration(g.RefreshInterval),
Port: g.Port,
TagSeparator: g.TagSeparator,
}
}
// Service return discoverer type
func (g Config) Service() string {
return "gce"
}
// ServiceID returns the discoverers name
func (g Config) ServiceID() string {
return g.ID
}