Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
commons
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DevOps
commons
Commits
ded01291
Commit
ded01291
authored
Apr 08, 2022
by
王亮
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit init version.
parent
f749a398
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
35 deletions
+16
-35
KafkaMeterRegistry.java
...oup/ext/micrometer/register/kafka/KafkaMeterRegistry.java
+1
-33
MicroMeterKafkaAutoConfiguration.java
...eter/register/kafka/MicroMeterKafkaAutoConfiguration.java
+15
-2
No files found.
qg-micrometer-register-kafka-starter/src/main/java/cn/quantgroup/ext/micrometer/register/kafka/KafkaMeterRegistry.java
View file @
ded01291
...
...
@@ -34,9 +34,6 @@ public class KafkaMeterRegistry extends StepMeterRegistry {
private
KafkaProducer
<
String
,
String
>
kafkaProducer
;
private
final
String
key
;
private
final
List
<
Tag
>
tags
=
new
ArrayList
<>();
public
KafkaMeterRegistry
(
KafkaConfig
config
,
Clock
clock
)
{
super
(
config
,
clock
);
...
...
@@ -47,31 +44,6 @@ public class KafkaMeterRegistry extends StepMeterRegistry {
key
=
System
.
getProperty
(
"NAMESPACE"
);
}
tags
.
add
(
new
Tag
()
{
@Override
public
String
getKey
()
{
return
"namespace"
;
}
@Override
public
String
getValue
()
{
return
key
;
}
});
tags
.
add
(
new
Tag
()
{
@Override
public
String
getKey
()
{
return
"application"
;
}
@Override
public
String
getValue
()
{
return
config
.
applicationName
();
}
});
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
ProducerConfig
.
BOOTSTRAP_SERVERS_CONFIG
,
config
.
services
());
properties
.
setProperty
(
ProducerConfig
.
KEY_SERIALIZER_CLASS_CONFIG
,
...
...
@@ -92,11 +64,7 @@ public class KafkaMeterRegistry extends StepMeterRegistry {
protected
void
publish
()
{
for
(
List
<
Meter
>
batch
:
MeterPartition
.
partition
(
this
,
config
.
batchSize
()))
{
batch
.
stream
().
map
(
i
->
{
getConventionTags
(
i
.
getId
()).
addAll
(
tags
);
return
i
;
})
batch
.
stream
()
.
flatMap
(
m
->
m
.
match
(
gauge
->
writeGauge
(
gauge
.
getId
(),
gauge
.
value
()),
counter
->
writeCounter
(
counter
.
getId
(),
counter
.
count
()),
...
...
qg-micrometer-register-kafka-starter/src/main/java/cn/quantgroup/ext/micrometer/register/kafka/MicroMeterKafkaAutoConfiguration.java
View file @
ded01291
package
cn
.
quantgroup
.
ext
.
micrometer
.
register
.
kafka
;
import
io.micrometer.core.instrument.Clock
;
import
io.micrometer.core.instrument.Tag
;
import
java.util.Arrays
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
...
...
@@ -8,6 +10,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.util.ObjectUtils
;
@Configuration
@ComponentScan
(
basePackageClasses
=
KafkaMeterRegistry
.
class
)
...
...
@@ -20,7 +23,7 @@ public class MicroMeterKafkaAutoConfiguration {
public
MicroMeterKafkaAutoConfiguration
(
EnochAgentProperties
enochAgentProperties
)
{
this
.
enochAgentProperties
=
enochAgentProperties
;
this
.
enochAgentProperties
=
enochAgentProperties
;
}
@Bean
...
...
@@ -49,6 +52,16 @@ public class MicroMeterKafkaAutoConfiguration {
@Bean
public
KafkaMeterRegistry
kafkaMeterRegistry
(
KafkaConfig
kafkaConfig
)
{
return
new
KafkaMeterRegistry
(
kafkaConfig
,
Clock
.
SYSTEM
);
//运行环境env,由于现有项目错误使用NAMESPACE,所以为了维持兼容采用这个参数
String
env
;
if
(
ObjectUtils
.
isEmpty
(
System
.
getProperty
(
"NAMESPACE"
)))
{
env
=
"default"
;
}
else
{
env
=
System
.
getProperty
(
"NAMESPACE"
);
}
KafkaMeterRegistry
kafkaMeterRegistry
=
new
KafkaMeterRegistry
(
kafkaConfig
,
Clock
.
SYSTEM
);
kafkaMeterRegistry
.
config
().
commonTags
(
Arrays
.
asList
(
Tag
.
of
(
"env"
,
env
),
Tag
.
of
(
"application"
,
kafkaConfig
.
applicationName
())));
return
kafkaMeterRegistry
;
}
}
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