Skip to content

Commit 1667c61

Browse files
committed
update metrics publisher hostname when hostname is changed
1 parent af689b6 commit 1667c61

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

photon-core/src/main/java/org/photonvision/common/hardware/metrics/MetricsManager.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.photonvision.common.hardware.metrics;
1919

20-
import edu.wpi.first.cscore.CameraServerJNI;
2120
import edu.wpi.first.networktables.ProtobufPublisher;
2221
import java.io.PrintWriter;
2322
import java.io.StringWriter;
@@ -47,7 +46,9 @@ public class MetricsManager {
4746
NetworkTablesManager.getInstance()
4847
.kCoprocTable
4948
.getSubTable("/metrics")
50-
.getProtobufTopic(CameraServerJNI.getHostname(), DeviceMetrics.proto)
49+
.getProtobufTopic(
50+
ConfigManager.getInstance().getConfig().getNetworkConfig().hostname,
51+
DeviceMetrics.proto)
5152
.publish();
5253

5354
private final ShellExec runCommand = new ShellExec(true, true);
@@ -244,6 +245,24 @@ public double getUptime() {
244245

245246
public void publishMetrics() {
246247
logger.debug("Publishing Metrics...");
248+
249+
// Check that the hostname hasn't changed
250+
if (!metricPublisher
251+
.getTopic()
252+
.getName()
253+
.equals(ConfigManager.getInstance().getConfig().getNetworkConfig().hostname)) {
254+
logger.warn("Metrics publisher name does not match hostname! Reinitializing publisher...");
255+
metricPublisher.close();
256+
metricPublisher =
257+
NetworkTablesManager.getInstance()
258+
.kCoprocTable
259+
.getSubTable("/metrics")
260+
.getProtobufTopic(
261+
ConfigManager.getInstance().getConfig().getNetworkConfig().hostname,
262+
DeviceMetrics.proto)
263+
.publish();
264+
}
265+
247266
var metrics =
248267
new DeviceMetrics(
249268
this.getCpuTemp(),

0 commit comments

Comments
 (0)