Configuration

다음에서는 Anyframe Monitoring Tool을 통해 특정 어플리케이션에 대한 모니터링을 수행하기 위해서 필요한 기본 속성과 모니터링 대상에 대한 정의 방법에 대해 살펴보기로 한다. 또한, 어플리케이션 서버내에 InfraRED Agent 파일이 설치된 후 메모리를 많이 점유하게 되는 문제가 발생할 수 있는데 이를 대처하기 위한 속성 정의 방법에 대해서도 살펴볼 것이다.

모니터링 속성 정의

모니터링 대상이 되는 어플리케이션은 Anyframe Monitoring Tool과 통신하기 위한 기본 속성 정의를 필요로 한다. 따라서, 이러한 속성 정의를 포함한 infrared-agent.properties 파일(anyframe.tools.monitoring-agent-x.x.x.zip 내에 포함)을 다운로드 한 후, 다음을 참고하여 해당 프로젝트에 맞게 변경하여 모니터링 대상 어플리케이션의 WebRoot/WEB-INF/classes 폴더 내에 복사한다.
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)을 정의한다. 수행시간은 Anyframe Monitoring Tool을 통해 ms보다 더 작은 값으로 줄어든다. 3000
last-invocations-to-trace Anyframe Monitoring Tool GUI의 Last Invocations 페이지에 표현될 Invocation 개수를 정의한다. 0
prepared-statement-monitoring-enable PreparedStatement 처리시 해당 쿼리문의 인자값을 표현할 것인지를 정의한다. false
mbean-server-provider MBean server provider의 클래스명을 정의한다. Weblogic server의 net.sf.infrared.weblogic.configmgmt.WLSMBeanServerProvider와 net.sf.infrared.jboss.configmgmt가 보통이며, JBoss server에는 JBossMBeanServerProvider가 있다. Anyframe Monitoring Tool MBean은 MC4K Management Console과 같은 JMX 기반의 툴을 사용하여 설정할 수 있다. 이 MBean은 다음과 같은 속성들을 attribute로 노출하고 있다. : enable-monitoring, jdbc-monitoring-enable, enable-call-tracing, prune-threshold none
collection-strategy 수집된 데이터를 표현하기 위한 strategy가 정의된 class명을 정의한다. Anyframe Monitoring Tool은 현재 CentralizedCollectionStrategy, 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을 통해 Anyframe Monitoring Tool의 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
			

모니터링 대상 정의

HTTP Request 모니터링

HTTP Request에 대한 모니터링을 수행하기 위해서는 해당 어플리케이션의 web.xml 파일 내에 HTTP Request에 대한 Listener와 Filter를 등록해 주어야 한다. 다음은 WEB-INF/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 Core에서는 비즈니스 레이어를 구성하는 서비스의 호출 정보를 모니터링하기 위해 ApiAspect 클래스를 제공한다. 따라서 모니터링 대상 어플리케이션 실행 시 ApiAspect을 적용시키면 비즈니스 서비스 호출 정보를 모니터링할 수 있게 된다. 다음은 ApiAspect에 대한 속성 정보를 포함하고 있는 context-monitoring.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으로 정의되어 있다. 또한, Bean 이름이 Service로 끝나는 모든 Bean 인스턴스의 실행에 대해 anyframe_api_profiler라는 이름의 Bean을 interceptor로 적용하게 될 것이다. ApiAspect은 layerName 속성을 가질 수 있는데 이는 Anyframe Monitoring Tool에 의해 ApiApsect을 통해 모니터링된 결과를 표현하기 위한 레이어 이름을 정의하는데 사용된다.
ApiAspect는 특정 서비스에 대한 proxy를 통해 메소드를 수행하고 있다. Anyframe Core에서는 특정 서비스의 Proxy를 생성할 때, 해당 서비스의 인터페이스를 이용하기 때문에, ApiAspect를 사용할 경우 대상 서비스는 반드시 인터페이스와 구현 클래스로 구성되어 있어야 함에 유의하도록 한다.

쿼리문 실행 모니터링

Anyframe Core에서는 쿼리문 실행 정보를 모니터링하기 위해 JdbcAspect 클래스를 제공한다. JdbcAspect는 수행되는 쿼리문이나 쿼리문 실행시간을 체크하기 위해 DB 연결을 핸들링하기 위한 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으로 정의되어 있다. 또한, Bean 이름이 dataSource인 Bean 인스턴스의 실행에 대해 anyframe_jdbc_profiler라는 이름의 Bean을 interceptor로 적용하게 될 것이다.

* Anyframe Monitoring Tool에서는 InfraRED에서 지원하는 모든 기능(AspectJ 기반 Aspect 적용, AspectsWerks 기반 Aspect 적용 등) 에 대해서 검증을 수행한 것은 아니므로 위에서 언급한 대로 사용할 것을 권장한다.

Memory Leak 해결 방법

어플리케이션 서버내에 InfraRED agent 파일이 설치가 되면 ThreadPool에 존재하는 스레드에 statisticsCollector가 바인딩 되면서 실제 스레드 종료시 statisticsCollector가 garbage collection이 되지 않고 pool속으로 들어가기 때문에 Memery Leak이 발생한다. 그렇게 되면 pool내의 스레드 갯수가 많아지면서 메모리를 많이 점유하게 되는 문제가 발생할 수 있다.
이러한 경우 다음과 같이 infrared-db.properties 파일에 대한 속성 수정이 필요하다. Windows의 경우, Anyframe Monitoring Tool을 시작하면 C:\document and settings\사용자명\.infrared 폴더가 자동으로 생성된다. 이 폴더 내에 존재하는 infrared-db.properties 를 다음과 같이 변경하고 서버를 재시작 시키면 된다.
#HSQL Database Engine
#Thu Mar 12 13:30:09 KST 2009
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 #기본값 권장
hsqldb.nio_data_file=true #기본값 권장 (JDK가 NIO를 지원지 않으면 false 로 설정)
#4k rows 메모리에 캐쉬할 레코드 갯수 (14의 의미 : 2^14개, 클 수록 성능은 좋아지나, 메모리 많이 점유함)
hsqldb.cache_scale=14 
version=1.8.0 
#테이블 정보를 메모리에 저장할지 디스크에 저장할지 여부 결정? 
#(기본 Memory로 되어 있으나 서버 메모리 Full나므로 Cache로 설정)
hsqldb.default_table_type=cached 
hsqldb.cache_file_scale=8 #8gb db 정보를 디스크 캐쉬에 저장할 사이즈 (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