diff --git a/photon-core/src/main/java/org/photonvision/common/hardware/metrics/MetricsManager.java b/photon-core/src/main/java/org/photonvision/common/hardware/metrics/MetricsManager.java index 8d7c597c68..717c844146 100644 --- a/photon-core/src/main/java/org/photonvision/common/hardware/metrics/MetricsManager.java +++ b/photon-core/src/main/java/org/photonvision/common/hardware/metrics/MetricsManager.java @@ -224,9 +224,7 @@ public double[] getNpuUsage() { */ public String getIpAddress() { String dev = ConfigManager.getInstance().getConfig().getNetworkConfig().networkManagerIface; - logger.debug("Requesting IP addresses for \"" + dev + "\""); String addr = NetworkUtils.getIPAddresses(dev); - logger.debug("Got value \"" + addr + "\""); return addr; } @@ -244,8 +242,6 @@ public double getUptime() { } public void publishMetrics() { - logger.debug("Publishing Metrics..."); - // Check that the hostname hasn't changed if (!CameraServerJNI.getHostname() .equals(NetworkTable.basenameKey(metricPublisher.getTopic().getName()))) { diff --git a/photon-core/src/main/java/org/photonvision/common/networking/NetworkUtils.java b/photon-core/src/main/java/org/photonvision/common/networking/NetworkUtils.java index f259317e8f..77aee6600a 100644 --- a/photon-core/src/main/java/org/photonvision/common/networking/NetworkUtils.java +++ b/photon-core/src/main/java/org/photonvision/common/networking/NetworkUtils.java @@ -78,7 +78,7 @@ public static boolean nmcliIsInstalled() { } } - private static List allInterfaces = new ArrayList<>(); + private static List allInterfaces = null; private static long lastReadTimestamp = 0; public static List getAllInterfaces() { @@ -88,35 +88,36 @@ public static List getAllInterfaces() { var ret = new ArrayList(); - if (!Platform.isLinux()) { - // Can only determine interface name on Linux, give up - return ret; - } - - try { - var shell = new ShellExec(true, false); - shell.executeBashCommand( - "nmcli -t -f GENERAL.CONNECTION,GENERAL.DEVICE,GENERAL.TYPE device show"); - String out = shell.getOutput(); - if (out == null) { - return new ArrayList<>(); + if (Platform.isLinux()) { + String out = null; + try { + var shell = new ShellExec(true, false); + shell.executeBashCommand( + "nmcli -t -f GENERAL.CONNECTION,GENERAL.DEVICE,GENERAL.TYPE device show", true, false); + out = shell.getOutput(); + } catch (IOException e) { + logger.error("IO Exception occured when calling nmcli to get network interfaces!", e); } - Pattern pattern = - Pattern.compile("GENERAL.CONNECTION:(.*)\nGENERAL.DEVICE:(.*)\nGENERAL.TYPE:(.*)"); - Matcher matcher = pattern.matcher(out); - while (matcher.find()) { - if (!matcher.group(2).equals("lo")) { - // only include non-loopback devices - ret.add(new NMDeviceInfo(matcher.group(1), matcher.group(2), matcher.group(3))); + if (out != null) { + Pattern pattern = + Pattern.compile("GENERAL.CONNECTION:(.*)\nGENERAL.DEVICE:(.*)\nGENERAL.TYPE:(.*)"); + Matcher matcher = pattern.matcher(out); + while (matcher.find()) { + if (!matcher.group(2).equals("lo")) { + // only include non-loopback devices + ret.add(new NMDeviceInfo(matcher.group(1), matcher.group(2), matcher.group(3))); + } } } - } catch (IOException e) { - logger.error("Could not get active network interfaces!", e); } - - logger.debug("Found network interfaces: " + ret); - - allInterfaces = ret; + if (!ret.equals(allInterfaces)) { + if (ret.isEmpty()) { + logger.error("Unable to identify network interfaces!"); + } else { + logger.debug("Found network interfaces: " + ret); + } + allInterfaces = ret; + } return ret; } diff --git a/photon-core/src/main/java/org/photonvision/common/util/ShellExec.java b/photon-core/src/main/java/org/photonvision/common/util/ShellExec.java index 59c3329cc1..958b6767f2 100644 --- a/photon-core/src/main/java/org/photonvision/common/util/ShellExec.java +++ b/photon-core/src/main/java/org/photonvision/common/util/ShellExec.java @@ -60,7 +60,7 @@ public int executeBashCommand(String command) throws IOException { * @return process exit code */ public int executeBashCommand(String command, boolean wait) throws IOException { - return executeBashCommand(command, true, true); + return executeBashCommand(command, wait, true); } /**