Wolring hddstatus
This commit is contained in:
parent
3469940cd0
commit
f0b5cc1b72
3 changed files with 191 additions and 3 deletions
95
src/wa/server/plugin/hwstatus/HDDStatus.java
Normal file
95
src/wa/server/plugin/hwstatus/HDDStatus.java
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
* 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.FileSystem;
|
||||||
|
import org.hyperic.sigar.FileSystemUsage;
|
||||||
|
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 zutil.parser.Templator;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Ziver on 2015-04-17.
|
||||||
|
*/
|
||||||
|
public class HDDStatus implements WAStatus {
|
||||||
|
private int nextId;
|
||||||
|
private HashMap<String,Integer> idMap = new HashMap<String,Integer>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "HDD Status";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String html() {
|
||||||
|
try {
|
||||||
|
return FileUtil.getContent(FileUtil.findURL("wa/server/plugin/hwstatus/HddStatus.tmpl"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
return e.getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void jsonUpdate(Map<String, String> request, DataNode root) {
|
||||||
|
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());
|
||||||
|
|
||||||
|
if(idMap.containsKey(device))
|
||||||
|
node.set("id", idMap.get(device));
|
||||||
|
else{
|
||||||
|
idMap.put(device, nextId);
|
||||||
|
node.set("id", nextId);
|
||||||
|
++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);
|
||||||
|
}
|
||||||
|
}catch(SigarException e){} catch (UnsupportedEncodingException e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
85
src/wa/server/plugin/hwstatus/HDDStatus.tmpl
Normal file
85
src/wa/server/plugin/hwstatus/HDDStatus.tmpl
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
<!--<div class="col-md-12"><div class="panel panel-default">
|
||||||
|
<div class="panel-heading">HDD Summary</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div></div>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<div id="hdd-container"></div>
|
||||||
|
|
||||||
|
<div id="template" class="hidden">
|
||||||
|
<div id="" class="col-md-12"><div class="panel panel-default">
|
||||||
|
<div class="panel-heading hdd-title">HDD: {{.mount}} ({{.size_total}})</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="progress">
|
||||||
|
<div class="progress-bar hdd-used" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100">
|
||||||
|
5600 MB
|
||||||
|
</div>
|
||||||
|
<center class="hdd-free">{{.size_free}}</center>
|
||||||
|
</div>
|
||||||
|
<!--<div><canvas id="hdd-io" height="400"></canvas></div>-->
|
||||||
|
</div>
|
||||||
|
</div></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script language="javascript" type="text/javascript">
|
||||||
|
$(function() {
|
||||||
|
updateHdd();
|
||||||
|
});
|
||||||
|
|
||||||
|
var hdd_io_chart = {};
|
||||||
|
var hdd_io_data = {
|
||||||
|
labels : ["","","","","","","","","",""],
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
strokeColor: "rgba(151,0,0,1)",
|
||||||
|
fillColor: "rgba(151,0,0,0.2)",
|
||||||
|
data: [0,0,0,0,0,0,0,0,0,0,0]
|
||||||
|
},{
|
||||||
|
strokeColor: "rgba(0,187,0,1)",
|
||||||
|
fillColor: "rgba(0,187,0,0.2)",
|
||||||
|
data: [0,0,0,0,0,0,0,0,0,0,0]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
function updateHdd(){
|
||||||
|
$.getJSON("?i=0&json&hdd", function( data ) {
|
||||||
|
$.each(data['hdd'], function( index, hdd ){
|
||||||
|
var element = null;
|
||||||
|
var html_id = "hdd-id-" + hdd.id;
|
||||||
|
if($("#"+html_id).length)
|
||||||
|
element = $("#hdd-id-" + hdd.id);
|
||||||
|
else{ // Create new element
|
||||||
|
element = $("#template").children().clone();
|
||||||
|
$(element).attr("id", html_id);
|
||||||
|
$(element).appendTo("#hdd-container");
|
||||||
|
// Set static values
|
||||||
|
$(element).find(".hdd-title").html("HDD: "+hdd.device+" ("+byteToString(hdd.size_total)+")");
|
||||||
|
$(element).find(".progress-bar").attr("aria-valuemax", hdd.size_total);
|
||||||
|
}
|
||||||
|
|
||||||
|
$(element).find(".progress-bar").attr("aria-valuenow", hdd.size_used);
|
||||||
|
$(element).find(".progress-bar").css("width", (hdd.size_used/hdd.size_total)*100+"%");
|
||||||
|
$(element).find(".hdd-used").html(byteToString(hdd.size_used));
|
||||||
|
$(element).find(".hdd-free").html(byteToString(hdd.size_free));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
setTimeout(updateHdd, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
var sizes = ["YB", "ZB", "EB", "PB", "TB", "GB", "MB", "kB", "B"];
|
||||||
|
function byteToString(value){
|
||||||
|
var total = sizes.length-1;
|
||||||
|
|
||||||
|
for(; value > 1024 ;--total) {
|
||||||
|
value /= 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = Math.round(value*10)/10;
|
||||||
|
return value+" "+sizes[total];
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
@ -11,8 +11,10 @@
|
||||||
<br>
|
<br>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr><th></th><th>Used</th><th>Free</th></tr>
|
<tr><th></th><th>Used</th><th>Free</th></tr>
|
||||||
<tr><th><b>Memory</b></th><td>55</td><td>55</td></tr>
|
<tr><th><b>Memory</b></th>
|
||||||
<tr><th><b>Swap</b></th><td>55</td><td>55</td></tr>
|
<td id="mem-used"></td><td id="mem-free"></td></tr>
|
||||||
|
<tr><th><b>Swap</b></th>
|
||||||
|
<td id="swap-used"></td><td id="swap-free"></td></tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div></div>
|
</div></div>
|
||||||
|
|
@ -56,7 +58,7 @@ function updateCpuChart(){
|
||||||
// Setup graph
|
// Setup graph
|
||||||
if(cpu_chart == null){
|
if(cpu_chart == null){
|
||||||
// Fill in cpus
|
// Fill in cpus
|
||||||
for(i=0; i<data['cpu'].length; ++i)
|
for(i=0; i<data['cpu'].length; ++i){
|
||||||
cpu_data['datasets'].push({
|
cpu_data['datasets'].push({
|
||||||
strokeColor: "rgba(151,187,205,1)",
|
strokeColor: "rgba(151,187,205,1)",
|
||||||
fillColor: "rgba(151,187,205,0.2)",
|
fillColor: "rgba(151,187,205,0.2)",
|
||||||
|
|
@ -64,6 +66,7 @@ function updateCpuChart(){
|
||||||
0,0,0,0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,0,0,0,
|
||||||
0,0,0,0,0,0,0,0,0,0,0]
|
0,0,0,0,0,0,0,0,0,0,0]
|
||||||
});
|
});
|
||||||
|
}
|
||||||
// Graph
|
// Graph
|
||||||
var ctx = $("#cpu-chart").get(0).getContext("2d");
|
var ctx = $("#cpu-chart").get(0).getContext("2d");
|
||||||
cpu_chart = new Chart(ctx).Line(cpu_data, {
|
cpu_chart = new Chart(ctx).Line(cpu_data, {
|
||||||
|
|
@ -109,6 +112,11 @@ function updateMemChart(){
|
||||||
mem_chart.segments[0].value = data.memory.used;
|
mem_chart.segments[0].value = data.memory.used;
|
||||||
mem_chart.segments[1].value = data.memory.free;
|
mem_chart.segments[1].value = data.memory.free;
|
||||||
mem_chart.update();
|
mem_chart.update();
|
||||||
|
|
||||||
|
$("#mem-used").html(data.memory.used + " MB");
|
||||||
|
$("#mem-free").html(data.memory.free + " MB");
|
||||||
|
$("#swap-used").html(data.swap.used + " MB");
|
||||||
|
$("#swap-free").html(data.swap.free + " MB");
|
||||||
});
|
});
|
||||||
setTimeout(updateMemChart, 5000);
|
setTimeout(updateMemChart, 5000);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue