Use log rotation for Ops Agent self logs Stay organized with collections Save and categorize content based on your preferences.
The Ops Agent writes to a log file calledlogging-module.log. When theagent runs unattended for long periods or when a problem occurs, this"self log" file can consume all available disk space. This document describeshow to use log rotation to prevent this problem.
Ops Agent version 2.31.0 introducesa configurable log-rotation feature built into the agent. If you are runningOps Agent version 2.31.0 or newer, thenyou can use the built-in log-rotation feature; seeConfigure log rotation in the Ops Agent.
You can also manage log rotation manually. You might need a manual processif you are using a version of the Ops Agent without built-in log rotation,or if you prefer to rotate your logs manually. SeeSet up self-log filerotation on Linux VMs for one possible approach.
Configure log rotation in the Ops Agent
This section describes how to modify the default log-rotation configurationused by Ops Agent to rotate its logs automatically.Using this feature requires Ops Agent version2.31.0 or newer.
Default configuration
The Ops Agent uses thedefault_self_log_file_rotation entry toconfigure log rotation. This configuration entry takes three options;the following snippet shows the options and their default values:
default_self_log_file_rotation: enabled: true max_file_size_megabytes: 400 backup_count: 1
Thedefault_self_log_file_rotation configuration takes three options:
enabled: Whether log rotation is enabled; default istrue.max_file_size_megabytes: The maximum size the log file can reach beforeit is backed up by log rotation.Measured in megabytes (10242 bytes). Default is 400, minimumvalid value is 1.backup_count: The number of old log files to retain. Default is 1,minimum valid value is 1.
User configuration of log rotation
To modify the default log-rotation configuration, you override thatconfiguration by redefining the configuration in the Ops Agentuser-configuration file:
- On Linux:
/etc/google-cloud-ops-agent/config.yaml - On Windows:
C:\Program Files\Google\Cloud Operations\Ops Agent\config\config.yaml
To configure log rotation in the Ops Agent, add aglobal sectionto the user configuration file and include the configuration elementdefault_self_log_file_rotation in theglobal section. You mightalready have logging or metrics pipelines in the this configuration file;add theglobal section after your pipelines. The result, specifying alloptions and default values, looks like the following:
logging: ...metrics: ...global: default_self_log_file_rotation: enabled: true max_file_size_megabytes: 400 backup_count: 1
Example configurations
To disable log rotation by the Ops Agent, specify theenabled option with thevaluefalse:
logging: ...metrics: ...global: default_self_log_file_rotation: enabled: false
To rotate the log when the log file reaches 20 MB and keep 5 backups(6 files total):
logging: ...metrics: ...global: default_self_log_file_rotation: max_file_size_megabytes: 20 backup_count: 5
To rotate the log when the log file reaches 2,000 MB (2 GB)and keep 1 backup (2 files total):
logging: ...metrics: ...global: default_self_log_file_rotation: max_file_size_megabytes: 2000
To rotate the log when the log file reaches 400 MB and keep 2 backups(3 files total):
logging: ...metrics: ...global: default_self_log_file_rotation: backup_count: 2
If you make frequent changes as you refine your log-rotation configuration,remember torestart the agent toapply your changes.
Set up self-log file rotation on Linux VMs
To limit the size of the logging sub-agent log at/var/log/google-cloud-ops-agent/subagents/logging-module.log, install andconfigure thelogrotate utility.
Install the
logrotateutility by running the following command:On Debian and Ubuntu
sudoaptinstalllogrotateOn CentOS, RHEL and Fedora
sudoyuminstalllogrotateCreate a
logrotateconfig file at/etc/logrotate.d/google-cloud-ops-agent.conf.sudotee/etc/logrotate.d/google-cloud-ops-agent.conf >/dev/null <<EOF# logrotate config to rotate Google Cloud Ops Agent self log file.# See https://manpages.debian.org/jessie/logrotate/logrotate.8.en.html for# the full options./var/log/google-cloud-ops-agent/subagents/logging-module.log{# Log files are rotated every day.daily# Log files are rotated this many times before being removed. This# effectively limits the disk space used by the Ops Agent self log files.rotate30# Log files are rotated when they grow bigger than maxsize even before the# additionally specified time intervalmaxsize256M# Skip rotation if the log file is missing.missingok# Do not rotate the log if it is empty.notifempty# Old versions of log files are compressed with gzip by default.compress# Postpone compression of the previous log file to the next rotation# cycle.delaycompress}EOFSet up
crontaborsystemdtimerto trigger thelogrotateutility periodically.
After the log rotation takes effect, you see rotated files in the/var/log/google-cloud-ops-agent/subagents/ directory. The results look similarto the following output:
/var/log/google-cloud-ops-agent/subagents$ls-lhtotal24K-rw-r--r--1rootroot717Sep319:54logging-module.log-rw-r--r--1rootroot6.8KSep319:51logging-module.log.1-rw-r--r--1rootroot874Sep319:50logging-module.log.2.gz-rw-r--r--1rootroot873Sep319:50logging-module.log.3.gz-rw-r--r--1rootroot3.2KSep319:34logging-module.log.4.gzTo test log rotation, do the following:
Temporarily reduce the file size at which rotation is triggered by settingthe
maxsizevalue to1kin the/etc/logrotate.d/google-cloud-ops-agent.conffile.Trigger the agent self log file to be larger than 1K by restarting the agenta few times:
sudo service google-cloud-ops-agent restartWait for the
crontaborsystemd timerto take effect to trigger thelogrotateutility, or trigger thelogrotateutility manually by runningthis command:sudo logrotate /etc/logrotate.d/google-cloud-ops-agent.confVerify that you see rotated log files in the
/var/log/google-cloud-ops-agent/subagents/directory.Reset the log-rotation configuration by restoring the original
maxsizevalue.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.