Generate graphs with gnuplot or matplotlib (Python) from sar data
This repository is intended to give a simple way to measure resources usage (CPU, RAM...) in a machine. It uses sar to retrieve data and gnuplot (by default) or matplotlib to generate graphs from it.
Useful to visualize and analyze data during stress tests.
The following graphs based on sar data are generated:
For basic functionality you will need to install sysstat and gnuplot in your system using your package manager:
# Debian & based
apt-get install sysstat gnuplot
# RHEL & based
yum install sysstat gnuplot
Minimum version required:
You can check your current version with:
# Gnuplot
gnuplot --version
# Sysstat
sar -V
If your current distribution (for example, CentOS 6) doesn't have these versions in repositories by default, you will have to either install the needed package or build from sources.
If you want to generate the graphs using matplotlib (in Python 2.7) you can install it with pip. In case you don't have pip check the official guide to install it using your chosen package manager. Once you have pip just:
pip install matplotlib
# Debian & based
apt-get install mutt
# RHEL & based
yum install mutt
[jota@myserver sarviewer]$ ./data_collector.sh
Please specify the number of samples to take-> 10
Please specify the sample interval (take sample every X seconds)-> 2
Taking 10 samples with 2 seconds interval
Total time to collect all data: 20 seconds
----------------------------------
>>> Collecting data
>>> Please wait until data collection is completed
----------------------------------
- You can abort this script with Ctrl+C, but have in mind the data will stop being collected when you cancel it.
- You will also need to manually launch script plotter.sh to generate the graphs.
Once the script has finished the data collection or you have cancelled it (and subsequently launched plotter.sh) you can analyze the resource usage in the graphs (PNG format) that have been generated in the graphs/ folder of this repo.
You can also use parameters with the script, for example:
# Generate 10 samples with 1 second interval between each one
./data_collector.sh -n 10 -i 1
# Generate 10 samples with 1 second interval between each one and send results to mail
./data_collector.sh -n 10 -i 1 -m [email protected]
[jota@myserver sarviewer]$ ./system_data_reader.sh
List of sa* files available at this moment to retrieve data from:
-------------------------------------------
File sa15 with data from Linux 3.16.0-4-amd64 (myserver) 04/15/17 _x86_64_ (8 CPU)
File sa16 with data from Linux 3.16.0-4-amd64 (myserver) 04/16/17 _x86_64_ (8 CPU)
File sa17 with data from Linux 3.16.0-4-amd64 (myserver) 04/17/17 _x86_64_ (8 CPU)
File sa18 with data from Linux 3.16.0-4-amd64 (myserver) 04/18/17 _x86_64_ (8 CPU)
File sa19 with data from Linux 3.16.0-4-amd64 (myserver) 04/19/17 _x86_64_ (8 CPU)
File sa20 with data from Linux 3.16.0-4-amd64 (myserver) 04/20/17 _x86_64_ (8 CPU)
File sa21 with data from Linux 3.16.0-4-amd64 (myserver) 04/21/17 _x86_64_ (8 CPU)
File sa22 with data from Linux 3.16.0-4-amd64 (myserver) 04/22/17 _x86_64_ (8 CPU)
File sa23 with data from Linux 3.16.0-4-amd64 (myserver) 04/23/17 _x86_64_ (8 CPU)
-------------------------------------------
Note that the number that follows the "sa" file specifies the day of the data collected by sar daemon
Please select a sa* file from the listed above: sa15
# Send by email day 04 statistics
./system_data_reader.sh -f sa04 -m [email protected]
# Send by email day 04 statistics between 09:00 and 12:00
./system_data_reader.sh -f sa04 -s 09:00 -e 12:00 -m [email protected]
# Send by email day 05 statistics just since 10:00
./system_data_reader.sh -f sa05 -s 10:00 -m [email protected]
# Just parse day 05 statistics
./system_data_reader.sh -f sa05
# Send graphs statistics from present day everyday at 23:30
30 23 * * * /home/jota/scripts/sarviewer/system_data_reader.sh -f sa$(date +\%d) -m [email protected]
# Send graphs statistics from the day before everyday at 23:30
30 23 * * * /home/jota/scripts/sarviewer/system_data_reader.sh -f sa$(date +\%d -d yesterday) -m [email protected]
Some samples of graphs generated with gnuplot
Some samples of graphs generated with matplotlib (Python)