Moved to oshi

This commit is contained in:
Ziver Koc 2020-10-17 23:20:31 +02:00
parent ca311839f5
commit 6c096a42d7
14 changed files with 160 additions and 158 deletions

View file

@ -11,7 +11,7 @@ repositories {
} }
dependencies { dependencies {
implementation 'se.koc:zutil:1.0.0-SNAPSHOT' implementation 'se.koc:zutil:1.0.264'
implementation 'org.xerial:sqlite-jdbc:3.32.3.2' implementation 'org.xerial:sqlite-jdbc:3.32.3.2'
implementation 'com.github.oshi:oshi-core:5.2.5' implementation 'com.github.oshi:oshi-core:5.2.5'
@ -25,7 +25,11 @@ sourceSets {
srcDirs 'src' srcDirs 'src'
} }
resources { resources {
srcDir 'resources' exclude '**/*.java'
srcDirs = [
'resources',
'src',
]
} }
} }
test { test {

View file

@ -41,7 +41,6 @@ import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;

View file

@ -2,14 +2,9 @@ package wa.server;
import wa.server.page.ConfigPage; import wa.server.page.ConfigPage;
import wa.server.page.WAPage; import wa.server.page.WAPage;
import zutil.io.file.FileUtil;
import zutil.log.CompactLogFormatter; import zutil.log.CompactLogFormatter;
import zutil.log.LogUtil; import zutil.log.LogUtil;
import zutil.net.http.HttpServer;
import zutil.net.http.page.HttpFilePage;
import zutil.plugin.PluginManager;
import java.util.Iterator;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;

View file

@ -30,7 +30,6 @@ import zutil.io.file.FileUtil;
import zutil.log.LogUtil; import zutil.log.LogUtil;
import zutil.net.http.HttpHeader; import zutil.net.http.HttpHeader;
import zutil.parser.Templator; import zutil.parser.Templator;
import zutil.ui.Navigation;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;

View file

@ -4,7 +4,6 @@ package wa.server.plugin;
import zutil.db.DBConnection; import zutil.db.DBConnection;
import zutil.db.bean.DBBean; import zutil.db.bean.DBBean;
import zutil.db.bean.DBBeanSQLResultHandler; import zutil.db.bean.DBBeanSQLResultHandler;
import zutil.db.handler.SimpleSQLResult;
import zutil.parser.json.JSONParser; import zutil.parser.json.JSONParser;
import zutil.parser.json.JSONWriter; import zutil.parser.json.JSONWriter;
import zutil.ui.Configurator; import zutil.ui.Configurator;

View file

@ -23,7 +23,9 @@
package wa.server.plugin.apache; package wa.server.plugin.apache;
import wa.server.page.WAServicePage; import wa.server.page.WAServicePage;
import wa.server.plugin.*; import wa.server.plugin.WAInstaller;
import wa.server.plugin.WALog;
import wa.server.plugin.WAServiceStatus;
/** /**
* Created by Ziver on 2014-12-23. * Created by Ziver on 2014-12-23.

View file

@ -22,11 +22,9 @@
package wa.server.plugin.hwstatus; package wa.server.plugin.hwstatus;
import org.hyperic.sigar.FileSystem; import oshi.SystemInfo;
import org.hyperic.sigar.FileSystemUsage; import oshi.software.os.OSFileStore;
import org.hyperic.sigar.Sigar; import oshi.software.os.OperatingSystem;
import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.cmd.Shell;
import wa.server.WAContext; import wa.server.WAContext;
import wa.server.page.WAStatusPage; import wa.server.page.WAStatusPage;
import zutil.io.file.FileUtil; import zutil.io.file.FileUtil;
@ -35,8 +33,6 @@ import zutil.parser.DataNode;
import zutil.parser.Templator; import zutil.parser.Templator;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
@ -45,11 +41,6 @@ import java.util.Map;
public class HDDStatus extends WAStatusPage { public class HDDStatus extends WAStatusPage {
private static final String TEMPLATE = "wa/server/plugin/hwstatus/HddStatus.tmpl"; 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() { public HDDStatus() {
super("hdd", "Harddrives"); super("hdd", "Harddrives");
} }
@ -67,42 +58,30 @@ public class HDDStatus extends WAStatusPage {
Map<String, String> cookie, Map<String, String> cookie,
Map<String, String> request) { Map<String, String> request) {
DataNode root = new DataNode(DataNode.DataType.Map); DataNode root = new DataNode(DataNode.DataType.Map);
if (request.containsKey("hdd")) { if (request.containsKey("hdd")) {
DataNode hdd_root = new DataNode(DataNode.DataType.List); DataNode hdd_root = new DataNode(DataNode.DataType.List);
root.set("hdd", hdd_root); root.set("hdd", hdd_root);
Sigar sigar = new Shell().getSigar();
try { SystemInfo system = new SystemInfo();
FileSystem[] hdds = sigar.getFileSystemList(); OperatingSystem os = system.getOperatingSystem();
for (FileSystem hdd : hdds) {
if (hdd.getType() != FileSystem.TYPE_LOCAL_DISK) for (OSFileStore filesystem : os.getFileSystem().getFileStores(true)) {
continue;
DataNode node = new DataNode(DataNode.DataType.Map); DataNode node = new DataNode(DataNode.DataType.Map);
String device = new String(hdd.getDevName().getBytes(), "UTF-8"); node.set("device", filesystem.getLogicalVolume());
node.set("device", device); node.set("filesystem", filesystem.getType());
node.set("filesystem", hdd.getSysTypeName()); node.set("mount", filesystem.getMount());
node.set("mount", hdd.getDirName());
if (idMap.containsKey(device)) node.set("size_total", filesystem.getTotalSpace() * 1000);
node.set("pageName", idMap.get(device)); node.set("size_used", (filesystem.getTotalSpace() - filesystem.getFreeSpace()) * 1000);
else { node.set("size_free", filesystem.getFreeSpace() * 1000);
idMap.put(device, nextId);
node.set("pageName", nextId++);
}
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);
hdd_root.add(node); hdd_root.add(node);
} }
} catch (SigarException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} }
return root; return root;
} }

View file

@ -59,7 +59,7 @@ function byteToString(value){
<div id="" class="col-md-4"><div class="panel panel-default"> <div id="" class="col-md-4"><div class="panel panel-default">
<div class="panel-heading hdd-title"></div> <div class="panel-heading hdd-title"></div>
<div class="panel-body"> <div class="panel-body">
<center><img src="img/hdd_ok.png" /></center><br> <center><img src="/img/hdd_ok.png" /></center><br>
<div class="progress"> <div class="progress">
<div class="progress-bar hdd-used" role="progressbar"></div> <div class="progress-bar hdd-used" role="progressbar"></div>
<center class="hdd-free"></center> <center class="hdd-free"></center>

View file

@ -22,8 +22,14 @@
package wa.server.plugin.hwstatus; package wa.server.plugin.hwstatus;
import org.hyperic.sigar.*; import oshi.SystemInfo;
import org.hyperic.sigar.cmd.Shell; import oshi.hardware.CentralProcessor;
import oshi.hardware.GlobalMemory;
import oshi.hardware.HardwareAbstractionLayer;
import oshi.hardware.VirtualMemory;
import oshi.software.os.OSProcess;
import oshi.software.os.OSService;
import oshi.software.os.OperatingSystem;
import wa.server.WAContext; import wa.server.WAContext;
import wa.server.page.WAStatusPage; import wa.server.page.WAStatusPage;
import zutil.StringUtil; import zutil.StringUtil;
@ -42,6 +48,7 @@ import java.util.Map;
public class HwStatus extends WAStatusPage { public class HwStatus extends WAStatusPage {
private static final String TEMPLATE = "wa/server/plugin/hwstatus/HwStatus.tmpl"; private static final String TEMPLATE = "wa/server/plugin/hwstatus/HwStatus.tmpl";
private long[][] prevProcTicks;
public HwStatus() { public HwStatus() {
super("hw", "Hardware Summary"); super("hw", "Hardware Summary");
@ -61,60 +68,83 @@ public class HwStatus extends WAStatusPage {
Map<String, String> cookie, Map<String, String> cookie,
Map<String, String> request) { Map<String, String> request) {
DataNode root = new DataNode(DataNode.DataType.Map); DataNode root = new DataNode(DataNode.DataType.Map);
try{
Sigar sigar = new Shell().getSigar(); SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
OperatingSystem os = si.getOperatingSystem();
if(request.containsKey("uptime")){ if(request.containsKey("uptime")){
root.set("uptime", root.set("uptime", StringUtil.formatTimeToString(os.getSystemUptime()));
StringUtil.formatTimeToString(
(long)sigar.getUptime().getUptime()));
} }
if(request.containsKey("cpu")) { if(request.containsKey("cpu")) {
DataNode cpuNode = new DataNode(DataType.List); DataNode cpuNode = new DataNode(DataType.List);
CpuInfo cpu_info = sigar.getCpuInfoList()[0]; CentralProcessor processor = hal.getProcessor();
for (CpuPerc cpu : sigar.getCpuPercList()) {
cpuNode.add(Math.round(cpu.getCombined() * 100.0) / 100.0); if (prevProcTicks == null)
prevProcTicks = processor.getProcessorCpuLoadTicks();
double[] load = processor.getProcessorCpuLoadBetweenTicks(prevProcTicks);
for (double avg : load) {
cpuNode.add(Math.round(avg * 100));
} }
prevProcTicks = processor.getProcessorCpuLoadTicks();
root.set("cpu", cpuNode); root.set("cpu", cpuNode);
} }
if(request.containsKey("memory")) { if(request.containsKey("memory")) {
GlobalMemory memory = hal.getMemory();
DataNode memNode = new DataNode(DataType.Map); DataNode memNode = new DataNode(DataType.Map);
Mem mem = sigar.getMem(); memNode.set("total", sizeByteToMB(memory.getTotal()));
memNode.set("free", sizeByteToMB(mem.getFree())); memNode.set("used", sizeByteToMB(memory.getTotal() - memory.getAvailable()));
memNode.set("used", sizeByteToMB(mem.getUsed())); memNode.set("free", sizeByteToMB(memory.getAvailable()));
root.set("memory", memNode); root.set("memory", memNode);
VirtualMemory virtualMemory = memory.getVirtualMemory();
DataNode swapNode = new DataNode(DataType.Map); DataNode swapNode = new DataNode(DataType.Map);
Swap swap = sigar.getSwap(); swapNode.set("total", sizeByteToMB(virtualMemory.getSwapTotal()));
swapNode.set("free", sizeByteToMB(swap.getFree())); swapNode.set("used", sizeByteToMB(virtualMemory.getSwapUsed()));
swapNode.set("used", sizeByteToMB(swap.getUsed())); swapNode.set("free", sizeByteToMB(virtualMemory.getSwapTotal() - virtualMemory.getSwapUsed()));
root.set("swap", swapNode); root.set("swap", swapNode);
} }
if(request.containsKey("proc")) { if(request.containsKey("proc")) {
DataNode procListNode = new DataNode(DataType.List); DataNode procListNode = new DataNode(DataType.List);
long[] pids = sigar.getProcList(); for(OSProcess process : os.getProcesses()) {
//long[] pids = Shell.getPids(sigar, new String[0]);
for( long pid : pids ) {
DataNode procNode = new DataNode(DataType.Map); DataNode procNode = new DataNode(DataType.Map);
procNode.set("pid", process.getProcessID());
procNode.set("pid", pid); procNode.set("mem", sizeByteToMB(process.getVirtualSize()));
try { procNode.set("user", process.getUserID());
procNode.set("mem", sizeByteToMB(sigar.getProcMem(pid).getSize())); procNode.set("cputime", process.getUserTime());
procNode.set("user", sigar.getProcCredName(pid).getUser()); procNode.set("cpu", process.getProcessCpuLoadCumulative());
procNode.set("cputime", sigar.getProcTime(pid).getTotal() / 1000); procNode.set("cmd", process.getCommandLine());
ProcCpu cpu = sigar.getProcCpu(pid);
procNode.set("cpu", CpuPerc.format(cpu.getPercent()));
}catch(Exception e){}
procNode.set("cmd", ProcUtil.getDescription(sigar, pid) );
procListNode.add(procNode); procListNode.add(procNode);
} }
root.set("proc", procListNode); root.set("proc", procListNode);
} }
} catch (SigarException e) {
e.printStackTrace(); if(request.containsKey("service")) {
DataNode procListNode = new DataNode(DataType.List);
for (OSService service : os.getServices()) {
DataNode procNode = new DataNode(DataType.Map);
procNode.set("id", service.getProcessID());
procNode.set("state", service.getState().toString());
procNode.set("name", service.getName());
procListNode.add(procNode);
} }
root.set("proc", procListNode);
}
return root; return root;
} }

View file

@ -29,7 +29,7 @@
<th data-field="cpu" data-sortable="true">CPU</th> <th data-field="cpu" data-sortable="true">CPU</th>
<th data-field="cputime" data-sortable="true">CpuTime</th> <th data-field="cputime" data-sortable="true">CpuTime</th>
<th data-field="mem" data-sortable="true">Memory(MB)</th> <th data-field="mem" data-sortable="true">Memory(MB)</th>
<th data-field="cmd" data-sortable="true" style="word-wrap: break-word;">Proc</th> <th data-field="cmd" data-sortable="true" style="overflow-wrap: break-word;">Proc</th>
</tr> </tr>
</thead> </thead>
</table> </table>
@ -73,7 +73,7 @@ function updateCpuChart(){
responsive: true, responsive: true,
maintainAspectRatio: false, // Fixes stuped behaviour with size maintainAspectRatio: false, // Fixes stuped behaviour with size
datasetFill: true, pointDot: false, showTooltips: false, datasetFill: true, pointDot: false, showTooltips: false,
scaleOverride: true, scaleStartValue: 0, scaleStepWidth: 0.1, scaleSteps: 10, scaleIntegersOnly: false, scaleOverride: true, scaleStartValue: 0, scaleStepWidth: 10, scaleSteps: 10, scaleIntegersOnly: false,
animation : false, animation : false,
}); });
} }

View file

@ -22,8 +22,9 @@
package wa.server.plugin.hwstatus; package wa.server.plugin.hwstatus;
import org.hyperic.sigar.*; import oshi.SystemInfo;
import org.hyperic.sigar.cmd.Shell; import oshi.hardware.HardwareAbstractionLayer;
import oshi.hardware.NetworkIF;
import wa.server.WAContext; import wa.server.WAContext;
import wa.server.page.WAStatusPage; import wa.server.page.WAStatusPage;
import zutil.io.file.FileUtil; import zutil.io.file.FileUtil;
@ -42,9 +43,6 @@ import java.util.Map;
public class NetStatus extends WAStatusPage { public class NetStatus extends WAStatusPage {
private static final String TEMPLATE = "wa/server/plugin/hwstatus/NetStatus.tmpl"; private static final String TEMPLATE = "wa/server/plugin/hwstatus/NetStatus.tmpl";
private int nextId;
private HashMap<String,Integer> idMap = new HashMap<String,Integer>();
private HashMap<String,ThroughputCalculator> txMap = new HashMap<String,ThroughputCalculator>(); private HashMap<String,ThroughputCalculator> txMap = new HashMap<String,ThroughputCalculator>();
private HashMap<String,ThroughputCalculator> rxMap = new HashMap<String,ThroughputCalculator>(); private HashMap<String,ThroughputCalculator> rxMap = new HashMap<String,ThroughputCalculator>();
@ -67,62 +65,61 @@ public class NetStatus extends WAStatusPage {
Map<String, String> cookie, Map<String, String> cookie,
Map<String, String> request) { Map<String, String> request) {
DataNode root = new DataNode(DataNode.DataType.Map); DataNode root = new DataNode(DataNode.DataType.Map);
try{
Sigar sigar = new Shell().getSigar(); SystemInfo si = new SystemInfo();
if(request.containsKey("net")){ if(request.containsKey("net")){
HardwareAbstractionLayer hal = si.getHardware();
DataNode intfListNode = new DataNode(DataNode.DataType.List); DataNode intfListNode = new DataNode(DataNode.DataType.List);
String[] intfNameList = sigar.getNetInterfaceList();
for( String intfName : intfNameList ){ for (NetworkIF intf : hal.getNetworkIFs()){
DataNode intfNode = new DataNode(DataNode.DataType.Map); DataNode intfNode = new DataNode(DataNode.DataType.Map);
if(idMap.containsKey(intfName)) intf.updateAttributes();
intfNode.set("pageName", idMap.get(intfName));
else{
idMap.put(intfName, nextId);
intfNode.set("pageName", nextId++);
}
NetInterfaceStat net_stat = sigar.getNetInterfaceStat(intfName); intfNode.set("name", intf.getName());
intfNode.set("name", intfName); intfNode.set("speed", intf.getSpeed());
intfNode.set("speed", net_stat.getSpeed()); intfNode.set("dropped", intf.getInDrops());
intfNode.set("dropped", net_stat.getRxDropped() + net_stat.getTxDropped() ); intfNode.set("error", intf.getInErrors() + intf.getOutErrors());
intfNode.set("error", net_stat.getRxErrors() + net_stat.getTxErrors() ); intfNode.set("total_tx", intf.getBytesSent());
intfNode.set("total_tx", net_stat.getTxBytes()); intfNode.set("total_rx", intf.getBytesRecv());
intfNode.set("total_rx", net_stat.getRxBytes()); intfNode.set("up", intf.isConnectorPresent());
intfNode.set("mac", intf.getMacaddr());
intfNode.set("type", intf.getIfType());
intfNode.set("desc", intf.getDisplayName());
ThroughputCalculator txThroughput = txMap.get(intfName); if (intf.getIPv4addr().length > 0)
intfNode.set("ipv4", intf.getIPv4addr()[0]);
if (intf.getIPv6addr().length > 0)
intfNode.set("ipv6", intf.getIPv6addr()[0]);
if (intf.getSubnetMasks().length > 0)
intfNode.set("netmask", intf.getSubnetMasks()[0]);
ThroughputCalculator txThroughput = txMap.get(intf);
if(txThroughput == null) { if(txThroughput == null) {
txThroughput = new ThroughputCalculator(); txThroughput = new ThroughputCalculator();
txMap.put(intfName, txThroughput); txMap.put(intf.getName(), txThroughput);
} }
txThroughput.setTotalHandledData(net_stat.getTxBytes()); txThroughput.setTotalHandledData(intf.getBytesSent());
intfNode.set("tx", txThroughput.getBitThroughput()); intfNode.set("tx", txThroughput.getBitThroughput());
ThroughputCalculator rxThroughput = rxMap.get(intfName); ThroughputCalculator rxThroughput = rxMap.get(intf);
if(rxThroughput == null) { if(rxThroughput == null) {
rxThroughput = new ThroughputCalculator(); rxThroughput = new ThroughputCalculator();
rxMap.put(intfName, rxThroughput); rxMap.put(intf.getName(), rxThroughput);
} }
rxThroughput.setTotalHandledData(net_stat.getRxBytes()); rxThroughput.setTotalHandledData(intf.getBytesRecv());
intfNode.set("rx", rxThroughput.getBitThroughput()); intfNode.set("rx", rxThroughput.getBitThroughput());
NetInterfaceConfig net_conf = sigar.getNetInterfaceConfig( intfName );
intfNode.set("up", (net_conf.getFlags() & NetFlags.IFF_UP) > 0 );
intfNode.set("ip", net_conf.getAddress() );
intfNode.set("netmask", net_conf.getNetmask() );
intfNode.set("mac", net_conf.getHwaddr() );
intfNode.set("type", net_conf.getType() );
intfNode.set("flags", NetFlags.getIfFlagsString(net_conf.getFlags()) );
intfNode.set("desc", net_conf.getDescription() );
intfListNode.add(intfNode); intfListNode.add(intfNode);
} }
root.set("net", intfListNode); root.set("net", intfListNode);
} }
if (request.containsKey("routing")) { if (request.containsKey("routing")) {
DataNode routeListNode = new DataNode(DataNode.DataType.List); DataNode routeListNode = new DataNode(DataNode.DataType.List);
NetRoute[] routes = sigar.getNetRouteList();
for( NetRoute route : routes ) { /*for(NetRoute route : os.) {
DataNode routeNode = new DataNode(DataNode.DataType.Map); DataNode routeNode = new DataNode(DataNode.DataType.Map);
routeNode.set("interface", route.getIfname()); routeNode.set("interface", route.getIfname());
routeNode.set("destination", route.getDestination()); routeNode.set("destination", route.getDestination());
@ -131,12 +128,11 @@ public class NetStatus extends WAStatusPage {
routeNode.set("flags", NetFlags.getIfFlagsString((route.getFlags()))); routeNode.set("flags", NetFlags.getIfFlagsString((route.getFlags())));
routeNode.set("metric", route.getMetric()); routeNode.set("metric", route.getMetric());
routeListNode.add(routeNode); routeListNode.add(routeNode);
} }*/
root.set("routing", routeListNode); root.set("routing", routeListNode);
} }
} catch (SigarException e) {
e.printStackTrace();
}
return root; return root;
} }

View file

@ -80,7 +80,8 @@ function updateNet(){
$(element).find(".net-up").html( (net.up ? $(element).find(".net-up").html( (net.up ?
"<span class='label label-success'>UP</span>" : "<span class='label label-success'>UP</span>" :
"<span class='label label-danger'>DOWN</span>") ); "<span class='label label-danger'>DOWN</span>") );
$(element).find(".net-ip").html(net.ip); $(element).find(".net-ipv4").html(net.ipv4);
//$(element).find(".net-ipv6").html(net.ipv6);
$(element).find(".net-netmask").html(net.netmask); $(element).find(".net-netmask").html(net.netmask);
$(element).find(".net-mac").html(net.mac); $(element).find(".net-mac").html(net.mac);
$(element).find(".net-type").html(net.type); $(element).find(".net-type").html(net.type);
@ -128,7 +129,8 @@ function updateRoutingTable(){
<table class="table small net-detail"> <table class="table small net-detail">
<tr><th>Name</th><td class="net-name"></td></tr> <tr><th>Name</th><td class="net-name"></td></tr>
<tr><th>Status</th><td class="net-up"></td></tr> <tr><th>Status</th><td class="net-up"></td></tr>
<tr><th>IP</th><td class="net-ip"></td></tr> <tr><th>IPv4</th><td class="net-ipv4"></td></tr>
<!--<tr><th>IPv6</th><td class="net-ipv6" style="word-wrap: break-word;"></td></tr>-->
<tr><th>Netmask</th><td class="net-netmask"></td></tr> <tr><th>Netmask</th><td class="net-netmask"></td></tr>
<tr><th>Total Rx</th><td class="net-total-rx"></td></tr> <tr><th>Total Rx</th><td class="net-total-rx"></td></tr>
<tr><th>Total Tx</th><td class="net-total-tx"></td></tr> <tr><th>Total Tx</th><td class="net-total-tx"></td></tr>

View file

@ -21,9 +21,6 @@
*/ */
package wa.server.plugin.tomcat; package wa.server.plugin.tomcat;
import java.io.PrintStream;
public class TomcatConfigApplication { public class TomcatConfigApplication {
/* /*

0
webadmin_default.db Executable file → Normal file
View file