-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmp-stats-api.txt
111 lines (105 loc) · 3.74 KB
/
mmp-stats-api.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash
# -- mmpOS agent searches for executable bash script mmp-stats.sh in custom miners.
# -- This is an example content of mmp-stats.sh
# -- When agent calls mmp-stats.sh it fetches this as an example:
#{
# "busid": [
# 1
# ],
# "hash": [
# 111.0
# ],
# "units": "hs",
# "air": [
# "0",
# "0",
# "0"
# ],
# "miner_name": "miner-name",
# "miner_version": "miner-version"
#}
# -- You can see more in https://app.mmpos.eu/faq
DEVICE_COUNT=$1 # agent calls with device count per platform or globally
LOG_FILE=$2 # agent provides the path to log file if no json api is available.
cd `dirname $0`
. mmp-external.conf # Use this to add name and version if its not provided/ EXTERNAL_NAME && EXTERNAL_VERSION
# -- curl API settings --
MINER_API_PORT=5001 # Make sure the port is properly exported in miner arguments.
stats_json=$(curl --silent --insecure --header 'Accept: application/json' http://127.0.0.1:${MINER_API_PORT}/gpu)
# -- Check if miner is running with API or not --
if [[ $? -ne 0 || -z $stats_json ]]; then
echo -e "Miner API connection failed"
else
get_cards_busid(){
busid=''
local bus=$(echo $stats_json |jq '.data.gpus[].bus|tonumber')
if [[ -z "$bus" ]]; then
local bus="0"
fi
if [[ ${bus} > 0 ]]; then
busid=$(echo $bus)
fi
}
get_miner_shares_ac(){
local ac=0
for ((i=0; i < ${DEVICE_COUNT}; i++ )); do
local ac=$(echo $stats_json | jq '.data.gpus[]| select('.id' == '$i')|.valid')
if [[ -z "$ac" ]]; then
local ac="0"
fi
(( total_ac=total_ac+${ac%%.*} ))
done
echo "$total_ac"
}
get_miner_shares_inv(){
local inv=0
for ((i=0; i < ${DEVICE_COUNT}; i++ )); do
local inv=$(echo $stats_json | jq '.data.gpus[]| select('.id' == '$i')|.inval')
if [[ -z "$inv" ]]; then
local inv="0"
fi
(( total_inv=total_inv+${inv%%.*} ))
done
echo "$total_inv"
}
get_miner_shares_rj(){
local rj=0
for ((i=0; i < ${DEVICE_COUNT}; i++ )); do
local rj=$(echo $stats_json | jq '.data.gpus[]| select('.id' == '$i')|.statle')
if [[ -z "$rj" ]]; then
local rj="0"
fi
(( total_rj=total_rj+${rj%%.*} ))
done
echo "$total_rj"
}
get_miner_stats() {
stats=
# Actual data getting
local index=$(echo $stats_json |jq '.data.gpus[].id|tonumber')
if [[ "$(( $(echo "${index[*]}" | sort -nr | head -n1) + 1 ))" -ne $DEVICE_COUNT ]]; then
DEVICE_COUNT=$(( $(echo "${index[*]}" | sort -nr | head -n1) + 1 ))
fi
local busid=
get_cards_busid
local hash=$(echo $stats_json |jq '.data.gpus[].proof|tonumber')
local units='hs' # hashes units
# A/R shares by pool
local ac=$(get_miner_shares_ac)
local inv=$(get_miner_shares_inv)
local rj=$(get_miner_shares_rj)
# make JSON
stats=$(jq -nc \
--argjson index "$(echo $index| tr " " "\n" | jq -cs '.')" \
--argjson hash "$(echo $hash | tr " " "\n" | jq -cs '.')" \
--argjson busid "$(echo ${busid[@]} | tr " " "\n" | jq -cs '.')" \
--arg units "$units" \
--arg ac "$ac" --arg inv "$inv" --arg rj "$rj" \
--arg miner_version "$EXTERNAL_VERSION" \
--arg miner_name "$EXTERNAL_NAME" \
'{$index, $busid, $hash, $units, air: [$ac, $inv, $rj], miner_name: $miner_name, miner_version: $miner_version}')
# total hashrate in khs
echo $stats
}
fi
get_miner_stats $DEVICE_COUNT $LOG_FILE