mindreframer-riemann-dash 0.2.3

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.
Files changed (55) hide show
  1. data/.gitignore +8 -0
  2. data/Gemfile +7 -0
  3. data/Gemfile.lock +52 -0
  4. data/LICENSE +21 -0
  5. data/README.markdown +52 -0
  6. data/Rakefile.rb +11 -0
  7. data/bin/riemann-dash +7 -0
  8. data/example/config.rb +17 -0
  9. data/lib/riemann/dash.rb +5 -0
  10. data/lib/riemann/dash/app.rb +32 -0
  11. data/lib/riemann/dash/config.rb +154 -0
  12. data/lib/riemann/dash/controller/css.rb +5 -0
  13. data/lib/riemann/dash/controller/index.rb +20 -0
  14. data/lib/riemann/dash/public/clock.js +45 -0
  15. data/lib/riemann/dash/public/dash.js +287 -0
  16. data/lib/riemann/dash/public/format.js +24 -0
  17. data/lib/riemann/dash/public/jquery-1.7.2.min.js +4 -0
  18. data/lib/riemann/dash/public/jquery-ui-1.9.0.custom.min.js +6 -0
  19. data/lib/riemann/dash/public/jquery.json-2.2.min.js +31 -0
  20. data/lib/riemann/dash/public/jquery.quickfit.js +144 -0
  21. data/lib/riemann/dash/public/jquery.simplemodal.1.4.3.min.js +26 -0
  22. data/lib/riemann/dash/public/keys.js +46 -0
  23. data/lib/riemann/dash/public/mustache.js +597 -0
  24. data/lib/riemann/dash/public/persistence.js +30 -0
  25. data/lib/riemann/dash/public/profile.js +33 -0
  26. data/lib/riemann/dash/public/subs.js +164 -0
  27. data/lib/riemann/dash/public/toastr.css +174 -0
  28. data/lib/riemann/dash/public/toastr.js +207 -0
  29. data/lib/riemann/dash/public/toolbar.js +217 -0
  30. data/lib/riemann/dash/public/underscore-min.js +5 -0
  31. data/lib/riemann/dash/public/util.js +34 -0
  32. data/lib/riemann/dash/public/vendor/smoothie.js +374 -0
  33. data/lib/riemann/dash/public/view.js +704 -0
  34. data/lib/riemann/dash/public/views/gauge.js +76 -0
  35. data/lib/riemann/dash/public/views/grid.js +279 -0
  36. data/lib/riemann/dash/public/views/help.js +28 -0
  37. data/lib/riemann/dash/public/views/timeseries.js +107 -0
  38. data/lib/riemann/dash/public/views/title.js +35 -0
  39. data/lib/riemann/dash/public/x.png +0 -0
  40. data/lib/riemann/dash/rack/static.rb +16 -0
  41. data/lib/riemann/dash/version.rb +4 -0
  42. data/lib/riemann/dash/views/css.scss +393 -0
  43. data/lib/riemann/dash/views/index.erubis +203 -0
  44. data/lib/riemann/dash/views/layout.erubis +21 -0
  45. data/riemann-dash.gemspec +28 -0
  46. data/sh/c +1 -0
  47. data/sh/env.rb +2 -0
  48. data/sh/test +1 -0
  49. data/test/config_test.rb +106 -0
  50. data/test/fixtures/config/basic_config.rb +2 -0
  51. data/test/fixtures/config/ws_config.rb +1 -0
  52. data/test/fixtures/ws_config/dummy_config.json +1 -0
  53. data/test/fixtures/ws_config/pretty_printed_config.json +6 -0
  54. data/test/test_helper.rb +10 -0
  55. metadata +202 -0
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ pkg/
2
+ ._*
3
+ .sass-cache/
4
+ *~
5
+ .DS_Store
6
+ .*.swp
7
+ *.log
8
+ /config
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'pry'
7
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ reslike-dash (0.2.2)
5
+ erubis (>= 2.7.0)
6
+ multi_json (= 1.3.6)
7
+ riemann-client (>= 0.0.7)
8
+ sass (>= 3.1.14)
9
+ sinatra (>= 1.3.2)
10
+ thin (>= 1.3.1)
11
+
12
+ GEM
13
+ remote: http://rubygems.org/
14
+ specs:
15
+ beefcake (0.3.7)
16
+ coderay (1.0.9)
17
+ daemons (1.1.9)
18
+ erubis (2.7.0)
19
+ eventmachine (1.0.3)
20
+ method_source (0.8.1)
21
+ mtrc (0.0.4)
22
+ multi_json (1.3.6)
23
+ pry (0.9.12)
24
+ coderay (~> 1.0.5)
25
+ method_source (~> 0.8)
26
+ slop (~> 3.4)
27
+ rack (1.5.2)
28
+ rack-protection (1.4.0)
29
+ rack
30
+ riemann-client (0.0.8)
31
+ beefcake (>= 0.3.5)
32
+ mtrc (>= 0.0.4)
33
+ trollop (>= 1.16.2)
34
+ sass (3.2.7)
35
+ sinatra (1.3.5)
36
+ rack (~> 1.4)
37
+ rack-protection (~> 1.3)
38
+ tilt (~> 1.3, >= 1.3.3)
39
+ slop (3.4.3)
40
+ thin (1.5.0)
41
+ daemons (>= 1.0.9)
42
+ eventmachine (>= 0.12.6)
43
+ rack (>= 1.0.0)
44
+ tilt (1.3.5)
45
+ trollop (2.0)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ pry
52
+ reslike-dash!
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011 Kyle Kingsbury
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,52 @@
1
+ Riemann-Dash
2
+ ============
3
+
4
+ A javascript, websockets-powered dashboard for Riemann.
5
+
6
+ Get started
7
+ ==========
8
+
9
+ ``` bash
10
+ $ gem install riemann-dash
11
+ $ riemann-dash
12
+ ```
13
+
14
+ Then open http://localhost:4567 in a browser. Riemann-dash will connect to the local host (relative to your browser) by default, and show you a small manual.
15
+
16
+ Configuring
17
+ ===========
18
+
19
+ Riemann-dash takes an optional config file, which you can specify as the first
20
+ command-line argument. If none is given, it looks for a file in the local
21
+ directory: config.rb. That file can override any configuration options on the
22
+ Dash class, and hence, all Sinatra configuration.
23
+
24
+ ``` ruby
25
+ set :port, 6000 # HTTP server on port 6000
26
+ config[:ws_config] = 'custom/config.json' # Specify custom workspace config
27
+ ```
28
+
29
+
30
+
31
+ Development
32
+ ===========
33
+
34
+ $ git clone git://github.com/aphyr/riemann-dash.git
35
+ $ cd riemann-dash
36
+ $ bundle
37
+
38
+ Testing
39
+ =======
40
+ # run tests
41
+ $ sh/test
42
+
43
+ Releasing
44
+ ==========
45
+ $ rake build
46
+ $ rake release
47
+
48
+ REPL
49
+ ====
50
+ $ sh/c
51
+ > irb :001 > Riemann::Dash::VERSION
52
+ > => "0.2.2"
data/Rakefile.rb ADDED
@@ -0,0 +1,11 @@
1
+ #$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+ #require 'rubygems'
3
+ require "bundler/gem_tasks"
4
+
5
+ task :default => :test
6
+ require 'rake/testtask'
7
+ Rake::TestTask.new do |t|
8
+ t.libs.push "lib"
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ t.verbose = false
11
+ end
data/bin/riemann-dash ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
4
+ require 'riemann/dash'
5
+
6
+ Riemann::Dash::App.load ARGV.first
7
+ Riemann::Dash::App.run!
data/example/config.rb ADDED
@@ -0,0 +1,17 @@
1
+ # Serve HTTP traffic on this port
2
+ set :port, 4567
3
+
4
+ riemann_base = '.'
5
+ riemann_src = "${riemann_base}/lib/riemann/dash"
6
+
7
+ # Add custom controllers in controller/
8
+ config.store[:controllers] = ["#{riemann_src}/controller"]
9
+
10
+ # Use the local view directory instead of the default
11
+ config.store[:views] = "#{riemann_src}/views"
12
+
13
+ # Specify a custom path to your workspace config.json
14
+ config.store[:ws_config] = "#{riemann_base}/config/config.json"
15
+
16
+ # Serve static files from this directory
17
+ config.store[:public] = "#{riemann_src}/public"
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'sinatra/base'
3
+ require 'riemann/dash/version'
4
+ require 'riemann/dash/config'
5
+ require 'riemann/dash/app'
@@ -0,0 +1,32 @@
1
+ module Riemann
2
+ module Dash
3
+ class App < Sinatra::Base
4
+ # A little dashboard sinatra application.
5
+
6
+ require 'yaml'
7
+ require 'find'
8
+ require 'erubis'
9
+ require 'sass'
10
+
11
+ def self.config
12
+ Riemann::Dash::Config.instance
13
+ end
14
+
15
+ def config
16
+ self.class.config
17
+ end
18
+
19
+ def self.load(filename)
20
+ filename ||= 'config.rb'
21
+ unless config.load_config(filename)
22
+ # Configuration failed; load a default view.
23
+ puts "No configuration loaded; using defaults."
24
+ end
25
+
26
+ config.load_controllers
27
+ config.setup_views
28
+ config.setup_public_dir
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,154 @@
1
+ class Riemann::Dash::Config
2
+ attr_accessor :config_path
3
+ attr_accessor :store
4
+
5
+ def initialize
6
+ self.store = {}
7
+ setup_default_values
8
+ end
9
+
10
+ def self.instance
11
+ @instance ||= Riemann::Dash::Config.new
12
+ end
13
+
14
+ def self.reset!
15
+ @instance = nil
16
+ end
17
+
18
+ def setup_default_values
19
+ store.merge!({
20
+ :controllers => [File.join(File.dirname(__FILE__), 'controller')],
21
+ :views => File.join(File.dirname(__FILE__), 'views'),
22
+ :ws_config => File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'config.json')),
23
+ :public => File.join(File.dirname(__FILE__), 'public')
24
+ })
25
+ end
26
+
27
+ def ws_config_file
28
+ store[:ws_config]
29
+ end
30
+
31
+ # backwards compatible forwarder to store-ivar
32
+ def [](k)
33
+ store[k]
34
+ end
35
+
36
+ def []=(k,v)
37
+ store[k] = v
38
+ end
39
+
40
+
41
+ # Executes the configuration file.
42
+ def load_config(path)
43
+ self.config_path = path
44
+ begin
45
+ Riemann::Dash::App.instance_eval File.read(config_path)
46
+ true
47
+ rescue Errno::ENOENT
48
+ false
49
+ end
50
+ end
51
+
52
+ def load_controllers
53
+ store[:controllers].each { |d| load_controllers_from(d) }
54
+ end
55
+
56
+ def setup_views
57
+ Riemann::Dash::App.set :views, File.expand_path(store[:views])
58
+ end
59
+
60
+ def setup_public_dir
61
+ require 'riemann/dash/rack/static'
62
+ Riemann::Dash::App.use Riemann::Dash::Static, :root => store[:public]
63
+ end
64
+
65
+ # Load controllers.
66
+ def load_controllers_from(dir)
67
+ sorted_controller_list(dir).each do |r|
68
+ require r
69
+ end
70
+ end
71
+
72
+ # Controllers can be regular old one-file-per-class, but
73
+ # if you prefer a little more modularity, this method will allow you to
74
+ # define all controller methods in their own files. For example, get
75
+ # "/posts/*/edit" can live in controller/posts/_/edit.rb. The sorting
76
+ # system provided here requires files in the correct order to handle
77
+ # wildcards appropriately.
78
+ def sorted_controller_list(dir)
79
+ rbs = []
80
+ Find.find(
81
+ File.expand_path(dir)
82
+ ) do |path|
83
+ rbs << path if path =~ /\.rb$/
84
+ end
85
+
86
+ # Sort paths with _ last, becase those are wildcards.
87
+ rbs.sort! do |a, b|
88
+ as = a.split File::SEPARATOR
89
+ bs = b.split File::SEPARATOR
90
+
91
+ # Compare common subpaths
92
+ l = [as.size, bs.size].min
93
+ catch :x do
94
+ (0...l).each do |i|
95
+ a, b = as[i], bs[i]
96
+ if a[/^_/] and not b[/^_/]
97
+ throw :x, 1
98
+ elsif b[/^_/] and not a[/^_/]
99
+ throw :x, -1
100
+ elsif ord = (a <=> b) and ord != 0
101
+ throw :x, ord
102
+ end
103
+ end
104
+
105
+ # All subpaths are identical; sort longest first
106
+ if as.size > bs.size
107
+ throw :x, -1
108
+ elsif as.size < bs.size
109
+ throw :x, -1
110
+ else
111
+ throw :x, 0
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+
118
+ require 'multi_json'
119
+ require 'fileutils'
120
+
121
+
122
+ def read_ws_config
123
+ if File.exists? ws_config_file
124
+ File.read(ws_config_file)
125
+ else
126
+ MultiJson.encode({})
127
+ end
128
+ end
129
+
130
+ def update_ws_config(update)
131
+ update = MultiJson.decode(update)
132
+
133
+ # Read old config
134
+ if File.exists? ws_config_file
135
+ old = MultiJson.decode File.read(ws_config_file)
136
+ else
137
+ old = {}
138
+ end
139
+
140
+ new_config = {}
141
+
142
+ # Server
143
+ new_config['server'] = update['server'] or old['server']
144
+
145
+ #p update['workspaces']
146
+ new_config['workspaces'] = update['workspaces'] or old['workspaces']
147
+
148
+ # Save new config
149
+ FileUtils.mkdir_p File.dirname(ws_config_file)
150
+ File.open(ws_config_file, 'w') do |f|
151
+ f.write(MultiJson.encode(new_config, :pretty => true))
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,5 @@
1
+ class Riemann::Dash::App
2
+ get '/css' do
3
+ scss :css, :layout => false
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ class Riemann::Dash::App
2
+ get '/' do
3
+ erb :index, :layout => false
4
+ end
5
+
6
+ get '/config', :provides => 'json' do
7
+ content_type "application/json"
8
+ config.read_ws_config
9
+ end
10
+
11
+ post '/config' do
12
+ # Read update
13
+ request.body.rewind
14
+ config.update_ws_config(request.body.read)
15
+
16
+ # Return current config
17
+ content_type "application/json"
18
+ config.read_ws_config
19
+ end
20
+ end
@@ -0,0 +1,45 @@
1
+ // Global clock
2
+ var clock = (function() {
3
+ var clock = new Date();
4
+ var offset = 0;
5
+ var callback_i = 0;
6
+ var callbacks = {};
7
+
8
+ var advance = function(t) {
9
+ if (clock < t) {
10
+ // New local offset
11
+ offset = t - (new Date());
12
+ //console.log("new offset is", offset);
13
+
14
+ clock = t;
15
+ }
16
+ //console.log("Clock is", clock);
17
+ }
18
+
19
+ var register = function(f) {
20
+ callback_i = callback_i + 1;
21
+ callbacks[callback_i] = f;
22
+ return callback_i;
23
+ }
24
+
25
+ var unregister = function(i) {
26
+ callbacks.delete(i);
27
+ }
28
+
29
+ // Automatically advance clock.
30
+ setInterval(function() {
31
+ offset = offset * 0.99;
32
+ advance(new Date(new Date().valueOf() + offset));
33
+ $.each(callbacks, function(k, f) {
34
+ f(clock);
35
+ });
36
+ }, 1000);
37
+
38
+ return {
39
+ 'clock': clock,
40
+ 'offset': offset,
41
+ 'advance': advance,
42
+ 'register': register,
43
+ 'unregister': unregister
44
+ }
45
+ })();