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 we find available in all Linux distributions. Additionally, we also need to install the jq command.

Follow these steps:

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. Next, we will use these 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. Then 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 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 we can calculate the intervals as seconds with the epoch time (Unix time) or by specifying the reference.

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

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

In conclusion, this was our tutorial on how to measure the traffic of your virtual machines. We hope you found it useful!