feat[monitor]: performance of disk io monitoring

This commit is contained in:
sun committed 2023-02-21 20:17:19 +08:00
1 parent a26bb90438
commit 1b1844950c
13 files changed
+277 -228

No files matched your search

+8
View File
@@ -95,3 +95,11 @@ SignalAttachment的signalId就是用于RPC的同步和异步的信号,通过
- zfoo的orm接近0封装,简单的封装可以极大提高上层的自由度
---
#### logback为什么在main和test都有一份日志配置,为什么弄了两份日志配置
- 隔离生产环境配置和测试环境的日志配置
- test的配置会覆盖main中的配置
- main中没有控制台日志,test中只有控制台日志,控制台日志会加锁在生产环境会导致性能问题
---
+9 -2
View File
@@ -194,11 +194,18 @@ replace,设置为alt+f
### 4.2 服务器插件安装
- translate插件
```
快捷键设置
Show Translation Dialog,设置为ctrl + shift + x
Translate,设置为ctrl + x
```
- Cyan Light Theme主题插件,个人习惯
- zoolytic,zookeeper客户端管理插件,推荐下载
- vue.js,vue语法识别,推荐下载
- jclasslib,字节码查看工具,推荐下载
- Maven Helper,maven依赖查看工具,推荐下载
- jclasslib,字节码查看工具,推荐下载
- vue,vue语法识别,推荐下载
- Alibaba Java Coding Guidelines
- Alibaba Cloud tool
@@ -22,7 +22,7 @@ import com.zfoo.scheduler.util.TimeUtils;
* @author godotg
* @version 3.0
*/
public class DiskFileSystemVO implements Comparable<DiskFileSystemVO> {
public class DiskFileSystem implements Comparable<DiskFileSystem> {
private String name;
@@ -32,49 +32,48 @@ public class DiskFileSystemVO implements Comparable<DiskFileSystemVO> {
private long timestamp;
public static DiskFileSystemVO valueOf(String name, long size, long available, long timestamp) {
var vo = new DiskFileSystemVO();
vo.name = name;
vo.size = size;
vo.available = available;
vo.timestamp = timestamp;
return vo;
public static DiskFileSystem valueOf(String name, long size, long available, long timestamp) {
var dfs = new DiskFileSystem();
dfs.name = name;
dfs.size = size;
dfs.available = available;
dfs.timestamp = timestamp;
return dfs;
}
public String pressure() {
var usage = 1D * (size - available) / size;
var usage = usage();
if (usage >= 0.8) {
var tempVO = this.toGB();
var temp = this.toGB();
return StringUtils.format("df - 磁盘[name:{}]空间过高[size:{}GB][available:{}GB][usage:{}][{}]"
, name, tempVO.getSize(), tempVO.getAvailable(), OSUtils.toPercent(usage), TimeUtils.timeToString(timestamp));
, name, temp.getSize(), temp.getAvailable(), OSUtils.toPercent(usage), TimeUtils.timeToString(timestamp));
}
return StringUtils.EMPTY;
}
public double usage() {
return ((double) (size - available)) / size;
}
@Override
public int compareTo(DiskFileSystemVO target) {
public int compareTo(DiskFileSystem target) {
if (target == null) {
return 1;
}
if (!this.name.equals(target.getName())) {
return 0;
}
var a = 1D * (this.size - this.available) / this.size;
var b = 1D * (target.getSize() - target.getAvailable()) / target.getSize();
return Double.compare(a, b);
return Double.compare(usage(), target.usage());
}
public DiskFileSystemVO toMB() {
public DiskFileSystem toMB() {
var size = this.size / IOUtils.BYTES_PER_MB;
var available = this.available / IOUtils.BYTES_PER_MB;
return DiskFileSystemVO.valueOf(this.name, size, available, timestamp);
return DiskFileSystem.valueOf(this.name, size, available, timestamp);
}
public DiskFileSystemVO toGB() {
var size = (long) Math.ceil(1D * this.size / IOUtils.BYTES_PER_GB);
var available = (long) Math.ceil(1D * this.available / IOUtils.BYTES_PER_GB);
return DiskFileSystemVO.valueOf(this.name, size, available, timestamp);
public DiskFileSystem toGB() {
var size = (long) Math.ceil(this.size / (double) IOUtils.BYTES_PER_GB);
var available = (long) Math.ceil(this.available / (double) IOUtils.BYTES_PER_GB);
return DiskFileSystem.valueOf(this.name, size, available, timestamp);
}
public String getName() {
@@ -0,0 +1,77 @@
/*
* Copyright (C) 2020 The zfoo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.monitor.model;
/**
* @author godotg
* @version 3.0
*/
public class DiskStorage implements Comparable<DiskStorage> {
private String device;
// 每秒实际读取需求的数量
private long rs;
// 每秒实际读取的大小,单位为KB
private long rKBs;
// 每秒实际写入需求的数量
private long ws;
// 每秒实际写入的大小,单位为KB
private long wKBs;
public static DiskStorage valueOf(String device, long rs, long rKBs, long ws, long wKBs)
{
DiskStorage ds = new DiskStorage();
ds.device = device;
ds.rs = rs;
ds.rKBs = rKBs;
ds.ws = ws;
ds.wKBs = wKBs;
return ds;
}
@Override
public int compareTo(DiskStorage target) {
if (target == null) {
return 1;
}
var a = this.rs + this.ws;
var b = target.getRs() + target.getWs();
return Double.compare(a, b);
}
public String getDevice() {
return device;
}
public long getRs() {
return rs;
}
public long getrKBs() {
return rKBs;
}
public long getWs() {
return ws;
}
public long getwKBs() {
return wKBs;
}
}
@@ -1,5 +1,7 @@
package com.zfoo.monitor.model;
import com.zfoo.protocol.util.IOUtils;
import java.lang.management.MemoryUsage;
/**
@@ -7,31 +9,18 @@ import java.lang.management.MemoryUsage;
* @date 2022/10/10 下午6:44
*/
public class JvmMemoryVo {
public class JvmMemory {
private String name;
private double total;
private double max;
private double used;
@Override
public String toString() {
return "JvmMemoryVo{" +
"name='" + name + '\'' +
", total=" + total +
", max=" + max +
", used=" + used +
'}';
}
public JvmMemory(String name, MemoryUsage usage) {
this.name = name;
this.total = usage.getCommitted() / (double) IOUtils.BYTES_PER_MB;
this.max = usage.getMax() / (double) IOUtils.BYTES_PER_MB;
this.used = usage.getUsed() / (double) IOUtils.BYTES_PER_MB;
public JvmMemoryVo(String name, MemoryUsage usage) {
this.name=name;
this.total=bitTomb(usage.getCommitted());
this.max=bitTomb(usage.getMax());
this.used=bitTomb(usage.getUsed());
}
private static double bitTomb(long val){
return (double) (val/1024/1024);
}
public String getName() {
@@ -65,4 +54,14 @@ public class JvmMemoryVo {
public void setUsed(double used) {
this.used = used;
}
@Override
public String toString() {
return "JvmMemory{" +
"name='" + name + '\'' +
", total=" + total +
", max=" + max +
", used=" + used +
'}';
}
}
@@ -22,7 +22,7 @@ import com.zfoo.scheduler.util.TimeUtils;
* @author godotg
* @version 3.0
*/
public class MemoryVO implements Comparable<MemoryVO> {
public class Memory implements Comparable<Memory> {
private long total;
@@ -30,45 +30,47 @@ public class MemoryVO implements Comparable<MemoryVO> {
private long timestamp;
public static MemoryVO valueOf(long total, long available, long timestamp) {
var vo = new MemoryVO();
vo.total = total;
vo.available = available;
vo.timestamp = timestamp;
return vo;
public static Memory valueOf(long total, long available, long timestamp) {
var memory = new Memory();
memory.total = total;
memory.available = available;
memory.timestamp = timestamp;
return memory;
}
public String pressure() {
var usage = 1D * (total - available) / total;
if (usage >= 0.8) {
var tempVO = this.toGB();
var temp = this.toGB();
return StringUtils.format("free - 内存占用过高[total:{}GB][available:{}GB][usage:{}][{}]"
, tempVO.getTotal(), tempVO.getAvailable(), OSUtils.toPercent(usage), TimeUtils.timeToString(timestamp));
, temp.getTotal(), temp.getAvailable(), OSUtils.toPercent(usage), TimeUtils.timeToString(timestamp));
}
return StringUtils.EMPTY;
}
public double usage() {
return ((double) (total - available)) / total;
}
@Override
public int compareTo(MemoryVO target) {
public int compareTo(Memory target) {
if (target == null) {
return 1;
}
var a = 1D * (this.total - this.available) / this.total;
var b = 1D * (target.getTotal() - target.getAvailable()) / target.getTotal();
return Double.compare(a, b);
return Double.compare(usage(), target.usage());
}
public MemoryVO toMB() {
public Memory toMB() {
var total = this.total / IOUtils.BYTES_PER_MB;
var available = this.available / IOUtils.BYTES_PER_MB;
return MemoryVO.valueOf(total, available, timestamp);
return Memory.valueOf(total, available, timestamp);
}
public MemoryVO toGB() {
var total = (long) Math.ceil(1D * this.total / IOUtils.BYTES_PER_GB);
var available = (long) Math.ceil(1D * this.available / IOUtils.BYTES_PER_GB);
return MemoryVO.valueOf(total, available, timestamp);
public Memory toGB() {
var total = (long) Math.ceil(this.total / (double) IOUtils.BYTES_PER_GB);
var available = (long) Math.ceil(this.available / (double) IOUtils.BYTES_PER_GB);
return Memory.valueOf(total, available, timestamp);
}
public long getTotal() {
@@ -27,26 +27,26 @@ import java.util.List;
* @author godotg
* @version 3.0
*/
public class MonitorVO {
public class Monitor {
private String uuid;
private UptimeVO uptime;
private Uptime uptime;
private List<DiskFileSystemVO> df;
private List<DiskFileSystem> df;
private MemoryVO free;
private Memory free;
private List<SarVO> sar;
private List<Sar> sar;
public static MonitorVO valueOf(String uuid, UptimeVO uptime, List<DiskFileSystemVO> df, MemoryVO free, List<SarVO> sar) {
var vo = new MonitorVO();
vo.uuid = uuid;
vo.uptime = uptime;
vo.df = df;
vo.free = free;
vo.sar = sar;
return vo;
public static Monitor valueOf(String uuid, Uptime uptime, List<DiskFileSystem> df, Memory free, List<Sar> sar) {
var monitor = new Monitor();
monitor.uuid = uuid;
monitor.uptime = uptime;
monitor.df = df;
monitor.free = free;
monitor.sar = sar;
return monitor;
}
public List<String> toPressures() {
@@ -145,39 +145,19 @@ public class MonitorVO {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public UptimeVO getUptime() {
public Uptime getUptime() {
return uptime;
}
public void setUptime(UptimeVO uptime) {
this.uptime = uptime;
}
public List<DiskFileSystemVO> getDf() {
public List<DiskFileSystem> getDf() {
return df;
}
public void setDf(List<DiskFileSystemVO> df) {
this.df = df;
}
public MemoryVO getFree() {
public Memory getFree() {
return free;
}
public void setFree(MemoryVO free) {
this.free = free;
}
public List<SarVO> getSar() {
public List<Sar> getSar() {
return sar;
}
public void setSar(List<SarVO> sar) {
this.sar = sar;
}
}
@@ -20,7 +20,7 @@ import com.zfoo.scheduler.util.TimeUtils;
* @author godotg
* @version 3.0
*/
public class SarVO implements Comparable<SarVO> {
public class Sar implements Comparable<Sar> {
private String name;
@@ -42,20 +42,20 @@ public class SarVO implements Comparable<SarVO> {
private long timestamp;
public static SarVO valueOf(String name, long rxpck, long txpck, long rxBytes, long txBytes
public static Sar valueOf(String name, long rxpck, long txpck, long rxBytes, long txBytes
, long inErrors, long outErrors, long inDrops, long collisions, long timestamp) {
var vo = new SarVO();
vo.name = name;
vo.rxpck = rxpck;
vo.txpck = txpck;
vo.rxBytes = rxBytes;
vo.txBytes = txBytes;
vo.inErrors = inErrors;
vo.outErrors = outErrors;
vo.inDrops = inDrops;
vo.collisions = collisions;
vo.timestamp = timestamp;
return vo;
var sar = new Sar();
sar.name = name;
sar.rxpck = rxpck;
sar.txpck = txpck;
sar.rxBytes = rxBytes;
sar.txBytes = txBytes;
sar.inErrors = inErrors;
sar.outErrors = outErrors;
sar.inDrops = inDrops;
sar.collisions = collisions;
sar.timestamp = timestamp;
return sar;
}
public String pressure() {
@@ -71,13 +71,10 @@ public class SarVO implements Comparable<SarVO> {
}
@Override
public int compareTo(SarVO target) {
public int compareTo(Sar target) {
if (target == null) {
return 1;
}
if (!this.name.equals(target.getName())) {
return 0;
}
var a = this.rxpck + this.txpck;
var b = target.getRxpck() + target.getTxpck();
@@ -102,71 +99,35 @@ public class SarVO implements Comparable<SarVO> {
return rxpck;
}
public void setRxpck(long rxpck) {
this.rxpck = rxpck;
}
public long getTxpck() {
return txpck;
}
public void setTxpck(long txpck) {
this.txpck = txpck;
}
public long getRxBytes() {
return rxBytes;
}
public void setRxBytes(long rxBytes) {
this.rxBytes = rxBytes;
}
public long getTxBytes() {
return txBytes;
}
public void setTxBytes(long txBytes) {
this.txBytes = txBytes;
}
public long getInErrors() {
return inErrors;
}
public void setInErrors(long inErrors) {
this.inErrors = inErrors;
}
public long getOutErrors() {
return outErrors;
}
public void setOutErrors(long outErrors) {
this.outErrors = outErrors;
}
public long getInDrops() {
return inDrops;
}
public void setInDrops(long inDrops) {
this.inDrops = inDrops;
}
public long getCollisions() {
return collisions;
}
public void setCollisions(long collisions) {
this.collisions = collisions;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
}
@@ -1,6 +1,6 @@
package com.zfoo.monitor.model;
public class SystemInfoVO {
public class SystemInfo {
/**
* host名称
@@ -27,14 +27,14 @@ public class SystemInfoVO {
*/
private String cpuName;
public static SystemInfoVO valueOf(String hostname, String version, String versionDetail, int cpuLogicCore, String cpuName) {
var vo = new SystemInfoVO();
vo.hostname = hostname;
vo.version = version;
vo.versionDetail = versionDetail;
vo.cpuLogicCore = cpuLogicCore;
vo.cpuName = cpuName;
return vo;
public static SystemInfo valueOf(String hostname, String version, String versionDetail, int cpuLogicCore, String cpuName) {
var systemInfo = new SystemInfo();
systemInfo.hostname = hostname;
systemInfo.version = version;
systemInfo.versionDetail = versionDetail;
systemInfo.cpuLogicCore = cpuLogicCore;
systemInfo.cpuName = cpuName;
return systemInfo;
}
public String getHostname() {
@@ -21,7 +21,7 @@ import com.zfoo.scheduler.util.TimeUtils;
* @author godotg
* @version 3.0
*/
public class UptimeVO implements Comparable<UptimeVO> {
public class Uptime implements Comparable<Uptime> {
private double oneMinute;
@@ -33,14 +33,14 @@ public class UptimeVO implements Comparable<UptimeVO> {
private long timestamp;
public static UptimeVO valueOf(double oneMinute, double fiveMinute, double fiftyMinute, double usage, long timestamp) {
var vo = new UptimeVO();
vo.oneMinute = oneMinute;
vo.fiveMinute = fiveMinute;
vo.fiftyMinute = fiftyMinute;
vo.usage = usage;
vo.timestamp = timestamp;
return vo;
public static Uptime valueOf(double oneMinute, double fiveMinute, double fiftyMinute, double usage, long timestamp) {
var uptime = new Uptime();
uptime.oneMinute = oneMinute;
uptime.fiveMinute = fiveMinute;
uptime.fiftyMinute = fiftyMinute;
uptime.usage = usage;
uptime.timestamp = timestamp;
return uptime;
}
public String pressure() {
@@ -74,7 +74,7 @@ public class UptimeVO implements Comparable<UptimeVO> {
}
@Override
public int compareTo(UptimeVO target) {
public int compareTo(Uptime target) {
if (target == null) {
return 1;
}
@@ -86,39 +86,19 @@ public class UptimeVO implements Comparable<UptimeVO> {
return oneMinute;
}
public void setOneMinute(double oneMinute) {
this.oneMinute = oneMinute;
}
public double getFiveMinute() {
return fiveMinute;
}
public void setFiveMinute(double fiveMinute) {
this.fiveMinute = fiveMinute;
}
public double getFiftyMinute() {
return fiftyMinute;
}
public void setFiftyMinute(double fiftyMinute) {
this.fiftyMinute = fiftyMinute;
}
public double getUsage() {
return usage;
}
public void setUsage(double usage) {
this.usage = usage;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
}
@@ -1,6 +1,6 @@
package com.zfoo.monitor.util;
import com.zfoo.monitor.model.JvmMemoryVo;
import com.zfoo.monitor.model.JvmMemory;
import java.lang.management.*;
import java.util.ArrayList;
@@ -13,21 +13,21 @@ import java.util.List;
public class JvmUtils {
public static List<JvmMemoryVo> getJvmInfo() {
List<JvmMemoryVo> list = new ArrayList<>();
public static List<JvmMemory> getJvmInfo() {
List<JvmMemory> list = new ArrayList<>();
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
//堆内存
MemoryUsage heapMemoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
list.add(new JvmMemoryVo("heap", heapMemoryUsage));
list.add(new JvmMemory("heap", heapMemoryUsage));
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean mxBean : memoryPoolMXBeans) {
//获取堆内存明细
if (MemoryType.HEAP.equals(mxBean.getType())) {
MemoryUsage usage = mxBean.getUsage();
list.add(new JvmMemoryVo(mxBean.getName(), usage));
list.add(new JvmMemory(mxBean.getName(), usage));
}
}
return list;
@@ -21,7 +21,7 @@ import com.zfoo.util.net.NetUtils;
import com.zfoo.util.security.IdUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import oshi.SystemInfo;
import oshi.hardware.HWDiskStore;
import oshi.hardware.HardwareAbstractionLayer;
import oshi.hardware.NetworkIF;
import oshi.software.os.OperatingSystem;
@@ -53,7 +53,7 @@ public abstract class OSUtils {
/**
* 系统信息
*/
private static final SystemInfo systemInfo = new SystemInfo();
private static final oshi.SystemInfo systemInfo = new oshi.SystemInfo();
/**
* 硬件信息
@@ -65,6 +65,11 @@ public abstract class OSUtils {
*/
private static final OperatingSystem os = systemInfo.getOperatingSystem();
/**
* 磁盘io
*/
private static final List<HWDiskStore> hwDiskStores = hardware.getDiskStores();
/**
* 网络信息
*/
@@ -90,11 +95,9 @@ public abstract class OSUtils {
// 最大小数位数
percentFormat.setMaximumFractionDigits(2);
// 最大整数位数
percentFormat.setMaximumIntegerDigits(2);
percentFormat.setMaximumIntegerDigits(3);
// 最小小数位数
percentFormat.setMinimumFractionDigits(2);
// 最小整数位数
percentFormat.setMinimumIntegerDigits(2);
// 自动转换成百分比显示
return percentFormat.format(num);
}
@@ -102,7 +105,7 @@ public abstract class OSUtils {
/**
* 对应于Linux中的uptime命令,windows中无法统计,所以在windows返回的结果默认是-1
*/
public static UptimeVO uptime() {
public static Uptime uptime() {
var processor = hardware.getProcessor();
var loads = processor.getSystemLoadAverage(3);
var oneMinute = loads[0];
@@ -113,25 +116,25 @@ public abstract class OSUtils {
var usage = processor.getSystemCpuLoadBetweenTicks(ticks);
ticks = cpuTicks;
return UptimeVO.valueOf(oneMinute, fiveMinute, fiftyMinute, usage, TimeUtils.now());
return Uptime.valueOf(oneMinute, fiveMinute, fiftyMinute, usage, TimeUtils.now());
}
/**
* 对应于Linux中的df -h命令,兼容windows
*/
public static List<DiskFileSystemVO> df() {
public static List<DiskFileSystem> df() {
var fileSystems = os.getFileSystem().getFileStores();
var nameDfMap = new HashMap<String, List<DiskFileSystemVO>>();
var nameDfMap = new HashMap<String, List<DiskFileSystem>>();
for (var fs : fileSystems) {
var name = fs.getName();
var size = fs.getTotalSpace();
var available = fs.getFreeSpace();
var list = nameDfMap.computeIfAbsent(name, (it) -> new ArrayList<>());
list.add(DiskFileSystemVO.valueOf(name, size, available, TimeUtils.now()));
list.add(DiskFileSystem.valueOf(name, size, available, TimeUtils.now()));
}
var dfs = new ArrayList<DiskFileSystemVO>();
var dfs = new ArrayList<DiskFileSystem>();
for (var dfList : nameDfMap.values()) {
if (dfList.size() == 1) {
dfs.add(dfList.get(0));
@@ -152,19 +155,49 @@ public abstract class OSUtils {
/**
* 对应于Linux中的free命令,兼容windows
*/
public static MemoryVO free() {
public static Memory free() {
var memory = hardware.getMemory();
var total = memory.getTotal();
var available = memory.getAvailable();
return MemoryVO.valueOf(total, available, TimeUtils.now());
return Memory.valueOf(total, available, TimeUtils.now());
}
public static List<DiskStorage> iostat() {
var diskStorages = new ArrayList<DiskStorage>();
for (var ds : hwDiskStores) {
var name = ds.getName();
var oldTimestamp = ds.getTimeStamp();
var oldReads = ds.getReads();
var oldReadBytes = ds.getReadBytes();
var oldWrites = ds.getWrites();
var oldWriteBytes = ds.getWriteBytes();
if (!ds.updateAttributes()) {
throw new RuntimeException(StringUtils.format("iostat update exception [ds:{}]", ds));
}
var timestamp = ds.getTimeStamp();
var timeInterval = (timestamp - oldTimestamp) / 1000D;
var reads = (long) Math.ceil(((ds.getReads() - oldReads) / timeInterval));
var readKBs = (long) Math.ceil(((ds.getReadBytes() - oldReadBytes) / timeInterval / IOUtils.BYTES_PER_KB));
var writes = (long) Math.ceil(((ds.getWrites() - oldWrites) / timeInterval));
var writeKBs = (long) Math.ceil(((ds.getWriteBytes() - oldWriteBytes) / timeInterval / IOUtils.BYTES_PER_KB));
var diskStorage = DiskStorage.valueOf(name, reads, readKBs, writes, writeKBs);
diskStorages.add(diskStorage);
}
return diskStorages;
}
/**
* 对应于Linux中的sar -n DEV 1命令,兼容windows
*/
public static List<SarVO> sar() {
var nameSarMap = new HashMap<String, List<SarVO>>();
public static List<Sar> sar() {
var nameSarMap = new HashMap<String, List<Sar>>();
for (var networkIF : networkIFs) {
var name = networkIF.getDisplayName() + StringUtils.SPACE + networkIF.getName();
var oldTimestamp = networkIF.getTimeStamp();
@@ -177,7 +210,10 @@ public abstract class OSUtils {
var oldInDrops = networkIF.getInDrops();
var oldCollisions = networkIF.getCollisions();
networkIF.updateAttributes();
if (!networkIF.updateAttributes()) {
throw new RuntimeException(StringUtils.format("sar update exception [networkIF:{}]", networkIF));
}
var timestamp = networkIF.getTimeStamp();
var timeInterval = (timestamp - oldTimestamp) / 1000D;
var rxpck = (long) Math.ceil(((networkIF.getPacketsRecv() - oldPacketsRecv) / timeInterval));
@@ -190,10 +226,10 @@ public abstract class OSUtils {
var collisions = networkIF.getCollisions() - oldCollisions;
var list = nameSarMap.computeIfAbsent(name, (it) -> new ArrayList<>());
list.add(SarVO.valueOf(name, rxpck, txpck, rxBytes, txBytes, inErrors, outErrors, inDrops, collisions, timestamp));
list.add(Sar.valueOf(name, rxpck, txpck, rxBytes, txBytes, inErrors, outErrors, inDrops, collisions, timestamp));
}
var sars = new ArrayList<SarVO>();
var sars = new ArrayList<Sar>();
for (var sarList : nameSarMap.values()) {
if (sarList.size() == 1) {
sars.add(sarList.get(0));
@@ -211,10 +247,10 @@ public abstract class OSUtils {
return sars;
}
private static UptimeVO maxUptime;
private static Map<String, DiskFileSystemVO> maxDfMap;
private static MemoryVO maxFree;
private static Map<String, SarVO> maxSarMap;
private static Uptime maxUptime;
private static Map<String, DiskFileSystem> maxDfMap;
private static Memory maxFree;
private static Map<String, Sar> maxSarMap;
static {
initMonitor();
@@ -227,15 +263,15 @@ public abstract class OSUtils {
maxSarMap = new ConcurrentHashMap<>(sar().stream().collect(Collectors.toMap(key -> key.getName(), value -> value)));
}
public static MonitorVO maxMonitor() {
public static Monitor maxMonitor() {
var uuid = IdUtils.getUUID();
var monitor = MonitorVO.valueOf(uuid, maxUptime, new ArrayList<>(maxDfMap.values()), maxFree, new ArrayList<>(maxSarMap.values()));
var monitor = Monitor.valueOf(uuid, maxUptime, new ArrayList<>(maxDfMap.values()), maxFree, new ArrayList<>(maxSarMap.values()));
initMonitor();
return monitor;
}
public static MonitorVO monitor() {
public static Monitor monitor() {
var uuid = IdUtils.getUUID();
var uptime = uptime();
var df = df();
@@ -264,7 +300,7 @@ public abstract class OSUtils {
}
}
return MonitorVO.valueOf(uuid, uptime, df, free, sar);
return Monitor.valueOf(uuid, uptime, df, free, sar);
}
public static String execCommand(String command) {
@@ -303,10 +339,10 @@ public abstract class OSUtils {
return StringUtils.EMPTY;
}
public static SystemInfoVO os() {
public static SystemInfo os() {
var processor = hardware.getProcessor();
var cpuLogicCore = processor.getLogicalProcessorCount();
var cpuName = processor.getProcessorIdentifier().getName();
return SystemInfoVO.valueOf(NetUtils.getLocalhostStr(), os.toString(), os.toString(), cpuLogicCore, cpuName);
return SystemInfo.valueOf(NetUtils.getLocalhostStr(), os.toString(), os.toString(), cpuLogicCore, cpuName);
}
}
+1 -1
View File
@@ -13,7 +13,7 @@ English | [简体中文](./README_CN.md)
- There are already quite a few JetBrains plugins that can do it in the way to generate POJOs, and you can search for
Proto in the plugin of Idea
### Ⅱ. 快速使用
### Ⅱ. Quick use
- Environmental requirements **JDK 11+**