JMX 알림을 사용하여 애플리케이션 로깅 모니터링

Java 개발자는 JMX 알림을 사용하여 애플리케이션 서버 로그를 모니터하는 프로그램을 작성할 수 있습니다.

이 태스크 정보

가장 공통된 로그 메시지 리스너는 Java로 작성되며 SOAP를 사용하여 애플리케이션 서버 또는 배치 관리자에 연결합니다. 이 주제를 사용하여 로그 이벤트에 대해 청취하는 Java 클라이언트를 빌드하십시오.
참고: 이 주제는 하나 이상의 애플리케이션 서버 로그 파일을 참조합니다. 권장되는 대안은 분배 및 IBM® i 시스템에서 SystemOut.log, SystemErr.log, trace.logactivity.log 파일을 사용하는 대신 HPEL(High Performance Extensible Logging) 로그를 사용하고 인프라를 추적하도록 서버를 구성하는 것입니다. 원시 z/OS® 로깅 기능과 연계하여 HPEL을 사용할 수도 있습니다. HPEL을 사용하는 경우 서버 프로파일 바이너리 디렉토리의 LogViewer 명령행 도구를 사용하여 모든 로그에 액세스하고 정보를 추적할 수 있습니다. HPEL 사용에 대한 자세한 정보는 HPEL을 사용한 애플리케이션 문제점 해결 정보를 참조하십시오.
문제점 방지 문제점 방지: JMX 알림이 서버 속도를 늦출 수 있으므로 로깅 볼륨이 높은 서버에 리스너를 추가할 때 주의하십시오. gotcha

프로시저

  1. 필요한 패키지를 가져오십시오. Java 프로그램 시작 시 일반적으로 다음 import 문이 필요합니다.
    import javax.management.Notification;
    import javax.management.NotificationListener;
    import javax.management.ObjectName;
    import javax.management.InstanceNotFoundException;
    import javax.management.MalformedObjectNameException;
    
    import com.ibm.websphere.management.AdminClient;
    import com.ibm.websphere.management.AdminClientFactory;
    import com.ibm.websphere.management.exception.ConnectorException;
    또한 메시지와 후속 단계의 셀에서 리턴된 유형을 처리하려면 다음 import 문이 필요합니다.
    import java.util.Iterator;
    import java.util.Properties; 
    import java.util.Set;
    import com.ibm.websphere.ras.RasMessage; 
  2. NotificationListener 인터페이스를 구현하는 Java 클래스를 작성하십시오.
  3. handleNotification 메소드를 구현하십시오. 다음 예제는 Java 콘솔에 메시지 텍스트를 쓰는 샘플입니다.
    public void handleNotification(Notification notification, Object handback) {
            RasMessage rasMessage = (RasMessage)notification.getUserData() ;
            System.out.println("Localized message: " + rasMessage.getLocalizedMessage(null));
    }
  4. JMX MBean을 모니터하려는 서버의 SOAP 포트에 연결하십시오. 다음 코드는 지정된 호스트 및 지정된 포트를 사용하여 SOAP에 연결된 AdminClient 오브젝트를 작성합니다.
            AdminClient adminClient = null ;
            String hostName = "someHostName";
            String soapPort = "8880";
    
            Properties connectProps = new Properties();
            connectProps.setProperty(AdminClient.CONNECTOR_TYPE, "SOAP");
            connectProps.setProperty(AdminClient.CONNECTOR_HOST, hostName);
            connectProps.setProperty(AdminClient.CONNECTOR_PORT, soapPort);
    
            try {
                adminClient = AdminClientFactory.createAdminClient(connectProps);
            } catch (ConnectorException e) {
                // error handling code
            } 
  5. RasLoggingService MBean에 대한 MBean 오브젝트 이름을 검색하십시오. 다음 코드는 RasLoggingService MBean 오브젝트 이름을 검색합니다.
            String queryString = "WebSphere:cell="+cellName+",node="+nodeName+",process="+serverName+",
    type=RasLoggingService,*" ;
            Set<ObjectName> objectMBeans = null;
            try {
                ObjectName queryName = new ObjectName(queryString);
                objectMBeans = (Set<ObjectName>)adminClient.queryNames(queryName, null);
                if (objectMBeans.size() > 1) {
                    // error handling code to deal with the case where we get more than one name returned.
                }
            } catch (MalformedObjectNameException e) {
                // error handling code
            } catch (ConnectorException e) {
                // error handling code
            }
    
            if (objectMBeans.isEmpty()) {
                // error handling code to deal with the case where the MBean is not found
            }
    
            Iterator<ObjectName> objectNames = objectMBeans.iterator() ;
            ObjectName objectName = objectNames.next() ; 
  6. 알림 리스너를 추가하십시오. 이 샘플 코드는 알림 리스너를 추가하고 알림을 처리하는 동안 60초간 대기한 후 알림 리스너를 제거합니다. 필요한 동안은 리스너가 연결될 수 있습니다.
            try {
                adminClient.addNotificationListener(objectName, this, null, null);
                Thread.sleep(60 * 1000) ;
                adminClient.removeNotificationListener(objectName, this) ;
            } catch (InstanceNotFoundException e) {
                // error handling code
            } catch (ConnectorException e) {
                // error handling code
            } catch (Exception e) {
                // error handling code
            }
  7. 클래스 경로에 필요한 jar를 추가하십시오. 관리 클라이언트 jar 파일을 클래스 경로에 추가하여 코드를 컴파일하고 실행할 수 있습니다. 관리 클라이언트 jar 파일은 <install_root>/runtimes 디렉토리에 있습니다.

결과

청취할 수 있는 Java 프로그램을 작성했으며, 애플리케이션 서버에서 로그 이벤트 알림의 결과로 조치를 수행합니다.

주제 유형을 표시하는 아이콘 태스크 주제



시간소인 아이콘 마지막 업데이트 날짜: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=ttrb_HPELNotification
파일 이름:ttrb_HPELNotification.html