ITeye博客

jvmstat hsperfdata java.io.tmpdir

dikar · 2011-09-13 16:13 · JAVA · 编程语言 · Markdown

线上遇到一个问题:

Unable to open socket file: target process not responding or HotSpot VM not loaded
The -F option can be used when the target process is not responding




重启后解决,主要原因是pid文件没有生成,这里记录下相关的问题点。

首先解释下  java.io.tmpdir

见 http://download.oracle.com/javase/1.4.2/docs/api/java/io/File.html

   If the directory argument is null then the system-dependent default temporary-file directory will 
be used. The default temporary-file directory is specified by the system property java.io.tmpdir.
On UNIX systems the default value of this property is typically "/tmp" or "/var/tmp"; 
on Microsoft Windows systems it is typically "c:\\temp". A different value may be given to this 
system property when the Java virtual machine is invoked, but programmatic changes to this
property are not guaranteed to have any effect upon the the temporary directory used by this
method






 

其次看下jvmstat使用的前提

见 http://java.sun.com/performance/jvmstat/faq.html#3

If the error message is of the form:
      Could not attach to vmid: reason
The jvmstat tools can only monitor the HotSpot 1.4.1 JVM and only when the target JVM has been 
started with the -XX:+UsePerfData option. Please verify that your application is running with the 
correct JVM and that the required -XX option is set. 






 

接着来说下上面2者的关系,jvmstat会生成一个目录文件叫hsperfdata_username,那这个目录文件在哪里呢,默认的是生成在 java.io.tmpdir目录下, java.io.tmpdir在linux下默认是/tmp下,故默认开启了jvm monitor的功能以后就会在/tmp目录下生成一个目录叫 hsperfdata_username ,然后这个目录中会有一个pid文件,可以利用strings查看里面的文件内容,一般就是jvm的进程信息而已。

知道了这个所以我们可以自己修改这个目录位置,防止被删除而导致一些依赖这个目录的程序出现问题。

Djava.io.tmpdir=/home/admin/xxxxxx

看下之前别人给sun的一个bug report与该问题相关的

JVM creates subdirectory "hsperfdata_xxx"

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5012932

temp dir locations should not be hardcoded for hsperfdata_<USER> dirctories

http://bugs.sun.com/view_bug.do?bug_id=6447182

针对jdk更新带出的问题 ,参见一个blog说明

Java update breaks jps, jconsole, etc

http://underlap.blogspot.com/2011/03/java-update-breaks-jps-jconsole-etc.html

由此问题进一步引申开来就会发现以下几点容易出问题的地方:

1:没有生成 hsperfdata_xxx目录报错

2:生成 hsperfdata_xxx目录但是没有pid文件

3:没权限生成,例如指定的/tmp或者其他目录不可 写,包括2种情况,一是没权限,而是空间不够

4:文件不可读,例如2个不同的用户来操作这个文件,一般是A用户启动java  B用户来运行jvmstat等等

5:java生成的目录 和 jvmstat 使用的目录文件不是同一个,这个可以见上面jdk update引起的bug导致

ps:JE的样式排版。。。。泪奔

评论(5)

  1. #5 楼 · di1984HIT · 2016-02-22 22:14

    学习了!!!!

  2. #4 楼 · william_ai · 2011-09-13 17:44

    hadoop也有类似的坑。

  3. #3 楼 · RednaxelaFX · 2011-09-13 17:10

    诶,老问题了。

  4. #2 楼 · dikar · 2011-09-13 16:31

    RednaxelaFX writes:

    其实还有可能是/tmp被定时清理了。我们线上就有这种问题,所以启动超过1天还是几天就不行了。后来清理的脚本有的被修改过有的没修。

    恩 ,是被清理了的 :cry: ,tmpwatch

  5. #1 楼 · RednaxelaFX · 2011-09-13 16:24

    其实还有可能是/tmp被定时清理了。我们线上就有这种问题,所以启动超过1天还是几天就不行了。后来清理的脚本有的被修改过有的没修。

评论功能维护中,当前仅展示历史评论。