Measuring VM Traffic on CloudSigma

How to measure the traffic on your VM with the CloudSigma API and RRDtool

Learn how to measure the traffic of your virtual machines in CloudSigma using the simple instructions below, to obtain, store and graph the traffic from our different network interfaces. To obtain the statistics of each interface we can make use of the CloudSigma API and a simple script that will store the data of each network interface.

The database we use in this example is RRDTool, a database specially for time series data. You can also use other similar databases like InfluxDB or Graphite, but for this example we will continue with the old and reliable RRDTool that is found available in all Linux distributions. Additionally, we also need to install the jq command.

The first step will be to create a database where we will store the traffic of our network interface to monitor in our designated directory:

With this command we are creating a database with two Data Sources (DS), one for incoming traffic (traffic_in) and one for outbound traffic (traffic_out). The next part will be to obtain the statistics of the interface with the CloudSigma API. First of all we will get the string to authenticate with the CloudSigma API:

From here we will obtain a text string with the username and password in Base64 that we will use in the script to obtain the data:

This script will obtain the number of bytes sent and received with the public IP interface, and will be saved to the rdd file. It is important to note that the sign for tx and rx are inverted relative to how we want to measure the traffic on the public interface. That is to say that if the API reports 20 Megabytes of reception (rx), the virtual machine will report those 20 Megabytes in the transmission (tx). For example:

We now have to execute this command periodically so that we obtain the flow of statistics. For this we create a cronjob that runs every 5 minutes and feeds the data with the command crontab -e and we add the following line to the end of the file.

This will feed the data to the rrd file.

Finally, we want to graph the data or query specific data intervals also with rrdtool. For example, let’s say that we want to obtain the graph and the total bandwidth consumed in the last 7 days. For the time interval we use the parameters --end now --start end-7d.

With this we will create a graph with the total summary of the bandwidth calculated by the VDEF functions. The time intervals can be calculated as seconds with the epoch time (Unix time) or by specifying the reference.

Finally I share the documentation and official site of RRDtool, so you can learn more about this tool that has many more amazing functions it offers:

https://oss.oetiker.ch/rrdtool/doc/index.en.html

Share this Post

Leave a Reply