Slate

Build Status Dependency Status

Simple wrapper to the Graphite render api

Installation

Add this line to your application's Gemfile:

gem 'slate'

And then execute:

$ bundle

Or install it yourself as:

$ gem install slate

Usage

Configuration

Configure the Slate client

Slate.configure do |config|
  config.endpoint = "http://your.graphite-server.com"
end

Ruby interface

To build a basic graph

graph = Slate::Graph.new
graph << Slate::Target.build("stats.web01.load")

puts graph.url
puts graph.download(:json)

Adjust the timeframe of the graph

graph       = Slate::Graph.new
graph.from  = "-1w"
graph.until = "-1d"
graph << Slate::Target.build("stats.web01.load")

Use functions

graph = Slate::Graph.new

graph << Slate::Target.build("stats.web01.load") do |target|
  target.add_function :sum
  target.add_function :alias, "load"
end

Or more complex targets (like passing targets to other targets): Graph Spec

Slate text interface

Slate also provides a text interface for building targets, this can be useful if you want to enable users to create graphs. This text interface also support being able to pass targets as arguments to functions, like you need for the asPercentOf function.

graph = Slate::Graph.new

target = <<-SLATE
"stats.web1.load" {
  sum
  alias "load"
}
SLATE

graph << Slate::Parser.parse(target)

Full test cases for different things this syntax supports are here: Parser Spec

Calculations

Slate supports things call Calculations, which take in graphite data and boil them down to single numbers, this can be useful if you wanted to calculate the average load over the week for all your servers.

graph = Slate::Graph.new
graph << Slate::Target.build("stats.web01.load")

p Slate::Calculation::Mean.new(graph).result
# [{ "name" => "stats.web01.load", "value" => 1.5 }]

All the possible calculation classes are here.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Contributors

Trae Robrock (https://github.com/trobrock)

Andrew Katz (https://github.com/andrewkatz)