Extending Monitoring Capabilities With Golang

 

Yieldbot

March 10 2016

whoami

I am an operational tool and infrastructure developer at Yieldbot that has mild OCD and hates doing things twice.

I don't even wait till I do something once before scripting it

Part 1

There's More To Being An Infrastructure Developer Than Writing Code

Just Use Perl or How About No

Don't want to deal with a runtime or interpreter


Clear performance gains using a compiled language


Why Golang

already in use at Yieldbot


less complex than C/C++


Rust is not mature yet


Java requires a jvm


Goals

increased performance


dependency isolation


lightweight codebase


max compatibility across any environment


It worked in dev...sorta

fancy tools != easier process

static builds for a static language

Makefiles are your friend

library vs. binary vs. dammit just compile

dealing with dependents (don't kick'em out)

Part 2

Where Has This Gotten Us

Toolbelt

cli.go


func main() {
  app := cli.NewApp()
  app.Name = "boom"
  app.Usage = "make an explosive entrance"
  app.Action = func(c *cli.Context) {
    println("boom! I say!")
  }
  app.Run(os.Args)
}
        

Cobra


var checkFileHandlesCmd = &cobra.Command{
  Use:   "checkFileHandles",
  Short: "A brief description of your command",
  Long: "A longer description",
  Run: func(cmd *cobra.Command, args []string) {

    var appPid string

    if app == "" {
      fmt.Printf("Please enter a process name to check. \n")
    }
  },
}
        

Viper

  • Find, load, and unmarshal a configuration file in JSON, YAML, HCL, etc.
  • Allow you to set default values for your different config options.
  • Allow you to set override values command line flags.

Godep

Geting From Here To There

Writing the code

Any editor as long as its vim

Cobra provides a simple scaffolding command

Viper provides a simple way to deal with configuration

Godep provides a simple and clean vendoring solution

Vagrant/Docker provide a simple local test environment

Building the code

Commit to Github

Building is managed via jenkins through a Makefile

Compiling is done within a container of the dev's choice

Binaries are versioned and pushed to Artifactory and Github

Libraries are marked as building

Deploying the code

Via Curl from Artifactory in Dockerfiles

Via Chef ark cookbook on vm's

Part 3

What did you actually write with Golang

sensuplugin

Repo: sensuplugin


 

Features


common exit codes


common error handler


common exit function


functions to facilitate writing Sensu handlers


sensuplugines

Repo: sensuplugines


 

Features


send a defined subset of Sensu event data to ES


uses sensuplugin functionality


sensupluginslack

Repo: sensupluginslack


 

Features


send a defined subset of Sensu event data to Slack


uses sensuplugin functionality


sensupluginfile

Repo: sensupluginfile


 

Features


monitor the number of open file handles


monitor the size of a given file


uses sensuplugin functionality


functions to facilitate working with files


Additional Resources

Questions?