SlideShare a Scribd company logo
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 Meet
Robert 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 - BogotaJS
philogb
 
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
philogb
 
maXbox Starter 40 REST API Coding
maXbox Starter 40 REST API CodingmaXbox Starter 40 REST API Coding
maXbox Starter 40 REST API Coding
Max Kleiner
 
Async
AsyncAsync
Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010
Ismael Celis
 
Server-Sent Events in Action
Server-Sent Events in ActionServer-Sent Events in Action
Server-Sent Events in Action
Andrei 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-22
Fré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 2
Wes 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 India
Point 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 Platform
Srinath Perera
 
Notification Service 2005
Notification Service 2005Notification Service 2005
Notification Service 2005
shram2k
 
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 Grab
Roman
 
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 app
Petr Dvorak
 
Pyrax talk
Pyrax talkPyrax talk
Pyrax talk
Kamesh Pemmaraju
 
Windows Azure Mobile Services
Windows Azure Mobile ServicesWindows Azure Mobile Services
Windows Azure Mobile Services
Sasha 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

AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 

Recently uploaded (20)

AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 

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. ?