The first step is to install CollectD:
yum -y install epel-release yum -y install collectd
At the time of writing, this resulted in the installation of CollectD version 5.5.0. If you are using an older version of CentOS, make sure that you do not install version 4 or lower.
The configuration can be tweaked to your liking, but should contain at least something like this in /etc/collectd.conf:
FQDNLookup true BaseDir "/var/lib/collectd" PIDFile "/var/run/collectd.pid" PluginDir "/usr/lib64/collectd" TypesDB "/usr/share/collectd/types.db" LoadPlugin syslog LoadPlugin interface LoadPlugin load LoadPlugin network <Plugin interface> Interface "eth0" IgnoreSelected false </Plugin> <Plugin load> ReportRelative true </Plugin> <Plugin network> Server "127.0.0.1" "25826" </Plugin>
The most important part is the “network” plugin, where we define that the measurements should be sent to 127.0.0.1 on port 25826. We will instruct InfluxDB shortly to listen on that port for incoming packets from CollectD.
Now start the daemon and make sure that it starts at boot as well:
systemctl start collectd.service systemctl enable collectd.service
Installation of InfluxDB can be achieved like this:
yum -y install http://influxdb.s3.amazonaws.com/influxdb-0.9.4.2-1.x86_64.rpm
Edit the InfluxDB configuration file /etc/opt/influxdb/influxdb.conf and change the lines near the [collectd] heading as follows:
[collectd] enabled = true bind-address = "127.0.0.1:25826" database = "collectd" typesdb = "/usr/share/collectd/types.db"
And then start the daemon:
systemctl start influxdb.service
You can now check if the measurements from CollectD are received by InfluxDB as follows:
# /opt/influxdb/influx Connected to http://localhost:8086 version 0.9.4.2 InfluxDB shell 0.9.4.2 > use collectd Using database collectd > show measurements name: measurements ------------------ name interface_rx interface_tx load_longterm load_midterm load_shortterm
The final step is installing and starting Grafana:
yum -y install https://grafanarel.s3.amazonaws.com/builds/grafana-2.5.0-1.x86_64.rpm systemctl start grafana-server.service systemctl enable grafana-server.service
Start a webbrowser and navigate to http://the_host_running_grafana:3000. Login with username admin and password admin. You will be presented with the following page:
Now click on Data Sources and then Add new. Fill in the resulting screen as follows:
The default user for InfluxDB is root and the password is also root. Test the connection and then save.
Click on Dashboards, then on the triangle pointing down next to Home, then on New:
The screen now shows a small green rectangle just below New dashboard. Hover over this rectangle and select Add Panel and then Graph:
A graph is now shown with test data. Click on the title of this graph and choose Edit. Click on — Grafana — and select collectd as the datasource:
An edit window now allows you to change the appearance and data of the graph. On the General tab, change the title of the graph into Load. On the Metrics tab, click on select measurement next to FROM and select load_longterm. Click on the plus sign next to WHERE and select host. Then click on select tag value and choose the name of the host you want to display the load from. Finally, change the value of ALIAS BY to Long:
Click on + Query to add similar queries for the mid term and short term load values. Finally, click on the save button on the top of the screen. The graph should now look like this:
For showing the network traffic statistics for our host, we will add a new graph to the dashboard. Click on + ADD ROW, then on the green rectangle and select Add Panel and Graph again. Select the collectd datasource. This time, we will not be able to use the visual query editor. The measurements from interface_rx and interface_tx are numbers that show the total number of packets or bytes, instead of the numbers per time unit. Click on the three horizontal lines on the right side of the graph editor and choose Switch editor mode:
Use the following text in the input box:
SELECT derivative("value") AS "value" FROM "interface_rx" WHERE "host" = 'test' AND "type" = 'if_octets' AND "instance" = 'eth0'
Make sure to change the value of host and instance to the correct values. Also make sure to use single quotes for the values and not double quotes. On the Axes & Grid tab, change the unit of Left Y to bytes per second:
Click on + Query to add a similar query for interface_tx. Add aliases for both queries: Received for interface_rx and Transmitted for interface_tx. Now the graph looks like this: