diff --git a/build.gradle b/build.gradle index fb2af5a..6d722ec 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ repositories { } 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 'com.github.oshi:oshi-core:5.2.5' @@ -25,7 +25,11 @@ sourceSets { srcDirs 'src' } resources { - srcDir 'resources' + exclude '**/*.java' + srcDirs = [ + 'resources', + 'src', + ] } } test { diff --git a/src/wa/server/WAContext.java b/src/wa/server/WAContext.java index 5c62d79..3fedc91 100755 --- a/src/wa/server/WAContext.java +++ b/src/wa/server/WAContext.java @@ -41,7 +41,6 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/src/wa/server/WebAdminServer.java b/src/wa/server/WebAdminServer.java index 6d4521b..152a5ee 100755 --- a/src/wa/server/WebAdminServer.java +++ b/src/wa/server/WebAdminServer.java @@ -2,14 +2,9 @@ package wa.server; import wa.server.page.ConfigPage; import wa.server.page.WAPage; -import zutil.io.file.FileUtil; import zutil.log.CompactLogFormatter; 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.Logger; diff --git a/src/wa/server/page/WAServicePage.java b/src/wa/server/page/WAServicePage.java index 62c4e3c..b096f2d 100755 --- a/src/wa/server/page/WAServicePage.java +++ b/src/wa/server/page/WAServicePage.java @@ -30,7 +30,6 @@ import zutil.io.file.FileUtil; import zutil.log.LogUtil; import zutil.net.http.HttpHeader; import zutil.parser.Templator; -import zutil.ui.Navigation; import java.io.IOException; import java.util.Map; diff --git a/src/wa/server/plugin/WAConfigObject.java b/src/wa/server/plugin/WAConfigObject.java index 54fbeed..136acfa 100755 --- a/src/wa/server/plugin/WAConfigObject.java +++ b/src/wa/server/plugin/WAConfigObject.java @@ -4,7 +4,6 @@ package wa.server.plugin; import zutil.db.DBConnection; import zutil.db.bean.DBBean; import zutil.db.bean.DBBeanSQLResultHandler; -import zutil.db.handler.SimpleSQLResult; import zutil.parser.json.JSONParser; import zutil.parser.json.JSONWriter; import zutil.ui.Configurator; diff --git a/src/wa/server/plugin/apache/ApacheService.java b/src/wa/server/plugin/apache/ApacheService.java index 21b6bfc..f80c176 100755 --- a/src/wa/server/plugin/apache/ApacheService.java +++ b/src/wa/server/plugin/apache/ApacheService.java @@ -23,7 +23,9 @@ package wa.server.plugin.apache; 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. diff --git a/src/wa/server/plugin/hwstatus/HDDStatus.java b/src/wa/server/plugin/hwstatus/HDDStatus.java index f91139b..4aeb481 100755 --- a/src/wa/server/plugin/hwstatus/HDDStatus.java +++ b/src/wa/server/plugin/hwstatus/HDDStatus.java @@ -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 idMap = new HashMap(); - - - public HDDStatus() { super("hdd", "Harddrives"); } @@ -67,42 +58,30 @@ public class HDDStatus extends WAStatusPage { Map cookie, Map 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; } diff --git a/src/wa/server/plugin/hwstatus/HDDStatus.tmpl b/src/wa/server/plugin/hwstatus/HDDStatus.tmpl index 063eacd..5155ffe 100755 --- a/src/wa/server/plugin/hwstatus/HDDStatus.tmpl +++ b/src/wa/server/plugin/hwstatus/HDDStatus.tmpl @@ -59,7 +59,7 @@ function byteToString(value){
-

+

diff --git a/src/wa/server/plugin/hwstatus/HwStatus.java b/src/wa/server/plugin/hwstatus/HwStatus.java index 09beb2d..dd7aced 100755 --- a/src/wa/server/plugin/hwstatus/HwStatus.java +++ b/src/wa/server/plugin/hwstatus/HwStatus.java @@ -22,8 +22,14 @@ package wa.server.plugin.hwstatus; -import org.hyperic.sigar.*; -import org.hyperic.sigar.cmd.Shell; +import oshi.SystemInfo; +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.page.WAStatusPage; import zutil.StringUtil; @@ -42,6 +48,7 @@ import java.util.Map; public class HwStatus extends WAStatusPage { private static final String TEMPLATE = "wa/server/plugin/hwstatus/HwStatus.tmpl"; + private long[][] prevProcTicks; public HwStatus() { super("hw", "Hardware Summary"); @@ -61,60 +68,83 @@ public class HwStatus extends WAStatusPage { Map cookie, Map request) { DataNode root = new DataNode(DataNode.DataType.Map); - try{ - Sigar sigar = new Shell().getSigar(); - if(request.containsKey("uptime")){ - root.set("uptime", - StringUtil.formatTimeToString( - (long)sigar.getUptime().getUptime())); - } - if(request.containsKey("cpu")) { - DataNode cpuNode = new DataNode(DataType.List); - CpuInfo cpu_info = sigar.getCpuInfoList()[0]; - for (CpuPerc cpu : sigar.getCpuPercList()) { - cpuNode.add(Math.round(cpu.getCombined() * 100.0) / 100.0); - } - root.set("cpu", cpuNode); - } - if(request.containsKey("memory")) { - DataNode memNode = new DataNode(DataType.Map); - Mem mem = sigar.getMem(); - memNode.set("free", sizeByteToMB(mem.getFree())); - memNode.set("used", sizeByteToMB(mem.getUsed())); - root.set("memory", memNode); + SystemInfo si = new SystemInfo(); + HardwareAbstractionLayer hal = si.getHardware(); + OperatingSystem os = si.getOperatingSystem(); - DataNode swapNode = new DataNode(DataType.Map); - Swap swap = sigar.getSwap(); - swapNode.set("free", sizeByteToMB(swap.getFree())); - swapNode.set("used", sizeByteToMB(swap.getUsed())); - root.set("swap", swapNode); - } - if(request.containsKey("proc")) { - DataNode procListNode = new DataNode(DataType.List); - - long[] pids = sigar.getProcList(); - //long[] pids = Shell.getPids(sigar, new String[0]); - for( long pid : pids ) { - DataNode procNode = new DataNode(DataType.Map); - - procNode.set("pid", pid); - try { - procNode.set("mem", sizeByteToMB(sigar.getProcMem(pid).getSize())); - procNode.set("user", sigar.getProcCredName(pid).getUser()); - procNode.set("cputime", sigar.getProcTime(pid).getTotal() / 1000); - 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); - } - root.set("proc", procListNode); - } - } catch (SigarException e) { - e.printStackTrace(); + if(request.containsKey("uptime")){ + root.set("uptime", StringUtil.formatTimeToString(os.getSystemUptime())); } + + if(request.containsKey("cpu")) { + DataNode cpuNode = new DataNode(DataType.List); + CentralProcessor processor = hal.getProcessor(); + + 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); + } + + if(request.containsKey("memory")) { + GlobalMemory memory = hal.getMemory(); + + DataNode memNode = new DataNode(DataType.Map); + memNode.set("total", sizeByteToMB(memory.getTotal())); + memNode.set("used", sizeByteToMB(memory.getTotal() - memory.getAvailable())); + memNode.set("free", sizeByteToMB(memory.getAvailable())); + root.set("memory", memNode); + + VirtualMemory virtualMemory = memory.getVirtualMemory(); + + DataNode swapNode = new DataNode(DataType.Map); + swapNode.set("total", sizeByteToMB(virtualMemory.getSwapTotal())); + swapNode.set("used", sizeByteToMB(virtualMemory.getSwapUsed())); + swapNode.set("free", sizeByteToMB(virtualMemory.getSwapTotal() - virtualMemory.getSwapUsed())); + root.set("swap", swapNode); + } + + if(request.containsKey("proc")) { + DataNode procListNode = new DataNode(DataType.List); + + for(OSProcess process : os.getProcesses()) { + DataNode procNode = new DataNode(DataType.Map); + procNode.set("pid", process.getProcessID()); + procNode.set("mem", sizeByteToMB(process.getVirtualSize())); + procNode.set("user", process.getUserID()); + procNode.set("cputime", process.getUserTime()); + procNode.set("cpu", process.getProcessCpuLoadCumulative()); + procNode.set("cmd", process.getCommandLine()); + + procListNode.add(procNode); + } + + root.set("proc", procListNode); + } + + 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; } diff --git a/src/wa/server/plugin/hwstatus/HwStatus.tmpl b/src/wa/server/plugin/hwstatus/HwStatus.tmpl index 3d8f12a..a099303 100755 --- a/src/wa/server/plugin/hwstatus/HwStatus.tmpl +++ b/src/wa/server/plugin/hwstatus/HwStatus.tmpl @@ -29,7 +29,7 @@ CPU CpuTime Memory(MB) - Proc + Proc @@ -54,7 +54,7 @@ var cpu_data = { }; function updateCpuChart(){ - $.getJSON("?json&cpu", function( data ) { + $.getJSON("?json&cpu", function(data) { // Setup graph if(cpu_chart == null){ // Fill in cpus @@ -73,7 +73,7 @@ function updateCpuChart(){ responsive: true, maintainAspectRatio: false, // Fixes stuped behaviour with size 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, }); } @@ -102,7 +102,7 @@ var mem_data = [ ]; function updateMemChart(){ - $.getJSON("?json&memory", function( data ) { + $.getJSON("?json&memory", function(data) { if(mem_chart == null){ var ctx = $("#mem-chart").get(0).getContext("2d"); mem_chart = new Chart(ctx).Doughnut(mem_data, { @@ -123,7 +123,7 @@ function updateMemChart(){ function updateProcTable(){ - $.getJSON("?json&proc", function( data ) { + $.getJSON("?json&proc", function(data) { $('#proc-list').bootstrapTable({ data: data['proc'] }); diff --git a/src/wa/server/plugin/hwstatus/NetStatus.java b/src/wa/server/plugin/hwstatus/NetStatus.java index 4e41770..2cecc0c 100755 --- a/src/wa/server/plugin/hwstatus/NetStatus.java +++ b/src/wa/server/plugin/hwstatus/NetStatus.java @@ -22,8 +22,9 @@ package wa.server.plugin.hwstatus; -import org.hyperic.sigar.*; -import org.hyperic.sigar.cmd.Shell; +import oshi.SystemInfo; +import oshi.hardware.HardwareAbstractionLayer; +import oshi.hardware.NetworkIF; import wa.server.WAContext; import wa.server.page.WAStatusPage; import zutil.io.file.FileUtil; @@ -42,9 +43,6 @@ import java.util.Map; public class NetStatus extends WAStatusPage { private static final String TEMPLATE = "wa/server/plugin/hwstatus/NetStatus.tmpl"; - private int nextId; - private HashMap idMap = new HashMap(); - private HashMap txMap = new HashMap(); private HashMap rxMap = new HashMap(); @@ -67,62 +65,61 @@ public class NetStatus extends WAStatusPage { Map cookie, Map request) { DataNode root = new DataNode(DataNode.DataType.Map); - try{ - Sigar sigar = new Shell().getSigar(); + + SystemInfo si = new SystemInfo(); + if(request.containsKey("net")){ + HardwareAbstractionLayer hal = si.getHardware(); 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); - if(idMap.containsKey(intfName)) - intfNode.set("pageName", idMap.get(intfName)); - else{ - idMap.put(intfName, nextId); - intfNode.set("pageName", nextId++); - } + intf.updateAttributes(); - NetInterfaceStat net_stat = sigar.getNetInterfaceStat(intfName); - intfNode.set("name", intfName); - intfNode.set("speed", net_stat.getSpeed()); - intfNode.set("dropped", net_stat.getRxDropped() + net_stat.getTxDropped() ); - intfNode.set("error", net_stat.getRxErrors() + net_stat.getTxErrors() ); - intfNode.set("total_tx", net_stat.getTxBytes()); - intfNode.set("total_rx", net_stat.getRxBytes()); + intfNode.set("name", intf.getName()); + intfNode.set("speed", intf.getSpeed()); + intfNode.set("dropped", intf.getInDrops()); + intfNode.set("error", intf.getInErrors() + intf.getOutErrors()); + intfNode.set("total_tx", intf.getBytesSent()); + intfNode.set("total_rx", intf.getBytesRecv()); + 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) { 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()); - ThroughputCalculator rxThroughput = rxMap.get(intfName); + ThroughputCalculator rxThroughput = rxMap.get(intf); if(rxThroughput == null) { 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()); - 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); } root.set("net", intfListNode); } - if(request.containsKey("routing")) { + + if (request.containsKey("routing")) { 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); routeNode.set("interface", route.getIfname()); routeNode.set("destination", route.getDestination()); @@ -131,12 +128,11 @@ public class NetStatus extends WAStatusPage { routeNode.set("flags", NetFlags.getIfFlagsString((route.getFlags()))); routeNode.set("metric", route.getMetric()); routeListNode.add(routeNode); - } + }*/ + root.set("routing", routeListNode); } - } catch (SigarException e) { - e.printStackTrace(); - } + return root; } diff --git a/src/wa/server/plugin/hwstatus/NetStatus.tmpl b/src/wa/server/plugin/hwstatus/NetStatus.tmpl index 0b53dd1..998225c 100755 --- a/src/wa/server/plugin/hwstatus/NetStatus.tmpl +++ b/src/wa/server/plugin/hwstatus/NetStatus.tmpl @@ -80,7 +80,8 @@ function updateNet(){ $(element).find(".net-up").html( (net.up ? "UP" : "DOWN") ); - $(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-mac").html(net.mac); $(element).find(".net-type").html(net.type); @@ -128,7 +129,8 @@ function updateRoutingTable(){ - + + diff --git a/src/wa/server/plugin/tomcat/TomcatConfigApplication.java b/src/wa/server/plugin/tomcat/TomcatConfigApplication.java index f6e2451..1a14d00 100755 --- a/src/wa/server/plugin/tomcat/TomcatConfigApplication.java +++ b/src/wa/server/plugin/tomcat/TomcatConfigApplication.java @@ -21,9 +21,6 @@ */ package wa.server.plugin.tomcat; -import java.io.PrintStream; - - public class TomcatConfigApplication { /* diff --git a/webadmin_default.db b/webadmin_default.db old mode 100755 new mode 100644
Name
Status
IP
IPv4
Netmask
Total Rx
Total Tx