arvicco-avalon 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,9 +6,9 @@ Helper scripts for Bitcoin and Avalon miners management...
6
6
 
7
7
  Scripts:
8
8
 
9
- $ bin/monitor [last_ip]
9
+ $ bin/monitor [environment]
10
10
 
11
- - Monitors all miners from 151 to last_ip (default 182)
11
+ - Monitors all the nodes (miners, pools, Internet connections) that are listed in config/monitor.yml file. Sounds alarm is anything is wrong with the monitored nodes. TODO: takes action to correct errors found (like restarting the miners etc).
12
12
 
13
13
  $ mtgox_tx
14
14
 
@@ -16,23 +16,23 @@ $ mtgox_tx
16
16
 
17
17
  ## Configuration
18
18
 
19
- Sample monitor config file for production environment below. Modify it, add your own nodes to be monitored.
20
-
21
- ------- config/monitor.yml --------
22
- # Prod configuration
23
- prod:
24
- :bitcoind:
25
- :ip: 192.168.1.13
26
- :rpcuser: jbond
27
- :rpcpassword: youcannotguessitdonteventry
28
- :monitor:
29
- :verbose: true
30
- :timeout: 30
31
- :nodes:
32
- - [miner, 192.168.1.151, 70] # type, ip, gh/s
33
- - [miner, 192.168.1.152, 70]
34
- - [eloipool, 192.168.1.13, 4] # frequency of old block updates (once per X polls)
35
- - [internet, www.google.com, www.speedtest.net]
19
+ Sample monitor config file for production environment below. Modify it, add your own nodes to be monitored (for Avalon miners, you have to set their IP address and min hashrate in Gh/s):
20
+
21
+ ------- config/monitor.yml --------
22
+ # Prod configuration (default)
23
+ prod:
24
+ :bitcoind:
25
+ :ip: 192.168.1.13
26
+ :rpcuser: jbond
27
+ :rpcpassword: youcannotguessitdonteventry
28
+ :monitor:
29
+ :verbose: true
30
+ :timeout: 30
31
+ :nodes:
32
+ - [miner, 192.168.1.151, 70] # type, ip, gh/s
33
+ - [miner, 192.168.1.152, 70]
34
+ - [eloipool, 192.168.1.13, 4] # frequency of old block updates (once per X polls)
35
+ - [internet, www.google.com, www.speedtest.net]
36
36
 
37
37
  ## License
38
38
 
@@ -2,6 +2,7 @@ require 'pp'
2
2
  require 'time'
3
3
 
4
4
  require "avalon/version"
5
+ require "avalon/utils"
5
6
  require "avalon/blockchain"
6
7
  require "avalon/bitcoind"
7
8
  require "avalon/config"
@@ -39,7 +39,7 @@ module Avalon
39
39
  @ip = ip
40
40
  @num = ip.split('.').last.to_i
41
41
  @min_speed = min_speed * 1000 # Gh/s to Mh/s
42
- @blanks = 0
42
+ @fails = 0
43
43
  super()
44
44
  end
45
45
 
@@ -70,10 +70,12 @@ module Avalon
70
70
  # Check for any exceptional situations in stats, sound alarm if any
71
71
  def report
72
72
  if data[:ping].nil?
73
- @blanks += 1
74
- alarm "Miner #{@num} did not respond to status query" if @blanks > 2
73
+ @fails += 1
74
+ if @fails >= Avalon::Config[:status_fails_to_alarm] || 1
75
+ alarm "Miner #{@num} did not respond to status query"
76
+ end
75
77
  else
76
- @blanks = 0
78
+ @fails = 0
77
79
  if self[:mhs] < @min_speed*0.95 and upminutes > 5
78
80
  alarm "Miner #{@num} performance is #{self[:mhs]}, should be #{@min_speed}"
79
81
  elsif upminutes < 2
@@ -20,6 +20,7 @@ module Avalon
20
20
  # Report node errors (if any)
21
21
  @nodes.each {|node| node.report}
22
22
 
23
+ @nodes.first.alarm 'Poll completed', 'Purr.aiff'
23
24
  sleep @timeout
24
25
 
25
26
  end
@@ -3,6 +3,7 @@ module Avalon
3
3
  # Node is a single object to be monitored
4
4
  # It should implement simple interface, only 2 required methods: #poll and #report
5
5
  class Node
6
+ include Utils # Helper methods
6
7
 
7
8
  # Builder method for creating Node subclasses from config arrays
8
9
  def Node.create *args
@@ -26,25 +27,6 @@ module Avalon
26
27
  @data[key] = value
27
28
  end
28
29
 
29
- # Helper method: sound alarm with message
30
- def alarm message, *tunes
31
- puts message
32
-
33
- tunes.push('Glass.aiff') if tunes.empty?
34
-
35
- tunes.each do |tune|
36
- File.exist?(tune) ? `afplay #{tune}` : `afplay /System/Library/Sounds/#{tune}`
37
- end
38
- end
39
-
40
- # Helper method: ping the Node
41
- def ping ip
42
- ping_result = `ping -c 1 #{ip}`
43
- if ping_result =~ / 0.0% packet loss/
44
- ping_result.match(/time=([\.\d]*) ms/)[1].to_f
45
- end
46
- end
47
-
48
30
  # Abstract: Check node status
49
31
  # If verbose, the Node should print out its state after the status update
50
32
  def poll verbose
@@ -0,0 +1,43 @@
1
+ module Avalon
2
+ module Utils
3
+
4
+ def system
5
+ @system = `uname -a`.match(/^\w*/).to_s
6
+ end
7
+
8
+ # Helper method: play a sound file
9
+ def play tune
10
+ file = [ tune,
11
+ File.expand_path("../../../sound/#{tune}", __FILE__),
12
+ File.expand_path("~/sound/#{tune}", __FILE__),
13
+ File.expand_path("/System/Library/Sounds/#{tune}")
14
+ ].find {|f| File.exist?(f)}
15
+
16
+ case system
17
+ when 'Darwin'
18
+ `afplay #{file}`
19
+ when 'Linux'
20
+ raise 'Please install sox package: sudo apt-get install sox' if `which sox`.empty?
21
+ `play #{file}`
22
+ end
23
+ end
24
+
25
+ # Helper method: sound alarm with message
26
+ def alarm message, *tunes
27
+ puts message
28
+
29
+ tunes.push('Glass.aiff') if tunes.empty?
30
+
31
+ tunes.each {|tune| play tune }
32
+ end
33
+
34
+ # Helper method: ping the Node, return ping time in ms
35
+ def ping ip
36
+ ping_result = `ping -c 1 #{ip}`
37
+ if ping_result =~ / 0.0% packet loss/
38
+ ping_result.match(/time=([\.\d]*) ms/)[1].to_f
39
+ end
40
+ end
41
+
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module Avalon
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
Binary file
Binary file
Binary file
Binary file
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arvicco-avalon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-05 00:00:00.000000000 Z
12
+ date: 2013-06-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -55,7 +55,13 @@ files:
55
55
  - lib/avalon/miner.rb
56
56
  - lib/avalon/monitor.rb
57
57
  - lib/avalon/node.rb
58
+ - lib/avalon/utils.rb
58
59
  - lib/avalon/version.rb
60
+ - sound/Dog.aiff
61
+ - sound/Frog.aiff
62
+ - sound/Glass.aiff
63
+ - sound/Ping.aiff
64
+ - sound/Purr.aiff
59
65
  homepage: https://github.com/arvicco/avalon
60
66
  licenses: []
61
67
  post_install_message: