• Get In Touch
October 9, 2016

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

  • A server running Ubuntu-14.04 with Docker installed.
  • A non-root user with sudo privileges setup on server.

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

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]