当前位置:网站首页>OperatingSystemMXBean获取系统性能指标
OperatingSystemMXBean获取系统性能指标
2022-08-02 02:33:00 【LG_985938339】
OperatingSystemMXBean获取系统性能指标
方法名称 | 含义 | 单位 |
---|---|---|
getFreePhysicalMemorySize | 可用物理内存 | 字节 |
getTotalPhysicalMemorySize | 总物理内存 | 字节 |
getFreeSwapSpaceSize | 可用交换空间 | 字节 |
getTotalSwapSpaceSize | 交换空间总量 | 字节 |
getCommittedVirtualMemorySize | 已提交虚拟内存大小 | 字节 |
getProcessCpuLoad | 进程CPU使用率(0~1之间) | |
getSystemCpuLoad | 系统CPU使用率(0~1之间) | |
getAvailableProcessors | 可用CPU核数 | 个 |
getProcessCpuTime | 进程使用的 CPU 时间 | 纳秒 |
import com.sun.management.OperatingSystemMXBean;
import java.lang.management.ManagementFactory;
public class Test {
public static void main(String[] args) throws InterruptedException {
final long GB = 1024 * 1024 * 1024;
OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();
System.out.println("进程CPU使用率: "+operatingSystemMXBean.getProcessCpuLoad()* 100+"%");
System.out.println("系统CPU使用率: "+operatingSystemMXBean.getSystemCpuLoad()* 100+"%");
System.out.println("物理内存总量: "+operatingSystemMXBean.getTotalPhysicalMemorySize()/GB+"GB");
System.out.println("物理内存剩余可用量: "+operatingSystemMXBean.getFreePhysicalMemorySize()/GB+"GB");
System.out.println("内存使用率: "+(double)100*operatingSystemMXBean.getFreePhysicalMemorySize()/operatingSystemMXBean.getTotalPhysicalMemorySize()+"%");
System.out.println("交换空间总量: "+operatingSystemMXBean.getTotalSwapSpaceSize()/GB+"GB");
System.out.println("交换空间剩余可用量: "+operatingSystemMXBean.getFreeSwapSpaceSize()/GB+"GB");
System.out.println("CPU核心数: "+operatingSystemMXBean.getAvailableProcessors()+"个");
System.out.println("已提交虚拟内存量: "+operatingSystemMXBean.getCommittedVirtualMemorySize());
System.out.println("进程已使用CPU时间: "+operatingSystemMXBean.getProcessCpuTime()/1000000000.0+"秒");
}
}
边栏推荐
猜你喜欢
永磁同步电机36问(二)——机械量与电物理量如何转化?
MySQL8 download, start, configure, verify
网络层解析——IP协议、地址管理、路由选择
面对职场“毕业”,PM&PMO应该如何从容的应对?如何跳槽能够大幅度升职加薪?
Electronic Manufacturing Warehouse Barcode Management System Solution
数仓:为什么说 ETL 的未来不是 ELT,而是 EL (T)
The state status is displayed incorrectly after the openGauss switch
GTK RGB图像绘制
Use DBeaver for mysql data backup and recovery
The first time I wrote a programming interview question for Niu Ke: input a string and return the letter with the most occurrences of the string
随机推荐
What to study after the PMP exam?The soft exam ahead is waiting for you~
CodeTon Round 2 D. Magical Array
2022年NPDP考完多久出成绩?怎么查询?
PAT甲级打卡-1001-1004
Service discovery of kubernetes
Analysis of the status quo of digital transformation of manufacturing enterprises
十字光标太小怎么调节、CAD梦想画图算量技巧
工程师如何对待开源
微信小程序异步回调函数恶梦和解决办法
240...循迹
Nanoprobes免疫测定丨FluoroNanogold试剂免疫染色方案
feign调用不通问题,JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r
记一次gorm事务及调试解决mysql死锁
[ORB_SLAM2] SetPose, UpdatePoseMatrices
【CNN记录】tensorflow slice和strided_slice
使用docker安装mysql
永磁同步电机36问(三)——SVPWM代码实现
53. 最小的k个数
Nanoprobes Polyhistidine (His-) Tag: Recombinant Protein Detection Protocol
Moonbeam and Project integration of the Galaxy, bring brand-new user experience for the community