Metrics by coda hale : to know your app’ health

Izzet Mustafaiev
Izzet MustafaievSolution Architect at EPAM Systems
Metrics by Coda Haleto know your app’ health
Izzet Mustafayev@EPAM Systems
@webdizz webdizz izzetmustafaiev
http://webdizz.name
this is me
● SA at EPAM Systems
● primary skill is Java
● JUG member/speaker
● hands-on-coding with Ruby, Groovy and
some Scala
● passionate about agile, clean code
practices and devops movement
agenda
● introduction
● why should i care
● features
● reporting
● recipes
● alternatives
● q&a
Metrics by coda hale : to know your app’ health
Finish or Start?
Familiar?
Possible?!.
Your app?!.
Dreams...
One thing...
● does my app work?
● does my app work?
● will my app keep working?
● does my app work?
● will my app keep working?
● what happened that
made my app stop
working?
Statistics
Metrics
Features
Registry.
..- is the heart of metrics framework
MetricRegistry registry = new MetricRegistry();​
// or
@Bean
public MetricRegistry metricRegistry(){
return new MetricRegistry();
}
Gauge...
- is the simplest metric type that just returns a value
registry.register(
name(Persistence.class, "entities-cached"),
new Gauge<Integer>() {
public Integer getValue() {
return cache.getItems();
}
}
);​
Counter...
- is a simple incrementing and decrementing integer value
Counter onSiteUsers = registry.counter(
name(User.class, "users-logged-in"));
// on login increase
onSiteUsers.inc();​
// on logout/session expiration decrease
onSiteUsers.dec();​
Histogram.
..- measures the distribution of values in a stream of data
Histogram requestTimes = registry.histogram(
name(Request.class, "request-processed")
);
requestTimes.update(request.getTime());
​
Meter...
- measures the rate at which a set of events occur
Meter timedOutRequests = registry.meter(
name(Request.class, "request-timed-out")
);
// in finally block on time-out
timedOutRequests.mark();
Timer...
- is basically a histogram of the duration of a type of event
and a meter of the rate of its occurrence
​Timer requests = registry.timer(
name(Request.class, "request-processed")
);
Timer.Context time = requests.time();
// in finally block of request processing
time.stop();​
Health Check..
- is a unified way of performing application health checks
public class BackendHealthCheck extends HealthCheck {
private Backend backend;
protected Result check() {
if (backend.ping()) {
return Result.healthy();
}
return Result.unhealthy("Can't ping backend");
}
}
Reporting
JMX
// somewhere in your application​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
JmxReporter reporter =
JmxReporter.forRegistry(registry).build();
reporter.start();​
HTTP
● AdminServlet
○ MetricsServlet
○ ThreadDumpServlet
○ PingServlet
○ HealthCheckServlet
Console
ConsoleReporter reporter = ConsoleReporter.forRegistry
(registry)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build();
reporter.start(1, TimeUnit.MINUTES);​
Slf4jReporter reporter = Slf4jReporter.forRegistry(registry)
.outputTo(LoggerFactory.getLogger("com.app.metrics"))
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build();
reporter.start(1, TimeUnit.MINUTES);​
Ganglia & Graphite
Metrics by coda hale : to know your app’ health
Naming by Matt Aimonetti
<namespace>.<instrumented section>.<target (noun)>.
<action (past tense verb)>
Example
● customers.registration.validation.failed
Nesting
● customers.registration.validation.failure.
similar_email_found
● customers.registration.validation.failure.
email_verification_failed
AOP
There is an easy way to introduce metrics using AOP.
<aop:config proxy-target-class="false">
<aop:aspect id="controllerProfilerAspect"
ref="executionMonitor">
<aop:pointcut id="controllerMethods"
expression="execution(*
com.app.controller.*Controller.*(..))" />
<aop:around pointcut-ref="controllerMethods"
method="logExecutionTime" />
</aop:aspect>
</aop:config>
​
public Object logExecutionTime(ProceedingJoinPoint joinPoint)
throws Throwable {
String namePfx = metricNamePrefix(joinPoint);
Timer.Context time = registry.timer(
name(namePfx, "timed")).time();
try {
// execute joint point ...
} catch(Throwable throwable) {
registry.counter(
name(namePfx, "exception-counted")).inc();
throw throwable;
} finally {
time.stop()
}
}
​
metrics-spring
@Configuration
@EnableMetrics
public class ApplicationConfiguration {
@Bean
public MetricRegistry metricRegistry(){
return new MetricRegistry();
}
// your other beans here ...
}
// annotations
@Timed, @Metered, @ExceptionMetered, @Counted​, @Gauge,
@CachedGauge and @Metric
instrumentation
● JVM
● Jetty
● Jersey
● InstrumentedFilter​
● InstrumentedEhcache​
● InstrumentedAppender (Log4j and Logback)
● InstrumentedHttpClient
Alternatives
https://github.com/twitter/zipkin
Zipkin is a distributed tracing system that helps
Twitter gather timing data for all the disparate
services.
Zipkin provides three services:
● to collect data: bin/collector
● to extract data: bin/query
● to display data: bin/web
http://www.moskito.org/
MoSKito is a
● Multi-purpose: collects any possible type of
performance data, including business-related
● Non-invasive: does not require any code
change
● Interval-based: works simultaneously with
short & long time intervals, allowing instant
comparison
● Data privacy: keeps collected data locally,
with no 3rd party resources involved.
● Analysis tools: displays accumulated
performance data in charts. Live profiling:
records user actions as system calls.
https://code.google.com/p/javasimon/
Java Simon is a
simple monitoring API that allows you to
follow and better understand your application.
Monitors (familiarly called Simons) are
placed directly into your code and you can
choose whether you want to count something or
measure time/duration.
https://github.com/Netflix/servo
Servo goal is to provide a simple interface for
exposing and publishing application metrics in
Java.
● JMX: JMX is the standard monitoring
interface for Java
● Simple: It is trivial to expose and publish
metrics
● Flexible publishing: Once metrics are
exposed, it is easy to regularly poll the
metrics and make them available for
reporting systems, logs, and services like
Amazon’s CloudWatch.
Summary
getting started
● http://metrics.codahale.com/
● http://matt.aimonetti.
net/posts/2013/06/26/practical-guide-to-
graphite-monitoring/
● http://www.ryantenney.com/metrics-spring/
q&a
ThanksIzzet Mustafayev@EPAM Systems
@webdizz webdizz izzetmustafaiev
http://webdizz.name
1 of 43

Recommended

Metrics by
MetricsMetrics
MetricsZach Cox
1.5K views12 slides
Continuous performance management with Gatling by
Continuous performance management with GatlingContinuous performance management with Gatling
Continuous performance management with GatlingRadoslaw Smilgin
977 views17 slides
Wicket Live on Stage by
Wicket Live on StageWicket Live on Stage
Wicket Live on StageMartijn Dashorst
954 views25 slides
Extending Spark With Java Agent (handout) by
Extending Spark With Java Agent (handout)Extending Spark With Java Agent (handout)
Extending Spark With Java Agent (handout)Jaroslav Bachorik
1.4K views33 slides
React state management with Redux and MobX by
React state management with Redux and MobXReact state management with Redux and MobX
React state management with Redux and MobXDarko Kukovec
2K views93 slides
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5 by
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5Marcin Mieszek
1.1K views22 slides

More Related Content

What's hot

ServiceWorker: Exploring the Core of the Progressive Web App-Bagus Aji Santos... by
ServiceWorker: Exploring the Core of the Progressive Web App-Bagus Aji Santos...ServiceWorker: Exploring the Core of the Progressive Web App-Bagus Aji Santos...
ServiceWorker: Exploring the Core of the Progressive Web App-Bagus Aji Santos...DicodingEvent
8.7K views30 slides
Using redux by
Using reduxUsing redux
Using reduxJonas Ohlsson Aden
3.4K views22 slides
Introducing spring by
Introducing springIntroducing spring
Introducing springErnesto Hernández Rodríguez
473 views60 slides
Serverless Angular, Material, Firebase and Google Cloud applications by
Serverless Angular, Material, Firebase and Google Cloud applicationsServerless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applicationsLoiane Groner
2K views77 slides
The Road To Reactive with RxJava JEEConf 2016 by
The Road To Reactive with RxJava JEEConf 2016The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016Frank Lyaruu
749 views80 slides
Redux Universal by
Redux UniversalRedux Universal
Redux UniversalNikolaus Graf
1.9K views25 slides

What's hot(20)

ServiceWorker: Exploring the Core of the Progressive Web App-Bagus Aji Santos... by DicodingEvent
ServiceWorker: Exploring the Core of the Progressive Web App-Bagus Aji Santos...ServiceWorker: Exploring the Core of the Progressive Web App-Bagus Aji Santos...
ServiceWorker: Exploring the Core of the Progressive Web App-Bagus Aji Santos...
DicodingEvent8.7K views
Serverless Angular, Material, Firebase and Google Cloud applications by Loiane Groner
Serverless Angular, Material, Firebase and Google Cloud applicationsServerless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applications
Loiane Groner2K views
The Road To Reactive with RxJava JEEConf 2016 by Frank Lyaruu
The Road To Reactive with RxJava JEEConf 2016The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016
Frank Lyaruu749 views
Do we need a bigger dev data culture by Simon Dittlmann
Do we need a bigger dev data cultureDo we need a bigger dev data culture
Do we need a bigger dev data culture
Simon Dittlmann516 views
React.js and Redux overview by Alex Bachuk
React.js and Redux overviewReact.js and Redux overview
React.js and Redux overview
Alex Bachuk566 views
Full-Stack Reativo com Spring WebFlux + Angular - Devs Java Girl by Loiane Groner
Full-Stack Reativo com Spring WebFlux + Angular - Devs Java GirlFull-Stack Reativo com Spring WebFlux + Angular - Devs Java Girl
Full-Stack Reativo com Spring WebFlux + Angular - Devs Java Girl
Loiane Groner222 views
Angular & RXJS: examples and use cases by Fabio Biondi
Angular & RXJS: examples and use casesAngular & RXJS: examples and use cases
Angular & RXJS: examples and use cases
Fabio Biondi1.8K views
Designing applications with Redux by Fernando Daciuk
Designing applications with ReduxDesigning applications with Redux
Designing applications with Redux
Fernando Daciuk1.2K views
Gerenciamento de estado no Angular com NgRx by Loiane Groner
Gerenciamento de estado no Angular com NgRxGerenciamento de estado no Angular com NgRx
Gerenciamento de estado no Angular com NgRx
Loiane Groner1K views
Intro to RxJava/RxAndroid - GDG Munich Android by Egor Andreevich
Intro to RxJava/RxAndroid - GDG Munich AndroidIntro to RxJava/RxAndroid - GDG Munich Android
Intro to RxJava/RxAndroid - GDG Munich Android
Egor Andreevich1.8K views
Reactive Programming on Android - RxAndroid - RxJava by Ali Muzaffar
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJava
Ali Muzaffar15.1K views
Angular for Java Enterprise Developers: Oracle Code One 2018 by Loiane Groner
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018
Loiane Groner726 views
ProvJS: Six Months of ReactJS and Redux by Thom Nichols
ProvJS:  Six Months of ReactJS and ReduxProvJS:  Six Months of ReactJS and Redux
ProvJS: Six Months of ReactJS and Redux
Thom Nichols836 views
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018 by Loiane Groner
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018
Loiane Groner1.1K views
Full-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConf by Loiane Groner
Full-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConfFull-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConf
Full-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConf
Loiane Groner863 views

Similar to Metrics by coda hale : to know your app’ health

Introduction to ASP.NET MVC by
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCMaarten Balliauw
2.8K views37 slides
...and thus your forms automagically disappeared by
...and thus your forms automagically disappeared...and thus your forms automagically disappeared
...and thus your forms automagically disappearedLuc Bors
954 views45 slides
QTP Tutorial Slides Presentation. by
QTP Tutorial Slides Presentation.QTP Tutorial Slides Presentation.
QTP Tutorial Slides Presentation.Jaya Priya
962 views28 slides
Dhanasekaran 2008-2009 Quick Test Pro Presentation by
Dhanasekaran 2008-2009 Quick Test Pro PresentationDhanasekaran 2008-2009 Quick Test Pro Presentation
Dhanasekaran 2008-2009 Quick Test Pro PresentationDhanasekaran Nagarajan
952 views28 slides
First QTP Tutorial by
First QTP TutorialFirst QTP Tutorial
First QTP Tutorialtjdhans
10.4K views28 slides
TDC 2015 - POA - Trilha PHP - Shit Happens by
TDC 2015 - POA - Trilha PHP - Shit HappensTDC 2015 - POA - Trilha PHP - Shit Happens
TDC 2015 - POA - Trilha PHP - Shit HappensJackson F. de A. Mafra
602 views83 slides

Similar to Metrics by coda hale : to know your app’ health(20)

...and thus your forms automagically disappeared by Luc Bors
...and thus your forms automagically disappeared...and thus your forms automagically disappeared
...and thus your forms automagically disappeared
Luc Bors954 views
QTP Tutorial Slides Presentation. by Jaya Priya
QTP Tutorial Slides Presentation.QTP Tutorial Slides Presentation.
QTP Tutorial Slides Presentation.
Jaya Priya962 views
First QTP Tutorial by tjdhans
First QTP TutorialFirst QTP Tutorial
First QTP Tutorial
tjdhans10.4K views
Debugging Planning Issues Using Calcite's Built-in Loggers by Stamatis Zampetakis
Debugging Planning Issues Using Calcite's Built-in LoggersDebugging Planning Issues Using Calcite's Built-in Loggers
Debugging Planning Issues Using Calcite's Built-in Loggers
Automated Performance Testing by Lars Thorup
Automated Performance TestingAutomated Performance Testing
Automated Performance Testing
Lars Thorup1.2K views
Sql storeprocedure by ftz 420
Sql storeprocedureSql storeprocedure
Sql storeprocedure
ftz 4201.5K views
Workflow demo by Kamal Raj
Workflow demoWorkflow demo
Workflow demo
Kamal Raj615 views
Good practices for debugging Selenium and Appium tests by Abhijeet Vaikar
Good practices for debugging Selenium and Appium testsGood practices for debugging Selenium and Appium tests
Good practices for debugging Selenium and Appium tests
Abhijeet Vaikar233 views
jBPM5 in action - a quickstart for developers by Kris Verlaenen
jBPM5 in action - a quickstart for developersjBPM5 in action - a quickstart for developers
jBPM5 in action - a quickstart for developers
Kris Verlaenen5.8K views
Spring AOP @ DevClub.eu by arsenikum
Spring AOP @ DevClub.euSpring AOP @ DevClub.eu
Spring AOP @ DevClub.eu
arsenikum622 views
Automated Performance Testing With J Meter And Maven by PerconaPerformance
Automated  Performance  Testing With  J Meter And  MavenAutomated  Performance  Testing With  J Meter And  Maven
Automated Performance Testing With J Meter And Maven
PerconaPerformance5.2K views
Testing with VS2010 - A Bugs Life by Peter Gfader
Testing with VS2010 - A Bugs LifeTesting with VS2010 - A Bugs Life
Testing with VS2010 - A Bugs Life
Peter Gfader2.7K views
SoftTest Ireland: Model Based Testing - January 27th 2011 by David O'Dowd
SoftTest Ireland: Model Based Testing - January 27th 2011SoftTest Ireland: Model Based Testing - January 27th 2011
SoftTest Ireland: Model Based Testing - January 27th 2011
David O'Dowd1.3K views
What's Coming in Spring 3.0 by Matt Raible
What's Coming in Spring 3.0What's Coming in Spring 3.0
What's Coming in Spring 3.0
Matt Raible6.1K views

More from Izzet Mustafaiev

Overcome a Frontier by
Overcome a FrontierOvercome a Frontier
Overcome a FrontierIzzet Mustafaiev
166 views23 slides
Web Security... Level Up by
Web Security... Level UpWeb Security... Level Up
Web Security... Level UpIzzet Mustafaiev
431 views39 slides
Kotlin strives for Deep Learning by
Kotlin strives for Deep LearningKotlin strives for Deep Learning
Kotlin strives for Deep LearningIzzet Mustafaiev
651 views28 slides
Can I do AI? by
Can I do AI?Can I do AI?
Can I do AI?Izzet Mustafaiev
853 views46 slides
Consumer-Driven Contracts to enable API evolution by
Consumer-Driven Contracts to enable API evolutionConsumer-Driven Contracts to enable API evolution
Consumer-Driven Contracts to enable API evolutionIzzet Mustafaiev
518 views28 slides
Functional web with elixir and elm in phoenix by
Functional web with elixir and elm in phoenixFunctional web with elixir and elm in phoenix
Functional web with elixir and elm in phoenixIzzet Mustafaiev
559 views16 slides

More from Izzet Mustafaiev(20)

Consumer-Driven Contracts to enable API evolution by Izzet Mustafaiev
Consumer-Driven Contracts to enable API evolutionConsumer-Driven Contracts to enable API evolution
Consumer-Driven Contracts to enable API evolution
Izzet Mustafaiev518 views
Functional web with elixir and elm in phoenix by Izzet Mustafaiev
Functional web with elixir and elm in phoenixFunctional web with elixir and elm in phoenix
Functional web with elixir and elm in phoenix
Izzet Mustafaiev559 views
Don’t let your code to be illiterate along with your colleagues by Izzet Mustafaiev
Don’t let your code to be illiterate along with your colleaguesDon’t let your code to be illiterate along with your colleagues
Don’t let your code to be illiterate along with your colleagues
Izzet Mustafaiev707 views
[Szjug] Docker. Does it matter for java developer? by Izzet Mustafaiev
[Szjug] Docker. Does it matter for java developer?[Szjug] Docker. Does it matter for java developer?
[Szjug] Docker. Does it matter for java developer?
Izzet Mustafaiev468 views
µServices Architecture @ EPAM WOW 2015 by Izzet Mustafaiev
µServices Architecture @ EPAM WOW 2015µServices Architecture @ EPAM WOW 2015
µServices Architecture @ EPAM WOW 2015
Izzet Mustafaiev1.3K views
Gradle - the Enterprise Automation Tool by Izzet Mustafaiev
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
Izzet Mustafaiev3.9K views
Docker. Does it matter for Java developer ? by Izzet Mustafaiev
Docker. Does it matter for Java developer ?Docker. Does it matter for Java developer ?
Docker. Does it matter for Java developer ?
Izzet Mustafaiev11.4K views
“Bootify your app - from zero to hero by Izzet Mustafaiev
“Bootify  your app - from zero to hero“Bootify  your app - from zero to hero
“Bootify your app - from zero to hero
Izzet Mustafaiev2.2K views

Recently uploaded

The Era of Large Language Models.pptx by
The Era of Large Language Models.pptxThe Era of Large Language Models.pptx
The Era of Large Language Models.pptxAbdulVahedShaik
6 views9 slides
SAP FOR CONTRACT MANUFACTURING.pdf by
SAP FOR CONTRACT MANUFACTURING.pdfSAP FOR CONTRACT MANUFACTURING.pdf
SAP FOR CONTRACT MANUFACTURING.pdfVirendra Rai, PMP
13 views2 slides
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft... by
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...Deltares
7 views18 slides
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... by
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...sparkfabrik
7 views46 slides
Short_Story_PPT.pdf by
Short_Story_PPT.pdfShort_Story_PPT.pdf
Short_Story_PPT.pdfutkarshsatishkumarsh
5 views16 slides
360 graden fabriek by
360 graden fabriek360 graden fabriek
360 graden fabriekinfo33492
122 views25 slides

Recently uploaded(20)

DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft... by Deltares
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...
Deltares7 views
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... by sparkfabrik
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
sparkfabrik7 views
360 graden fabriek by info33492
360 graden fabriek360 graden fabriek
360 graden fabriek
info33492122 views
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J... by Deltares
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
Deltares12 views
Copilot Prompting Toolkit_All Resources.pdf by Riccardo Zamana
Copilot Prompting Toolkit_All Resources.pdfCopilot Prompting Toolkit_All Resources.pdf
Copilot Prompting Toolkit_All Resources.pdf
Riccardo Zamana10 views
tecnologia18.docx by nosi6702
tecnologia18.docxtecnologia18.docx
tecnologia18.docx
nosi67025 views
Quality Engineer: A Day in the Life by John Valentino
Quality Engineer: A Day in the LifeQuality Engineer: A Day in the Life
Quality Engineer: A Day in the Life
John Valentino6 views
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... by Deltares
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
Deltares14 views
Headless JS UG Presentation.pptx by Jack Spektor
Headless JS UG Presentation.pptxHeadless JS UG Presentation.pptx
Headless JS UG Presentation.pptx
Jack Spektor8 views
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs by Deltares
DSD-INT 2023 The Danube Hazardous Substances Model - KovacsDSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
Deltares10 views
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P... by NimaTorabi2
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
NimaTorabi212 views
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action by Márton Kodok
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action
Márton Kodok6 views
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols by Deltares
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - DolsDSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols
Deltares9 views
FIMA 2023 Neo4j & FS - Entity Resolution.pptx by Neo4j
FIMA 2023 Neo4j & FS - Entity Resolution.pptxFIMA 2023 Neo4j & FS - Entity Resolution.pptx
FIMA 2023 Neo4j & FS - Entity Resolution.pptx
Neo4j8 views
Ports-and-Adapters Architecture for Embedded HMI by Burkhard Stubert
Ports-and-Adapters Architecture for Embedded HMIPorts-and-Adapters Architecture for Embedded HMI
Ports-and-Adapters Architecture for Embedded HMI
Burkhard Stubert21 views

Metrics by coda hale : to know your app’ health

  • 1. Metrics by Coda Haleto know your app’ health Izzet Mustafayev@EPAM Systems @webdizz webdizz izzetmustafaiev http://webdizz.name
  • 2. this is me ● SA at EPAM Systems ● primary skill is Java ● JUG member/speaker ● hands-on-coding with Ruby, Groovy and some Scala ● passionate about agile, clean code practices and devops movement
  • 3. agenda ● introduction ● why should i care ● features ● reporting ● recipes ● alternatives ● q&a
  • 11. ● does my app work?
  • 12. ● does my app work? ● will my app keep working?
  • 13. ● does my app work? ● will my app keep working? ● what happened that made my app stop working?
  • 17. Registry. ..- is the heart of metrics framework MetricRegistry registry = new MetricRegistry();​ // or @Bean public MetricRegistry metricRegistry(){ return new MetricRegistry(); }
  • 18. Gauge... - is the simplest metric type that just returns a value registry.register( name(Persistence.class, "entities-cached"), new Gauge<Integer>() { public Integer getValue() { return cache.getItems(); } } );​
  • 19. Counter... - is a simple incrementing and decrementing integer value Counter onSiteUsers = registry.counter( name(User.class, "users-logged-in")); // on login increase onSiteUsers.inc();​ // on logout/session expiration decrease onSiteUsers.dec();​
  • 20. Histogram. ..- measures the distribution of values in a stream of data Histogram requestTimes = registry.histogram( name(Request.class, "request-processed") ); requestTimes.update(request.getTime()); ​
  • 21. Meter... - measures the rate at which a set of events occur Meter timedOutRequests = registry.meter( name(Request.class, "request-timed-out") ); // in finally block on time-out timedOutRequests.mark();
  • 22. Timer... - is basically a histogram of the duration of a type of event and a meter of the rate of its occurrence ​Timer requests = registry.timer( name(Request.class, "request-processed") ); Timer.Context time = requests.time(); // in finally block of request processing time.stop();​
  • 23. Health Check.. - is a unified way of performing application health checks public class BackendHealthCheck extends HealthCheck { private Backend backend; protected Result check() { if (backend.ping()) { return Result.healthy(); } return Result.unhealthy("Can't ping backend"); } }
  • 25. JMX // somewhere in your application​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ JmxReporter reporter = JmxReporter.forRegistry(registry).build(); reporter.start();​
  • 26. HTTP ● AdminServlet ○ MetricsServlet ○ ThreadDumpServlet ○ PingServlet ○ HealthCheckServlet
  • 27. Console ConsoleReporter reporter = ConsoleReporter.forRegistry (registry) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); reporter.start(1, TimeUnit.MINUTES);​ Slf4jReporter reporter = Slf4jReporter.forRegistry(registry) .outputTo(LoggerFactory.getLogger("com.app.metrics")) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); reporter.start(1, TimeUnit.MINUTES);​
  • 30. Naming by Matt Aimonetti <namespace>.<instrumented section>.<target (noun)>. <action (past tense verb)> Example ● customers.registration.validation.failed Nesting ● customers.registration.validation.failure. similar_email_found ● customers.registration.validation.failure. email_verification_failed
  • 31. AOP There is an easy way to introduce metrics using AOP. <aop:config proxy-target-class="false"> <aop:aspect id="controllerProfilerAspect" ref="executionMonitor"> <aop:pointcut id="controllerMethods" expression="execution(* com.app.controller.*Controller.*(..))" /> <aop:around pointcut-ref="controllerMethods" method="logExecutionTime" /> </aop:aspect> </aop:config> ​
  • 32. public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable { String namePfx = metricNamePrefix(joinPoint); Timer.Context time = registry.timer( name(namePfx, "timed")).time(); try { // execute joint point ... } catch(Throwable throwable) { registry.counter( name(namePfx, "exception-counted")).inc(); throw throwable; } finally { time.stop() } } ​
  • 33. metrics-spring @Configuration @EnableMetrics public class ApplicationConfiguration { @Bean public MetricRegistry metricRegistry(){ return new MetricRegistry(); } // your other beans here ... } // annotations @Timed, @Metered, @ExceptionMetered, @Counted​, @Gauge, @CachedGauge and @Metric
  • 34. instrumentation ● JVM ● Jetty ● Jersey ● InstrumentedFilter​ ● InstrumentedEhcache​ ● InstrumentedAppender (Log4j and Logback) ● InstrumentedHttpClient
  • 36. https://github.com/twitter/zipkin Zipkin is a distributed tracing system that helps Twitter gather timing data for all the disparate services. Zipkin provides three services: ● to collect data: bin/collector ● to extract data: bin/query ● to display data: bin/web
  • 37. http://www.moskito.org/ MoSKito is a ● Multi-purpose: collects any possible type of performance data, including business-related ● Non-invasive: does not require any code change ● Interval-based: works simultaneously with short & long time intervals, allowing instant comparison ● Data privacy: keeps collected data locally, with no 3rd party resources involved. ● Analysis tools: displays accumulated performance data in charts. Live profiling: records user actions as system calls.
  • 38. https://code.google.com/p/javasimon/ Java Simon is a simple monitoring API that allows you to follow and better understand your application. Monitors (familiarly called Simons) are placed directly into your code and you can choose whether you want to count something or measure time/duration.
  • 39. https://github.com/Netflix/servo Servo goal is to provide a simple interface for exposing and publishing application metrics in Java. ● JMX: JMX is the standard monitoring interface for Java ● Simple: It is trivial to expose and publish metrics ● Flexible publishing: Once metrics are exposed, it is easy to regularly poll the metrics and make them available for reporting systems, logs, and services like Amazon’s CloudWatch.
  • 41. getting started ● http://metrics.codahale.com/ ● http://matt.aimonetti. net/posts/2013/06/26/practical-guide-to- graphite-monitoring/ ● http://www.ryantenney.com/metrics-spring/
  • 42. q&a
  • 43. ThanksIzzet Mustafayev@EPAM Systems @webdizz webdizz izzetmustafaiev http://webdizz.name