@@ -19,13 +19,17 @@ import (
1919 "gopkg.in/yaml.v3"
2020)
2121
22+ const (
23+ defaultTarget = 60.0
24+ )
25+
2226func main () {
2327 defaultDuration , _ := time .ParseDuration ("336h" )
2428
2529 app := & cli.Command {
2630 Name : "rigthsizer" ,
2731 Usage : "Right size your AWS ECS services." ,
28- Version : "3.0 .0" ,
32+ Version : "3.1 .0" ,
2933 HideHelpCommand : true ,
3034 ArgsUsage : "<cluster> <service>" ,
3135 UseShortOptionHandling : true ,
@@ -40,7 +44,13 @@ func main() {
4044 & cli.StringFlag {
4145 Name : "region" ,
4246 Aliases : []string {"r" },
43- Usage : "AWS `REGION` to use" ,
47+ Usage : "AWS region to use" ,
48+ },
49+ & cli.FloatFlag {
50+ Name : "target" ,
51+ Aliases : []string {"g" },
52+ Value : defaultTarget ,
53+ Usage : "Target resource utilization percentage" ,
4454 },
4555 },
4656
@@ -57,23 +67,15 @@ func main() {
5767 return errors .New ("cannot see into the future just yet" )
5868 }
5969
60- region := cmd .String ("region" )
61- if region == "" {
62- region = os .Getenv ("AWS_REGION" )
63- }
64-
65- if region == "" {
66- return errors .New ("cannot determine AWS region, checked the --region flag and the AWS_REGION environment variable" )
67- }
68-
69- cfg , err := config .LoadDefaultConfig (ctx , config .WithRegion (region ))
70+ defaultRegion := cmd .String ("region" )
71+ cfg , err := config .LoadDefaultConfig (ctx , config .WithDefaultRegion (defaultRegion ))
7072 if err != nil {
7173 return fmt .Errorf ("unable to load SDK config, %v" , err )
7274 }
7375
7476 awsCloudwatchClient := cloudwatch .NewFromConfig (cfg )
75- cloutwatchClient := clients .NewCloudWatchClient (awsCloudwatchClient )
76- usageService := services .NewUsageService (cloutwatchClient )
77+ cloudwatchClient := clients .NewCloudWatchClient (awsCloudwatchClient )
78+ usageService := services .NewUsageService (cloudwatchClient )
7779
7880 awsEcsClient := ecs .NewFromConfig (cfg )
7981 ecsClient := clients .NewECSClient (awsEcsClient )
@@ -98,7 +100,8 @@ func main() {
98100 return fmt .Errorf ("failed to get allocation: %w" , err )
99101 }
100102
101- newAllocation := allocation .Fix (usage , & models.Usage {CPU : 90 , Memory : 90 })
103+ target := cmd .Float ("target" )
104+ newAllocation := allocation .Fix (usage , & models.Usage {CPU : target , Memory : target })
102105
103106 bytes , err := yaml .Marshal (newAllocation )
104107 if err != nil {
0 commit comments