Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
order-group
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
order-group-application
order-group
Commits
ea1150be
Commit
ea1150be
authored
Jun 21, 2021
by
bing.liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加基础组件监控mq及db连接数
parent
88954d24
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
140 additions
and
0 deletions
+140
-0
order-application-service/src/main/java/cn/freemud/OrderApplication.java
+2
-0
order-application-service/src/main/java/cn/freemud/service/job/PrometheusSchedulerCustomJob.java
+68
-0
shopping-cart-application-service/src/main/java/cn/freemud/ShoppingCartApplication.java
+2
-0
shopping-cart-application-service/src/main/java/cn/freemud/service/job/PrometheusSchedulerCustomJob.java
+68
-0
No files found.
order-application-service/src/main/java/cn/freemud/OrderApplication.java
View file @
ea1150be
...
...
@@ -35,6 +35,7 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
import
tk.mybatis.spring.annotation.MapperScan
;
...
...
@@ -58,6 +59,7 @@ import java.util.concurrent.ThreadPoolExecutor;
"cn.freemud.fuyou"
})
@EnableAutoConfiguration
@EnableScheduling
public
class
OrderApplication
{
private
static
final
String
GRAY_VERSION_PROD
=
"PROD"
;
//生产版本
...
...
order-application-service/src/main/java/cn/freemud/service/job/PrometheusSchedulerCustomJob.java
0 → 100644
View file @
ea1150be
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
());
}
}
shopping-cart-application-service/src/main/java/cn/freemud/ShoppingCartApplication.java
View file @
ea1150be
...
...
@@ -31,6 +31,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.EnableAspectJAutoProxy
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
import
tk.mybatis.spring.annotation.MapperScan
;
...
...
@@ -48,6 +49,7 @@ import tk.mybatis.spring.annotation.MapperScan;
"com.freemud.api.assortment.datamanager.manager"
})
@EnableFeignClients
@EnableAsync
@EnableScheduling
public
class
ShoppingCartApplication
{
private
static
final
String
GRAY_VERSION_PROD
=
"PROD"
;
//生产版本
private
static
final
String
GRAY_VERSION_GRAY
=
"GRAY"
;
//灰度版本
...
...
shopping-cart-application-service/src/main/java/cn/freemud/service/job/PrometheusSchedulerCustomJob.java
0 → 100644
View file @
ea1150be
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
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment