From 35c6e69648d6149fee044ae811ccd7b0180709ec Mon Sep 17 00:00:00 2001 From: Vincent Mercier Date: Mon, 23 Oct 2023 22:25:37 +0200 Subject: [PATCH] feat(exporter): Add --collect-instance-types parameter to enable/disable AWS instance types information --- README.md | 1 + cmd/root.go | 16 ++++++++++++---- internal/app/exporter/exporter.go | 11 ++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c4c7c74..778af48 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,7 @@ Configuration could be defined in `.prometheus-rds-exporter.yaml` or environment | --- | --- | --- | | aws-assume-role-arn | AWS IAM ARN role to assume to fetch metrics | | | aws-assume-role-session | AWS assume role session name | prometheus-rds-exporter | +| collect-instance-types | Collect AWS instance types information (AWS EC2 API) | true | | collect-logs-size | Collect AWS instances logs size (AWS RDS API) | true | | collect-maintenances | Collect AWS instances maintenances (AWS RDS API) | true | | collect-quotas | Collect AWS RDS quotas (AWS quotas API) | true | diff --git a/cmd/root.go b/cmd/root.go index 6dbb386..b7e2285 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -35,6 +35,7 @@ type exporterConfig struct { ListenAddress string `mapstructure:"listen-address"` AWSAssumeRoleSession string `mapstructure:"aws-assume-role-session"` AWSAssumeRoleArn string `mapstructure:"aws-assume-role-arn"` + CollectInstanceTypes bool `mapstructure:"collect-instances-types"` CollectLogsSize bool `mapstructure:"collect-logs-size"` CollectMaintenances bool `mapstructure:"collect-maintenances"` CollectQuotas bool `mapstructure:"collect-quotas"` @@ -66,10 +67,11 @@ func run(configuration exporterConfig) { servicequotasClient := servicequotas.NewFromConfig(cfg) collectorConfiguration := exporter.Configuration{ - CollectLogsSize: configuration.CollectLogsSize, - CollectMaintenances: configuration.CollectMaintenances, - CollectQuotas: configuration.CollectQuotas, - CollectUsages: configuration.CollectUsages, + CollectLogsSize: configuration.CollectLogsSize, + CollectMaintenances: configuration.CollectMaintenances, + CollectQuotas: configuration.CollectQuotas, + CollectUsages: configuration.CollectUsages, + CollectInstanceTypes: configuration.CollectInstanceTypes, } collector := exporter.NewCollector(*logger, collectorConfiguration, awsAccountID, awsRegion, rdsClient, ec2Client, cloudWatchClient, servicequotasClient) @@ -113,6 +115,7 @@ func NewRootCommand() (*cobra.Command, error) { cmd.Flags().StringP("listen-address", "", ":9043", "Address to listen on for web interface") cmd.Flags().StringP("aws-assume-role-arn", "", "", "AWS IAM ARN role to assume to fetch metrics") cmd.Flags().StringP("aws-assume-role-session", "", "prometheus-rds-exporter", "AWS assume role session name") + cmd.Flags().BoolP("collect-instance-types", "", true, "Collect AWS instance types") cmd.Flags().BoolP("collect-logs-size", "", true, "Collect AWS instances logs size") cmd.Flags().BoolP("collect-maintenances", "", true, "Collect AWS instances maintenances") cmd.Flags().BoolP("collect-quotas", "", true, "Collect AWS RDS quotas") @@ -148,6 +151,11 @@ func NewRootCommand() (*cobra.Command, error) { return cmd, fmt.Errorf("failed to bind 'aws-assume-role-session' parameter: %w", err) } + err = viper.BindPFlag("collect-instance-types", cmd.Flags().Lookup("collect-instance-types")) + if err != nil { + return cmd, fmt.Errorf("failed to bind 'collect-instance-types' parameter: %w", err) + } + err = viper.BindPFlag("collect-quotas", cmd.Flags().Lookup("collect-quotas")) if err != nil { return cmd, fmt.Errorf("failed to bind 'collect-quotas' parameter: %w", err) diff --git a/internal/app/exporter/exporter.go b/internal/app/exporter/exporter.go index 0f8f820..fa297fd 100644 --- a/internal/app/exporter/exporter.go +++ b/internal/app/exporter/exporter.go @@ -21,10 +21,11 @@ const ( ) type Configuration struct { - CollectQuotas bool - CollectUsages bool - CollectLogsSize bool - CollectMaintenances bool + CollectQuotas bool + CollectUsages bool + CollectInstanceTypes bool + CollectLogsSize bool + CollectMaintenances bool } type counters struct { @@ -302,7 +303,7 @@ func (c *rdsCollector) fetchMetrics() error { instanceIdentifiers, instanceTypes := getUniqTypeAndIdentifiers(rdsMetrics.Instances) // Fetch EC2 Metrics for instance types - if len(instanceTypes) > 0 { + if c.configuration.CollectInstanceTypes && len(instanceTypes) > 0 { go c.getEC2Metrics(c.EC2Client, instanceTypes) c.wg.Add(1) }