RRDTOOL
Monitor and graph your system metrics
Graphs make Matt Holder happy, so he spent his weekend storing system statistics in a database and pumping out graphs so you can, too!
Credit: https://oss.oetiker.ch/rrdtool
OUR EXPERT
Matt Holder has worked in IT support for over a decade, and always tries to use Linux alongside other installed systems.
The code used in this article can be downloaded from https:// github.com/ mattmole/ LXF297.
A susers who take interest in the operating systems we run, freedoms granted by the software we use and state of our networks, it can be of interest or importance to keep track of system metrics. Metrics of interest include download and upload internet speeds, and temperature and CPU usage of our servers and Raspberry Pis, which are likely to be running our home automation systems.
In this article, we will first of all discuss a method of writing our own tool that reads metrics, writes them to a database and then visualises them using the built-in graphing functionality.
RRDTool was originally written as a part of the Multi Router Traffic Grapher (MRTG) tool as a way of visualising the data it generated. This tool, while quite specialised and technical, is of interest to multiple projects and can serve many purposes.
Firstly, we shall describe what RRDTool actually is and explain some terminology, and then move on to writing the Python code to write data to the database and create the graphs. RRDTool stands for Round-Robin-Database Tool. When creating the database, we define the initial time that values can be sent from and a step size. This means that a database can start receiving values from now (defined using seconds since Unix epoch, which is 1st Jan 1970) and should receive a value every, for example, 30 seconds.
The next step in creating the database is to define our data sources (DS), and a database can hold many. To cycle back to our first example from above, the first data source could be download speed. When defining a data source, we need to define the name, representation type, time to wait until an ‘unknown’ value should be entered into the database, in case of lack of data, and then minimum and maximum values, if these are appropriate. Representation type depends on the data being stored. If we were looking at packet counts, we would want the representation type to be COUNTER as these values will increase for each number being sent to the database. If values can decrease as well as increase, then DERIVE should be used. Viewing absolute values, such as a download speed, should use the GAUGE type, as each value