Java实现查看Web部署在Linux所在机的CPU、内存、I/O运行情况

先了解最基本的查看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数据错误");
		}
	}
	 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ItJavawfc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值