218.12. MetricsMessageHistoryFactory


可从 Camel 2.17 开始

此工厂允许使用指标在路由消息期间捕获消息历史性能统计数据。它的工作原理是在所有路由中的每个节点使用指标计时器。 此工厂可以在 Java 和 XML 中使用,作为以下示例。 

从 Java 中,您要将工厂设置为 CamelContext ,如下所示:

context.setMessageHistoryFactory(new MetricsMessageHistoryFactory());
Copy to Clipboard Toggle word wrap

在 XML DSL 中,您将定义 <bean>,如下所示:

  <!-- use camel-metrics message history to gather metrics for all messages being routed -->
  <bean id="metricsMessageHistoryFactory" class="org.apache.camel.component.metrics.messagehistory.MetricsMessageHistoryFactory"/>
Copy to Clipboard Toggle word wrap

因工厂支持以下选项:

Expand
名称default描述

useJmx

false

是否使用 com.codahale.metrics.JmxReporter 向 JMX 报告精细统计。
请注意,如果在 CamelContext 上启用了 JMX,则会在 JMX 树中的服务类型下列出 MetricsRegistryService mbean。该 mbean 有一个操作来通过 json 输出统计信息。只有在每个统计类型需要精细的 mbeans 时,才需要将 useJmx 设置为 true。

jmxDomain

org.apache.camel.metrics

JMX 域名

prettyPrint

false

是否在以 json 格式输出统计信息时打印情况

metricsRegistry

 

allow 使用共享的 com.codahale.metrics.MetricRegistry。如果没有提供,Camel 将创建此 CamelContext 使用的共享实例。

rateUnit

TimeUnit.SECONDS

指标报告者中用于速率的单位,或者将统计信息转储到 json。

durationUnit

TimeUnit.MILLISECONDS

指标报告程序中的 for 持续时间或者将统计信息转储到 json 时使用的单位。

namePattern

名称.routeId.id.type

要使用的名称模式。使用点作为分隔符,但您可以修改。值 名称routeIdtypeid 和 id 将替换为实际值。其中 name 是 CamelContext 的名称。routeId 是路由的名称。id 模式表示节点 ID。type 是 history 的值。

在运行时,指标可以从 Java API 或 JMX 访问,后者可以将数据作为 json 输出来收集。

从 Java 代码中,您可以从 CamelContext 获取服务,如下所示:

MetricsMessageHistoryService service = context.hasService(MetricsMessageHistoryService.class);
String json = service.dumpStatisticsAsJson();
Copy to Clipboard Toggle word wrap

而 JMX API,MBean 在 type=services 树中注册, 名称为=MetricsMessageHistoryService

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat