搜索

180.5. 使用 JMX 监控 Camel

download PDF

180.5.1. 使用 JConsole 监控 Camel

如果您在与 Camel 相同的主机上运行 JConsole,则 CamelContext 应该出现在本地连接列表中。

要连接到远程 Camel 实例,或者本地进程未显示,请使用 Remote Process 选项,并输入 URL。以下是 localhost URL:service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi/camel 示例。

使用带有 JConsole 的 Apache Camel:

image

180.5.2. 注册哪些端点

Camel 2.1 中,只有 单例 端点注册为非单例的开销将在使用数千或数百万端点的情况下大量注册。当使用 Recipient List EIP 或发送大量消息的 ProducerTemplate 时,会出现这种情况。

180.5.3. 哪些处理器被注册

请查看此常见问题。

180.5.4. 如何使用 JMX NotificationListener 侦听 camel 事件?

Camel 通知事件给出粗略概述发生的情况。您可以查看上下文和端点的生命周期事件,您可以看到由端点接收的交换并发送到端点。

Camel 2.4 中,您可以使用自定义 JMX NotificationListener 侦听 camel 事件。

首先,您需要在启动 CamelContext 前设置 JmxNotificationEventNotifier

// Set up the JmxNotificationEventNotifier
notifier = new JmxNotificationEventNotifier();
notifier.setSource("MyCamel");
notifier.setIgnoreCamelContextEvents(true);
notifier.setIgnoreRouteEvents(true);
notifier.setIgnoreServiceEvents(true);

CamelContext context = new DefaultCamelContext(createRegistry());
context.getManagementStrategy().addEventNotifier(notifier);

其次,您可以注册侦听事件的监听程序:

// register the NotificationListener
ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=eventnotifiers,name=JmxEventNotifier");
MyNotificationListener listener = new MyNotificationListener();
context.getManagementStrategy().getManagementAgent().getMBeanServer().addNotificationListener(on,
    listener,
    new NotificationFilter() {
        private static final long serialVersionUID = 1L;

        public boolean isNotificationEnabled(Notification notification) {
            return notification.getSource().equals("MyCamel");
        }
    }, null);

180.5.5. 使用 Tracer MBean 获取精细的追踪

除了 Camel 2.9.0 以上的粗粒度通知外,还支持 JMX 通知以进行细粒度跟踪事件。

它们可以在 Tracer MBean 中找到。要激活精细的追踪,首先需要在上下文或路由上激活追踪。

这可以在配置上下文或上下文/路由 MBeans 时完成。

作为第二步,您必须在 tracer 上将 jmxTraceNotifications 属性设置为 true。在配置上下文或 tracer MBean 的运行时,可以再次完成此操作。

现在,您可以使用 JConsole 在 Tracer MBean 上注册 TraceEvent 通知。路由上带有所有交换和消息详情的每个步骤都会有一个通知:

image

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

© 2024 Red Hat, Inc.