#influxdb

Monitor Nginx with CollectD, InfluxDB and Grafana

Monitor is the best solution to know your system is working well or not.  If your system is complicated,  you will have many things need to be monitored. In this post, I just show you a simple way to monitor Nginx with CollectD, InfluxDB and Grafana.

Before reading this post, make sure that you are take a look Monitor server with CollectD, InfluxDB and Grafana to get started with CollectD, InfluxDB and Grafana.

Nginx

To monitor Nginx, your nginx have to be enabled http_stub_status_module. At the first, you should check your Nginx contains http_stub_status_module or not by command:

In the default, if you are using Ubuntu 14.04, and install nginx by apt-get command, then you do not worry about the step above.

And now, you should change nginx config with the content below:

And restart your nginx:

Now, you can get nginx status by url http://127.0.0.1/nginx_status:

The output should be:

CollectD

In the next step, we will enable Nginx plugin of CollectD in /opt/collectd/etc/collectd.conf:

Restart your CollectD:

InfluxDB

After restarting CollectD, you wait a minute then checking InfluxDB to make sure that Nginx monitor data is stored.

Grafana

In the last step, we create a Graph Panel in Grafana to monitor how many “requests per second” . And Switch editor Mode to input the query below:

If you do not know how to “Switch editor mode”, you should see the image below:

14-01-2016 9-17-47 SA

Grafana – Switch editor mode

Finally, you will get the graph below:

13-01-2016 10-17-47 SA

Nginx – Request Per Second

You can also use data stored in InfluxDB to create the output by your way.

 

Monitor server with CollectD, InfluxDB and Grafana

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

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.
Collectd Grafana InfluxDB

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:

(libcurl4-gnutls-dev to enable curl and nginx plugin)

Edit /opt/collectd/etc/collectd.conf to enable CollectD collect cpu data with percentage instead of jitters:

And enable network plugin to push monitor data to InfluxDB at address 192.168.1.194, port 25826

Restart CollectD

Debug:

And now, we install InfluxDB and Grafana in Server 192.168.1.194

InfluxDB

Install with dpkg command:

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:

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:

For troubleshoot the issue with InfluxDB, we can view logs:

Grafana

Download and install via dpkg command:

If you meet an error as below:

You can correct it by the commands:

 

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:

25-11-2015 3-22-51 CH

Grafana connects to InfluxDB (default account root/root)

After that, create New Dash Board => New Panel => Graph as image below:

28-11-2015 7-31-40 CH

Grafana + CollectD CPU (percentage)

I created a new dashboard that help me monitor CPU and RAM:

25-11-2015 4-19-02 CH

Grafana, CollectD and InfluxDB

Tips

To collect interface data in bytes per second we should use: