A tool to manage Librato. It defines the state of Librato using DSL, and updates Librato according to DSL.
Ruby Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
etc
exe
lib
spec
.gitignore
.rspec
.travis.yml
Gemfile
LICENSE.txt
README.md
Rakefile
lbrt.gemspec

README.md

Lbrt

A tool to manage Librato. It defines the state of Librato using DSL, and updates Librato according to DSL.

Installation

Add this line to your application's Gemfile:

gem 'lbrt'

And then execute:

$ bundle

Or install it yourself as:

$ gem install lbrt

Usage

$ lbrt
Commands:
  lbrt alert SUBCOMMAND    # Manage alerts
  lbrt help [COMMAND]      # Describe available commands or one specific command
  lbrt metric SUBCOMMAND   # Manage metrics
  lbrt service SUBCOMMAND  # Manage services
  lbrt space SUBCOMMAND    # Manage spaces

Options:
  [--user=USER]
                           # Default: ENV['LIBRATO_USER']
  [--token=TOKEN]
                           # Default: ENV['LIBRATO_TOKEN]
  [--color], [--no-color]
                           # Default: true
  [--debug], [--no-debug]
$ lbrt help alert
Commands:
  lbrt alert apply FILE      # Apply alerts
  lbrt alert export [FILE]   # Export alerts
  lbrt alert help [COMMAND]  # Describe subcommands or one specific subcommand
  lbrt alert list            # Show alerts
  lbrt alert peco            # Show alert by peco

Options:
  [--target=TARGET]
$ brt help metric
Commands:
  lbrt metric help [COMMAND]  # Describe subcommands or one specific subcommand
  lbrt metric list            # Show metrics
  lbrt metric peco REGRXP     # Show metric by peco

Options:
  [--target=TARGET]
$ lbrt help service
Commands:
  lbrt service apply FILE      # Apply services
  lbrt service export [FILE]   # Export services
  lbrt service help [COMMAND]  # Describe subcommands or one specific subcommand
  lbrt service list            # Show services

Options:
  [--target=TARGET]
$ lbrt help space
Commands:
  lbrt space apply FILE      # Apply spaces
  lbrt space export [FILE]   # Export spaces
  lbrt space help [COMMAND]  # Describe subcommands or one specific subcommand
  lbrt space list            # Show spaces
  lbrt space peco            # Show space by peco

Options:
  [--target=TARGET]
  [--concurrency=N]
                            # Default: 32

Export/Apply

$ lbrt space export space.rb

$ cat space.rb
space "My Space" do
  chart "My Chart" do
    type "line"
    stream do
      metric "login-delay"
      type "gauge"
      ...

$ lbrt space apply space.rb --dry-run

$ lbrt space apply space.rb

DSL Example

Sevice

service "mail", "my email" do
  settings "addresses"=>"sugawara@example.com"
end

service "slack", "my slack" do
  settings "url"=>"https://hooks.slack.com/services/..."
end

Alert

alert "alert1" do
  description "My Alert1"
  attributes "runbook_url"=>"http://example.com"
  active true
  rearm_seconds 600
  rearm_per_signal false

  condition do
    type "below"
    metric_name "login-delay"
    source "foo.bar.com"
    threshold 1.0
    summary_function "sum"
  end

  service "mail", "my email"
end

alert "alert2" do
  description "My Alert2"
  active true
  rearm_seconds 600
  rearm_per_signal true

  condition do
    type "absent"
    metric_name "login-delay2"
    source nil
    duration 600
  end

  service "slack", "my slack"
end

Space

space "My Space1" do
  chart "chart1" do
    type "stacked"
    stream do
      metric "login-delay"
      type "gauge"
      source "*"
      group_function "average"
      summary_function "average"
    end
  end
end

space "My Space2" do
  chart "chart1" do
    type "line"
    stream do
      metric "login-delay"
      type "gauge"
      source "*"
      group_function "breakout"
      summary_function "average"
    end
  end

  chart "chart2" do
    type "line"
    stream do
      metric "login-delay2"
      type "gauge"
      source "*"
      group_function "breakout"
      summary_function "average"
    end
  end
end

Using template

template "dstat" do
  chart "total_cpu_usage" do
    type "stacked"
    stream do
      metric "dstat.#{context.space_name}.total_cpu_usage"
      type "gauge"
      source "*"
      group_function "breakout"
      summary_function "average"
    end
    max 100.0
  end

  chart "load_avg" do
    type "line"
    stream do
      metric "dstat.#{context.space_name}.load_avg"
      type "gauge"
      source "*"
      group_function "breakout"
      summary_function "average"
    end
  end
end

space "my-host-001" do
  include_template "dstat"
end

You can use the template in the alert and service.

template "my alert" do
  alert context.metric_name do
    description "desc"
    attributes "runbook_url"=>"http://url.com"
    active true
    rearm_seconds 600
    rearm_per_signal false

    condition do
      type "below"
      metric_name context.metric_name
      source nil
      threshold 4.0
      summary_function "sum"
    end

    service "mail", "my email"
  end
end

include_template "my alert", metric_name: 'login-delay'
include_template "my alert", metric_name: 'login-delay2'
template "alert set1" do
  alert "#{context.hostname}/login-delay" do
    description "desc"
    attributes "runbook_url"=>"http://example.com"
    active true
    rearm_seconds 600
    rearm_per_signal false

    condition do
      type "below"
      metric_name 'login-delay'
      source nil
      threshold 4.0
      summary_function "sum"
    end

    service "mail", "my email"
  end

  alert "#{context.hostname}/login-delay2" do
    description "desc"
    attributes "runbook_url"=>"http://example.com"
    active true
    rearm_seconds 600
    rearm_per_signal false

    condition do
      type "below"
      metric_name 'login-delay2'
      source nil
      threshold 4.0
      summary_function "sum"
    end

    service "mail", "my email"
  end
end

include_template "alert set1", hostname: 'host1'
include_template "alert set1", hostname: 'host2'

Show resource by peco

lbrt alert peco
lbrt metric peco
lbrt space peco

Similar tools