UNPKG

node-os-utils

Version:

Advanced cross-platform operating system monitoring utilities with TypeScript support

197 lines 5.33 kB
import { PlatformAdapter, CommandResult, SupportedFeatures } from '../types/platform'; import { ExecuteOptions } from '../types/config'; import { MonitorError } from '../types/errors'; /** * 平台适配器抽象基类 * * 为不同操作系统提供统一的接口,子类需要实现具体的平台相关逻辑 */ export declare abstract class BasePlatformAdapter implements PlatformAdapter { protected platformName: string; protected supportedFeatures: SupportedFeatures; constructor(platformName: string); /** * 获取平台名称 */ getPlatform(): string; /** * 检查是否支持特定功能 */ isSupported(feature: string): boolean; /** * 获取支持的功能列表 */ getSupportedFeatures(): SupportedFeatures; /** * 执行系统命令 */ abstract executeCommand(command: string, options?: ExecuteOptions): Promise<CommandResult>; /** * 读取文件内容 */ abstract readFile(path: string): Promise<string>; /** * 检查文件是否存在 */ abstract fileExists(path: string): Promise<boolean>; /** * 获取 CPU 信息 */ abstract getCPUInfo(): Promise<any>; /** * 获取 CPU 使用率 */ abstract getCPUUsage(): Promise<any>; /** * 获取 CPU 温度 */ abstract getCPUTemperature(): Promise<any>; /** * 获取内存信息 */ abstract getMemoryInfo(): Promise<any>; /** * 获取内存使用情况 */ abstract getMemoryUsage(): Promise<any>; /** * 获取磁盘信息 */ abstract getDiskInfo(): Promise<any>; /** * 获取磁盘 I/O 统计 */ abstract getDiskIO(): Promise<any>; /** * 获取网络接口列表 */ abstract getNetworkInterfaces(): Promise<any>; /** * 获取网络统计信息 */ abstract getNetworkStats(): Promise<any>; /** * 获取进程列表 */ abstract getProcesses(): Promise<any>; /** * 获取特定进程信息 */ abstract getProcessInfo(pid: number): Promise<any>; /** * 获取系统信息 */ abstract getSystemInfo(): Promise<any>; /** * 获取系统负载 */ abstract getSystemLoad(): Promise<any>; /** * 获取磁盘使用情况 */ abstract getDiskUsage(): Promise<any>; /** * 获取磁盘统计 */ abstract getDiskStats(): Promise<any>; /** * 获取挂载点 */ abstract getMounts(): Promise<any>; /** * 获取文件系统 */ abstract getFileSystems(): Promise<any>; /** * 获取网络连接 */ abstract getNetworkConnections(): Promise<any>; /** * 获取默认网关 */ abstract getDefaultGateway(): Promise<any>; /** * 获取进程列表 */ abstract getProcessList(): Promise<any>; /** * 杀死进程 */ abstract killProcess(pid: number, signal?: string): Promise<boolean>; /** * 获取进程打开文件 */ abstract getProcessOpenFiles(pid: number): Promise<string[]>; /** * 获取进程环境变量 */ abstract getProcessEnvironment(pid: number): Promise<Record<string, string>>; /** * 获取系统运行时间 */ abstract getSystemUptime(): Promise<any>; /** * 获取系统用户 */ abstract getSystemUsers(): Promise<any>; /** * 获取系统服务 */ abstract getSystemServices(): Promise<any>; /** * 安全执行命令 */ protected safeExecute(command: string, options?: ExecuteOptions): Promise<CommandResult>; /** * 创建不支持功能的错误 */ protected createUnsupportedError(feature: string): MonitorError; /** * 创建命令执行失败错误 */ protected createCommandError(command: string, details?: any): MonitorError; /** * 创建解析错误 */ protected createParseError(data: string, reason?: string): MonitorError; /** * 验证命令执行结果 */ protected validateCommandResult(result: CommandResult, command: string): void; /** * 安全解析 JSON */ protected safeParseJSON(data: string, fallback?: any): any; /** * 安全解析数字 */ protected safeParseNumber(value: string | number, fallback?: number): number; /** * 安全解析整数 */ protected safeParseInt(value: string | number, fallback?: number, radix?: number): number; /** * 解析键值对格式的输出 */ protected parseKeyValueOutput(output: string, separator?: string): Record<string, string>; /** * 解析表格格式的输出 */ protected parseTableOutput(output: string, hasHeader?: boolean): Record<string, string>[]; /** * 分割表格行 */ protected splitTableRow(row: string): string[]; /** * 字节单位转换 */ /** * 将带单位的容量统一换算为字节,支持 SI 与二进制后缀 */ protected convertToBytes(value: string | number, unit?: string): number; /** * 初始化支持的功能 - 子类可以重写 */ protected abstract initializeSupportedFeatures(): SupportedFeatures; } //# sourceMappingURL=platform-adapter.d.ts.map