dashboarder 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +1 -0
- data/dashboarder.gemspec +21 -0
- data/lib/dashboarder.rb +14 -0
- data/lib/dashboarder/api.rb +39 -0
- data/lib/dashboarder/config.rb +21 -0
- data/lib/dashboarder/dashboard.rb +22 -0
- data/lib/dashboarder/instrument.rb +25 -0
- data/lib/dashboarder/metric.rb +7 -0
- data/lib/dashboarder/version.rb +3 -0
- metadata +81 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Michael Gorsuch
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Dashboarder
|
2
|
+
|
3
|
+
An experimental library to help in the construction of Librato Metrics dashboards from simple definitions.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Fetch the repo for now. Will consider a gem release once things seem steady.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
```bash
|
12
|
+
$ export LIBRATO_EMAIL=me@example.com
|
13
|
+
$ export LIBRATO_KEY=123456
|
14
|
+
$ bundle exec irb -I lib -r dashboarder
|
15
|
+
```
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
# a simple dashboard definition
|
19
|
+
definition = [
|
20
|
+
'my dashboard name',
|
21
|
+
[:an_instrument_name, :a_metric_name, :another_metric_name],
|
22
|
+
[:another_instrument_name, :a_metric_name]
|
23
|
+
]
|
24
|
+
|
25
|
+
# this will ensure the dashboard exists
|
26
|
+
# will not overwrite if already does
|
27
|
+
Dashboarder::Dashboard.compose(definition)
|
28
|
+
|
29
|
+
# compose an individual instrument
|
30
|
+
# will not overwrite if already exists
|
31
|
+
Dashboarder::Instrument.compose(['my instrument', :first_metric, :second_metric])
|
32
|
+
```
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/dashboarder.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dashboarder/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "dashboarder"
|
8
|
+
gem.version = Dashboarder::VERSION
|
9
|
+
gem.authors = ["Michael Gorsuch"]
|
10
|
+
gem.email = ["michael.gorsuch@gmail.com"]
|
11
|
+
gem.description = %q{a lightweight composer for librato instruments and dashboards}
|
12
|
+
gem.summary = gem.description
|
13
|
+
gem.homepage = "https://github.com/gorsuch/dashboarder"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_dependency('json')
|
20
|
+
gem.add_dependency('excon')
|
21
|
+
end
|
data/lib/dashboarder.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'excon'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
require 'dashboarder/api'
|
5
|
+
require 'dashboarder/config'
|
6
|
+
require 'dashboarder/dashboard'
|
7
|
+
require 'dashboarder/instrument'
|
8
|
+
require 'dashboarder/version'
|
9
|
+
|
10
|
+
module Dashboarder
|
11
|
+
def self.api
|
12
|
+
@api ||= Api.new
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Dashboarder
|
2
|
+
class Api
|
3
|
+
def initialize(options={})
|
4
|
+
@options = options
|
5
|
+
@options[:api_url] = Config.librato_api_url || 'https://metrics-api.librato.com'
|
6
|
+
@options[:api_user] = Config.librato_email
|
7
|
+
@options[:api_pass] = Config.librato_key
|
8
|
+
end
|
9
|
+
|
10
|
+
def connection
|
11
|
+
@connection ||= connect
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(path, options = {})
|
15
|
+
JSON.load(connection.get(options.merge(:path => path, :idempotent => true)).body)
|
16
|
+
end
|
17
|
+
|
18
|
+
def post(path, body, options = {})
|
19
|
+
JSON.load(connection.post(options.merge(:path => path, :body => body.to_json, :headers => { 'Content-Type' => 'application/json' })).body)
|
20
|
+
end
|
21
|
+
|
22
|
+
def connect
|
23
|
+
uri = URI.parse(@options[:api_url])
|
24
|
+
Excon.new(api_url, :headers => { 'Authorization' => 'Basic ' + [api_user.sub('%40', '@') + ':' + api_pass].pack('m').delete(Excon::CR_NL) })
|
25
|
+
end
|
26
|
+
|
27
|
+
def api_url
|
28
|
+
@options[:api_url]
|
29
|
+
end
|
30
|
+
|
31
|
+
def api_user
|
32
|
+
@options[:api_user]
|
33
|
+
end
|
34
|
+
|
35
|
+
def api_pass
|
36
|
+
@options[:api_pass]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Dashboarder
|
2
|
+
module Config
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def env!(key)
|
6
|
+
ENV[key] || raise("#{key} not found in ENV")
|
7
|
+
end
|
8
|
+
|
9
|
+
def librato_api_url
|
10
|
+
ENV['LIBRATO_API_URL']
|
11
|
+
end
|
12
|
+
|
13
|
+
def librato_key
|
14
|
+
env!('LIBRATO_KEY')
|
15
|
+
end
|
16
|
+
|
17
|
+
def librato_email
|
18
|
+
env!('LIBRATO_EMAIL')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Dashboarder
|
2
|
+
module Dashboard
|
3
|
+
def self.compose!(definition)
|
4
|
+
name = definition.first
|
5
|
+
instrument_definitions = definition[1..-1]
|
6
|
+
instrument_ids = instrument_definitions.map { |d| Instrument.compose(d)['id'] }
|
7
|
+
Dashboarder.api.post('/v1/dashboards', { :name => name, :instruments => instrument_ids })
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.compose(definition)
|
11
|
+
dashboard = get(definition.first)
|
12
|
+
unless dashboard
|
13
|
+
dashboard = compose!(definition)
|
14
|
+
end
|
15
|
+
dashboard
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.get(name)
|
19
|
+
Dashboarder.api.get('/v1/dashboards', :query => {:name => name})['dashboards'].first
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Dashboarder
|
2
|
+
module Instrument
|
3
|
+
def self.get(name)
|
4
|
+
Dashboarder.api.get('/v1/instruments', :query => {:name => name})['instruments'].first
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.compose!(definition)
|
8
|
+
name = definition.first
|
9
|
+
metric_names = definition[1..-1]
|
10
|
+
|
11
|
+
streams = metric_names.map { |n| { :metric => n, :source => '*' } }
|
12
|
+
Dashboarder.api.post('/v1/instruments', { :name => name, :streams => streams })
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.compose(definition)
|
16
|
+
name = definition.first
|
17
|
+
instrument = get(name)
|
18
|
+
|
19
|
+
unless instrument
|
20
|
+
instrument = compose!(definition)
|
21
|
+
end
|
22
|
+
instrument
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dashboarder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael Gorsuch
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: &70101351060000 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70101351060000
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: excon
|
27
|
+
requirement: &70101351058660 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70101351058660
|
36
|
+
description: a lightweight composer for librato instruments and dashboards
|
37
|
+
email:
|
38
|
+
- michael.gorsuch@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- LICENSE.txt
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- dashboarder.gemspec
|
49
|
+
- lib/dashboarder.rb
|
50
|
+
- lib/dashboarder/api.rb
|
51
|
+
- lib/dashboarder/config.rb
|
52
|
+
- lib/dashboarder/dashboard.rb
|
53
|
+
- lib/dashboarder/instrument.rb
|
54
|
+
- lib/dashboarder/metric.rb
|
55
|
+
- lib/dashboarder/version.rb
|
56
|
+
homepage: https://github.com/gorsuch/dashboarder
|
57
|
+
licenses: []
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.8.10
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: a lightweight composer for librato instruments and dashboards
|
80
|
+
test_files: []
|
81
|
+
has_rdoc:
|