Cluster 된 개별 WAS들이 모두 정상적으로 가동되고 있는지 모니터링 화면에서 표현해보자.
기준은 각 WAS의 Memory MBean 정보를 활용해서 WAS가 정상적인지도 체크 하고, 현재 Memory 상황은 어떤지 파악도 함께 할 수 있게 해본다.
[각각의 WAS Agent] -> vertx Net-> [모니터링 서버] -> vertx SockJs -> [Client Broswer] 방향으로 Memory 정보를 보낸다.
장애판단 기준은 WAS Agent에서 현재 5초 기준으로 모니터링 서버쪽으로 보내주고 있다.
그에 따라 Client Borswer 부분에서는 해당 정보가 (5초*1.5) 이후에도 정보가 오지 않으면 서버가 내려갔다고 판단한다.
또한 이 정보를 DB화 하여, Memory 증가량을 파악하고, GC 이후에도 Memory 가 부족하지는 않은지 판단해본다.
[MonitorAgent.java]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import java.lang.instrument.Instrumentation; import java.util.Timer; import pe.kr.ddakker.monitor.agent.timer.MBeanTimer; public class MonitorAgent { Timer timer = new Timer( "ddakker Agent Timer" , true ); Instrumentation instrumentation; static MonitorAgent monitorAgent; public static boolean isDebug = false ; public static void premain(String args, Instrumentation instrumentation) throws Exception { //instrumentation.addTransformer(new TomcatTransformer()); monitorAgent = new MonitorAgent(instrumentation); monitorAgent.start(); } public final void start( boolean isRequest, boolean isMBean) { MBeanTimer mBeanTimer = new MBeanTimer(); timer.scheduleAtFixedRate(mBeanTimer, 5000 , 5000 ); } } |
[MBeanTimer.java]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import java.lang.management.ManagementFactory; import java.util.TimerTask; import javax.management.MBeanServer; import javax.management.ObjectName; import javax.management.openmbean.CompositeData; import pe.kr.ddakker.monitor.agent.send.VertxClient; public class MBeanTimer extends TimerTask { public void run() { try { ObjectName om = new ObjectName( "java.lang:type=Memory" ); MBeanServer connection = ManagementFactory.getPlatformMBeanServer(); Object attrValue = connection.getAttribute(om, "HeapMemoryUsage" ); long max = Long.parseLong(((CompositeData)attrValue).get( "max" ).toString()); long used = Long.parseLong(((CompositeData)attrValue).get( "used" ).toString()); long heapUsedPercent = Math.round((used* 1.0 / max* 1.0 ) * 100.0 ); String msg = "{name: '" + System.getProperty( "jvmRoute" ) + "', heapUsedPercent: '" + heapUsedPercent + "', time: '" + System.currentTimeMillis() + "'}" ; msg = "{result: '0000', grp: 'grp_was', msg: '성공', data: " + msg + "}" ; VertxClient.send(msg); } catch (Exception e) { System.err.println(); } } } |