@@ -43,7 +43,9 @@ func main() {
43
43
}
44
44
45
45
type BaseConfig struct {
46
- Enabled bool `yaml:"enabled"`
46
+ Enabled bool `yaml:"enabled"`
47
+ Interval * time.Duration `yaml:"interval"`
48
+ CacheTTL * time.Duration `yaml:"cache_ttl"`
47
49
}
48
50
49
51
type RDSConfig struct {
@@ -53,21 +55,20 @@ type RDSConfig struct {
53
55
54
56
type VPCConfig struct {
55
57
BaseConfig `yaml:"base,inline"`
56
- Timeout time.Duration `yaml:"timeout"`
57
- Regions []string `yaml:"regions"`
58
+ Timeout * time.Duration `yaml:"timeout"`
59
+ Regions []string `yaml:"regions"`
58
60
}
59
61
60
62
type Route53Config struct {
61
63
BaseConfig `yaml:"base,inline"`
62
- Interval time.Duration `yaml:"interval"`
63
- Timeout time.Duration `yaml:"timeout"`
64
- Region string `yaml:"region"` // Use only a single Region for now, as the current metric is global
64
+ Timeout * time.Duration `yaml:"timeout"`
65
+ Region string `yaml:"region"` // Use only a single Region for now, as the current metric is global
65
66
}
66
67
67
68
type EC2Config struct {
68
69
BaseConfig `yaml:"base,inline"`
69
- Timeout time.Duration `yaml:"timeout"`
70
- Regions []string `yaml:"regions"`
70
+ Timeout * time.Duration `yaml:"timeout"`
71
+ Regions []string `yaml:"regions"`
71
72
}
72
73
73
74
type Config struct {
@@ -77,6 +78,10 @@ type Config struct {
77
78
EC2Config EC2Config `yaml:"ec2"`
78
79
}
79
80
81
+ func durationPtr (duration time.Duration ) * time.Duration {
82
+ return & duration
83
+ }
84
+
80
85
func loadExporterConfiguration (logger log.Logger , configFile string ) (* Config , error ) {
81
86
var config Config
82
87
file , err := ioutil .ReadFile (configFile )
@@ -85,6 +90,42 @@ func loadExporterConfiguration(logger log.Logger, configFile string) (*Config, e
85
90
return nil , errors .New ("Could not load configuration file: " + configFile )
86
91
}
87
92
yaml .Unmarshal (file , & config )
93
+
94
+ if config .RdsConfig .CacheTTL == nil {
95
+ config .RdsConfig .CacheTTL = durationPtr (35 * time .Second )
96
+ }
97
+ if config .VpcConfig .CacheTTL == nil {
98
+ config .VpcConfig .CacheTTL = durationPtr (35 * time .Second )
99
+ }
100
+ if config .Route53Config .CacheTTL == nil {
101
+ config .Route53Config .CacheTTL = durationPtr (35 * time .Second )
102
+ }
103
+ if config .EC2Config .CacheTTL == nil {
104
+ config .EC2Config .CacheTTL = durationPtr (35 * time .Second )
105
+ }
106
+
107
+ if config .RdsConfig .Interval == nil {
108
+ config .RdsConfig .Interval = durationPtr (15 * time .Second )
109
+ }
110
+ if config .VpcConfig .Interval == nil {
111
+ config .VpcConfig .Interval = durationPtr (15 * time .Second )
112
+ }
113
+ if config .Route53Config .Interval == nil {
114
+ config .Route53Config .Interval = durationPtr (15 * time .Second )
115
+ }
116
+ if config .EC2Config .Interval == nil {
117
+ config .EC2Config .Interval = durationPtr (15 * time .Second )
118
+ }
119
+
120
+ if config .VpcConfig .Timeout == nil {
121
+ config .VpcConfig .Timeout = durationPtr (10 * time .Second )
122
+ }
123
+ if config .Route53Config .Timeout == nil {
124
+ config .Route53Config .Timeout = durationPtr (10 * time .Second )
125
+ }
126
+ if config .EC2Config .Timeout == nil {
127
+ config .EC2Config .Timeout = durationPtr (10 * time .Second )
128
+ }
88
129
return & config , nil
89
130
}
90
131
@@ -106,7 +147,9 @@ func setupCollectors(logger log.Logger, configFile string, creds *credentials.Cr
106
147
sess := session .Must (session .NewSession (config ))
107
148
vpcSessions = append (vpcSessions , sess )
108
149
}
109
- collectors = append (collectors , NewVPCExporter (vpcSessions , logger , config .VpcConfig .Timeout ))
150
+ vpcExporter := NewVPCExporter (vpcSessions , logger , config .VpcConfig )
151
+ collectors = append (collectors , vpcExporter )
152
+ go vpcExporter .CollectLoop ()
110
153
}
111
154
level .Info (logger ).Log ("msg" , "Will RDS metrics be gathered?" , "rds-enabled" , config .RdsConfig .Enabled )
112
155
var rdsSessions []* session.Session
@@ -116,7 +159,9 @@ func setupCollectors(logger log.Logger, configFile string, creds *credentials.Cr
116
159
sess := session .Must (session .NewSession (config ))
117
160
rdsSessions = append (rdsSessions , sess )
118
161
}
119
- collectors = append (collectors , NewRDSExporter (rdsSessions , logger ))
162
+ rdsExporter := NewRDSExporter (rdsSessions , logger , config .RdsConfig )
163
+ collectors = append (collectors , rdsExporter )
164
+ go rdsExporter .CollectLoop ()
120
165
}
121
166
level .Info (logger ).Log ("msg" , "Will EC2 metrics be gathered?" , "ec2-enabled" , config .EC2Config .Enabled )
122
167
var ec2Sessions []* session.Session
@@ -126,13 +171,15 @@ func setupCollectors(logger log.Logger, configFile string, creds *credentials.Cr
126
171
sess := session .Must (session .NewSession (config ))
127
172
ec2Sessions = append (ec2Sessions , sess )
128
173
}
129
- collectors = append (collectors , NewEC2Exporter (ec2Sessions , logger , config .EC2Config .Timeout ))
174
+ ec2Exporter := NewEC2Exporter (ec2Sessions , logger , config .EC2Config )
175
+ collectors = append (collectors , ec2Exporter )
176
+ go ec2Exporter .CollectLoop ()
130
177
}
131
178
level .Info (logger ).Log ("msg" , "Will Route53 metrics be gathered?" , "route53-enabled" , config .Route53Config .Enabled )
132
179
if config .Route53Config .Enabled {
133
180
awsConfig := aws .NewConfig ().WithCredentials (creds ).WithRegion (config .Route53Config .Region )
134
181
sess := session .Must (session .NewSession (awsConfig ))
135
- r53Exporter := NewRoute53Exporter (sess , logger , config .Route53Config . Interval , config . Route53Config . Timeout )
182
+ r53Exporter := NewRoute53Exporter (sess , logger , config .Route53Config )
136
183
collectors = append (collectors , r53Exporter )
137
184
go r53Exporter .CollectLoop ()
138
185
}
0 commit comments