Rotate Agent Log Files¶
On this page
Overview¶
During normal operation, the Monitoring Agent and Backup Agent report a live account of all activity and operations to a log file. When a log file reaches a user-specified limit, the system must replace or rotate the log file.
On Linux systems, the logrotate
command automatically copies,
renames, compresses, and removes older archived log files.
For programs that do not have an interface to close the log file, use
copytruncate
command to rotate log files without stopping the process.
For Ops Manager, this allows you to rotate log files without restarting the backup
and Monitoring Agents.
Log Rotation With logrotate
¶
logrotate
is available on most Linux systems. Check the
logrotate.conf
configuration file exists in the /etc
folder or install
the logrotate
package.
Configure the behavior of the logrotate
command in the
logrotate.conf
configuration file. Open this file then add entries and
directives for the monitoring and Backup Agent log files.
The logrotate.conf
file includes a set of directives in a structured
format, for example:
In this example, the entries and directives in the logrotate.conf
configuration file will rotate the Backup Agent log file once it exceeds 10MB
in size and compress the old file using gzip (default). logrotate
rotates the log files for the Monitoring Agent
daily and compresses previous log files with gzip
. The copytruncate
directive ensures permits log rotation without restarting the agent
process.
Common logrotate Configuration Directives¶
See the Additional Information section below for
links to complete documentation of logrotate
.
compress
¶
Sets a global option to compress log
files after rotating each file. Place compress
within directive
blocks if only some log files require compression.
<backup agent log file path>
or <monitoring agent log file path>
¶
Sets commands specific to the Backup Agent or Monitoring Agent log
file. You set the name and location of the agent log files when you
installed the agents. The default log file path with agents installed
from the .rpm
and .deb
packages is
/var/log/mongodb-mms/monitoring-agent.log
or
/var/log/mongodb-mms/backup-agent.log
. For agents installed from
.tar.gz
archives the default log files are at
/log/mms-agent/monitoring-agent.log
and
/log/mms-agent/backup-agent.log
.
size
¶
Rotates the log file once it exceeds 10 megabytes in size. The file size is configurable.
copytruncate
¶
Rotates the log file without shutting down the agent software. This directive copies the contents of the current log file to a new archive file then deletes the contents of the current log file. The process adds new log messages to the, now empty, log file. Use this directive to rotate logs file without restarting the Backup and Monitoring Agents.
When using copytruncate
the create
option has no
effect because the old log file stays in place. There also is a small time
window between copying the log file and emptying it. In this mode,
logrotate
may lose some logging
information.
daily
, weekly
, monthly
¶
If you must rotate logs every day, week, or month, then use the
daily
, weekly
, monthly
directives and remove the size
directive. size
is not compatible with frequency-based log
rotation.
Global and Local Scope for Configuration Directives¶
Configuration directives have either a global scope or local scope.
In the example above, compress
is a global configuration directive and
size
and copytruncate
local directives. Place global
directives at the top of the logrotate.conf
file and apply to
all log files defined within the file. Local directives appear only in
a specific log file definition in the logrotate.conf
file. Local configuration directives have no effect on other log files.
Additional Information¶
See also the logrotate Man Page.