...

Chia Report

No-installation monitoring for your Chia farm.

hero

How it works

Call this simple shell script to POST your `chia farm summary` to an API endpoint. Track your progress and keep your private keys safe.

#!/bin/bash
# Run this script manually or invoke it periodically using cron.
# To do so, add a line like the following with `sudo crontab -e`
#
# */5 * * * * su user -c /home/user/chia-report-scripts/report.sh
#
# This will execute the script every 5 minutes as user `user`.
# ------------- DEFINE VARIABLES -------------
CWD=$PWD;
API_ENDPOINT="YOUR_HTTP_ENDPOINT"
CHIA_INSTALL_DIR="/home/user/chia-blockchain"
TEMP_DIR="/chia/logs";
CURR_REPORT="${TEMP_DIR}/chia-report-current.log"
PREV_REPORT="${TEMP_DIR}/chia-report-previous.log"
TEMP_REPORT="${TEMP_DIR}/chia-report-temp.log"
# Whitelist the attributes we want from `chia farm summary`
declare -a GET_LINES;
GET_LINES+=("Farming status");
GET_LINES+=("Total chia farmed");
#GET_LINES+=("User transaction fees"); # Commented to reduce noise
#GET_LINES+=("Block rewards"); # Commented to reduce noise
GET_LINES+=("Plot count");
GET_LINES+=("Total size of plots");
#GET_LINES+=("Estimated network space"); # Commented to reduce noise
#GET_LINES+=("Expected time to win"); # Commented to reduce noise
# Build the string payload
TEXT="";
# ----------- END DEFINE VARIABLES ------------
# Check for existing files
if [ -f "$CURR_REPORT" ]; then
# A current report exists,
if [ -f "$PREV_REPORT" ]; then
# A previous report exists; remove it
rm "$PREV_REPORT";
fi
# Replace the previous report with the current report
mv "$CURR_REPORT" "$PREV_REPORT";
fi
# Activate chia and return to the current directory
cd $CHIA_INSTALL_DIR
. ./activate
cd "$CWD"
# Generate temp report
chia farm summary > "$TEMP_REPORT"
# Find values of interest
while read -r LINE; do
for EL in "${GET_LINES[@]}"
do
if [[ $LINE =~ $EL ]]; then
VAL=${LINE:$((${#EL} + 2))};
TEXT="${TEXT}\n${EL}: ${VAL}"
fi
done
done < "$TEMP_REPORT"
# Save current report
echo $TEXT > "$CURR_REPORT";
# If there's no previous report, just create an empty file
if [ ! -f "$PREV_REPORT" ]; then
touch "$PREV_REPORT";
fi
# Compare current and previous reports
if cmp -s "$CURR_REPORT" "$PREV_REPORT"; then
printf '"%s" is the same as "%s"\n' "$CURR_REPORT" "$PREV_REPORT"
else
printf '"%s" is different from "%s"\nSEND IT!
' "$CURR_REPORT" "$PREV_REPORT"
# POST data to $API_ENDPOINT
curl -X POST --data-urlencode "payload={\"text\": \"$TEXT\"}" "$API_ENDPOINT"
fi
# Fin!
exit 0;

How Exactly ?

Get an API endpoint

I use a Slack webhook, but you can use any HTTP endpoint you like. Set the $API_ENDPOINT in the script above to the endpoint of your choosing.

Copy the script to your farming server

That is, the server where you run chia farm summary. You may still need to set a couple other variables to match your system - variables such as $CHIA_INSTALL_DIR and $TEMP_DIR.
The simplest way to get a copy of this script is to run git clone https://github.com/marclar/chia-report-scripts.git or you can copy the script from GitHub.

Try it out!

Execute the script (you can call it with bash report.sh) and ensure that you get a result at your $API_ENDPOINT. For debugging purposes, you can use a Request Bin as your $API_ENDPOINT to see what your server is actually POSTing.

Set a recurring timer

To run this script repeatedly, edit your crontab (docs about crontab) . This can be done using sudo crontab -e, and an example of a valid cron string is located at the top of the script above. For example, to run this script every 5 minutes, you can use an entry like

*/5 * * * * su user -c /home/user/chia-report-scripts/report.sh

Sleep like a baby log

Turn on your Slack notifications and turn off your debilitating anxiety. My name is Michael and I'll help when I can. You can find me at @marclar on Keybase or at @ChiaReport on Twitter. Happy farming!