Grafana is an open source feature rich metrics dashboard. It is very useful for visualizing large-scale measurement data. It provides a powerful and elegant way to create, share, and explore data and dashboards from your disparate metric databases.
It supports a wide variety of graphing options for ultimate flexibility. Furthermore, it supports many different storage backends for your Data Source. Each Data Source has a specific Query Editor that is customized for the features and capabilities that the particular Data Source exposes. The following datasources are officially supported by Grafana: Graphite, InfluxDB, OpenTSDB, Prometheus, Elasticsearch and Cloudwatch
The query language and capabilities of each Data Source are obviously very different. You can combine data from multiple Data Sources onto a single Dashboard, but each Panel is tied to a specific Data Source that belongs to a particular Organization. It supports authenticated login and a basic role based access control implementation. It is deployed as a single software installation which is written in Go and Javascript.
In this article, I'll explain on how to install Grafana on a docker container in Ubuntu 16.04 and configure docker monitoring using this software.
### Pre-requisites ###
- Docker installed server
### Installing Grafana ###
We can build our Grafana in a docker container. There is an official docker image available for building Grafana. Please run this command to build a Grafana container.
We can confirm the working of the Grafana container by running this command `docker ps -a` or by accessing it by URL `http://Docker IP:3000`
All Grafana configuration settings are defined using environment variables, this is much useful when using container technology. The Grafana configuration file is located at /etc/grafana/grafana.ini.
### Understanding the Configuration ###
The Grafana has number of configuration options that can be specified in its configuration file as .ini file or can be specified using environment variables as mentioned before.
#### Config file locations ####
Normal config file locations.
- Default configuration from : $WORKING_DIR/conf/defaults.ini
- Custom configuration from : $WORKING_DIR/conf/custom.ini
PS : When you install Grafana using the deb or rpm packages or docker images, then your configuration file is located at /etc/grafana/grafana.ini
#### Understanding the config variables ####
Let's see some of the variables in the configuration file below:
`instance_name` : It's the name of the grafana server instance. It default value is fetched from ${HOSTNAME}, which will be replaced with environment variable HOSTNAME, if that is empty or does not exist Grafana will try to use system calls to get the machine name.
`[paths]`
`data` : It's the path where Grafana stores the sqlite3 database (when used), file based sessions (when used), and other data.
`logs` : It's where Grafana stores the logs.
Both these paths are usually specified via command line in the init.d scripts or the systemd service file.
`[server]`
`http_addr` : The IP address to bind the application. If it's left empty it will bind to all interfaces.
`http_port` : The port to which the application is bind to, defaults is 3000. You can redirect your 80 port to 3000 using the below command.
`root_url` : This is the URL used to access Grafana from a web browser.
`cert_file` : Path to the certificate file (if protocol is set to https).
`cert_key` : Path to the certificate key file (if protocol is set to https).
`[database]`
Grafana uses a database to store its users and dashboards and other informations. By default it is configured to use sqlite3 which is an embedded database included in the main Grafana binary.
`type`
You can choose mysql, postgres or sqlite3 as per our requirement.
`path`
It's applicable only for sqlite3 database. The file path where the database will be stored.
`host`
It's applicable only to MySQL or Postgres. it includes IP or hostname and port. For example, for MySQL running on the same host as Grafana: host = 127.0.0.1:3306
`name`
The name of the Grafana database. Leave it set to grafana or some other name.
`user`
The database user (not applicable for sqlite3).
`password`
The database user's password (not applicable for sqlite3).
`ssl_mode`
For Postgres, use either disable, require or verify-full. For MySQL, use either true, false, or skip-verify.
`ca_cert_path`
(MySQL only) The path to the CA certificate to use. On many linux systems, certs can be found in /etc/ssl/certs.
`client_key_path`
(MySQL only) The path to the client key. Only if server requires client authentication.
`client_cert_path`
(MySQL only) The path to the client cert. Only if server requires client authentication.
`server_cert_name`
(MySQL only) The common name field of the certificate used by the mysql server. Not necessary if ssl_mode is set to skip-verify.
`[security]`
`admin_user` : It is the name of the default Grafana admin user. The default name set is admin.
`admin_password` : It is the password of the default Grafana admin. It is set on first-run. The default password is admin.
`login_remember_days` : The number of days the keep me logged in / remember me cookie lasts.
`secret_key` : It is used for signing keep me logged in / remember me cookies.
### Essentials components for setting up Monitoring ###
We use the below components to create our Docker Monitoring system.
`cAdvisor` : It is otherwise called Container Advisor. It provides its users an understanding of the resource usage and performance characteristics. It collects, aggregates, processes and exports information about the running containers. You can go through this documentation for more information about this.
`InfluxDB` : It is a time series, metrics, and analytic database. We use this datasource for setting up our monitoring. cAdvisor displays only real time information and doesn’t store the metrics. Influx Db helps to store the monitoring information which cAdvisor provides in order to display a time range other than real time.
`Grafana Dashboard` : It allows us to combine all the pieces of information together visually. This powerful Dashboard allows us to run queries against the data store InfluxDB and chart them accordingly in beautiful layout.
### Installation of Docker Monitoring ###
We need to install each of these components one by one in our docker system.
#### Installing InfluxDB ####
We can use this command to pull InfluxDB image and setuup a influxDB container.
You can test our cAdvisor installation by calling this URL >>http://45.79.148.234:8080. This will provide you the statistics of your Docker host and containers.
Now we can login to Grafana and configure the Data Sources. Navigate to http://45.79.148.234:3000 or just http://45.79.148.234:
Username - admin
Password - admin
Once we've installed Grafana, we can connect the InfluxDB. Login on the Dashboard and click on the Grafana icon(Fireball) in the upper left hand corner of the panel. Click on Data Sources to configure.
You can get [more information][1] on docker monitoring here. Thank you for reading this. I would suggest your valuable comments and suggestions on this. Hope you'd a wonderful day!