简体   繁体   中英

Expose spring integration amqp/jms channel messages metrics to prometheus

I am trying to enable metrics to feed message statistics from a spring-integration RabbitMq <=> MqSeries gateway into Prometheus.

The documentation states that the channel must extends AbstractMessageChannel in order the metrics to apply. Since I am quite uncomfortable with namespaces , I am not sure if this is the case here.
Also, I don't understand how to add a MeterRegistryBean (and which one.) in order to trigger the metrics on.
And eventually, I don't understand how to use it. Basically, since I am new to most of the framework implied here, the documentation here lacks an example that could help me understand it a little better.

Here's how I do my channel definition:

    <!--    *** MQseries  ***       -->
    <!-- ========================== -->
    
    <bean id="jmsConnectionFactory" class="com.ibm.mq.jms.MQConnectionFactory" >
          <property...>
    </bean>
    
    <bean id="jmsConnectionFactory_cred"
        class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
        <property name="targetConnectionFactory" ref="jmsConnectionFactory" />
        <property...>
    </bean> 

    <bean id="connectionFactoryCaching" class="org.springframework.jms.connection.CachingConnectionFactory">
          <property name="targetConnectionFactory" ref="jmsConnectionFactory_cred" />
          <property...>
    </bean> 
    
    <bean id="jmsQueue" class="com.ibm.mq.jms.MQQueue" depends-on="jmsConnectionFactory">
          <property...>
    </bean>
    
    <bean id="fixedBackOff" class="org.springframework.util.backoff.FixedBackOff">
          <property...>
    </bean>
    
    
    <bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer" >
        <property...>
        <property name="connectionFactory" ref="connectionFactoryCaching" />
        <property name="destination" ref="jmsQueue" />
    </bean>
    
    <int-jms:message-driven-channel-adapter id="jmsIn" container="myListener" channel="channelMQ_RMQ" error-channel="processChannel1"/>

    <!--    *** Rabbit  ***     -->
    <!-- ====================== -->

    <bean id="connectionAmqpFactoryDest" class="com.rabbitmq.client.ConnectionFactory">
          <property...>
    </bean>

    <!-- Attribute : addresses = List of addresses; e.g. host1,host2:4567,host3 - overrides host/port if supplied. -->
    <rabbit:connection-factory id="rabbitConnectionFactory" 
            connection-factory="connectionAmqpFactoryDest"
            addresses="..." ... />

    <bean id="simpleMessageConverter" class="org.springframework.amqp.support.converter.SimpleMessageConverter">
          <property...>
    </bean>     
    <rabbit:template    id="rabbitTemplate" 
                        connection-factory="rabbitConnectionFactory"  
                        mandatory="true" 
                        channel-transacted="true" 
                        message-converter="simpleMessageConverter"/>

    <int-amqp:outbound-channel-adapter  channel="channelMQ_RMQ" 
                                        ...
                                        amqp-template="rabbitTemplate" />
    

Any idea on how I can do that?

Spring Integration metrics (as well as Spring JMS and Spring AMQP) are fully based on the Micrometer implementation: https://docs.spring.io/spring-integration/docs/current/reference/html/system-management.html#micrometer-integration . That all is good if you use some of the latest, supported Spring Integration version: https://spring.io/projects/spring-integration#learn .

If you don't use Spring Boot, then you need to declare a MeterRegistry bean in the application context. And probably the one exactly for Prometheus: https://micrometer.io/docs/registry/prometheus .

If you are new to the framework, consider to move away from the XML configuration in favor of Java DSL: https://docs.spring.io/spring-integration/docs/current/reference/html/dsl.html#java-dsl .

Also make yourself familiar with Spring Boot which really auto-configurs for us many things, even a MeterRegistry for Prometheus: https://spring.io/projects/spring-boot

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM