# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

public_url: "https://cloud.google.com/stackdriver/docs/solutions/agents/ops-agent/third-party/mongodb"
app_url: "https://www.mongodb.com/"
short_name: MongoDB
long_name: MongoDB
logo_path: /images/launcher/logos/mongodb.png # supplied by google technical writer
description: |-
  The MongoDB integration primarily collects database metrics, such as the number
  of operations and objects, as well as resource usage. The integration also
  collects logs and parses them into a JSON payload. The result includes fields
  for context, component, level, and message.

  Note: Metrics for MongoDB are collected on a per-collection level.
  A _collection_ is a group of documents and is analogous to a table in
  a relational database. A MongoDB integration with a high number of
  collections will produce a high volume of metrics, which can have cost
  implications.
minimum_supported_agent_version:
  metrics: 2.19.0
  logging: 2.10.0
supported_operating_systems: linux
platforms_to_skip:
  # MongoDB3.6 hit end of life in 2021 and is not supported on various distros.
  - debian-cloud:debian-11
  - debian-cloud:debian-12
  - debian-cloud:debian-12-arm64
  - ml-images:common-gpu-debian-11-py310
  - rocky-linux-cloud:rocky-linux-8-optimized-gcp-arm64
  - rocky-linux-cloud:rocky-linux-9
  - rocky-linux-cloud:rocky-linux-9-optimized-gcp
  - rocky-linux-cloud:rocky-linux-9-arm64
  - rocky-linux-cloud:rocky-linux-9-optimized-gcp-arm64
  - suse-cloud:sles-15
  - suse-cloud:sles-15-arm64
  - ubuntu-os-cloud:ubuntu-2004-lts
  - ubuntu-os-cloud:ubuntu-2004-lts-arm64
  - ubuntu-os-cloud:ubuntu-2204-lts
  - ubuntu-os-cloud:ubuntu-2204-lts-arm64
  - ubuntu-os-cloud:ubuntu-2404-lts-amd64
  - ubuntu-os-cloud:ubuntu-2404-lts-arm64
  - ubuntu-os-cloud:ubuntu-2410-amd64
  - ubuntu-os-cloud:ubuntu-minimal-2410-amd64
  - ubuntu-os-cloud:ubuntu-2410-arm64
  - ubuntu-os-cloud:ubuntu-minimal-2410-arm64
supported_app_version: ["2.6", "3.0+", "4.0+", "5.0"]
expected_metrics:
  - type: workload.googleapis.com/mongodb.cache.operations
    value_type: INT64
    kind: CUMULATIVE
    monitored_resources: [gce_instance]
    labels:
      - name: type
        value_regex: .*
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.collection.count
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
    labels:
      - name: database
        value_regex: .*
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.connection.count
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
    labels:
      - name: database
        value_regex: .*
      - name: type
        value_regex: .*
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.data.size
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
    labels:
      - name: database
        value_regex: .*
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.global_lock.time
    value_type: INT64
    kind: CUMULATIVE
    monitored_resources: [gce_instance]
    labels:
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.index.count
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
    labels:
      - name: database
        value_regex: .*
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.index.size
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
    labels:
      - name: database
        value_regex: .*
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.memory.usage
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
    labels:
      - name: database
        value_regex: .*
      - name: type
        value_regex: .*
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
    representative: true
  - type: workload.googleapis.com/mongodb.object.count
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
    labels:
      - name: database
        value_regex: .*
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.operation.count
    value_type: INT64
    kind: CUMULATIVE
    monitored_resources: [gce_instance]
    labels:
      - name: operation
        value_regex: .*
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.storage.size
    value_type: INT64
    kind: CUMULATIVE
    monitored_resources: [gce_instance]
    labels:
      - name: database
        value_regex: .*
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.database.count
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
    labels:
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.index.access.count
    value_type: INT64
    monitored_resources: [gce_instance]
    kind: GAUGE
    labels:
      - name: collection
        value_regex: .*
      - name: database
        value_regex: .*
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.document.operation.count
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
    labels:
      - name: database
        value_regex: .*
      - name: operation
        value_regex: .*
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.network.io.receive
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
    labels:
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.network.io.transmit
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
    labels:
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.network.request.count
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
    labels:
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.operation.time
    value_type: INT64
    kind: CUMULATIVE
    monitored_resources: [gce_instance]
    labels:
      - name: operation
        value_regex: insert|query|update|delete|getmore|command
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.session.count
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
    labels:
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.cursor.count
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
    labels:
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
  - type: workload.googleapis.com/mongodb.cursor.timeout.count
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
    labels:
      - name: instrumentation_source
        value_regex: agent.googleapis.com/mongodb
expected_logs:
  - log_name: mongodb
    fields:
      - name: jsonPayload.component
        type: string
        description: Categorization of the log message. A full list can be found in the [MongoDB documentation](https://docs.mongodb.com/manual/reference/log-messages/#std-label-log-message-components).
      - name: jsonPayload.ctx
        type: string
        description: The name of the thread issuing the log statement
        optional: true
      - name: jsonPayload.id
        type: number
        description: Log ID
        optional: true  # This is not optional in more recent versions of MongoDB.
      - name: jsonPayload.message
        type: string
        description: Log message
        value_regex: .+
      - name: jsonPayload.attributes
        type: object (optional)
        description: Object containing one or more key-value pairs for any additional attributes provided
        optional: true
      - name: jsonPayload.context
        type: string
        description: ''
        optional: true
      - name: jsonPayload.severity
        type: string
        description: Log entry level
        optional: true
      - name: jsonPayload.ms
        type: string
        description: ''
        optional: true
      - name: severity
        type: string
        description: ''
configuration_options:
  logs:
    - type: mongodb
      fields:
        - name: type
          default: null
          description: This value must be `mongodb`.
        - name: include_paths
          default: '[/var/log/mongodb/mongod.log*]'
          description: A list of filesystem paths to read by tailing each file. A wild card (`*`) can be used in the paths; for example, `/var/log/mongodb/*.log`.
        - name: exclude_paths
          default: null
          description: A list of filesystem path patterns to exclude from the set matched by `include_paths`.
        - name: record_log_file_path
          default: false
          description: If set to `true`, then the path to the specific file from which the log record was obtained appears in the output log entry as the value of the `agent.googleapis.com/log_file_path` label. When using a wildcard, only the path of the file from which the record was obtained is recorded.
        - name: wildcard_refresh_interval
          default: 60s
          description: The interval at which wildcard file paths in `include_paths` are refreshed. Given as a [time duration](https://pkg.go.dev/time#ParseDuration), for example `30s` or `2m`. This property might be useful under high logging throughputs where log files are rotated faster than the default interval.
  metrics:
    - type: mongodb
      fields:
        - name: type
          default: null
          description: This value must be `mongodb`.
        - name: endpoint
          default: localhost:27017
          description: The hostname, IP address, or UNIX domain socket. A port can be specified like `<hostname>:<port>`. If no port is specified the default 27017 will be used.
        - name: collection_interval
          default: 60s
          description: A [time duration](https://pkg.go.dev/time#ParseDuration) value, such as `30s` or `5m`.
        - name: username
          default: null
          description: Username for authentication with the MongoDB instance. Required if `password` is set.
        - name: password
          default: null
          description: Password for authentication with the MongoDB instance. Required if `username` is set.
        - name: insecure
          default: true
          description: Sets whether or not to use a secure TLS connection. If set to `false`, then TLS is enabled.
        - name: insecure_skip_verify
          default: false
          description: Sets whether or not to skip verifying the certificate. If `insecure` is set to `true`, then the `insecure_skip_verify` value is not used.
        - name: cert_file
          default: null
          description: Path to the TLS certificate to use for mTLS-required connections.
        - name: key_file
          default: null
          description: Path to the TLS key to use for mTLS-required connections, for example, the key used in `--tlsCertificateKeyFile`.
        - name: ca_file
          default: null
          description: Path to the CA certificate. As a client, this verifies the server certificate. If empty, the receiver uses the system root CA.
