Amazon RDS 上の SQL Server のデータベースモニタリングの設定

データベースモニタリングは、クエリメトリクス、クエリサンプル、実行計画、データベースの状態、フェイルオーバー、イベントを公開することで、Microsoft SQL Server データベースを詳細に可視化します。

データベースでデータベースモニタリングを有効にするには、以下の手順を実行します。

  1. AWS インテグレーションを構成する
  2. Agent にアクセスを付与する
  3. エージェントをインストールする
  4. RDS インテグレーションをインストールする

はじめに

サポートされている SQL Server バージョン
2014、2016、2017、2019、2022
Supported Agent versions
7.41.0+
Performance impact
The default Agent configuration for Database Monitoring is conservative, but you can adjust settings such as the collection interval and query sampling rate to better suit your needs. For most workloads, the Agent represents less than one percent of query execution time on the database and less than one percent of CPU.

Database Monitoring runs as an integration on top of the base Agent (see benchmarks).
Proxies, load balancers, and connection poolers
The Datadog Agent must connect directly to the host being monitored. The Agent should not connect to the database through a proxy, load balancer, or connection pooler. If the Agent connects to different hosts while it is running (as in the case of failover, load balancing, and so on), the Agent calculates the difference in statistics between two hosts, producing inaccurate metrics.
Data security considerations
Read about how Database Management handles sensitive information for information about what data the Agent collects from your databases and how to ensure it is secure.
RDS Custom
Datadog supports DBM for some RDS Custom configurations that make OS-level changes. This support depends on the customizations stable compatibility with DBM.

AWS インテグレーションを構成する

Amazon Web Services インテグレーションタイルの Resource Collection セクションで Standard Collection を有効にします。

Agent にアクセスを付与する

Datadog Agent が統計やクエリを収集するためには、データベースサーバーへの読み取り専用のアクセスが必要となります。

サーバーに接続するための読み取り専用ログインを作成し、必要な権限を付与します。

USE [master];
CREATE LOGIN datadog WITH PASSWORD = '<PASSWORD>';
GO
--Set context to msdb database and create datadog user
USE [msdb];
CREATE USER datadog FOR LOGIN datadog;
-- If not using either of Log Shipping Monitoring (available in Agent v7.50+), comment out the next line:
GRANT SELECT ON dbo.log_shipping_monitor_primary to datadog;
GRANT SELECT ON dbo.log_shipping_monitor_secondary to datadog;
-- If not using SQL Server Agent Monitoring (available in Agent v7.57+), comment out the next three lines:
GRANT SELECT ON dbo.sysjobs to datadog;
GRANT SELECT ON dbo.sysjobhistory TO datadog;
GRANT SELECT ON dbo.sysjobactivity to datadog;
GO
--Switch back to master and grant datadog user server permissions
USE [master];
GRANT VIEW SERVER STATE to datadog;
GRANT VIEW ANY DEFINITION to datadog;
GO

追加した各アプリケーションデータベースに datadog ユーザーを作成します。

USE [database_name];
CREATE USER datadog FOR LOGIN datadog;

これは RDS が CONNECT ANY DATABASE を付与することを許可しないために必要です。Datadog Agent は、データベース固有のファイル I/O 統計を収集するために各データベースに接続する必要があります。

パスワードを安全に保管する

Store your password using secret management software such as Vault. You can then reference this password as ENC[<SECRET_NAME>] in your Agent configuration files: for example, ENC[datadog_user_database_password]. See Secrets Management for more information.

The examples on this page use datadog_user_database_password to refer to the name of the secret where your password is stored. It is possible to reference your password in plain text, but this is not recommended.

Agent をインストールする

AWS はホストへの直接アクセスを許可しないため、Datadog Agent は SQL Server ホストと通信可能な別のホストにインストールする必要があります。Agent のインストールと実行には、いくつかのオプションがあります。

Note: For AlwaysOn users with cloud-hosted instances, the recommended approach is to install the Agent on a remote instance and connect to each individual replica. Telemetry for the relevant availability groups will be collected from each replica the agent is connected to. As a fallback method, the Agent can be installed on a separate server and connected to the cluster through the listener endpoint.

SQL Server テレメトリを収集するには、Datadog Agent をインストールし、次に C:\ProgramData\Datadog\conf.d\sqlserver.d\conf.yaml に SQL Server Agent の conf ファイルを作成します。使用可能なすべての構成オプションについては、サンプル構成ファイルを参照してください。

init_config:
instances:
  - dbm: true
    host: '<HOSTNAME>,<PORT>'
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    tags:  # Optional
      - 'service:<CUSTOM_SERVICE>'
      - 'env:<CUSTOM_ENV>'
    # After adding your instance endpoint, configure the Datadog AWS integration to pull additional cloud data such as CPU, Memory, etc.
    aws:
      instance_endpoint: '<INSTANCE_ENDPOINT>'

Windows 認証を使用するには、connection_string: "Trusted_Connection=yes" を設定し、username および password フィールドを省略します。

service および env タグを使用して、共通のタグ付けスキームを通じてデータベーステレメトリを他のテレメトリにリンクします。これらのタグが Datadog 全体でどのように使用されるかの詳細については、統合サービスタグ付けを参照してください。

対応ドライバー

Microsoft ADO

推奨される ADO プロバイダーは Microsoft OLE DB ドライバーです。ドライバーが、Agent が実行されているホストにインストールされていることを確認してください。

connector: adodbapi
adoprovider: MSOLEDBSQL19  # Replace with MSOLEDBSQL for versions 18 and lower

他の 2 つのプロバイダー、SQLOLEDB と SQLNCLI は、Microsoft によって非推奨と見なされており、使用しないことをお勧めします。

ODBC

推奨される ODBC ドライバーは Microsoft ODBC ドライバーです。Agent 7.51 以降では、ODBC Driver 18 for SQL Server が Linux Agent にデフォルトで含まれています。Windows の場合、ドライバーが、Agent が実行されているホストにインストールされていることを確認してください。

connector: odbc
driver: 'ODBC Driver 18 for SQL Server'

すべての Agent の構成が完了したら、Datadog Agent を再起動します。

検証

Agent のステータスサブコマンドを実行し、Checks セクションに sqlserver があることを確認します。Datadog の データベースページに移動して開始します。

Note: For AlwaysOn users with cloud-hosted instances, the recommended approach is to install the Agent on a remote instance and connect to each individual replica. Telemetry for the relevant availability groups will be collected from each replica the agent is connected to. As a fallback method, the Agent can be installed on a separate server and connected to the cluster through the listener endpoint.

SQL Server テレメトリーの収集を開始するには、まず Datadog Agent をインストールします。

Linux では、Microsoft ODBC ドライバーのような ODBC SQL Server ドライバーもインストールする必要があります。インストール後、odbc.ini および odbcinst.ini ファイルを /opt/datadog-agent/embedded/etc フォルダーにコピーします。

odbc コネクターを使用し、odbcinst.ini ファイルに示されているように、適切なドライバーを指定します。

SQL Server Agent の conf ファイル /etc/datadog-agent/conf.d/sqlserver.d/conf.yaml を作成します。使用可能なすべての構成オプションについては、サンプル構成ファイルを参照してください。

init_config:
instances:
  - dbm: true
    host: '<HOSTNAME>,<PORT>'
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    connector: odbc
    driver: '<Driver from the `odbcinst.ini` file>'
    tags:  # Optional
      - 'service:<CUSTOM_SERVICE>'
      - 'env:<CUSTOM_ENV>'
    # After adding your instance endpoint, configure the Datadog AWS integration to pull additional cloud data such as CPU, Memory, etc.
    aws:
      instance_endpoint: '<INSTANCE_ENDPOINT>'

service および env タグを使用して、共通のタグ付けスキームを通じてデータベーステレメトリを他のテレメトリにリンクします。これらのタグが Datadog 全体でどのように使用されるかの詳細については、統合サービスタグ付けを参照してください。

すべての Agent の構成が完了したら、Datadog Agent を再起動します。

検証

Agent のステータスサブコマンドを実行し、Checks セクションに sqlserver があることを確認します。Datadog のデータベースページに移動して開始します。

Note: For AlwaysOn users with cloud-hosted instances, the recommended approach is to install the Agent on a remote instance and connect to each individual replica. Telemetry for the relevant availability groups will be collected from each replica the agent is connected to. As a fallback method, the Agent can be installed on a separate server and connected to the cluster through the listener endpoint.

Docker コンテナで実行されている Database Monitoring Agent を設定するには、Autodiscovery インテグレーションテンプレートを Agent コンテナの Docker ラベルとして設定します。

注: Autodiscovery によるラベルの検出を有効にするには、Agent が Docker ソケットの読み取り権限を持っている必要があります。

お使いのアカウントや環境に合わせて値を変更してください。使用可能なすべての構成オプションについては、サンプル構成ファイルを参照してください。

export DD_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export DD_AGENT_VERSION=<AGENT_VERSION>

docker run -e "DD_API_KEY=${DD_API_KEY}" \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  -l com.datadoghq.ad.check_names='["sqlserver"]' \
  -l com.datadoghq.ad.init_configs='[{}]' \
  -l com.datadoghq.ad.instances='[{
    "dbm": true,
    "host": "<HOSTNAME>,<PORT>",
    "connector": "odbc",
    "driver": "ODBC Driver 18 for SQL Server",
    "username": "datadog",
    "password": "<PASSWORD>",
    "tags": [
      "service:<CUSTOM_SERVICE>"
      "env:<CUSTOM_ENV>"
    ],
    "aws": {
      "instance_endpoint": "<INSTANCE_ENDPOINT>"
    }
  }]' \
  registry.datadoghq.com/agent:${DD_AGENT_VERSION}

service および env タグを使用して、共通のタグ付けスキームを通じてデータベーステレメトリを他のテレメトリにリンクします。これらのタグが Datadog 全体でどのように使用されているかについては、統合サービスタグ付けを参照してください。

検証

Agent のステータスサブコマンドを実行し、Checks セクションに sqlserver があることを確認します。または、Datadog のデータベースページに移動して開始します。

Note: For AlwaysOn users with cloud-hosted instances, the recommended approach is to install the Agent on a remote instance and connect to each individual replica. Telemetry for the relevant availability groups will be collected from each replica the agent is connected to. As a fallback method, the Agent can be installed on a separate server and connected to the cluster through the listener endpoint.

Kubernetes クラスターを実行している場合は、Datadog Cluster Agent を使用して Database Monitoring を有効にしてください。クラスターチェックがまだ有効でない場合は、手順に従って、続行する前に有効化してください。

Operator

以下の手順に従って、Kubernetes およびインテグレーションにおけるオペレーター手順を参照しながら SQL Server インテグレーションを設定します。

  1. 次の構成で datadog-agent.yaml ファイルを作成または更新します。

    apiVersion: datadoghq.com/v2alpha1
    kind: DatadogAgent
    metadata:
      name: datadog
    spec:
      global:
        clusterName: <CLUSTER_NAME>
        site: <DD_SITE>
        credentials:
          apiSecret:
            secretName: datadog-agent-secret
            keyName: api-key
    
      features:
        clusterChecks:
          enabled: true
    
      override:
        nodeAgent:
          image:
            name: agent
            tag: <AGENT_VERSION>
    
        clusterAgent:
          extraConfd:
            configDataMap:
              sqlserver.yaml: |-
                cluster_check: true # Required for cluster checks
                init_config:
                instances:
                - host: <HOSTNAME>,<PORT>
                  username: datadog
                  password: 'ENC[datadog_user_database_password]'
                  connector: 'odbc'
                  driver: 'ODBC Driver 18 for SQL Server'
                  dbm: true
                  # Optional: For additional tags
                  tags:
                    - 'service:<CUSTOM_SERVICE>'
                    - 'env:<CUSTOM_ENV>'
                  # After adding your instance endpoint, configure the Datadog AWS integration to pull additional cloud data such as CPU, Memory, etc.
                  aws:
                    instance_endpoint: <INSTANCE_ENDPOINT>
    
  2. 次のコマンドを使用して Datadog Operator に変更を適用します。

    kubectl apply -f datadog-agent.yaml
    

Helm

以下の手順を踏んで、Kubernetes クラスターに Datadog Cluster Agent をインストールします。お使いのアカウントや環境に合わせて値を変更してください。

  1. Helm の Datadog Agent インストール手順を踏みます。

  2. YAML 構成ファイル (Cluster Agent インストール手順の datadog-values.yaml) を更新して、以下を含めます。

    clusterAgent:
      confd:
        sqlserver.yaml: |-
          cluster_check: true # Required for cluster checks
          init_config:
          instances:
          - dbm: true
            host: <HOSTNAME>,<PORT>
            username: datadog
            password: 'ENC[datadog_user_database_password]'
            connector: 'odbc'
            driver: 'ODBC Driver 18 for SQL Server'
            # Optional: For additional tags
            tags:
              - 'service:<CUSTOM_SERVICE>'
              - 'env:<CUSTOM_ENV>'
            # After adding your instance endpoint, configure the Datadog AWS integration to pull additional cloud data such as CPU, Memory, etc.
            aws:
              instance_endpoint: <INSTANCE_ENDPOINT>
    
    clusterChecksRunner:
      enabled: true
    
  3. コマンドラインから上記の構成ファイルを使用して Agent をデプロイします。

    helm install datadog-agent -f datadog-values.yaml datadog/datadog
    
Windows の場合、 --set targetSystem=windows を helm install コマンドに追記します。

マウントされたファイルで構成する

マウントされた構成ファイルを使用してクラスターチェックを構成するには、構成ファイルを Cluster Agent コンテナのパス /conf.d/sqlserver.yaml にマウントします。

cluster_check: true  # Required for cluster checks
init_config:
instances:
  - dbm: true
    host: <HOSTNAME>,<PORT>
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    connector: 'odbc'
    driver: 'ODBC Driver 18 for SQL Server'
    # Optional: For additional tags
    tags:
      - 'service:<CUSTOM_SERVICE>'
      - 'env:<CUSTOM_ENV>'
    # After adding your instance endpoint, configure the Datadog AWS integration to pull additional cloud data such as CPU, Memory, etc.
    aws:
      instance_endpoint: <INSTANCE_ENDPOINT>

Kubernetes サービスアノテーションで構成する

ファイルをマウントする代わりに、インスタンス構成を Kubernetes サービスとして宣言できます。Kubernetes 上で実行されている Agent に対してこのチェックを構成するには、次の構文を使用してサービスを作成します。

apiVersion: v1
kind: Service
metadata:
  name: sqlserver-datadog-check-instances
  annotations:
    ad.datadoghq.com/service.check_names: '["sqlserver"]'
    ad.datadoghq.com/service.init_configs: '[{}]'
    ad.datadoghq.com/service.instances: |
      [
        {
          "dbm": true,
          "host": "<HOSTNAME>,<PORT>",
          "username": "datadog",
          "password": "ENC[datadog_user_database_password]",
          "connector": "odbc",
          "driver": "ODBC Driver 18 for SQL Server",
          "tags": ["service:<CUSTOM_SERVICE>", "env:<CUSTOM_ENV>"],
          "aws": {
            "instance_endpoint": "<INSTANCE_ENDPOINT>"
          }
        }
      ]
spec:
  ports:
  - port: 1433
    protocol: TCP
    targetPort: 1433
    name: sqlserver

deployment_type と name フィールドの設定に関する追加情報は、SQL Server インテグレーション仕様を参照してください。

Cluster Agent は自動的にこの構成を登録し、SQL Server チェックを開始します。

datadog ユーザーのパスワードがプレーンテキストで公開されることがないようにするために、Agent のシークレット管理パッケージを使用し、ENC[] 構文でパスワードを宣言します。

Agent の構成例

Connecting with DSN using the ODBC driver on Linux

  1. Locate the odbc.ini and odbcinst.ini files. By default, these are placed in the /etc directory when installing ODBC.

  2. Copy the odbc.ini and odbcinst.ini files into the /opt/datadog-agent/embedded/etc folder.

  3. Configure your DSN settings as follows:

    odbcinst.ini must provide at least one section header and ODBC driver location.

    Example:

    [ODBC Driver 18 for SQL Server]
    Description=Microsoft ODBC Driver 18 for SQL Server
    Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.3.so.2.1
    UsageCount=1
    

    odbc.ini must provide a section header and a Driver path that matches odbcinst.ini.

    Example:

    [datadog]
    Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.3.so.2.1
    
  4. Update the /etc/datadog-agent/conf.d/sqlserver.d/conf.yaml file with your DSN information.

    Example:

    instances:
      - dbm: true
        host: 'localhost,1433'
        username: datadog
        password: 'ENC[datadog_user_database_password]'
        connector: 'odbc'
        driver: 'ODBC Driver 18 for SQL Server' # This is the section header of odbcinst.ini
        dsn: 'datadog' # This is the section header of odbc.ini
    
  5. Restart the Agent.

Using AlwaysOn

For AlwaysOn users, the Agent should be installed on each replica server and connected directly to each replica. The full set of AlwaysOn telemetry is collected from each individual replica, in addition to host-based telemetry (CPU, disk, memory, and so on) for each server.

instances:
  - dbm: true
    host: 'shopist-prod,1433'
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    database_metrics:
      # If Availability Groups is enabled
      ao_metrics:
        enabled: true
      # If Failover Clustering is enabled
      fci_metrics:
        enabled: true

Monitoring SQL Server Agent Jobs

To enable monitoring of SQL Server Agent jobs, the Datadog Agent must have access to the [msdb] database.
SQL Server Agent Jobs monitoring is not available for Azure SQL Database.

Monitoring of SQL Server Agent jobs is supported on SQL Server versions 2016 and newer. Starting from Agent v7.57, the Datadog Agent can collect SQL Server Agent job metrics and histories. To enable this feature, set enabled to true in the agent_jobs section of the SQL Server integration configuration file. The collection_interval and history_row_limit fields are optional.

instances:
  - dbm: true
    host: 'shopist-prod,1433'
    username: datadog
    password: '<PASSWORD>'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    agent_jobs:
      enabled: true
      collection_interval: 15
      history_row_limit: 10000

Collecting schemas

Datadog Agent v7.56+ and SQL Server 2017 or higher are required for SQL Server schema collection.

To enable this feature, use the collect_schemas option. Schemas are collected on databases for which the Agent has CONNECT access.

To collect schema information from RDS instances, you must grant the datadog user explicit CONNECT access to each database on the instance. For more information, see Grant the Agent access.

Use the database_autodiscovery option to avoid specifying each logical database. See the sample sqlserver.d/conf.yaml for more details.

init_config:
instances:
 # This instance detects every logical database automatically
  - dbm: true
        host: 'shopist-prod,1433'
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    database_autodiscovery: true
    collect_schemas:
      enabled: true
    database_metrics:
      # Optional: enable metric collection for indexes
      index_usage_metrics:
        enabled: true
# This instance only collects schemas and index metrics from the `users` database
  - dbm: true
        host: 'shopist-prod,1433'
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    database: users
    collect_schemas:
      enabled: true
    database_metrics:
      # Optional: enable metric collection for indexes
      index_usage_metrics:
        enabled: true

Note: For Agent v7.68 and below, use schemas_collection instead of collect_schemas.

One Agent connecting to multiple hosts

It is common to configure a single Agent host to connect to multiple remote database instances (see Agent installation architectures for DBM). To connect to multiple hosts, create an entry for each host in the SQL Server integration config.

Datadog recommends using one Agent to monitor no more than 30 database instances.

Benchmarks show that one Agent running on a t4g.medium EC2 instance (2 CPUs and 4GB of RAM) can successfully monitor 30 RDS db.t3.medium instances (2 CPUs and 4GB of RAM).
init_config:
instances:
  - dbm: true
    host: 'example-service-primary.example-host.com,1433'
    username: datadog
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    password: 'ENC[datadog_user_database_password]'
    tags:
      - 'env:prod'
      - 'team:team-discovery'
      - 'service:example-service'
  - dbm: true
    host: 'example-service–replica-1.example-host.com,1433'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    tags:
      - 'env:prod'
      - 'team:team-discovery'
      - 'service:example-service'
  - dbm: true
    host: 'example-service–replica-2.example-host.com,1433'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    tags:
      - 'env:prod'
      - 'team:team-discovery'
      - 'service:example-service'
    [...]

Running custom queries

To collect custom metrics, use the custom_queries option. See the sample sqlserver.d/conf.yaml for more details.

init_config:
instances:
  - dbm: true
    host: 'localhost,1433'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    custom_queries:
    - query: SELECT age, salary, hours_worked, name FROM hr.employees;
      columns:
        - name: custom.employee_age
          type: gauge
        - name: custom.employee_salary
           type: gauge
        - name: custom.employee_hours
           type: count
        - name: name
           type: tag
      tags:
        - 'table:employees'

Working with hosts through a remote proxy

If the Agent must connect to a database host through a remote proxy, all telemetry is tagged with the hostname of the proxy rather than the database instance. Use the reported_hostname option to set a custom override of the hostname detected by the Agent.

init_config:
instances:
  - dbm: true
    host: 'localhost,1433'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    reported_hostname: products-primary
  - dbm: true
    host: 'localhost,1433'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    reported_hostname: products-replica-1

Discovering ports automatically

SQL Server Browser Service, Named Instances, and other services can automatically detect port numbers. You can use this instead of hardcoding port numbers in connection strings. To use the Agent with one of these services, set the port field to 0.

For example, a Named Instance config:

init_config:
instances:
  - host: <hostname\instance name>
    port: 0

RDS インテグレーションをインストールする

AWS からより包括的なデータベースメトリクスとログを収集するには、RDS インテグレーションをインストールします。

参考資料