Supported OS Linux Windows Mac OS

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

概要

このチェックは SonarQube を監視します。

セットアップ

インストール

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

コンフィギュレーション

SonarQube は、Web API および JMX の 2 つのソースからのメトリクスを公開します。 以下で指定されたメトリクスのすべてを収集するには、このチェックの 3 つのインスタンスを構成します。SonarQube の Web API を監視するものと、SonarQube の JMX Bean を監視する 2 つです。

SonarQube の Web API に関するドキュメントは、SonarQube Web UI の /web_api でご確認ください。デフォルトで このインテグレーションは SonarQube の JMX Bean を通じて公開されたすべての関連 SonarQube パフォーマンスを収集します。この デフォルトのメトリクスのコンフィギュレーションは、sonarqube.d/metrics.yaml ファイルにあります。Bean に関するドキュメントは、 SonarQube のウェブサイトをご覧ください。

SonarQube の JMX サーバーは、デフォルトで無効になっています。つまり、有効にしない限り sonarqube.server.* メトリクスは収集されません。有効化して SonarQube 内で JMX を構成する方法について、詳細は SonarQube ドキュメントをご参照ください。以下は、いくつかの一般的な Java プロセスで JMX サーバーを有効にするために必要な構成です。

# WEB SERVER
sonar.web.javaAdditionalOpts="
  -Dcom.sun.management.jmxremote=true
  -Dcom.sun.management.jmxremote.port=10443
  -Dcom.sun.management.jmxremote.rmi.port=10443
  ...
  "

# COMPUTE ENGINE
sonar.ce.javaAdditionalOpts="
  -Dcom.sun.management.jmxremote=true
  -Dcom.sun.management.jmxremote.port=10444
  -Dcom.sun.management.jmxremote.rmi.port=10444
  ...
  "

# ELASTICSEARCH
sonar.search.javaAdditionalOpts="
  -Dcom.sun.management.jmxremote=true
  -Dcom.sun.management.jmxremote.port=10445
  -Dcom.sun.management.jmxremote.rmi.port=10445
  ...
  "

これは、SonarQube および JMX のデフォルトに基づく基本的な sonarqube.d/conf.yaml 例です。ホストベースまたはコンテナベースで Agent をインストールする場合、ここを起点として開始できます。

init_config:
    is_jmx: false
    collect_default_metrics: true
instances:

  # Web API インスタンス
  - is_jmx: false
    web_endpoint: http://localhost:9000
    auth_type: basic
    username: <username>    # Web UI で定義済み
    password: <password>    # Web UI で定義済み
    default_tag: component  # オプション
    components:             # 必須
      my-project:
        tag: project_name

  # Web JMX インスタンス
  - is_jmx: true
    host: localhost
    port: 10443           # SonarQube の sonar.properties ファイルの sonar.web.javaAdditionalOpts を参照してください
    user: <username>      # SonarQube の sonar.properties ファイルで定義済み
    password: <password>  # SonarQube の sonar.properties ファイルで定義済み

  # Compute Engine JMX インスタンス
  - is_jmx: true
    host: localhost
    port: 10444           # SonarQube の sonar.properties ファイルの sonar.ce.javaAdditionalOpts を参照してください
    user: <username>      # SonarQube の sonar.properties ファイルで定義済み
    password: <password>  # SonarQube の sonar.properties ファイルで定義済み

: インテグレーションを構成したら、SonarQube で 1 つ以上のプロジェクトをスキャンし、メトリクスを Datadog に送信します。

このインテグレーションで収集される.メトリクスは、デフォルトで component タグが付けられます。タグ名をコンポーネント別に変更するには、コンポーネントの定義で tag プロパティを指定します。すべてのプロジェクトに設定するには、インスタンスのコンフィグで default_tag プロパティを設定します。

: SonarQube のプロジェクトには、よく複数のソース管理ブランチが含まれています。このインテグレーションでは、SonarQube 内のデフォルトブランチ (通常は main) からのメトリクスのみが収集されます。

サーバーメトリクスの検索

SonarQube はこのインテグレーションの追加インスタンスおよび JMX メトリクスのコンフィギュレーションを使用して監視される検索サーバーを公開します。収集するメトリクスのカスタマイズ方法については、JMX チェックのドキュメントで詳細をご確認ください。例については、以下のコンフィグや、 sonarqube.d/metrics.yaml 内のデフォルトの JMX メトリクスコンフィグなどもご活用いただけます。

init_config:
  # インテグレーションにより収集されるメトリクスのリスト。
  config:
    - include:
      domain: SonarQube
      name: <name>
      exclude_tags:
        - name
      attribute:
        MyMetric:
          alias: sonarqube.search_server.my_metric
          metric_type: gauge
instances:
  # Search Server JMX インスタンス
  - is_jmx: true
    host: localhost
    port: 10445           # SonarQube の sonar.properties ファイルの sonar.search.javaAdditionalOpts を参照してください
    user: <username>      # SonarQube の sonar.properties ファイルで定義済み
    password: <password>  # SonarQube の sonar.properties ファイルで定義済み

ホスト

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

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

    このチェックでは、JMX インスタンスあたりのメトリクス数が 350 に制限されています。返されたメトリクスの数は、情報ページに表示されます。 以下で説明する構成を編集することで、関心があるメトリクスを指定できます。 収集するメトリクスをカスタマイズする方法については、JMX チェックのドキュメントで詳細な手順を参照してください。 制限以上のメトリクスを監視する必要がある場合は、Datadog のサポートチームまでお問い合わせください。

  2. Agent を再起動します

ログの収集
  1. SonarQube ログの収集を有効化します。

  2. Datadog Agent で、ログの収集はデフォルトで無効になっています。以下のように、datadog.yaml ファイルでこれを有効にします。

    logs_enabled: true
    
  3. 次のコンフィギュレーションブロックを sonarqube.d/conf.yaml ファイルに追加します。環境に基づいて、path パラメーターと service パラメーターの値を変更してください。使用可能なすべてのコンフィギュレーションオプションの詳細については、サンプル sonarqube.d/conf.yaml を参照してください。

    logs:
      - type: file
        path: /opt/sonarqube/logs/access.log
        source: sonarqube
      - type: file
        path: /opt/sonarqube/logs/ce.log
        source: sonarqube
        log_processing_rules:
          - type: multi_line
            name: log_start_with_date
            pattern: \d{4}\.\d{2}\.\d{2}
      - type: file
        path: /opt/sonarqube/logs/es.log
        source: sonarqube
        log_processing_rules:
          - type: multi_line
            name: log_start_with_date
            pattern: \d{4}\.\d{2}\.\d{2}
      - type: file
        path: /opt/sonarqube/logs/sonar.log
        source: sonarqube
        log_processing_rules:
          - type: multi_line
            name: log_start_with_date
            pattern: \d{4}\.\d{2}\.\d{2}
      - type: file
        path: /opt/sonarqube/logs/web.log
        source: sonarqube
        log_processing_rules:
          - type: multi_line
            name: log_start_with_date
            pattern: \d{4}\.\d{2}\.\d{2}
    
  4. Agent を再起動します

コンテナ化

メトリクスの収集

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

ログの収集

Datadog Agent では、ログの収集がデフォルトで無効になっています。これを有効にするには、Docker ログの収集を参照してください。

パラメーター
<LOG_CONFIG>{"source": "sonarqube"}

コンポーネントの検出

components_discovery パラメータで、コンポーネントの検出方法を構成することができます。

limit
自動検出するアイテムの最大数。 デフォルト値: 10
include
正規表現キーとコンポーネント設定値の自動検出へのマッピング。 デフォルト値: 空のマップ
exclude
自動検出から除外するコンポーネントのパターンを持つ正規表現のリスト。 デフォルト値: 空のリスト

:

my_project で始まる名前のコンポーネントを最大 5 まで含めます。

components_discovery:
  limit: 5
  include:
    'my_project*':

最大 20 のコンポーネントを含み、temp で始まるコンポーネントは除外します。

components_discovery:
  limit: 20
  include:
    '.*':
  exclude:
    - 'temp*'

名前が issues で始まるコンポーネントをすべて含み、issues_project タグを適用し、カテゴリー issues に属するメトリクスのみを収集します。limit が定義されていないため、検出されるコンポーネントの数はデフォルト値の 10 に制限されます。

components_discovery:
  include:
    'issues*':
       tag: issues_project
       include:
         - issues.

検証

Agent のステータスサブコマンドを実行し、 JMXFetch セクションで sonarqube を探します。

========
JMXFetch
========
  Initialized checks
  ==================
    sonarqube
      instance_name : sonarqube-localhost-10444
      message : <no value>
      metric_count : 33
      service_check_count : 0
      status : OK
      instance_name : sonarqube-localhost-10443
      message : <no value>
      metric_count : 38
      service_check_count : 0
      status : OK

is_jmx: true を使用せずにインスタンスを設定する場合も、Collector セクションで sonarqube を探します。

=========
Collector
=========
  Running Checks
  ==============
    sonarqube (1.1.0)
    -----------------
      Instance ID: sonarqube:1249c1ed7c7b489a [OK]
      Configuration Source: file:/etc/datadog-agent/conf.d/sonarqube.d/conf.yaml
      Total Runs: 51
      Metric Samples: Last Run: 39, Total: 1,989
      Events: Last Run: 0, Total: 0
      Service Checks: Last Run: 1, Total: 51
      Average Execution Time : 1.19s
      Last Execution Date : 2021-03-12 00:00:44.000000 UTC
      Last Successful Execution Date : 2021-03-12 00:00:44.000000 UTC

収集データ

メトリクス

sonarqube.complexity.cognitive_complexity
(gauge)
Cognitive complexity
sonarqube.complexity.complexity
(gauge)
Cyclomatic complexity
sonarqube.coverage.branch_coverage
(gauge)
Condition coverage
Shown as percent
sonarqube.coverage.conditions_to_cover
(gauge)
Conditions to cover
sonarqube.coverage.coverage
(gauge)
Coverage by tests
Shown as percent
sonarqube.coverage.line_coverage
(gauge)
Line coverage
Shown as percent
sonarqube.coverage.lines_to_cover
(gauge)
Lines to cover
sonarqube.coverage.new_branch_coverage
(gauge)
Condition coverage of new/changed code
Shown as percent
sonarqube.coverage.new_conditions_to_cover
(gauge)
Conditions to cover on new code
sonarqube.coverage.new_coverage
(gauge)
Coverage of new/changed code
Shown as percent
sonarqube.coverage.new_line_coverage
(gauge)
Line coverage of added/changed code
Shown as percent
sonarqube.coverage.new_lines_to_cover
(gauge)
Lines to cover on new code
sonarqube.coverage.new_uncovered_conditions
(gauge)
Uncovered conditions on new code
sonarqube.coverage.new_uncovered_lines
(gauge)
Uncovered lines on new code
sonarqube.coverage.skipped_tests
(gauge)
Number of skipped unit tests
sonarqube.coverage.test_errors
(gauge)
Number of unit test errors
sonarqube.coverage.test_failures
(gauge)
Number of unit test failures
sonarqube.coverage.test_success_density
(gauge)
Density of successful unit tests
Shown as percent
sonarqube.coverage.tests
(gauge)
Number of unit tests
sonarqube.coverage.uncovered_conditions
(gauge)
Uncovered conditions
sonarqube.coverage.uncovered_lines
(gauge)
Uncovered lines
sonarqube.duplications.duplicated_blocks
(gauge)
Duplicated blocks
sonarqube.duplications.duplicated_files
(gauge)
Duplicated files
sonarqube.duplications.duplicated_lines
(gauge)
Duplicated lines
sonarqube.duplications.duplicated_lines_density
(gauge)
Duplicated lines balanced by statements
Shown as percent
sonarqube.duplications.new_duplicated_blocks
(gauge)
Duplicated blocks on new code
sonarqube.duplications.new_duplicated_lines
(gauge)
Duplicated Lines on New Code
sonarqube.duplications.new_duplicated_lines_density
(gauge)
Duplicated lines (%) on new code balanced by statements
Shown as percent
sonarqube.issues.blocker_violations
(gauge)
Blocker issues
sonarqube.issues.confirmed_issues
(gauge)
Confirmed issues
sonarqube.issues.critical_violations
(gauge)
Critical issues
sonarqube.issues.false_positive_issues
(gauge)
False positive issues
sonarqube.issues.info_violations
(gauge)
Info issues
sonarqube.issues.major_violations
(gauge)
Major issues
sonarqube.issues.minor_violations
(gauge)
Minor issues
sonarqube.issues.new_blocker_violations
(gauge)
New Blocker issues
sonarqube.issues.new_critical_violations
(gauge)
New Critical issues
sonarqube.issues.new_info_violations
(gauge)
New Info issues
sonarqube.issues.new_major_violations
(gauge)
New Major issues
sonarqube.issues.new_minor_violations
(gauge)
New Minor issues
sonarqube.issues.new_violations
(gauge)
New issues
sonarqube.issues.open_issues
(gauge)
Open issues
sonarqube.issues.reopened_issues
(gauge)
Reopened issues
sonarqube.issues.violations
(gauge)
Issues
sonarqube.issues.wont_fix_issues
(gauge)
Won't fix issues
sonarqube.maintainability.code_smells
(gauge)
Code Smells
sonarqube.maintainability.new_code_smells
(gauge)
New Code Smells
sonarqube.maintainability.new_maintainability_rating
(gauge)
Maintainability rating on new code
sonarqube.maintainability.new_sqale_debt_ratio
(gauge)
Technical Debt Ratio of new/changed code.
Shown as percent
sonarqube.maintainability.sqale_debt_ratio
(gauge)
Ratio of the actual technical debt compared to the estimated cost to develop the whole source code from scratch
Shown as percent
sonarqube.maintainability.sqale_rating
(gauge)
A-to-E rating based on the technical debt ratio
sonarqube.reliability.bugs
(gauge)
Bugs
sonarqube.reliability.new_bugs
(gauge)
New Bugs
sonarqube.reliability.new_reliability_rating
(gauge)
Reliability rating on new code
sonarqube.reliability.reliability_rating
(gauge)
Reliability rating
sonarqube.security.new_security_rating
(gauge)
Security rating on new code
sonarqube.security.new_vulnerabilities
(gauge)
New Vulnerabilities
sonarqube.security.security_rating
(gauge)
Security rating
sonarqube.security.vulnerabilities
(gauge)
Vulnerabilities
sonarqube.security_review.new_security_hotspots
(gauge)
New Security Hotspots
sonarqube.security_review.new_security_hotspots_reviewed
(gauge)
Percentage of Security Hotspots Reviewed on New Code
Shown as percent
sonarqube.security_review.new_security_review_rating
(gauge)
Security Review Rating on New Code
sonarqube.security_review.security_hotspots
(gauge)
Security Hotspots
sonarqube.security_review.security_hotspots_reviewed
(gauge)
Percentage of Security Hotspots Reviewed
Shown as percent
sonarqube.security_review.security_review_rating
(gauge)
Security Review Rating
sonarqube.server.async_execution.largest_worker_count
(gauge)
sonarqube.server.async_execution.queue_size
(gauge)
sonarqube.server.async_execution.worker_count
(gauge)
sonarqube.server.compute_engine_tasks.error_count
(count)
Number of Background Tasks which failed since the last restart of SonarQube
Shown as error
sonarqube.server.compute_engine_tasks.in_progress_count
(gauge)
Number of Background Tasks currently under processing. Its value is either 1 or 0, since SonarQube can process only one task at a time.
sonarqube.server.compute_engine_tasks.longest_pending_time
(gauge)
Pending time (ms) of the oldest Background Task waiting to be processed. This measure, together with PendingCount, helps you know if analyses are stacking and taking too long to start processing. This helps you evaluate if it might be worth configuring additional Compute Engine workers (Enterprise Edition) or additional nodes (Data Center Edition) to improve performance. Requires SonarQube >=9.0.
Shown as millisecond
sonarqube.server.compute_engine_tasks.pending_count
(count)
Number of Background Tasks waiting to be processed since the last restart of SonarQube
sonarqube.server.compute_engine_tasks.processing_time
(gauge)
Measure the time spent to process Background Tasks since the last restart. The value will always increase. This measure is powerful when combined with SuccessCount and ErrorCount measures to get the average time to handle a Background Task, or when used to understand how much time the server is spending during a day to handle Background Tasks. It gives you an indication of the load on your server.
sonarqube.server.compute_engine_tasks.success_count
(count)
Number of Background Tasks successfully processed since the last restart of SonarQube
sonarqube.server.compute_engine_tasks.worker_count
(gauge)
Number of Background Tasks that can be processed at the same time
sonarqube.server.compute_engine_tasks.worker_max_count
(gauge)
sonarqube.server.database.pool_active_connections
(gauge)
Number of active database connections
Shown as connection
sonarqube.server.database.pool_idle_connections
(gauge)
Number of database connections waiting to be used
Shown as connection
sonarqube.server.database.pool_initial_size
(gauge)
Initial size of the database connections pool
Shown as connection
sonarqube.server.database.pool_max_active_connections
(gauge)
Maximum number of active database connections
Shown as connection
sonarqube.server.database.pool_max_idle_connections
(gauge)
Maximum number of database connections waiting to be used
Shown as connection
sonarqube.server.database.pool_max_wait_millis
(gauge)

Shown as millisecond
sonarqube.server.database.pool_min_idle_connections
(gauge)

Shown as connection
sonarqube.server.database.pool_remove_abandoned_timeout_seconds
(gauge)

Shown as second
sonarqube.size.classes
(gauge)
Classes
sonarqube.size.comment_lines
(gauge)
Number of comment lines
sonarqube.size.comment_lines_density
(gauge)
Comments balanced by ncloc + comment lines
Shown as percent
sonarqube.size.directories
(gauge)
Directories
sonarqube.size.files
(gauge)
Number of files
sonarqube.size.functions
(gauge)
Functions
sonarqube.size.generated_lines
(gauge)
Number of generated lines
sonarqube.size.generated_ncloc
(gauge)
Generated non Commenting Lines of Code
sonarqube.size.lines
(gauge)
Lines
sonarqube.size.ncloc
(gauge)
Non commenting lines of code
sonarqube.size.new_lines
(gauge)
New lines
sonarqube.size.projects
(gauge)
Number of projects
sonarqube.size.statements
(gauge)
Number of statements

イベント

SonarQube には、イベントは含まれません。

サービスのチェック

sonarqube.can_connect
Returns CRITICAL if the Agent is unable to connect to and collect metrics from the monitored SonarQube instance’s JMX endpoint, WARNING if no metrics are collected, and OK otherwise.
Statuses: ok, critical, warning

sonarqube.api_access
Returns CRITICAL if the Agent is unable to connect to and collect metrics from the monitored SonarQube instance’s web endpoint, otherwise returns OK.
Statuses: ok, critical

トラブルシューティング

ご不明な点は、Datadog のサポートチームまでお問合せください。

その他の参考資料

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