Author

Topic: [ANN] bcmon: Monitor your Blades/Cubes/Avalons/AntMinerS1 all at once (linux) (Read 2597 times)

newbie
Activity: 13
Merit: 0
Solved problem:

on each antminer we must edit:
Code:
vim /etc/config/cgminer

find:

Code:
option api_allow 'W:127.0.0.1'

replace:

Code:
option api_allow 'W:127.0.0.1,W:192.168.x.x'


where 192.168.x.x is your server on which you want check bcmon

additional for non english languages linux add new line in top of file: minread

Quote
LC_NUMERIC=C LC_COLLATE=C
newbie
Activity: 13
Merit: 0
I replaced file api-example.py (from distro https://raw.github.com/luke-jr/bfgminer/bfgminer/api-example.py ) and is ok

I have another problem:

~/bin# ./minread ant4 192.168.3.34 4028
(standard_in) 1: syntax error
ant4    :   0,000    0,00%     0/m  |           0        0           0:00:00:00

How solve this problem?
newbie
Activity: 13
Merit: 0
Traceback (most recent call last):
  File "./api-example.py", line 53, in
    response = linesplit(s)
  File "./api-example.py", line 21, in linesplit
    buffer = socket.recv(4096)
socket.error: [Errno 104] Connection reset by peer


I have problem with connections to antminers S1

what is the errno 104 ?

I tested using: ./api-example.py stats 192.168.3.34 4028
full member
Activity: 177
Merit: 100
Cool, I'll give this a try!

8 )
sr. member
Activity: 280
Merit: 250
Helperizer
26 Jan 2014:  Tightened up the code and made it more robust in case of API info out of order (or reporting GH/s versus MH/s).
                   Also added temperature support for AntMiner S1 units.
sr. member
Activity: 280
Merit: 250
Helperizer
21 Jan 2014:  Tightened up the layout and added temperature support (only tested for Chilis and Avalons, but might work with others).
sr. member
Activity: 280
Merit: 250
Helperizer
sr. member
Activity: 280
Merit: 250
Helperizer
New Version: 26 Jan 2014

Linux/unix shell-based miner monitoring for blades, cubes, antminers, avalons, and anything that works within cgminer/bfgminer.  Added temperature display support for avalons, antminer S1s, chilis - others might work too but I don't have the gear to test them.

I have several cubes, and I usually run the stratum_proxy.py from slush so it's hard to monitor them in one place.  So, I wrote a few scripts to do the work for me, bcread (to read blades and cubes), minread (to read API output from Avalons and AntMiner S1s, as well as miners like cgminer/bfgminer), and bcshow (to show all that data).  I invoke with
Code:
watch -n 10 bcshow
or its "bcmon" alias
Code:
alias bcmon='watch -n 10 bcshow'
and then I get 10-second updates for all blades and cubes in one handy text window.

It occurred to me that I probably wasn't the only one in this situation, so I thought I'd share.  The code is not pretty, but it should work fine under most versions of linux.  The comments indicate where most of the configuration should be done, but feel free to modify to your liking.  Copy these files to your ~/bin directory and chmod +x them and you should be good to go after setting a couple of variables.

There are also api-reads to monitor any other miners you have that are set up with api-listen, api-allow, and api-port so they can be monitored.  It requires the api-example.py script from bfgminer (or similar).

Enjoy - hope this is useful to someone!  Tips are welcome but not at all required (BTC: 1GY9wmMmw1E7DPLzQXt4UPuEuHQN29PixD).

Here's a window shot of it in action (nothing fancy but most of the monitoring info is there):


bcread:
Code:
#!/bin/bash

# These scripts assume your blades are between 192.168.1.200 and 192.168.1.210
#       and your cubes are 192.168.1.211 and higher.  If you have a different
#       configuration, please edit the cutoff numbers here:
bladelow=200
bladehigh=210

# Enter your network prefix here.  If your network is 192.168.1.x,
#       then just enter the first 3 portions, as below:
net="192.168.1"

# The web interfaces are standard, i.e. port 8000 for both blades and cubes

if [ "$1" = "" ] ; then exit ; fi

dev="blade"
spc=""

n=$(($1-$bladelow))

if [ $1 -gt $bladehigh ] ; then
   dev="cube"
   n=$(echo -n $(($1-$bladehigh))" ")
   spc="   "
fi

if [ $1 -le $bladehigh ] ; then
      t=$(curl -s http://$net.$1:8000 | sed 's/^.*MHS:/MHS:/' | sed 's/s<\/.*/s/' | sed 's/<[^>]*>/ /g' | sed 's/:/: /g' | tr -s " ")
      mp=2 ; jp=4 ; ap=6 ; wup=9 ; ep=11 ; upp=14
else
      t=$(curl -s http://$net.$1:8000 | sed 's/^.*Jobs:/Jobs:/' | sed 's/s<\/.*/s/' | sed 's/<[^>]*>/ /g' | sed 's/:/: /g' | tr -s " ")
      mp=13 ; jp=2 ; ap=4 ; wup=15 ; ep=17 ; upp=20
fi
tmh=$(echo $t | cut -f $mp -d " ")
if [ "$tmh" = "" ] ; then tmh=0 ; fi
gh=$(printf "% 6.3f\n" $(echo $tmh/1000 | bc -l))

tjobs=$(echo $t | cut -f $jp -d " " | sed 's/^0*//')
if [ "$tjobs" = "" ] ; then tjobs=0 ; fi

tacc=$(echo $t | cut -f $ap -d " " | sed 's/^0*//')
acc=$(printf "% 9.0f\n" $tacc)
if [ "$tacc" = "" ] ; then tacc=0 ; fi

let tlost=$tjobs-$tacc
lost=$(printf "% 9.0f\n" $tlost)

tutil=$(echo $t | cut -f $wup -d " ")
util=$(printf "% 3.0f\n" $tutil)

teff=$(echo $t | cut -f $ep -d " ")
numeff=$(echo $teff | cut -d "%" -f 1)
eff=$(printf "% 6.2f\n" $numeff)

tup=$(echo $t | cut -f $upp -d " " | sed 's/[a-z],/:/g' | sed 's/s$//')

printf "% -7s" "$dev $n "
printf "% 2s" " :"
printf "% 8s" $gh
printf "% 9s" "$eff%"
printf "% 12s" "$util/m  | "
printf "% 11s" $acc
printf "% 9s" $lost
printf "% 21s\n" $tup

bcshow:
Code:
#!/bin/bash                                                                     
                                                                                
# Enter the last portion of the ip address of each blade and cube, and          
#       a "0" indicates you want a line skipped.  Use your own numbers          
#       below - these are just my examples.                                    
ips=(211 212 213 214 215 216 217 )                                              
                                                                                
# If you're doing API reads of other miners, enter their info here,            
# using an array format of "miner name", "host", "port"                        
#   Note: you must have all three for each miner, no fancy error traps here!    
#   Please delete my entries below - they're just there for examples            
apis=(avalon avalon 4028                                                        
         ant.1 ant1 4028                                                        
         ant.2 ant2 4028                                                        
         cubemine tyenas 4211                                                  
         chili.1 tyenas 4231                                                    
         chili.2 kira 4232                                                      
         blademine tyenas 4201                                                  
         ant-u1s rita 4224                                                      
         redfurys tyenas 4221                                                  
         erupters tye 4222)                                                    
                                                                                
let tot=0                                                                      
                                                                                
#echo -------------------------------------------------------------------------$
echo "             GH/s     Eff     Util         Accepts     Lost   Temp    Upt$
echo --------------------------------------------------------------------------$
for ip in ${ips[@]}                                                            
do                                                                              
   if [ "$ip" -gt 0 ] ; then                                                    
      tmh=0                                                                    
      . bcread $ip                                                              
      ttt=$((10#$tmh))                                                          
      let tot="$tot"+"$ttt"                                                    
   else                                                                        
      echo "           :                           |"                          
   fi                                                                          
done                                                                            
                                                                                
# get do minread here for other things running via bfgminer/cgminer...          
for i in $( seq 0 3 $(echo ${#apis[@]}-3 | bc -l ))                            
do                                                                              
   tmh=0                                                                        
   . minread ${apis[$i]} ${apis[$i+1]} ${apis[$i+2]}                            
   ttt=$((10#$(echo $tmh | sed 's/\..*//')))                                    
   let tot="$tot"+"$ttt"                                                        
done                                                                            
echo --------------------------------------------------------------------------$
printf "Total      %6.3f GH/s" $(echo $tot/1000 | bc -l)                        
echo

minread:
Code:
#!/bin/bash

if [ $1 = "" ] ; then exit ; fi

dev=$1
host=$2
port=$3
temp1=0
temp2=0

if [ "$(nc -z $host $port ; echo $?)" = "0" ] ; then

t=$(api-example.py --host $host --port $port | sed 's/^.* u.//' \
    | sed 's/,$//' | sed 's/.: /:/' \
    | sed 's/ //g' | sed 's/SUMM*u././' | grep -v "'")

  tmh=$(echo $t | sed 's/ /\n/g' | grep "MHSav" | cut -f 2 -d ":")
  if [ "$tmh" = "" ] ; then tmh=0 ; fi
  tgh=$(echo $t | sed 's/ /\n/g' | grep "GHSav" | cut -f 2 -d ":")
  if [ "$tgh" = "" ] ; then tgh=0 ; fi
  gh=$(printf "% 6.3f\n" $tgh)
  if [ $(echo $tmh | cut -f 1 -d ".") -gt 0 ] ; then
     gh=$(printf "% 6.3f\n" $(echo $tmh/1000 | bc -l))
  else
     tmh=$(echo $tgh*1000 | bc -l)
  fi
  tmh=$(echo $tmh | cut -f 1 -d ".")

  tacc=$(echo $t | sed 's/ /\n/g' | grep "Accepted" | cut -f 2 -d ":")
  acc=$(printf "% 9.0f\n" $tacc)

  trej=$(echo $t | sed 's/ /\n/g' | grep "DifficultyRejected" \
  | cut -f 2 -d ":")
  tdis=$(echo $t | sed 's/ /\n/g' | grep "Discarded" | cut -f 2 -d ":")
  if [ "$trej" = "" ] ; then trej=0 ; fi
  if [ "$tdis" = "" ] ; then tdis=0 ; fi
  tlost=$(echo $trej+$tdis | bc -l)
  lost=$(printf "% 9.0f\n" $tlost)

  tutil=$(echo $t | sed 's/ /\n/g' | grep "WorkUtility" \
  | cut -f 2 -d ":" | sed 's/..$//')
  util=$(printf "% 3.0f\n" $tutil)

  tdevr=$(echo $t | sed 's/ /\n/g' | grep "DeviceRejected%" \
  | cut -f 2 -d ":")
  tdevhw=$(echo $t | sed 's/ /\n/g' | grep "DeviceHardware%" \
  | cut -f 2 -d ":")
  numeff=$(echo 100-$tdevr-$tdevhw | bc -l)
  eff=$(printf "% 6.2f\n" $numeff)

  d=0 ; h=0 ; m=0 ; s=0
  if [ "$tmh" -gt 0 ] ; then
    totmh=$(echo $t | sed 's/ /\n/g' | grep "TotalMH" | cut -f 2 -d ":")
    time=$(echo $totmh/$tmh | bc -l )
    tsec=$((10#$(echo $time | cut -d "." -f 1 )))
      d=$(($tsec/86400))
      h=$(($tsec/3600))
      m=$((($tsec/60)%60))
      s=$(($tsec%60))
  fi

  tup=$( printf "%01dd,%02dh,%02dm,%02ds\n" $d $h $m $s  \
              | sed 's/[a-z],/:/g' | sed 's/s$//' )

  printf "% -9s" "$dev"
  printf "% 1s" ":"
  printf "% 8s" $gh
  printf "% 9s" "$eff%"
  printf "% 12s" "$util/m  | "
  printf "% 11s" $acc
  printf "% 9s" $lost

  $(api-example.py stats --hostname $host --port $port | \
     grep 'temp[12]\|Temper' | \
     sed 's/Temperature0/temp1/' | sed 's/Temperature1/temp2/' | \
     sed 's/^.*u./let /' | \
     sed 's/.: /=/' | cut -d "." -f 1 | \
     sed 's/,//')

  if [ $temp1 -gt 0 ] ; then
    printf "% 8s" "$temp1,$temp2"
    printf "% 13s\n" $tup
  else
    printf "% 21s\n" $tup
  fi

else

  if [ "$port" != "4201" ] && [ "$port" != "4211" ] && [ "$port" != "4232" ] ; then
    printf "% -9s" "$dev"
    printf "% 1s" ":"
    echo "   -----   -----    -----  |"
    tmh="0.0"
  fi

fi

You also need  api-example.py from the bfgminer distro (it's not mine to distribute, so I won't do that without permission).

Under the hood:  Basically it just scrapes the web interfaces of the blades and cubes and picks out the info I wanted to monitor, then parses it, displays it and does a total hashrate.  Then it does API calls and scrapes and formats that data.  Simple and probably not nearly as elegant as it should be, but I'm a quick and dirty "basher" when I can get away with it.  Wink

No doubt these scripts could be easily modified to scrape other miners with web interfaces that don't have APIs, but since I don't have those other miners (and no doubt no-one will donate to me), that is an exercise left to the reader.  Wink
Jump to: