先了解最基本的查看Linux所在机的CPU、内存、I/O运行情况的命令: http://blog.csdn.net/itjavawfc/article/details/42216171
1)黑体字是执行ocx文件下面monitor_message.sh脚本中的命令:并将结果输出返回字符串String
2)黑体字下面代码是为了更好的在前台处理,进行字符串处理
public void monitor(){
<strong> HttpServletRequest req=ServletActionContext.getRequest();
String filePath = req.getSession().getServletContext().getRealPath("");
String commands="sh " +filePath+ "/ocx/monitor_message.sh";
try {
Process process = Runtime.getRuntime().exec(commands);
InputStreamReader ir = new InputStreamReader(process.getInputStream(), "GBK");
BufferedReader input = new BufferedReader(ir);
String line;
String message="";
while ((line = input.readLine()) != null) {
message+=line;
logger.info(message);
} </strong>
if(Monitorflag.getInstance().isMonitorfirst()==false){
String[] msarray1 = message.split("cpu------");
String ms1=msarray1[0]+"cpu------"; //前台界面第一行要显示的数据
String[] msarray2=msarray1[1].split("st");
String ms2=msarray2[0]+" st"; //前台界面第二行要显示的数据
String ms2_1=ms2.replace("r b", "r b").replace("b swpd", "b swpd").replace("swpd free", "swpd free").replace("free buf", "free buf")
.replace("buff cache", "buff cache").replace("cache si", "cache si").replace("so bi", "so bi");
String ms3=msarray2[1];
message=ms1+"\n"+ms2_1+"\n"+ms3;
Monitorflag.getInstance().setMessagefinal(message);
Monitorflag.getInstance().setMonitorfirst(true);
this.actionWrite(message.toString());
}else{
String[] msarray=message.split("wa st");
String ms=Monitorflag.getInstance().getMessagefinal()+"\n"+msarray[1];
Monitorflag.getInstance().setMessagefinal(ms);
this.actionWrite(ms.toString());
}
}catch(Exception e){
this.actionWrite("actionwrite数据错误");
}
}