jboss rhq와 byteman을 이용한 오픈소스 자바 애플리케이션 모니터링

Post on 05-Dec-2014

2.645 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

JBoss RHQ와 Byteman을 이용한

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

JBoss User Group Community

RHQ Contributor

원종석

Break the Ice

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

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

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

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

• Thanks a lot JBoss!!

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

• 언제나 환영합니다.

- 1 -

About me?

• 그냥 딸 바보 아빠

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

• 대형 SI 개발, 운영, SA

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

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

• JBoss User Group Community 부대표

• RHQ Contributor - 한글화 작업

• tedwon.com WIKI 운영

- 2 -

Agenda

• RHQ 소개

• Byteman 소개

• Demo

- 3 -

- 4 -

Open Source Monitoring & Management Project

For Instance

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

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

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

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

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

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

- 5 -

- 6 -

완전 공짜

RHQ would be one of the Solutions!

- 7 -

RHQ 4’s New Features

• New Ajax Dynamic GUI

• Use Java SE 6 Script Feature for RHQ CLI

• REST API (under development)

- 8 -

RHQ would be one of the Solutions!

- 9 -

RHQ would be one of the Solutions!

- 10 -

RHQ would be one of the Solutions!

- 11 -

RHQ would be one of the Solutions!

- 12 -

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 -

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 -

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 -

What is RHQ?

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

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

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

• 장기간 모니터링에 적합

- 17 -

RHQ Server & Agent Architecture

- 18 -

RHQ Management Functionality

• Inventory

• Monitoring

• Configuration

• Events

• Control

- 19 -

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 -

RHQ Management Functionality

• Events

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

o 원격에서 operation 실행

o Operation 스케쥴링

- 21 -

RHQ Monitor Architecture

- 22 -

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

OS

Process

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

RHQ / JBoss ON Team

- 25 -

• Red Hat building in Westford, Massachusetts

RHQ Contributions

- 26 -

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

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

Red Hat - Heiko Rupp

그냥 - Ted Won

- 27 -

- 28 -

http://www.jboss.org/byteman

- 29 -

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

명품 영국제 무기

Thanks Andrew :-)

Where to use?

- 30 -

• Performance check

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

• synchronized block check

• Analyze 3rd party library, WAS, etc

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를 직접 변경

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는 다시 원복 가능

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 정의

Sample Byteman Rule Script

- 33 -

RULE trace main entry

CLASS MyAppMain

METHOD main

AT ENTRY

IF true

DO

traceln("entering main")

ENDRULE

Sample Byteman Rule Script

- 34 -

RULE trace main entry => Rule name

CLASS MyAppMain

METHOD main

AT ENTRY

IF true

DO

traceln("entering main")

ENDRULE

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

Sample Byteman Rule Script

- 36 -

RULE trace main entry

CLASS MyAppMain

METHOD main

AT ENTRY

IF true => Condition

DO

traceln("entering main")

ENDRULE

Sample Byteman Rule Script

- 37 -

RULE trace main entry

CLASS MyAppMain

METHOD main

AT ENTRY

IF true

DO

traceln("entering main") => Action

ENDRULE

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

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

Driving Byteman

- 40 -

• Download Byteman and unzip

• Set BYTEMAN_HOME

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"

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

Quick Start - appmain.btm

- 43 -

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

RULE trace main entry

CLASS MyAppMain

METHOD main

AT ENTRY

IF true

DO traceln("entering main")

ENDRULE

Load Rules at JVM Start

- 44 -

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

org.my.MyAppMain foo bar baz

entering main

foo

bar

baz

$

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

- 46 -

Refer to Byteman Programmer’s Guide

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

- 47 -

Byteman Versions

- 48 -

DEMO

- 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

Thanks iamtedwon@gmail.com

top related