java获得linux环境的硬盘、内存、cpu使用率
思路:java代码读取linux主机的磁盘使用信息,同时截取出文件系统和已使用情况 放在map中可以得到keyvalue package com.cmmb.util; import java.io.*; /** * linux 下 cpu 内存 磁盘 jvm的使用监控 * @author avery_leo * */ public class DiskSpace { /** * 获取 cpu 使用情况 * @return * @throws Exception */ public double get cpu Usage() throws Exception { double cpu Used = 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