A simple way of logging server stats
Here is a simple example of how you could log server CPU load and free memory in a bash script.
This can be useful to help keep a passively watchful eye on your server instead of having to log in every now and then. Also, cross checking these metric stats with things like page load speed, database size or when you’ve deployed new code can help debugging hard found problems.
# log server metrics to umlogger.com api_key={apikey} # get current CPU load and log it to metric value=$(top -n 1 -b | awk '/^%Cpu/{print $2}') metric_name="CPU load" curl -d "metric_name=$metric_name&value=$value&t=value&apikey=$api_key" https://umlogger.com/p # get current free memory and log it to metric value=$(top -n 1 -b | awk '/^MiB Mem/{print $6}') metric_name="Free memory" curl -d "metric_name=$metric_name&value=$value&t=value&apikey=$api_key" https://umlogger.com/p
To get it running, save this bash script (e.g. as log_server_stats.sh), set as executable (chmod u+x log_server_stats.sh) and then add a cronjob, perhaps to execute every 15 minutes (*/15 * * * * /scriptlocation/log_server_stats.sh).
Make sure to update with your own {apikey}, found on your account page.