Skip to content
/ slate Public
forked from trobrock/slate

Simple wrapper around the graphite render api

License

Notifications You must be signed in to change notification settings

careport/slate

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Slate

Build Status Dependency Status Coverage Status Code Climate Bitdeli Badge

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

client = Slate.configure do |config|
  config.endpoint = "http://your.graphite-server.com"
  config.timeout  = 30 # In seconds (default: 10)
end

Ruby interface

To build a basic graph

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

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

Adjust the timeframe of the graph

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

Use functions

graph = Slate::Graph.new(client)

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(client)

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(client)
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)

David Sennerlöv (https://github.com/dsennerlov)

About

Simple wrapper around the graphite render api

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%