使用logrotate的垃圾收集器日志(loggc)文件旋转无法正常工作 [英] Garbage collector log (loggc) file rotation with logrotate does not work properly

查看:254
本文介绍了使用logrotate的垃圾收集器日志(loggc)文件旋转无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用Linux logrotate命令使用JVM垃圾收集日志选项时,我遇到了一个奇怪的问题。
当循环执行时,它将NUL(^ @)值作为参数给JVM的第一行。

java调用(Test.class位于/ home / test /):


java -Xloggc:/home/test/test.log -b / home / test / Test

此文件的logrotate配置如下:


/home/test/test.log {

    旋转56美元
   ;  missingok

    notifempty

    copytruncate

    nocreate <
    nobs

}


我也有crontab入口日志记录每分钟用于测试目的:

lockquote
/ 1 * * * * / usr / sbin / logrotate -f / etc / logrotate .d / gcLog


我得出JVM写入的结论
附加模式,并保留用于在相关文件中写入下一行的某种偏移量,即使该文件被logrotate截断(我可能是错误的)。


b
$ b

我的下一个想法是尝试将stdout重定向到test.log文件。
我使用了这个java调用,并为logrotate和cron保留了相同的配置:
$ b


java -verbose:gc -cp / home / test / Test> /home/test/test.log

再一次,当test.log被logrotate截断时,新的

创建的文件在第一行填入NUL(^ @)值。



不需要说我没有使用谷歌找不到有用的东西。
我发现了另一个关于stackoverflow类型的问题,但是我无法设置Java Script Wrapper,所以这是行不通的。



有没有人遇到这个问题?任何想法为什么发生这种情况?更好,任何解决方法或解决方案?
我需要尝试将调用传递给应用程序以读取输出的一些脚本,也许看看Tomcat在catalina.out中记录和旋转stdout的方式(这里也会非常感谢一些帮助)我们在运行Jboss7和Java6的地方遇到了同样的问题,我们在GC文件中获得了空值,并且它们只是不断增长。



解决方案是将GC记录到stdout,然后将追加 stdout到文件中:



简单的例子:

  java -verbose:gc>> console.log 

显然,使用append(>>)可以将Java指针在文件中。还有一个额外的好处就是不必每次重启服务器都重置GC日志,这样我们就可以获得一些统计信息。



至少IBM PMAT工具在解析sysout时没有问题与GC输出。

最简单的解决方案有时是最好的:)

虽然我希望Java支持旋转的GC日志,因为我看到有人以前一直在讨论:
http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/2011-April/002061.html


I came across a weird issue when using JVM garbage collection log option with Linux logrotate command. When rotation is executed, it fills NUL ( ^@ ) values the first line of the file given as argument to the JVM.

Let say this is the java call (Test.class is located in /home/test/) :

java -Xloggc:/home/test/test.log -cp /home/test/ Test

The configuration of logrotate for this file is as follow :

/home/test/test.log {
   rotate 56
   missingok
   notifempty
   copytruncate
   nocreate
   nomail
}

I also have a crontab entry logging every minute for testing purposes :

*/1 * * * * /usr/sbin/logrotate -f /etc/logrotate.d/gcLog

I came to the conclusion that JVM writes in append mode and keeps some kind of offset used to write next line in the related file, even if the file is truncated by logrotate (I may be wrong).


My next idea was to try and redirect the stdout to test.log file. I used this java call and kept the same configuration for logrotate and cron:

java -verbose:gc -cp /home/test/ Test > /home/test/test.log

Once again, when test.log is truncated by logrotate, the new created file is filled with NUL (^@) values on the first line.


No need to say that I didn't find anything helpful using google. I found another question on stackoverflow kind of related, but I couldn't manage to setup Java Script Wrapper, so this doesn't work.

Did anybody come across this issue ? Any idea why is this happening ? Better, any workaround or solution ? I need to try and pipe the call to the application to a some script reading the output and maybe look at the way Tomcat logs and rotate stdout in catalina.out (here some help will be really appreciated as well)

解决方案

We had the same problem at our place running Jboss7 and Java6, we were getting NULLs in the GC file and they just kept growing.

Solution was to just log GC to stdout and then append stdout to a file:

Simple example:

java -verbose:gc >> console.log

Apparently using append (>>) gets rid of the Java "pointer" to a position in the file. With the added bonus of not having the GC logs reset per server restart so we can have some stats over time.

At least the IBM PMAT tool has no problem parsing the sysout with GC output.

The simplest solution is sometimes the best :)

Though I wish Java would support rotating of GC logs, as I see someone's been discussing before: http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/2011-April/002061.html

这篇关于使用logrotate的垃圾收集器日志(loggc)文件旋转无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆