Displaying server stats
Let's say that we have to write a shell script that's going to display the following pieces of information:
- Current hostname
- Current date
- Current kernel version
- Current CPU usage
- Current memory usage
- Current swap space usage
- Current disk I/O
- Current network bandwidth
This is more of an exercise in filtering data and using commands, but there are some interesting concepts in terms of how to format data to look nice and readable. This is something we consider to be very important.
Getting ready
We need to leave the cli1
machine running. Also, for this script to work, we need to deploy the sysstat
package, and then enable the necessary service. We can do this by using the following command for Ubuntu:
sudo apt-get -y install sysstat
We can use the following command for CentOS:
sudo yum -y install sysstat
After that, we need to start the sysstat
service:
sudo systemctl enable --now sysstat...