open source monitoring for java with jmx and graphite - softshake 2013

Post on 11-May-2015

3.535 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

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 based on JMX and Graphite makes it easy to graph java application metrics, including business indicators, 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.

TRANSCRIPT

©2013 CloudBees, Inc. All Rights Reserved

Cyrille Le Clerc

Open Source Monitoring for Java with Graphite

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

/me

2

Cyrille Le Clerc

@cyrilleleclerc

Open Source

CTO

DevOps, Infra as Code

Solution Architect

Cloud

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

You ?

DEV ? QA ? OPS ?Monitoring Experience ?

3

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Agenda

4

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Agenda

• The demo application

• Monitoring performance: Why? What?

• Java webapp monitoring with JMX

• Monitoring with Graphite

• Conclusion

5

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

The Application

6

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

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

e-commerce SOS Cocktailshttp://www.flickr.com/photos/23791504@N08/2607814349

Setup technical and business monitoring

7

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

SOS Cocktail

8

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

MonitoringWhy ? What ?

9

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

The Indicators to Monitor

10

http://www.langevin.com/blog/2013/08/29/3-ways-to-maximize-brainstorming/

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

The Indicators to Monitor

• Operating System ➔ Sysload

• JVM ➔ GC duration

• Tomcat ➔ activeSessions (active visitors)

• Application ➔ sales revenue & items

11

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Open Source Monitoring for Java

12

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Open Source Monitoring for Javae-commerce web site

Graphite

Seyren

Dashboard - wiki

Nagios

Email

13

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

JMX & Metrics

14

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Why JMX ?

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

• Simple and secured

• Displayable with web pages and logs

• Alternatives to JMX ?

15

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

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 ?

16

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

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

17

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

JMX with VisualVM

18

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

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 !

19

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

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

19

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

JMX with JSP

20

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Alternatives to JMX

21

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

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

21

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

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

 }

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

Metrics

21

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

• OS: Sysload

• JVM: Garbage Collector

• Tomcat: activeSessions

• Application: Web Site Revenue

JMX

22

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved 23

jmxtrans

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

jmxtrans - standaloneecommerceTomcat

Graphite

accountingTomcat

logisticsTomcat

...

24

jmxtrans - standalone

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

embedded-jmxtrans

embedded-jmxtrans

25

logistics

Tomcat

Graphite

ecommerce

Tomcat

accounting

Tomcat

...batch

Librato

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

jmxtrans-agent

java -javaagent=jmxtrans-agent.jar=...

Graphite

...

batch

ecommerce

TomcatJVM

ecommerce

TomcatJVM

ecommerce

TomcatJVM

logistics

TomcatJVM

ecommerce

TomcatJVM

accounting

TomcatJVM

JVM

JVM

Librato

26

jmxtrans-agent

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

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 caseNet unfriendly monitoring,

OPScloud, batch

DEV/QAcloud, batch

OPS

27

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

embedded-jmxtrans configuration

28

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

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

28

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

embedded-jmxtrans configuration<dependency>    <groupId>org.jmxtrans.embedded</groupId>    <artifactId>embedded-­‐jmxtrans</artifactId>    <version>1.0.8</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>

28

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

embedded-jmxtrans configuration<dependency>    <groupId>org.jmxtrans.embedded</groupId>    <artifactId>embedded-­‐jmxtrans</artifactId>    <version>1.0.8</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}"            }        }    ]}

28

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved 29

Graphite

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Graphite• Open Source

• Time series database and graphing tool

• Used by tech giants

• Similar

30

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Graphite• Open Source

• Time series database and graphing tool

• Used by tech giants

• Similar

Simplicity and Self Service

30

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

• Automatic metrics creation

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

• Precision and storage duration by configuration

Metrics injection / Write Access

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

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

31

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Metrics rendering / Read Access• 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

32

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved 33

The Art of Graphing

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Monitoring on the Cloud

• http://hostedgraphite.com/

• Graphite as a Service

• Zero setup

• Addons: Tasseo

• No-OPS

1

2

3

email: admin@jmxtrans.orgpassword: SOFTSHAKE

34

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Metrics Types

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

• Information available without transformation

Ever Increasing Counter

• Examples: requestsCount, revenue, ...

• “per minute” aggregation required

Gauge

35

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Graphs and Maths

Ever Increasing Counter Revenue per Second

?

36

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Graphs and Maths

Ever Increasing Counter Revenue per Second

?derivative()

36

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Graphs and Maths

?

Revenue per HourPer Second → Per Hour

37

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Graphs and Maths

?

Revenue per HourPer Second → Per Hour

summarize(..., “1h”)

37

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Graphs and Maths

2 servers

?

Total Revenue per Hour

38

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Graphs and Maths

2 servers

?

Total Revenue per Hour

sumSeries()

38

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Graphs and Maths

server restart

?

Ignore reset to zero

39

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Graphs and Maths

server restart

?

Ignore reset to zero

nonNegativeDerivative()

39

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Graphs and Maths

?

40

Compare to last week

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Graphs and Maths

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

40

Compare to last week

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

• OS: Sysload

• JVM: Garbage Collector

• Tomcat: activeSessions

• Application: Web Site Revenue

JMX

41

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Graphite URL APIhttp://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)...)&        ...

42

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved 43

Sharing metrics and graphs

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

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

44

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Dashboards and EmailSend dashboards by email

45

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved 46

Alerting with Metrics

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Graphite Integration with Alerting• Based on Graphite URL API

• RawText or JSON format

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

47

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

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

47

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Graphite Alerting with Seyren• Alerting Dashboard for Graphite

• Open Source

• Java .war + MongoDB

• Alerts: email, PagerDuty, ... http://seyren.jmxtrans.cloudbees.net/

48

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

• Monitoring Infrastructure

• Open Source

• De facto standard

• check_graphite plugin

• Pierre-Yves Ritschard

• Jason Dixon / obfuscurity

Graphite Alerting with Nagios

49

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved 50

Conclusion

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Conclusion• Self-service monitoring changes everything

• Technical and business monitoring

• Monitoring integrated in the Continuous Delivery pipeline

• Open Source solutions are available

51

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

Hosted Graphite Promo• http://hostedgraphite.com

• 45 days trial with “SOFTSHAKE” promo code

help: cleclerc@cloudbees.com

(1) Signup(2) Options / Enter Promo Code

(3) Promo Code “SOFTSHAKE”

52

Thursday, October 24, 13

©2013 CloudBees, Inc. All Rights Reserved

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

53

Thursday, October 24, 13

top related