Supported OS Linux Windows Mac OS

インテグレーションバージョン1.11.2

Tomcat ダッシュボード

概要

このチェックは、次のような Tomcat メトリクスを収集します。

  • 全体的なアクティビティメトリクス: エラー数、リクエスト数、処理時間など
  • スレッドプールメトリクス: スレッド数、ビジースレッド数など
  • サーブレット処理時間

セットアップ

インストール

Tomcat チェックは Datadog Agent パッケージに含まれています。Tomcat サーバーに追加でインストールする必要はありません。

このチェックは JMX ベースなので、Tomcat サーバーで JMX リモートを有効にする必要があります。この方法については、Tomcat の監視と管理の手順に従ってください。

コンフィギュレーション

ホスト

ホストで実行中の Agent に対してこのチェックを構成するには:

  1. Tomcat のメトリクスとログを収集するには、Agent のコンフィギュレーションディレクトリのルートにある conf.d/ フォルダーの tomcat.d/conf.yaml ファイルを編集します。使用可能なすべてのコンフィギュレーションオプションについては、tomcat.d/conf.yaml のサンプルを参照してください。

  2. Agent を再起動します

JMX ベースのすべてのチェックで使用可能なコンフィギュレーションオプションのリストについては、JMX チェックに関するドキュメントを参照してください。

メトリクスのリスト

conf パラメーターは、インテグレーションによって収集されるメトリクスのリストです。次の 2 つのキーのみが許可されます。

  • include (必須): フィルターの辞書。これらのフィルターに一致する属性は、exclude フィルターにも一致している場合を除き、収集されます (以下を参照)。
  • exclude (任意): フィルターの辞書。これらのフィルターに一致する属性は収集されません。

特定の Bean に対して、メトリクスは次のようにタグ付けされます。

mydomain:attr0=val0,attr1=val1

この例では、メトリクスは mydomain (Bean 内の属性によっては多少異なる) になり、タグ attr0:val0attr1:val1domain:mydomain が付きます。

include キー内の指定したエイリアスが_キャメルケース_として書式設定されている場合、_スネークケース_に変換されます。たとえば MyMetricName は、Datadog では my_metric_name と表示されます。

属性フィルター

attribute フィルターは、次の 2 種類の値を受け入れます。

  • キーが属性名の辞書(以下を参照)。この場合、メトリクスのエイリアスを指定でき、それが 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.\[ドメイン名].\[属性名] です。

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

以前のバージョン

フィルターのリストは、5.3.0 よりも新しい Datadog Agent でのみサポートされます。以前のバージョンを使用している場合は、代わりにシングルトンと複数の include ステートメントを使用します。

# Datadog Agent > 5.3.0
  conf:
    - include:
      domain: domain_name
      bean:
        - first_bean_name
        - second_bean_name
# Older Datadog Agent versions
  conf:
    - include:
      domain: domain_name
      bean: first_bean_name
    - include:
      domain: domain_name
      bean: second_bean_name

ログの収集

  1. ログを Datadog に送信する際、Tomcat は log4j ロガーを使用します。バージョン 8.0 より前の Tomcat では、log4j がデフォルトで構成されています。バージョン 8.0+ の Tomcat では、Tomcat を構成し log4j を使用する必要があります。Log4 の使用を参照してください。この手順の初めに、以下の要領で $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 Agent で、ログの収集はデフォルトで無効になっています。以下のように、datadog.yaml ファイルでこれを有効にします。

    logs_enabled: true
    
  4. Tomcat のログの収集を開始するには、次の構成ブロックを tomcat.d/conf.yaml ファイルに追加します。

    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])
    

    path パラメーターと service パラメーターの値を変更し、環境に合わせて構成します。使用可能なすべてのコンフィギュレーションオプションについては、サンプル tomcat.yaml を参照してください。

  5. Agent を再起動します

コンテナ化

コンテナ環境の場合は、JMX を使用したオートディスカバリーのガイドを参照してください。

検証

Agent の status サブコマンドを実行し、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
Agent が監視対象の Tomcat インスタンスに接続できず、メトリクスを収集できない場合は、CRITICAL を返します。それ以外の場合は、OK を返します。
Statuses: ok, クリティカル

トラブルシューティング

tomcat.* メトリクスの欠落

このインテグレーションでは、Catalina Bean ドメイン名からデフォルトの Tomcat メトリクスを収集します。もし、公開されている Tomcat のメトリクスが Tomcat などの別の Bean ドメイン名でプレフィックスされている場合は、metrics.yaml から tomcat.d/conf.yamlconf セクションにデフォルトメトリクスをコピーして、domain フィルターを変更して該当する Bean ドメイン名を使用できるようにします。

- include:
    domain: Tomcat      # デフォルト: Catalina
    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 Check ドキュメントを参照してください。

使用可能なメトリクスを表示するコマンド

バージョン 4.1.0 で datadog-agent jmx コマンドが追加されました。

  • 1 つ以上のインスタンス構成に一致する属性をリストする: sudo /etc/init.d/datadog-agent jmx list_matching_attributes
  • インスタンス構成の 1 つに一致するが、収集可能なメトリクス数を超えるために収集されない属性をリストする: sudo /etc/init.d/datadog-agent jmx list_limited_attributes
  • 現在のインスタンス構成によって実際に収集される属性をリストする: sudo /etc/init.d/datadog-agent jmx list_collected_attributes
  • どのインスタンス構成にも一致しない属性をリストする: sudo /etc/init.d/datadog-agent jmx list_not_matching_attributes
  • JMXFetch でサポートされているタイプのすべての使用可能な属性をリストする: sudo /etc/init.d/datadog-agent jmx list_everything
  • 現在の構成に基づいてメトリクスの収集を開始し、コンソールに表示する: sudo /etc/init.d/datadog-agent jmx collect

その他の参考資料

お役に立つドキュメント、リンクや記事: