Initial commit
This commit is contained in:
commit
aa4e110832
69 changed files with 17898 additions and 0 deletions
11
src/wa/server/plugin/WAConfigurator.java
Normal file
11
src/wa/server/plugin/WAConfigurator.java
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package wa.server.plugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import zutil.db.DBConnection;
|
||||
|
||||
public interface WAConfigurator {
|
||||
public void read(DBConnection db) throws SQLException;
|
||||
public void save(DBConnection db) throws IOException;
|
||||
}
|
||||
5
src/wa/server/plugin/WAFrontend.java
Normal file
5
src/wa/server/plugin/WAFrontend.java
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package wa.server.plugin;
|
||||
|
||||
public interface WAFrontend {
|
||||
|
||||
}
|
||||
31
src/wa/server/plugin/WAInstaller.java
Normal file
31
src/wa/server/plugin/WAInstaller.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2014 Ziver
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package wa.server.plugin;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2014-11-09.
|
||||
*/
|
||||
public interface WAInstaller {
|
||||
public void install();
|
||||
public void uninstall();
|
||||
}
|
||||
14
src/wa/server/plugin/WAService.java
Normal file
14
src/wa/server/plugin/WAService.java
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package wa.server.plugin;
|
||||
|
||||
public interface WAService {
|
||||
public enum WAServiceStatus{
|
||||
RUNNING,
|
||||
NOT_RESPONDING,
|
||||
UNAVAILABLE,
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
public void start();
|
||||
public void stop();
|
||||
public WAServiceStatus getStatus();
|
||||
}
|
||||
37
src/wa/server/plugin/WAStatus.java
Normal file
37
src/wa/server/plugin/WAStatus.java
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Ziver
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package wa.server.plugin;
|
||||
|
||||
import zutil.parser.DataNode;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-04-06.
|
||||
*/
|
||||
public interface WAStatus {
|
||||
|
||||
public String getName();
|
||||
|
||||
public String html();
|
||||
|
||||
public void jsonUpdate(DataNode root);
|
||||
}
|
||||
40
src/wa/server/plugin/apache/ApacheConfigVirtualHost.java
Normal file
40
src/wa/server/plugin/apache/ApacheConfigVirtualHost.java
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package wa.server.plugin.apache;
|
||||
|
||||
import wa.server.WAConstants;
|
||||
import zutil.db.bean.DBBean;
|
||||
import zutil.db.bean.DBBean.DBTable;;
|
||||
|
||||
@DBTable(WAConstants.DB_TABLE_PREFIX+"_apache_vhost")
|
||||
public class ApacheConfigVirtualHost extends DBBean{
|
||||
protected String domain;
|
||||
protected String path;
|
||||
protected boolean ssl;
|
||||
protected boolean tomcat;
|
||||
|
||||
|
||||
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
public void setDomain(String domain) {
|
||||
this.domain = domain;
|
||||
}
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
public boolean isSSL() {
|
||||
return ssl;
|
||||
}
|
||||
public void setSSL(boolean ssl) {
|
||||
this.ssl = ssl;
|
||||
}
|
||||
public boolean isTomcatApp() {
|
||||
return tomcat;
|
||||
}
|
||||
public void setTomcatApp(boolean tomcat) {
|
||||
this.tomcat = tomcat;
|
||||
}
|
||||
}
|
||||
104
src/wa/server/plugin/apache/ApacheConfigurator.java
Normal file
104
src/wa/server/plugin/apache/ApacheConfigurator.java
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
package wa.server.plugin.apache;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import wa.server.WAConstants;
|
||||
import wa.server.plugin.WAConfigurator;
|
||||
import wa.server.util.ConfigFileUtil;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.io.file.FileUtil;
|
||||
|
||||
public class ApacheConfigurator implements WAConfigurator {
|
||||
private static final String APACHE_CONF_FILE = "wa_apache_vhost.conf";
|
||||
private static final String APACHE_MAIN_CONFIG_FILE = "/etc/apache2/apache2.conf";
|
||||
private static final String STATIC_PRE_CONF = "wa/server/plugin/apache/apache_default.config";
|
||||
|
||||
// Configuration data
|
||||
List<ApacheConfigVirtualHost> vhosts;
|
||||
|
||||
|
||||
public ApacheConfigurator(){
|
||||
vhosts = new LinkedList<ApacheConfigVirtualHost>();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void read(DBConnection db) throws SQLException {
|
||||
vhosts = ApacheConfigVirtualHost.load(db, ApacheConfigVirtualHost.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(DBConnection db) throws IOException {
|
||||
File file = WAConstants.getConfigFile(APACHE_CONF_FILE);
|
||||
// Update Man configuration file
|
||||
ConfigFileUtil.writeBetweenBoundary(
|
||||
new File(APACHE_MAIN_CONFIG_FILE),
|
||||
"#",
|
||||
"Include "+file.getAbsolutePath());
|
||||
|
||||
// Write Vhost configuration
|
||||
PrintStream out = new PrintStream(file);
|
||||
|
||||
out.println(FileUtil.getContent(new File(STATIC_PRE_CONF)));
|
||||
out.println("######################################");
|
||||
out.println("# vhost.php");
|
||||
for(ApacheConfigVirtualHost vhost : vhosts){
|
||||
if(vhost.isTomcatApp())
|
||||
writeTomcatVhost(out, vhost);
|
||||
else if(vhost.isSSL())
|
||||
writeSSLVhost(out, vhost);
|
||||
else
|
||||
writeVhost(out, vhost);
|
||||
}
|
||||
|
||||
out.close();
|
||||
}
|
||||
|
||||
private void writeVhost(PrintStream out, ApacheConfigVirtualHost conf) throws IOException{
|
||||
out.println("<VirtualHost *:80>");
|
||||
out.println(" ServerName "+conf.getDomain()+":80");
|
||||
out.println(" DocumentRoot "+conf.getPath());
|
||||
out.println("</VirtualHost>");
|
||||
out.println("");
|
||||
}
|
||||
|
||||
private void writeSSLVhost(PrintStream out, ApacheConfigVirtualHost conf) throws IOException{
|
||||
out.println("<VirtualHost *:80>");
|
||||
out.println(" ServerName "+conf.getDomain()+":80");
|
||||
out.println(" RewriteEngine On");
|
||||
out.println(" RewriteCond %{SERVER_PORT} !^443$");
|
||||
out.println(" RewriteRule ^(.*)$ https://server$1 [L,R]");
|
||||
out.println("</VirtualHost>");
|
||||
out.println("<VirtualHost *:443>");
|
||||
out.println(" ServerName "+conf.getDomain()+":443");
|
||||
out.println(" DocumentRoot "+conf.getPath());
|
||||
out.println("");
|
||||
out.println(" SSLEngine on");
|
||||
out.println(" SSLCertificateFile "+WAConstants.getConfigFile(WAConstants.WA_SSL_CERT));
|
||||
out.println(" SSLCertificateKeyFile "+WAConstants.getConfigFile(WAConstants.WA_SSL_KEY));
|
||||
out.println("</VirtualHost>");
|
||||
out.println("");
|
||||
}
|
||||
|
||||
private void writeTomcatVhost(PrintStream out, ApacheConfigVirtualHost conf) throws IOException{
|
||||
out.println("<VirtualHost *:80>");
|
||||
out.println(" ServerName "+conf.getDomain()+":80");
|
||||
out.println(" ");
|
||||
out.println(" RewriteEngine On");
|
||||
out.println(" RewriteRule ^/$ /"+conf.getPath()+" [R]");
|
||||
out.println(" ProxyPreserveHost on");
|
||||
out.println(" <Proxy *>");
|
||||
out.println(" Order deny,allow");
|
||||
out.println(" Allow from all");
|
||||
out.println(" </Proxy>");
|
||||
out.println(" ProxyPass / ajp://localhost:8009/");
|
||||
out.println(" ProxyPassReverse / http://localhost:8080/");
|
||||
out.println("</VirtualHost>");
|
||||
out.println("");
|
||||
}
|
||||
}
|
||||
43
src/wa/server/plugin/apache/ApacheInstaller.java
Normal file
43
src/wa/server/plugin/apache/ApacheInstaller.java
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2014 Ziver
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package wa.server.plugin.apache;
|
||||
|
||||
import wa.server.plugin.WAInstaller;
|
||||
import wa.server.util.AptGet;
|
||||
import zutil.osal.OSAbstractionLayer;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2014-11-09.
|
||||
*/
|
||||
public class ApacheInstaller implements WAInstaller {
|
||||
|
||||
@Override
|
||||
public void install() {
|
||||
AptGet.install("apache php5 php5-mcrypt php5-gd imagemagick");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uninstall() {
|
||||
AptGet.purge("apache php5 php5-mcrypt php5-gd imagemagick");
|
||||
}
|
||||
}
|
||||
68
src/wa/server/plugin/apache/ApacheService.java
Normal file
68
src/wa/server/plugin/apache/ApacheService.java
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 2014 Ziver
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package wa.server.plugin.apache;
|
||||
|
||||
import wa.server.plugin.WAService;
|
||||
import wa.server.util.Ps;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.osal.OSAbstractionLayer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2014-12-23.
|
||||
*/
|
||||
public class ApacheService implements WAService {
|
||||
private static Logger log = LogUtil.getLogger();
|
||||
|
||||
private static OSAbstractionLayer os = OSAbstractionLayer.getInstance();
|
||||
private static final String PID_FILE = "/var/run/apache2.pid";
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
os.runCommand("service apache2 start");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
os.runCommand("service apache2 stop");
|
||||
}
|
||||
|
||||
@Override
|
||||
public WAServiceStatus getStatus() {
|
||||
try {
|
||||
int pid = Integer.parseInt(
|
||||
FileUtil.getContent(new File(PID_FILE)));
|
||||
if(Ps.isRunning(pid))
|
||||
return WAServiceStatus.RUNNING;
|
||||
return WAServiceStatus.UNAVAILABLE;
|
||||
}catch(IOException e){
|
||||
log.log(Level.WARNING, null, e);
|
||||
}
|
||||
return WAServiceStatus.UNKNOWN;
|
||||
}
|
||||
}
|
||||
91
src/wa/server/plugin/apache/apache_default.config
Normal file
91
src/wa/server/plugin/apache/apache_default.config
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
###################################
|
||||
# default.php
|
||||
|
||||
ScriptAlias /cgi-bin/ /home/www/cgi-bin/
|
||||
#NameVirtualHost *:80
|
||||
NameVirtualHost *:443
|
||||
ServerName koc.se
|
||||
ServerAdmin ziver@koc.se
|
||||
|
||||
#<VirtualHost *:80>
|
||||
# Redirect / http://koc.se
|
||||
#</VirtualHost>
|
||||
|
||||
# WebAdmin {
|
||||
<VirtualHost *:80>
|
||||
ServerName admin.koc.se:80
|
||||
RewriteEngine On
|
||||
RewriteCond %{SERVER_PORT} !^443$
|
||||
RewriteRule ^(.*)$ https://admin.koc.se$1 [L,R]
|
||||
</VirtualHost>
|
||||
<VirtualHost *:443>
|
||||
ServerName admin.koc.se:443
|
||||
DocumentRoot ".$config["apache_www_path"]."/admin
|
||||
|
||||
SSLEngine on
|
||||
SSLCertificateFile ".$config["apache_conf_path"]."/cert/server.crt
|
||||
SSLCertificateKeyFile ".$config["apache_conf_path"]."/cert/server.key
|
||||
</VirtualHost>
|
||||
|
||||
<VirtualHost *:80>
|
||||
ServerName server:80
|
||||
RewriteEngine On
|
||||
RewriteCond %{SERVER_PORT} !^443$
|
||||
RewriteRule ^(.*)$ https://server$1 [L,R]
|
||||
</VirtualHost>
|
||||
<VirtualHost *:443>
|
||||
ServerName server:443
|
||||
DocumentRoot ".$config["apache_www_path"]."/admin
|
||||
|
||||
SSLEngine on
|
||||
SSLCertificateFile ".$config["apache_conf_path"]."/cert/server.crt
|
||||
SSLCertificateKeyFile ".$config["apache_conf_path"]."/cert/server.key
|
||||
</VirtualHost>
|
||||
|
||||
<VirtualHost *:80>
|
||||
ServerName localhost:80
|
||||
RewriteEngine On
|
||||
RewriteCond %{SERVER_PORT} !^443$
|
||||
RewriteRule ^(.*)$ https://localhost$1 [L,R]
|
||||
</VirtualHost>
|
||||
<VirtualHost *:443>
|
||||
ServerName localhost:443
|
||||
DocumentRoot ".$config["apache_www_path"]."/admin
|
||||
|
||||
SSLEngine on
|
||||
SSLCertificateFile ".$config["apache_conf_path"]."/cert/server.crt
|
||||
SSLCertificateKeyFile ".$config["apache_conf_path"]."/cert/server.key
|
||||
</VirtualHost>
|
||||
|
||||
<VirtualHost *:80>
|
||||
ServerName 192.168.0.2:80
|
||||
RewriteEngine On
|
||||
RewriteCond %{SERVER_PORT} !^443$
|
||||
RewriteRule ^(.*)$ https://192.168.0.2$1 [L,R]
|
||||
</VirtualHost>
|
||||
<VirtualHost *:443>
|
||||
ServerName 192.168.0.2:443
|
||||
DocumentRoot ".$config["apache_www_path"]."/admin
|
||||
|
||||
SSLEngine on
|
||||
SSLCertificateFile ".$config["apache_conf_path"]."/cert/server.crt
|
||||
SSLCertificateKeyFile ".$config["apache_conf_path"]."/cert/server.key
|
||||
</VirtualHost>
|
||||
#}
|
||||
# Mythweb
|
||||
#<VirtualHost *:80>
|
||||
# ServerName mythtv.koc.se
|
||||
# DirectoryIndex mythweb
|
||||
# DocumentRoot /var/www
|
||||
#
|
||||
# # Include /etc/apache2/sites-available/mythweb.conf
|
||||
#</VirtualHost>
|
||||
# TvHeadend
|
||||
<VirtualHost *:80>
|
||||
ServerName tv.koc.se:80
|
||||
|
||||
ProxyPreserveHost on
|
||||
ProxyPass / http://localhost:9981/
|
||||
ProxyPassReverse / http://localhost:9981/
|
||||
</VirtualHost>
|
||||
|
||||
9
src/wa/server/plugin/apache/plugin.json
Normal file
9
src/wa/server/plugin/apache/plugin.json
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"version": "1.0",
|
||||
"name": "Apache Web Server",
|
||||
"interfaces": {
|
||||
"wa.server.plugin.WAInstaller": "wa.server.plugin.apache.ApacheInstaller",
|
||||
"wa.server.plugin.WAConfigurator": "wa.server.plugin.apache.ApacheConfigurator",
|
||||
"wa.server.plugin.WAService": "wa.server.plugin.apache.ApacheService"
|
||||
}
|
||||
}
|
||||
71
src/wa/server/plugin/hwstatus/CpuStatus.java
Normal file
71
src/wa/server/plugin/hwstatus/CpuStatus.java
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Ziver
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package wa.server.plugin.hwstatus;
|
||||
|
||||
import org.hyperic.sigar.CpuInfo;
|
||||
import org.hyperic.sigar.CpuPerc;
|
||||
import org.hyperic.sigar.Sigar;
|
||||
import org.hyperic.sigar.SigarException;
|
||||
import org.hyperic.sigar.cmd.Shell;
|
||||
import wa.server.plugin.WAStatus;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.parser.DataNode;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-04-07.
|
||||
*/
|
||||
public class CpuStatus implements WAStatus {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Cpu Load";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String html() {
|
||||
try {
|
||||
return FileUtil.getContent(FileUtil.findURL("wa/server/plugin/hwstatus/CpuStatus.tmpl"));
|
||||
} catch (IOException e) {
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonUpdate(DataNode root) {
|
||||
DataNode cpuNode = new DataNode(DataNode.DataType.List);
|
||||
|
||||
try{
|
||||
Sigar sigar = new Shell().getSigar();
|
||||
for(CpuInfo cpu_info : sigar.getCpuInfoList()){
|
||||
for(CpuPerc cpu : sigar.getCpuPercList()){
|
||||
cpuNode.add(cpu.getCombined());
|
||||
}
|
||||
}
|
||||
} catch (SigarException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
root.set("cpu", cpuNode);
|
||||
}
|
||||
}
|
||||
39
src/wa/server/plugin/hwstatus/CpuStatus.tmpl
Normal file
39
src/wa/server/plugin/hwstatus/CpuStatus.tmpl
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Cpu Status</div>
|
||||
<div class="panel-body">
|
||||
<div id="cpu_chart"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script language="javascript" type="text/javascript">
|
||||
var cpu_data = [];
|
||||
|
||||
function update_cpu(data){
|
||||
$(data).find("cpu").each(function() {
|
||||
$(this).find("core").each(function() {
|
||||
var cpu_nr = parseInt($(this).attr("id"));
|
||||
if(cpu_data.length < (cpu_nr+1))
|
||||
cpu_data.push( [] );
|
||||
cpu_data[cpu_nr].push( [index, $(this).attr("load")] );
|
||||
if(index>MAX_POINTS)
|
||||
cpu_data[cpu_nr].shift();
|
||||
});
|
||||
});
|
||||
|
||||
var datasets = [];
|
||||
for(i=0; i<cpu_data.length ;i++){
|
||||
datasets[i] = {
|
||||
label: "Cpu"+i,
|
||||
data: cpu_data[i],
|
||||
lines: { show: true },
|
||||
points: { show: true }
|
||||
};
|
||||
}
|
||||
var options = {
|
||||
legend: { position: "ne" },
|
||||
xaxis: { ticks: [] },
|
||||
yaxis: { ticks: [0,20,40,60,80,100] }
|
||||
};
|
||||
$.plot($("#cpu_chart"), datasets, options);
|
||||
}
|
||||
</script>
|
||||
10
src/wa/server/plugin/hwstatus/plugin.json
Normal file
10
src/wa/server/plugin/hwstatus/plugin.json
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"version": "1.0",
|
||||
"name": "HW Status",
|
||||
"interfaces": [
|
||||
{"wa.server.plugin.WAStatus": "wa.server.plugin.hwstatus.CpuStatus"},
|
||||
{"wa.server.plugin.WAStatus": "wa.server.plugin.hwstatus.MemStatus"},
|
||||
{"wa.server.plugin.WAStatus": "wa.server.plugin.hwstatus.HDDStatus"},
|
||||
{"wa.server.plugin.WAStatus": "wa.server.plugin.hwstatus.NetStatus"}
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue