Skip to content

Commit 29e1836

Browse files
authored
Remove log spam from periodic network and IP address queries (#2051)
1 parent 8676649 commit 29e1836

File tree

3 files changed

+28
-31
lines changed

3 files changed

+28
-31
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,7 @@ public double[] getNpuUsage() {
224224
*/
225225
public String getIpAddress() {
226226
String dev = ConfigManager.getInstance().getConfig().getNetworkConfig().networkManagerIface;
227-
logger.debug("Requesting IP addresses for \"" + dev + "\"");
228227
String addr = NetworkUtils.getIPAddresses(dev);
229-
logger.debug("Got value \"" + addr + "\"");
230228
return addr;
231229
}
232230

@@ -244,8 +242,6 @@ public double getUptime() {
244242
}
245243

246244
public void publishMetrics() {
247-
logger.debug("Publishing Metrics...");
248-
249245
// Check that the hostname hasn't changed
250246
if (!CameraServerJNI.getHostname()
251247
.equals(NetworkTable.basenameKey(metricPublisher.getTopic().getName()))) {

photon-core/src/main/java/org/photonvision/common/networking/NetworkUtils.java

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static boolean nmcliIsInstalled() {
7878
}
7979
}
8080

81-
private static List<NMDeviceInfo> allInterfaces = new ArrayList<>();
81+
private static List<NMDeviceInfo> allInterfaces = null;
8282
private static long lastReadTimestamp = 0;
8383

8484
public static List<NMDeviceInfo> getAllInterfaces() {
@@ -88,35 +88,36 @@ public static List<NMDeviceInfo> getAllInterfaces() {
8888

8989
var ret = new ArrayList<NMDeviceInfo>();
9090

91-
if (!Platform.isLinux()) {
92-
// Can only determine interface name on Linux, give up
93-
return ret;
94-
}
95-
96-
try {
97-
var shell = new ShellExec(true, false);
98-
shell.executeBashCommand(
99-
"nmcli -t -f GENERAL.CONNECTION,GENERAL.DEVICE,GENERAL.TYPE device show");
100-
String out = shell.getOutput();
101-
if (out == null) {
102-
return new ArrayList<>();
91+
if (Platform.isLinux()) {
92+
String out = null;
93+
try {
94+
var shell = new ShellExec(true, false);
95+
shell.executeBashCommand(
96+
"nmcli -t -f GENERAL.CONNECTION,GENERAL.DEVICE,GENERAL.TYPE device show", true, false);
97+
out = shell.getOutput();
98+
} catch (IOException e) {
99+
logger.error("IO Exception occured when calling nmcli to get network interfaces!", e);
103100
}
104-
Pattern pattern =
105-
Pattern.compile("GENERAL.CONNECTION:(.*)\nGENERAL.DEVICE:(.*)\nGENERAL.TYPE:(.*)");
106-
Matcher matcher = pattern.matcher(out);
107-
while (matcher.find()) {
108-
if (!matcher.group(2).equals("lo")) {
109-
// only include non-loopback devices
110-
ret.add(new NMDeviceInfo(matcher.group(1), matcher.group(2), matcher.group(3)));
101+
if (out != null) {
102+
Pattern pattern =
103+
Pattern.compile("GENERAL.CONNECTION:(.*)\nGENERAL.DEVICE:(.*)\nGENERAL.TYPE:(.*)");
104+
Matcher matcher = pattern.matcher(out);
105+
while (matcher.find()) {
106+
if (!matcher.group(2).equals("lo")) {
107+
// only include non-loopback devices
108+
ret.add(new NMDeviceInfo(matcher.group(1), matcher.group(2), matcher.group(3)));
109+
}
111110
}
112111
}
113-
} catch (IOException e) {
114-
logger.error("Could not get active network interfaces!", e);
115112
}
116-
117-
logger.debug("Found network interfaces: " + ret);
118-
119-
allInterfaces = ret;
113+
if (!ret.equals(allInterfaces)) {
114+
if (ret.isEmpty()) {
115+
logger.error("Unable to identify network interfaces!");
116+
} else {
117+
logger.debug("Found network interfaces: " + ret);
118+
}
119+
allInterfaces = ret;
120+
}
120121
return ret;
121122
}
122123

photon-core/src/main/java/org/photonvision/common/util/ShellExec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public int executeBashCommand(String command) throws IOException {
6060
* @return process exit code
6161
*/
6262
public int executeBashCommand(String command, boolean wait) throws IOException {
63-
return executeBashCommand(command, true, true);
63+
return executeBashCommand(command, wait, true);
6464
}
6565

6666
/**

0 commit comments

Comments
 (0)