Hypothetical (having duplicate Block producers) 1 cloud 1 home

Short explanation of the script. It is executed through crontab every minute.
It send OK pings to healthchecks.io. If the TIP diff is too high it does not send the ping.
Healtchecks.io will alert if no valid ping comes in for 5 Minutes.
This way I will recognize that something is wrong in any case (also when the machine is not running/crashed/not able to execute the check) without exposing anything to the outside world (like it would be the case if using a cloud monitoring agent)

Remarks:

  • The script is kind of hardcoded currently, so it will require customization for you
  • Also if Cardano Config / Parameters change the calculation may be invalid because I’m just substracting the constant 1591566291 from the current Time. So it could be improved to calculate this static value from the Cardano Config Parameters.
  • Please customize the following parts of the script:
  • Change USERNAME to your user
  • Change the “all good sending ping” area to your appropriate handler or define a non success area to trigger somethign in this case.

Script (pingTipCheck.sh):

#!/usr/bin/env bash
# shellcheck disable=SC2034,SC2086,SC2230,SC2009,SC2206,SC2062,SC2059

export CARDANO_NODE_SOCKET_PATH=/opt/cardano/cnode/sockets/node0.socket

customCurrentSlotNoString=$(/home/USERNAME/.cabal/bin/cardano-cli shelley query tip --mainnet | grep -Po '\"slotNo\": \K[0-9]+')
customCurrentSlotNo=$(expr $customCurrentSlotNoString + 0)

customRefSlotNo=$(expr $(printf '%(%s)T\n' -1) - 1591566291)
customDiff=$(expr $customRefSlotNo - $customCurrentSlotNo)

if [[ $customDiff -le 50 ]]
then
  echo "all good sending ping"
  curl -m 10 --retry 5 https://hc-ping.com/YOURPINGENDPOINT
exit
fi

Crontab Entry (crontab -e -u USER):

* * * * * /opt/cardano/cnode/custom/pingTipCheck.sh
1 Like