package Client;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import org.hyperic.sigar.CpuInfo;
import org.hyperic.sigar.CpuPerc;
import org.hyperic.sigar.FileSystem;
import org.hyperic.sigar.FileSystemUsage;
import org.hyperic.sigar.Mem;
import org.hyperic.sigar.NetInfo;
import org.hyperic.sigar.NetInterfaceConfig;
import org.hyperic.sigar.NfsFileSystem;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.SysInfo;
/**
*
* @author k02
*/
public class LocalInfoCollection {
Sigar sigar;
/**
* Construction Method
*/
public LocalInfoCollection() {
sigar = new Sigar();
}
public String getIPAddress() throws SigarException {
NetInterfaceConfig nic = sigar.getNetInterfaceConfig();
return nic.getAddress();
}
public String getMacAddress() throws SigarException {
NetInterfaceConfig nic = sigar.getNetInterfaceConfig();
return nic.getHwaddr();
}
public String getHostname() throws SigarException {
NetInfo ni = sigar.getNetInfo();
return ni.getHostName();
}
public String getOSInfo() throws SigarException {
SysInfo si = new SysInfo();
si.gather(sigar);
return si.getDescription() + " " + si.getPatchLevel() + " " + si.getArch();
}
public int getProcessCount() throws SigarException {
long[] proList = sigar.getProcList();
return proList.length;
}
public String getCPUModels() throws SigarException {
CpuInfo[] infos = sigar.getCpuInfoList();
CpuInfo info = infos[0];
return info.getVendor() + " " + info.getModel() + " " + info.getMhz() / 1000.0 + "Mhz";
}
public String getCPUUsage() throws SigarException {
CpuPerc usage = sigar.getCpuPerc();
return CpuPerc.format(usage.getCombined());
}
public String getMemSize() throws SigarException {
Mem m = sigar.getMem();
String mStr = new Long(m.getTotal() / 1024).toString();
return mStr + "K";
}
public String getMemUsage() throws SigarException {
Mem m = sigar.getMem();
String mStr = new Double(m.getUsedPercent()).toString();
return mStr.substring(0, 5) + "%";
}
public String getDiskTotalSize() throws SigarException {
String diskSize="";
long diskTotalSizeL = 0;
FileSystem[] fslist = null;
try {
fslist = sigar.getFileSystemList();
} catch (SigarException se) {
se.printStackTrace();
}
for (int i = 0; i < fslist.length; i++) {
diskTotalSizeL+=getEachPartSize(fslist[i]);
}
diskSize=Sigar.formatSize(diskTotalSizeL).trim();
return diskSize;
}
private long getEachPartSize(FileSystem fs) {
long total;
try {
FileSystemUsage usage;
if (fs instanceof NfsFileSystem) {
NfsFileSystem nfs = (NfsFileSystem) fs;
if (!nfs.ping()) {
return 0;
}
}
usage = sigar.getFileSystemUsage(fs.getDirName());
total = usage.getTotal() * 1024;
} catch (SigarException e) {
//if there is no cd in the drive.
total = 0;
}
return total;
}
public String toString(){
String localDataStr="";
//Wait modify
return "";
}
}
wjjheychx
- 粉丝: 6
- 资源: 10
最新资源
- fed54987-3a28-4a7a-9c89-52d3ac6bc048.vsidx
- (177367038)QT实现教务管理系统.zip
- (178041422)基于springboot网上书城系统.zip
- (3127654)超级玛丽游戏源码下载
- (175717016)CTGU单总线CPU设计(变长指令周期3级时序)(HUST)(circ文件)
- (133916396)单总线CPU设计(变长指令周期3级时序)(HUST).rar
- Unity In-game Debug Console
- (3292010)Java图书管理系统(源码)
- Oracle期末复习题:选择题详解与数据库管理技术
- (176721246)200行C++代码写一个Qt俄罗斯方块
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
前往页