Commit ea1150be by bing.liu

添加基础组件监控mq及db连接数

parent 88954d24
...@@ -35,6 +35,7 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy; ...@@ -35,6 +35,7 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import springfox.documentation.swagger2.annotations.EnableSwagger2;
import tk.mybatis.spring.annotation.MapperScan; import tk.mybatis.spring.annotation.MapperScan;
...@@ -58,6 +59,7 @@ import java.util.concurrent.ThreadPoolExecutor; ...@@ -58,6 +59,7 @@ import java.util.concurrent.ThreadPoolExecutor;
"cn.freemud.fuyou" "cn.freemud.fuyou"
}) })
@EnableAutoConfiguration @EnableAutoConfiguration
@EnableScheduling
public class OrderApplication { public class OrderApplication {
private static final String GRAY_VERSION_PROD = "PROD"; //生产版本 private static final String GRAY_VERSION_PROD = "PROD"; //生产版本
......
package cn.freemud.service.job;
import com.alibaba.druid.pool.DruidDataSource;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author: liubing.
* @date: 2021/6/15 15:37
*/
@Component
public class PrometheusSchedulerCustomJob {
/**
* mq当前空闲(缓存)的事务通道的数量。
* mq当前空闲(高速缓存)的非事务性通道的数量。
* mq同时空闲(缓存)的事务通道的最大数量。
* mq非事务性通道的最大数量同时处于空闲状态(缓存)。
*/
private final AtomicInteger idleChannelsNotTxGauge, idleChannelsTxGauge, idleChannelsTxHighWaterGauge, idleChannelsNotTxHighWaterGauge;
/**
* 当前连接数
* 最大连接池数量
* 最大连接池数量
* 最小连接池数量
*/
private final AtomicInteger activeCountGauge, maxActiveGauge, maxIdleGauge, minIdleGauge;
private final CachingConnectionFactory cachingConnectionFactory;
private final DruidDataSource druidDataSource;
public PrometheusSchedulerCustomJob(MeterRegistry meterRegistry, CachingConnectionFactory cachingConnectionFactory, DruidDataSource druidDataSource) {
this.cachingConnectionFactory = cachingConnectionFactory;
this.druidDataSource = druidDataSource;
idleChannelsNotTxGauge = meterRegistry.gauge("rabbitmq_idle_channels_not_tx", new AtomicInteger(0));
idleChannelsTxGauge = meterRegistry.gauge("rabbitmq_idle_channels_tx", new AtomicInteger(0));
idleChannelsTxHighWaterGauge = meterRegistry.gauge("rabbitmq_idle_channels_tx_high_water", new AtomicInteger(0));
idleChannelsNotTxHighWaterGauge = meterRegistry.gauge("rabbitmq_idle_channels_not_tx_high_water", new AtomicInteger(0));
activeCountGauge = meterRegistry.gauge("db_active_count", new AtomicInteger(0));
maxActiveGauge = meterRegistry.gauge("db_max_active", new AtomicInteger(0));
maxIdleGauge = meterRegistry.gauge("db_max_idle", new AtomicInteger(0));
minIdleGauge = meterRegistry.gauge("db_min_idle", new AtomicInteger(0));
}
@Scheduled(fixedRateString = "15000", initialDelayString = "0")
public void schedulingTask() {
Properties cacheProperties = cachingConnectionFactory.getCacheProperties();
idleChannelsNotTxGauge.set(Integer.parseInt(cacheProperties.getOrDefault("idleChannelsNotTx", 0).toString()));
idleChannelsTxGauge.set(Integer.parseInt(cacheProperties.getOrDefault("idleChannelsTx", 0).toString()));
idleChannelsTxHighWaterGauge.set(Integer.parseInt(cacheProperties.getOrDefault("idleChannelsTxHighWater", 0).toString()));
idleChannelsNotTxHighWaterGauge.set(Integer.parseInt(cacheProperties.getOrDefault("idleChannelsNotTxHighWater", 0).toString()));
activeCountGauge.set(druidDataSource.getActiveCount());
maxActiveGauge.set(druidDataSource.getMaxActive());
maxIdleGauge.set(druidDataSource.getMaxIdle());
minIdleGauge.set(druidDataSource.getMinIdle());
}
}
...@@ -31,6 +31,7 @@ import org.springframework.context.annotation.Bean; ...@@ -31,6 +31,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import springfox.documentation.swagger2.annotations.EnableSwagger2;
import tk.mybatis.spring.annotation.MapperScan; import tk.mybatis.spring.annotation.MapperScan;
...@@ -48,6 +49,7 @@ import tk.mybatis.spring.annotation.MapperScan; ...@@ -48,6 +49,7 @@ import tk.mybatis.spring.annotation.MapperScan;
"com.freemud.api.assortment.datamanager.manager"}) "com.freemud.api.assortment.datamanager.manager"})
@EnableFeignClients @EnableFeignClients
@EnableAsync @EnableAsync
@EnableScheduling
public class ShoppingCartApplication { public class ShoppingCartApplication {
private static final String GRAY_VERSION_PROD = "PROD"; //生产版本 private static final String GRAY_VERSION_PROD = "PROD"; //生产版本
private static final String GRAY_VERSION_GRAY = "GRAY"; //灰度版本 private static final String GRAY_VERSION_GRAY = "GRAY"; //灰度版本
......
package cn.freemud.service.job;
import com.alibaba.druid.pool.DruidDataSource;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author: liubing.
* @date: 2021/6/15 15:37
*/
@Component
public class PrometheusSchedulerCustomJob {
/**
* mq当前空闲(缓存)的事务通道的数量。
* mq当前空闲(高速缓存)的非事务性通道的数量。
* mq同时空闲(缓存)的事务通道的最大数量。
* mq非事务性通道的最大数量同时处于空闲状态(缓存)。
*/
private final AtomicInteger idleChannelsNotTxGauge, idleChannelsTxGauge, idleChannelsTxHighWaterGauge, idleChannelsNotTxHighWaterGauge;
/**
* 当前连接数
* 最大连接池数量
* 最大连接池数量
* 最小连接池数量
*/
private final AtomicInteger activeCountGauge, maxActiveGauge, maxIdleGauge, minIdleGauge;
private final CachingConnectionFactory cachingConnectionFactory;
private final DruidDataSource druidDataSource;
public PrometheusSchedulerCustomJob(MeterRegistry meterRegistry, CachingConnectionFactory cachingConnectionFactory, DruidDataSource druidDataSource) {
this.cachingConnectionFactory = cachingConnectionFactory;
this.druidDataSource = druidDataSource;
idleChannelsNotTxGauge = meterRegistry.gauge("rabbitmq_idle_channels_not_tx", new AtomicInteger(0));
idleChannelsTxGauge = meterRegistry.gauge("rabbitmq_idle_channels_tx", new AtomicInteger(0));
idleChannelsTxHighWaterGauge = meterRegistry.gauge("rabbitmq_idle_channels_tx_high_water", new AtomicInteger(0));
idleChannelsNotTxHighWaterGauge = meterRegistry.gauge("rabbitmq_idle_channels_not_tx_high_water", new AtomicInteger(0));
activeCountGauge = meterRegistry.gauge("db_active_count", new AtomicInteger(0));
maxActiveGauge = meterRegistry.gauge("db_max_active", new AtomicInteger(0));
maxIdleGauge = meterRegistry.gauge("db_max_idle", new AtomicInteger(0));
minIdleGauge = meterRegistry.gauge("db_min_idle", new AtomicInteger(0));
}
@Scheduled(fixedRateString = "15000", initialDelayString = "0")
public void schedulingTask() {
Properties cacheProperties = cachingConnectionFactory.getCacheProperties();
idleChannelsNotTxGauge.set(Integer.parseInt(cacheProperties.getOrDefault("idleChannelsNotTx", 0).toString()));
idleChannelsTxGauge.set(Integer.parseInt(cacheProperties.getOrDefault("idleChannelsTx", 0).toString()));
idleChannelsTxHighWaterGauge.set(Integer.parseInt(cacheProperties.getOrDefault("idleChannelsTxHighWater", 0).toString()));
idleChannelsNotTxHighWaterGauge.set(Integer.parseInt(cacheProperties.getOrDefault("idleChannelsNotTxHighWater", 0).toString()));
activeCountGauge.set(druidDataSource.getActiveCount());
maxActiveGauge.set(druidDataSource.getMaxActive());
maxIdleGauge.set(druidDataSource.getMaxIdle());
minIdleGauge.set(druidDataSource.getMinIdle());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment