[Using GCP] Stackdriver Third-party Appication Monitoring (8.Tomcat)

글쓴이 : 윤성재 (공작명왕)
E-mail : <gongjak@gmail.com>
Facebook : < https://www.facebook.com/sungjae.yun >

Tomcat Monitoring

1.Tomcat 설치와 시작

< Debian 8 >

sudo apt-get install tomcat7

< CentOS 7 >

sudo yum install tomcat
sudo systemctl start tomcat

2.사전 준비

JMX 모니터링을 사용하기 위해 catalina-jmx-remote.jar 파일을 설치해줘야 하는데, Debian 8 은 tomcat7을 설치하면 함께 설치가 되나 CentOS 7 은 직접 설치해줘야 한다.

< Debian 8 >

다음 내용으로 /usr/share/tomcat7/bin/setenv.sh 파일을 만든다.

sudo vi /usr/share/tomcat7/bin/setenv.sh
#!/bin/sh
JMX_OPTS=" -Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Djava.rmi.server.hostname=localhost \
-Dcom.sun.management.jmxremote.ssl=false "
CATALINA_OPTS=" ${JMX_OPTS} ${CATALINA_OPTS}"

/etc/tomcat7/server.xml 파일을 열고 Server 항목에 다음 Listener를 추가한다.

<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener"
rmiRegistryPortPlatform="9012" rmiServerPortPlatform="9013"/>

Tomcat을 재기동하고, 9012 포트가 열렸는지 확인한다.

sudo service tomcat7 restart
netstat -na | grep 9012

< CentOS 7 >

JMX 모니터링을 위한 jar 파일이 기본 패키지에 포함되어 있지 않으니 톰캣 다운로드 사이트 (http://tomcat.apache.org/download-70.cgi) 에서 최신버전을 다운로드 받아야 한다.

JMX_Remote.jar Download :

cd /usr/share/tomcat/lib && sudo wget http://apache.mirror.cdnetworks.com/tomcat/tomcat-7/v7.0.70/bin/extras/catalina-jmx-remote.jar

tomcat 실행 파일을 열어 if 문 앞(15번행)에 다음 내용을 추가한다.

/usr/libexec/tomcat/server

JMX_OPTS=" -Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Djava.rmi.server.hostname=localhost \
-Dcom.sun.management.jmxremote.ssl=false "
OPTIONS=" ${JMX_OPTS} ${OPTIONS}"

/etc/tomcat/server.xml 파일을 열고 Server 항목에 다음 Listener를 추가한다.

<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener"
rmiRegistryPortPlatform="9012" rmiServerPortPlatform="9013"/>

Tomcat을 재기동하고, 9012 포트가 열렸는지 확인한다.

sudo systemctl restart tomcat
netstat -na | grep 9012

3.Plugin 설치

cd /opt/stackdriver/collectd/etc/collectd.d/ && sudo curl -O https://raw.githubusercontent.com/Stackdriver/stackdriver-agent-service-configs/master/etc/collectd.d/tomcat-7.conf

4.Stackdriver Agent 재시작

< Debian 8 >

sudo service stackdriver-agent restart

< CentOS 7 >

sudo systemctl restart stackdriver-agent

5.Monitoring 확인

Monitoring -> Resources -> Instances

각 서버를 클릭해보자. stackdriver agent가 plugin이 정상으로 동작하여 정보를 제대로 가져온다면 Monitoring의 오른쪽 그래프 윗부분에서 다음과 같은 화면을 볼 수 있다.

Tomcat 은 JVM 기반으로 동작하기에 친절한 Stackdriver는 JVM 모니터링까지 함께 할 수 있게 자료를 수집해서 보여준다.

stackdriver-2-image11

[ 출처: Flickr, gongjak1 ]

6.현재 모니터링 가능한 항목

Tomcat

  • Threads: Total and busy threads in the Tomcat process.
  • Requests: The number of completed and error requests that took place.
  • Sessions: How many sessions are active in Tomcat.

JVM

  • Active JVM Threads
  • JVM Heap memory usage
  • JVM Non-Heap memory usage
  • JVM Open File Descriptors
  • JVM Garbage Collection Count

Plugin 설정을 마치며…

Stackdriver 라는 도구가 GCP 에 추가되어 들어오고나서 각 인스턴스들에 대해 좀 더 세밀한 모니터링이 가능하게 되었다. 서비스 구성에서 필수적으로 사용해야할 각 종 Application 들의 모니터링까지 쉽게 설정할 수 있게 되어 시스템 운영자들의 필수 과제인 “모니터링과 알람” 에 대한 1차 문제를 해결할 수 있게 되었는데, 이 중 모니터링에 대한 부분만을 해결 하였다.
그런데 아직도 남은 숙제가 있어 보인다.
바로 각 서비스에서 개발자들이 남기는 User-Defined Log 들에 대한 모니터링이다.
다음에는 이 로그들에 대한 모니터링 방법과 이렇게 모인 Metric을 이용해서 어떻게 알람을 설정할 수 있는지 알아보도록 하겠다.

답글 남기기

아래 항목을 채우거나 오른쪽 아이콘 중 하나를 클릭하여 로그 인 하세요:

WordPress.com 로고

WordPress.com의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

Facebook 사진

Facebook의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

%s에 연결하는 중

%d 블로거가 이것을 좋아합니다: