- 重要な情報
- はじめに
- 用語集
- ガイド
- エージェント
- インテグレーション
- OpenTelemetry
- 開発者
- API
- CoScreen
- アプリ内
- Service Management
- インフラストラクチャー
- アプリケーションパフォーマンス
- 継続的インテグレーション
- ログ管理
- セキュリティ
- UX モニタリング
- 管理
MongoDB インテグレーション
でカスタムメトリクスを収集するには、Agent の構成ディレクトリ
のルートにある conf.d/mongo.d/conf.yaml
ファイルの custom_queries
オプションを使用します。詳細については、サンプル mongo.d/conf.yaml
を参照してください。
custom_queries
には以下のオプションがあります:
metric_prefix
: 各メトリクスは選択したプレフィックスで始まります。query
: JSON オブジェクトとして実行する Mongo runCommand
クエリです。注: Agent では count
、find
、aggregates
クエリのみサポートされます。database
: メトリクスの収集先となる MongoDB データベースです。fields
: count
クエリでは無視されます。各フィールドを表す順不同のリストです。未指定および欠落フィールドは無視します。各 fields
には 3 つの必須データがあります:field_name
: データを取得するフィールドの名前。name
: 完全なメトリクス名を形成するために metric_prefix に付けるサフィックス。type
が tag
である場合、この列はタグとして扱われ、この特定のクエリによって収集されたすべてのメトリクスに適用されます。type
: 送信方法 (gauge
、count
、rate
など)。これを tag
に設定して、行の各メトリクスにこの列の項目の名前と値でタグ付けすることもできます。count
タイプを使用して、同じタグを持つか、タグのない複数の行を返すクエリの集計を実行できます。tags
: 各メトリクスに適用するタグのリスト(上記で指定)。count_type
: count
クエリに対してのみ、カウント結果を送信するメソッド(gauge
、count
、rate
など)として機能します。非カウントクエリでは無視されます。以下の例では、次の 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:foo
と name: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:true
と is_admin:false
の 2 つのタグを持つ 1 つの gauge
メトリクス mongo.example3.user.age
(各タグのユーザーの平均年齢を表す)が生成されます。
注: Mongo YAML ファイルを更新した後、Datadog Agentを再起動 します。
結果を確認するには、メトリクスエクスプローラー を使用してメトリクスを検索します。
Agent のステータスサブコマンドを実行
し、Checks セクションで mongo
を探します。さらに、Agent のログ
から有用な情報が得られることもあります。
お役に立つドキュメント、リンクや記事: