Slate
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
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Contributors
Trae Robrock (https://github.com/trobrock)
Andrew Katz (https://github.com/andrewkatz)
David Sennerlöv (https://github.com/dsennerlov)