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 {
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 {

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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.

View file

@ -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;
}

View file

@ -59,7 +59,7 @@ function byteToString(value){
<div id="" class="col-md-4"><div class="panel panel-default">
<div class="panel-heading hdd-title"></div>
<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-bar hdd-used" role="progressbar"></div>
<center class="hdd-free"></center>

View file

@ -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<String, String> cookie,
Map<String, String> 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;
}

View file

@ -29,7 +29,7 @@
<th data-field="cpu" data-sortable="true">CPU</th>
<th data-field="cputime" data-sortable="true">CpuTime</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>
</thead>
</table>
@ -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']
});

View file

@ -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<String,Integer> idMap = new HashMap<String,Integer>();
private HashMap<String,ThroughputCalculator> txMap = 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> 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;
}

View file

@ -80,7 +80,8 @@ function updateNet(){
$(element).find(".net-up").html( (net.up ?
"<span class='label label-success'>UP</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-mac").html(net.mac);
$(element).find(".net-type").html(net.type);
@ -128,7 +129,8 @@ function updateRoutingTable(){
<table class="table small net-detail">
<tr><th>Name</th><td class="net-name"></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>Total Rx</th><td class="net-total-rx"></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;
import java.io.PrintStream;
public class TomcatConfigApplication {
/*

0
webadmin_default.db Executable file → Normal file
View file