当前位置:首页 » 操作系统 » linux监控jvm

linux监控jvm

发布时间: 2022-12-25 13:20:55

linux怎么启动可视化的jvm 监控工具

呵呵,你的意思是如何进入图形界面把,编辑/etc/inittab 中的id:3:initdefault,把3改为5,然后保存退出,输入reboot重启系统就可以了

② 如何jvm监控linux服务器

如何配置visualvm监控
visualvm支持在Linux和windows上启用图形界面监控jvm的资源,但是如何可以使我们在windows上监控到远程linux服务器资源,这还需要做一些配置,此文是在原文基础上做了更改的,希望对大家能有所帮助。
(1)首先要修改JDK中JMX服务的配置文件,以获得相应的权限:
进入$java_HOME所在的根目录的/jre/lib/management子目录下,
a. 将jmxremote.password.template文件复制为jmxremote.password
b. 调整jmxremote.access和jmxremote.password的权限为只读写,可以使用如下命令
chmod 600 jmxremote.access jmxremote.password
c. 打开jmxremote.password文件,去掉
# monitorRole QED
# controlRole R&D
这两行前面的注释符号
(2)修改env.sh
打开env.sh文件,并在JVM的启动配置中添加如下信息:
JAVA_OPTS="-Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=10.20.150.218 其他配置”
这几个配置的说明如下:
-Dcom.sun.management.jmxremote.port:这个是配置远程connection的端口号的,要确定这个端口没有被占用
-Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false:这两个是固定配置,是JMX的远程服务权限的
-Djava.rmi.server.hostname:这个是配置server的IP的,要使用server的IP最好在机器上先用hostname –i看一下IP是不是机器本身的IP,如果是127.0.0.1的话要改一下,否则远程的时候连不上,目前我们的server上我已经都改好了
(3)Windows客户端配置
JDK 1.6版本自带visualvm,只需要进到bin目录下启动即可
启动后页面比较简洁,配置也很简单:
a. 点击左侧菜单的add Remote host,输入server的IP,然后再advanced settings里配置端口(注意这个端口要和server上的端口一致)
b. 右击刚才配置的IP,选择JMX connection方式,再次输入端口,就可以监视到JVM资源了

③ 怎么通过linux命令去分析jvm里面那个线程阻塞了

仍然需要生成jvm进程的thread mp data,便于与Linux top命令输出关联。步骤如下:
1)执行top命令,或使用-H选项(显示所有线程),找到相关的高CPU的PID
2)生成thread mp 快照(kill -3 PID)。
3)将top命令输出PID转换为HEX格式(16进制)
4)在thread mp data中搜索nid=<Hex PID>
5)分析受影响的thread和stack trace,精确定位代码。
top output sample

[plain] view plain
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND
...........
22111 userWLS 9 0 86616 84M 26780 S 0.0 40.1 0:00 java

④ 怎么用linux命令查看jvm进程有几个线程

在LINUX上可以使用kill -3 pid > thread.info来取得当前JVM线程的信息;
jstack 这个是用来查看jvm当前的thread mp的。可以看到当前Jvm里面的线程状况。
这个对于查找blocked线程比较有意义;

⑤ 怎么用java代码读取linux主机的磁盘使用信息,同时截取出文件系统和已使用情况 放在map中可以得到keyvalu

package com.cmmb.util;
import java.io.*;
/**
* linux 下cpu 内存 磁盘 jvm的使用监控
* @author avery_leo
*
*/
public class DiskSpace {
/**
* 获取cpu使用情况
* @return
* @throws Exception
*/
public double getCpuUsage() throws Exception {
double cpuUsed = 0;

Runtime rt = Runtime.getRuntime();
Process p = rt.exec("top -b -n 1");// 调用系统的“top"命令

BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String str = null;
String[] strArray = null;

while ((str = in.readLine()) != null) {
int m = 0;

if (str.indexOf(" R ") != -1) {// 只分析正在运行的进程,top进程本身除外 &&

strArray = str.split(" ");
for (String tmp : strArray) {
if (tmp.trim().length() == 0)
continue;
if (++m == 9) {// 第9列为CPU的使用百分比(RedHat

cpuUsed += Double.parseDouble(tmp);

}

}

}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
in.close();
}
return cpuUsed;
}
/**
* 内存监控
* @return
* @throws Exception
*/
public double getMemUsage() throws Exception {

double menUsed = 0;
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("top -b -n 1");// 调用系统的“top"命令

BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String str = null;
String[] strArray = null;

while ((str = in.readLine()) != null) {
int m = 0;

if (str.indexOf(" R ") != -1) {// 只分析正在运行的进程,top进程本身除外 &&
//
// System.out.println("------------------3-----------------");
strArray = str.split(" ");
for (String tmp : strArray) {
if (tmp.trim().length() == 0)
continue;

if (++m == 10) {
// 9)--第10列为mem的使用百分比(RedHat 9)

menUsed += Double.parseDouble(tmp);

}
}

}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
in.close();
}
return menUsed;
}

/**
* 获取磁盘空间大小
*
* @return
* @throws Exception
*/
public double getDeskUsage() throws Exception {
double totalHD = 0;
double usedHD = 0;
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("df -hl /home");//df -hl 查看硬盘空间

BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String str = null;
String[] strArray = null;
while ((str = in.readLine()) != null) {
int m = 0;
strArray = str.split(" ");
for (String tmp : strArray) {
if (tmp.trim().length() == 0)
continue;
++m;
System.out.println("----tmp----" + tmp);
if (tmp.indexOf("G") != -1) {
if (m == 2) {
System.out.println("---G----" + tmp);
if (!tmp.equals("") && !tmp.equals("0"))
totalHD += Double.parseDouble(tmp
.substring(0, tmp.length() - 1)) * 1024;

}
if (m == 3) {
System.out.println("---G----" + tmp);
if (!tmp.equals("none") && !tmp.equals("0"))
usedHD += Double.parseDouble(tmp.substring(
0, tmp.length() - 1)) * 1024;

}
}
if (tmp.indexOf("M") != -1) {
if (m == 2) {
System.out.println("---M---" + tmp);
if (!tmp.equals("") && !tmp.equals("0"))
totalHD += Double.parseDouble(tmp
.substring(0, tmp.length() - 1));

}
if (m == 3) {
System.out.println("---M---" + tmp);
if (!tmp.equals("none") && !tmp.equals("0"))
usedHD += Double.parseDouble(tmp.substring(
0, tmp.length() - 1));
System.out.println("----3----" + usedHD);
}
}

}

}
} catch (Exception e) {
e.printStackTrace();
} finally {
in.close();
}
//上面写在userd和total写反了,懒得改了,就反着用了
System.out.println("----totalHD----" + usedHD);
System.out.println("----usedHD----" + totalHD);
return (totalHD / usedHD) * 100;
}

public static void main(String[] args) throws Exception {
DiskSpace cpu = new DiskSpace();
System.out.println("---------------cpu used:" + cpu.getCpuUsage() + "%");
System.out.println("---------------mem used:" + cpu.getMemUsage() + "%");
System.out.println("---------------HD used:" + cpu.getDeskUsage() + "%");
System.out.println("------------jvm监控----------------------");
Runtime lRuntime = Runtime.getRuntime();
System.out.println("--------------Free Momery:" + lRuntime.freeMemory()+"K");
System.out.println("--------------Max Momery:" + lRuntime.maxMemory()+"K");
System.out.println("--------------Total Momery:" + lRuntime.totalMemory()+"K");
System.out.println("---------------Available Processors :"
+ lRuntime.availableProcessors());
}
}

热点内容
android停靠 发布:2025-05-11 08:42:23 浏览:645
超时代加密 发布:2025-05-11 08:41:29 浏览:780
为什么还要输入支取密码 发布:2025-05-11 08:32:24 浏览:362
数据库课程设计案例 发布:2025-05-11 08:15:33 浏览:51
为什么安卓不能通过蓝牙传东西 发布:2025-05-11 08:15:27 浏览:717
tomcat下载linux 发布:2025-05-11 07:47:06 浏览:792
phpcookie设置时间 发布:2025-05-11 07:36:15 浏览:111
固态硬盘需要缓存吗 发布:2025-05-11 07:29:09 浏览:606
松江换门密码锁哪里有 发布:2025-05-11 07:23:21 浏览:327
自动配置代理什么意思 发布:2025-05-11 07:16:51 浏览:994