SlideShare a Scribd company logo
1 of 29
Download to read offline
Pretio 
Real-time Mapping of API Requests 
Rob O'Dwyer 
Nathan Lambert 
Cameron Rohani
About Pretio 
We power reward-based advertising on mobile apps and FB games
Why this Project 
We wanted to start making visualizations of our data 
See patterns in geographic location 
Show traffic changes and shifts in popularity as they happen 
Investors like pretty graphs!
Where's the Data From? 
Mobile Ad Unit API 
Traffic from one of our US-only publishers
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"] 
}
Quick Demo 
Check it out at 
geo.pretio.in
The Map 
Uses 
Custom icons 
Leaflet.js
Server-Sent Events 
HTML5 
Stream data in real-time to the browser
Why not Websockets?? 
Bidirectional, more flexibility 
Special server support needed 
SSE - lines of text from a long HTTP connection 
Auto reconnects!
Server-Sent Event Protocol 
event: notification 
data: hello world 
event: location 
data: { 
data: "latitude": 38.2542, 
data: "longitude": -85.7594 
data: }
In the browser 
// Connect to server 
var source = new EventSource('server/path/to/events'); 
source.addEventListener('open', function(e) { 
console.log('Connected!'); 
}); 
// Listen for "location" events 
source.addEventListener('location', function(e) { 
// We're sending data as JSON 
var data = JSON.parse(e.data); 
displayOnMap(data.latitude, data.longitude); 
});
node.js 
So hot right now 
Event-driven JavaScript on the server 
Good for building "real-time" apps
The app 
Uses Express 
for rendering web pages 
Simple UDP server that receives events
Listening for UDP packets 
var 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 messages 
udpServer.bind(PORT, '0.0.0.0');
Event Stream 
app.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: locationn'); 
res.write('data: ' + JSON.stringify(data) + 'nn'); 
}); 
});
Logstash 
A tool for parsing, rewriting and shipping logs 
Continuous pipeline of events 
Connects to almost everything (log files, queues, sockets, DBs, etc.) 
IP » Geo is built-in
Sample Logstash Config 
input { 
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 
} 
}
Read your web server logs! 
input { 
file { 
path => "/var/log/apache/access.log" 
} 
} filter { 
grok { 
pattern => "%{COMBINEDAPACHELOG}" 
} 
}
IP Geolocation 
Uses free MaxMind GeoIP database 
Not very accurate
Redis 
Advanced key-value datastore 
API Servers publish events to here 
Logstash picks them up
Multi-layered Rendering
Ideas 
Show server logs from your app 
Plotting real-time tweet data
?

More Related Content

Similar to UVic Startup Slam September 2014 (Pretio)

Bringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek Meet
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek MeetBringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek Meet
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek MeetRobert Nyman
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSphilogb
 
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datosphilogb
 
maXbox Starter 40 REST API Coding
maXbox Starter 40 REST API CodingmaXbox Starter 40 REST API Coding
maXbox Starter 40 REST API CodingMax Kleiner
 
Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Ismael Celis
 
Server-Sent Events in Action
Server-Sent Events in ActionServer-Sent Events in Action
Server-Sent Events in ActionAndrei Rusu
 
Firefox OS: HTML5 sur les stéroïdes - HTML5mtl - 2014-04-22
Firefox OS: HTML5 sur les stéroïdes - HTML5mtl - 2014-04-22Firefox OS: HTML5 sur les stéroïdes - HTML5mtl - 2014-04-22
Firefox OS: HTML5 sur les stéroïdes - HTML5mtl - 2014-04-22Frédéric Harper
 
Windows Phone 7 Unleashed Session 2
Windows Phone 7 Unleashed Session 2Windows Phone 7 Unleashed Session 2
Windows Phone 7 Unleashed Session 2Wes Yanaga
 
Bloomberg API Open Source Development and Solution Providers India
Bloomberg API Open Source Development and Solution Providers IndiaBloomberg API Open Source Development and Solution Providers India
Bloomberg API Open Source Development and Solution Providers IndiaPoint Perfect Technology Solutions
 
Introduction to WSO2 Data Analytics Platform
Introduction to  WSO2 Data Analytics PlatformIntroduction to  WSO2 Data Analytics Platform
Introduction to WSO2 Data Analytics PlatformSrinath Perera
 
Notification Service 2005
Notification Service 2005Notification Service 2005
Notification Service 2005shram2k
 
AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】
AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】
AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】tsuchimon
 
Scaling Experimentation & Data Capture at Grab
Scaling Experimentation & Data Capture at GrabScaling Experimentation & Data Capture at Grab
Scaling Experimentation & Data Capture at GrabRoman
 
Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...
Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...
Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...BizTalk360
 
mDevCamp 2016 - Zingly, or how to design multi-banking app
mDevCamp 2016 - Zingly, or how to design multi-banking appmDevCamp 2016 - Zingly, or how to design multi-banking app
mDevCamp 2016 - Zingly, or how to design multi-banking appPetr Dvorak
 
Windows Azure Mobile Services
Windows Azure Mobile ServicesWindows Azure Mobile Services
Windows Azure Mobile ServicesSasha Goldshtein
 
Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)Deepak Gupta
 
Web 2.0 Patterns and Technologies - Lecture 07 - Web Information Systems (401...
Web 2.0 Patterns and Technologies - Lecture 07 - Web Information Systems (401...Web 2.0 Patterns and Technologies - Lecture 07 - Web Information Systems (401...
Web 2.0 Patterns and Technologies - Lecture 07 - Web Information Systems (401...Beat Signer
 

Similar to UVic Startup Slam September 2014 (Pretio) (20)

Bringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek Meet
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek MeetBringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek Meet
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek Meet
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
 
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datos
 
maXbox Starter 40 REST API Coding
maXbox Starter 40 REST API CodingmaXbox Starter 40 REST API Coding
maXbox Starter 40 REST API Coding
 
Async
AsyncAsync
Async
 
Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010
 
Server-Sent Events in Action
Server-Sent Events in ActionServer-Sent Events in Action
Server-Sent Events in Action
 
Firefox OS: HTML5 sur les stéroïdes - HTML5mtl - 2014-04-22
Firefox OS: HTML5 sur les stéroïdes - HTML5mtl - 2014-04-22Firefox OS: HTML5 sur les stéroïdes - HTML5mtl - 2014-04-22
Firefox OS: HTML5 sur les stéroïdes - HTML5mtl - 2014-04-22
 
Windows Phone 7 Unleashed Session 2
Windows Phone 7 Unleashed Session 2Windows Phone 7 Unleashed Session 2
Windows Phone 7 Unleashed Session 2
 
Bloomberg API Open Source Development and Solution Providers India
Bloomberg API Open Source Development and Solution Providers IndiaBloomberg API Open Source Development and Solution Providers India
Bloomberg API Open Source Development and Solution Providers India
 
Introduction to WSO2 Data Analytics Platform
Introduction to  WSO2 Data Analytics PlatformIntroduction to  WSO2 Data Analytics Platform
Introduction to WSO2 Data Analytics Platform
 
Notification Service 2005
Notification Service 2005Notification Service 2005
Notification Service 2005
 
AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】
AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】
AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】
 
Scaling Experimentation & Data Capture at Grab
Scaling Experimentation & Data Capture at GrabScaling Experimentation & Data Capture at Grab
Scaling Experimentation & Data Capture at Grab
 
Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...
Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...
Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...
 
mDevCamp 2016 - Zingly, or how to design multi-banking app
mDevCamp 2016 - Zingly, or how to design multi-banking appmDevCamp 2016 - Zingly, or how to design multi-banking app
mDevCamp 2016 - Zingly, or how to design multi-banking app
 
Pyrax talk
Pyrax talkPyrax talk
Pyrax talk
 
Windows Azure Mobile Services
Windows Azure Mobile ServicesWindows Azure Mobile Services
Windows Azure Mobile Services
 
Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)
 
Web 2.0 Patterns and Technologies - Lecture 07 - Web Information Systems (401...
Web 2.0 Patterns and Technologies - Lecture 07 - Web Information Systems (401...Web 2.0 Patterns and Technologies - Lecture 07 - Web Information Systems (401...
Web 2.0 Patterns and Technologies - Lecture 07 - Web Information Systems (401...
 

Recently uploaded

How to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in PakistanHow to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in Pakistandanishmna97
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfdanishmna97
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...marcuskenyatta275
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024Lorenzo Miniero
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxFIDO Alliance
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxFIDO Alliance
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data SciencePaolo Missier
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!Memoori
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentationyogeshlabana357357
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...ScyllaDB
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsLeah Henrickson
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...panagenda
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe中 央社
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGDSC PJATK
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...FIDO Alliance
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxFIDO Alliance
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 

Recently uploaded (20)

How to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in PakistanHow to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in Pakistan
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 

UVic Startup Slam September 2014 (Pretio)

  • 1. Pretio Real-time Mapping of API Requests Rob O'Dwyer Nathan Lambert Cameron Rohani
  • 2. About Pretio We power reward-based advertising on mobile apps and FB games
  • 3.
  • 4.
  • 5. Why this Project We wanted to start making visualizations of our data See patterns in geographic location Show traffic changes and shifts in popularity as they happen Investors like pretty graphs!
  • 6. Where's the Data From? Mobile Ad Unit API Traffic from one of our US-only publishers
  • 7. 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"] }
  • 8. Quick Demo Check it out at geo.pretio.in
  • 9.
  • 10. The Map Uses Custom icons Leaflet.js
  • 11. Server-Sent Events HTML5 Stream data in real-time to the browser
  • 12. Why not Websockets?? Bidirectional, more flexibility Special server support needed SSE - lines of text from a long HTTP connection Auto reconnects!
  • 13. Server-Sent Event Protocol event: notification data: hello world event: location data: { data: "latitude": 38.2542, data: "longitude": -85.7594 data: }
  • 14. In the browser // Connect to server var source = new EventSource('server/path/to/events'); source.addEventListener('open', function(e) { console.log('Connected!'); }); // Listen for "location" events source.addEventListener('location', function(e) { // We're sending data as JSON var data = JSON.parse(e.data); displayOnMap(data.latitude, data.longitude); });
  • 15. node.js So hot right now Event-driven JavaScript on the server Good for building "real-time" apps
  • 16. The app Uses Express for rendering web pages Simple UDP server that receives events
  • 17. Listening for UDP packets var 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 messages udpServer.bind(PORT, '0.0.0.0');
  • 18. Event Stream app.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: locationn'); res.write('data: ' + JSON.stringify(data) + 'nn'); }); });
  • 19. Logstash A tool for parsing, rewriting and shipping logs Continuous pipeline of events Connects to almost everything (log files, queues, sockets, DBs, etc.) IP » Geo is built-in
  • 20. Sample Logstash Config input { 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 } }
  • 21. Read your web server logs! input { file { path => "/var/log/apache/access.log" } } filter { grok { pattern => "%{COMBINEDAPACHELOG}" } }
  • 22. IP Geolocation Uses free MaxMind GeoIP database Not very accurate
  • 23. Redis Advanced key-value datastore API Servers publish events to here Logstash picks them up
  • 25.
  • 26.
  • 27.
  • 28. Ideas Show server logs from your app Plotting real-time tweet data
  • 29. ?