mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
Added warning message if OperatingSystemMXBean not available
Also corrected spacing after code review comments. Fixes #11786
This commit is contained in:
parent
caa40036bc
commit
51431af405
2 changed files with 7 additions and 2 deletions
|
@ -97,7 +97,7 @@ public final class LogstashJavaCompat {
|
|||
* @return True if running on Java whose major version is greater than or equal to the
|
||||
* specified version.
|
||||
*/
|
||||
public static boolean isJavaAtLeast(int version){
|
||||
public static boolean isJavaAtLeast(int version) {
|
||||
final String value = System.getProperty("java.specification.version");
|
||||
final int actualVersion;
|
||||
// Java specification version prior to Java 9 were of the format `1.X`, and after the format `X`
|
||||
|
|
|
@ -28,12 +28,16 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.logstash.Logstash;
|
||||
import org.logstash.LogstashJavaCompat;
|
||||
|
||||
public class ProcessMonitor {
|
||||
|
||||
private static final OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
|
||||
private static final Method CPU_LOAD_METHOD = getCpuLoadMethod();
|
||||
private static final Logger LOGGER = LogManager.getLogger(ProcessMonitor.class);
|
||||
|
||||
public static class Report {
|
||||
private long memTotalVirtualInBytes = -1;
|
||||
|
@ -97,7 +101,7 @@ public class ProcessMonitor {
|
|||
// The method `getSystemCpuLoad` is deprecated in favour of `getCpuLoad` since JDK14
|
||||
// This method uses reflection to use the correct method depending on the version of
|
||||
// the JDK being used.
|
||||
private short getSystemCpuLoad(){
|
||||
private short getSystemCpuLoad() {
|
||||
if (CPU_LOAD_METHOD == null){
|
||||
return -1;
|
||||
}
|
||||
|
@ -118,6 +122,7 @@ public class ProcessMonitor {
|
|||
String methodName = (LogstashJavaCompat.isJavaAtLeast(14)) ? "getCpuLoad" : "getSystemCpuLoad";
|
||||
return Class.forName("com.sun.management.OperatingSystemMXBean").getMethod(methodName);
|
||||
} catch (ReflectiveOperationException e){
|
||||
LOGGER.warn("OperatingSystemMXBean CPU load method not available, CPU load will not be measured", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue