In this article, I will explain how to monitor a Geth node and keep track of the syncing process very easily with a CronJob and Google Sheet
Capture and store geth and system metrics every 15 min
In the first step, we are configuring a cronjob (15 min scheduled task) on our Linux system where Geth is installed to capture some interesting metrics about the syncing state of Geth (blocks, states, peers) and the operating system (e.g CPU, memory, disk, load average).
Use the command $ crontab -e to edit the crontab file and add the following line at the end to capture all the metrics and print them into a semi-column seperated CSV file.
Please find below a detailed explanation of each metrics:
date --iso-8601=seconds prints the current date and time
/usr/local/bin/geth --verbosity 0 --datadir /mnt/ssd/ethereum/ --exec 'var a = admin.peers; var s = eth.syncing; s.currentBlock + ";" + s.highestBlock + ";" + (s.highestBlock-s.currentBlock) + ";" + s.pulledStates + ";" + s.knownStates + ";" + a.length' attach | tr -d "\"" connects to geth (--datadir might differ) and retrieve the following information: number of peers connected, current block, highest block, pulled states count, known states counts
df /dev/sda --output=used | sed -n 2p prints the used disk space
iostat /dev/sda -d -x | awk {'print $4";"$5";"$16'} | sed -n 4p returns the current disk speed (read/write) as well as the percentage utilization of the disk
free | awk {'print $3";"$2'} | sed -n 2p prints the used and total memory of the system
free | awk {'print $3";"$2'} | sed -n 3p prints the used and total swap of the system
cat /proc/loadavg | awk {'print $1";"$2";"$3'} returns the current load average (1min, 5min, 15min)
iostat -c | sed -n 4p | awk {'print $1'} prints the current CPU percentage utilization
cat /sys/devices/virtual/thermal/thermal_zone?/temp | sed -n 1p | awk '{ print $1/1000 }' gives the CPU temperature`
You can replace /home/pi/geth_metrics.csv by any files on the system.
As a result, every 15 min, the CSV file will be appended with new metrics.
Now we have a consistent way to capture periodically our Geth and system metrics into a CSV, we can download this file and upload it to a Google Spreadsheet template.
Download the CSV file
Connect via SSH using SCP to download the CSV file.