Skip to main content
Sumo Logic

Collect MongoDB Logs and Metrics for Non-Kubernetes environments

Configure collection of logs and metrics for the Sumo Logic app for MongoDB, in a non-Kubernetes environment.

We use the Telegraf operator for MongoDB metric collection and Sumo Logic Installed Collector for collecting MongoDB logs. The diagram below illustrates the components of the MongoDB collection in a non-Kubernetes environment. Telegraf runs on the same system as MongoDB, and uses the MongoDB input plugin to obtain MongoDB metrics, and the Sumo Logic output plugin to send the metrics to Sumo Logic. Logs from MongoDB on the other hand are sent to either a Sumo Logic Local File source or Syslog source.

This section provides instructions for configuring metrics collection for the Sumo Logic App for MongoDB. Follow the below instructions to set up the metric collection:

  1. Configure Metrics Collection

    1. Configure a Hosted Collector

    2. Configure an HTTP Logs and Metrics Source

    3. Install Telegraf

    4. Configure and start Telegraf

  2. Configure Logs Collection

    1. Configure logging in MongoDB

    2. Configure Sumo Logic Installed Collector

Step 1 Configure Metrics Collection

  1. Configure a Hosted Collector

To create a new Sumo Logic hosted collector, perform the steps in the Configure a Hosted Collector section of the Sumo Logic documentation.

  1. Configure an HTTP Logs and Metrics Source

Create a new HTTP Logs and Metrics Source in the hosted collector created above by following these instructions. Make a note of the HTTP Source URL.

  1. Install Telegraf

Use the following steps to install Telegraf.

  1. Configure and start Telegraf

As part of collecting metrics data from Telegraf, we will use the MongoDB input plugin to get data from Telegraf and the Sumo Logic output plugin to send data to Sumo Logic. 

Create or modify telegraf.conf and copy and paste the text below:  

[[inputs.mongodb]]
  servers = ["mongodb://<username-CHANGME>:<password-CHANGEME>@127.0.0.1:27017"]
  gather_perdb_stats = true
  gather_col_stats = true
  [inputs.mongodb.tags]
    environment="prod"
    component="database"
    db_system="mongodb"
    db_cluster="mongodb_on_premise"

[[outputs.sumologic]]
  url = "<URL Created in Step b>”
  data_format = "prometheus"

Please enter values for the following parameters (marked in bold above):

  • In the input plugins section - [inputs.mongodb]: 

    • servers - The URL to the MongoDB server. This can be a comma-separated list to connect to multiple MongoDB servers. Please see this doc for more information on additional parameters for configuring the MongoDB input plugin for Telegraf.

    • In the tags section - [inputs.mongodb.tags]

      • environment - This is the deployment environment where the MongoDB cluster identified by the value of servers resides. For example: dev, prod or qa. While this value is optional we highly recommend setting it. 

      • db_cluster - Enter a name to identify this MongoDB cluster. This cluster name will be shown in the Sumo Logic dashboards. 

  • In the output plugins section - [outputs.sumologic]: 

    • url - This is the HTTP source URL created in step 3. Please see this doc for more information on additional parameters for configuring the Sumo Logic Telegraf output plugin.

Here’s an explanation for additional values set by this Telegraf configuration that we request you please do not modify as they will cause the Sumo Logic apps to not function correctly.

  • data_format - “prometheus” In the output plugins section - [outputs.sumologic] Metrics are sent in the Prometheus format to Sumo LogicComponent: “database” - In the input plugins section - [inputs.MongoDB]. This value is used by Sumo Logic apps to identify application components.

  • gather_perdb_stats: “true” - When true, collect per database stats.

  • gather_col_stats: “true” - When true, collect per collection stats.

  •  For all other parameters please see this doc for more properties that can be configured in the Telegraf agent globally.

Once you have finalized your telegraf.conf file, you can start or reload the telegraf service using instructions from the doc.

At this point, MongoDB metrics should start flowing into Sumo Logic.

Step 2 Configure Logs Collection

This section provides instructions for configuring log collection for MongoDB running on a non-kubernetes environment for the Sumo Logic App for MongoDB. 

By default, MongoDB logs are stored in a log file. MongoDB also supports forwarding logs via Syslog.

Sumo Logic supports collecting logs both via Syslog and a local log file. Utilizing Sumo Logic Cloud Syslog will require TCP TLS Port 6514 to be open in your network. Local log files can be collected via Installed collectors. Installed collector will require you to allow outbound traffic to Sumo Logic endpoints for collection to work. For detailed requirements for Installed collectors, see this page.

Based on your infrastructure and networking setup choose one of these methods to collect MongoDB logs and follow the instructions below to set up log collection:

  1. Configure logging in MongoDB

  2. Configure local log file or syslog collection

  3. Configure a Collector

  4. Configure a Source

Detail instructions for each are as follows:

  1. Configure logging in MongoDB

MongoDB supports logging via the following methods: syslog, local text log files and stdout. MongoDB logs have four levels of verbosity. To select a level, set loglevel to one of:

  • 0 is the MongoDB's default log verbosity level, to include Informational messages.
  • 1 to 5 increases the verbosity level to include Debug messages.

All logging settings are located in MongoDB.conf

  1. Configure MongoDB to log to a Local file or syslog

Configuring MongoDB logs to go to log files

By default, MongoDB logs are stored in /var/log/mongodb/mongodb.log. The default directory for log files is listed in the MongoDB.conf file. 

To configure the log output destination to a log file, use one of the following settings, either in the configuration file or on the command-line:

Configuration file:

Command-line:

Logs from the MongoDB log file can be collected via a Sumo Logic Installed collector and a Local File Source as explained in the next section.

Configuring MongoDB logs to stream via syslog

To configure the log output destination to syslog, use one of the following settings, either in the configuration file or on the command-line:

Configuration file:

Command-line:

To capture MongoDB logs using syslog, configure a syslog source on an Installed collector as explained in the next section.

  1. Configuring a Collector

To add an Installed collector, perform the steps as defined on the page Configure an Installed Collector.

  1. Configuring a Source

To add a Local File Source source for MongoDB do the following

To collect logs directly from your MongoDB machine, use an Installed Collector and a Local File Source. 

  1. Add a Local File Source.

  2. Configure the Local File Source fields as follows:

  • Name. (Required)
  • Description. (Optional)
  • File Path (Required). Enter the path to your error.log or access.log. The files are typically located in /var/log/mongodb/mongodb.log. If you are using a customized path, check the MongoDB.conf file for this information. 
  • Source Host. Sumo Logic uses the hostname assigned by the OS unless you enter a different host name
  • Source Category. Enter any string to tag the output collected from this Source, such as MongoDB/Logs. (The Source Category metadata field is a fundamental building block to organize and label Sources. For details see Best Practices.)
  • Fields. Set the following fields:
    • component = database
    • db_system = mongodb
    • db_cluster = <Your_MongoDB_Cluster_Name>
    • environment = <Environment_Name>, such as Dev, QA or Prod.

  1. Configure the Advanced section:

  • Enable Timestamp Parsing. Select Extract timestamp information from log file entries.
  • Time Zone. Choose the option, Ignore time zone from log file and instead use, and then select your MongoDB Server’s time zone.
  • Timestamp Format. The timestamp format is automatically detected.
  • Encoding. Select UTF-8 (Default).
  • Enable Multiline Processing. Detect messages spanning multiple lines
    • Infer Boundaries - Detect message boundaries automatically
  1. Click Save.

To add a Syslog Source source for MongoDB do the following

  1. Add a  Syslog source in the installed collector configured in the previous step.

  2. Configure the Syslog Source fields as follows:

  • Name. (Required)
  • Description. (Optional)
  • Protocol: UDP
  • Port: 514 (as entered while configuring logging in Step b.)
  • Source Category. Enter any string to tag the output collected from this Source, such as MongoDB/Logs. (The Source Category metadata field is a fundamental building block to organize and label Sources. For details see Best Practices.)
  • Fields. Set the following fields:
    • component = database
    • db_system = MongoDB
    • db_cluster = <Your_MongoDB_Cluster_Name>
    • environment = <Environment_Name>, such as Dev, QA or Prod.

  1. Configure the Advanced section:

    • Enable Timestamp Parsing. Select Extract timestamp information from log file entries.
    • Time Zone. Choose the option, Ignore time zone from log file and instead use, and then select your MongoDB Server’s time zone.
    • Timestamp Format. The timestamp format is automatically detected.
    • Encoding. Select UTF-8 (Default).
  2. Click Save.

At this point, MongoDB logs should start flowing into Sumo Logic.