Plotbot: would anyone be interested in a bash script that sends you a regular email with your farmer/plotter status?

I have been spending way too much time watching Chia plotters / farmers do their work and making sure the right processes are running, that CPUs are not overloaded, disks are not full, and RAM is not overloaded.

I have created a script that I call plotbot that runs as a cron job every half an hour on each of my machines and sends me an email that looks like the output below.

I find this really useful and if others would find it useful then I am happy to clean it up a bit and put it on Github? My bash skills are extremely basic, fair warning.

(edit: the copy and paste into this forum software has messed up the tables below. in gmail they appear nicely the way they do on linux command line)

chia farm summary

Farming status:           Farming
Total chia farmed:            2.0
User transaction fees:        0.0
Block rewards:                2.0
Last height farmed:        208528
Plot count:                    98
Total size of plots:        9.700 TiB
Estimated network space: 1690.137 PiB
Expected time to win:           1 month

Note: log into your key using ‘chia wallet show’ to see rewards for each key

plotman status

plot id   k                      tmp        dst     wall  phase    tmp     pid   
xx   32   /media/ajca/pt_int_0   /plots/1   0:20     1:2    73G   45706   
xx   32   /media/ajca/pt_int_0   /plots/2   2:54     1:7   176G   41142   
xx   32   /media/ajca/pt_int_0   /plots/0   3:29     2:1   205G   39852   
xx   32   /media/ajca/pt_int_0   /plots/1   5:42     3:3   186G   35769   
xx   32   /media/ajca/pt_int_0   /plots/2   6:12     3:5   163G   32995   

free memory

              total        used        free      shared  buff/cache   available
Mem:           15Gi        11Gi       168Mi        20Mi       4.4Gi       4.2Gi
Swap:         2.0Gi       1.4Gi       634Mi

disk space

Filesystem       1K-blocks       Used   Available Use% Mounted on
tmpfs              1637212       3536     1633676   1% /run
/dev/sda2        479152840   44011908   410731540  10% /
tmpfs              8186044         60     8185984   1% /dev/shm
tmpfs                 5120          4        5116   1% /run/lock
tmpfs                 4096          0        4096   0% /sys/fs/cgroup
/dev/sda1           523244       5340      517904   2% /boot/efi
tmpfs              1637208        108     1637100   1% /run/user/1000
/dev/sdb1        976729088       1792   976727296   1% /media/ajca/TempDrive
/dev/sdc1      15501611616 7864595364  6855705996  54% /media/ajca/pl4
/dev/sdd1      15501611616 2577403988 12142897372  18% /media/ajca/pl9
/dev/nvme0n1p1  1921802432  784670600  1039439776  44% /media/ajca/pt_int_0

chia plot directories

Directories where plots are being searched for:
Note that subdirectories must be added manually
Add with chia plots add -d [dir] and remove with chia plots remove -d [dir]

/media/ajca/LongDrive2
/media/ajca/LongDrive
/media/ajca/pm1
/media/ajca/pl4
/media/ajca/pl9
/media/ajca/TempDrive

mpstat

Linux 5.11.0-16-generic (Farmer1) 	05/03/2021 	_x86_64_	(16 CPU)

11:00:03 AM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest
11:00:03 AM  all    1.47   15.28    1.71    1.10    0.00    0.25    0.00    0.00

chia info error log

2021-05-03T11:00:02.979 full_node full_node_server        : INFO     <- respond_
2021-05-03T11:00:02.980 full_node full_node_server        : INFO     <- respond_
2021-05-03T11:00:02.993 full_node full_node_server        : INFO     <- new_sign
2021-05-03T11:00:02.995 full_node full_node_server        : INFO     <- new_comp
2021-05-03T11:00:02.995 full_node full_node_server        : INFO     <- new_comp
2021-05-03T11:00:02.999 full_node full_node_server        : INFO     <- new_comp
2021-05-03T11:00:03.006 full_node full_node_server        : INFO     <- new_comp
2021-05-03T11:00:03.008 full_node full_node_server        : INFO     <- new_unfi
2021-05-03T11:00:03.020 full_node full_node_server        : INFO     <- new_comp
2021-05-03T11:00:03.022 full_node full_node_server        : INFO     <- new_comp
2021-05-03T11:00:03.029 full_node full_node_server        : INFO     <- new_comp
2021-05-03T11:00:03.030 full_node full_node_server        : INFO     <- new_unfi
2021-05-03T11:00:03.031 full_node full_node_server        : INFO     <- new_unfi
2021-05-03T11:00:03.053 full_node full_node_server        : INFO     <- new_comp
2021-05-03T11:00:03.055 full_node full_node_server        : INFO     <- new_comp
2021-05-03T11:00:03.065 full_node full_node_server        : INFO     <- new_comp
2021-05-03T11:00:03.069 full_node full_node_server        : INFO     <- new_comp
2021-05-03T11:00:03.073 full_node full_node_server        : INFO     <- new_unfi
2021-05-03T11:00:03.088 full_node full_node_server        : INFO     <- new_unfi
2021-05-03T11:00:03.092 full_node full_node_server        : INFO     <- new_comp

chia internal farmer harvester connections

chia & plotman processes running
   3224 pts/0    00:01:10 chia_daemon
   3440 pts/0    00:02:29 chia_harvester
   3441 pts/0    00:01:44 chia_farmer
   3442 pts/0    03:25:28 chia_full_node
   3443 pts/0    00:17:04 chia_wallet
   4230 pts/0    00:02:33 chia_full_node
   4233 pts/0    00:02:34 chia_full_node
   4234 pts/0    00:02:33 chia_full_node
   4235 pts/0    00:02:34 chia_full_node
   4236 pts/0    00:02:32 chia_full_node
   4237 pts/0    00:02:34 chia_full_node
   4238 pts/0    00:02:32 chia_full_node
  34964 pts/8    00:01:23 plotman

syslog

May  3 10:30:33 Farmer1 systemd[1034]: tracker-store.service: Succeeded.
May  3 10:30:34 Farmer1 systemd[1]: session-21.scope: Succeeded.
May  3 10:32:02 Farmer1 systemd[1]: Started Run anacron jobs.
May  3 10:32:02 Farmer1 anacron[45530]: Anacron 2.3 started on 2021-05-03
May  3 10:32:02 Farmer1 anacron[45530]: Normal exit (0 jobs run)
May  3 10:32:02 Farmer1 systemd[1]: anacron.service: Succeeded.
May  3 10:35:01 Farmer1 CRON[45602]: (root) CMD (command -v debian-sa1 > /dev/nu
May  3 10:45:01 Farmer1 CRON[46155]: (root) CMD (command -v debian-sa1 > /dev/nu
May  3 10:55:01 Farmer1 CRON[46351]: (root) CMD (command -v debian-sa1 > /dev/nu
May  3 11:00:01 Farmer1 CRON[46464]: (ajca) CMD (sh /home/ajca/monitor.sh >> /ho
May  3 11:00:01 Farmer1 dbus-daemon[1318]: [session uid=1000 pid=1318] Activatin
May  3 11:00:01 Farmer1 systemd[1034]: Starting Tracker metadata database store 
May  3 11:00:01 Farmer1 dbus-daemon[1318]: [session uid=1000 pid=1318] Successfu
May  3 11:00:01 Farmer1 systemd[1034]: Started Tracker metadata database store a
May  3 11:00:01 Farmer1 dbus-daemon[1318]: [session uid=1000 pid=1318] Activatin
May  3 11:00:01 Farmer1 systemd[1034]: Starting Tracker metadata extractor...
May  3 11:00:01 Farmer1 tracker-extract[46481]: Set scheduler policy to SCHED_ID
May  3 11:00:01 Farmer1 tracker-extract[46481]: Setting priority nice level to 1
May  3 11:00:01 Farmer1 dbus-daemon[1318]: [session uid=1000 pid=1318] Successfu
May  3 11:00:01 Farmer1 systemd[1034]: Started Tracker metadata extractor.
3 Likes

Can you drop a screenshot in here too please?

It’s because I manually edited to produce code blocks (monospace font) for the sections. You may want to click the little pencil at upper right of the post.

2 Likes

yeah, i think this would be super useful to me @ajca

1 Like

Here you go: https://github.com/alexjcampbell/plotbot/blob/main/plotbot.sh

Any feedback most welcome! My bash script skills are very basic but I am very happy with the output of this!

I’ve got a cronjob running every 30 minutes on each farmer / plotter to send me this.

3 Likes

Nicely done work.

Note, untested code below:

Change this:

cd ~/chia-blockchain && . ./activate

To this:

(cd ~/chia-blockchain && . ./activate) || (exit "Could not load the Chia application"; exit 1)

That way, if chia is not installed, or could not be loaded, it will exit with a nice clean message rather than trying to blindly carry on executing.

Change:

"$(cat ~/.chia/mainnet/log/debug.log | grep 'INFO' | tail -n 20)"

To:

$(grep 'INFO'  ~/.chia/mainnet/log/debug.log | tail -n 20)

You don’t need to touch on line 26, but you can do:
> plotbot_output.html
which will truncate the file to zero length. Or use the “truncate” command, e.g. truncate -s 0 plotbot_output.html

This:

write_html_block() {
    echo "<h3>$1</h3><pre>" >> "$PLOTBOT_DIR/plotbot_output.html"
    echo "$2" >> "$PLOTBOT_DIR/plotbot_output.html"
    echo "</pre>" >> "$PLOTBOT_DIR/plotbot_output.html"
}

Can become this:

write_html_block() {
    cat >> plotbot_output.html <<'block'
<h3>$1</h3><pre>
$2
</pre>
block
}

Or this:

write_html_block() {
    cat >> plotbot_output.html <<'block'
<h3>$1</h3><pre>$2</pre>
block
}

Or this:

write_html_block() {
    echo "<h3>$1</h3><pre>$2</pre>" >> plotbot_output.html
}

Alternatively:

write_html_block() {
    "<h3>$1</h3><pre>$2</pre>"
}

Which turns your overall code in to this:

(echo "<html><body><h2>$(hostname)</h2>"
echo write_html_block "chia farm summary" "$(chia farm summary)"
echo write_html_block "plotman status" "$(plotman status)"
echo write_html_block "chia & plotman processes running" "$(ps -a  | grep -e 'plotman' -e 'chia')"
# and so on and so forth
echo "</body></html>" # you forgot to close your body & html tags in your repo version
) | mail -a 'Content-Type: text/html' -s "chia update : $(hostname) : $(date +%F) $(date +%T)" $DESTINATION_EMAIL

If you switch to using sendmail it will work on more platforms.

3 Likes

Hy @ajca, just to say i’m loving the script. cheers!

2 Likes