Skip to content

Commit 7916d65

Browse files
committed
Format SFP health check values for readability (#579)
- Link speed: 2500Mb/s → 2.5 Gbps, 1000Mb/s → 1 Gbps - SerDes register: 0x00000050 → 0x50 - Clock rate parenthetical: (2.5 G) → (2.5 Gbps)
1 parent 640becc commit 7916d65

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

src/NetworkOptimizer.Web/Services/PerfTweaksDeploymentService.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,24 +259,25 @@ public async Task<PerfTweaksStatus> CheckAllStatusAsync()
259259

260260
if (clockRate != "N/A")
261261
{
262-
var clockLabel = clockRate == "312500000" ? "312.5 MHz (2.5 G)" : clockRate == "125000000" ? "125 MHz (1 G)" : $"{clockRate} Hz";
262+
var clockLabel = clockRate == "312500000" ? "312.5 MHz (2.5 Gbps)" : clockRate == "125000000" ? "125 MHz (1 Gbps)" : $"{clockRate} Hz";
263263
sfpStatus.HealthChecks.Add(new("Clock Rate", clockLabel, clockRate == "312500000" ? HealthCheckStatus.Ok : HealthCheckStatus.Error));
264264
}
265265

266266
if (serdesReg != "n/a")
267267
{
268-
var regLabel = isSgmiiPlus ? $"{serdesReg} (SGMII+)" : isSgmii ? $"{serdesReg} (SGMII)" : serdesReg;
268+
var regDisplay = FormatHexRegister(serdesReg);
269+
var regLabel = isSgmiiPlus ? $"{regDisplay} (SGMII+)" : isSgmii ? $"{regDisplay} (SGMII)" : regDisplay;
269270
sfpStatus.HealthChecks.Add(new("SerDes Register", regLabel, isSgmiiPlus ? HealthCheckStatus.Ok : HealthCheckStatus.Error));
270271
}
271272

272273
if (ethSpeed != "N/A" && ethSpeed != "Unknown!")
273-
sfpStatus.HealthChecks.Add(new("eth6 Speed", ethSpeed, ethSpeed.Contains("2500") ? HealthCheckStatus.Ok : HealthCheckStatus.Warning));
274+
sfpStatus.HealthChecks.Add(new("eth6 Speed", FormatLinkSpeed(ethSpeed), ethSpeed.Contains("2500") ? HealthCheckStatus.Ok : HealthCheckStatus.Warning));
274275
else if (ethSpeed == "Unknown!")
275276
sfpStatus.HealthChecks.Add(new("eth6 Speed", "No link", HealthCheckStatus.Ok));
276277

277278
if (sfpModuleLoaded && !is25g && clockRate != "N/A")
278279
{
279-
sfpStatus.IssueDescription = "Module loaded but clock/register mismatch - link may not be running at 2.5 G.";
280+
sfpStatus.IssueDescription = "Module loaded but clock/register mismatch - link may not be running at 2.5 Gbps.";
280281
}
281282
}
282283
status.Tweaks["sfp-sgmiiplus"] = sfpStatus;
@@ -486,7 +487,7 @@ public async Task<PerfTweaksStatus> CheckAllStatusAsync()
486487
var clkOk = GetSection(verifySections, "CLK").Trim() == "312500000";
487488

488489
if (modLoaded && clkOk)
489-
Report("Verified: Module loaded, uniphy1 at 312.5 MHz (2.5 G).");
490+
Report("Verified: Module loaded, uniphy1 at 312.5 MHz (2.5 Gbps).");
490491
else if (modLoaded)
491492
Report("Module loaded but clock rate not at expected value. Check logs.");
492493
else
@@ -725,6 +726,27 @@ private static Dictionary<string, string> ParseDelimitedOutput(string output)
725726

726727
private static string GetSection(Dictionary<string, string> sections, string key)
727728
=> sections.TryGetValue(key, out var value) ? value : "";
729+
730+
private static string FormatHexRegister(string raw)
731+
{
732+
if (string.IsNullOrEmpty(raw) || !raw.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
733+
return raw;
734+
var hex = raw[2..].TrimStart('0');
735+
if (hex.Length == 0) hex = "0";
736+
return "0x" + hex;
737+
}
738+
739+
private static string FormatLinkSpeed(string ethtoolSpeed)
740+
{
741+
var numeric = ethtoolSpeed.Replace("Mb/s", "").Trim();
742+
if (int.TryParse(numeric, out var mbps))
743+
{
744+
return mbps % 1000 == 0
745+
? $"{mbps / 1000} Gbps"
746+
: $"{mbps / 1000.0:0.#} Gbps";
747+
}
748+
return ethtoolSpeed;
749+
}
728750
}
729751

730752
public class PerfTweaksStatus

0 commit comments

Comments
 (0)