问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

...同时截取出文件系统和已使用情况 放在map中可以得到keyvalu_百度知...

发布网友 发布时间:2024-10-04 12:27

我来回答

3个回答

热心网友 时间:2024-11-07 15:41

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());
}
}

热心网友 时间:2024-11-07 15:41

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());
}
}

热心网友 时间:2024-11-07 15:41

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());
}
}
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
八月中国最凉快的地方 八月份哪里最凉快,去哪旅游好?美丽的地方 乱字同韵字是什么意思 华硕笔记本电脑触摸板怎么开笔记本电脑触摸板怎么开启和关闭_百度知 ... 陕西职务侵占案立案准则 结婚后我的恋情维系了十年,怎么做到的? 玉米仁子饭产自哪里 中国期货交易所的交易品种有哪些? 历史要怎么读,有啥诀窍 高中历史诀窍 ...ini文件中读取出字符串并转换成cstring对象,如何把此对象转换成unic... ...存入map中 并将这个map读出 存入一个txt文件里 学校可以把户口转到南宁,我要不要转?有什么好处和坏处?拜托了各位... 福绵区户口本买房在玉林可以上公立学校么 九十年代初期央视播出的一部美国电视剧/电影? N82怎么样 摩托罗拉的手机好还是诺基亚的好 nokian81nokia82拍照哪个好? nokian81行货多少 诺基亚N81和N82要是一个价格你们会选择哪个呢 ...求具体地方,还有蹦极要注意什么,求高手解答 梦幻西游:我在小梅沙服务器想最近转到无与伦比将军服务器,可转服务器... 美团购买了不可退的门票,能申请退款吗,美团买景区门票怎么退_百度知 ... 吉林站的东出口开了没有 从长春铁北机车厂到龙嘉机场怎么走近 从王府高速到长春中日联谊医院停车场怎么走近 98年左右的一部电影 ...是98 99还是00年 不记得了 一部美国的青春歌舞片 说现代芭蕾的片子... 本人深圳二区世界之窗有个69极品DT和145垃圾WZ号求赚钱方法。如图打了... 深圳小梅沙好玩吗世界之窗好玩吗?我有一天时间不知道选择去哪玩。小梅沙... 《星愿》上映:刘亦菲配音女主角 于适配音山羊“小瓦” 怎样在职场拓展人际关系网? 根据哪些需要拓展人脉 治安管理处罚法打架斗殴部分的规定是什么? 没有自尊心的人是不是很强大 html内联元素定义dispaly:block后还是内联元素了吗? 没有自尊的人是什么样的?如题谢谢了 html里a 标签可以通过一个属性让它变成段落标签么?求指教 人不能没有自尊是什么意思 网页CSS 可以当div用吗? 比如: span{ display:block; b 宝鸡建筑资质办理,转让,升级,延期流程及条件 宝鸡办理建筑资质延续2024年办理步骤(宝鸡办理建筑资质延续2024年办理... 宝鸡2024年甲级设计资质公司转让的注意问题 宝鸡建筑施工企业资质延续步骤和条件 宝鸡申请建筑企业资质升级流程及费用详解 html行内元素和块状元素 行内元素和块级元素有哪些 妖精的尾巴第一集的城市名? 妖精的尾巴放送情报 妖精的尾巴中:菲利欧、艾斯兰特和玛古诺基亚的关系??