当前位置:网站首页>OperatingSystemMXBean to get system performance metrics
OperatingSystemMXBean to get system performance metrics
2022-08-02 02:46:00 【LG_985938339】
OperatingSystemMXBeanGet system performance metrics
方法名称 | 含义 | 单位 |
---|---|---|
getFreePhysicalMemorySize | 可用物理内存 | 字节 |
getTotalPhysicalMemorySize | 总物理内存 | 字节 |
getFreeSwapSpaceSize | 可用交换空间 | 字节 |
getTotalSwapSpaceSize | 交换空间总量 | 字节 |
getCommittedVirtualMemorySize | Committed virtual memory size | 字节 |
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("The remaining available amount of physical memory: "+operatingSystemMXBean.getFreePhysicalMemorySize()/GB+"GB");
System.out.println("内存使用率: "+(double)100*operatingSystemMXBean.getFreePhysicalMemorySize()/operatingSystemMXBean.getTotalPhysicalMemorySize()+"%");
System.out.println("交换空间总量: "+operatingSystemMXBean.getTotalSwapSpaceSize()/GB+"GB");
System.out.println("The amount of swap space remaining available: "+operatingSystemMXBean.getFreeSwapSpaceSize()/GB+"GB");
System.out.println("CPU核心数: "+operatingSystemMXBean.getAvailableProcessors()+"个");
System.out.println("Amount of virtual memory committed: "+operatingSystemMXBean.getCommittedVirtualMemorySize());
System.out.println("process usedCPU时间: "+operatingSystemMXBean.getProcessCpuTime()/1000000000.0+"秒");
}
}
边栏推荐
猜你喜欢
永磁同步电机36问(三)——SVPWM代码实现
51. 数字排列
Oracle19c安装图文教程
AI目标分割能力,无需绿幕即可实现快速视频抠图
使用docker安装mysql
How ReentrantLock works
The principle and code implementation of intelligent follower robot in the actual combat of innovative projects
The failure to create a role in Dahua Westward Journey has been solved
【每日一道LeetCode】——1. 两数之和
Entry name 'org/apache/commons/codec/language/bm/gen_approx_greeklatin.txt' collided
随机推荐
(1) Redis: Key-Value based storage system
EFCore 反向工程
OC中new和init的区别
【LeetCode】104.二叉树的最大深度
使用docker安装mysql
忽晴忽雨
最大层内元素和
永磁同步电机36问(三)——SVPWM代码实现
51. 数字排列
EasyGBS平台播放视频时偶尔出现播放失败是什么原因?
【每日一道LeetCode】——1. 两数之和
789. 数的范围
(一)Redis: 基于 Key-Value 的存储系统
Outsourcing worked for three years, it was abolished...
FOFAHUB usage test
Chrome浏览器无法加载已解压的.crx文件的解决办法
简单的页面跳转活动
AI target segmentation capability for fast video cutout without green screen
MySQL - CRUD operations
局部敏感哈希:如何在常数时间内搜索Embedding最近邻