JSP获取CPU使用率、系统内存、虚拟机内存等情况(不用JNI)(2)
this.totalMemorySize = totalMemorySize;
}
public int getTotalThread() {
return totalThread;
}
public void setTotalThread(int totalThread) {
this.totalThread = totalThread;
}
public long getUsedMemory() {
return usedMemory;
}
public void setUsedMemory(long usedMemory) {
this.usedMemory = usedMemory;
}
public double getCpuRatio() {
return cpuRatio;
}
public void setCpuRatio(double cpuRatio) {
this.cpuRatio = cpuRatio;
}
}
接着编写一个获得当前的监控信息的接口,该类的代码如下所示:
package performance;
/**
* 获取系统信息的业务逻辑类接口.
*/
public interface IMonitorService {
/**
* 获得当前的监控对象.
*
* @return 返回构造好的监控对象
* @throws Exception
*/
public MonitorInfoBean getMonitorInfoBean() throws Exception;
}
该类的实现类MonitorServiceImpl如下所示:
package performance;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.StringTokenizer;
import sun.management.ManagementFactory;
import com.sun.management.OperatingSystemMXBean;
/**
*
* 获取系统信息的业务逻辑实现类.
*
* @author GuoHuang
*/
public class MonitorServiceImpl implements IMonitorService {
private static final int CPUTIME = 30;
private static final int PERCENT = 100;
private static final int FAULTLENGTH = 10;
private static String linuxVersion = null;
/**
* 获得当前的监控对象.
*
* @return 返回构造好的监控对象
* @throws Exception
* @author GuoHuang
*/
public MonitorInfoBean getMonitorInfoBean() throws Exception {
int kb = 1024;
// 可使用内存
long totalMemory = Runtime.getRuntime().totalMemory() / kb;
相关新闻>>
- 发表评论
-
- 最新评论 更多>>