sigmund

package module
v0.0.0-...-47f0617 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2019 License: MIT Imports: 3 Imported by: 0

README

Sigmund

A Go tool designed to shrink AWS Autoscaling Clusters based on CPU and Memory Cloudwatch Alarm Metrics.

This tool is meant to be for people who want to scale their instances back in whenever both CPU AND Memory conditions are met.

Sigmund Go

Prerequisites

  • A DynamoDB table
  • AWS credentials with the following permissions:
    • DynamoDB Table Read/Write access
    • Ability to Execute Autoscaling Policies
DyanamoDB Table structure

In order to work, your DynamoDB table should look like the one that follows:

ID isLowCPU isLowMemory
0 false false

NB it is important that the table is pre-populated with the values showed above, most importantly you must make sure that the ID = 0 - that value will never change.

Installing

You can directly use the go tool to download and install the sigmund package into your GOPATH:

$ go get github.com/darkraiden/sigmund.go

You can also clone the repository yourself:

$ mkdir -p $GOPATH/src/github.com/darkraiden
$ cd $GOPATH/src/github.com/darkraiden
$ git clone git@git.int.avast.com:devops/sigmund

How to use it

First things first, initialise a Sigmund from your application:

  // Get a Sigmund
  s, err := sigmund.New(&sigmund.Config{Region: "eu-west-1", AsgName: "anASGName", PolicyName: "anASGPolicyName", TableName: "aDynamoTableName", Metric: "LowCPU"}) // LowCPU can be replaced by OkCPU, LowMemory, OkMemory, depending on which metric changed on your Cloudwatch Alerts
  if err != nil {
    panic(err)
  }

Now that you have your Sigmund, you're ready to update the DB and eventually execute the autoscaling group policy:

  err := s.Shrink()
  if err != nil {
    panic(err)
  }
Logging

Sigmund uses Logrus for logging. The default config is different depending on whether it was compiled for production or not (mage releaseLambda or building with the PRODUCTION environment variable set).

Currently, all errors are deemed irrecoverable and result in a panic.

Running the tests

Every Package of this project comes with some unit tests which use the Go testing package. Run the tests, from the package folder, by typing:

$ go test ./...

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Autoscaling

type Autoscaling struct {
	AutoScalingGroupName string
	PolicyName           string
	Region               string
}

Autoscaling represents the structure of a series of AWS autoscaling group parameters to trigger a dimension change

type Config

type Config struct {
	Region     string
	AsgName    string
	PolicyName string
	TableName  string
	Metric     Metric
	Log        *logrus.Logger
}

Config is a struct containing all the info required by the constructor function

type DBItem

type DBItem struct {
	ID          int  `json:"ID"`
	IsLowMemory bool `json:"isLowMemory"`
	IsLowCPU    bool `json:"isLowCPU"`
}

DBItem represents the structure of the JSON body coming back from DynamoDB after a Select query is executed

type Dynamo

type Dynamo struct {
	TableName string
	Region    string
	Key       string
}

Dynamo contains the DyanamoDB basic information needed to connect to the instance

type Logger

type Logger struct {
	Log *logrus.Logger
}

Logger wraps a logger, so the correct logging context can be passed from the main package into Sigmund

type Metric

type Metric int

Metric is a type that will be used to serialise the metric types received from SNS

const (
	// LowMemory is a metric that indicates low memory
	LowMemory Metric = iota
	// LowCPU is a metric that indicates low CPU
	LowCPU
	// OkMemory is a metric that indicates the absence of memory issues
	OkMemory
	// OkCPU is a metric that indicates the absence of CPU issues
	OkCPU
)

func (Metric) String

func (m Metric) String() string

type Sigmund

type Sigmund struct {
	Autoscaling
	Dynamo
	Logger
}

Sigmund is a struct containing info regarding the autoscaling group and the Datastore used by the application

func New

func New(conf *Config) *Sigmund

New is the Package constructor that takes in a Config and returns a pointer to Sigmund

func (*Sigmund) Shrink

func (s *Sigmund) Shrink()

Shrink is the core function of the package which Executes an Autoscaling Group Policy when requirements are met

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL