Add software and hardware statistics api

This commit is contained in:
2023-12-06 18:30:56 +08:00
parent d64fdcd5ca
commit c0e9380082
8 changed files with 125 additions and 12 deletions

View File

@@ -0,0 +1,10 @@
package top.fatweb.api.service.system
import top.fatweb.api.vo.system.HardwareInfoVo
import top.fatweb.api.vo.system.SoftwareInfoVo
interface IStatisticsService {
fun software(): SoftwareInfoVo
fun hardware(): HardwareInfoVo
}

View File

@@ -0,0 +1,44 @@
package top.fatweb.api.service.system.impl
import org.springframework.stereotype.Service
import oshi.SystemInfo
import top.fatweb.api.properties.ServerProperties
import top.fatweb.api.service.system.IStatisticsService
import top.fatweb.api.vo.system.HardwareInfoVo
import top.fatweb.api.vo.system.SoftwareInfoVo
import java.time.LocalDateTime
import java.time.ZoneOffset
import java.util.Properties
@Service
class StatisticsServiceImpl : IStatisticsService {
private val systemProperties: Properties = System.getProperties()
private val systemInfo: SystemInfo = SystemInfo()
override fun software(): SoftwareInfoVo = SoftwareInfoVo(
os = systemInfo.operatingSystem.toString(),
bitness = systemInfo.operatingSystem.bitness,
javaVersion = systemProperties.getProperty("java.version"),
javaVersionDate = systemProperties.getProperty("java.version.date"),
javaVendor = systemProperties.getProperty("java.vendor"),
javaRuntime = systemProperties.getProperty("java.runtime.name"),
javaRuntimeVersion = systemProperties.getProperty("java.runtime.version"),
jvm = systemProperties.getProperty("java.vm.name"),
jvmVersion = systemProperties.getProperty("java.vm.version"),
jvmInfo = systemProperties.getProperty("java.vm.info"),
jvmVendor = systemProperties.getProperty("java.vm.vendor"),
javaClassVersion = systemProperties.getProperty("java.class.version"),
osBootTime = LocalDateTime.ofEpochSecond(systemInfo.operatingSystem.systemBootTime, 0, ZoneOffset.UTC),
serverStartupTime = ServerProperties.startupTime
)
override fun hardware(): HardwareInfoVo = HardwareInfoVo(
cpu = systemInfo.hardware.processor.processorIdentifier.name,
arch = systemProperties.getProperty("os.arch"),
is64Bit = systemInfo.hardware.processor.processorIdentifier.isCpu64bit,
cpuPhysicalPackageCount = systemInfo.hardware.processor.physicalPackageCount,
cpuPhysicalProcessorCount = systemInfo.hardware.processor.physicalProcessorCount,
cpuLogicalProcessorCount = systemInfo.hardware.processor.logicalProcessorCount,
microarchitecture = systemInfo.hardware.processor.processorIdentifier.microarchitecture
)
}