mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-25 01:41:40 +00:00
Remove log spam from periodic network and IP address queries (#2051)
This commit is contained in:
@@ -224,9 +224,7 @@ public class MetricsManager {
|
||||
*/
|
||||
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 class MetricsManager {
|
||||
}
|
||||
|
||||
public void publishMetrics() {
|
||||
logger.debug("Publishing Metrics...");
|
||||
|
||||
// Check that the hostname hasn't changed
|
||||
if (!CameraServerJNI.getHostname()
|
||||
.equals(NetworkTable.basenameKey(metricPublisher.getTopic().getName()))) {
|
||||
|
||||
@@ -78,7 +78,7 @@ public class NetworkUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static List<NMDeviceInfo> allInterfaces = new ArrayList<>();
|
||||
private static List<NMDeviceInfo> allInterfaces = null;
|
||||
private static long lastReadTimestamp = 0;
|
||||
|
||||
public static List<NMDeviceInfo> getAllInterfaces() {
|
||||
@@ -88,35 +88,36 @@ public class NetworkUtils {
|
||||
|
||||
var ret = new ArrayList<NMDeviceInfo>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class ShellExec {
|
||||
* @return process exit code
|
||||
*/
|
||||
public int executeBashCommand(String command, boolean wait) throws IOException {
|
||||
return executeBashCommand(command, true, true);
|
||||
return executeBashCommand(command, wait, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user