You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2019/11/24 00:46:32 UTC

[qpid-broker-j] branch 7.1.x updated (cdde19c -> d100cdc)

This is an automated email from the ASF dual-hosted git repository.

orudyy pushed a change to branch 7.1.x
in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git.


    from cdde19c  QPID-8377 : add test to verify IGNORE behaviour
     new d238eae  QPID-8376 : Report Process CPU usage in Broker Stats
     new d100cdc  QPID-8376 : Fix earlier change to work on JDK 11 as well as JDK 8

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../qpid/server/model/BrokerAttributeInjector.java | 138 ++++++++++++++++++++-
 1 file changed, 135 insertions(+), 3 deletions(-)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[qpid-broker-j] 01/02: QPID-8376 : Report Process CPU usage in Broker Stats

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orudyy pushed a commit to branch 7.1.x
in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git

commit d238eae169f5a543163111cce1aaa6676cbda793
Author: Robert Godfrey <rg...@apache.org>
AuthorDate: Sun Nov 17 13:14:50 2019 +0100

    QPID-8376 : Report Process CPU usage in Broker Stats
    
    (cherry picked from commit b8d24fc93ba41d3a4b4b5b74c04ea444a78e7943)
---
 .../qpid/server/model/BrokerAttributeInjector.java | 105 +++++++++++++++++++++
 1 file changed, 105 insertions(+)

diff --git a/broker-core/src/main/java/org/apache/qpid/server/model/BrokerAttributeInjector.java b/broker-core/src/main/java/org/apache/qpid/server/model/BrokerAttributeInjector.java
index 42d108e..a2d5278 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/model/BrokerAttributeInjector.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/model/BrokerAttributeInjector.java
@@ -23,13 +23,18 @@ package org.apache.qpid.server.model;
 import java.lang.management.GarbageCollectorMXBean;
 import java.lang.management.ManagementFactory;
 import java.lang.management.MemoryPoolMXBean;
+import java.lang.management.OperatingSystemMXBean;
 import java.lang.management.PlatformManagedObject;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
+import java.util.function.Function;
+import java.util.function.ToLongFunction;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -197,6 +202,95 @@ public class BrokerAttributeInjector implements ConfiguredObjectAttributeInjecto
                 LOGGER.warn("Failed to inject statistic '{}'", jvmGCCollectionCountStatisticName, e);
             }
         }
+
+        OperatingSystemMXBean osMXBean = ManagementFactory.getOperatingSystemMXBean();
+        try
+        {
+            Method method = osMXBean.getClass().getDeclaredMethod("getProcessCpuTime");
+            method.setAccessible(true);
+            ToLongFunction<Broker> supplier  = broker -> {
+                try
+                {
+                    final Object returnValue = method.invoke(osMXBean);
+
+                    if(returnValue instanceof Number)
+                    {
+                        return ((Number)returnValue).longValue();
+                    }
+                }
+                catch (IllegalAccessException | InvocationTargetException e)
+                {
+                    LOGGER.warn("Unable to get cumulative process CPU time");
+                }
+                return -1L;
+            };
+
+            Method getLongValue = BrokerAttributeInjector.class.getDeclaredMethod("getLongValue",
+                                                                                  Broker.class,
+                                                                                  ToLongFunction.class);
+
+            final ConfiguredObjectInjectedStatistic<?, ?> injectedStatistic =
+                    new ConfiguredObjectInjectedStatistic<>("processCpuTime",
+                                                            getLongValue,
+                                                            new Object[]{supplier},
+                                                            "Cumulative process CPU time",
+                                                            _typeValidator,
+                                                            StatisticUnit.TIME_DURATION,
+                                                            StatisticType.CUMULATIVE,
+                                                            osMXBean.getName()
+                                                            + " Process CPU Time");
+            statistics.add(injectedStatistic);
+
+        }
+        catch (NoSuchMethodException e)
+        {
+            LOGGER.warn("Failed to inject statistic 'getProcessCpuTime'", e);
+        }
+
+        try
+        {
+            Method method = osMXBean.getClass().getDeclaredMethod("getProcessCpuLoad");
+            method.setAccessible(true);
+            Function<Broker, BigDecimal> supplier  = broker -> {
+                try
+                {
+                    final Object returnValue = method.invoke(osMXBean);
+
+                    if(returnValue instanceof Number)
+                    {
+                        return BigDecimal.valueOf(((Number) returnValue).doubleValue()).setScale(4,
+                                                                                                 RoundingMode.HALF_UP);
+                    }
+                }
+                catch (IllegalAccessException | InvocationTargetException e)
+                {
+                    LOGGER.warn("Unable to get current process CPU load");
+                }
+                return BigDecimal.valueOf(Double.NaN);
+            };
+
+            Method getBigDecimalValue = BrokerAttributeInjector.class.getDeclaredMethod("getBigDecimalValue",
+                                                                                      Broker.class,
+                                                                                      Function.class);
+
+            final ConfiguredObjectInjectedStatistic<?, ?> injectedStatistic =
+                    new ConfiguredObjectInjectedStatistic<>("processCpuLoad",
+                                                            getBigDecimalValue,
+                                                            new Object[]{supplier},
+                                                            "Current process CPU load",
+                                                            _typeValidator,
+                                                            StatisticUnit.COUNT,
+                                                            StatisticType.POINT_IN_TIME,
+                                                            osMXBean.getName()
+                                                            + " Process CPU Load");
+            statistics.add(injectedStatistic);
+
+        }
+        catch (NoSuchMethodException e)
+        {
+            LOGGER.warn("Failed to inject statistic 'getProcessCpuLoad'", e);
+        }
+
         return statistics;
     }
 
@@ -365,6 +459,17 @@ public class BrokerAttributeInjector implements ConfiguredObjectAttributeInjecto
         }
     }
 
+    private static long getLongValue(Broker broker, ToLongFunction<Broker> supplier)
+    {
+        return supplier.applyAsLong(broker);
+    }
+
+    private static BigDecimal getBigDecimalValue(Broker broker, Function<Broker, BigDecimal> supplier)
+    {
+        return supplier.apply(broker);
+    }
+
+
     public static void dumpHeap(Broker<?> broker,
                                 PlatformManagedObject hotSpotDiagnosticMXBean,
                                 Method dumpHeapMethod,


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[qpid-broker-j] 02/02: QPID-8376 : Fix earlier change to work on JDK 11 as well as JDK 8

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orudyy pushed a commit to branch 7.1.x
in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git

commit d100cdcac4d29f7ec3be82b55f7cbea193715eb4
Author: Robert Godfrey <rg...@apache.org>
AuthorDate: Fri Nov 22 21:34:31 2019 +0100

    QPID-8376 : Fix earlier change to work on JDK 11 as well as JDK 8
    
    (cherry picked from commit 039e34899c229164a557c8e6debec3e11f5db6bc)
---
 .../qpid/server/model/BrokerAttributeInjector.java | 183 ++++++++++++---------
 1 file changed, 105 insertions(+), 78 deletions(-)

diff --git a/broker-core/src/main/java/org/apache/qpid/server/model/BrokerAttributeInjector.java b/broker-core/src/main/java/org/apache/qpid/server/model/BrokerAttributeInjector.java
index a2d5278..61be55f 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/model/BrokerAttributeInjector.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/model/BrokerAttributeInjector.java
@@ -62,14 +62,16 @@ public class BrokerAttributeInjector implements ConfiguredObjectAttributeInjecto
 
     private final Class<?> _hotSpotDiagnosticMXBeanClass;
     private final PlatformManagedObject _hotSpotDiagnosticMXBean;
+    private final Class<?> _operatingSystemMXBeanClass;
+    private final OperatingSystemMXBean _operatingSystemMXBean;
 
     public BrokerAttributeInjector()
     {
+        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
         Class<?> hotSpotDiagnosticMXBeanClass = null;
         PlatformManagedObject hotSpotDiagnosticMXBean = null;
         try
         {
-            ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
             hotSpotDiagnosticMXBeanClass =
                     Class.forName("com.sun.management.HotSpotDiagnosticMXBean", true, systemClassLoader);
             hotSpotDiagnosticMXBean =
@@ -83,6 +85,26 @@ public class BrokerAttributeInjector implements ConfiguredObjectAttributeInjecto
 
         _hotSpotDiagnosticMXBeanClass = hotSpotDiagnosticMXBeanClass;
         _hotSpotDiagnosticMXBean = hotSpotDiagnosticMXBean;
+
+
+        Class<?> operatingSystemMXBeanClass = null;
+        PlatformManagedObject operatingSystemMXBean = null;
+        try
+        {
+            operatingSystemMXBeanClass =
+                    Class.forName("com.sun.management.OperatingSystemMXBean", true, systemClassLoader);
+            operatingSystemMXBean =
+                    ManagementFactory.getPlatformMXBean((Class<? extends PlatformManagedObject>) operatingSystemMXBeanClass);
+
+        }
+        catch (IllegalArgumentException | ClassNotFoundException e)
+        {
+            LOGGER.debug("com.sun.management.OperatingSystemMXBean MXBean: " + e);
+        }
+
+        _operatingSystemMXBeanClass = operatingSystemMXBeanClass;
+        _operatingSystemMXBean = (OperatingSystemMXBean) operatingSystemMXBean;
+
     }
 
     @Override
@@ -167,7 +189,8 @@ public class BrokerAttributeInjector implements ConfiguredObjectAttributeInjecto
                         new ConfiguredObjectInjectedStatistic<>(jvmGCCollectionTimeStatisticName,
                                                                 getGCCollectionTime,
                                                                 new Object[]{garbageCollectorMXBean},
-                                                                "Cumulative time in ms taken to perform collections for GC " + garbageCollectorMXBean.getName(),
+                                                                "Cumulative time in ms taken to perform collections for GC "
+                                                                + garbageCollectorMXBean.getName(),
                                                                 _typeValidator,
                                                                 StatisticUnit.COUNT,
                                                                 StatisticType.CUMULATIVE,
@@ -189,7 +212,8 @@ public class BrokerAttributeInjector implements ConfiguredObjectAttributeInjecto
                         new ConfiguredObjectInjectedStatistic<>(jvmGCCollectionCountStatisticName,
                                                                 getGCCollectionCount,
                                                                 new Object[]{garbageCollectorMXBean},
-                                                                "Cumulative number of collections for GC " + garbageCollectorMXBean.getName(),
+                                                                "Cumulative number of collections for GC "
+                                                                + garbageCollectorMXBean.getName(),
                                                                 _typeValidator,
                                                                 StatisticUnit.COUNT,
                                                                 StatisticType.CUMULATIVE,
@@ -203,94 +227,97 @@ public class BrokerAttributeInjector implements ConfiguredObjectAttributeInjecto
             }
         }
 
-        OperatingSystemMXBean osMXBean = ManagementFactory.getOperatingSystemMXBean();
-        try
+        if (_operatingSystemMXBean != null)
         {
-            Method method = osMXBean.getClass().getDeclaredMethod("getProcessCpuTime");
-            method.setAccessible(true);
-            ToLongFunction<Broker> supplier  = broker -> {
-                try
-                {
-                    final Object returnValue = method.invoke(osMXBean);
+            try
+            {
+                Method method = _operatingSystemMXBeanClass.getDeclaredMethod("getProcessCpuTime");
 
-                    if(returnValue instanceof Number)
+                ToLongFunction<Broker> supplier = broker -> {
+                    try
                     {
-                        return ((Number)returnValue).longValue();
+                        final Object returnValue = method.invoke(_operatingSystemMXBean);
+
+                        if (returnValue instanceof Number)
+                        {
+                            return ((Number) returnValue).longValue();
+                        }
                     }
-                }
-                catch (IllegalAccessException | InvocationTargetException e)
-                {
-                    LOGGER.warn("Unable to get cumulative process CPU time");
-                }
-                return -1L;
-            };
+                    catch (IllegalAccessException | InvocationTargetException e)
+                    {
+                        LOGGER.warn("Unable to get cumulative process CPU time");
+                    }
+                    return -1L;
+                };
 
-            Method getLongValue = BrokerAttributeInjector.class.getDeclaredMethod("getLongValue",
-                                                                                  Broker.class,
-                                                                                  ToLongFunction.class);
-
-            final ConfiguredObjectInjectedStatistic<?, ?> injectedStatistic =
-                    new ConfiguredObjectInjectedStatistic<>("processCpuTime",
-                                                            getLongValue,
-                                                            new Object[]{supplier},
-                                                            "Cumulative process CPU time",
-                                                            _typeValidator,
-                                                            StatisticUnit.TIME_DURATION,
-                                                            StatisticType.CUMULATIVE,
-                                                            osMXBean.getName()
-                                                            + " Process CPU Time");
-            statistics.add(injectedStatistic);
+                Method getLongValue = BrokerAttributeInjector.class.getDeclaredMethod("getLongValue",
+                                                                                      Broker.class,
+                                                                                      ToLongFunction.class);
 
-        }
-        catch (NoSuchMethodException e)
-        {
-            LOGGER.warn("Failed to inject statistic 'getProcessCpuTime'", e);
-        }
+                final ConfiguredObjectInjectedStatistic<?, ?> injectedStatistic =
+                        new ConfiguredObjectInjectedStatistic<>("processCpuTime",
+                                                                getLongValue,
+                                                                new Object[]{supplier},
+                                                                "Cumulative process CPU time",
+                                                                _typeValidator,
+                                                                StatisticUnit.TIME_DURATION,
+                                                                StatisticType.CUMULATIVE,
+                                                                _operatingSystemMXBeanClass.getName()
+                                                                + " Process CPU Time");
+                statistics.add(injectedStatistic);
 
-        try
-        {
-            Method method = osMXBean.getClass().getDeclaredMethod("getProcessCpuLoad");
-            method.setAccessible(true);
-            Function<Broker, BigDecimal> supplier  = broker -> {
-                try
-                {
-                    final Object returnValue = method.invoke(osMXBean);
+            }
+            catch (NoSuchMethodException | SecurityException e)
+            {
+                LOGGER.warn("Failed to inject statistic 'getProcessCpuTime'");
+                LOGGER.debug("Exception:",e);
+            }
 
-                    if(returnValue instanceof Number)
+            try
+            {
+                Method method = _operatingSystemMXBeanClass.getDeclaredMethod("getProcessCpuLoad");
+                method.setAccessible(true);
+                Function<Broker, BigDecimal> supplier = broker -> {
+                    try
                     {
-                        return BigDecimal.valueOf(((Number) returnValue).doubleValue()).setScale(4,
-                                                                                                 RoundingMode.HALF_UP);
+                        final Object returnValue = method.invoke(_operatingSystemMXBean);
+
+                        if (returnValue instanceof Number)
+                        {
+                            return BigDecimal.valueOf(((Number) returnValue).doubleValue()).setScale(4,
+                                                                                                     RoundingMode.HALF_UP);
+                        }
                     }
-                }
-                catch (IllegalAccessException | InvocationTargetException e)
-                {
-                    LOGGER.warn("Unable to get current process CPU load");
-                }
-                return BigDecimal.valueOf(Double.NaN);
-            };
+                    catch (IllegalAccessException | InvocationTargetException e)
+                    {
+                        LOGGER.warn("Unable to get current process CPU load", e);
+                    }
+                    return BigDecimal.valueOf(-1L);
+                };
 
-            Method getBigDecimalValue = BrokerAttributeInjector.class.getDeclaredMethod("getBigDecimalValue",
-                                                                                      Broker.class,
-                                                                                      Function.class);
-
-            final ConfiguredObjectInjectedStatistic<?, ?> injectedStatistic =
-                    new ConfiguredObjectInjectedStatistic<>("processCpuLoad",
-                                                            getBigDecimalValue,
-                                                            new Object[]{supplier},
-                                                            "Current process CPU load",
-                                                            _typeValidator,
-                                                            StatisticUnit.COUNT,
-                                                            StatisticType.POINT_IN_TIME,
-                                                            osMXBean.getName()
-                                                            + " Process CPU Load");
-            statistics.add(injectedStatistic);
+                Method getBigDecimalValue = BrokerAttributeInjector.class.getDeclaredMethod("getBigDecimalValue",
+                                                                                            Broker.class,
+                                                                                            Function.class);
 
-        }
-        catch (NoSuchMethodException e)
-        {
-            LOGGER.warn("Failed to inject statistic 'getProcessCpuLoad'", e);
-        }
+                final ConfiguredObjectInjectedStatistic<?, ?> injectedStatistic =
+                        new ConfiguredObjectInjectedStatistic<>("processCpuLoad",
+                                                                getBigDecimalValue,
+                                                                new Object[]{supplier},
+                                                                "Current process CPU load",
+                                                                _typeValidator,
+                                                                StatisticUnit.COUNT,
+                                                                StatisticType.POINT_IN_TIME,
+                                                                _operatingSystemMXBean.getName()
+                                                                + " Process CPU Load");
+                statistics.add(injectedStatistic);
 
+            }
+            catch (NoSuchMethodException e)
+            {
+                LOGGER.warn("Failed to inject statistic 'getProcessCpuLoad'");
+                LOGGER.debug("Exception:",e);
+            }
+        }
         return statistics;
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org