Extending Monitoring Capabilities With Golang



March 10 2016


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


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



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


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")


  • 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.


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


Repo: sensuplugin



common exit codes

common error handler

common exit function

functions to facilitate writing Sensu handlers


Repo: sensuplugines



send a defined subset of Sensu event data to ES

uses sensuplugin functionality


Repo: sensupluginslack



send a defined subset of Sensu event data to Slack

uses sensuplugin functionality


Repo: sensupluginfile



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