+ All Categories
Home > Software > Metrics by coda hale : to know your app’ health

Metrics by coda hale : to know your app’ health

Date post: 02-Nov-2014
Category:
Upload: izzet-mustafaiev
View: 3,036 times
Download: 0 times
Share this document with a friend
Description:
Nowadays when developers required to be aligned with operations it’s quite important to have common understanding of how application is performing in production. I believe quite small amount of developers are really care/think about operation of the app. In this talk I’m going to describe how it’s easy to provide performance information of application in production with Metrics by Coda Hale and to share practical use cases.
Popular Tags:
43
Metrics by Coda Hale to know your app’ health Izzet Mustafayev@EPAM Systems @webdizz webdizz izzetmustafaiev http://webdizz.name
Transcript
Page 1: Metrics by coda hale : to know your app’ health

Metrics by Coda Haleto know your app’ health

Izzet Mustafayev@EPAM Systems@webdizz webdizz izzetmustafaievhttp://webdizz.name

Page 2: Metrics by coda hale : to know your app’ health

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

Page 3: Metrics by coda hale : to know your app’ health

agenda● introduction

● why should i care

● features

● reporting

● recipes

● alternatives

● q&a

Page 4: Metrics by coda hale : to know your app’ health
Page 5: Metrics by coda hale : to know your app’ health

Finish or Start?

Page 6: Metrics by coda hale : to know your app’ health

Familiar?

Page 7: Metrics by coda hale : to know your app’ health

Possible?!.

Page 8: Metrics by coda hale : to know your app’ health

Your app?!.

Page 9: Metrics by coda hale : to know your app’ health

Dreams...

Page 10: Metrics by coda hale : to know your app’ health

One thing...

Page 11: Metrics by coda hale : to know your app’ health

● does my app work?

Page 12: Metrics by coda hale : to know your app’ health

● does my app work?

● will my app keep working?

Page 13: Metrics by coda hale : to know your app’ health

● does my app work?

● will my app keep working?

● what happened that

made my app stop

working?

Page 14: Metrics by coda hale : to know your app’ health

Statistics

Page 15: Metrics by coda hale : to know your app’ health

Metrics

Page 16: Metrics by coda hale : to know your app’ health

Features

Page 17: Metrics by coda hale : to know your app’ health

Registry...- is the heart of metrics framework

MetricRegistry registry = new MetricRegistry();

// or

@Bean public MetricRegistry metricRegistry(){ return new MetricRegistry(); }

Page 18: Metrics by coda hale : to know your app’ health

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(); }

});

Page 19: Metrics by coda hale : to know your app’ health

Counter...- is a simple incrementing and decrementing integer value

Counter onSiteUsers = registry.counter(name(User.class, "users-logged-in"));

// on login increaseonSiteUsers.inc();

// on logout/session expiration decreaseonSiteUsers.dec();

Page 20: Metrics by coda hale : to know your app’ health

Histogram...- measures the distribution of values in a stream of data

Histogram requestTimes = registry.histogram(name(Request.class, "request-processed")

);

requestTimes.update(request.getTime());

Page 21: Metrics by coda hale : to know your app’ health

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-outtimedOutRequests.mark();

Page 22: Metrics by coda hale : to know your app’ health

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 processingtime.stop();

Page 23: Metrics by coda hale : to know your app’ health

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"); } }

Page 24: Metrics by coda hale : to know your app’ health

Reporting

Page 25: Metrics by coda hale : to know your app’ health

JMX

// somewhere in your application

JmxReporter reporter = JmxReporter.forRegistry(registry).build();

reporter.start();

Page 26: Metrics by coda hale : to know your app’ health

HTTP

● AdminServlet

○ MetricsServlet

○ ThreadDumpServlet

○ PingServlet

○ HealthCheckServlet

Page 27: Metrics by coda hale : to know your app’ health

ConsoleConsoleReporter 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);

Page 28: Metrics by coda hale : to know your app’ health

Ganglia & Graphite

Page 29: Metrics by coda hale : to know your app’ health
Page 30: 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

Page 31: Metrics by coda hale : to know your app’ health

AOPThere 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>

Page 32: Metrics by coda hale : to know your app’ health

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() } }

Page 33: Metrics by coda hale : to know your app’ health

metrics-spring@Configuration@EnableMetricspublic class ApplicationConfiguration { @Bean public MetricRegistry metricRegistry(){ return new MetricRegistry(); } // your other beans here ...}

// annotations@Timed, @Metered, @ExceptionMetered, @Counted , @Gauge, @CachedGauge and @Metric

Page 34: Metrics by coda hale : to know your app’ health

instrumentation

● JVM

● Jetty

● Jersey

● InstrumentedFilter

● InstrumentedEhcache

● InstrumentedAppender (Log4j and Logback)

● InstrumentedHttpClient

Page 35: Metrics by coda hale : to know your app’ health

Alternatives

Page 36: Metrics by coda hale : to know your app’ health

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

Page 37: Metrics by coda hale : to know your app’ health

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.

Page 38: Metrics by coda hale : to know your app’ health

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.

Page 39: Metrics by coda hale : to know your app’ health

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.

Page 40: Metrics by coda hale : to know your app’ health

Summary

Page 42: Metrics by coda hale : to know your app’ health

q&a

Page 43: Metrics by coda hale : to know your app’ health

ThanksIzzet Mustafayev@EPAM Systems@webdizz webdizz izzetmustafaievhttp://webdizz.name


Recommended