Advertisement
Guest User

ypool-stats.sh

a guest
Nov 28th, 2013
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.04 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # This script harvest some data from ypool PTS pool
  4. # Autor: Yago
  5. # License:  WTFPL http://www.wtfpl.net/txt/copying/
  6.  
  7. HTTP_TIMEOUT=5 # seconds
  8. MINING_TIMEOUT=5 # seconds
  9. TMP=/tmp/ypool-stats
  10.  
  11. mkdir -p $TMP
  12.  
  13.  
  14. harvest() {
  15.     # login to ypool
  16.     wget --quiet --save-cookies /tmp/ycookies.txt --post-data="login_username=sternburg&login_password=poemacatedral" "http://ypool.net/howto?ct=3" -O $TMP/howto.html
  17.  
  18.     # harvest mining ports
  19.     awk -F "mining: <b>"  '{print $2}' $TMP/howto.html | awk -F '<' '{print $1}' | perl -pe 's/, /\n/g' > $TMP/ports
  20.  
  21.     # harvest Workers
  22.     WORKERS=`awk -F 'stats_pool_worker">' '{print $2}' /tmp/howto.html | awk -F '<' '{print $1}'`
  23.  
  24.     # harvest hashrate (coll/m)
  25.     HASHRATE=`awk -F 'stats_pool_hashrate">' '{print $2}' /tmp/howto.html | awk -F '<' '{print $1}'`
  26.  
  27.     # harvest Blocks found last 24h
  28.     wget --quiet --load-cookies /tmp/ycookies.txt "http://ypool.net/pts/stats_overall" -O $TMP/poolstats.html
  29.     BLOCKSLAST24H=`perl -pe 's/<td>1 Hour/\n<td>1 Hour/g' $TMP/poolstats.html | perl -pe 's/table>/\n/g' | grep "Hour" | awk -F '>' '{print $26}' | perl -pe 's/<\/td//g'`
  30.  
  31. }
  32.  
  33. checkminingports() {
  34.  
  35.     # List of the working mining ports as of 28/nov/2013
  36.     # just in case HTTP is down and $TMP got deleted
  37.     if [ ! -f $TMP/ports ]; then
  38.         echo "8080
  39. 8081
  40. 8082
  41. 8083
  42. 8084
  43. 8085
  44. 8086
  45. 8087
  46. 10034" > $TMP/ports
  47.     fi
  48.  
  49. MINING_PORT_STATUS=""
  50.  
  51.     while read PORT
  52.     do
  53.         nc -z -w$MINING_TIMEOUT ypool.net $PORT
  54.         if [ $? -eq 0 ]; then
  55.             MINING_PORT_STATUS="$MINING_PORT_STATUS $PORT:up"
  56.         else
  57.             MINING_PORT_STATUS="$MINING_PORT_STATUS $PORT:DOWN :("
  58.         fi
  59.    
  60.     done <$TMP/ports
  61.  
  62. }
  63.  
  64.  
  65. # check http
  66. wget --quiet --timeout=$HTTP_TIMEOUT http://ypool.net -O /dev/null
  67. if [ $? -eq 0 ]; then
  68.     harvest
  69.     checkminingports
  70.     echo "YPOOL status: HTTP:80 up, Mining:$MINING_PORT_STATUS, Workers: $WORKERS, coll/m: $HASHRATE, Blocks found last 24h: $BLOCKSLAST24H"
  71. else
  72.     checkminingports
  73.     echo "YPOOL status: HTTP:80 down :/, Mining:$MINING_PORT_STATUS, Workers,coll/m,Blocks found last 24h: data source down."
  74. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement