feat(监控): 新增监控模块API接口层

- 新增服务器监控API接口和类型定义
- 新增Redis监控API接口和类型定义
- 新增缓存管理API接口和类型定义
- 新增在线用户监控API接口和类型定义
- 新增定时任务监控API接口和类型定义
- 统一API响应格式和错误处理机制
This commit is contained in:
Leo 2025-09-28 00:07:19 +08:00
parent e5ad68f1ff
commit a6ce521255
6 changed files with 266 additions and 0 deletions

55
src/service/api/monitor/cache/index.ts vendored Normal file
View File

@ -0,0 +1,55 @@
import { request } from '@/service/http'
import type { DeleteCacheKeyBo, GetCacheValueBo, SysCacheVo } from './types'
/**
* Redis缓存所有Key
*/
export function getRedisCache() {
return request.Get<Service.ResponseResult<SysCacheVo[]>>('/coder/monitor/cache/getRedisCache')
}
/**
* Redis缓存键名列表
*/
export function getCacheKeys(cacheName: string) {
// 对缓存名称进行URL编码处理冒号等特殊字符
const encodedCacheName = encodeURIComponent(cacheName)
return request.Get<Service.ResponseResult<string[]>>(`/coder/monitor/cache/getCacheKeys/${encodedCacheName}`)
}
/**
* Redis缓存内容
*/
export function getCacheValue(data: GetCacheValueBo) {
return request.Post<Service.ResponseResult<SysCacheVo>>('/coder/monitor/cache/getValue', data)
}
/**
* Redis指定名称缓存
*/
export function deleteCacheName(cacheName: string) {
// 对缓存名称进行URL编码处理冒号等特殊字符
const encodedCacheName = encodeURIComponent(cacheName)
return request.Post<Service.ResponseResult<void>>(`/coder/monitor/cache/deleteCacheName/${encodedCacheName}`)
}
/**
* Redis指定键名缓存
*/
export function deleteCacheKey(data: DeleteCacheKeyBo) {
return request.Post<Service.ResponseResult<void>>('/coder/monitor/cache/deleteCacheKey', data)
}
/**
* Redis所有信息
*/
export function deleteCacheAll() {
return request.Post<Service.ResponseResult<void>>('/coder/monitor/cache/deleteCacheAll')
}
// 重新导出类型供外部使用
export type {
DeleteCacheKeyBo,
GetCacheValueBo,
SysCacheVo,
} from './types'

33
src/service/api/monitor/cache/types.ts vendored Normal file
View File

@ -0,0 +1,33 @@
/**
*
*/
// 缓存信息
export interface SysCacheVo {
/** 缓存名称 */
cacheName: string
/** 缓存键名 */
cacheKey?: string
/** 缓存内容 */
cacheValue?: string
/** 缓存过期时间 */
expireTime?: string
/** 备注信息 */
remark?: string
}
// 获取缓存内容请求参数
export interface GetCacheValueBo {
/** 缓存名称 */
cacheName: string
/** 缓存键名 */
cacheKey: string
}
// 删除缓存键请求参数
export interface DeleteCacheKeyBo {
/** 缓存名称 */
cacheName?: string
/** 缓存键名 */
cacheKey: string
}

View File

@ -0,0 +1,15 @@
import { request } from '@/service/http'
import type { RedisInfoVo } from './types'
/**
* Redis监控信息
*/
export function getRedisInformation() {
return request.Get<Service.ResponseResult<RedisInfoVo>>('/coder/monitor/redis/getRedisInformation')
}
// 重新导出类型供外部使用
export type {
RedisCommandStatVo,
RedisInfoVo,
} from './types'

View File

@ -0,0 +1,21 @@
/**
* Redis监控相关类型定义
*/
// Redis命令统计项
export interface RedisCommandStatVo {
/** 命令名称 */
name: string
/** 调用次数 */
value: string
}
// Redis监控信息
export interface RedisInfoVo {
/** Redis基本信息 */
info: Record<string, any>
/** 数据库大小 */
dbSize: number
/** 命令统计 */
commandStats: RedisCommandStatVo[]
}

View File

@ -0,0 +1,19 @@
import { request } from '@/service/http'
import type { ServerVo } from './types'
/**
*
*/
export function getServerInformation() {
return request.Get<Service.ResponseResult<ServerVo>>('/coder/monitor/server/getServerInformation')
}
// 重新导出类型供外部使用
export type {
CpuVo,
JvmVo,
MemVo,
ServerVo,
SysFileVo,
SysVo,
} from './types'

View File

@ -0,0 +1,123 @@
/**
*
*/
// CPU信息
export interface CpuVo {
/** 核心数 */
cpuNum: number
/** CPU总的使用率 */
total: number
/** CPU系统使用率 */
sys: number
/** CPU用户使用率 */
used: number
/** CPU当前等待率 */
wait: number
/** CPU当前空闲率 */
free: number
/** CPU使用率百分比 */
cpuUsage: number
/** CPU系统使用率百分比 */
sysUsage: number
/** CPU用户使用率百分比 */
userUsage: number
/** CPU等待率百分比 */
waitUsage: number
/** CPU空闲率百分比 */
freeUsage: number
}
// 内存信息
export interface MemVo {
/** 内存总量 */
total: number
/** 已用内存 */
used: number
/** 剩余内存 */
free: number
/** 内存使用率 */
usage: number
/** 总内存(格式化) */
totalStr: string
/** 已用内存(格式化) */
usedStr: string
/** 剩余内存(格式化) */
freeStr: string
}
// JVM信息
export interface JvmVo {
/** 当前JVM占用的内存总数(M) */
total: number
/** JVM最大可用内存总数(M) */
max: number
/** JVM空闲内存(M) */
free: number
/** JDK版本 */
version: string
/** JDK路径 */
home: string
/** JVM已用内存 */
used: number
/** JVM内存使用率 */
usage: number
/** 总内存(格式化) */
totalStr: string
/** 已用内存(格式化) */
usedStr: string
/** 剩余内存(格式化) */
freeStr: string
/** 最大内存(格式化) */
maxStr: string
/** JVM启动时间 */
startTime: string
/** JVM运行时间 */
runTime: string
}
// 系统信息
export interface SysVo {
/** 服务器名称 */
computerName: string
/** 服务器IP */
computerIp: string
/** 项目路径 */
userDir: string
/** 操作系统 */
osName: string
/** 系统架构 */
osArch: string
}
// 磁盘文件信息
export interface SysFileVo {
/** 盘符路径 */
dirName: string
/** 盘符类型 */
sysTypeName: string
/** 文件类型 */
typeName: string
/** 总大小 */
total: string
/** 剩余大小 */
free: string
/** 已经使用量 */
used: string
/** 资源的使用率 */
usage: number
}
// 服务器信息
export interface ServerVo {
/** CPU相关信息 */
cpu: CpuVo
/** 内存相关信息 */
mem: MemVo
/** JVM相关信息 */
jvm: JvmVo
/** 服务器相关信息 */
sys: SysVo
/** 磁盘相关信息 */
sysFiles: SysFileVo[]
}