<commit_before>﻿using Amazon;
using Amazon.CloudWatch;
using Amazon.CloudWatch.Model;
using Amazon.EC2;
using Amazon.EC2.Model;
using Microsoft.Framework.Runtime.Common.CommandLine;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace FixStuckWorkers
{
    internal class InstanceResult
    {
        public string Name { get; private set; }
        public double Cpu { get; private set; }
        public InstanceResult(string name, double cpu)
        {
            Name = name;
            Cpu = cpu;
        }
        public override string ToString()
        {
            return Name + "\t\t" + Cpu.ToString("0.00");
        }
    }
    internal class InstanceResults
    {
        public ConcurrentBag<InstanceResult> BadInstances { get; set; }
        public ConcurrentBag<InstanceResult> GoodInstances { get; set; }
        public ConcurrentBag<InstanceResult> UnknownInstances { get; set; }
        public InstanceResults()
        {
            BadInstances = new ConcurrentBag<InstanceResult>();
            GoodInstances = new ConcurrentBag<InstanceResult>();
            UnknownInstances = new ConcurrentBag<InstanceResult>();
        }
    }
    public class Program
    {
        private const double MaxBadCpuPercent = 1.0;
        private const double UnknownCpuPercent = -1;
        private const int MaxMetricConcurrency = 8;
        private const int MetricRetrievalInHours = 3;
        private const int PeriodInMinutes = 10;
        //require at least 6 periods (60 minutes) to judge good or bad
        private const int MinServerMetricsToJudge = 6;

        private static string AccessKey { get; set; }
        private static string SecretKey { get; set; }
        private static string Name { get; set; }
        private static RegionEndpoint Region { get; set; }
        private static bool ShowGoodInstances { get; set; }
        private static bool ShowUnknownInstances { get; set; }

        public static int Main(string[] args)
        {


            var app = new CommandLineApplication
            {
                Name = "FixStuckWorkers",
                Description = string.Format("Analyzes and fixes 'stuck' workers in Hudl encoder pools. Stuck is defined as less than {0}% CPU for {1} hours.",
                    MaxBadCpuPercent, MetricRetrievalInHours),
                FullName = "FixStuckWorkers - fixing your jank/frozen AWS servers since 2016"
            };


            //if no command - show help
            app.OnExecute(() =>
            {
                app.ShowHelp();
                return 2;
            });

            app.Command("find", c =>
            {
                c.Description = "Finds stuck instances";
                var accessOption = c.Option("--accesskey", "AWS Access Key (required)", CommandOptionType.SingleValue);
                var secretOption = c.Option("--secretkey", "AWS Secret Key (required)", CommandOptionType.SingleValue);
                var nameOption = c.Option("--name", "Name of worker to search on (required)", CommandOptionType.SingleValue);
                var regionOption = c.Option("--region", "AWS region name (optional)", CommandOptionType.SingleValue);
                var showGoodOption = c.Option("--show-good", "Display 'good' instances in results (optional)", CommandOptionType.NoValue);
                var showUnknownOption = c.Option("--show-unknown", "Display 'unknown' instances in results (optional)", CommandOptionType.NoValue);

                c.OnExecute(async () =>
                {
                    bool success = ValidateAndSetOptions(accessOption, secretOption, nameOption, regionOption, showGoodOption, showUnknownOption);
                    if(!success)
                    {
                        c.ShowHelp("find");<commit_msg>Updated 'help' text<commit_after>﻿using Amazon;
using Amazon.CloudWatch;
using Amazon.CloudWatch.Model;
using Amazon.EC2;
using Amazon.EC2.Model;
using Microsoft.Framework.Runtime.Common.CommandLine;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace FixStuckWorkers
{
    internal class InstanceResult
    {
        public string Name { get; private set; }
        public double Cpu { get; private set; }
        public InstanceResult(string name, double cpu)
        {
            Name = name;
            Cpu = cpu;
        }
        public override string ToString()
        {
            return Name + "\t\t" + Cpu.ToString("0.00");
        }
    }
    internal class InstanceResults
    {
        public ConcurrentBag<InstanceResult> BadInstances { get; set; }
        public ConcurrentBag<InstanceResult> GoodInstances { get; set; }
        public ConcurrentBag<InstanceResult> UnknownInstances { get; set; }
        public InstanceResults()
        {
            BadInstances = new ConcurrentBag<InstanceResult>();
            GoodInstances = new ConcurrentBag<InstanceResult>();
            UnknownInstances = new ConcurrentBag<InstanceResult>();
        }
    }
    public class Program
    {
        private const double MaxBadCpuPercent = 1.0;
        private const double UnknownCpuPercent = -1;
        private const int MaxMetricConcurrency = 8;
        private const int MetricRetrievalInHours = 3;
        private const int PeriodInMinutes = 10;
        //require at least 6 periods (60 minutes) to judge good or bad
        private const int MinServerMetricsToJudge = 6;

        private static string AccessKey { get; set; }
        private static string SecretKey { get; set; }
        private static string Name { get; set; }
        private static RegionEndpoint Region { get; set; }
        private static bool ShowGoodInstances { get; set; }
        private static bool ShowUnknownInstances { get; set; }

        public static int Main(string[] args)
        {


            var app = new CommandLineApplication
            {
                Name = "find-idle-instances",
                Description = string.Format("Identifies and optionally terminates idle workers. Idle is defined as less than {0}% CPU for {1} hours.",
                    MaxBadCpuPercent, MetricRetrievalInHours),
                FullName = "find-idle-instances - fixing your idle AWS servers since 2016"
            };


            //if no command - show help
            app.OnExecute(() =>
            {
                app.ShowHelp();
                return 2;
            });

            app.Command("find", c =>
            {
                c.Description = "Finds stuck instances";
                var accessOption = c.Option("--accesskey", "AWS Access Key (required)", CommandOptionType.SingleValue);
                var secretOption = c.Option("--secretkey", "AWS Secret Key (required)", CommandOptionType.SingleValue);
                var nameOption = c.Option("--name", "Name of worker to search on (required)", CommandOptionType.SingleValue);
                var regionOption = c.Option("--region", "AWS region name (optional)", CommandOptionType.SingleValue);
                var showGoodOption = c.Option("--show-good", "Display 'good' instances in results (optional)", CommandOptionType.NoValue);
                var showUnknownOption = c.Option("--show-unknown", "Display 'unknown' instances in results (optional)", CommandOptionType.NoValue);

                c.OnExecute(async () =>
                {
                    bool success = ValidateAndSetOptions(accessOption, secretOption, nameOption, regionOption, showGoodOption, showUnknownOption);
                    if(!success)
                    {
                        c.ShowHelp("find");
{'fraction_non_alphanumeric': 0.09081540641504574, 'fraction_numerical': 0.005925544248357594, 'mean_word_length': 2.2016494845360826, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2694496', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1907, 'n_words': 582}