# Copyright 2025 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.

type: mongodb

status:
  class: receiver
  stability:
    beta: [metrics]

resource_attributes:
  database:
    description: The name of a database.
    type: string

attributes:
  database:
    description: The name of a database.
    type: string
  collection:
    description: The name of a collection.
    type: string
  memory_type:
    name_override: type
    description: The type of memory used.
    type: string
    enum:
      - resident
      - virtual
  operation:
    description: The MongoDB operation being counted.
    type: string
    enum:
      - insert
      - query
      - update
      - delete
      - getmore
      - command
  connection_type:
    name_override: type
    description: The status of the connection.
    type: string
    enum:
      - active
      - available
      - current
  type:
    description: The result of a cache request.
    type: string
    enum:
      - hit
      - miss
  lock_type:
    description: The Resource over which the Lock controls access
    type: string
    enum:
      - parallel_batch_write_mode
      - replication_state_transition
      - global
      - database
      - collection
      - mutex
      - metadata
      - oplog
  lock_mode:
    description: The mode of Lock which denotes the degree of access
    type: string
    enum:
      - shared
      - exclusive
      - intent_shared
      - intent_exclusive

metrics:
  mongodb.cache.operations:
    description: The number of cache operations of the instance.
    unit: "{operations}"
    enabled: true
    sum:
      aggregation_temporality: cumulative
      value_type: int
      monotonic: true
    attributes: [type]
  mongodb.collection.count:
    description: The number of collections.
    unit: "{collections}"
    enabled: true
    sum:
      aggregation_temporality: cumulative
      value_type: int
      monotonic: false
    attributes: [database]
  mongodb.data.size:
    description: The size of the collection. Data compression does not affect this value.
    unit: By
    enabled: true
    sum:
      aggregation_temporality: cumulative
      value_type: int
      monotonic: false
    attributes: [database]
  mongodb.connection.count:
    description: The number of connections.
    unit: "{connections}"
    enabled: true
    sum:
      value_type: int
      aggregation_temporality: cumulative
      monotonic: false
    attributes: [database, connection_type]
  mongodb.extent.count:
    description: The number of extents.
    unit: "{extents}"
    enabled: true
    sum:
      aggregation_temporality: cumulative
      value_type: int
      monotonic: false
    attributes: [database]
  mongodb.global_lock.time:
    description: The time the global lock has been held.
    unit: ms
    enabled: true
    sum:
      aggregation_temporality: cumulative
      value_type: int
      monotonic: true
    attributes: []
  mongodb.index.count:
    description: The number of indexes.
    unit: "{indexes}"
    enabled: true
    sum:
      aggregation_temporality: cumulative
      value_type: int
      monotonic: false
    attributes: [database]
  mongodb.index.size:
    description: Sum of the space allocated to all indexes in the database, including free index space.
    unit: By
    enabled: true
    sum:
      aggregation_temporality: cumulative
      value_type: int
      monotonic: false
    attributes: [database]
  mongodb.memory.usage:
    description: The amount of memory used.
    unit: By
    enabled: true
    sum:
      aggregation_temporality: cumulative
      value_type: int
      monotonic: false
    attributes: [database, memory_type]
  mongodb.object.count:
    description: The number of objects.
    unit: "{objects}"
    enabled: true
    sum:
      aggregation_temporality: cumulative
      value_type: int
      monotonic: false
    attributes: [database]
  mongodb.operation.count:
    description: The number of operations executed.
    unit: "{operations}"
    enabled: true
    sum:
      aggregation_temporality: cumulative
      value_type: int
      monotonic: true
    attributes: [operation]
  mongodb.storage.size:
    description: The total amount of storage allocated to this collection.
    extended_documentation: If collection data is compressed it reflects the compressed size.
    unit: By
    enabled: true
    sum:
      aggregation_temporality: cumulative
      value_type: int
      monotonic: true
    attributes: [database]
  mongodb.database.count:
    description: The number of existing databases.
    unit: "{databases}"
    enabled: true
    sum:
      value_type: int
      aggregation_temporality: cumulative
      monotonic: false
    attributes: []
  mongodb.index.access.count:
    description: The number of times an index has been accessed.
    unit: "{accesses}"
    enabled: true
    sum:
      value_type: int
      aggregation_temporality: cumulative
      monotonic: false
    attributes: [database, collection]
  mongodb.document.operation.count:
    description: The number of document operations executed.
    unit: "{documents}"
    enabled: true
    sum:
      value_type: int
      aggregation_temporality: cumulative
      monotonic: false
    attributes: [database, operation]
  mongodb.network.io.receive:
    description: The number of bytes received.
    unit: By
    enabled: true
    sum:
      value_type: int
      aggregation_temporality: cumulative
      monotonic: false
    attributes: []
  mongodb.network.io.transmit:
    description: The number of by transmitted.
    unit: By
    enabled: true
    sum:
      value_type: int
      aggregation_temporality: cumulative
      monotonic: false
    attributes: []
  mongodb.network.request.count:
    description: The number of requests received by the server.
    unit: "{requests}"
    enabled: true
    sum:
      value_type: int
      aggregation_temporality: cumulative
      monotonic: false
    attributes: []
  mongodb.operation.time:
    description: The total time spent performing operations.
    unit: ms
    enabled: true
    sum:
      value_type: int
      aggregation_temporality: cumulative
      monotonic: true
    attributes: [operation]
  mongodb.session.count:
    description: The total number of active sessions.
    unit: "{sessions}"
    enabled: true
    sum:
      value_type: int
      aggregation_temporality: cumulative
      monotonic: false
    attributes: []
  mongodb.cursor.count:
    description: The number of open cursors maintained for clients.
    unit: "{cursors}"
    enabled: true
    sum:
      value_type: int
      aggregation_temporality: cumulative
      monotonic: false
    attributes: []
  mongodb.cursor.timeout.count:
    description: The number of cursors that have timed out.
    unit: "{cursors}"
    enabled: true
    sum:
      value_type: int
      aggregation_temporality: cumulative
      monotonic: false
    attributes: []
  mongodb.lock.acquire.count:
    description: Number of times the lock was acquired in the specified mode.
    unit: "{count}"
    enabled: false
    sum:
      value_type: int
      aggregation_temporality: cumulative
      monotonic: true
    attributes: [database, lock_type, lock_mode]
  mongodb.lock.acquire.wait_count:
    description: Number of times the lock acquisitions encountered waits because the locks were held in a conflicting mode.
    unit: "{count}"
    enabled: false
    sum:
      value_type: int
      aggregation_temporality: cumulative
      monotonic: true
    attributes: [database, lock_type, lock_mode]
  mongodb.lock.acquire.time:
    description: Cumulative wait time for the lock acquisitions.
    unit: "microseconds"
    enabled: false
    sum:
      value_type: int
      aggregation_temporality: cumulative
      monotonic: true
    attributes: [database, lock_type, lock_mode]
  mongodb.lock.deadlock.count:
    description: Number of times the lock acquisitions encountered deadlocks.
    unit: "{count}"
    enabled: false
    sum:
      value_type: int
      aggregation_temporality: cumulative
      monotonic: true
    attributes: [database, lock_type, lock_mode]
