Bug #55711 Agent log rotation : a HUP should rotate the log file
Submitted: 3 Aug 2010 12:02 Modified: 4 Jan 2011 20:52
Reporter: Leandro Morgado Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Enterprise Monitor: Agent Severity:S3 (Non-critical)
Version:2.2.2 OS:Linux
Assigned to: Mark Leith CPU Architecture:Any

[3 Aug 2010 12:02] Leandro Morgado
Description:
The logrotate sample below seems to suggest that sending the agent a HUP will make it close and reopen the log file:

http://dev.mysql.com/doc/mysql-monitor/2.2/en/mem-agent-log-and-pid-files.html

However, the agent will only create the new file when it has something to write to it. With less verbose log-level (the default) this can take a while, leaving the user wondering what happened to mysql-monitor-agent.log

How to repeat:
shell> mv /opt/mysql/enterprise/agent/mysql-monitor-agent.log /opt/mysql/enterprise/agent/mysql-monitor-agent.OLD

shell> ll /opt/mysql/enterprise/agent/
drwxr-xr-x 2 root root 4.0K May 31 21:02 bin
-rw------- 1 root root 2.6K May 31 21:02 configuration_report.txt
drwxr-xr-x 4 root root 4.0K Jul 21 18:26 etc
drwxr-xr-x 2 root root 4.0K May 31 21:02 include
drwxr-xr-x 6 root root 4.0K May 31 21:02 lib
drwxr-xr-x 2 root root 4.0K May 31 21:02 libexec
drwxrwxr-x 2 root root 4.0K May 31 21:02 licenses
-rw-r----- 1 root root  346 Aug  3 13:25 mysql-monitor-agent.OLD
-rw------- 1 root root    4 Aug  3 13:25 mysql-monitor-agent.pid
drwxr-xr-x 9 root root 4.0K May 31 21:02 patchbackup
-rw-r--r-- 1 root root    0 Jun 16 19:27 ram
drwxr-xr-x 4 root root 4.0K May 31 21:02 share
-rwx------ 1 root root 3.8M May 31 21:02 uninstall

shell> kill -HUP $(cat /opt/mysql/enterprise/agent/mysql-monitor-agent.pid)

I would expect a new ysql-monitor-agent.log file to exist, even if it's size was zero:

shell> ll /opt/mysql/enterprise/agent/
drwxr-xr-x 2 root root 4.0K May 31 21:02 bin
-rw------- 1 root root 2.6K May 31 21:02 configuration_report.txt
drwxr-xr-x 4 root root 4.0K Jul 21 18:26 etc
drwxr-xr-x 2 root root 4.0K May 31 21:02 include
drwxr-xr-x 6 root root 4.0K May 31 21:02 lib
drwxr-xr-x 2 root root 4.0K May 31 21:02 libexec
drwxrwxr-x 2 root root 4.0K May 31 21:02 licenses
-rw-r----- 1 root root  346 Aug  3 13:25 mysql-monitor-agent.OLD
-rw------- 1 root root    4 Aug  3 13:25 mysql-monitor-agent.pid
drwxr-xr-x 9 root root 4.0K May 31 21:02 patchbackup
-rw-r--r-- 1 root root    0 Jun 16 19:27 ram
drwxr-xr-x 4 root root 4.0K May 31 21:02 share
-rwx------ 1 root root 3.8M May 31 21:02 uninstall

This works fine if I set log-level=debug in the agent .ini file as it immediately grows to a few hundred Kb. 

Suggested fix:
Create the new mysql-monitor-agent.log after receiving the HUP without needing to wait on the first log entry, avoiding confusing users, who think it never reopened the file.
[20 Sep 2010 17:52] Enterprise Tools JIRA Robot
Carsten Segieth writes: 
tested OK in both 2.2.3.1755 (GA) and 2.3.0.2021; an empty file is created immediately, so we see with 'more silent' log levels that it's "there". For more verbose log levels the file is 'filled' anyway.
[4 Jan 2011 20:52] John Russell
Added to 2.2.3 change log:

After a SIGHUP signal, the mysql-monitor-agent.log file could be
missing for some time until there was a new message to write. Now the
empty file is created immediately.