In the software development, Monitor is a big feature we need to concern. It is not only for monitoring the production. But we also need to monitor your testing environment (e.g for performance test, stress test). So in this post, I will show you how to monitor server with CollectD, InfluxDB and Grafana.
At the first, we have to install CollectD in the agent machine. In my case, the agent machine also uses Ubuntu 14.04. And we have to install CollectD version 5.5.0+. Why? Because all the versions easier 5.5.0, Plugin cpu of CollectD only use jitters metric that we can not show properly in Grafana.

Gopher and Gun T-Shirt
My scenario is:
- I have 2 servers installed Ubuntu 14.04
- One at address 192.168.1.194. And the other one is 192.168.1.192 that we need to monitor
- They can ping each others.

We will monitor server 192.168.1.192 with CollectD
So now, Install CollectD to Server 192.168.1.192.
CollectD
I recommend you install CollectD from the source code to make sure that you are using the correct version.
Before running build the packet from source code, we need to install the dependencies:
|
sudo apt-get install libcurl4-gnutls-dev |
(libcurl4-gnutls-dev to enable curl and nginx plugin)
|
cd /tmp/ wget https://collectd.org/files/collectd-5.5.0.tar.bz2 tar -jxf collectd-5.5.0.tar.bz2 cd collectd-5.5.0 sudo ./configure sudo make all install sudo wget -O /etc/init.d/collectd https://raw.githubusercontent.com/martin-magakian/collectd-script/master/collectd.init sudo chmod 744 /etc/init.d/collectd # Run CollectD sudo /etc/init.d/collectd start |
Edit /opt/collectd/etc/collectd.conf to enable CollectD collect cpu data with percentage instead of jitters:
|
<Plugin cpu> ReportByCpu true ReportByState true ValuesPercentage true </Plugin> |
And enable network plugin to push monitor data to InfluxDB at address 192.168.1.194, port 25826
|
LoadPlugin network <Plugin network> # # client setup: Server "192.168.1.194" "25826" </Plugin> |
Restart CollectD
|
sudo /etc/init.d/collectd stop sudo /etc/init.d/collectd start |
Debug:
|
tcpdump -i eth0 -p -n dst port 25826 |
And now, we install InfluxDB and Grafana in Server 192.168.1.194
InfluxDB
Install with dpkg command:
|
wget http://influxdb.s3.amazonaws.com/influxdb_0.9.5_amd64.deb sudo dpkg -i influxdb_0.9.5_amd64.deb sudo service influxdb start |
InfluxDB Web run on port 8083, so you access web at address http://192.168.1.194:8083 and create collectd database:
Edit /etc/influxdb/influxdb.conf to enable collectd. See the content below:
|
[collectd] enabled = true bind-address = ":25826" # the bind address database = "collectd" # Name of the database that will be written to retention-policy = "" batch-size = 5000 # will flush if this many points get buffered batch-pending = 10 # number of batches that may be pending in memory batch-timeout = "10s" read-buffer = 0 # UDP read buffer size, 0 means to use OS default typesdb = "/usr/share/collectd/types.db" |
Please make note that with the configuration above we use port 25826 on UDP to receive monitor data that pushed from CollectD
And the next step, restart InfluxDb:
|
sudo /etc/init.d/influxdb restart |
For troubleshoot the issue with InfluxDB, we can view logs:
|
sudo tail -f /var/log/influxdb/influxd.log |
Grafana
Download and install via dpkg command:
|
wget https://grafanarel.s3.amazonaws.com/builds/grafana_2.5.0_amd64.deb sudo dpkg -i grafana_2.5.0_amd64.deb sudo service grafana-server start |
If you meet an error as below:
|
/tmp# sudo dpkg -i grafana_2.5.0_amd64.deb Selecting previously unselected package grafana. (Reading database ... 61771 files and directories currently installed.) Preparing to unpack grafana_2.5.0_amd64.deb ... Unpacking grafana (2.5.0) ... dpkg: dependency problems prevent configuration of grafana: grafana depends on libfontconfig; however: Package libfontconfig is not installed. dpkg: error processing package grafana (--install): dependency problems - leaving unconfigured Processing triggers for ureadahead (0.100.0-16) ... Errors were encountered while processing: grafana |
You can correct it by the commands:
|
apt-get install libfontconfig1 apt-get -f install |
Grafana run on port 3000. So you can access via link http://192.168.1.194:3000.
To connect InfluxDb, you follow the path: Grafana => Data Source => Add New => And Input the information as the image below:

Grafana connects to InfluxDB (default account root/root)
After that, create New Dash Board => New Panel => Graph as image below:

Grafana + CollectD CPU (percentage)
I created a new dashboard that help me monitor CPU and RAM:

Grafana, CollectD and InfluxDB
Tips
To collect interface data in bytes per second we should use:
|
SELECT derivative("value") FROM "interface_" WHERE "host" = 'yourhost' AND "instance" = 'eth0' AND "type" = 'if_octets' |