My HP

9th October, 2016 | Tutorials |

How to Create Grafana and InfluxDB Docker Containers in Ubuntu-14.04

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.

Get a Cloud Server

InfluxDB : InfluxDB is an open-source time series database written in Go that has been built to work best with metrics, events, and analytics. Using InfluxDB, you can easily store system and application performance data and manage any time series data.

Grafana : Grafana is an open-source, general purpose dashboard that is used for visualizing time series data for Internet infrastructure and application analytics. Grafana supports graphite, influxdb or opentsdb as backends and runs as a web application.

In this tutorial, we will learn how to create and run Grafana and InfluxDB Docker containers in Ubuntu 14.04.

Requirements

Creating The Dockerfile

First, you will need to create the Docker file to install all requisite software. Create docker file inside your home directory using the following command:

sudo nano Dockerfile

Add the following lines with all requisite software:

    FROM ubuntu
    MAINTAINER Hitesh Jethva (hitjethva@gmail.com)

RUN apt-get update && apt-get -y --no-install-recommends install ca-certificates software-properties-common python-django-tagging python-simplejson python-memcache python-ldap python-cairo python-pysqlite2 python-support python-pip gunicorn supervisor nginx-light nodejs git curl openjdk-7-jre build-essential python-dev

Add the following lines to install Grafana, InfluxDB, and do some basic configuration:

    WORKDIR /opt
    RUN 
      curl -s -o /opt/grafana-1.8.1.tar.gz http://grafanarel.s3.amazonaws.com/grafana-1.8.1.tar.gz && 
      curl -s -o /opt/influxdb_latest_amd64.deb http://s3.amazonaws.com/influxdb/influxdb_latest_amd64.deb && 
    mkdir /opt/grafana && 
      tar -xzvf grafana-1.8.1.tar.gz --directory /opt/grafana --strip-components=1 && 
      dpkg -i influxdb_latest_amd64.deb && 
      echo "influxdb soft nofile unlimited" >> /etc/security/limits.conf && 
      echo "influxdb hard nofile unlimited" >> /etc/security/limits.conf

Next, copy some configuration files:

    ADD config.js /opt/grafana/config.js
    ADD nginx.conf /etc/nginx/nginx.conf
    ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
    ADD types.db /opt/influxdb/current/types.db
    ADD config.toml /opt/influxdb/current/config.toml

Next, map volumes, expose ports, and setup the run command:

    VOLUME ["/opt/influxdb/shared/data"]

EXPOSE 80 8083 8086 8096

CMD ["supervisord", "-n"]

After adding all the content, your file should looks like the following:

    FROM ubuntu
    MAINTAINER Hitesh Jethva (hitjethva@gmail.com)

RUN apt-get update && apt-get -y --no-install-recommends install ca-certificates software-properties-common python-django-tagging python-simplejson python-memcache python-ldap python-cairo python-pysqlite2 python-support python-pip gunicorn supervisor nginx-light nodejs git curl openjdk-7-jre build-essential python-dev

WORKDIR /opt RUN curl -s -o /opt/grafana-1.8.1.tar.gz http://grafanarel.s3.amazonaws.com/grafana-1.8.1.tar.gz && curl -s -o /opt/influxdb_latest_amd64.deb http://s3.amazonaws.com/influxdb/influxdb_latest_amd64.deb && mkdir /opt/grafana && tar -xzvf grafana-1.8.1.tar.gz --directory /opt/grafana --strip-components=1 && dpkg -i influxdb_latest_amd64.deb && echo "influxdb soft nofile unlimited" >> /etc/security/limits.conf && echo "influxdb hard nofile unlimited" >> /etc/security/limits.conf

ADD config.js /opt/grafana/config.js ADD nginx.conf /etc/nginx/nginx.conf ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf ADD types.db /opt/influxdb/current/types.db ADD config.toml /opt/influxdb/current/config.toml

VOLUME ["/opt/influxdb/shared/data"]

EXPOSE 80 8083 8086 8096

CMD ["supervisord", "-n"]

Configure Grafana

Once Dockerfile is created, you will need to create config.js file at your home directory:

sudo nano config.js

Add / Edit the following lines as per your requirements:

    datasources: {
        influxdb: {
          type: 'influxdb',
          url: "http://your-server-ip:8086/db/testdb",
          username: 'root',
          password: 'root',
        },
        grafana: {
          type: 'influxdb',
          url: "http://your-server-ip:8086/db/grafana",
          username: 'root',
          password: 'root',
          grafanaDB: true
        },
      },

Configure InfluxDB

Next, you will need to enable collectdb in InfluxDB's config.toml

sudo nano config.toml

Add / Edit the following lines:

    [input_plugins]
      [input_plugins.collectd]
      enabled = true
      port = 8096
      database = "testdb"
      typesdb = "/opt/influxdb/current/types.db"

Building the Container

Once you have finished, it's time to build container. Before starting, make sure you're working directory has your Dockerfile and configuration files in it.

Now, run the following command to create the container:

sudo docker build -t influx .

-t perameter specify the name of the image.

Once you have built the container, you will need to start the container. You can do this by running the following command:

sudo docker run --name influx -d -v /opt/influxdb/:/opt/influxdb/shared/data -p 80:80 -p 8083:8083 -p 8086:8086 -p 8096:8096/udp influx

The above command starts the influx image, map the container path of /opt/influxdb/shared/data to your local /opt/influxdb, your local port 80, 8083, and 8086 to the exposed ports in the container and map port 8096 to UDP.

You can check the container is running by issuing the following command:

sudo docker ps

Accessing Grafana and InfluxDB

Once everything is up-to-date, you can reach the grafana web interface by typing the URL http://your-server-ip in your web browser, you should see the Grafana default page as below:

HP_NO_IMG/data/uploads/users/7ecb43a5-b365-4ebf-93d5-f3b632f29f33/1233861792.png" alt="" />

You can the access InfluxDB management interface using the URL http://your-server-ip:8083 on your web browser.

HP_NO_IMG/data/uploads/users/7ecb43a5-b365-4ebf-93d5-f3b632f29f33/47301862.png" alt="" />

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.

Get a Cloud Server

Comments