rig-monitor icon indicating copy to clipboard operation
rig-monitor copied to clipboard

MODULE: profitability

Open wishbone1138 opened this issue 6 years ago • 6 comments

I'm having some issues with your profitability script. I'm not sure if it's my data, the script, or a combination of both. I haven't had the time to try and debug it as there is a lot going on, I'll leave this up here in case you have a second to look at it. I noticed that the EST earnings sections seem to be barfing on some of the values. Also I have multiple workers in some pools, I'm not sure the script is setup to handle that? Here's a full trace on a single pool.

+ SAVEIFS='
'
+ for POOL_LINE in '"${POOL_LIST[@]}"'
+ IFS=,
+ read POOL_TYPE CRYPTO LABEL BASE_API_URL API_TOKEN WALLET_ADDR
+ ((  DEBUG == 1  ))
+ echo ''

+ echo 'Pool info in conf file: NANOPOOL ETH NANO_ETH'
Pool info in conf file: NANOPOOL ETH NANO_ETH
+ PRICE=price_usd
+ VOLUME=24h_volume_usd
+ MARKET=market_cap_usd
+ COIN_DATA_SQL='select * from coin_data where crypto='\''ETH'\'''
++ jq -r '.results[0].series[0].values[0] | "\(.[1]) \(.[2]) \(.[3]) \(.[5]) \(.[6]) \(.[7]) \(.[8]) \(.[9])" '
++ curl -sG 'http://localhost:8086/query?pretty=true' --data-urlencode db=rigdata --data-urlencode epoch=ns --data-urlencode 'q=select * from coin_data where crypto='\''ETH'\'''
+ COIN_DATA='267836000 4.85 30.0785 2920928752921000 28656896451 0.0692888 301.707 USD'
+ IFS=' '
+ read VOLUME_24H_QC BLOCK_REWARD BLOCK_TIME DIFFICULTY MARKET_CAP_QC PRICE_BTC PRICE_QC QUOTE_CURRENCY
+ ((  DEBUG == 1  ))
+ echo 'SQL: select * from coin_data where crypto='\''ETH'\'''
SQL: select * from coin_data where crypto='ETH'
+ echo 'HTTP QUERY: curl -sG '\''http://'\''localhost'\'':8086/query?pretty=true'\'' --data-urlencode "db=rigdata" --data-urlencode "epoch=ns" --data-urlencode "q=select * from coin_data where crypto='\''ETH'\''"'
HTTP QUERY: curl -sG 'http://'localhost':8086/query?pretty=true' --data-urlencode "db=rigdata" --data-urlencode "epoch=ns" --data-urlencode "q=select * from coin_data where crypto='ETH'"
+ echo 'OUTPUT: 267836000 4.85 30.0785 2920928752921000 28656896451 0.0692888 301.707 USD'
OUTPUT: 267836000 4.85 30.0785 2920928752921000 28656896451 0.0692888 301.707 USD
+ echo -e 'VOLUME_24H_QC:267836000\nBLOCK_REWARD:4.85\nBLOCK_TIME:30.0785\nDIFFICULTY:2920928752921000\nMARKET_CAP_QC:28656896451\nPRICE_BTC:0.0692888\nPRICE_QC:301.707\nQUOTE_CURRENCY:USD'
VOLUME_24H_QC:267836000
BLOCK_REWARD:4.85
BLOCK_TIME:30.0785
DIFFICULTY:2920928752921000
MARKET_CAP_QC:28656896451
PRICE_BTC:0.0692888
PRICE_QC:301.707
QUOTE_CURRENCY:USD
+ [[ 301.707 == \n\u\l\l ]]
+ SQL='SELECT last(revenue_24h) from pool_profitability where label='\''NANO_ETH'\'''
++ get_last_record 'SELECT last(revenue_24h) from pool_profitability where label='\''NANO_ETH'\'''
+++ curl -sG 'http://localhost:8086/query?pretty=true' --data-urlencode db=rigdata --data-urlencode epoch=ns --data-urlencode 'q=SELECT last(revenue_24h) from pool_profitability where label='\''NANO_ETH'\'''
+++ sed s/null/0/g
+++ jq -r '.results[0].series[0].values[0][0]'
++ local _LAST_RECORD=1509148800000000000
++ ((  _LAST_RECORD == 0  ))
++ echo 1509148800000000000
+ LAST_RECORD=1509148800000000000
+ ((  DEBUG == 1  ))
+ echo 'SQL: SELECT last(revenue_24h) from pool_profitability where label='\''NANO_ETH'\'''
SQL: SELECT last(revenue_24h) from pool_profitability where label='NANO_ETH'
+ echo 'HTTP QUERY: curl -sG '\''http://'\''localhost'\'':8086/query?pretty=true'\'' --data-urlencode "db=rigdata" --data-urlencode "epoch=ns" --data-urlencode "q=SELECT last(revenue_24h) from pool_profitability where label='\''NANO_ETH'\''"'
HTTP QUERY: curl -sG 'http://'localhost':8086/query?pretty=true' --data-urlencode "db=rigdata" --data-urlencode "epoch=ns" --data-urlencode "q=SELECT last(revenue_24h) from pool_profitability where label='NANO_ETH'"
+ echo 'LAST RECORD FROM SQL:1509148800000000000'
LAST RECORD FROM SQL:1509148800000000000
+ echo 'calculating profitability from 1509148800000000000 until 1509223225398479712 (now)'
calculating profitability from 1509148800000000000 until 1509223225398479712 (now)
+ [[ NANOPOOL == \M\P\O\S ]]
+ REVENUE_24H_SQL='select sum(amount) from pool_payments where time >= 1509148800000000000 and time <= 1509223225398479712 and label='\''NANO_ETH'\'' group by time(24h)'
++ curl -sG 'http://localhost:8086/query?pretty=true' --data-urlencode db=rigdata --data-urlencode epoch=ns --data-urlencode 'q=select sum(amount) from pool_payments where time >= 1509148800000000000 and time <= 1509223225398479712 and label='\''NANO_ETH'\'' group by time(24h)'
++ sed -e s/null/0/g
++ jq -r '.results[0].series[0].values[]? | "\(.[0]) \(.[1])"'
+ REVENUE_24H=
+ ((  DEBUG == 1  ))
+ echo 'SQL: select sum(amount) from pool_payments where time >= 1509148800000000000 and time <= 1509223225398479712 and label='\''NANO_ETH'\'' group by time(24h)'
SQL: select sum(amount) from pool_payments where time >= 1509148800000000000 and time <= 1509223225398479712 and label='NANO_ETH' group by time(24h)
+ echo 'HTTP QUERY: curl -sG '\''http://'\''localhost'\'':8086/query?pretty=true'\'' --data-urlencode "db=rigdata" --data-urlencode "epoch=ns" --data-urlencode q="select sum(amount) from pool_payments where time >= 1509148800000000000 and time <= 1509223225398479712 and label='\''NANO_ETH'\'' group by time(24h)"'
HTTP QUERY: curl -sG 'http://'localhost':8086/query?pretty=true' --data-urlencode "db=rigdata" --data-urlencode "epoch=ns" --data-urlencode q="select sum(amount) from pool_payments where time >= 1509148800000000000 and time <= 1509223225398479712 and label='NANO_ETH' group by time(24h)"
+ echo 'OUTPUT (DATE REVENUE): '
OUTPUT (DATE REVENUE):
+ SQL='select sum(power_usage)/1440*24 from env_data where time >= 1509148800000000000 and time <= 1509223225398479712 and label='\''NANO_ETH'\'' group by time(24h)'
++ curl -sG 'http://localhost:8086/query?pretty=true' --data-urlencode db=rigdata --data-urlencode epoch=ns --data-urlencode 'q=select sum(power_usage)/1440*24 from env_data where time >= 1509148800000000000 and time <= 1509223225398479712 and label='\''NANO_ETH'\'' group by time(24h)'
++ jq -r '.results[0].series[0].values[]? | "\(.[0]) \(.[1])"'
++ sed -e s/null/0/g
+ POWER_USAGE=
+ ((  DEBUG == 1  ))
+ echo 'SQL: select sum(power_usage)/1440*24 from env_data where time >= 1509148800000000000 and time <= 1509223225398479712 and label='\''NANO_ETH'\'' group by time(24h)'
SQL: select sum(power_usage)/1440*24 from env_data where time >= 1509148800000000000 and time <= 1509223225398479712 and label='NANO_ETH' group by time(24h)
+ echo 'HTTP QUERY: curl -sG '\''http://'\''localhost'\'':8086/query?pretty=true'\'' --data-urlencode "db=rigdata" --data-urlencode "epoch=ns" --data-urlencode "q=select sum(power_usage)/1440*24 from env_data where time >= 1509148800000000000 and time <= 1509223225398479712 and label='\''NANO_ETH'\'' group by time(24h)"'
HTTP QUERY: curl -sG 'http://'localhost':8086/query?pretty=true' --data-urlencode "db=rigdata" --data-urlencode "epoch=ns" --data-urlencode "q=select sum(power_usage)/1440*24 from env_data where time >= 1509148800000000000 and time <= 1509223225398479712 and label='NANO_ETH' group by time(24h)"
+ '[' '!' -z '' ']'
+ MEASUREMENT=pool_profitability
+ TAGS=pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH
+ read _DATE _REVENUE
++ awk 'BEGIN {print  * 0.0692888}'
awk: line 1: syntax error at or near *
+ REVENUE_BTC=
++ awk 'BEGIN {print  * 301.707}'
awk: line 1: syntax error at or near *
+ REVENUE_QC=
+ LINE='pool_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH revenue_24h=,revenue_btc_24h=,revenue_qc_24h=,power_costs_24h=0 '
+ ((  DEBUG == 1  ))
+ echo 'pool_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH revenue_24h=,revenue_btc_24h=,revenue_qc_24h=,power_costs_24h=0 '
pool_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH revenue_24h=,revenue_btc_24h=,revenue_qc_24h=,power_costs_24h=0
+ DATA_BINARY='
pool_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH revenue_24h=,revenue_btc_24h=,revenue_qc_24h=,power_costs_24h=0 '
+ read _DATE _REVENUE
+ SQL='select mean(power_usage) from env_data where time >= 1509136825404882292 and time <= 1509223225398479712 and label='\''NANO_ETH'\'' group by rig_id'
++ jq -r '.results[0].series[]? | "\(.tags.rig_id) \(.values[0][1])"'
++ curl -sG 'http://localhost:8086/query?pretty=true' --data-urlencode db=rigdata --data-urlencode epoch=ns --data-urlencode 'q=select mean(power_usage) from env_data where time >= 1509136825404882292 and time <= 1509223225398479712 and label='\''NANO_ETH'\'' group by rig_id'
+ POWER_USAGE=
+ ((  DEBUG == 1  ))
+ echo 'SQL: select mean(power_usage) from env_data where time >= 1509136825404882292 and time <= 1509223225398479712 and label='\''NANO_ETH'\'' group by rig_id'
SQL: select mean(power_usage) from env_data where time >= 1509136825404882292 and time <= 1509223225398479712 and label='NANO_ETH' group by rig_id
+ echo 'HTTP QUERY: curl -sG '\''http://localhost:8086/query?pretty=true'\'' --data-urlencode "db=rigdata" --data-urlencode "epoch=ns" --data-urlencode "q=select mean(power_usage) from env_data where time >= 1509136825404882292 and time <= 1509223225398479712 and label='\''NANO_ETH'\'' group by rig_id"'
HTTP QUERY: curl -sG 'http://localhost:8086/query?pretty=true' --data-urlencode "db=rigdata" --data-urlencode "epoch=ns" --data-urlencode "q=select mean(power_usage) from env_data where time >= 1509136825404882292 and time <= 1509223225398479712 and label='NANO_ETH' group by rig_id"
+ echo ''

+ '[' '!' -z '' ']'
+ [[ NANOPOOL == \M\P\O\S ]]
+ [[ NANOPOOL == \C\R\Y\P\T\O\N\O\T\E ]]
+ SQL='select mean(avg_hr_24h) from worker_stats where time >= 1509136825404882292 and label='\''NANO_ETH'\'' group by rig_id'
++ curl -sG 'http://localhost:8086/query?pretty=true' --data-urlencode db=rigdata --data-urlencode epoch=ns --data-urlencode 'q=select mean(avg_hr_24h) from worker_stats where time >= 1509136825404882292 and label='\''NANO_ETH'\'' group by rig_id'
++ jq -r '.results[0].series[]? | "\(.tags.rig_id) \(.values[0][0]) \(.values[0][1])"'
+ RIG_HR_LAST_24H='Kinko1 1509136825404882200 190.96610169491518
rekt 1509136825404882200 4.022033898305086'
+ ((  DEBUG == 1  ))
+ echo 'SQL: select mean(avg_hr_24h) from worker_stats where time >= 1509136825404882292 and label='\''NANO_ETH'\'' group by rig_id'
SQL: select mean(avg_hr_24h) from worker_stats where time >= 1509136825404882292 and label='NANO_ETH' group by rig_id
+ echo 'HTTP QUERY: curl -sG '\''http://'\''localhost'\'':8086/query?pretty=true'\'' --data-urlencode "db=rigdata" --data-urlencode "epoch=ns" --data-urlencode "q=select mean(avg_hr_24h) from worker_stats where time >= 1509136825404882292 and label='\''NANO_ETH'\'' group by rig_id" '
HTTP QUERY: curl -sG 'http://'localhost':8086/query?pretty=true' --data-urlencode "db=rigdata" --data-urlencode "epoch=ns" --data-urlencode "q=select mean(avg_hr_24h) from worker_stats where time >= 1509136825404882292 and label='NANO_ETH' group by rig_id"
+ echo 'Kinko1 1509136825404882200 190.96610169491518
rekt 1509136825404882200 4.022033898305086'
Kinko1 1509136825404882200 190.96610169491518
rekt 1509136825404882200 4.022033898305086
+ read _RIG_ID _TIME _HR
+ [[ -z 190.96610169491518 ]]
++ awk 'BEGIN {print (190.96610169491518/(2920928752921000/30.0785))*((60/30.0785)*4.85)*(60*24)*(301.707)}'
+ EST_EARNINGS_DAY=8.26563e-06
+ EST_POWER_COSTS_DAY=
++ awk 'BEGIN {print (8.26563e-06-)}'
awk: line 1: syntax error at or near )
+ EST_PROFIT_DAY=
+ MEASUREMENT=future_profitability
+ TAGS=pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH,rig_id=Kinko1
+ LINE='future_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH,rig_id=Kinko1 est_revenue_qc_24h=8.26563e-06,est_power_costs_24h=,est_profit_24h= 1509223225398479712'
+ DATA_BINARY='
pool_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH revenue_24h=,revenue_btc_24h=,revenue_qc_24h=,power_costs_24h=0
future_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH,rig_id=Kinko1 est_revenue_qc_24h=8.26563e-06,est_power_costs_24h=,est_profit_24h= 1509223225398479712'
+ ((  DEBUG == 1  ))
+ echo 'EARNINGS PER DAY CALC: (190.96610169491518/(2920928752921000/30.0785))*((60/30.0785)*4.85)*(60*24)*(301.707)'
EARNINGS PER DAY CALC: (190.96610169491518/(2920928752921000/30.0785))*((60/30.0785)*4.85)*(60*24)*(301.707)
+ echo 'future_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH,rig_id=Kinko1 est_revenue_qc_24h=8.26563e-06,est_power_costs_24h=,est_profit_24h= 1509223225398479712'
future_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH,rig_id=Kinko1 est_revenue_qc_24h=8.26563e-06,est_power_costs_24h=,est_profit_24h= 1509223225398479712
+ read _RIG_ID _TIME _HR
+ [[ -z 4.022033898305086 ]]
++ awk 'BEGIN {print (4.022033898305086/(2920928752921000/30.0785))*((60/30.0785)*4.85)*(60*24)*(301.707)}'
+ EST_EARNINGS_DAY=1.74087e-07
+ EST_POWER_COSTS_DAY=
++ awk 'BEGIN {print (1.74087e-07-)}'
awk: line 1: syntax error at or near )
+ EST_PROFIT_DAY=
+ MEASUREMENT=future_profitability
+ TAGS=pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH,rig_id=rekt
+ LINE='future_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH,rig_id=rekt est_revenue_qc_24h=1.74087e-07,est_power_costs_24h=,est_profit_24h= 1509223225398479712'
+ DATA_BINARY='
pool_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH revenue_24h=,revenue_btc_24h=,revenue_qc_24h=,power_costs_24h=0
future_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH,rig_id=Kinko1 est_revenue_qc_24h=8.26563e-06,est_power_costs_24h=,est_profit_24h= 1509223225398479712
future_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH,rig_id=rekt est_revenue_qc_24h=1.74087e-07,est_power_costs_24h=,est_profit_24h= 1509223225398479712'
+ ((  DEBUG == 1  ))
+ echo 'EARNINGS PER DAY CALC: (4.022033898305086/(2920928752921000/30.0785))*((60/30.0785)*4.85)*(60*24)*(301.707)'
EARNINGS PER DAY CALC: (4.022033898305086/(2920928752921000/30.0785))*((60/30.0785)*4.85)*(60*24)*(301.707)
+ echo 'future_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH,rig_id=rekt est_revenue_qc_24h=1.74087e-07,est_power_costs_24h=,est_profit_24h= 1509223225398479712'
future_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH,rig_id=rekt est_revenue_qc_24h=1.74087e-07,est_power_costs_24h=,est_profit_24h= 1509223225398479712
+ read _RIG_ID _TIME _HR
+ echo '
pool_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH revenue_24h=,revenue_btc_24h=,revenue_qc_24h=,power_costs_24h=0
future_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH,rig_id=Kinko1 est_revenue_qc_24h=8.26563e-06,est_power_costs_24h=,est_profit_24h= 1509223225398479712
future_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH,rig_id=rekt est_revenue_qc_24h=1.74087e-07,est_power_costs_24h=,est_profit_24h= 1509223225398479712'
+ ((  NO_WRITE == 1  ))
+ curl -s -i -XPOST 'http://localhost:8086/write?db=rigdata' --data-binary @tmp/profitability_binary_data.tmp
HTTP/1.1 400 Bad Request
Content-Type: application/json
Request-Id: 3aa3824b-bc20-11e7-a9aa-000000000000
X-Influxdb-Version: 1.3.6
Date: Sat, 28 Oct 2017 20:40:26 GMT
Content-Length: 594
{"error":"unable to parse 'pool_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH revenue_24h=,revenue_btc_24h=,revenue_qc_24h=,power_costs_24h=0 ': missing field value\nunable to parse 'future_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH,rig_id=Kinko1 est_revenue_qc_24h=8.26563e-06,est_power_costs_24h=,est_profit_24h= 1509223225398479712': missing field value\nunable to parse 'future_profitability,pool_type=NANOPOOL,crypto=ETH,label=NANO_ETH,rig_id=rekt est_revenue_qc_24h=1.74087e-07,est_power_costs_24h=,est_profit_24h= 1509223225398479712': missing field value"}
+ IFS='
'
+ rm /home/pi/src/rig-monitor_dev_influxdb/run/PROFIT_LOCK

wishbone1138 avatar Oct 28 '17 20:10 wishbone1138