Build a modern monitoring system using Grafana, collectd, and InfluxDB
To create a beautiful real-time monitoring system like New Relic, we only need the three InfluxDB, collectd, and Grafana tools. The relationship between these three tools is as follows:
Collect data-> store data (InfluxDB)-> display data (Grafana ).
- InfluxDB is an open-source Distributed Time Series database developed by the Go language. It is ideal for storing metrics, events, analysis, and other data. You can see that this project is still very young when you look at the version number (v0.8.8;
- Collectd is a system performance collection tool written in C language;
- Grafana is a front-end tool developed by pure Javascript. It is used to access InfluxDB, customize reports, and display charts.
The following installation and configuration steps are completed on Ubuntu 14.04 Server 64bit. Restart the entire system after upgrading:
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo reboot
Install InfluxDB
InfluxDB is written in Go and is clean without any other packages or libraries. Easy to install:
$ wget https://s3.amazonaws.com/influxdb/influxdb_latest_amd64.deb
$ sudo dpkg -i influxdb_latest_amd64.deb
Start InfluxDB:
$ sudo /etc/init.d/influxdb start
Setting ulimit -n 65536
Starting the process influxdb [ OK ]
influxdb process was started [ OK ]
Open the web Management Interface http: // 192.168.2.183: 8083/the default username and password are root and root. the Web management interface port of InfluxDB is 8083, And the http api listening port is 8086. to change these default settings, modify the InfluxDB configuration file/opt/influxdb/current/config. after toml, restart InfluxDB.
Create a database named collectd on the newly installed InfluxDB, which can be created using the command line or the Web management interface:
$ curl "http://192.168.2.183:8086/db?u=root&p=root"-d "{\"name\": \"collectd\"}"
Install collectd
Install collectd:
$ sudo apt-get install collectd
Configure collectd as the client and send the collected data directly to InfluxDB:
$ sudo vi /etc/collectd/collectd.conf
...
LoadPlugin network
...
<Plugin network>
Server"192.168.2.183""25826"
</Plugin>
...
Restart collectd:
$ sudo /etc/init.d/collectd restart
InfluxDB now comes with a collectd plug-in to obtain the data sent from the collectd client, which is not so convenient in the past, before Version 0.8.4, you can only use a third-party program such as influxdb-collectd-proxy to connect collectd and InfluxDB. if you check the port opened on the server, you will find that the influxdb plug-in has started port 25826. If the InfluxDB database does not have (collected) data, check whether port 25826 is enabled properly:
$ sudo netstat -tupln
ActiveInternet connections (only servers)
ProtoRecv-Q Send-Q LocalAddressForeignAddressState PID/Program name
tcp 000.0.0.0:220.0.0.0:* LISTEN 622/sshd
tcp6 00:::8086:::* LISTEN 668/influxdb
tcp6 00:::22:::* LISTEN 622/sshd
tcp6 00:::8090:::* LISTEN 668/influxdb
tcp6 00:::8099:::* LISTEN 668/influxdb
tcp6 00:::8083:::* LISTEN 668/influxdb
udp6 00:::25826:::*668/influxdb
The built-in collectd plug-in of InfluxDB is disabled by default. You need to manually enabled = true and fill in the row "database =" collectd, the "collectd" here is the database we created above. After changing the configuration, remember to restart InfluxDB:
$ sudo vi /opt/influxdb/current/config.toml
$ sudo vi /opt/influxdb/shared/config.toml
...
# Configure the collectd api
[input_plugins.collectd]
enabled =true
# address = "0.0.0.0" # If not set, is actually set to bind-address.
# port = 25826
database ="collectd"
# types.db can be found in a collectd installation or on github:
# https://github.com/collectd/collectd/blob/master/src/types.db
# typesdb = "/usr/share/collectd/types.db" # The path to the collectd types.db file
...
$ sudo /etc/init.d/influxdb restart
Setting ulimit -n 65536
Setting ulimit -n 65536
influxdb process was stopped [ OK ]
Setting ulimit -n 65536
Starting the process influxdb [ OK ]
influxdb process was started [ OK ]
Now, InfluxDB is ready to accept and process data from collectd. Use the command line or Web management interface to verify whether data exists in the database:
$ curl -G 'http://192.168.2.183:8086/db/collectd/series?u=root&p=root&q=list+series&pretty=true'
[
{
"name":"list_series_result",
"columns":[
"time",
"name"
],
"points":[
[
0,
"192.168.2.183/cpu-0/cpu-idle"
],
...
]
}
]
Install Grafana
Download grafana and decompress it on the web server. This saves the trouble of configuring Nginx/Apache, and directly uses the simplest Web Server python-m SimpleHTTPServer DRIVER:
$ wget http://grafanarel.s3.amazonaws.com/grafana-1.9.1.tar.gz
$ tar xzvf grafana-1.9.1.tar.gz
$ cd grafana-1.9.1.tar.gz
$ cp config.sample.js config.js
$ vi config.js
...
// InfluxDB example setup (the InfluxDB databases specified need to exist)
datasources:{
influxdb:{
type:'influxdb',
url:"http://192.168.2.183:8086/db/collectd",
username:'root',
password:'root',
},
...
},
...
$ sudo python -m SimpleHTTPServer
Access Grafana through a browser. The default port here is 8000:
This article permanently updates the link address: