SlideShare a Scribd company logo
1 of 44
Download to read offline
FUNCTIONAL
DEVOPSEVENT PROCESSING IN CLOJURE
Andy Marks
@andee_marks
amarks@thoughtworks.com
Background
we all code!
(prn “Hello World”)
(ns hello.core)
(defn -main []
(prn “Hello World”))
Jetty
(ns hello.core)
(defn -main []
(prn “Hello World”))
✓access requests
✓queues
✓sessions
AWS EC2
Jetty
(ns hello.core)
(defn -main []
(prn “Hello World”))
✓disk
✓network interfaces
✓memory
✓cores/cpus
AWS EC2
Jetty
AWS EC2
Jetty
AWS EC2
Jetty
DNS
(Master)
DNS
(Slave)
✓records
✓replication
✓resolution
WS EC2
Jetty
AWS EC2
Jetty
AWS EC2
Jetty
DNS
(Master)
DNS
DB
✓performance
✓indexing
✓locking
✓connections
WS EC2
Jetty
AWS EC2
Jetty
AWS EC2
Jetty
DNS
(Master)
DNS
DB
Load Balancer
AWS EC2
Jetty
AWS EC2
Jetty
✓connections
✓DoS
✓Clients
WS EC2
Jetty
AWS EC2
Jetty
AWS EC2
Jetty
DNS
(Master)
DNS
DB
Load Balancer
AWS EC2
Jetty
AWS EC2
Jetty
MessageQueue
✓queues
✓timeouts
that is a lot of
information…
from a lot of
different places
this is a problem
this is the problem
Riemann helps
solve
Riemann is
written in
Clojure
52 source files
7256 lines
377 functions
30 macros
Riemann is written
and configured
in Clojure
And so… to Riemann
kylekingsbury(@aphyr)
OVERVIEW
Correlate events from disparate
sources
What is the latency of the web servers when the DB
servers are generating timeouts?
Filter events based on key criteria Ignore all network events with a normal status
Aggregate events to perform
statistical analysis (e.g., percentiles)
What is the average response rate for 95% of requests?
Monitor status of sources by
availability of events
Which services haven’t sent any events for the last 5
minutes?
Route event streams to multiple
consumers
Send all error events from DB servers to the DBA team
as well as the main operational dashboards
SAMPLE RIEMANN USE CASES
i = f(e)
e: thundering herd of events
i: information ready for downstream processing
Hypothesis
Event processing is function
application at large scale… using
Clojure to build/configure Riemann is a
logical choice.
(defrecord Event
[
service
state
description
metric
tags
time
ttl
KEY CONCEPTS: EVENTS
“reg1.foo.bar”
“reg-service http”
“ok”
“apache-log”
201
[“reg1” “http”]
104534892
60
riemannsource
KEY CONCEPTS: STREAMS
(logging/init {:file "riemann.log" :console true})
(instrumentation {:interval 5}) ;; self monitor every 5 seconds
(periodically-expire 1) ;; check for expired events every second
(tcp-server)
(repl-server)
(streams
;; insert magic here!!!
prn)
riemannconfig
KEY CONCEPTS: INDEX
flow of events
index
riemann
process
General FP goodness
HOMOICONICITY
“[It] is where a program's source code is written
as a basic data structure that the
programming language knows how to access.”
Wikipedia
(defn validate-config
[file]
(try
(read-strings (slurp file))
(catch clojure.lang.LispReader$ReaderException e
(throw (logging/nice-syntax-error e file)))))
riemannsource
HIGHER ORDER FUNCTIONS
“A stream is just a function that takes a variable
number of child streams and returns a function
that takes an event and responds to the event it is passed
when it is invoked.”
http://riemann.io/quickstart.html
“a higher-order function… does at least one of the
following:
[1] takes one or more functions as an input,
[2] outputs a function”
Wikipedia
HIGHER ORDER FUNCTIONS
“A stream is just a function that takes a variable
number of child streams and returns a function
that takes an event and responds to the event it is passed
when it is invoked.”
http://riemann.io/quickstart.html
(streams
(rate 5 prn)
)
riemannconfig
IMMUTABILITY
“Streams ‘change’ events by sending altered,
shared-structure *copies* of events
downstream.”
http://riemann.io/howto.html#split-streams
(streams
(where (host "db04")
(with :service "foo" prn)
(with :service "bar" prn))
)
riemannconfig
Specific Clojure
goodness
“clojure's remarkably fast for
what it is, sexprs make the
tree structure of the streams
visually apparent, it makes
writing the concurrent algos
much simpler, and macros
allow us to express things
like 'by and 'pipe in ways
that would be awkward in
other languages without
building our own AST &
interpreter or transpiler,
etc.”
“clojure's remarkably fast for
what it is, sexprs make the
tree structure of the streams
visually apparent, it makes
writing the concurrent algos
much simpler, and macros
allow us to express things
like 'by and 'pipe in ways
that would be awkward in
other languages without
building our own AST &
interpreter or transpiler,
etc.”
@APHYR SAID…
S-EXPRESSIONS
“a notation for nested list (tree-structured)
data… popularised by the programming
language Lisp”
Wikipedia
S-EXPRESSIONS
(streams
(where (and (service #"^riak")
(state “critical”))
(email “delacroix@vonbraun.com"))
)
1 Filter certain events…
2 Let people know…
1
2
riemannconfig
“make the tree structure of the
streams visually apparent”
3
1
2
S-EXPRESSIONS
1 Split on event fields…
2 Detect state changes…
3 Collate and email
(streams
(by [:host :service]
(changed :state
(rollup 5 3600
(email “delacroix@vonbraun.com"))))
)
riemannconfig
“make the tree structure of the
streams visually apparent”
MACROS
(defmacro pipe
[marker & stages]
`(let [~@(->> stages
reverse
(interpose marker)
(cons marker))]
~marker))
(streams
(pipe -
(splitp = service
"http req rate" -
"0mq req rate" (scale 2 -))
(rate 5
(graphite {:host “127.0.0.1” :port 2003})))
)
riemannconfig
riemannsource
MACROS: PIPE
(streams
(let [aggregate
(rate 5
(graphite {:host “127.0.0.1” :port 2003}))]
(splitp = service
"http req rate" aggregate
"0mq req rate" (scale 2 aggregate)))
)
or
riemannconfigriemannconfig
(streams
(pipe -
(splitp = service
"http req rate" -
"0mq req rate" (scale 2 -))
(rate 5
(graphite {:host “127.0.0.1” :port 2003})))
)
Conclusion
Hypothesis
Event processing is function
application at large scale: using Clojure
to build/configure Riemann is a logical
choice.
homoiconicity
higherorderfunctions
s-expressions
macros
immutability
CLOJURE AD ABSURDUM
(defn do-you-trust-me? [event]
(prn (load-string (:description event))))
(streams
(where (service "event-gen")
do-you-trust-me?)
)
(ns event-gen.core
(:require [riemann.client :refer :all])
(:gen-class :main true))
(defn -main [& args]
(let [c (tcp-client {:host "127.0.0.1"})]
(send-event c
{:service "event-gen" :description "(+ 1 1)"})
(close-client c)))
riemannclientriemannconfig
CLOJURE AD ABSURDUM
(defrecord Event
[service
description
])
“event-gen”
“(+ 1 1)”
Riemann
(Clojure)
riemann.config
(Clojure)
Client
(Clojure)
Clojure
=> “2”
THANKS
Andy Marks
@andee_marks
amarks@thoughtworks.com

More Related Content

What's hot

Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Tom Croucher
 

What's hot (20)

Terraform 0.9 + good practices
Terraform 0.9 + good practicesTerraform 0.9 + good practices
Terraform 0.9 + good practices
 
Mito, a successor of Integral
Mito, a successor of IntegralMito, a successor of Integral
Mito, a successor of Integral
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012
 
PowerShell Technical Overview
PowerShell Technical OverviewPowerShell Technical Overview
PowerShell Technical Overview
 
CQL: SQL In Cassandra
CQL: SQL In CassandraCQL: SQL In Cassandra
CQL: SQL In Cassandra
 
What's new in Ansible 2.0
What's new in Ansible 2.0What's new in Ansible 2.0
What's new in Ansible 2.0
 
Hopping in clouds: a tale of migration from one cloud provider to another
Hopping in clouds: a tale of migration from one cloud provider to anotherHopping in clouds: a tale of migration from one cloud provider to another
Hopping in clouds: a tale of migration from one cloud provider to another
 
Docker tips & tricks
Docker  tips & tricksDocker  tips & tricks
Docker tips & tricks
 
Tuning Solr for Logs
Tuning Solr for LogsTuning Solr for Logs
Tuning Solr for Logs
 
Dexador Rises
Dexador RisesDexador Rises
Dexador Rises
 
Fluentd - CNCF Paris
Fluentd - CNCF ParisFluentd - CNCF Paris
Fluentd - CNCF Paris
 
Php assíncrono com_react_php
Php assíncrono com_react_phpPhp assíncrono com_react_php
Php assíncrono com_react_php
 
Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails Devs
 
Using Logstash, elasticsearch & kibana
Using Logstash, elasticsearch & kibanaUsing Logstash, elasticsearch & kibana
Using Logstash, elasticsearch & kibana
 
Git/Github/Bitbucket@TalkIt. Humber college.
Git/Github/Bitbucket@TalkIt. Humber college.Git/Github/Bitbucket@TalkIt. Humber college.
Git/Github/Bitbucket@TalkIt. Humber college.
 
Subversion To Mercurial
Subversion To MercurialSubversion To Mercurial
Subversion To Mercurial
 
From nothing to Prometheus : one year after
From nothing to Prometheus : one year afterFrom nothing to Prometheus : one year after
From nothing to Prometheus : one year after
 
Node.js - A practical introduction (v2)
Node.js  - A practical introduction (v2)Node.js  - A practical introduction (v2)
Node.js - A practical introduction (v2)
 
Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
 
Fluentd v0.12 master guide
Fluentd v0.12 master guideFluentd v0.12 master guide
Fluentd v0.12 master guide
 

Similar to Lambda Jam 2015: Event Processing in Clojure

PuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into OperationsPuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into Operations
grim_radical
 
Tml for Laravel
Tml for LaravelTml for Laravel
Tml for Laravel
Michael Berkovich
 

Similar to Lambda Jam 2015: Event Processing in Clojure (20)

Apache Spark Workshop, Apr. 2016, Euangelos Linardos
Apache Spark Workshop, Apr. 2016, Euangelos LinardosApache Spark Workshop, Apr. 2016, Euangelos Linardos
Apache Spark Workshop, Apr. 2016, Euangelos Linardos
 
From Zero to Stream Processing
From Zero to Stream ProcessingFrom Zero to Stream Processing
From Zero to Stream Processing
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.
 
Declarative & workflow based infrastructure with Terraform
Declarative & workflow based infrastructure with TerraformDeclarative & workflow based infrastructure with Terraform
Declarative & workflow based infrastructure with Terraform
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
Big Data Scala by the Bay: Interactive Spark in your Browser
Big Data Scala by the Bay: Interactive Spark in your BrowserBig Data Scala by the Bay: Interactive Spark in your Browser
Big Data Scala by the Bay: Interactive Spark in your Browser
 
PuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into OperationsPuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into Operations
 
Play framework
Play frameworkPlay framework
Play framework
 
Introduction to Apache Flink - Fast and reliable big data processing
Introduction to Apache Flink - Fast and reliable big data processingIntroduction to Apache Flink - Fast and reliable big data processing
Introduction to Apache Flink - Fast and reliable big data processing
 
Functional (web) development with Clojure
Functional (web) development with ClojureFunctional (web) development with Clojure
Functional (web) development with Clojure
 
Apache Flink internals
Apache Flink internalsApache Flink internals
Apache Flink internals
 
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
 
Microsoft 2014 Dev Plataform - Roslyn -& ASP.NET vNext
Microsoft 2014 Dev Plataform -  Roslyn -& ASP.NET vNextMicrosoft 2014 Dev Plataform -  Roslyn -& ASP.NET vNext
Microsoft 2014 Dev Plataform - Roslyn -& ASP.NET vNext
 
Data Streaming Technology Overview
Data Streaming Technology OverviewData Streaming Technology Overview
Data Streaming Technology Overview
 
Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4
 
Real-Time Web Programming with PrismTech Vortex Web
Real-Time Web Programming with PrismTech Vortex WebReal-Time Web Programming with PrismTech Vortex Web
Real-Time Web Programming with PrismTech Vortex Web
 
Building Real-Time Web Applications with Vortex-Web
Building Real-Time Web Applications with Vortex-WebBuilding Real-Time Web Applications with Vortex-Web
Building Real-Time Web Applications with Vortex-Web
 
Event Sourcing - what could possibly go wrong?
Event Sourcing - what could possibly go wrong?Event Sourcing - what could possibly go wrong?
Event Sourcing - what could possibly go wrong?
 
About Node.js
About Node.jsAbout Node.js
About Node.js
 
Tml for Laravel
Tml for LaravelTml for Laravel
Tml for Laravel
 

More from Andy Marks

YOW West 2016: "A Rose By Any Other Name: Monoglot Microservices"
YOW West 2016: "A Rose By Any Other Name: Monoglot Microservices"YOW West 2016: "A Rose By Any Other Name: Monoglot Microservices"
YOW West 2016: "A Rose By Any Other Name: Monoglot Microservices"
Andy Marks
 
Quality versus-speed-tradeoffs
Quality versus-speed-tradeoffsQuality versus-speed-tradeoffs
Quality versus-speed-tradeoffs
Andy Marks
 

More from Andy Marks (17)

YOW! Perth 2022 - Reviving the Art of Software Design
YOW! Perth 2022 - Reviving the Art of Software DesignYOW! Perth 2022 - Reviving the Art of Software Design
YOW! Perth 2022 - Reviving the Art of Software Design
 
Top 5 Software Purchasing Fails for an Agile Environment
Top 5 Software Purchasing Fails for an Agile EnvironmentTop 5 Software Purchasing Fails for an Agile Environment
Top 5 Software Purchasing Fails for an Agile Environment
 
"Kata" your way to better architecture skills
"Kata" your way to better architecture skills"Kata" your way to better architecture skills
"Kata" your way to better architecture skills
 
"Kata" your way to better architecture skills
"Kata" your way to better architecture skills"Kata" your way to better architecture skills
"Kata" your way to better architecture skills
 
IT Sociopath Bingo
IT Sociopath BingoIT Sociopath Bingo
IT Sociopath Bingo
 
Developer Experience (DX) as a Fitness Function for Platform Teams
Developer Experience (DX) as a Fitness Function for Platform TeamsDeveloper Experience (DX) as a Fitness Function for Platform Teams
Developer Experience (DX) as a Fitness Function for Platform Teams
 
Melbourne Clojure Meetup Jan 2018 - ClojureBridge
Melbourne Clojure Meetup Jan 2018  - ClojureBridgeMelbourne Clojure Meetup Jan 2018  - ClojureBridge
Melbourne Clojure Meetup Jan 2018 - ClojureBridge
 
YOW WEST 2014: "Adopting Functional Programming Languages"
YOW WEST 2014: "Adopting Functional Programming Languages"YOW WEST 2014: "Adopting Functional Programming Languages"
YOW WEST 2014: "Adopting Functional Programming Languages"
 
YOW West 2015: "Macromonitoring for Microservices"
YOW West 2015: "Macromonitoring for Microservices"YOW West 2015: "Macromonitoring for Microservices"
YOW West 2015: "Macromonitoring for Microservices"
 
ThoughtWorks Live 2014: "Building Systems That Pivot"
ThoughtWorks Live 2014: "Building Systems That Pivot"ThoughtWorks Live 2014: "Building Systems That Pivot"
ThoughtWorks Live 2014: "Building Systems That Pivot"
 
YOW West 2016: "A Rose By Any Other Name: Monoglot Microservices"
YOW West 2016: "A Rose By Any Other Name: Monoglot Microservices"YOW West 2016: "A Rose By Any Other Name: Monoglot Microservices"
YOW West 2016: "A Rose By Any Other Name: Monoglot Microservices"
 
2017 Melb.JVM: "The Hills are alive with the Sound of your Crappy Code! "
2017 Melb.JVM: "The Hills are alive with the Sound of your Crappy Code! "2017 Melb.JVM: "The Hills are alive with the Sound of your Crappy Code! "
2017 Melb.JVM: "The Hills are alive with the Sound of your Crappy Code! "
 
2017 YOW West: "Does Smelly Code Also Sound Bad?"
2017 YOW West: "Does Smelly Code Also Sound Bad?"2017 YOW West: "Does Smelly Code Also Sound Bad?"
2017 YOW West: "Does Smelly Code Also Sound Bad?"
 
1st conference 2015 devops
1st conference 2015   devops1st conference 2015   devops
1st conference 2015 devops
 
Quality versus-speed-tradeoffs
Quality versus-speed-tradeoffsQuality versus-speed-tradeoffs
Quality versus-speed-tradeoffs
 
Agile Methods for NTU Software Engineers
Agile Methods for NTU Software EngineersAgile Methods for NTU Software Engineers
Agile Methods for NTU Software Engineers
 
Aws map-reduce-aws
Aws map-reduce-awsAws map-reduce-aws
Aws map-reduce-aws
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Lambda Jam 2015: Event Processing in Clojure

  • 1.
  • 2. FUNCTIONAL DEVOPSEVENT PROCESSING IN CLOJURE Andy Marks @andee_marks amarks@thoughtworks.com
  • 6. (ns hello.core) (defn -main [] (prn “Hello World”))
  • 7. Jetty (ns hello.core) (defn -main [] (prn “Hello World”)) ✓access requests ✓queues ✓sessions
  • 8. AWS EC2 Jetty (ns hello.core) (defn -main [] (prn “Hello World”)) ✓disk ✓network interfaces ✓memory ✓cores/cpus
  • 9. AWS EC2 Jetty AWS EC2 Jetty AWS EC2 Jetty DNS (Master) DNS (Slave) ✓records ✓replication ✓resolution
  • 10. WS EC2 Jetty AWS EC2 Jetty AWS EC2 Jetty DNS (Master) DNS DB ✓performance ✓indexing ✓locking ✓connections
  • 11. WS EC2 Jetty AWS EC2 Jetty AWS EC2 Jetty DNS (Master) DNS DB Load Balancer AWS EC2 Jetty AWS EC2 Jetty ✓connections ✓DoS ✓Clients
  • 12. WS EC2 Jetty AWS EC2 Jetty AWS EC2 Jetty DNS (Master) DNS DB Load Balancer AWS EC2 Jetty AWS EC2 Jetty MessageQueue ✓queues ✓timeouts
  • 13. that is a lot of information…
  • 14. from a lot of different places
  • 15. this is a problem
  • 16. this is the problem Riemann helps solve
  • 17. Riemann is written in Clojure 52 source files 7256 lines 377 functions 30 macros
  • 18. Riemann is written and configured in Clojure
  • 19. And so… to Riemann
  • 22. Correlate events from disparate sources What is the latency of the web servers when the DB servers are generating timeouts? Filter events based on key criteria Ignore all network events with a normal status Aggregate events to perform statistical analysis (e.g., percentiles) What is the average response rate for 95% of requests? Monitor status of sources by availability of events Which services haven’t sent any events for the last 5 minutes? Route event streams to multiple consumers Send all error events from DB servers to the DBA team as well as the main operational dashboards SAMPLE RIEMANN USE CASES
  • 23. i = f(e) e: thundering herd of events i: information ready for downstream processing
  • 24. Hypothesis Event processing is function application at large scale… using Clojure to build/configure Riemann is a logical choice.
  • 25. (defrecord Event [ service state description metric tags time ttl KEY CONCEPTS: EVENTS “reg1.foo.bar” “reg-service http” “ok” “apache-log” 201 [“reg1” “http”] 104534892 60 riemannsource
  • 26. KEY CONCEPTS: STREAMS (logging/init {:file "riemann.log" :console true}) (instrumentation {:interval 5}) ;; self monitor every 5 seconds (periodically-expire 1) ;; check for expired events every second (tcp-server) (repl-server) (streams ;; insert magic here!!! prn) riemannconfig
  • 27. KEY CONCEPTS: INDEX flow of events index riemann process
  • 29. HOMOICONICITY “[It] is where a program's source code is written as a basic data structure that the programming language knows how to access.” Wikipedia (defn validate-config [file] (try (read-strings (slurp file)) (catch clojure.lang.LispReader$ReaderException e (throw (logging/nice-syntax-error e file))))) riemannsource
  • 30. HIGHER ORDER FUNCTIONS “A stream is just a function that takes a variable number of child streams and returns a function that takes an event and responds to the event it is passed when it is invoked.” http://riemann.io/quickstart.html “a higher-order function… does at least one of the following: [1] takes one or more functions as an input, [2] outputs a function” Wikipedia
  • 31. HIGHER ORDER FUNCTIONS “A stream is just a function that takes a variable number of child streams and returns a function that takes an event and responds to the event it is passed when it is invoked.” http://riemann.io/quickstart.html (streams (rate 5 prn) ) riemannconfig
  • 32. IMMUTABILITY “Streams ‘change’ events by sending altered, shared-structure *copies* of events downstream.” http://riemann.io/howto.html#split-streams (streams (where (host "db04") (with :service "foo" prn) (with :service "bar" prn)) ) riemannconfig
  • 34. “clojure's remarkably fast for what it is, sexprs make the tree structure of the streams visually apparent, it makes writing the concurrent algos much simpler, and macros allow us to express things like 'by and 'pipe in ways that would be awkward in other languages without building our own AST & interpreter or transpiler, etc.” “clojure's remarkably fast for what it is, sexprs make the tree structure of the streams visually apparent, it makes writing the concurrent algos much simpler, and macros allow us to express things like 'by and 'pipe in ways that would be awkward in other languages without building our own AST & interpreter or transpiler, etc.” @APHYR SAID…
  • 35. S-EXPRESSIONS “a notation for nested list (tree-structured) data… popularised by the programming language Lisp” Wikipedia
  • 36. S-EXPRESSIONS (streams (where (and (service #"^riak") (state “critical”)) (email “delacroix@vonbraun.com")) ) 1 Filter certain events… 2 Let people know… 1 2 riemannconfig “make the tree structure of the streams visually apparent”
  • 37. 3 1 2 S-EXPRESSIONS 1 Split on event fields… 2 Detect state changes… 3 Collate and email (streams (by [:host :service] (changed :state (rollup 5 3600 (email “delacroix@vonbraun.com")))) ) riemannconfig “make the tree structure of the streams visually apparent”
  • 38. MACROS (defmacro pipe [marker & stages] `(let [~@(->> stages reverse (interpose marker) (cons marker))] ~marker)) (streams (pipe - (splitp = service "http req rate" - "0mq req rate" (scale 2 -)) (rate 5 (graphite {:host “127.0.0.1” :port 2003}))) ) riemannconfig riemannsource
  • 39. MACROS: PIPE (streams (let [aggregate (rate 5 (graphite {:host “127.0.0.1” :port 2003}))] (splitp = service "http req rate" aggregate "0mq req rate" (scale 2 aggregate))) ) or riemannconfigriemannconfig (streams (pipe - (splitp = service "http req rate" - "0mq req rate" (scale 2 -)) (rate 5 (graphite {:host “127.0.0.1” :port 2003}))) )
  • 41. Hypothesis Event processing is function application at large scale: using Clojure to build/configure Riemann is a logical choice. homoiconicity higherorderfunctions s-expressions macros immutability
  • 42. CLOJURE AD ABSURDUM (defn do-you-trust-me? [event] (prn (load-string (:description event)))) (streams (where (service "event-gen") do-you-trust-me?) ) (ns event-gen.core (:require [riemann.client :refer :all]) (:gen-class :main true)) (defn -main [& args] (let [c (tcp-client {:host "127.0.0.1"})] (send-event c {:service "event-gen" :description "(+ 1 1)"}) (close-client c))) riemannclientriemannconfig
  • 43. CLOJURE AD ABSURDUM (defrecord Event [service description ]) “event-gen” “(+ 1 1)” Riemann (Clojure) riemann.config (Clojure) Client (Clojure) Clojure => “2”