Last active
March 13, 2024 13:07
-
-
Save tommyv1987/97e939a7adf491333d686a8eaa68d4bd to your computer and use it in GitHub Desktop.
Nym-node CPU cron service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ----------------------------------------- | |
# this script is designed to monitor the load on your mixnode or gateway | |
# whilst there's plenty of ways to do this, this is a simple cron service that polls the nym binary every minute to check CPU | |
# you can amend this script on your own accord to do what you need with the results | |
# in the interim this will write to a simple log file | |
# ----------------------------------------- | |
# add to your crontab -e | |
# chmod +x node_cpu_usage.sh | |
# */1 * * * * /usr/local/bin/node_cpu_usage.sh nym-mixnode | |
if [ $# -eq 0 ]; then | |
echo "usage: $0 <process_name>" | |
exit 1 | |
fi | |
PROCESS_NAME=$1 | |
LOG_FILE="/var/log/nym_node_cpu_usage.log" | |
case $PROCESS_NAME in | |
nym-mixnode | nym-gateway) | |
PROCESS_USAGE=$(ps -eo %cpu,comm | grep $PROCESS_NAME | awk '{print $1}') | |
;; | |
*) | |
echo "unsupported process: $PROCESS_NAME" | |
exit 2 | |
;; | |
esac | |
OVERALL_USAGE=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}') | |
TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S") | |
echo "$TIMESTAMP - $PROCESS_NAME CPU usage: $PROCESS_USAGE%, overall CPU usage: $OVERALL_USAGE%" >>$LOG_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment