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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 0ea9f0eab41 camel-jbang - Add load average statistics
0ea9f0eab41 is described below

commit 0ea9f0eab41af67c36af6f11249be64a35f7c3e7
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Thu Sep 8 16:13:35 2022 +0200

    camel-jbang - Add load average statistics
---
 .../main/camel-main-configuration-metadata.json    |  1 +
 .../camel/impl/console/ContextDevConsole.java      | 38 +++++++++++++++++++++-
 .../apache/camel/impl/console/RouteDevConsole.java | 37 ++++++++++++++++++++-
 .../MainConfigurationPropertiesConfigurer.java     |  6 ++++
 .../camel-main-configuration-metadata.json         |  1 +
 core/camel-main/src/main/docs/main.adoc            |  3 +-
 .../camel/main/DefaultConfigurationConfigurer.java |  2 ++
 .../camel/main/DefaultConfigurationProperties.java | 25 ++++++++++++++
 .../java/org/apache/camel/main/KameletMain.java    |  2 ++
 9 files changed, 112 insertions(+), 3 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
index 3c49d0982d8..895849bf2e0 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
@@ -59,6 +59,7 @@
     { "name": "camel.main.jmxManagementStatisticsLevel", "description": "Sets 
the JMX statistics level, the level can be set to Extended to gather additional 
information The default value is Default.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "object", 
"javaType": "org.apache.camel.ManagementStatisticsLevel", "defaultValue": 
"Default", "enum": [ "Extended", "Default", "RoutesOnly", "Off" ] },
     { "name": "camel.main.lightweight", "description": "Configure the context 
to be lightweight. This will trigger some optimizations and memory reduction 
options. Lightweight context have some limitations. At this moment, dynamic 
endpoint destinations are not supported.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": "false" },
     { "name": "camel.main.loadHealthChecks", "description": "Whether to load 
custom health checks by scanning classpath.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": "false" },
+    { "name": "camel.main.loadStatisticsEnabled", "description": "Sets whether 
context load statistics is enabled (something like the unix load average). The 
statistics requires to have camel-management on the classpath as JMX is 
required. The default value is false.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": "false" },
     { "name": "camel.main.loadTypeConverters", "description": "Whether to load 
custom type converters by scanning classpath. This is used for backwards 
compatibility with Camel 2.x. Its recommended to migrate to use fast type 
converter loading by setting Converter(loader = true) on your custom type 
converter classes.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": "false" },
     { "name": "camel.main.logDebugMaxChars", "description": "Is used to limit 
the maximum length of the logging Camel message bodies. If the message body is 
longer than the limit, the log message is clipped. Use -1 to have unlimited 
length. Use for example 1000 to log at most 1000 characters.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", 
"javaType": "int" },
     { "name": "camel.main.logExhaustedMessageBody", "description": "Sets 
whether to log exhausted message body with message history. Default is false.", 
"sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": 
"boolean", "javaType": "boolean", "defaultValue": "false" },
diff --git 
a/core/camel-console/src/main/java/org/apache/camel/impl/console/ContextDevConsole.java
 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/ContextDevConsole.java
index 6610d482ca2..0f1cafa1196 100644
--- 
a/core/camel-console/src/main/java/org/apache/camel/impl/console/ContextDevConsole.java
+++ 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/ContextDevConsole.java
@@ -60,6 +60,12 @@ public class ContextDevConsole extends AbstractDevConsole {
                 if (crs != null) {
                     reloaded += crs.getReloadCounter();
                 }
+                String load1 = getLoad1(mb);
+                String load5 = getLoad5(mb);
+                String load15 = getLoad15(mb);
+                if (!load1.isEmpty() || !load5.isEmpty() || !load15.isEmpty()) 
{
+                    sb.append(String.format("\n    Load Average: %s %s %s\n", 
load1, load5, load15));
+                }
                 sb.append(String.format("\n    Total: %s", 
mb.getExchangesTotal()));
                 sb.append(String.format("\n    Failed: %s", 
mb.getExchangesFailed()));
                 sb.append(String.format("\n    Inflight: %s", 
mb.getExchangesInflight()));
@@ -104,6 +110,8 @@ public class ContextDevConsole extends AbstractDevConsole {
         if (mcc != null) {
             ManagedCamelContextMBean mb = mcc.getManagedCamelContext();
             if (mb != null) {
+                JsonObject stats = new JsonObject();
+
                 int reloaded = 0;
                 ResourceReloadStrategy rrs = 
getCamelContext().hasService(ResourceReloadStrategy.class);
                 if (rrs != null) {
@@ -113,7 +121,14 @@ public class ContextDevConsole extends AbstractDevConsole {
                 if (crs != null) {
                     reloaded += crs.getReloadCounter();
                 }
-                JsonObject stats = new JsonObject();
+                String load1 = getLoad1(mb);
+                String load5 = getLoad5(mb);
+                String load15 = getLoad15(mb);
+                if (!load1.isEmpty() || !load5.isEmpty() || !load15.isEmpty()) 
{
+                    stats.put("load01", load1);
+                    stats.put("load05", load5);
+                    stats.put("load15", load15);
+                }
                 stats.put("exchangesTotal", mb.getExchangesTotal());
                 stats.put("exchangesFailed", mb.getExchangesFailed());
                 stats.put("exchangesInflight", mb.getExchangesInflight());
@@ -143,4 +158,25 @@ public class ContextDevConsole extends AbstractDevConsole {
         return root;
     }
 
+    private String getLoad1(ManagedCamelContextMBean mb) {
+        String s = mb.getLoad01();
+        // lets use dot as separator
+        s = s.replace(',', '.');
+        return s;
+    }
+
+    private String getLoad5(ManagedCamelContextMBean mb) {
+        String s = mb.getLoad05();
+        // lets use dot as separator
+        s = s.replace(',', '.');
+        return s;
+    }
+
+    private String getLoad15(ManagedCamelContextMBean mb) {
+        String s = mb.getLoad15();
+        // lets use dot as separator
+        s = s.replace(',', '.');
+        return s;
+    }
+
 }
diff --git 
a/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteDevConsole.java
 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteDevConsole.java
index 8131a4b81fc..a37c1044c79 100644
--- 
a/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteDevConsole.java
+++ 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteDevConsole.java
@@ -25,6 +25,7 @@ import java.util.function.Function;
 import org.apache.camel.Exchange;
 import org.apache.camel.Route;
 import org.apache.camel.api.management.ManagedCamelContext;
+import org.apache.camel.api.management.mbean.ManagedCamelContextMBean;
 import org.apache.camel.api.management.mbean.ManagedRouteMBean;
 import org.apache.camel.spi.annotations.DevConsole;
 import org.apache.camel.support.PatternHelper;
@@ -63,6 +64,12 @@ public class RouteDevConsole extends AbstractDevConsole {
             }
             sb.append(String.format("\n    State: %s", mrb.getState()));
             sb.append(String.format("\n    Uptime: %s", mrb.getUptime()));
+            String load1 = getLoad1(mrb);
+            String load5 = getLoad5(mrb);
+            String load15 = getLoad15(mrb);
+            if (!load1.isEmpty() || !load5.isEmpty() || !load15.isEmpty()) {
+                sb.append(String.format("\n    Load Average: %s %s %s\n", 
load1, load5, load15));
+            }
             sb.append(String.format("\n    Total: %s", 
mrb.getExchangesTotal()));
             sb.append(String.format("\n    Failed: %s", 
mrb.getExchangesFailed()));
             sb.append(String.format("\n    Inflight: %s", 
mrb.getExchangesInflight()));
@@ -99,7 +106,6 @@ public class RouteDevConsole extends AbstractDevConsole {
         Function<ManagedRouteMBean, Object> task = mrb -> {
             JsonObject jo = new JsonObject();
             list.add(jo);
-
             jo.put("routeId", mrb.getRouteId());
             jo.put("from", mrb.getEndpointUri());
             if (mrb.getSourceLocation() != null) {
@@ -108,6 +114,14 @@ public class RouteDevConsole extends AbstractDevConsole {
             jo.put("state", mrb.getState());
             jo.put("uptime", mrb.getUptime());
             JsonObject stats = new JsonObject();
+            String load1 = getLoad1(mrb);
+            String load5 = getLoad5(mrb);
+            String load15 = getLoad15(mrb);
+            if (!load1.isEmpty() || !load5.isEmpty() || !load15.isEmpty()) {
+                stats.put("load01", load1);
+                stats.put("load05", load5);
+                stats.put("load15", load15);
+            }
             stats.put("exchangesTotal", mrb.getExchangesTotal());
             stats.put("exchangesFailed", mrb.getExchangesFailed());
             stats.put("exchangesInflight", mrb.getExchangesInflight());
@@ -173,4 +187,25 @@ public class RouteDevConsole extends AbstractDevConsole {
         return o1.getRouteId().compareTo(o2.getRouteId());
     }
 
+    private String getLoad1(ManagedRouteMBean mrb) {
+        String s = mrb.getLoad01();
+        // lets use dot as separator
+        s = s.replace(',', '.');
+        return s;
+    }
+
+    private String getLoad5(ManagedRouteMBean mrb) {
+        String s = mrb.getLoad05();
+        // lets use dot as separator
+        s = s.replace(',', '.');
+        return s;
+    }
+
+    private String getLoad15(ManagedRouteMBean mrb) {
+        String s = mrb.getLoad15();
+        // lets use dot as separator
+        s = s.replace(',', '.');
+        return s;
+    }
+
 }
diff --git 
a/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
 
b/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
index fd3953a833b..f55f7da8e7c 100644
--- 
a/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
+++ 
b/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
@@ -115,6 +115,8 @@ public class MainConfigurationPropertiesConfigurer extends 
org.apache.camel.supp
         case "Lightweight": target.setLightweight(property(camelContext, 
boolean.class, value)); return true;
         case "loadhealthchecks":
         case "LoadHealthChecks": 
target.setLoadHealthChecks(property(camelContext, boolean.class, value)); 
return true;
+        case "loadstatisticsenabled":
+        case "LoadStatisticsEnabled": 
target.setLoadStatisticsEnabled(property(camelContext, boolean.class, value)); 
return true;
         case "loadtypeconverters":
         case "LoadTypeConverters": 
target.setLoadTypeConverters(property(camelContext, boolean.class, value)); 
return true;
         case "logdebugmaxchars":
@@ -356,6 +358,8 @@ public class MainConfigurationPropertiesConfigurer extends 
org.apache.camel.supp
         case "Lightweight": return boolean.class;
         case "loadhealthchecks":
         case "LoadHealthChecks": return boolean.class;
+        case "loadstatisticsenabled":
+        case "LoadStatisticsEnabled": return boolean.class;
         case "loadtypeconverters":
         case "LoadTypeConverters": return boolean.class;
         case "logdebugmaxchars":
@@ -598,6 +602,8 @@ public class MainConfigurationPropertiesConfigurer extends 
org.apache.camel.supp
         case "Lightweight": return target.isLightweight();
         case "loadhealthchecks":
         case "LoadHealthChecks": return target.isLoadHealthChecks();
+        case "loadstatisticsenabled":
+        case "LoadStatisticsEnabled": return target.isLoadStatisticsEnabled();
         case "loadtypeconverters":
         case "LoadTypeConverters": return target.isLoadTypeConverters();
         case "logdebugmaxchars":
diff --git 
a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
 
b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
index 3c49d0982d8..895849bf2e0 100644
--- 
a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
+++ 
b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
@@ -59,6 +59,7 @@
     { "name": "camel.main.jmxManagementStatisticsLevel", "description": "Sets 
the JMX statistics level, the level can be set to Extended to gather additional 
information The default value is Default.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "object", 
"javaType": "org.apache.camel.ManagementStatisticsLevel", "defaultValue": 
"Default", "enum": [ "Extended", "Default", "RoutesOnly", "Off" ] },
     { "name": "camel.main.lightweight", "description": "Configure the context 
to be lightweight. This will trigger some optimizations and memory reduction 
options. Lightweight context have some limitations. At this moment, dynamic 
endpoint destinations are not supported.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": "false" },
     { "name": "camel.main.loadHealthChecks", "description": "Whether to load 
custom health checks by scanning classpath.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": "false" },
+    { "name": "camel.main.loadStatisticsEnabled", "description": "Sets whether 
context load statistics is enabled (something like the unix load average). The 
statistics requires to have camel-management on the classpath as JMX is 
required. The default value is false.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": "false" },
     { "name": "camel.main.loadTypeConverters", "description": "Whether to load 
custom type converters by scanning classpath. This is used for backwards 
compatibility with Camel 2.x. Its recommended to migrate to use fast type 
converter loading by setting Converter(loader = true) on your custom type 
converter classes.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": "false" },
     { "name": "camel.main.logDebugMaxChars", "description": "Is used to limit 
the maximum length of the logging Camel message bodies. If the message body is 
longer than the limit, the log message is clipped. Use -1 to have unlimited 
length. Use for example 1000 to log at most 1000 characters.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", 
"javaType": "int" },
     { "name": "camel.main.logExhaustedMessageBody", "description": "Sets 
whether to log exhausted message body with message history. Default is false.", 
"sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": 
"boolean", "javaType": "boolean", "defaultValue": "false" },
diff --git a/core/camel-main/src/main/docs/main.adoc 
b/core/camel-main/src/main/docs/main.adoc
index 821bc36b5bc..ece27ae2d5a 100644
--- a/core/camel-main/src/main/docs/main.adoc
+++ b/core/camel-main/src/main/docs/main.adoc
@@ -18,7 +18,7 @@ The following tables lists all the options:
 
 // main options: START
 === Camel Main configurations
-The camel.main supports 117 options, which are listed below.
+The camel.main supports 118 options, which are listed below.
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
@@ -70,6 +70,7 @@ The camel.main supports 117 options, which are listed below.
 | *camel.main.jmxManagement{zwsp}StatisticsLevel* | Sets the JMX statistics 
level, the level can be set to Extended to gather additional information The 
default value is Default. | Default | ManagementStatisticsLevel
 | *camel.main.lightweight* | Configure the context to be lightweight. This 
will trigger some optimizations and memory reduction options. Lightweight 
context have some limitations. At this moment, dynamic endpoint destinations 
are not supported. | false | boolean
 | *camel.main.loadHealthChecks* | Whether to load custom health checks by 
scanning classpath. | false | boolean
+| *camel.main.loadStatistics{zwsp}Enabled* | Sets whether context load 
statistics is enabled (something like the unix load average). The statistics 
requires to have camel-management on the classpath as JMX is required. The 
default value is false. | false | boolean
 | *camel.main.loadTypeConverters* | Whether to load custom type converters by 
scanning classpath. This is used for backwards compatibility with Camel 2.x. 
Its recommended to migrate to use fast type converter loading by setting 
Converter(loader = true) on your custom type converter classes. | false | 
boolean
 | *camel.main.logDebugMaxChars* | Is used to limit the maximum length of the 
logging Camel message bodies. If the message body is longer than the limit, the 
log message is clipped. Use -1 to have unlimited length. Use for example 1000 
to log at most 1000 characters. |  | int
 | *camel.main.logExhaustedMessage{zwsp}Body* | Sets whether to log exhausted 
message body with message history. Default is false. | false | boolean
diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
 
b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
index cade2332f52..1f61ae5f9f7 100644
--- 
a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
+++ 
b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
@@ -258,6 +258,8 @@ public final class DefaultConfigurationConfigurer {
         if (camelContext.getManagementStrategy().getManagementAgent() != null) 
{
             camelContext.getManagementStrategy().getManagementAgent()
                     
.setEndpointRuntimeStatisticsEnabled(config.isEndpointRuntimeStatisticsEnabled());
+            camelContext.getManagementStrategy().getManagementAgent()
+                    
.setLoadStatisticsEnabled(config.isLoadStatisticsEnabled());
             camelContext.getManagementStrategy().getManagementAgent()
                     
.setStatisticsLevel(config.getJmxManagementStatisticsLevel());
             camelContext.getManagementStrategy().getManagementAgent()
diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
 
b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
index cebac3929ae..32543b30b1c 100644
--- 
a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
+++ 
b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
@@ -86,6 +86,7 @@ public abstract class DefaultConfigurationProperties<T> {
     private boolean caseInsensitiveHeaders = true;
     private boolean autowiredEnabled = true;
     private boolean endpointRuntimeStatisticsEnabled;
+    private boolean loadStatisticsEnabled;
     private boolean endpointLazyStartProducer;
     private boolean endpointBridgeErrorHandler;
     private boolean useDataType;
@@ -809,6 +810,20 @@ public abstract class DefaultConfigurationProperties<T> {
         this.endpointRuntimeStatisticsEnabled = 
endpointRuntimeStatisticsEnabled;
     }
 
+    public boolean isLoadStatisticsEnabled() {
+        return loadStatisticsEnabled;
+    }
+
+    /**
+     * Sets whether context load statistics is enabled (something like the 
unix load average).
+     * The statistics requires to have camel-management on the classpath as 
JMX is required.
+     *
+     * The default value is false.
+     */
+    public void setLoadStatisticsEnabled(boolean loadStatisticsEnabled) {
+        this.loadStatisticsEnabled = loadStatisticsEnabled;
+    }
+
     public boolean isEndpointLazyStartProducer() {
         return endpointLazyStartProducer;
     }
@@ -2026,6 +2041,16 @@ public abstract class DefaultConfigurationProperties<T> {
         return (T) this;
     }
 
+    /**
+     * Sets whether context load statistics is enabled (something like the 
unix load average).
+     *
+     * The default value is false.
+     */
+    public T withLoadStatisticsEnabled(boolean loadStatisticsEnabled) {
+        this.loadStatisticsEnabled = loadStatisticsEnabled;
+        return (T) this;
+    }
+
     /**
      * Whether the producer should be started lazy (on the first message). By 
starting lazy you can use this to allow
      * CamelContext and routes to startup in situations where a producer may 
otherwise fail during starting and cause
diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
index e187a9d1901..a471467bc7e 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
@@ -22,6 +22,7 @@ import java.util.Objects;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.ManagementStatisticsLevel;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.impl.DefaultCamelContext;
@@ -342,6 +343,7 @@ public class KameletMain extends MainCommandLineSupport {
         }
         configure().withLoadHealthChecks(true);
         configure().withModeline(true);
+        configure().withLoadStatisticsEnabled(true);
 
         boolean health = 
"true".equals(getInitialProperties().get("camel.jbang.health"));
         if (health && port == null) {

Reply via email to