Initial commit

This commit is contained in:
Ziver Koc 2015-04-09 21:22:47 +00:00
commit aa4e110832
69 changed files with 17898 additions and 0 deletions

View 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);
}
}

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

View 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"}
]
}