Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple start with InfluxDB & Grafana using Travis as a source of historical data

InfluxDB & Grafana starter pack

Simple example of how easy it is to jam numbers into InfluxDB and graph something with Grafana. I choose to use Travis as a source of historical time-series data.


Get InfluxDB installed with Homebrew

$ brew install influxdb
$ influxdb -config=/usr/local/etc/influxdb.conf

This might be a good time to just work through the InfluxDB getting started docs, just for some context.

Get the gem dependencies installed

$ gem install influxdb travis

And grab a copy Grafana and extract is somewhere where it can be served up via HTTP... Or just use heel.

Gather data

Use the InfluxDB console (http://localhost:8083/) to create a travis-builds database, and then simply run:

$ ruby travis-times.rb

It will simple iterate over the travis builds for Rails as far back as it can and pump the values into InfluxDB.


First use the InfluxDB interface to have a look your data - http://localhost:8083/ - where you can also delete the invalid build times:

DELETE FROM trails_rails WHERE time = 0

The influxdb ui tries to show some graphs, but Grafana would do better...


Once Grafana is extracted, copy config.sample.js to config.js, uncomment and fix the first section related to InfluxDB and open it up in a browser.

You should get a default screen with some help tips, but no graphs.

Next up, you can easily add a graph with the mean/median build times of the Rails project for the length of time for which you have metrics. You could also start playing with more queries to see what else is useful.

Simple Example

Get started

The main idea is to show just how low the barriers to entry are.

Go forth and measure stuff, and use real hard data to make decisions!

#!/usr/bin/env ruby
require 'travis'
require 'influxdb'
# Our client
influxdb = 'travis-builds'
# Our repo
rails = Travis::Repository.find("rails/rails")
# Iterate
rails.each_build do |build|
# Extract some build information
data = {
time: build.started_at.to_i,
number: build.number,
duration: build.duration,
job_count: build.job_ids.count,
finished_at: ( build.finished_at.nil? ? nil : build.finished_at.to_i ),
color: build.color
p data
# Jam this into influxdb
influxdb.write_point( "travis_rails", data )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.