Moved to oshi
This commit is contained in:
parent
ca311839f5
commit
6c096a42d7
14 changed files with 160 additions and 158 deletions
|
|
@ -22,11 +22,9 @@
|
|||
|
||||
package wa.server.plugin.hwstatus;
|
||||
|
||||
import org.hyperic.sigar.FileSystem;
|
||||
import org.hyperic.sigar.FileSystemUsage;
|
||||
import org.hyperic.sigar.Sigar;
|
||||
import org.hyperic.sigar.SigarException;
|
||||
import org.hyperic.sigar.cmd.Shell;
|
||||
import oshi.SystemInfo;
|
||||
import oshi.software.os.OSFileStore;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
import wa.server.WAContext;
|
||||
import wa.server.page.WAStatusPage;
|
||||
import zutil.io.file.FileUtil;
|
||||
|
|
@ -35,8 +33,6 @@ import zutil.parser.DataNode;
|
|||
import zutil.parser.Templator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -45,11 +41,6 @@ import java.util.Map;
|
|||
public class HDDStatus extends WAStatusPage {
|
||||
private static final String TEMPLATE = "wa/server/plugin/hwstatus/HddStatus.tmpl";
|
||||
|
||||
private int nextId;
|
||||
private HashMap<String,Integer> idMap = new HashMap<String,Integer>();
|
||||
|
||||
|
||||
|
||||
public HDDStatus() {
|
||||
super("hdd", "Harddrives");
|
||||
}
|
||||
|
|
@ -67,42 +58,30 @@ public class HDDStatus extends WAStatusPage {
|
|||
Map<String, String> cookie,
|
||||
Map<String, String> request) {
|
||||
DataNode root = new DataNode(DataNode.DataType.Map);
|
||||
|
||||
if (request.containsKey("hdd")) {
|
||||
DataNode hdd_root = new DataNode(DataNode.DataType.List);
|
||||
root.set("hdd", hdd_root);
|
||||
Sigar sigar = new Shell().getSigar();
|
||||
try {
|
||||
FileSystem[] hdds = sigar.getFileSystemList();
|
||||
for (FileSystem hdd : hdds) {
|
||||
if (hdd.getType() != FileSystem.TYPE_LOCAL_DISK)
|
||||
continue;
|
||||
DataNode node = new DataNode(DataNode.DataType.Map);
|
||||
|
||||
String device = new String(hdd.getDevName().getBytes(), "UTF-8");
|
||||
node.set("device", device);
|
||||
node.set("filesystem", hdd.getSysTypeName());
|
||||
node.set("mount", hdd.getDirName());
|
||||
SystemInfo system = new SystemInfo();
|
||||
OperatingSystem os = system.getOperatingSystem();
|
||||
|
||||
if (idMap.containsKey(device))
|
||||
node.set("pageName", idMap.get(device));
|
||||
else {
|
||||
idMap.put(device, nextId);
|
||||
node.set("pageName", nextId++);
|
||||
}
|
||||
for (OSFileStore filesystem : os.getFileSystem().getFileStores(true)) {
|
||||
DataNode node = new DataNode(DataNode.DataType.Map);
|
||||
|
||||
FileSystemUsage hdd_use = sigar.getFileSystemUsage(hdd.getDirName());
|
||||
node.set("size_total", hdd_use.getTotal() * 1000);
|
||||
node.set("size_used", (hdd_use.getTotal() - hdd_use.getFree()) * 1000);
|
||||
node.set("size_free", hdd_use.getFree() * 1000);
|
||||
node.set("device", filesystem.getLogicalVolume());
|
||||
node.set("filesystem", filesystem.getType());
|
||||
node.set("mount", filesystem.getMount());
|
||||
|
||||
hdd_root.add(node);
|
||||
}
|
||||
} catch (SigarException e) {
|
||||
e.printStackTrace();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
node.set("size_total", filesystem.getTotalSpace() * 1000);
|
||||
node.set("size_used", (filesystem.getTotalSpace() - filesystem.getFreeSpace()) * 1000);
|
||||
node.set("size_free", filesystem.getFreeSpace() * 1000);
|
||||
|
||||
hdd_root.add(node);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue