Skip to content

MongoDB

MongoDB is a widely used NoSQL database designed for scalability and flexibility. It stores data in a JSON-like format (BSON), enabling dynamic schema design and efficient handling of unstructured data. MongoDB is known for its high performance in read- and write-heavy environments and is commonly used for real-time analytics, content management, and IoT systems. It supports horizontal scaling through sharding and provides built-in replication for high availability.

MongoDB Monitoring in KloudMate helps you observe the health, performance, and behavior of your MongoDB servers by collecting metrics and logs using the KloudMate Agent powered by OpenTelemetry. This allows you to monitor MongoDB instances running on AWS EC2, Azure Virtual Machines, or on-premise servers from a centralized view.

With MongoDB Monitoring enabled, KloudMate collects telemetry at multiple levels, including:

  • Server-level performance metrics
  • Database and collection-level metrics
  • Connection, operation, and lock behavior
  • Network and storage usage
  • MongoDB server logs

This visibility helps identify performance bottlenecks, abnormal query behavior, resource saturation, and availability issues.

Before configuring MongoDB Monitoring, ensure the following:

  1. MongoDB server is running
  2. Supported MongoDB versions: 4.0+, 5.0, 6.0, 7.0
  3. KloudMate Agent installed on the MongoDB host
  4. MongoDB user configured with least-privilege access.

MongoDB recommends creating a user with the clusterMonitor role to collect metrics. Refer to lpu.sh for an example of how to configure these permissions.

Example:

mongosh
use admin
db.createUser({
  user: "USER",
  pwd: "PASSWORD",
  roles: [{ role: "clusterMonitor", db: "admin" }]
})
exit

Step 1: Access Agents and OpenTelemetry Collector Configuration

Section titled “Step 1: Access Agents and OpenTelemetry Collector Configuration”
  1. Log in to the KloudMate platform
  2. Navigate to Settings → Agents
  3. Select the agent running on the MongoDB host
  4. Open Collector Configuration from the agent actions
  5. The configuration editor opens, allowing you to modify the YAML directly

image

Step 2: Add Required Extensions and Receivers

Section titled “Step 2: Add Required Extensions and Receivers”

Extensions

Add the following extensions to support health checks, debugging, and local storage:

  extensions:
    file_storage:
      create_directory: true

Receivers

Two receivers can be used with MongoDB:

  • MongoDB Receiver – Collects MongoDB metrics
  • File Log Receiver – Collects MongoDB logs

If you only need metrics, configure only the MongoDB receiver.

receivers:
  mongodb:
    hosts:
      - endpoint: localhost:27017
    username: otel  #Change the correct username
    password: PASSWD  #change the correct password
    collection_interval: 60s
    initial_delay: 1s
    tls:
      insecure: true
      insecure_skip_verify: true
  filelog:
    include: [/var/log/mongodb/*.log]
    storage: file_storage
    retry_on_failure:
      enabled: true

Set up the processor component to identify resource information from the host and either append or replace the resource values in the telemetry data with this information.

Choose one configuration based on where MongoDB is running.

  • Server (On-premise / Non-cloud / Cloud)
processors:
  batch:
    send_batch_size: 5000
    timeout: 10s

  resourcedetection:
    detectors: [system]
    system:
      resource_attributes:
        host.name:
          enabled: true
        host.id:
          enabled: true
        os.type:
          enabled: false
  resource:
    attributes:
      - key: service.name
        action: insert
        from_attribute: host.name
  • AWS EC2:

(Optional) To collect EC2 tags, attach an IAM role with EC2:DescribeTags permission.

processors:
  batch:
    send_batch_size: 5000
    timeout: 10s

  resourcedetection/ec2:
    detectors:  ["ec2"]
    ec2:
      tags:
        - ^tag1$
        - ^tag2$
        - ^label.*$ 
        - ^Name$

  resource:
    attributes:
      - key: service.name
        action: insert
        from_attribute: ec2.tag.Name
      - key: service.instance.id
        action: insert
        from_attribute: host.id
  • Azure Virtual Machines:
processors:
  batch:
    send_batch_size: 5000
    timeout: 10s

  resourcedetection/azure:
    detectors: ["azure"]
    azure:
      tags:
        - ^tag1$
        - ^tag2$
        - ^label.*$
        - ^Name$

  resource:
    attributes:
      - key: service.name
        action: insert
        from_attribute: azure.vm.name
      - key: service.instance.id
        action: insert
        from_attribute: host.id

Configure the KloudMate backend exporter and define pipelines for metrics and logs.

exporters:
  debug:
    verbosity: detailed
  otlphttp:
    endpoint: 'https://otel.kloudmate.com:4318'
    headers:
      Authorization: xxxxxxxx  # Use the auth key

service:
  pipelines:

    metrics:
      receivers: [mongodb]
      processors: [batch, resourcedetection, resource]  # Apply the correct resourcedetection
      exporters: [otlphttp]

    logs:
      receivers: [filelog]
      processors: [batch, resourcedetection, resource]  # Apply the correct resourcedetection
      exporters: [otlphttp]

  extensions: [health_check, pprof, zpages, file_storage]

Step 5: Save Configuration and Restart Agent

Section titled “Step 5: Save Configuration and Restart Agent”

After updating the configuration, click Save Configuration in the KloudMate UI.

image

You can also restart the agent from your server’s console.

For Linux:

  1. Execute the following commands:
systemctl restart kmagent
systemctl status kmagent

These commands restart the KloudMate Agent and display its current status.

For Windows

  1. Open the Services window
    • Press Win + R, type services.msc, and press OK
    • Or search for Services from the Start menu
  2. Locate the KloudMate Agent service.
  3. Right-click the service and select Restart.

After restarting the agent, verify that MongoDB metrics and logs are visible in the KloudMate dashboard.

Verify that metrics are flowing into KloudMate using the Explore view.

After the agent restarts:

  1. Log in to KloudMate
  2. Navigate to Explore
  3. Select OpenTelemetry → Metrics
  4. Choose a MongoDB metric and run the query

Seeing time-series data confirms that MongoDB telemetry is flowing successfully.

image

KloudMate provides prebuilt MongoDB dashboards through dashboard templates. These dashboards visualize MongoDB server performance, operations, storage, and resource usage.

To import and start using these templates, follow the steps described in Import from Templates.

MongoDB Monitoring automatically collects commonly used MongoDB metrics when enabled.

Example Metrics

Metric NameDescription
mongodb_connection_countThe number of connections.
mongodb_operation_countThe number of operations executed.
mongodb_operation_latency_timeThe latency of operations.
mongodb_data_sizeThe size of the collection. Data compression does not affect this value.
mongodb_storage_sizeThe total amount of storage allocated to this collection.
mongodb_network_io_receiveThe number of bytes received.
mongodb_network_io_transmitThe number of bytes transmitted.
mongodb_lock_acquire_countNumber of times the lock was acquired in the specified mode.
mongodb_lock_acquire_timeCumulative wait time for the lock acquisitions.
mongodb_healthThe health status of the server.
mongodb_uptimeThe amount of time that the server has been running.

For the complete metrics list, refer to the metrics reference.

Streaming MongoDB Metrics & Logs to KloudMate Using Fluent Bit

Monitoring MongoDB with KloudMate Using Docker Compose