That's the point to watch that the pool is up and running.
I've elaborated this other example of how to get the data to make that check. I think is quite "universal" and should work with any miner, so if some of you want to test it that would be good info for developers.
#! /bin/bash
# Find out miner's name
P_NAME=$(ps aux | grep -v grep| grep SCREEN | grep miner | sed 's/ /\n/g' | grep /home/m1 | rev | cut -d"/" -f1 | rev)
# Find out miner's process number (PID)
P_NUMBER=$(pgrep $P_NAME)
# Find out pool ip and port
IP_POOL=$(sudo lsof -e /run/user/1000/gvfs -Pan -p "$P_NUMBER" -i | grep "$P_NAME" | sed 's/->/ /' | rev | cut -d" " -f2 | rev | cut -d":" -f1)
PORT_POOL=$(sudo lsof -e /run/user/1000/gvfs -Pan -p "$P_NUMBER" -i | grep "$P_NAME" | sed 's/->/ /' | rev | cut -d" " -f2 | rev | cut -d":" -f2)
echo "Miner's name : " $P_NAME
echo "Miner PID : " $P_NUMBER
echo "Pool's IP : " $IP_POOL
echo "pool's port : " $PORT_POOL
Hope that Stubo's idea and this one help devs to consolidate wdog.
That is a neat idea. The code worked until I determining the IP of the pool and port. Those were set to huge strings full of IPs and ports:
m1@Testy:~$ echo "Miner's name : " $P_NAME
Miner's name : zm
m1@Testy:~$ echo "Miner PID : " $P_NUMBER
Miner PID : 2191
m1@Testy:~$ echo "Pool's IP : " $IP_POOL
Pool's IP : 192.168.1.178 192.168.1.5 45.79.223.173 94.23.12.63 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5 192.168.1.5
m1@Testy:~$ echo "pool's port : " $PORT_POOL
pool's port : 42000 54332 20570 3443 64395 64396 64546 64571 64589 64608 64627 64644 64660 64677 64694 64711 64718 64734 64748 64767 64782 64795 64820 64833 64849 64860 64869 64884 64899 64918 64935 64945 64977 64988 65008 65027 65044 65064 65086 65107 65127 65145 65168 65186 65203 65219 65235 65249 65263 65277
I still don't think that checking for connectivity to a mining pool is a good idea because of all of the pitfalls in doing so as well as the odds of a good pool being down. That being said, I spent a little bit of time to develop my idea a little bit fuller. The following in totally untested in the sense that I have not put it into the watchdog and tried it out on my test rig. I have tested the logic however:
# This statement needs to be near the top of the watchdog script
NUM_MINER_CONS=0
# These statements need to be done continually [because of profit switching]
# where we know that the miner is connected and mining, toward the end of wdog
# Store active miner connection info into MINER_CONS array
FILTER=$(ss -tn state listening | gawk 'NR > 1 {n=split($3,A,":"); B[NR-1]=A[n]} END {for (i=1; iMINER_CONS=( $(ss -tn state established dst :* | grep -P -v "$FILTER" | grep -v Port |tr -s ' '|cut -d ' ' -f 4) )
NUM_MINER_CONS=${#MINER_CONS[@]}
if [ $NUM_MINER_CONS -eq 0 ]
then
echo "$(date) - Cannot detect active miner connections" | tee -a ${LOG_FILE} ${ALERT_LOG_FILE}
fi
# This is the check that should be done if the miner is down or the GPU utilization is low
# Make sure we can connect to the mining pools iff 1 or more known miner connections
if [ $NUM_MINER_CONS -gt 0 ]
then
CAN_HIT_POOL=0
while [ CAN_HIT_POOL -eq 0 ]
do
CAN_HIT_POOL = 1
for CON in "${MINER_CONS[@]}"
do
POOL_IP=$(echo $CON| cut -d':' -f 1)
POOL_PORT=$(echo $CON| cut -d':' -f 2)
if ! nc -vzw1 $POOL_IP $POOL_PORT;
then
CAN_HIT_POOL=0
echo "$(date) - Cannot connect to mining pool $POOL_IP, port $POOL_PORT, checking again in 30 seconds..." | tee -a ${LOG_FILE} ${ALERT_LOG_FILE}
fi
done
if [ CAN_HIT_POOL -eq 0 ]
then
sleep 30
fi
done
fi
Part of the difficulty here is that some miners will have multiple connections. One such is DSTM's zm. Also, folks can be using "plusCPU". Here is what the ss code I use spits out on my test rig with that case:
m1@Testy:~$ ss -tn state established dst :* | grep -P -v "$FILTER" | grep -v Port |tr -s ' '|cut -d ' ' -f 4
172.104.94.15:20580
45.79.223.173:20570
188.165.195.21:3443
Thanks.
Mmmm, I see, thx for testing the code. I only use claymore and ewbf, never found so many open connection from the miner.
I think @Papampi's idea and yours are both great.
About my code and your output I've notice that only 2 ips (guess must be pool's ips) are public and all others are private.
In case of need should be easy to find the local network range and remove ip+port for those ones and keep only the public ips+ports.
That way it does not matter how many ips has the pool, it would be possible to ping all of them.
Anyway, just thinking aloud. All approaches look good to me,