Skip to content

Instantly share code, notes, and snippets.

@anujkumar-df
Last active August 6, 2020 14:53
Show Gist options
  • Save anujkumar-df/059433be0e4c3a6d96a058b080887f0e to your computer and use it in GitHub Desktop.
Save anujkumar-df/059433be0e4c3a6d96a058b080887f0e to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
namespace COFinderDS
{
class Program
{
static void Main(string[] args)
{
// Step 1 - Create the idea (tPM, SEM, VP, SVP)
var idea = new Ideation(
ExecutiveSummary: "A lot of instances are not used as per their full potential. Downsizing them can a significant amount of money.",
EstimatedCostSavings: 6000
);
// Step 2 - Create the playbook from the idea (SEM)
var playbook = new Playbook(
Summary: "Underutilized EC2 Instances",
Ideation: idea,
Category: Category.Compute,
SubCategory: SubCategory.EC2
);
// Create the finder for the playbook (tPM)
playbook.AssociateFinder(CreateFinder());
// Configure the playbook with CO product (TBD)
var co = new CostOptimizationProduct();
co.AddPlaybook(Playbook: playbook, Enabled: true, RiskProfile: "M");
// Get all the playbooks by category or sub category (Anyone who wants to query the meta data)
co.GetAllPlaybooks(Category: Category.Compute);
co.GetAllPlaybooks(SubCategory: SubCategory.EC2);
// Get all the Metrics (Cloudwatch, DataDog, Prometheus) for a playbook (Anyone who wants to query the meta data)
co.GetAllMetricsForPlaybook("Underutilized EC2 Instances");
}
/// <summary>
/// Process to create a new finder
/// </summary>
/// <returns></returns>
private static Finder CreateFinder()
{
var finder = new Finder();
// Step 1 - Add ITDs of the finder
finder.AddITD(new ITD()
{
Problem = "What metrics do we use to find under utilized instances?",
Options = new List<string>
{
"CPU Utilization",
"Memory Utilization",
"Network Utilization",
"All above metrics",
"CPU and Network Utilization and Memory Utilization wherever possible"
},
ChosenOptionIndex = 5,
Rationale = "While one could argue that all metrics is the best option, memory utilization is not exposed by CW by default and it is not always possible to setup CW agent."
});
// Step 2 - Add Input parameters and map them to the ITD
finder.AddInputParameter(new InputParameter(Name: "CPUUtilization", ChosenITD: 1, Source: "CloudWatch"));
finder.AddInputParameter(new InputParameter(Name: "NetworkUtilization", ChosenITD: 1, Source: "CloudWatch"));
finder.AddInputParameter(new InputParameter(Name: "MemoryUtilization", ChosenITD: 1, Source: "Prometheus"));
// Step 3 - Specify Output Parameter for the fixer
finder.AddOutputParameter(new OutputParameter(Name: "EC2 Instance Id"));
// Step 4 - Specify Control Parameter based on the risk profile (L, M, H)
finder.AddControlParameter(new ControlParameter(Name: "Days to look back", RiskProfile: new int[7, 14, 28]));
finder.AddControlParameter(new ControlParameter(Name: "Overshoot Buffer", RiskProfile: new int[20, 10, 10]));
// Step 5 - Specify the algorithm that takes the input parameters, find the resource and generates the output
finder.SetFinderAlgorithm(@"
Get All the {{SubCategory.EC2}} from the AWS Account.
For each EC2 instance do
Collect the {{Input Param1}}, {{Input Param2}} for {{Control Param1}}
If CW exposes {{Input Param3}}, collect it
If metrics are lower than the {{Control Param2}}, output the {{Output Param1}} and {{Costing Algo Output}}
");
// Step 5 - Specify the algorithm that takes the input parameters, find the resource and generates the output
finder.SetCostingAlgorithm(@"
cost = InstanceType * InstanceTypePrice
");
return finder;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment