MySQL Source Template

The MySQL source template creates an OpenTelemetry configuration that can be pushed to a remotely managed OpenTelemetry collector (abbreviated as otelcol). By creating this source template and pushing the config to the appropriate OpenTelemetry agent, you can ensure collection of MySQL logs and metrics to Sumo Logic.
Fields creation in Sumo Logic for Local File​
If not already present, the following Fields are created as part of source template creation.
sumo.datasource
. Fixed value of mysql.deployment.environment
. This is a user-configured field set at the time of collector installation. It identifies the environment where the host resides, such asdev
,prod
, orqa
.db.cluster.name
. User configured. Enter a uniquely identifiable name for your mysql cluster to show in the Sumo Logic dashboards.db.node.name
. Includes the value of the hostname of the machine which is being monitored.
Prerequisites​
For metrics collection​
-
The MySQL metrics receiver collects metrics by querying MySQL's global status and InnoDB tables. This app has been tested with following MySQL versions: 8.0
-
Make sure to set the MySQL user's password as an environment variable for the OpenTelemetry agent. Refer to Setting Environment Variables with Secret Values for Source Templates.
For logs collection​
MySQL logs are stored in log files. Slow query logs must be explicitly enabled to be able to be written to a log file. To configure the MySQL log file(s), locate your local my.cnf
configuration file in the database directory.
- Open
my.cnf
in a text editor. - Set the following parameters in the
[mysqld]
section:
[mysqld]
log_error = /var/log/mysql/error.log
slow_query_log=1
slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time=2
- Error Logs. By default, error logs are enabled and are logged at file specified by the
log_error
key. - Slow Query Logs.
slow_query_log=1
enables logging of slow queries to the file specified byslow_query_log_file
. Settinglong_query_time=2
will cause queries that take more than two seconds to execute to be logged. The default value oflong_query_time
is 10 seconds. - General Query Logs. We do not recommend enabling
general_log
for performance reasons. These logs are not used by the Sumo Logic MySQL app.
- Save the
my.cnf
file. - Restart the MySQL server:
sudo mysql.server restart
Ensure that the otelcol has adequate permissions to access all log file paths. Execute the following command:
sudo setfacl -R -m d:u:otelcol-sumo:r-x,u:otelcol-sumo:r-x,g:otelcol-sumo:r-x <PATH_TO_LOG_FILE>
For Linux systems with ACL Support, the otelcol install process should have created the ACL grants necessary for the otelcol system user to access default log locations. You can verify the active ACL grants using the getfacl
command. Install the ACL in your Linux environment, if not installed.
The required ACL may not be supported for some rare cases, for example, Linux OS Distro, which is officially not supported by Sumo Logic. In this case, you can run the following command to explicitly grant the permissions.
sudo setfacl -R -m d:u:otelcol-sumo:r-x,d:g:otelcol-sumo:r-x,u:otelcol-sumo:r-x,g:otelcol-sumo:r-x <PATH_TO_LOG_FILE>
Run the above command for all the log files in the directory that need to be ingested, which are not residing in the default location.
If Linux ACL Support is not available, traditional Unix-styled user and group permission must be modified. It should be sufficient to add the otelcol system user to the specific group that has access to the log files.
For Windows systems, the collected log files should be accessible by the SYSTEM group. Use the following set of PowerShell commands if the SYSTEM group does not have access.
$NewAcl = Get-Acl -Path "<PATH_TO_LOG_FILE>"
# Set properties
$identity = "NT AUTHORITY\SYSTEM"
$fileSystemRights = "ReadAndExecute"
$type = "Allow"
# Create a new rule
$fileSystemAccessRuleArgumentList = $identity, $fileSystemRights, $$fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList
# Apply new rule
$NewAcl.SetAccessRule($fileSystemAccessRule)
Set-Acl -Path "<PATH_TO_LOG_FILE>" -AclObject $NewAcl
Configuring the MySQL source template​
You can follow the below steps to set a remotely managed OpenTelemetry collector and push the source template to it.
Step 1: Set up remotely managed OpenTelemetry collector​
In this step, we'll install the collector and add a uniquely identifiable tag to these collectors.
- Classic UI. In the main Sumo Logic menu, select Manage Data > Collection > OpenTelemetry Collection.
New UI. In the Sumo Logic top menu select Configuration, and then under Data Collection select OpenTelemetry Collection. You can also click the Go To... menu at the top of the screen and select OpenTelemetry Collection. - On the OpenTelemetry Collection page, click + Add Collector.
- In the Set up Collector step:
- Choose your platform (for example, Linux).
- Enter your Installation Token.
- Under Tag data on Collector level, add a new tag to identify these collectors as having Apache running on them (for example,
application = Apache
). - Leave the Collector Settings at their default values to configure collectors as remotely managed.
- Under Generate and run the command to install the collector, copy and run the installation command in your system terminal where the collector needs to be installed.
- After installation is complete, click Next to proceed.
- Select a source template (for example, Apache source template) to start collecting logs from all linked collectors, then proceed with the data configuration.
To revisit this screen later: From the Classic UI, select Manage Data > Collection > Source Template. From the New UI, select Configuration > Source Template.
Step 2: Configure the source template​
In this step, you will configure the yaml required for MySQL collection. Below are the inputs required for configuration:
- Name. Name of the source template.
- Description. Description for the source template.
- Error log path. Location where the SQL Errors are logged. Please refer to your my.cnf file.
- Slow Transaction log file path (optional). Location where the Slow SQL transactions are logged. Please refer to your my.cnf file.
- Endpoint. The URL of the MySQL endpoint (default:
localhost:3306
). - Username. Enter the MySQL username.
- Password Environment Variable Name. Enter the MySQL password environment variable name.
- Fields/Metadata. You can provide any customer fields to be tagged with the data collected. By default, Sumo Logic tags
_sourceCategory
with the value otel/mysql user needs to provide the value fordb.cluster.name
.
Advance options for log collection can be used as follows:
- Timestamp Format. By default, Sumo Logic will automatically detect the timestamp format of your logs. However, you can manually specify a timestamp format for a source by configuring the following:
- Timestamp locator. Use a Go regular expression to match the timestamp in your logs. Ensure the regular expression includes a named capture group called
timestamp_field
. - Layout. Specify the exact layout of the timestamp to be parsed. For example,
- %Y-%m-%dT%H:%M:%S.%LZ
. To learn more about the formatting rules, refer to this guide. - Location (Time zone). Define the geographic location (timezone) to use when parsing a timestamp that does not include a timezone. The available locations depend on the local IANA Time Zone database. For example,
America/New_York
. See more examples here.
- Timestamp locator. Use a Go regular expression to match the timestamp in your logs. Ensure the regular expression includes a named capture group called
Processing Rules. You can add processing rules for logs/metrics collected. To learn more, refer to Processing Rules.
Step 3: Push the source template to the desired remotely managed collectors​
A new source template will always be created with the latest version of the source template.
Follow the below steps to create a data collection configuration to gather the required logs and link them to all the collectors with the help of collector tags.
- Complete the source template form with the name and file path for your logs (for example, error logs or access logs), then click Next.
- Under Link Collectors, you will have the option to link the collectors using the collector name or by adding tags to find the group of collectors (for example,
application = Apache
). - Preview and confirm the collectors that will be linked (fetched automatically) to the newly created source template.
- Click Next to complete the source template creation. In the background, the system will apply the configuration to all the linked collectors and will start collecting the respective telemetry data from the remote host (in the example, it would start collecting Apache error logs).
- Click the Log Search or Metrics Search icons to search for and analyze your data collected for this source template.
Refer to the changelog for information on periodic updates to this source template.