Tomcat

Supported OS Linux Windows Mac OS

통합 버전4.0.0

Tomcat 대시보드

개요

이 점검은 Tomcat 메트릭을 수집합니다. 예:

  • 전체 활동 메트릭: 오류 수, 요청 수, 처리 시간 등
  • 스레드 풀 메트릭: 스레드 수, 사용 중인 스레드 수 등
  • Sevlet 처리 시간

설정

설치

Tomcat 점검은 [Datadog Agent2] 패키지에 포함되어 있으므로 Tomcat 서버에 아무 것도 설치할 필요가 없습니다.

이 점검은 JMX 기반이므로, Tomcat 서버에서 JMX Remote를 활성화해야 합니다. Tomcat 모니터링 및 관리의 지침을 따릅니다.

구성

호스트

호스트에서 실행 중인 에이전트에 대해 이 점검을 구성하려면:

  1. tomcat.d/conf.yaml 파일을 Agent 설정 디렉터리 루트에 있는 conf.d/ 폴더에서 수정하여 Tomcat 메트릭과 로그를 수집하세요. 사용 가능한 모든 설정 옵션은 샘플 tomcat.d/conf.yaml에서 확인할 수 있습니다.

  2. 에이전트를 재시작하세요.

모든 JMX 기반 점검에서 사용할 수 있는 구성 옵션 목록은 JMX 점검 설명서를 참조하세요.

메트릭 목록

conf 파라미터는 연동에서 수집할 지표의 목록입니다. 두 개의 키만 허용됩니다.

  • include (필수): 필터 사전입니다. 이 필터와 일치하는 모든 속성은 exclude 필터와도 일치하지 않는 한 수집됩니다(아래 참조).
  • exclude (옵션): 필터 사전입니다. 이 필터와 일치하는 속성은 수집되지 않습니다.

주어진 bean에 메트릭은 다음과 같은 방식으로 태그가 지정됩니다.

mydomain:attr0=val0,attr1=val1

이 예제에서 메트릭은 mydomain (또는 bean 내부의 속성에 따라 일부 변형)이며 attr0:val0, attr1:val1, domain:mydomain 태그가 있습니다.

include 키에 카멜(camel) 케이스 형식의 별칭을 지정하면 _스네이크(snake) 케이스_로 변환됩니다. 예를 들어 MyMetricName는 Datadog에서 my_metric_name로 표시됩니다.

속성 필터

attribute 필터는 다음 두 가지 유형의 값을 허용합니다.

  • 키가 속성 이름인 사전입니다(아래 참조). 이 경우 Datadog에서 메트릭의 별칭을 지정해 메트릭 이름으로 사용할 수 있습니다. 메트릭 유형을 게이지 또는 카운터로 지정할 수도 있습니다. 카운터를 선택하면 해당 메트릭의 초당 비율이 계산됩니다.

    conf:
      - include:
        attribute:
          maxThreads:
            alias: tomcat.threads.max
            metric_type: gauge
          currentThreadCount:
            alias: tomcat.threads.count
            metric_type: gauge
          bytesReceived:
            alias: tomcat.bytes_rcvd
            metric_type: counter
    
  • 속성 이름 목록입니다(아래 참조). 이 경우 메트릭 유형은 게이지이고 메트릭 이름은 jmx.\[DOMAIN_NAME].\[ATTRIBUTE_NAME]입니다.

    conf:
      - include:
        domain: org.apache.cassandra.db
        attribute:
          - BloomFilterDiskSpaceUsed
          - BloomFilterFalsePositives
          - BloomFilterFalseRatio
          - Capacity
          - CompressionRatio
          - CompletedTasks
          - ExceptionCount
          - Hits
          - RecentHitRate
    

로그 수집

  1. Datadog에 로그를 제출하려면 Tomcat은 log4j 로거를 사용합니다. 8.0 이전 버전의 Tomcat의 경우 log4j가 기본적으로 구성됩니다. Tomcat 8.0 이상의 경우 log4j를 사용하도록 Tomcat을 구성해야 합니다(Log4j 사용하기 참조). 해당 지침의 첫 번째 단계에서 $CATALINA_BASE/lib 디렉터리에 있는 log4j.properties 파일을 다음과 같이 편집합니다.

      log4j.rootLogger = INFO, CATALINA
    
      # Define all the appenders
      log4j.appender.CATALINA = org.apache.log4j.DailyRollingFileAppender
      log4j.appender.CATALINA.File = /var/log/tomcat/catalina.log
      log4j.appender.CATALINA.Append = true
    
      # Roll-over the log once per day
      log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout
      log4j.appender.CATALINA.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - %m%n
    
      log4j.appender.LOCALHOST = org.apache.log4j.DailyRollingFileAppender
      log4j.appender.LOCALHOST.File = /var/log/tomcat/localhost.log
      log4j.appender.LOCALHOST.Append = true
      log4j.appender.LOCALHOST.layout = org.apache.log4j.PatternLayout
      log4j.appender.LOCALHOST.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - %m%n
    
      log4j.appender.MANAGER = org.apache.log4j.DailyRollingFileAppender
      log4j.appender.MANAGER.File = /var/log/tomcat/manager.log
      log4j.appender.MANAGER.Append = true
      log4j.appender.MANAGER.layout = org.apache.log4j.PatternLayout
      log4j.appender.MANAGER.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - %m%n
    
      log4j.appender.HOST-MANAGER = org.apache.log4j.DailyRollingFileAppender
      log4j.appender.HOST-MANAGER.File = /var/log/tomcat/host-manager.log
      log4j.appender.HOST-MANAGER.Append = true
      log4j.appender.HOST-MANAGER.layout = org.apache.log4j.PatternLayout
      log4j.appender.HOST-MANAGER.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - %m%n
    
      log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender
      log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout
      log4j.appender.CONSOLE.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - %m%n
    
      # Configure which loggers log to which appenders
      log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost] = INFO, LOCALHOST
      log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager] =\
        INFO, MANAGER
      log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager] =\
        INFO, HOST-MANAGER
    

    그런 다음 Tomcat 설명서의 나머지 단계에 따라 log4j를 구성합니다.

  2. 기본적으로 Datadog 통합 파이프라인은 다음과 같은 전환 패턴을 지원합니다.

      %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
      %d [%t] %-5p %c - %m%n
    

    다른 형식이 있는 경우 통합 파이프라인을 복제하여 편집하세요. Tomcat 로깅 기능에 대한 자세한 내용은 Tomcat에서 로깅하기를 참조하세요.

  3. Datadog 에이전트에서 로그 수집은 기본적으로 사용하지 않도록 설정되어 있습니다. datadog.yaml파일에서 로그 수집을 사용하도록 설정합니다.

    logs_enabled: true
    
  4. 이 구성 블록을 tomcat.d/conf.yaml 파일에 추가하여 Tomcat 로그 수집을 시작하세요.

    logs:
      - type: file
        path: /var/log/tomcat/*.log
        source: tomcat
        service: "<SERVICE>"
        #To handle multi line that starts with yyyy-mm-dd use the following pattern
        #log_processing_rules:
        #  - type: multi_line
        #    name: log_start_with_date
        #    pattern: \d{4}\-(0?[1-9]|1[012])\-(0?[1-9]|[12][0-9]|3[01])
    

    pathservice 파라미터 값을 변경하고 사용자 환경에 맞게 구성합니다. 사용 가능한 모든 구성 옵션은 샘플 tomcat.yaml을 참조하세요.

  5. 에이전트를 재시작하세요.

컨테이너화

컨테이너화된 환경의 경우 JMX를 사용한 자동탐지 가이드를 참조하세요.

검증

Agent 상태 하위 명령을 실행하고 Checks 섹션에서 tomcat을 찾습니다.

수집한 데이터

메트릭

tomcat.bytes_rcvd
(gauge)
Bytes per second received by all request processors.
Shown as byte
tomcat.bytes_sent
(gauge)
Bytes per second sent by all the request processors.
Shown as byte
tomcat.error_count
(gauge)
The number of errors per second on all request processors.
Shown as error
tomcat.jdbc.connection_pool.active
(gauge)
The number of established connections in the pool that are in use.
tomcat.jdbc.connection_pool.idle
(gauge)
The number of established connections in the pool that are idle.
tomcat.jdbc.connection_pool.max_active
(gauge)
The maximum number of open connections.
tomcat.jdbc.connection_pool.max_idle
(gauge)
The maximum number of idle connections.
tomcat.jdbc.connection_pool.min_idle
(gauge)
The minimum number of idle connections.
tomcat.jdbc.connection_pool.size
(gauge)
The number of established connections in the pool, idle and in use.
tomcat.jsp.count
(gauge)
The number of JSPs per second that have been loaded in the web module.
Shown as page
tomcat.jsp.reload_count
(gauge)
The number of JSPs per second that have been reloaded in the web module.
Shown as page
tomcat.max_time
(gauge)
The longest request processing time (in milliseconds).
Shown as millisecond
tomcat.min_time
(gauge)
The shortest request processing time (in milliseconds).
Shown as millisecond
tomcat.processing_time
(gauge)
The sum of request processing times across all requests handled by the request processors (in milliseconds) per second.
tomcat.request_count
(gauge)
The number of requests per second across all request processors.
Shown as request
tomcat.servlet.error_count
(gauge)
The number of erroneous requests received by the servlet per second.
Shown as error
tomcat.servlet.max_time
(gauge)
The maximum processing time of a request
Shown as millisecond
tomcat.servlet.min_time
(gauge)
The minimum processing time of a request
Shown as millisecond
tomcat.servlet.processing_time
(gauge)
The sum of request processing times across all requests to the servlet (in milliseconds) per second.
tomcat.servlet.request_count
(gauge)
The number of requests received by the servlet per second.
Shown as request
tomcat.string_cache.access_count
(gauge)
The number of accesses to the string cache per second.
Shown as get
tomcat.string_cache.cache_size
(gauge)
The size of the String cache
Shown as byte
tomcat.string_cache.hit_count
(gauge)
The number of string cache hits per second.
Shown as hit
tomcat.string_cache.max_size
(gauge)
The maximum size of the String cache
Shown as byte
tomcat.threads.busy
(gauge)
The number of threads that are in use.
Shown as thread
tomcat.threads.count
(gauge)
The number of threads managed by the thread pool.
Shown as thread
tomcat.threads.max
(gauge)
The maximum number of allowed worker threads.
Shown as thread
tomcat.threads.min
(gauge)
The minimum number of allowed worker threads.
Shown as thread
tomcat.web.cache.hit_count
(gauge)
The number of web resource cache hits per second.
Shown as hit
tomcat.web.cache.lookup_count
(gauge)
The number of lookups to the web resource cache per second.
Shown as get

이벤트

Tomcat 점검에는 이벤트가 포함되지 않습니다.

서비스 점검

tomcat.can_connect

Returns CRITICAL if the Agent is unable to connect to and collect metrics from the monitored Tomcat instance, WARNING if no metrics are collected, and OK otherwise.

Statuses: ok, critical, warning

트러블슈팅

누락된 tomcat.* 메트릭

Datadog Agent는 Datadog Agent 버전 7.49.0 이상에서 Catalina 또는 Tomcat을 빈 도메인 이름으로 사용하여 JMX 메트릭을 수집합니다. 이전 버전에서는 Catalina를 빈 도메인 이름으로 사용하는 메트릭만 수집했습니다. 독립 실행형 Tomcat 배포에는 Catalina 도메인에 메트릭이 포함되지만, 임베디드 Tomcat 배포(예: Spring Boot)에는 Tomcat 도메인에 메트릭이 포함됩니다.

버전이 7.49.0보다 오래된 경우 및 Datadog Agent 버전이 7.49.0보다 이전 버전이고 노출된 Tomcat 메트릭에 Tomcat가 같은 다른 빈 도메인 이름이 접두사로 붙은 경우, metrics.yaml 파일의 기본 메트릭을 tomcat.d/conf.yaml 파일의 conf 섹션으로 복사하고 해당 빈 도메인 이름을 사용하도록 domain 필터를 수정합니다.

- include:
    domain: Tomcat
    type: ThreadPool
    attribute:
      maxThreads:
        alias: tomcat.threads.max
        metric_type: gauge
      currentThreadCount:
        alias: tomcat.threads.count
        metric_type: gauge
      currentThreadsBusy:
        alias: tomcat.threads.busy
        metric_type: gauge

자세한 내용은 JMX 점검 설명서를 참조하세요.

사용 가능한 메트릭을 보기 위한 명령

datadog-agent jmx 명령을 사용하면 JMXFetch 통합에서 트러블슈팅 명령을 실행할 수 있습니다. Linux 시스템에서는 명령 앞에 sudo -u dd-agent를 추가해 Datadog Agent가 올바른 사용자로 실행되도록 해야 합니다.

datadog-agent jmx collect

datadog-agent jmx collect를 실행하면 현재 구성에 따라 메트릭 수집이 시작되고 콘솔에 표시됩니다.

datadog-agent jmx list

datadog-agent jmx list에는 사용 가능한 여러 하위 명령이 있습니다.

  • collected - 현재 인스턴스의 구성으로 실제로 수집되는 속성을 나열합니다.
  • everything - JMXFetch에서 지원하는 유형이 있는 사용 가능한 모든 속성을 나열합니다.
  • limited - 인스턴스의 구성 중 하나와 일치하지만 수집할 수 있는 메트릭 수를 초과하여 수집되지 않는 속성을 나열합니다.
  • matching - 인스턴스의 구성 중 하나 이상과 일치하는 속성을 나열합니다.
  • not-matching - 인스턴스의 구성과 일치하지 않는 속성을 나열합니다.
  • with-metrics - 인스턴스의 구성 중 하나 이상과 일치하는 속성 및 메트릭 데이터를 나열합니다.
  • with-rate-metrics - 요금 및 카운터를 포함하여 인스턴스의 구성 중 하나 이상과 일치하는 속성 및 메트릭 데이터를 나열합니다.

참고 자료

기타 유용한 문서, 링크 및 기사: