To find out if this integration is available in your organization, see your Datadog Integrations page or ask your organization administrator.

To initiate an exception request to enable this integration for your organization, email support@ddog-gov.com.

概要

MongoDB インテグレーションでカスタムメトリクスを収集するには、Agent の構成ディレクトリのルートにある conf.d/mongo.d/conf.yaml ファイルの custom_queries オプションを使用します。詳細については、サンプルの mongo.d/conf.yaml を参照してください。

構成

custom_queries には以下のオプションがあります:

  • metric_prefix: 各メトリクスは選択したプレフィックスで始まります。
  • query: JSON オブジェクトとして実行する Mongo runCommand クエリです。: Agent では countfindaggregates クエリのみサポートされます。
  • database: メトリクスを収集する MongoDB データベースです。
  • fields: count クエリでは無視されます。各フィールドを表す順不同のリストです。未指定および欠落フィールドは無視します。各 fields には 3 つの必須データがあります:
    • field_name: データを取得するフィールドの名前。
    • name: 完全なメトリクス名を形成するために metric_prefix に付けるサフィックス。typetag である場合、この列はタグとして扱われ、この特定のクエリによって収集されたすべてのメトリクスに適用されます。
    • type: 送信メソッド (gaugecountrate など)。これを tag に設定して、行の各メトリクスにこの列の項目の名前と値でタグ付けすることもできます。count タイプを使用して、同じタグを持つか、タグのない複数の行を返すクエリの集計を実行できます。
  • tags: 各メトリクスに適用するタグのリスト(上記で指定)。
  • count_type: count クエリに対してのみ、カウント結果を送信するメソッド (gaugecountrate など) として機能します。非カウントクエリでは無視されます。

以下の例では、次の Mongo コレクション user_collection が使用されます。

{ name: "foo", id: 12345, active: true, age:45, is_admin: true}
{ name: "bar", id: 67890, active: false, age:25, is_admin: true}
{ name: "foobar", id: 16273, active: true, age:35, is_admin: false}

クエリタイプを選択すると例が表示されます。

所定の時間にアクティブユーザーの数を監視するには、次のような Mongo count コマンドを実行します:

db.runCommand( {count: user_collection, query: {active:true}})

mongo.d/conf.yaml ファイル内の次の custom_queries YAML コンフィギュレーションに対応するクエリ:

custom_queries:
  - metric_prefix: mongo.users
    query: {"count": "user_collection", "query": {"active":"true"}}
    count_type: gauge
    tags:
      - user:active

これにより、user:active の 1 つのタグを持つ 1 つの gauge メトリクス mongo.users が生成されます。

: 定義されているメトリクスタイプgauge です。

ユーザーの平均年齢を監視するには、次のような Mongo find コマンドを実行します。

db.runCommand( {find: user_collection, filter: {active:true} )

mongo.d/conf.yaml ファイル内の次の custom_queries YAML コンフィギュレーションに対応するクエリ:

custom_queries:
  - metric_prefix: mongo.example2
    query: {"find": "user_collection", "filter": {"active":"true"}}
    fields:
      - field_name: name
        name: name
        type: tag
      - field_name: age
        name: user.age
        type: gauge

これにより、name:fooname:foobar の 2 つのタグを持つ 1 つの gauge メトリクス mongo.example2.user.age が生成されます。

: 定義されているメトリクスタイプgauge です。

管理者および非管理者ユーザーの平均年齢を監視するには、次のような Mongo aggregate コマンドを実行します:

db.runCommand(
              {
                'aggregate': "user_collection",
                'pipeline': [
                  {"$match": {"active": "true"}},
                  {"$group": {"_id": "$is_admin", "age_avg": {"$avg": "$age"}}}
                ],
                'cursor': {}
              }
            )

mongo.d/conf.yaml ファイル内の次の custom_queries YAML コンフィギュレーションに対応するクエリ:

custom_queries:
  - metric_prefix: mongo.example3
    query: {"aggregate": "user_collection","pipeline": [{"$match": {"active": "true"}},{"$group": {"_id": "$is_admin", "age_avg": {"$avg": "$age"}}}],"cursor": {}}
    fields:
      - field_name: age_avg
        name: user.age
        type: gauge
      - field_name: _id
        name: is_admin
        type: tag
    tags:
      - test:mongodb

これにより、is_admin:trueis_admin:false の 2 つのタグを持つ 1 つの gauge メトリクス mongo.example3.user.age(各タグのユーザーの平均年齢を表す)が生成されます。

: Mongo YAML ファイルを更新した後、Datadog Agentを再起動します。

検証

結果を確認するには、メトリクスエクスプローラーを使用してメトリクスを検索します。

デバッグ

Agent のステータスサブコマンドを実行し、Checks セクションで mongo を探します。さらに、Agent のログから有用な情報が得られることもあります。

その他の参考資料

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