66
Cyrille Le Clerc Open Source Monitoring for Java with Graphite Wednesday, May 15, 13

Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Embed Size (px)

DESCRIPTION

Fast feedback from monitoring is a key of Continuous Delivery. JMX is the right Java API to do so but it unfortunately stayed underused and underappreciated as it was difficult to connect to monitoring and graphing systems. Throw in the sin bin the poor solutions based on log files and weakly secured web interfaces! A new generation of Open Source tooling makes it easy to graph java application metrics and integrate them to traditional monitoring systems like Nagios. Following the logic of DevOps, we will look together how best to integrate the monitoring dimension in a project: from design to development, to QA and finally to production on both traditional deployment and in the Cloud. Come and discover how the JmxTrans-Graphite ticket can make your life easier.

Citation preview

Page 1: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Cyrille Le Clerc

Open Source Monitoring for Java with Graphite

Wednesday, May 15, 13

Page 2: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Speaker

Cyrille Le Clerc

@cyrilleleclerc

Open Source

CTO

DevOps, Infra as Code

Solution Architect

Cloud

Wednesday, May 15, 13

Page 3: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

You ?

DEV ? QA ? OPS ?Monitoring Experience ?

Wednesday, May 15, 13

Page 4: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Agenda

Wednesday, May 15, 13

Page 5: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Agenda

• The demo application

• Monitoring performance: Why ? What ?

• Java webapp monitoring with JMX

• Monitoring with Graphite

• Conclusion

Wednesday, May 15, 13

Page 6: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

The Application

Wednesday, May 15, 13

Page 7: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Your mission, should you decide to accept it, ...

Setup technical and business monitoring

e-commerce SOS Cocktails

http://www.flickr.com/photos/23791504@N08/2607814349

Wednesday, May 15, 13

Page 8: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

SOS Cocktail

Wednesday, May 15, 13

Page 9: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Monitoring application performanceWhy ? What ?

Wednesday, May 15, 13

Page 10: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

The Indicators to Monitor

Wednesday, May 15, 13

Page 11: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

The Indicators to Monitor

• Operating System ➔ Sysload

• JVM ➔ GC duration

• Tomcat ➔ activeSessions (active visitors)

• Application ➔ sales revenue & items

Wednesday, May 15, 13

Page 12: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Open Source Monitoring for Java

Wednesday, May 15, 13

Page 13: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Open Source Monitoring for Java

e-commerce web siteGraphite

Seyren

Dashboard - wiki

Nagios

Email

Wednesday, May 15, 13

Page 14: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

JMX & Metrics

Wednesday, May 15, 13

Page 15: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Why JMX ?

• JMX vs. web pages vs. logs vs. ...

• Simple and secured

• Displayable with web pages and logs

• Alternatives to JMX ?

Wednesday, May 15, 13

Page 16: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

JMX vs. logs vs. web pages vs. ...

• Monitoring logs

• Parsing GB of text files ?

• Per invocation details vs. average per minute

• Web pages

• History ?

• Clustered applications ?

• Security ?

Wednesday, May 15, 13

Page 17: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

JMX with Spring Framework

<beans  ...>      ...      <context:mbean-­‐export/>      ...</beans> @ManagedResource("cocktail:name=ShoppingCartController,type=...")

class  ShoppingCartController  {          final  AtomicInteger  revenueInCentsCounter  =  new  AtomicInteger();

 void  purchase(...){      ...      revenueInCentsCounter.addAndGet(priceInCents);  }

 @ManagedAttribute  public  int  getRevenueInCentsCounter()  {    return  revenueInCentsCounter.get();  }        

Wednesday, May 15, 13

Page 18: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

JMX with VisualVM

Wednesday, May 15, 13

Page 19: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

JMX with JSP

$  curl  http://demo-­‐cocktail.jmxtrans.cloudbees.net/5ADrUWr5/jmx-­‐sales-­‐metrics.txt.jspEpoch   SalesRevenueInCentsCounter   SalesItemsCounter   SalesOrdersCounter1363217376   4500   7   2

curl  http://demo-­‐cocktail.jmxtrans.cloudbees.net/5ADrUWr5/...{    "Epoch":1363217653,    "SalesRevenueInCentsCounter":4050,    "SalesItemsCounter":7,  ...}http://demo-cocktail.jmxtrans.cloudbees.net/jmx.jsp

Human readable & script friendlyWatch out for security !

Wednesday, May 15, 13

Page 20: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

JMX with JSP

$  curl  http://demo-­‐cocktail.jmxtrans.cloudbees.net/5ADrUWr5/jmx-­‐sales-­‐metrics.txt.jspEpoch   SalesRevenueInCentsCounter   SalesItemsCounter   SalesOrdersCounter1363217376   4500   7   2

curl  http://demo-­‐cocktail.jmxtrans.cloudbees.net/5ADrUWr5/...{    "Epoch":1363217653,    "SalesRevenueInCentsCounter":4050,    "SalesItemsCounter":7,  ...}http://demo-cocktail.jmxtrans.cloudbees.net/jmx.jsp

Human readable & script friendlyWatch out for security !

/5ADrUWr5/jmx-sales-metrics.jsp

Wednesday, May 15, 13

Page 21: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

JMX with JSP

Wednesday, May 15, 13

Page 22: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Alternatives to JMX

Wednesday, May 15, 13

Page 23: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Alternatives to JMX

class  Shopping

CartController

 {

 @Monitor(name

="revenueInCen

ts",  type=COUN

TER)

 final  AtomicI

nteger  revenue

InCentsCounter

 =  new  AtomicI

nteger();

         void  p

urchase(...){

     ...

     revenueInCe

ntsCounter.add

AndGet(priceIn

Cents);

 }

Servo

Wednesday, May 15, 13

Page 24: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Alternatives to JMX

class  Shopping

CartController

 {

 @Monitor(name

="revenueInCen

ts",  type=COUN

TER)

 final  AtomicI

nteger  revenue

InCentsCounter

 =  new  AtomicI

nteger();

         void  p

urchase(...){

     ...

     revenueInCe

ntsCounter.add

AndGet(priceIn

Cents);

 }

Servo

class  ShoppingCartController  {          final  Counter  revenueInCentsCounter  =  Metrics.newCounter(                            ShoppingCartController,  "revenue-­‐in-­‐cents");          void  purchase(...){      ...      revenueInCentsCounter.inc(priceInCents);  }

Metrics

Wednesday, May 15, 13

Page 25: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

JMX

• OS: Sysload

• JVM: Garbage Collector

• Tomcat: activeSessions

• Application: Web Site Revenue

Wednesday, May 15, 13

Page 26: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

jmxtrans

Wednesday, May 15, 13

Page 27: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

jmxtrans - standalone

ecommerceTomcat

Graphite

accountingTomcat

logisticsTomcat

...

jmxtrans - standaloneWednesday, May 15, 13

Page 28: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

embedded-jmxtrans

logistics

Tomcat

Graphite

ecommerce

Tomcat

accounting

Tomcat

Librato

...

batch

embedded-jmxtransWednesday, May 15, 13

Page 29: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

jmxtrans-agent

jmxtrans-agentjava -javaagent=jmxtrans-agent.jar=...

Graphite

...

batch

ecommerce

TomcatJVM

ecommerce

TomcatJVM

ecommerce

TomcatJVM

logistics

TomcatJVM

ecommerce

TomcatJVM

accounting

TomcatJVM

JVM

JVM

Librato

Wednesday, May 15, 13

Page 30: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

standalone vs. embedded vs. agent

standalone embedded agent

Packaging

Model Manually connected appsPull

Standalone appsPush

Standalone middlewarePush

Cursor OPS -♦----------- DEV OPS ----------♦-- DEV OPS ---♦--------- DEV

Use case Net unfriendly monitoring, OPS

cloud, batch DEV/QA

cloud, batchOPS

Wednesday, May 15, 13

Page 31: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

embedded-jmxtrans configuration

Wednesday, May 15, 13

Page 32: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

embedded-jmxtrans configuration

<dependency>    <groupId>org.jmxtrans.embedded</groupId>    <artifactId>embedded-­‐jmxtrans</artifactId>    <version>1.0.7</version></dependency>

Wednesday, May 15, 13

Page 33: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

embedded-jmxtrans configuration

<dependency>    <groupId>org.jmxtrans.embedded</groupId>    <artifactId>embedded-­‐jmxtrans</artifactId>    <version>1.0.7</version></dependency>

<beans  ...    xmlns:jmxtrans="http://www.jmxtrans.org/schema/embedded"    xsi:schemaLocation="...        http://www.jmxtrans.org/schema/embedded  ...”>

   <jmxtrans:jmxtrans>        <jmxtrans:configuration>classpath:jmxtrans.json</jmxtrans:configuration>        ...    </jmxtrans:jmxtrans></beans>

Wednesday, May 15, 13

Page 34: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

embedded-jmxtrans configuration

<dependency>    <groupId>org.jmxtrans.embedded</groupId>    <artifactId>embedded-­‐jmxtrans</artifactId>    <version>1.0.7</version></dependency>

<beans  ...    xmlns:jmxtrans="http://www.jmxtrans.org/schema/embedded"    xsi:schemaLocation="...        http://www.jmxtrans.org/schema/embedded  ...”>

   <jmxtrans:jmxtrans>        <jmxtrans:configuration>classpath:jmxtrans.json</jmxtrans:configuration>        ...    </jmxtrans:jmxtrans></beans>

{    "queries":  [            {            "objectName":  "cocktail:name=ShoppingCartController",            "resultAlias":  "sales",            "attributes":  ["SalesRevenueInCentsCounter"]        },    ],    "outputWriters":  [        {            "@class":  "org.jmxtrans.embedded.output.GraphiteWriter",            "settings":  {                "host":  "${graphite.host:localhost}",                "port":  "${graphite.port:2003},"                "enabled":  "${graphite.enabled:true}"            }        }    ]}

Wednesday, May 15, 13

Page 35: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Graphite

Wednesday, May 15, 13

Page 36: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Graphite

• Open Source

• Time Series DataBase and graphing tool

• Used by tech giants

• Similar

Wednesday, May 15, 13

Page 37: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Graphite

• Open Source

• Time Series DataBase and graphing tool

• Used by tech giants

• Similar

Simplicity and Self Service

Wednesday, May 15, 13

Page 38: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Metrics injection / Write Access

• Automatic metrics creation

• Socket protocols: “plain text” & Python Pickle serialization

• Precision and storage duration by configuration

echo  "geecon.happyCounter  1.2  1364338989"  |  nc  localhost  2003

[sales_1min_for_15days_5min_for_1year]pattern  =  ^sales\.retentions  =  60s:30d,300s:365d 1.7MB

Wednesday, May 15, 13

Page 39: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

• Graph Composer & URL API

• Everybody can create graphs

• Wide range of functions• sum, scale, derivative, timeshift, deviation, filter, ...

• Various exports• png, svg, csv, json, raw text

Metrics rendering / Read Access

Wednesday, May 15, 13

Page 40: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

The Art of Graphing

Wednesday, May 15, 13

Page 41: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Monitoring on the Cloud

• http://hostedgraphite.com/

• Graphite as a Service• Zero setup

• Addons: Tasseo

• No-OPS

1

2

3

email: [email protected]

password: GEECON

Wednesday, May 15, 13

Page 42: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Metrics Types

• Examples: activeRequests, dataSource.activeConnection, ...

• Information available without transformation

Gauge Ever Increasing Counter

• Examples: requestsCount, revenue, ...

• “per minute” aggregation required

Wednesday, May 15, 13

Page 43: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Graphs and Maths

Ever Increasing Counter Revenue per Second

?

Wednesday, May 15, 13

Page 44: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Graphs and Maths

Ever Increasing Counter Revenue per Second

?derivative()

Wednesday, May 15, 13

Page 45: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Graphs and Maths

?

Revenue per HourPer Second → Per Hour

Wednesday, May 15, 13

Page 46: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Graphs and Maths

?

Revenue per HourPer Second → Per Hour

summarize(..., “1h”)

Wednesday, May 15, 13

Page 47: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Graphs and Maths

2 servers

?

Total Revenue per Hour

Wednesday, May 15, 13

Page 48: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Graphs and Maths

2 servers

?

Total Revenue per Hour

sumSeries()

Wednesday, May 15, 13

Page 49: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Graphs and Maths

server restart

?

Ignore reset to zero

Wednesday, May 15, 13

Page 50: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Graphs and Maths

server restart

?

Ignore reset to zero

nonNegativeDerivative()

Wednesday, May 15, 13

Page 51: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Graphs and Maths

Compare to last week

?

Wednesday, May 15, 13

Page 52: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Graphs and Maths

Compare to last week

?timeShift(..., “7d”)

Wednesday, May 15, 13

Page 53: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

JMX

• OS: Sysload

• JVM: Garbage Collector

• Tomcat: activeSessions

• Application: Web Site Revenue

Wednesday, May 15, 13

Page 54: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Graphite URL API

http://localhost:8081/render/?      from=-­‐7days&      title=Revenue%20per%20Hour&      vtitle=Dollars&      lineWidth=3&      xFormat=%25a%20%25H%25p&      target=        alias(          scale(            summarize(              sumSeries(                nonNegativeDerivative(                  edu.servers.*.sales.revenueInCentsCounter)...)&        ...

Wednesday, May 15, 13

Page 55: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Sharing metrics and graphs

Wednesday, May 15, 13

Page 56: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Dashboards and Wikisdashboard.prod.md#  Website  Traffic

<table><tr>    <td>        <img  src="http://graphite.prod.mycompany/graphite/render/?width=400&height=300&title=Revenue&xFormat=%25a%20%25d%25p&vtitle=USD&lineWidth=3&from=-­‐5days&target=alias(scale(summarize(sumSeries(nonNegativeDerivative(edu.servers.*.sales.revenueInCentsCounter))%2C%221h%22)%2C0.01)%2C%22Revenue%20per%20Hour%22)...">        </td>        <td>                <img  src="http://graphite.prod.mycompany/graphite/render/?...">        </td><tr></table>

Wiki

https://github.com/jmxtrans/embedded-jmxtrans-samples/wiki/Dashboard-PRODWednesday, May 15, 13

Page 57: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Dashboards and Email

Send dashboards by email

Wednesday, May 15, 13

Page 58: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Alerting with Metrics

Wednesday, May 15, 13

Page 59: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Graphite Integration with Alerting

• Based on Graphite URL API

• RawText or JSON format

• Pattern/render?from=-­‐11minutes&until=-­‐1minutes&format=raw&target=****

Wednesday, May 15, 13

Page 60: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Graphite Integration with Alerting

• Based on Graphite URL API

• RawText or JSON format

• Pattern/render?from=-­‐11minutes&until=-­‐1minutes&format=raw&target=****

$  curl  "http://graphite.example.com/render?from=-­‐11minutes&until=-­‐1minutes&format=raw&      target=keepLastValue(servers.cloudbees.jvm.os.SystemLoadAverage)"  

my-­‐metric,1363225680,1363226340,60|0.03,0.01,0.1,4.0,4.0,0.9,0.7,0.8,0.4,0.5,0.5

Example

Wednesday, May 15, 13

Page 61: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Graphite Alerting with Seyren

• Alerting Dashboard for Graphite

• Open Source

• Java .war + MongoDB

• Alerts: email, PagerDuty, ...

http://seyren.jmxtrans.cloudbees.net/

Wednesday, May 15, 13

Page 62: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

• Monitoring Infrastructure

• Open Source

• De facto standard

• check_graphite plugin• Pierre-Yves Ritschard

• Jason Dixon / obfuscurity

Graphite Alerting with Nagios

Wednesday, May 15, 13

Page 63: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Conclusion

Wednesday, May 15, 13

Page 64: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Conclusion

• Self-service monitoring changes everything

• Technical and business monitoring

• Monitoring integrated in the Continuous Delivery

pipeline

• Open Source solutions are available

Wednesday, May 15, 13

Page 65: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

Hosted Graphite Promo

• http://hostedgraphite.com

• 60 days trial with “GEECON” promo code

help: [email protected]

(1) Signup (2) Options / Enter Promo Code (3) Promo Code “GEECON”

Wednesday, May 15, 13

Page 66: Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)

http://demo-cocktail.jmxtrans.cloudbees.net/http://jmxtrans.org/

Wednesday, May 15, 13