Class: Dasht::Base
- Inherits:
-
Object
- Object
- Dasht::Base
- Defined in:
- lib/dasht/base.rb
Instance Attribute Summary collapse
-
#background ⇒ Object
Returns the value of attribute background.
-
#boards ⇒ Object
Returns the value of attribute boards.
-
#default_height ⇒ Object
Returns the value of attribute default_height.
-
#default_refresh ⇒ Object
Returns the value of attribute default_refresh.
-
#default_resolution ⇒ Object
Returns the value of attribute default_resolution.
-
#default_width ⇒ Object
Returns the value of attribute default_width.
-
#history ⇒ Object
Returns the value of attribute history.
-
#metrics ⇒ Object
Returns the value of attribute metrics.
-
#port ⇒ Object
Settings.
-
#rack_app ⇒ Object
Returns the value of attribute rack_app.
-
#reloader ⇒ Object
Returns the value of attribute reloader.
Instance Method Summary collapse
- #board(name = "default") {|board| ... } ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #interval(metric, &block) ⇒ Object
- #log(s) ⇒ Object
- #reload(&block) ⇒ Object
-
#run(&block) ⇒ Object
RUN & RELOAD ###.
-
#start(command) {|log_thread| ... } ⇒ Object
DATA INGESTION ###.
- #system_plugins_path ⇒ Object
- #tail(path) ⇒ Object
- #user_plugins_path ⇒ Object
-
#views_path ⇒ Object
DASHBOARD ###.
Constructor Details
Instance Attribute Details
#background ⇒ Object
Returns the value of attribute background.
10 11 12 |
# File 'lib/dasht/base.rb', line 10 def background @background end |
#boards ⇒ Object
Returns the value of attribute boards.
6 7 8 |
# File 'lib/dasht/base.rb', line 6 def boards @boards end |
#default_height ⇒ Object
Returns the value of attribute default_height.
14 15 16 |
# File 'lib/dasht/base.rb', line 14 def default_height @default_height end |
#default_refresh ⇒ Object
Returns the value of attribute default_refresh.
12 13 14 |
# File 'lib/dasht/base.rb', line 12 def default_refresh @default_refresh end |
#default_resolution ⇒ Object
Returns the value of attribute default_resolution.
11 12 13 |
# File 'lib/dasht/base.rb', line 11 def default_resolution @default_resolution end |
#default_width ⇒ Object
Returns the value of attribute default_width.
13 14 15 |
# File 'lib/dasht/base.rb', line 13 def default_width @default_width end |
#history ⇒ Object
Returns the value of attribute history.
15 16 17 |
# File 'lib/dasht/base.rb', line 15 def history @history end |
#metrics ⇒ Object
Returns the value of attribute metrics.
3 4 5 |
# File 'lib/dasht/base.rb', line 3 def metrics @metrics end |
#port ⇒ Object
Settings.
9 10 11 |
# File 'lib/dasht/base.rb', line 9 def port @port end |
#rack_app ⇒ Object
Returns the value of attribute rack_app.
4 5 6 |
# File 'lib/dasht/base.rb', line 4 def rack_app @rack_app end |
#reloader ⇒ Object
Returns the value of attribute reloader.
5 6 7 |
# File 'lib/dasht/base.rb', line 5 def reloader @reloader end |
Instance Method Details
#board(name = "default") {|board| ... } ⇒ Object
74 75 76 77 78 79 |
# File 'lib/dasht/base.rb', line 74 def board(name = "default", &block) name = name.to_s board = @boards[name] = Board.new(self, name) yield(board) if block board end |
#interval(metric, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dasht/base.rb', line 46 def interval(metric, &block) Thread.new do begin while true value = block.call metrics.set(metric, value, :last, Time.now.to_i) if value end rescue => e log e raise e end end end |
#log(s) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/dasht/base.rb', line 25 def log(s) if s.class < Exception print "\n#{s}\n" print s.backtrace.join("\n") else print "\r#{s}\n" end end |
#reload(&block) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/dasht/base.rb', line 102 def reload(&block) @boards = {} @log_threads.values.map(&:terminate) @log_threads = {} begin block.call(self) rescue => e log e raise e end @log_threads.values.map(&:run) end |
#run(&block) ⇒ Object
RUN & RELOAD ###
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/dasht/base.rb', line 83 def run(&block) if @already_running begin reload(&block) rescue => e log e end return end @already_running = true @reloader.run block.call(self) @log_threads.values.map(&:run) @rack_app.run(port) end |
#start(command) {|log_thread| ... } ⇒ Object
DATA INGESTION ###
36 37 38 39 40 |
# File 'lib/dasht/base.rb', line 36 def start(command, &block) log_thread = @log_threads[command] = LogThread.new(self, command) yield(log_thread) if block log_thread end |
#system_plugins_path ⇒ Object
66 67 68 |
# File 'lib/dasht/base.rb', line 66 def system_plugins_path File.join(File.dirname(__FILE__), "..", "..", "assets", "plugins") end |
#tail(path) ⇒ Object
42 43 44 |
# File 'lib/dasht/base.rb', line 42 def tail(path) start("tail -F -n 0 \"#{path}\"") end |
#user_plugins_path ⇒ Object
70 71 72 |
# File 'lib/dasht/base.rb', line 70 def user_plugins_path File.join(File.dirname($PROGRAM_NAME), "plugins") end |
#views_path ⇒ Object
DASHBOARD ###
62 63 64 |
# File 'lib/dasht/base.rb', line 62 def views_path File.join(File.dirname(__FILE__), "..", "..", "views") end |