From dafc0ac6710dbeca13c81c99eb987d6aeb11b3f4 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sun, 10 Dec 2023 12:42:28 +0800 Subject: [PATCH] Finish storage information api --- .../controller/system/StatisticsController.kt | 6 ++--- .../api/service/system/IStatisticsService.kt | 2 +- .../system/impl/StatisticsServiceImpl.kt | 24 ++++++++++++------- .../fatweb/api/vo/system/FileStoreInfoVo.kt | 7 ++++++ .../top/fatweb/api/vo/system/MemoryInfoVo.kt | 12 ---------- .../top/fatweb/api/vo/system/StorageInfoVo.kt | 13 ++++++++++ 6 files changed, 40 insertions(+), 24 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/api/vo/system/FileStoreInfoVo.kt delete mode 100644 src/main/kotlin/top/fatweb/api/vo/system/MemoryInfoVo.kt create mode 100644 src/main/kotlin/top/fatweb/api/vo/system/StorageInfoVo.kt diff --git a/src/main/kotlin/top/fatweb/api/controller/system/StatisticsController.kt b/src/main/kotlin/top/fatweb/api/controller/system/StatisticsController.kt index 7ad3ccf..b574272 100644 --- a/src/main/kotlin/top/fatweb/api/controller/system/StatisticsController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/system/StatisticsController.kt @@ -27,7 +27,7 @@ class StatisticsController( @GetMapping("/cpu") fun cpu(): ResponseResult = ResponseResult.success(data = statisticsService.cpu()) - @Operation(summary = "获取内存信息") - @GetMapping("/memory") - fun memory(): ResponseResult = ResponseResult.success(data = statisticsService.memory()) + @Operation(summary = "获取存储信息") + @GetMapping("/storage") + fun storage(): ResponseResult = ResponseResult.success(data = statisticsService.storage()) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/system/IStatisticsService.kt b/src/main/kotlin/top/fatweb/api/service/system/IStatisticsService.kt index 1307c9a..eb18a9e 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/IStatisticsService.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/IStatisticsService.kt @@ -9,5 +9,5 @@ interface IStatisticsService { fun cpu(): CpuInfoVo - fun memory(): MemoryInfoVo + fun storage(): StorageInfoVo } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsServiceImpl.kt index 8f1e601..3420d7b 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsServiceImpl.kt @@ -9,7 +9,7 @@ import top.fatweb.api.util.ByteUtil import top.fatweb.api.vo.system.* import java.time.LocalDateTime import java.time.ZoneOffset -import java.util.Properties +import java.util.* import java.util.concurrent.TimeUnit @Service @@ -93,7 +93,8 @@ class StatisticsServiceImpl : IStatisticsService { processorTicks[CentralProcessor.TickType.SOFTIRQ.index] - processorPrevTicks[CentralProcessor.TickType.SOFTIRQ.index] val processorSteal = processorTicks[CentralProcessor.TickType.STEAL.index] - processorPrevTicks[CentralProcessor.TickType.STEAL.index] - val processorTotal = processorUser + processorNice + processorSystem + processorIdle + processorIowait + processorIrq + processorSoftirq + processorSteal + val processorTotal = + processorUser + processorNice + processorSystem + processorIdle + processorIowait + processorIrq + processorSoftirq + processorSteal processors?.add( CpuInfoVo( processorUser, @@ -112,14 +113,21 @@ class StatisticsServiceImpl : IStatisticsService { } } - override fun memory() = MemoryInfoVo( - total = systemInfo.hardware.memory.total, - free = systemInfo.hardware.memory.available, - virtualMax = systemInfo.hardware.memory.virtualMemory.virtualMax, - virtualInUse = systemInfo.hardware.memory.virtualMemory.virtualInUse, + override fun storage() = StorageInfoVo( + memoryTotal = systemInfo.hardware.memory.total, + memoryFree = systemInfo.hardware.memory.available, + virtualMemoryMax = systemInfo.hardware.memory.virtualMemory.virtualMax, + virtualMemoryInUse = systemInfo.hardware.memory.virtualMemory.virtualInUse, swapTotal = systemInfo.hardware.memory.virtualMemory.swapTotal, swapUsed = systemInfo.hardware.memory.virtualMemory.swapUsed, jvmTotal = runtime.totalMemory(), - jvmFree = runtime.freeMemory() + jvmFree = runtime.freeMemory(), + fileStores = systemInfo.operatingSystem.fileSystem.fileStores.map { + FileStoreInfoVo( + mount = it.mount, + total = it.totalSpace, + free = it.freeSpace + ) + } ) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/vo/system/FileStoreInfoVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/FileStoreInfoVo.kt new file mode 100644 index 0000000..1d98f86 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/vo/system/FileStoreInfoVo.kt @@ -0,0 +1,7 @@ +package top.fatweb.api.vo.system + +data class FileStoreInfoVo( + val mount: String, + val total: Long, + val free: Long +) diff --git a/src/main/kotlin/top/fatweb/api/vo/system/MemoryInfoVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/MemoryInfoVo.kt deleted file mode 100644 index 056cdc8..0000000 --- a/src/main/kotlin/top/fatweb/api/vo/system/MemoryInfoVo.kt +++ /dev/null @@ -1,12 +0,0 @@ -package top.fatweb.api.vo.system - -data class MemoryInfoVo( - val total: Long, - val free: Long, - val virtualMax: Long, - val virtualInUse: Long, - val swapTotal: Long, - val swapUsed: Long, - val jvmTotal: Long, - val jvmFree: Long, -) diff --git a/src/main/kotlin/top/fatweb/api/vo/system/StorageInfoVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/StorageInfoVo.kt new file mode 100644 index 0000000..1f52758 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/vo/system/StorageInfoVo.kt @@ -0,0 +1,13 @@ +package top.fatweb.api.vo.system + +data class StorageInfoVo( + val memoryTotal: Long, + val memoryFree: Long, + val virtualMemoryMax: Long, + val virtualMemoryInUse: Long, + val swapTotal: Long, + val swapUsed: Long, + val jvmTotal: Long, + val jvmFree: Long, + val fileStores: List +)