Class: Avalon::Monitor
- Inherits:
-
Object
- Object
- Avalon::Monitor
- Defined in:
- lib/avalon/monitor.rb
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
-
#switches ⇒ Object
readonly
Returns the value of attribute switches.
Instance Method Summary collapse
-
#initialize(opts) ⇒ Monitor
constructor
List of nodes to monitor.
- #run ⇒ Object
Constructor Details
#initialize(opts) ⇒ Monitor
List of nodes to monitor
8 9 10 11 12 13 14 |
# File 'lib/avalon/monitor.rb', line 8 def initialize opts @timeout = opts[:timeout] || 30 @verbose = opts[:verbose] @switches = (opts[:switches] || []).map {|args| Avalon::Switch.new(*args)} @nodes = opts[:nodes].map {|args| Avalon::Node.create(self, *args)} @pool = @nodes.find {|node| node.is_a?(Avalon::Btcguild)} end |
Instance Attribute Details
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
5 6 7 |
# File 'lib/avalon/monitor.rb', line 5 def nodes @nodes end |
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
5 6 7 |
# File 'lib/avalon/monitor.rb', line 5 def pool @pool end |
#switches ⇒ Object (readonly)
Returns the value of attribute switches.
5 6 7 |
# File 'lib/avalon/monitor.rb', line 5 def switches @switches end |
Instance Method Details
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/avalon/monitor.rb', line 16 def run loop do # Check status for all nodes @nodes.inject(false) do |headers_printed, node| # Print miners headers once first miner encountered if @verbose && node.is_a?(Avalon::Miner) && !headers_printed Avalon::Miner.print_headers headers_printed = true end node.poll(@verbose) headers_printed end # Report node errors (if any) @nodes.each {|node| node.report} if @verbose unit_hash = @nodes.reduce(0) {|hash, node| hash + (node.unit_hash || 0)} pool_hash = @nodes.reduce(0) {|hash, node| hash + (node.pool_hash || 0)} puts "Total hash rate (from pool): #{unit_hash} (#{pool_hash}) MH/s" end sleep @timeout end end |