From f0b5cc1b72304fd4f1d48751ada2b389726ec847 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Sun, 19 Apr 2015 19:26:06 +0000 Subject: [PATCH] Wolring hddstatus --- src/wa/server/plugin/hwstatus/HDDStatus.java | 95 ++++++++++++++++++++ src/wa/server/plugin/hwstatus/HDDStatus.tmpl | 85 ++++++++++++++++++ src/wa/server/plugin/hwstatus/HwStatus.tmpl | 14 ++- 3 files changed, 191 insertions(+), 3 deletions(-) create mode 100644 src/wa/server/plugin/hwstatus/HDDStatus.java create mode 100644 src/wa/server/plugin/hwstatus/HDDStatus.tmpl diff --git a/src/wa/server/plugin/hwstatus/HDDStatus.java b/src/wa/server/plugin/hwstatus/HDDStatus.java new file mode 100644 index 0000000..2ce32f4 --- /dev/null +++ b/src/wa/server/plugin/hwstatus/HDDStatus.java @@ -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 idMap = new HashMap(); + + @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 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) {} + } +} diff --git a/src/wa/server/plugin/hwstatus/HDDStatus.tmpl b/src/wa/server/plugin/hwstatus/HDDStatus.tmpl new file mode 100644 index 0000000..7fbb864 --- /dev/null +++ b/src/wa/server/plugin/hwstatus/HDDStatus.tmpl @@ -0,0 +1,85 @@ + + +
+ + + + + + diff --git a/src/wa/server/plugin/hwstatus/HwStatus.tmpl b/src/wa/server/plugin/hwstatus/HwStatus.tmpl index d7c65ac..6199b5d 100644 --- a/src/wa/server/plugin/hwstatus/HwStatus.tmpl +++ b/src/wa/server/plugin/hwstatus/HwStatus.tmpl @@ -11,8 +11,10 @@
- - + + + +
UsedFree
Memory5555
Swap5555
Memory
Swap
@@ -56,7 +58,7 @@ function updateCpuChart(){ // Setup graph if(cpu_chart == null){ // Fill in cpus - for(i=0; i