Repair live server operations console
This commit is contained in:
@@ -1805,7 +1805,7 @@ func (svc *CoreService) ListServerMetricsForSession(sessionID string) ([]domain.
|
||||
}
|
||||
items := make([]domain.ServerMetrics, 0, len(instances))
|
||||
for _, instance := range instances {
|
||||
items = append(items, svc.metricsForServer(instance))
|
||||
items = append(items, svc.latestMetricsForServer(instance))
|
||||
}
|
||||
if err := validator.ValidateServerMetricsList(items); err != nil {
|
||||
return nil, err
|
||||
@@ -2026,32 +2026,43 @@ func (svc *CoreService) runtimeProfileScope(serverInstanceID string) string {
|
||||
return binding.ProfileKey
|
||||
}
|
||||
|
||||
func (svc *CoreService) metricsForServer(instance domain.ServerInstance) domain.ServerMetrics {
|
||||
metrics := domain.ServerMetrics{
|
||||
func (svc *CoreService) latestMetricsForServer(instance domain.ServerInstance) domain.ServerMetrics {
|
||||
samples, err := svc.store.MetricSamples().List(domain.MetricSampleFilter{ServerInstanceID: instance.ID})
|
||||
if err == nil {
|
||||
var latest domain.MetricSample
|
||||
found := false
|
||||
for i := range samples {
|
||||
sample := samples[i]
|
||||
if sample.RunEndpointID != "" && sample.RunEndpointID != instance.RunEndpointID {
|
||||
continue
|
||||
}
|
||||
if !found || sample.CollectedAt.After(latest.CollectedAt) {
|
||||
latest = sample
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if found {
|
||||
return domain.ServerMetrics{
|
||||
ServerInstanceID: latest.ServerInstanceID,
|
||||
Online: latest.Online,
|
||||
PlayerCount: latest.PlayerCount,
|
||||
MaxPlayers: latest.MaxPlayers,
|
||||
TPS: latest.TPS,
|
||||
LatencyMS: latest.LatencyMS,
|
||||
CPUPercent: latest.CPUPercent,
|
||||
MemoryPercent: latest.MemoryPercent,
|
||||
DiskPercent: latest.DiskPercent,
|
||||
Source: latest.Source,
|
||||
CollectedAt: latest.CollectedAt,
|
||||
}
|
||||
}
|
||||
}
|
||||
return domain.ServerMetrics{
|
||||
ServerInstanceID: instance.ID,
|
||||
Online: instance.State == domain.ServerInstanceStateRunning,
|
||||
Source: "platform-derived",
|
||||
Source: "run-metrics-pending",
|
||||
CollectedAt: svc.now(),
|
||||
}
|
||||
if !metrics.Online {
|
||||
return metrics
|
||||
}
|
||||
seed := len(instance.ID) + len(instance.Name) + instance.ConfigVersion
|
||||
playerCount := seed % 20
|
||||
maxPlayers := 20
|
||||
tps := 18.5 + float64(seed%15)/10
|
||||
latency := 35.0 + float64(seed%40)
|
||||
cpu := clampPercent(25 + float64(seed%45))
|
||||
memory := clampPercent(30 + float64(seed%50))
|
||||
disk := clampPercent(20 + float64(seed%60))
|
||||
metrics.PlayerCount = &playerCount
|
||||
metrics.MaxPlayers = &maxPlayers
|
||||
metrics.TPS = &tps
|
||||
metrics.LatencyMS = &latency
|
||||
metrics.CPUPercent = &cpu
|
||||
metrics.MemoryPercent = &memory
|
||||
metrics.DiskPercent = &disk
|
||||
return metrics
|
||||
}
|
||||
|
||||
func buildLogicalServerConfig(instance domain.ServerInstance) string {
|
||||
|
||||
Reference in New Issue
Block a user