Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building Custom Analytics with InfluxDB and D3

Paul Dix
January 27, 2014

Building Custom Analytics with InfluxDB and D3

Talk on InfluxDB and D3 given at the January NYC D3 meetup.

Paul Dix

January 27, 2014
Tweet

More Decks by Paul Dix

Other Decks in Technology

Transcript

  1. Analytics Database? • Metrics, events, time series • Infrastructure metrics

    • Application performance • User events/analytics • Business analytics
  2. Metrics or measurements • CPU load • Memory usage •

    Average response times • Counts over fixed intervals
  3. How data is organized • Databases (like in MySQL, Postgres,

    etc) • Time series ◦ like tables, but you can have millions of them ◦ no need to define ahead of time • Points or events ◦ like rows, but schemaless like Mongo ◦ single level hash
  4. [{ "name": "foo", "columns": [ "time", "sequence_number", "val1", "val2" ],

    "points": [ [1384295094, 3, "paul", 23], [1384295094, 2, "john", 92], [1384295094, 1, "todd", 61] ] }, {...}] As JSON
  5. [{ "name": "foo", "columns": [ "time", "sequence_number", "val1", "val2" ],

    "points": [ [1384295094, 3, "paul", 23], [1384295094, 2, "john", 92], [1384295094, 1, "todd", 61] ] }, {...}] JSON data returned
  6. [{ "name": "user_events", "columns": [ "time", "count" ], "points": [

    [1389729000, 3], [1389728700, 5], [1389728400, 1] ] }, {...}] JSON data returned
  7. [{ "name": "user_events", "columns": [ "time", "count", "state" ], "points":

    [ [1389729000, 3, "NY"], [1389729000, 5, "CO"], [1389728700, 1, "NY"] ] }, {...}] JSON data returned
  8. Other functions • Percentiles • Min, max, first, last, sum,

    count, stddev • Histogram • Lag, lead, funnel (next release)
  9. # install influxdb brew update && brew install influxdb influxdb

    -config=/usr/local/etc/influxdb.conf # set up the admin dashboard git clone https://github.com/influxdb/influxdb-admin cd influxdb-admin bundle install middleman server open http://localhost:4567 Building Custom UIs
  10. Starting the Interface # make the dir in the local

    admin interface # dir so it shows up on the drop down mkdir /usr/local/opt/influxdb/share/admin/interfaces/paul_owns # make the dir and file in the influxdb-admin repo mkdir source/interfaces/paul_owns touch source/interfaces/paul_owns/index.html # or slim, etc.
  11. <script src="http://code.jquery.com/jquery-2.0.3.min.js" type="text/javascript"></script> <script src="http://d3js.org/d3.v3.min.js" type="text/javascript"></script> <script src="http://influxdb.org/javascripts/vendor/rickshaw.js" type="text/javascript"></script> <script

    src="/javascripts/interfaces/paul_owns.js" type="text/javascript"></script> <link href="http://influxdb.org/stylesheets/vendor/rickshaw.css" media="screen" rel="stylesheet" type="text/css">
  12. q = "SELECT COUNT(type) FROM events GROUP BY time(1h), type

    fill(0)" parent.influxdb.query(q, (points) => typeToSeries = {} points.forEach((point) => series = typeToSeries[point.type] if !series typeToSeries[point.type] = []; series = typeToSeries[point.type]; series.push({x: point.time / 1000, y: point.count}) )
  13. lastColorUsed = -1 colors = d3.scale.category10() data = for type,

    series of typeToSeries lastColorUsed += 1 { data: series.reverse(), color: colors(lastColorUsed), name: type }
  14. hoverDetail = new Rickshaw.Graph.HoverDetail graph: graph, formatter: (series, x, y)

    -> date = '<span class="date">' + new Date(x * 1000).toUTCString() + '</span>' swatch = '<span class="detail_swatch" style="background-color: ' + series.color + '"></span>' content = swatch + series.name + ": " + parseInt(y) + '<br>' + date renderDetail(series.name, x) content
  15. renderDetail = (series, x) => startTime = x endTime =

    startTime + 3600 q = "select * from events where time > " + startTime + "s and time < " + endTime + "s and type = '" + series + "'"
  16. parent.influxdb.query(q, (points) => ul = "<ul>" points.forEach (point) => li

    = "<li>" li += point.email li += "</li>" ul += li ul += "</ul>" $("#events_detail").html(ul) )