다음에서는 Anyframe Monitoring Tool을 통해 특정 어플리케이션에 대한 모니터링을 수행하기 위해서 필요한 기본 속성과 모니터링 대상에 대한 정의 방법에 대해 살펴보기로 한다.
또한, 모니터링 대상 어플리케이션을 실행시키기 위한 어플리케이션 서버내에 InfraRED Agent 파일이 설치된 후 메모리를 많이 점유하게 되는 문제가 발생할 수 있는데 이를 대처하기 위한 속성 정의 방법에 대해서도 살펴보도록 하자.
모니터링 대상이 되는 어플리케이션은 Anyframe Monitoring Tool과 통신하기 위한 기본 속성 정의를 필요로 한다. 따라서, 이러한 속성 정의를 포함한 Agent Property File (anyframe.tools.monitoring.agent-x.x.x.zip 내에 포함)을 다운로드 한 후, 다음을 참고하여 해당 프로젝트에 맞게 변경하 모니터링 대상 어플리케이션의 WebRoot/WEB-INF/classes 폴더 내에 복사한다.
표 3.1. 모니터링 속성 - #1
| Property | Description | Default Value |
|---|---|---|
| enable-monitoring | 해당 어플리케이션에 대한 모니터링 여부를 정의한다. false일 경우, 어떠한 데이터도 Anyframe Monitoring Tool GUI에서 보이지 않는다. | |
| jdbc-monitoring-enable | 해당 어플리케이션의 JDBC 실행에 대한 모니터링 여부를 정의한다. | false |
| enable-call-tracing | Anyframe Monitoring Tool을 통해 실행 순서대로 기록될 것인지 정의한다. Anyframe Monitoring Tool GUI에서는 실행 순서를 트리 구조로써 보여준다. | false |
| prune-threshold | Anyframe Monitoring Tool이 표현할 수 있는 한계 시간(milliseconds)을 정의한다. 실행 시간이 지정된 milliseconds보다 적을 경우 표현되지 않는다. | 3000 |
| last-invocations-to-trace | Anyframe Monitoring Tool의 Last Invocations 페이지에 표현할 Invocation 개수를 정의한다. | 0 |
| prepared-statement-monitoring-enable | PreparedStatement 표현시 해당 쿼리문의 인자값을 함께 표현할 것인지를 정의한다. | false |
| mbean-server-provider | MBean server provider의 클래스명을 정의한다. 일반적으로 Weblogic server일 경우 net.sf.infrared.weblogic.configmgmt. WLSMBeanServerProvider를, JBoss server일 경우 net.sf.infrared.jboss.configmgmt.JBossMBeanServerProvider로 정의할 수 있다. MBean은 MC4J Management Console과 같은 JMX 기반 툴을 사용하여 속성 정보를 셋팅하는데 사용되며 InfraredProperties MBean은 enable-monitoring, jdbc-monitoring-enable, enable-call-tracing, prune-threshold와 같은 속성 정보를 셋팅할 수 있도록 지원한다. | none |
표 3.2. 모니터링 속성 - #2
| Property | Description | Default Value |
|---|---|---|
| collection-strategy | 수집된 데이터를 표현하기 위한 strategy가 정의된 class명을 정의한다. Anyframe Monitoring Tool은 현재 net.sf.infrared.agent.transport.impl. CentralizedCollectionStrategy만을 추가 지원한다. default로 적용되는 DoNothingCollectionStrategy는, 이름에서 알 수 있듯이 아무것도 수행하지 않는다. | net.sf.infrared.agent. transport.impl. DoNothingCollectionStrategy |
| collection-strategy.ccs.remotehost | Anyframe Monitoring Tool이 실행되는 컴퓨터의 ip를 정의한다. 모니터링 대상 어플리케이션으로부터 수집된 데이터는 Socket을 통해 Collertor에게 flush된다. | localhost |
| collection-strategy.ccs.port | Anyframe Monitoring Tool의 Collector가 listening할 대상 port를 정의한다. | 7777 |
| collection-strategy.ccs.flush-frequency | Remotehost에서 모니터링 대상 어플리케이션의 데이터가 Collector에 flush되는 주기를 정의한다. flush되는 주기값은 양호한 성능을 위해서 최적화될 필요가 있다. 그 값이 클수록 저장할 통계값이 커지고, 이에 따라 더 많은 메모리가 필요할 것이다. 반면에 주기값이 낮으면, 빈번한 network traffic을 유발할 수 있게 된다. | 30000 |
| collection-strategy.ccs.pool | Collector가 flush되기 전에 Thread Pool이 수집된 데이터를 유지할 것인지를 정의한다. | true |
| collection-strategy.ccs.pool. maxThreads | Thread pool에서 허용 가능한 thread의 최대 개수를 정의한다. collection-strategy.ccs.pool 속성이 true일 경우에만 적용할 수 있다. | 1 |
| collection-strategy.ccs.pool.buffer-length | 유지가능한 element의 수를 알려주는 pool buffer의 용량을 정의한다. collection-strategy.ccs.pool 속성이 true일 경우에만 적용할 수 있다. | 100 |
다음은 위에서 언급한 속성을 포함하고 있는 infrared-agent.properties 파일의 내용이다.
# The sample infrared-agent.properties enable-monitoring true enable-call-tracing true jdbc-monitoring-enable true prune-threshold -1 last-invocations-to-trace 5 prepared-statement-monitoring-enable true collection-strategy net.sf.infrared.agent.transport.impl.CentralizedCollectionStrategy collection-strategy.ccs.remotehost localhost collection-strategy.ccs.port 7777 collection-strategy.ccs.pool false collection-strategy.ccs.flush-frequency 3000
Anyframe Monitoring Tool을 이용하여 HTTP Request에 대한 모니터링을 수행하기 위해서는 해당 어플리케이션의 web.xml 파일 내에 HTTP Request에 대한 Listener와 Filter를 등록해 주어야 한다. 다음은 web.xml 파일에 대한 일부 내용이다.
중략...
<listener>
<listener-class>
net.sf.infrared.agent.setup.InfraREDServletContextListener
</listener-class>
</listener>
<filter>
<filter-name>infrared</filter-name>
<filter-class>
net.sf.infrared.aspects.servlet.InfraREDServletFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>infrared</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
중략...위 설정에 의하면 모든 .do로 끝나는 요청은 infrared라는 이름의 Filter를 통해 필터링됨으로써, Anyframe Monitoring Tool을 통해 모든 HTTP Request를 모니터링 할 수 있게 될 것이다.
Anyframe에서는 비즈니스 레이어를 구성하는 서비스에 대한 호출 정보를 모니터링하기 위해 ApiAspect 클래스를 제공한다. 따라서 모니터링 대상 어플리케이션 실행 시 ApiAspect을 적용시키면 비즈니스 서비스 호출 정보를 모니터링할 수 있게 될 것이. 다음은 ApiAspect에 대한 속성 정보를 포함하고 있는 context-monitoring-api.xml 파일의 내용이다.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="anyframe_api_profiler"
class="anyframe.common.aop.aspects.ApiAspect">
<property name="layerName" value="APPLICATION_SERVICE"></property>
</bean>
<bean id="anyframe_api_profiler_aop_autowire"
class="anyframe.common.aop.ExclusiveBeanNameAutoProxyCreator">
<property name="beanNames" value="*Service"/>
<property name="exclusiveBeanNames" value="anyframe_api_profiler"/>
<property name="interceptorNames">
<list>
<value>anyframe_api_profiler</value>
</list>
</property>
</bean>
</beans>
위 속성 정의에 의하면, ApiAspect은 anyframe_api_profiler라는 이름의 Bean으로 정의되어 있다. 그리고, anyframe_api_profiler_aop_autowire라는 이름의 Bean에 의해 Bean 이름이 Service로 끝나는 모든 Bean의 실행시마다 anyframe_api_profiler라는 이름의 Bean을 interceptor로 적용하게 될 것이다. ApiAspect은 layerName이라 속성을 가질 수 있는데 이는 ApiApsect을 통해 모니터링된 결과를 표현하기 위한 레이어의 이름을 정의하는데 사용된다. 또한 ApiAspect는 특정 서비스에 대한 proxy를 통해 해당 메소드를 수행하고 있다. Anyframe에서는 인터페이스를 이용하여 특정 서비스의 Proxy를 생성하므로 ApiAspect를 사용할 경우 대상 서비스는 반드시 인터페이스와 구현 클래스로 구성되어 있어야 함에 유의하도록 한다.
Anyframe에서는 특정 쿼리문에 대한 실행 정보를 모니터링하기 위해 JdbcAspect 클래스를 제공한다. JdbcAspect는 수행되는 쿼리문이나 쿼리문 실행 시간을 체크하기 위한 Aspect이다. 따라서 모니터링 대상 어플리케이션 실행 시 JdbcAspect을 적용시키면 쿼리문 실행 영역을 모니터링할 수 있게 된다. 다음은 JdbcAspect에 대한 속성 정보를 포함하고 있는 context-monitoring-jdbc.xml 파일의 내용이다.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="anyframe_jdbc_profiler"
class="anyframe.common.aop.aspects.JdbcAspect">
</bean>
<bean id="anyframe_jdbc_profiler_aop_autowire"
class="anyframe.common.aop.ExclusiveBeanNameAutoProxyCreator">
<property name="beanNames" value="dataSource"/>
<property name="exclusiveBeanNames" value="anyframe_jdbc_profiler"/>
<property name="interceptorNames">
<list>
<value>anyframe_jdbc_profiler</value>
</list>
</property>
</bean>
</beans>
위 속성 정의에 의하면, JdbcAspect은 anyframe_jdbc_profiler라는 이름의 Bean으로 정의되어 있다. 그리고 anyframe_jdbc_profiler_aop_autowire라는 Bean에 의 Bean 이름이 dataSource인 Bean 실행시마다 anyframe_jdbc_profiler라는 이름의 Bean을 interceptor로 적용하게 될 것이다.
Anyframe Monitoring Tool에서는 InfraRED에서 지원하는 모든 기능(AspectJ 기반 Aspect 적용, AspectsWerks 기반 Aspect 적용 등)에 대해서 검증을 수행한 것은 아니므로 위에서 언급한 대로 사용할 것을 권장한다.
최초 Monitoring 서버를 실행시키면 User Home 디렉토리 하위에 .infrared/infrared-db.properties 설정 파일이 생성된다. (예를 들어 Windows의 경우, Anyframe Monitoring Tool을 시작하면 C:\document and settings\사용자명\.infrared 폴더 하위에 이 설정파일이 자동으로 생성된다.) Anyframe Monitoring Tool은 HSQL DB만을 지원하고 있으며 기본 설정을 그대로 사용히면 모니터링 데이터가 대량으로 발생하는 경우 서버에서 memory overflow가 발생할 수 있다. 이를 방지하기 위해 infrared-db.properties를 다음과 같이 변경한 후 서버를 재시작한다.
#HSQL Database Engine hsqldb.script_format=0 #기본적으로는 값을 설정하지 않으나 메모리 문제가 있는 사이트에서는 #이와 같이 gc 주기를 줄수 있음(단위 ms) runtime.gc_interval=60000 sql.enforce_strict_size=false #1kb 하나의 레코드의 평균 크기 2^10 = 1024 bytes #(프로젝트 상황에 맞게 설정, default 10 권장) hsqldb.cache_size_scale=10 #기본값 권장 readonly=false #기본값 권장 (JDK가 NIO를 지원지 않으면 false 로 설정) hsqldb.nio_data_file=true #4k rows 메모리에 캐쉬할 레코드 갯수 #(14의 의미 : 2^14개, 클 수록 성능은 좋아지나, 메모리 많이 점유함) hsqldb.cache_scale=14 version=1.8.0 #테이블 정보를 메모리에 저장할지 디스크에 저장할지 여부 결정? #(default 가 me기본 Memory로 되어 있으나 서버 메모리 Full나므로 Cache로 설정) hsqldb.default_table_type=cached #8gb db 정보를 디스크 캐쉬에 저장할 사이즈 #(8기가 <-- 상황에 맞게 설정) hsqldb.cache_file_scale=8 sql.compare_in_locale=false hsqldb.log_size=200 #hsql 로그 사이즈 (기본값 유지) modified=yes hsqldb.cache_version=1.7.0 hsqldb.original_version=1.8.0 hsqldb.compatible_version=1.8.0