@@ -43,7 +43,9 @@ func main() {
4343}
4444
4545type 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"`
4749}
4850
4951type RDSConfig struct {
@@ -53,21 +55,20 @@ type RDSConfig struct {
5355
5456type VPCConfig struct {
5557 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"`
5860}
5961
6062type Route53Config struct {
6163 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
6566}
6667
6768type EC2Config struct {
6869 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"`
7172}
7273
7374type Config struct {
@@ -77,6 +78,10 @@ type Config struct {
7778 EC2Config EC2Config `yaml:"ec2"`
7879}
7980
81+ func durationPtr (duration time.Duration ) * time.Duration {
82+ return & duration
83+ }
84+
8085func loadExporterConfiguration (logger log.Logger , configFile string ) (* Config , error ) {
8186 var config Config
8287 file , err := ioutil .ReadFile (configFile )
@@ -85,6 +90,42 @@ func loadExporterConfiguration(logger log.Logger, configFile string) (*Config, e
8590 return nil , errors .New ("Could not load configuration file: " + configFile )
8691 }
8792 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+ }
88129 return & config , nil
89130}
90131
@@ -106,7 +147,9 @@ func setupCollectors(logger log.Logger, configFile string, creds *credentials.Cr
106147 sess := session .Must (session .NewSession (config ))
107148 vpcSessions = append (vpcSessions , sess )
108149 }
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 ()
110153 }
111154 level .Info (logger ).Log ("msg" , "Will RDS metrics be gathered?" , "rds-enabled" , config .RdsConfig .Enabled )
112155 var rdsSessions []* session.Session
@@ -116,7 +159,9 @@ func setupCollectors(logger log.Logger, configFile string, creds *credentials.Cr
116159 sess := session .Must (session .NewSession (config ))
117160 rdsSessions = append (rdsSessions , sess )
118161 }
119- collectors = append (collectors , NewRDSExporter (rdsSessions , logger ))
162+ rdsExporter := NewRDSExporter (rdsSessions , logger , config .RdsConfig )
163+ collectors = append (collectors , rdsExporter )
164+ go rdsExporter .CollectLoop ()
120165 }
121166 level .Info (logger ).Log ("msg" , "Will EC2 metrics be gathered?" , "ec2-enabled" , config .EC2Config .Enabled )
122167 var ec2Sessions []* session.Session
@@ -126,13 +171,15 @@ func setupCollectors(logger log.Logger, configFile string, creds *credentials.Cr
126171 sess := session .Must (session .NewSession (config ))
127172 ec2Sessions = append (ec2Sessions , sess )
128173 }
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 ()
130177 }
131178 level .Info (logger ).Log ("msg" , "Will Route53 metrics be gathered?" , "route53-enabled" , config .Route53Config .Enabled )
132179 if config .Route53Config .Enabled {
133180 awsConfig := aws .NewConfig ().WithCredentials (creds ).WithRegion (config .Route53Config .Region )
134181 sess := session .Must (session .NewSession (awsConfig ))
135- r53Exporter := NewRoute53Exporter (sess , logger , config .Route53Config . Interval , config . Route53Config . Timeout )
182+ r53Exporter := NewRoute53Exporter (sess , logger , config .Route53Config )
136183 collectors = append (collectors , r53Exporter )
137184 go r53Exporter .CollectLoop ()
138185 }
0 commit comments