You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by pv...@apache.org on 2022/08/08 12:57:28 UTC
[nifi] branch main updated: NIFI-10305 Fix network and cpu data in c2 heartbeat
This is an automated email from the ASF dual-hosted git repository.
pvillard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 0fe4d13490 NIFI-10305 Fix network and cpu data in c2 heartbeat
0fe4d13490 is described below
commit 0fe4d1349074b2fcbffe8fe2765fbe78fabc65c9
Author: Ferenc Erdei <er...@gmail.com>
AuthorDate: Mon Aug 1 12:23:18 2022 +0200
NIFI-10305 Fix network and cpu data in c2 heartbeat
Signed-off-by: Pierre Villard <pi...@gmail.com>
This closes #6263.
---
.../nifi/c2/client/service/C2HeartbeatFactory.java | 31 +++++++++++-----------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/c2/c2-client-bundle/c2-client-service/src/main/java/org/apache/nifi/c2/client/service/C2HeartbeatFactory.java b/c2/c2-client-bundle/c2-client-service/src/main/java/org/apache/nifi/c2/client/service/C2HeartbeatFactory.java
index 3fb40813cb..bac10e2d0b 100644
--- a/c2/c2-client-bundle/c2-client-service/src/main/java/org/apache/nifi/c2/client/service/C2HeartbeatFactory.java
+++ b/c2/c2-client-bundle/c2-client-service/src/main/java/org/apache/nifi/c2/client/service/C2HeartbeatFactory.java
@@ -146,22 +146,18 @@ public class C2HeartbeatFactory {
logger.debug("Instance has multiple interfaces. Generated information may be non-deterministic.");
}
- NetworkInterface iface = operationIfaces.iterator().next();
- Enumeration<InetAddress> inetAddresses = iface.getInetAddresses();
- while (inetAddresses.hasMoreElements()) {
- InetAddress inetAddress = inetAddresses.nextElement();
- String hostAddress = inetAddress.getHostAddress();
- String hostName = inetAddress.getHostName();
- byte[] address = inetAddress.getAddress();
- String canonicalHostName = inetAddress.getCanonicalHostName();
-
- networkInfo.setDeviceId(iface.getName());
- networkInfo.setHostname(hostName);
- networkInfo.setIpAddress(hostAddress);
+ for (NetworkInterface networkInterface : operationIfaces) {
+ Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
+ if (inetAddresses.hasMoreElements()) {
+ InetAddress inetAddress = inetAddresses.nextElement();
+ networkInfo.setDeviceId(networkInterface.getName());
+ networkInfo.setHostname(inetAddress.getHostName());
+ networkInfo.setIpAddress(inetAddress.getHostAddress());
+ break;
+ }
}
}
- } catch (
- Exception e) {
+ } catch (Exception e) {
logger.error("Network Interface processing failed", e);
}
return networkInfo;
@@ -206,7 +202,12 @@ public class C2HeartbeatFactory {
OperatingSystemMXBean osMXBean = ManagementFactory.getOperatingSystemMXBean();
systemInfo.setMachineArch(osMXBean.getArch());
systemInfo.setOperatingSystem(osMXBean.getName());
- systemInfo.setCpuUtilization(osMXBean.getSystemLoadAverage() / (double) osMXBean.getAvailableProcessors());
+
+ double systemLoadAverage = osMXBean.getSystemLoadAverage();
+ // getSystemLoadAverage is not available in Windows, so we need to prevent to send invalid data
+ if (systemLoadAverage >= 0) {
+ systemInfo.setCpuUtilization(systemLoadAverage / (double) osMXBean.getAvailableProcessors());
+ }
return systemInfo;
}