Skip to content

Commit

Permalink
feat(exporter): Add --collect-instance-types parameter to enable/disa…
Browse files Browse the repository at this point in the history
…ble AWS instance types information
  • Loading branch information
vmercierfr committed Oct 23, 2023
1 parent 8247421 commit 35c6e69
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
16 changes: 12 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions internal/app/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 35c6e69

Please sign in to comment.