JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

53
JBoss RHQByteman이용한 오픈소스 자바 애플리케이션 모니터링 JBoss User Group Community RHQ Contributor 원종석

description

JBoss 커뮤니티에서 제공하는 모니터링 오픈소스 플랫폼에 관한 소개입니다.

Transcript of JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Page 1: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

JBoss RHQ와 Byteman을 이용한

오픈소스 자바 애플리케이션 모니터링

JBoss User Group Community

RHQ Contributor

원종석

Page 2: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Break the Ice

• 보통 개발자의 두 가지 무기에 관한 이야기

• 비상시 유용한 오픈 소스 프로젝트 소개

• 운영 서비스 모니터링은 RHQ

• 운영 중인 JVM bytecode 들여다 볼 때는 Byteman

• Thanks a lot JBoss!!

• 그리고 Welcome to Korea JBoss User Group!!

• 언제나 환영합니다.

- 1 -

Page 3: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

About me?

• 그냥 딸 바보 아빠

• 오픈 소스로 일하는 보통 자바 개발자

• 대형 SI 개발, 운영, SA

• Workflow 솔루션, Big Data 플랫폼 개발

• 실시간 대용량 Event 처리 플랫폼 개발

• JBoss User Group Community 부대표

• RHQ Contributor - 한글화 작업

• tedwon.com WIKI 운영

- 2 -

Page 4: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Agenda

• RHQ 소개

• Byteman 소개

• Demo

- 3 -

Page 5: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

- 4 -

Open Source Monitoring & Management Project

Page 6: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

For Instance

• 내가 만든 Java Application을 모니터링하고 싶다.

• 장기간 지속적으로... Chart도 필요하고... Statistics도 필요하고...

• 직접 만들려고 해보면 너무 일이 커지고

• 돈 주고 사기에는 너무 비싸고

• 손쉽게 공짜로 사용 할 수 있는 것 어디 없을까?

• 게다가 좀 더 체계적이고 다양한 기능을 제공했으면 좋겠다.

- 5 -

Page 7: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

- 6 -

완전 공짜

Page 8: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

RHQ would be one of the Solutions!

- 7 -

Page 9: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

RHQ 4’s New Features

• New Ajax Dynamic GUI

• Use Java SE 6 Script Feature for RHQ CLI

• REST API (under development)

- 8 -

Page 10: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

RHQ would be one of the Solutions!

- 9 -

Page 11: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

RHQ would be one of the Solutions!

- 10 -

Page 12: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

RHQ would be one of the Solutions!

- 11 -

Page 13: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

RHQ would be one of the Solutions!

- 12 -

Page 15: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Conclusions in Advance

Step 1. RHQ Server 와 Agent 설치 Step 2. Java Application에 JMX MBean 추가 Step 3. JMX MBean 기반 Plugin Descriptor XML 파일 정의 Step 4. 나의 Application용 JMX Plugin을 RHQ Server에 등록 Step 5. 모니터링 및 관리 시작!!

- 14 -

Page 16: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

RHQ by JBoss

• JBoss Enterprise Management Platform

• JBoss Middleware 제품의 모니터링 Platform

o JBoss AS

o Byteman

o Hibernate

o HornetQ

o Infinispan

o BlackTie

o Mobicents

o CirrAS

o etc ...

- 15 -

Page 17: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

What is RHQ?

• Make technologies more manageable!!

• Aims to develop a common services management platform

• Java 기반의 Open Source System Management Project

• Sigar API 를 사용하여 System Information Gathering (CPU, Mem)

• JMX 기술 기반으로 원격 관리 기능 제공 - JMX Plugin

• OS 플랫폼에서 Server 리소스까지 전반적인 모니터링/관리 기능 제공

- 16 -

Page 18: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

What is RHQ?

• Agent의 plugin을 통해서 모니터링 정보 수집

• 필요한 plugin만 구성해서 사용하면 적절

• 실시간 모니터링 서버는 아님 - 최소 30초 주기로 모니터링

• 장기간 모니터링에 적합

- 17 -

Page 19: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

RHQ Server & Agent Architecture

- 18 -

Page 20: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

RHQ Management Functionality

• Inventory

• Monitoring

• Configuration

• Events

• Control

- 19 -

Page 21: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

RHQ Management Functionality

• Inventory

o 모니터링 대상 정의/등록/관리 o Resource directory

• Monitoring

o Monitoring any resource

o Automatic discovery of resources

o Monitoring for availability and performance

o Complex alerting

• Configuration

o Configuration management o Audited, validated configuration editing and history

- 20 -

Page 22: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

RHQ Management Functionality

• Events

o WAS의 로그 에러 트래킹과 레포트 • Control

o 원격에서 operation 실행

o Operation 스케쥴링

- 21 -

Page 23: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

RHQ Monitor Architecture

- 22 -

• 모니터링 대상을 Resource 라고 통칭한다.

OS

Process

Page 24: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

RHQ Agent Plugins

- 23 -

• 다양한 리소스를 위한 Plugin 제공

• Server Plugins: Apache, Tomcat, JBoss AS

• RDBMS Plugins: MySQL, PostgreSQL, Oracle

• Java JMX Plugin

• C daemon 프로세스 (Ex: Scribe Log Aggregator)

• 필요에 맞는 Custom Plugin 제작 가능

• http://rhq-project.org/display/RHQ/Plugin+Community

Page 26: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

RHQ / JBoss ON Team

- 25 -

• Red Hat building in Westford, Massachusetts

Page 27: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

RHQ Contributions

- 26 -

• Installer UI 한글화 작업 완료 from v4.2

• GWT UI 한글화 작업 진행 중...

Red Hat - Heiko Rupp

그냥 - Ted Won

Page 28: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

- 27 -

Page 29: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

- 28 -

http://www.jboss.org/byteman

Page 30: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

- 29 -

보통 개발자의 또 하나의 무기 Byteman

명품 영국제 무기

Thanks Andrew :-)

Page 31: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Where to use?

- 30 -

• Performance check

• System.exit() and System.gc() check

• synchronized block check

• Analyze 3rd party library, WAS, etc

Page 32: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Byte(code) man(ipulation) is

- 30 -

• 안전하게 실행 중인 JVM 안의 bytecode 들여다 보는 도구

• 디버깅 코드를 동적으로 삽입할 수 있는 도구

• Tool that simplifies tracing and testing of Java programs

• Bytecode Injection 방식 사용

• 재컴파일, 재구동 없이 실행 중인 애플리케이션에 bytecode inject 가능

• Works by modifying the bytecode of your application at runtime

o 소스 코드 없이 동적으로 bytecode를 직접 변경

Page 33: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Byte(code) man(ipulation) is

- 31 -

• Java Agent API를 기반으로 Byteman Agent 구현

o java.lang.instrument API for runtime bytecode transformation

• Byteman is a Java agent program

o Retransform code only after load

• Injected codes are reversible

o Inject된 bytecode는 다시 원복 가능

Page 34: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Byteman Rule Script is

- 32 -

• Rule based scripting language

• Write code to see what code is doing

• Very Java oriented (almost all Java)

• We inject codes through rule script files

• Event Condition Action (ECA) 으로 정의하는 scripting language

• Dynamically load, reload or unload rules

• BTrace는 rule 대신 annotation-oriented script 정의

Page 35: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Sample Byteman Rule Script

- 33 -

RULE trace main entry

CLASS MyAppMain

METHOD main

AT ENTRY

IF true

DO

traceln("entering main")

ENDRULE

Page 36: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Sample Byteman Rule Script

- 34 -

RULE trace main entry => Rule name

CLASS MyAppMain

METHOD main

AT ENTRY

IF true

DO

traceln("entering main")

ENDRULE

Page 37: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Sample Byteman Rule Script

- 35 -

RULE trace main entry

CLASS MyAppMain => Event (Trigger point)

METHOD main

AT ENTRY

IF true

DO

traceln("entering main")

ENDRULE

Page 38: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Sample Byteman Rule Script

- 36 -

RULE trace main entry

CLASS MyAppMain

METHOD main

AT ENTRY

IF true => Condition

DO

traceln("entering main")

ENDRULE

Page 39: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Sample Byteman Rule Script

- 37 -

RULE trace main entry

CLASS MyAppMain

METHOD main

AT ENTRY

IF true

DO

traceln("entering main") => Action

ENDRULE

Page 40: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Event Condition Action Rules

- 38 -

• Event

o CLASS/INTERFACE, METHOD, AT

defines trigger point(s) for rule

• Binding

o introduces/initializes rule variables

• Condition

o Java boolean expression

• Action

o one or more Java expressions

Page 41: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Driving Byteman

- 39 -

• Download Byteman and unzip

• Set BYTEMAN_HOME

• Install as “Java agent” through java options => 서버 재구동

-javaagent:$BYTEMAN_HOME/lib/byteman.jar=agentoptions

o script:script.btm install rules from script.btm at agent startup

o boot:my.jar add my.jar to bootstrap classpath

o sys:my.jar add my.jar to system classpath

o listener:true start up agent listener o port:999 use listener port 999

o address:192.168.0.1 use listener host 192.168.0.1

Page 42: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Driving Byteman

- 40 -

• Download Byteman and unzip

• Set BYTEMAN_HOME

Page 43: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Running JBoss AS with Byteman

- 41 -

• run-with-byteman.sh

o 시작 스크립트에 아래 두 라인 추가

o Tomcat 또한 동일

BYTEMAN_OPTS="-Dorg.jboss.byteman.verbose=true

-Dorg.jboss.byteman.debug=true -Dorg.jboss.byteman.transform.all -javaagent:byteman.jar=

script:my-byteman-rules.txt ,boot:byteman.jar ,boot:byteman-sample.jar ,sys:byteman-sample.jar ,listener:true

,port:9551

,address:127.0.0.1" JAVA_OPTS="$BYTEMAN_OPTS -Xms1g -Xmx1g $JAVA_OPTS"

Page 44: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Quick Start - MyAppMain.java

- 42 -

package org.my;

public class MyAppMain {

public static void main(String[] args) {

for (int i = 0; i < args.length; i++) {

System.out.println(args[i]);

}

}

}

$ java org.my.MyAppMain foo bar baz

foo

bar

baz

Page 45: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Quick Start - appmain.btm

- 43 -

MyAppMain 클래스의 main 메소드 호출 시작시에 로그를 출력하라.

RULE trace main entry

CLASS MyAppMain

METHOD main

AT ENTRY

IF true

DO traceln("entering main")

ENDRULE

Page 46: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Load Rules at JVM Start

- 44 -

$ java -javaagent:byteman.jar=script:appmain.btm

org.my.MyAppMain foo bar baz

entering main

foo

bar

baz

$

Page 47: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Byteman Built In Methods

- 45 -

• Tracing

o traceOpen, traceClose, traceln, traceStack, ... • Managing Shared Rule State

o flag, clear, countDown, incrementCounter, ... • Timing

o createTimer, getElapsedTime, resetTimer • Checking Caller Stack

o callerEquals, callerMatches

• Thread Synchronization

o delay, waitFor, signalWake, rendezvous, ... • Recursive Trigger Management

o setTriggering

Page 48: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

- 46 -

Refer to Byteman Programmer’s Guide

http://tedwon.com/display/dev/Byteman

Page 49: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

- 47 -

Byteman Versions

Page 50: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

- 48 -

DEMO

Page 51: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

- 49 -

• RHQ Demo

o Dashboard

o Custom Java App

o Alert o JBoss AS Cluster Group View

• Byteman Demo

o Install byteman agent at start up

o Install byteman agent into a running jvm

o Load Rule

o Unload Rule

• Byteman Plugin Demo

o Autodiscovery Byteman Agent o Monitor Byteman Agent Availability & Rules

Page 52: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Thanks [email protected]

Page 53: JBoss RHQ와 Byteman을 이용한 오픈소스 자바 애플리케이션 모니터링