uvic startup slam september 2014 (pretio)

29
Pretio Real-time Mapping of API Requests Rob O'Dwyer Nathan Lambert Cameron Rohani

Upload: sendwithus

Post on 25-Dec-2014

38 views

Category:

Technology


2 download

DESCRIPTION

Startup Slam! Vic Startups Talk. Real Code. Real Technology. On September 20th, 2014, five ambitious startups visited the University of Victoria (UVic). Kiind, Tiny Mob Games, Kano Apps, Sendwithus, and Pretio Interactive delievered tech talks to UVic students.

TRANSCRIPT

Page 1: UVic Startup Slam September 2014 (Pretio)

PretioReal-time Mapping of API Requests

Rob O'Dwyer

Nathan Lambert

Cameron Rohani

Page 2: UVic Startup Slam September 2014 (Pretio)

We power reward-based advertising on mobile apps and FB games

About Pretio

Page 3: UVic Startup Slam September 2014 (Pretio)
Page 4: UVic Startup Slam September 2014 (Pretio)
Page 5: UVic Startup Slam September 2014 (Pretio)

Why this ProjectWe wanted to start making visualizations of our dataSee patterns in geographic locationShow traffic changes and shifts in popularity as they happenInvestors like pretty graphs!

Page 6: UVic Startup Slam September 2014 (Pretio)

Where's the Data From?Mobile Ad Unit APITraffic from one of our US-only publishers

Page 7: UVic Startup Slam September 2014 (Pretio)

JSON Event{ "@version": "1", "@timestamp": "2014-09-20T02:11:57.681Z", "type": "offers:served", "offer": "3585b8da3f5011e4a11a12313f063e60", "user_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "geoip": { "country_code2": "US", "country_name": "United States", "city_name": "Louisville", "latitude": 38.2542, "longitude": -85.7594, "timezone": "America/New_York" }, "tags": ["geo"]}

Page 8: UVic Startup Slam September 2014 (Pretio)

Check it out at

Quick Demogeo.pretio.in

Page 9: UVic Startup Slam September 2014 (Pretio)
Page 10: UVic Startup Slam September 2014 (Pretio)

The MapUses Custom icons

Leaflet.js

Page 11: UVic Startup Slam September 2014 (Pretio)

Server-Sent EventsHTML5Stream data in real-time to the browser

Page 12: UVic Startup Slam September 2014 (Pretio)

Why not Websockets??Bidirectional, more flexibilitySpecial server support neededSSE - lines of text from a long HTTP connectionAuto reconnects!

Page 13: UVic Startup Slam September 2014 (Pretio)

Server-Sent Event Protocolevent: notificationdata: hello world

event: locationdata: {data: "latitude": 38.2542,data: "longitude": -85.7594data: }

Page 14: UVic Startup Slam September 2014 (Pretio)

In the browser// Connect to servervar source = new EventSource('server/path/to/events');

source.addEventListener('open', function(e) { console.log('Connected!');});

// Listen for "location" eventssource.addEventListener('location', function(e) {

// We're sending data as JSON var data = JSON.parse(e.data);

displayOnMap(data.latitude, data.longitude);

});

Page 15: UVic Startup Slam September 2014 (Pretio)

node.jsSo hot right nowEvent-driven JavaScript on the serverGood for building "real-time" apps

Page 16: UVic Startup Slam September 2014 (Pretio)

The appUses for rendering web pagesSimple UDP server that receives events

Express

Page 17: UVic Startup Slam September 2014 (Pretio)

Listening for UDP packetsvar udpServer = udp.createSocket('udp4', function(msg, remote) {

console.log('Received message from ' + remote.address + ':' + remote.port);

try { var data = JSON.parse(msg);

// Send out as event events.emit('received', data);

} catch(err) { console.error('Error parsing message: ' + err); }});

// Listen for UDP messagesudpServer.bind(PORT, '0.0.0.0');

Page 18: UVic Startup Slam September 2014 (Pretio)

Event Streamapp.get('/events', function(req, res) {

console.log('New client connected!');

res.status(200) .set({ 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive' });

// Listen for events from UDP server events.on('received', function(data) { // Send new "location" event to browser res.write('event: location\n'); res.write('data: ' + JSON.stringify(data) + '\n\n'); });});

Page 19: UVic Startup Slam September 2014 (Pretio)

Logstash

A tool for parsing, rewriting and shipping logsContinuous pipeline of eventsConnects to almost everything (log files, queues, sockets, DBs, etc.)IP » Geo is built-in

Page 20: UVic Startup Slam September 2014 (Pretio)

Sample Logstash Configinput { redis { data_type => channel host => "redis.server" port => 6379 key => logs:offer_serving codec => json }}

filter { grok { match => [ "[ip]", "%{IP:client_ip}" ] } geoip { source => client_ip }}

output { udp { codec => json host => "geo.pretio.in" port => 3847 }}

Page 21: UVic Startup Slam September 2014 (Pretio)

Read your web server logs!input { file { path => "/var/log/apache/access.log" }}filter { grok { pattern => "%{COMBINEDAPACHELOG}" }}

Page 22: UVic Startup Slam September 2014 (Pretio)

IP GeolocationUses free MaxMind GeoIP databaseNot very accurate

Page 23: UVic Startup Slam September 2014 (Pretio)

Redis

Advanced key-value datastoreAPI Servers publish events to hereLogstash picks them up

Page 24: UVic Startup Slam September 2014 (Pretio)

Multi-layered Rendering

Page 25: UVic Startup Slam September 2014 (Pretio)
Page 26: UVic Startup Slam September 2014 (Pretio)
Page 27: UVic Startup Slam September 2014 (Pretio)
Page 28: UVic Startup Slam September 2014 (Pretio)

IdeasShow server logs from your appPlotting real-time tweet data

Page 29: UVic Startup Slam September 2014 (Pretio)

?