mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-11 22:39:40 +08:00
- 后端新增监控会话管理,支持启动、停止和历史查询 - JMX、Endpoint、Agent Provider 补齐监控快照采集能力 - JMX helper 增加内存、GC、线程、类加载采样并更新内嵌运行时 - 生成 Wails 监控接口绑定并补充后端回归测试
78 lines
2.5 KiB
Go
78 lines
2.5 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"GoNavi-Wails/internal/connection"
|
|
"GoNavi-Wails/internal/jvm"
|
|
)
|
|
|
|
type jvmMonitoringService interface {
|
|
Start(ctx context.Context, cfg connection.ConnectionConfig, requestedMode string) (jvm.MonitoringSessionSnapshot, error)
|
|
GetHistory(connectionID string, providerMode string) (jvm.MonitoringSessionSnapshot, error)
|
|
Stop(connectionID string, providerMode string) error
|
|
}
|
|
|
|
var currentJVMMonitoringManager jvmMonitoringService = jvm.NewMonitoringManager()
|
|
|
|
func (a *App) JVMStartMonitoring(cfg connection.ConnectionConfig) connection.QueryResult {
|
|
snapshot, err := currentJVMMonitoringManager.Start(a.ctx, cfg, "")
|
|
if err != nil {
|
|
return connection.QueryResult{Success: false, Message: err.Error()}
|
|
}
|
|
return connection.QueryResult{Success: true, Data: snapshot}
|
|
}
|
|
|
|
func (a *App) JVMGetMonitoringHistory(cfg connection.ConnectionConfig, providerMode string) connection.QueryResult {
|
|
connectionID, resolvedMode, err := resolveJVMMonitoringLookup(cfg, providerMode)
|
|
if err != nil {
|
|
return connection.QueryResult{Success: false, Message: err.Error()}
|
|
}
|
|
|
|
snapshot, err := currentJVMMonitoringManager.GetHistory(connectionID, resolvedMode)
|
|
if err != nil {
|
|
return connection.QueryResult{Success: false, Message: err.Error()}
|
|
}
|
|
return connection.QueryResult{Success: true, Data: snapshot}
|
|
}
|
|
|
|
func (a *App) JVMStopMonitoring(cfg connection.ConnectionConfig, providerMode string) connection.QueryResult {
|
|
connectionID, resolvedMode, err := resolveJVMMonitoringLookup(cfg, providerMode)
|
|
if err != nil {
|
|
return connection.QueryResult{Success: false, Message: err.Error()}
|
|
}
|
|
|
|
if err := currentJVMMonitoringManager.Stop(connectionID, resolvedMode); err != nil {
|
|
return connection.QueryResult{Success: false, Message: err.Error()}
|
|
}
|
|
return connection.QueryResult{Success: true, Data: map[string]any{
|
|
"connectionId": connectionID,
|
|
"providerMode": resolvedMode,
|
|
"status": "stopped",
|
|
}}
|
|
}
|
|
|
|
func resolveJVMMonitoringLookup(cfg connection.ConnectionConfig, requestedMode string) (string, string, error) {
|
|
normalized, resolvedMode, err := jvm.ResolveProviderMode(cfg, requestedMode)
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
return resolveJVMMonitoringConnectionID(normalized), resolvedMode, nil
|
|
}
|
|
|
|
func resolveJVMMonitoringConnectionID(cfg connection.ConnectionConfig) string {
|
|
if trimmed := strings.TrimSpace(cfg.ID); trimmed != "" {
|
|
return trimmed
|
|
}
|
|
host := strings.TrimSpace(cfg.Host)
|
|
if host == "" {
|
|
host = "unknown"
|
|
}
|
|
if cfg.Port > 0 {
|
|
return fmt.Sprintf("%s:%d", host, cfg.Port)
|
|
}
|
|
return host
|
|
}
|