Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
40e57c04
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
40e57c04
编写于
4月 29, 2020
作者:
X
xiaoyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
build base framework for metrics
上级
d0d7648b
变更
32
隐藏空白更改
内联
并排
Showing
32 changed file
with
1416 addition
and
8 deletion
+1416
-8
sharding-metrics/pom.xml
sharding-metrics/pom.xml
+6
-8
sharding-metrics/sharding-metrics-facade/pom.xml
sharding-metrics/sharding-metrics-facade/pom.xml
+42
-0
sharding-metrics/sharding-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacade.java
...e/shardingsphere/metrics/facade/MetricsTrackerFacade.java
+183
-0
sharding-metrics/sharding-metrics-facade/src/test/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacadeTest.java
...ardingsphere/metrics/facade/MetricsTrackerFacadeTest.java
+34
-0
sharding-metrics/sharding-metrics-facade/src/test/java/org/apache/shardingsphere/metrics/facade/fixture/MetricsTrackerManagerFixture.java
.../metrics/facade/fixture/MetricsTrackerManagerFixture.java
+51
-0
sharding-metrics/sharding-metrics-facade/src/test/resources/META-INF/services/org.apache.shardingsphere.metrics.spi.MetricsTrackerManager
...g.apache.shardingsphere.metrics.spi.MetricsTrackerManager
+18
-0
sharding-metrics/sharding-metrics-prometheus/pom.xml
sharding-metrics/sharding-metrics-prometheus/pom.xml
+58
-0
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/PrometheusMetricsTrackerFactory.java
...e/metrics/prometheus/PrometheusMetricsTrackerFactory.java
+51
-0
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/PrometheusMetricsTrackerManager.java
...e/metrics/prometheus/PrometheusMetricsTrackerManager.java
+54
-0
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/counter/RequestTotalCounterMetricsTracker.java
...theus/impl/counter/RequestTotalCounterMetricsTracker.java
+44
-0
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/counter/SQLStatementCounterMetricsTracker.java
...theus/impl/counter/SQLStatementCounterMetricsTracker.java
+45
-0
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/gauge/ChannelCountGaugeMetricsTracker.java
...rometheus/impl/gauge/ChannelCountGaugeMetricsTracker.java
+45
-0
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/histogram/PrometheusHistogramMetricsTrackerDelegate.java
.../histogram/PrometheusHistogramMetricsTrackerDelegate.java
+36
-0
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/histogram/RequestLatencyHistogramMetricsTracker.java
...impl/histogram/RequestLatencyHistogramMetricsTracker.java
+45
-0
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/summary/PrometheusSummaryMetricsTrackerDelegate.java
...impl/summary/PrometheusSummaryMetricsTrackerDelegate.java
+36
-0
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/summary/RequestLatencySummaryMetricsTracker.java
...eus/impl/summary/RequestLatencySummaryMetricsTracker.java
+51
-0
sharding-metrics/sharding-metrics-prometheus/src/main/resources/META-INF/services/org.apache.shardingsphere.metrics.spi.MetricsTrackerManager
...g.apache.shardingsphere.metrics.spi.MetricsTrackerManager
+18
-0
sharding-metrics/sharding-metrics-prometheus/src/test/java/org/apache/shardingsphere/metrics/prometheus/PrometheusMetricsTrackerFactoryTest.java
...trics/prometheus/PrometheusMetricsTrackerFactoryTest.java
+39
-0
sharding-metrics/sharding-metrics-spi/pom.xml
sharding-metrics/sharding-metrics-spi/pom.xml
+40
-0
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/CounterMetricsTracker.java
...che/shardingsphere/metrics/api/CounterMetricsTracker.java
+43
-0
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/GaugeMetricsTracker.java
...pache/shardingsphere/metrics/api/GaugeMetricsTracker.java
+51
-0
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/HistogramMetricsTracker.java
...e/shardingsphere/metrics/api/HistogramMetricsTracker.java
+54
-0
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/HistogramMetricsTrackerDelegate.java
...ngsphere/metrics/api/HistogramMetricsTrackerDelegate.java
+31
-0
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/MetricsTracker.java
...org/apache/shardingsphere/metrics/api/MetricsTracker.java
+38
-0
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/MetricsTrackerFactory.java
...che/shardingsphere/metrics/api/MetricsTrackerFactory.java
+35
-0
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/NoneHistogramMetricsTrackerDelegate.java
...here/metrics/api/NoneHistogramMetricsTrackerDelegate.java
+21
-0
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/NoneSummaryMetricsTrackerDelegate.java
...sphere/metrics/api/NoneSummaryMetricsTrackerDelegate.java
+24
-0
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/SummaryMetricsTracker.java
...che/shardingsphere/metrics/api/SummaryMetricsTracker.java
+54
-0
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/SummaryMetricsTrackerDelegate.java
...dingsphere/metrics/api/SummaryMetricsTrackerDelegate.java
+31
-0
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/enums/MetricsLabelEnum.java
...apache/shardingsphere/metrics/enums/MetricsLabelEnum.java
+53
-0
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/enums/MetricsTypeEnum.java
.../apache/shardingsphere/metrics/enums/MetricsTypeEnum.java
+44
-0
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/spi/MetricsTrackerManager.java
...che/shardingsphere/metrics/spi/MetricsTrackerManager.java
+41
-0
未找到文件。
sharding-metrics/pom.xml
浏览文件 @
40e57c04
...
...
@@ -18,6 +18,12 @@
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<packaging>
pom
</packaging>
<modules>
<module>
sharding-metrics-spi
</module>
<module>
sharding-metrics-facade
</module>
<module>
sharding-metrics-prometheus
</module>
</modules>
<parent>
<groupId>
org.apache.shardingsphere
</groupId>
<artifactId>
shardingsphere
</artifactId>
...
...
@@ -25,12 +31,4 @@
</parent>
<artifactId>
sharding-metrics
</artifactId>
<name>
${project.artifactId}
</name>
<dependencies>
<dependency>
<groupId>
org.apache.shardingsphere
</groupId>
<artifactId>
shardingsphere-executor
</artifactId>
<version>
${project.version}
</version>
</dependency>
</dependencies>
</project>
sharding-metrics/sharding-metrics-facade/pom.xml
0 → 100644
浏览文件 @
40e57c04
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
sharding-metrics
</artifactId>
<groupId>
org.apache.shardingsphere
</groupId>
<version>
5.0.0-RC1-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
sharding-metrics-facade
</artifactId>
<dependencies>
<dependency>
<groupId>
org.apache.shardingsphere
</groupId>
<artifactId>
sharding-metrics-spi
</artifactId>
<version>
${project.version}
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
sharding-metrics/sharding-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacade.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.facade
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.shardingsphere.metrics.api.CounterMetricsTracker
;
import
org.apache.shardingsphere.metrics.api.GaugeMetricsTracker
;
import
org.apache.shardingsphere.metrics.api.HistogramMetricsTracker
;
import
org.apache.shardingsphere.metrics.api.HistogramMetricsTrackerDelegate
;
import
org.apache.shardingsphere.metrics.api.MetricsTracker
;
import
org.apache.shardingsphere.metrics.api.NoneHistogramMetricsTrackerDelegate
;
import
org.apache.shardingsphere.metrics.api.NoneSummaryMetricsTrackerDelegate
;
import
org.apache.shardingsphere.metrics.api.SummaryMetricsTracker
;
import
org.apache.shardingsphere.metrics.api.SummaryMetricsTrackerDelegate
;
import
org.apache.shardingsphere.metrics.enums.MetricsTypeEnum
;
import
org.apache.shardingsphere.metrics.spi.MetricsTrackerManager
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.ServiceLoader
;
import
java.util.concurrent.atomic.AtomicBoolean
;
/**
* Metrics tracker facade.
*/
@Slf4j
public
final
class
MetricsTrackerFacade
{
private
static
final
Map
<
String
,
MetricsTrackerManager
>
METRICS_MAP
=
new
HashMap
<>();
private
static
final
MetricsTrackerFacade
INSTANCE
=
new
MetricsTrackerFacade
();
private
volatile
AtomicBoolean
isInit
=
new
AtomicBoolean
(
false
);
private
Optional
<
MetricsTrackerManager
>
metricsTrackerManager
=
Optional
.
empty
();
private
MetricsTrackerFacade
()
{
loadMetricsManager
();
}
/**
* Get metrics tracker facade.
*
* @return metrics tracker facade
*/
public
static
MetricsTrackerFacade
getInstance
()
{
return
INSTANCE
;
}
/**
* Find metrics tracker manager.
*
* @param metricsName metrics name
* @return metrics tracker manager
*/
public
Optional
<
MetricsTrackerManager
>
findMetricsTrackerManager
(
final
String
metricsName
)
{
return
Optional
.
ofNullable
(
METRICS_MAP
.
get
(
metricsName
));
}
/**
* Init for metrics tracker manager.
*
* @param metricsName metrics name
* @param port port
*/
public
void
init
(
final
String
metricsName
,
final
int
port
)
{
if
(!
isInit
.
compareAndSet
(
false
,
true
))
{
return
;
}
metricsTrackerManager
=
findMetricsTrackerManager
(
metricsName
);
metricsTrackerManager
.
ifPresent
(
manager
->
manager
.
init
(
port
));
}
/**
* Inc of counter metrics tracker.
*
* @param metricsLabel metrics label
* @param labelValues label values
*/
public
void
counterInc
(
final
String
metricsLabel
,
final
String
...
labelValues
)
{
metricsTrackerManager
.
flatMap
(
manager
->
manager
.
getMetricsTrackerFactory
().
create
(
MetricsTypeEnum
.
COUNTER
.
name
(),
metricsLabel
))
.
ifPresent
(
metricsTracker
->
((
CounterMetricsTracker
)
metricsTracker
).
inc
(
1.0
,
labelValues
));
}
/**
* Inc of gauge metrics tracker.
*
* @param metricsLabel metrics label
* @param labelValues label values
*/
public
void
gaugeInc
(
final
String
metricsLabel
,
final
String
...
labelValues
)
{
metricsTrackerManager
.
flatMap
(
manager
->
manager
.
getMetricsTrackerFactory
().
create
(
MetricsTypeEnum
.
GAUGE
.
name
(),
metricsLabel
))
.
ifPresent
(
metricsTracker
->
((
GaugeMetricsTracker
)
metricsTracker
).
inc
(
1.0
,
labelValues
));
}
/**
* Dec of gauge metrics tracker.
*
* @param metricsLabel metrics label
* @param labelValues label values
*/
public
void
gaugeDec
(
final
String
metricsLabel
,
final
String
...
labelValues
)
{
metricsTrackerManager
.
flatMap
(
manager
->
manager
.
getMetricsTrackerFactory
().
create
(
MetricsTypeEnum
.
GAUGE
.
name
(),
metricsLabel
))
.
ifPresent
(
metricsTracker
->
((
GaugeMetricsTracker
)
metricsTracker
).
dec
(
1.0
,
labelValues
));
}
/**
* Start timer of histogram metrics tracker.
*
* @param metricsLabel metrics label
* @param labelValues label values
* @return histogram metrics tracker delegate
*/
public
HistogramMetricsTrackerDelegate
histogramStartTimer
(
final
String
metricsLabel
,
final
String
...
labelValues
)
{
Optional
<
MetricsTracker
>
metricsTracker
=
metricsTrackerManager
.
flatMap
(
manager
->
manager
.
getMetricsTrackerFactory
().
create
(
MetricsTypeEnum
.
HISTOGRAM
.
name
(),
metricsLabel
));
if
(
metricsTracker
.
isPresent
())
{
return
((
HistogramMetricsTracker
)
metricsTracker
.
get
()).
startTimer
(
labelValues
);
}
else
{
return
new
NoneHistogramMetricsTrackerDelegate
();
}
}
/**
* Observe amount of time since start time with histogram metrics tracker.
*
* @param delegate histogram metrics tracker delegate
*/
public
void
histogramObserveDuration
(
final
HistogramMetricsTrackerDelegate
delegate
)
{
delegate
.
observeDuration
();
}
/**
* Start timer of summary metrics tracker.
*
* @param metricsLabel metrics label
* @param labelValues label values
* @return summary metrics tracker delegate
*/
public
SummaryMetricsTrackerDelegate
summaryStartTimer
(
final
String
metricsLabel
,
final
String
...
labelValues
)
{
Optional
<
MetricsTracker
>
metricsTracker
=
metricsTrackerManager
.
flatMap
(
manager
->
manager
.
getMetricsTrackerFactory
().
create
(
MetricsTypeEnum
.
SUMMARY
.
name
(),
metricsLabel
));
if
(
metricsTracker
.
isPresent
())
{
return
((
SummaryMetricsTracker
)
metricsTracker
.
get
()).
startTimer
(
labelValues
);
}
else
{
return
new
NoneSummaryMetricsTrackerDelegate
();
}
}
/**
* Observe amount of time since start time with summary metrics tracker.
*
* @param delegate summary metrics tracker delegate
*/
public
void
summaryObserveDuration
(
final
SummaryMetricsTrackerDelegate
delegate
)
{
delegate
.
observeDuration
();
}
private
void
loadMetricsManager
()
{
for
(
MetricsTrackerManager
each
:
ServiceLoader
.
load
(
MetricsTrackerManager
.
class
))
{
if
(
METRICS_MAP
.
containsKey
(
each
.
getType
()))
{
log
.
warn
(
"Find more than one {} metricsTracker manager implementation class, use `{}` now"
,
each
.
getType
(),
METRICS_MAP
.
get
(
each
.
getType
()).
getClass
().
getName
());
continue
;
}
METRICS_MAP
.
put
(
each
.
getType
(),
each
);
}
}
}
sharding-metrics/sharding-metrics-facade/src/test/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacadeTest.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.facade
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
final
class
MetricsTrackerFacadeTest
{
private
MetricsTrackerFacade
metricsTrackerFacade
=
MetricsTrackerFacade
.
getInstance
();
@Test
public
void
assertFindMetricsTrackerManager
()
{
assertThat
(
metricsTrackerFacade
.
findMetricsTrackerManager
(
"fixture1"
).
isPresent
(),
is
(
false
));
assertThat
(
metricsTrackerFacade
.
findMetricsTrackerManager
(
"fixture"
).
isPresent
(),
is
(
true
));
}
}
sharding-metrics/sharding-metrics-facade/src/test/java/org/apache/shardingsphere/metrics/facade/fixture/MetricsTrackerManagerFixture.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.facade.fixture
;
import
org.apache.shardingsphere.metrics.api.MetricsTrackerFactory
;
import
org.apache.shardingsphere.metrics.spi.MetricsTrackerManager
;
import
java.util.Properties
;
public
class
MetricsTrackerManagerFixture
implements
MetricsTrackerManager
{
@Override
public
void
init
(
final
int
port
)
{
}
@Override
public
MetricsTrackerFactory
getMetricsTrackerFactory
()
{
return
null
;
}
@Override
public
String
getType
()
{
return
"fixture"
;
}
@Override
public
Properties
getProperties
()
{
return
null
;
}
@Override
public
void
setProperties
(
final
Properties
properties
)
{
}
}
sharding-metrics/sharding-metrics-facade/src/test/resources/META-INF/services/org.apache.shardingsphere.metrics.spi.MetricsTrackerManager
0 → 100644
浏览文件 @
40e57c04
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
org.apache.shardingsphere.metrics.facade.fixture.MetricsTrackerManagerFixture
sharding-metrics/sharding-metrics-prometheus/pom.xml
0 → 100644
浏览文件 @
40e57c04
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
sharding-metrics
</artifactId>
<groupId>
org.apache.shardingsphere
</groupId>
<version>
5.0.0-RC1-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
sharding-metrics-prometheus
</artifactId>
<dependencies>
<dependency>
<groupId>
org.apache.shardingsphere
</groupId>
<artifactId>
sharding-metrics-spi
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<version>
1.16.20
</version>
</dependency>
<dependency>
<groupId>
io.prometheus
</groupId>
<artifactId>
simpleclient
</artifactId>
<version>
0.6.0
</version>
</dependency>
<dependency>
<groupId>
io.prometheus
</groupId>
<artifactId>
simpleclient_httpserver
</artifactId>
<version>
0.6.0
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/PrometheusMetricsTrackerFactory.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.prometheus
;
import
org.apache.shardingsphere.metrics.api.MetricsTracker
;
import
org.apache.shardingsphere.metrics.api.MetricsTrackerFactory
;
import
org.apache.shardingsphere.metrics.prometheus.impl.counter.RequestTotalCounterMetricsTracker
;
import
org.apache.shardingsphere.metrics.prometheus.impl.counter.SQLStatementCounterMetricsTracker
;
import
org.apache.shardingsphere.metrics.prometheus.impl.gauge.ChannelCountGaugeMetricsTracker
;
import
org.apache.shardingsphere.metrics.prometheus.impl.histogram.RequestLatencyHistogramMetricsTracker
;
import
org.apache.shardingsphere.metrics.prometheus.impl.summary.RequestLatencySummaryMetricsTracker
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Optional
;
/**
* Prometheus metrics tracker factory.
*/
public
class
PrometheusMetricsTrackerFactory
implements
MetricsTrackerFactory
{
private
static
final
Collection
<
MetricsTracker
>
REGISTER
=
new
ArrayList
<>();
static
{
REGISTER
.
add
(
new
RequestTotalCounterMetricsTracker
());
REGISTER
.
add
(
new
SQLStatementCounterMetricsTracker
());
REGISTER
.
add
(
new
ChannelCountGaugeMetricsTracker
());
REGISTER
.
add
(
new
RequestLatencyHistogramMetricsTracker
());
REGISTER
.
add
(
new
RequestLatencySummaryMetricsTracker
());
}
@Override
public
Optional
<
MetricsTracker
>
create
(
final
String
metricsType
,
final
String
metricsLabel
)
{
return
REGISTER
.
stream
().
filter
(
each
->
each
.
metricsLabel
().
equals
(
metricsLabel
)
&&
each
.
metricsType
().
equals
(
metricsType
)).
findFirst
();
}
}
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/PrometheusMetricsTrackerManager.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.prometheus
;
import
io.prometheus.client.CollectorRegistry
;
import
io.prometheus.client.exporter.HTTPServer
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.SneakyThrows
;
import
org.apache.shardingsphere.metrics.api.MetricsTrackerFactory
;
import
org.apache.shardingsphere.metrics.spi.MetricsTrackerManager
;
import
java.net.InetSocketAddress
;
import
java.util.Properties
;
/**
* Prometheus metrics tracker manager.
*/
@Getter
@Setter
public
class
PrometheusMetricsTrackerManager
implements
MetricsTrackerManager
{
private
Properties
properties
=
new
Properties
();
private
MetricsTrackerFactory
metricsTrackerFactory
=
new
PrometheusMetricsTrackerFactory
();
@Override
public
String
getType
()
{
return
"prometheus"
;
}
@SneakyThrows
@Override
public
void
init
(
final
int
port
)
{
new
HTTPServer
(
new
InetSocketAddress
(
port
),
CollectorRegistry
.
defaultRegistry
,
true
);
}
}
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/counter/RequestTotalCounterMetricsTracker.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.prometheus.impl.counter
;
import
io.prometheus.client.Counter
;
import
org.apache.shardingsphere.metrics.api.CounterMetricsTracker
;
import
org.apache.shardingsphere.metrics.enums.MetricsLabelEnum
;
/**
* Request total counter metrics tracker.
*/
public
class
RequestTotalCounterMetricsTracker
implements
CounterMetricsTracker
{
private
static
final
Counter
REQUEST_TOTAL
=
Counter
.
build
()
.
name
(
"request_total"
)
.
help
(
"proxy request total count"
)
.
register
();
@Override
public
void
inc
(
final
double
amount
,
final
String
...
labelValues
)
{
REQUEST_TOTAL
.
inc
(
amount
);
}
@Override
public
String
metricsLabel
()
{
return
MetricsLabelEnum
.
REQUEST_TOTAL
.
getName
();
}
}
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/counter/SQLStatementCounterMetricsTracker.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.prometheus.impl.counter
;
import
io.prometheus.client.Counter
;
import
org.apache.shardingsphere.metrics.api.CounterMetricsTracker
;
import
org.apache.shardingsphere.metrics.enums.MetricsLabelEnum
;
/**
* SQL statement counter metrics tracker.
*/
public
class
SQLStatementCounterMetricsTracker
implements
CounterMetricsTracker
{
private
static
final
Counter
SQL_STATEMENT_COUNT
=
Counter
.
build
()
.
name
(
"sql_statement_count"
)
.
labelNames
(
"sql_type"
)
.
help
(
"proxy sql statement count"
)
.
register
();
@Override
public
void
inc
(
final
double
amount
,
final
String
...
labelValues
)
{
SQL_STATEMENT_COUNT
.
labels
(
labelValues
).
inc
(
amount
);
}
@Override
public
String
metricsLabel
()
{
return
MetricsLabelEnum
.
SQL_STATEMENT_COUNT
.
getName
();
}
}
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/gauge/ChannelCountGaugeMetricsTracker.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.prometheus.impl.gauge
;
import
io.prometheus.client.Gauge
;
import
org.apache.shardingsphere.metrics.api.GaugeMetricsTracker
;
import
org.apache.shardingsphere.metrics.enums.MetricsLabelEnum
;
/**
* Channel count gauge metrics tracker.
*/
public
class
ChannelCountGaugeMetricsTracker
implements
GaugeMetricsTracker
{
private
static
final
Gauge
CHANNEL_COUNT
=
Gauge
.
build
().
name
(
"channel_count"
).
help
(
"proxy channel count"
).
register
();
@Override
public
void
inc
(
final
double
amount
,
final
String
...
labelValues
)
{
CHANNEL_COUNT
.
inc
(
amount
);
}
@Override
public
void
dec
(
final
double
amount
,
final
String
...
labelValues
)
{
CHANNEL_COUNT
.
dec
(
amount
);
}
@Override
public
String
metricsLabel
()
{
return
MetricsLabelEnum
.
CHANNEL_COUNT
.
getName
();
}
}
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/histogram/PrometheusHistogramMetricsTrackerDelegate.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.prometheus.impl.histogram
;
import
io.prometheus.client.Histogram
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.shardingsphere.metrics.api.HistogramMetricsTrackerDelegate
;
/**
* Prometheus histogram metrics tracker delegate.
*/
@RequiredArgsConstructor
public
class
PrometheusHistogramMetricsTrackerDelegate
implements
HistogramMetricsTrackerDelegate
{
private
final
Histogram
.
Timer
timer
;
@Override
public
void
observeDuration
()
{
timer
.
observeDuration
();
}
}
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/histogram/RequestLatencyHistogramMetricsTracker.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.prometheus.impl.histogram
;
import
io.prometheus.client.Histogram
;
import
org.apache.shardingsphere.metrics.api.HistogramMetricsTrackerDelegate
;
import
org.apache.shardingsphere.metrics.api.HistogramMetricsTracker
;
import
org.apache.shardingsphere.metrics.enums.MetricsLabelEnum
;
/**
* Request latency histogram metrics tracker.
*/
public
class
RequestLatencyHistogramMetricsTracker
implements
HistogramMetricsTracker
{
private
static
final
Histogram
REQUEST_LATENCY
=
Histogram
.
build
()
.
name
(
"requests_latency_Histogram_millis"
).
help
(
"Requests Latency Histogram Millis (ms)"
)
.
exponentialBuckets
(
1.0
,
2
,
10
)
.
register
();
@Override
public
HistogramMetricsTrackerDelegate
startTimer
(
final
String
...
labelValues
)
{
Histogram
.
Timer
timer
=
REQUEST_LATENCY
.
labels
(
labelValues
).
startTimer
();
return
new
PrometheusHistogramMetricsTrackerDelegate
(
timer
);
}
@Override
public
String
metricsLabel
()
{
return
MetricsLabelEnum
.
REQUEST_LATENCY
.
getName
();
}
}
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/summary/PrometheusSummaryMetricsTrackerDelegate.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.prometheus.impl.summary
;
import
io.prometheus.client.Summary
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.shardingsphere.metrics.api.SummaryMetricsTrackerDelegate
;
/**
* Prometheus summary metrics tracker delegate.
*/
@RequiredArgsConstructor
public
class
PrometheusSummaryMetricsTrackerDelegate
implements
SummaryMetricsTrackerDelegate
{
private
final
Summary
.
Timer
timer
;
@Override
public
void
observeDuration
()
{
timer
.
observeDuration
();
}
}
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/summary/RequestLatencySummaryMetricsTracker.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.prometheus.impl.summary
;
import
io.prometheus.client.Summary
;
import
org.apache.shardingsphere.metrics.api.SummaryMetricsTracker
;
import
org.apache.shardingsphere.metrics.api.SummaryMetricsTrackerDelegate
;
import
org.apache.shardingsphere.metrics.enums.MetricsLabelEnum
;
import
java.util.concurrent.TimeUnit
;
/**
* Request latency summary metrics tracker.
*/
public
class
RequestLatencySummaryMetricsTracker
implements
SummaryMetricsTracker
{
private
static
final
Summary
REQUEST_LATENCY
=
Summary
.
build
()
.
name
(
"requests_latency_summary_millis"
).
help
(
"Requests Latency Summary Millis (ms)"
)
.
quantile
(
0.5
,
0.05
)
.
quantile
(
0.95
,
0.01
)
.
quantile
(
0.99
,
0.001
)
.
maxAgeSeconds
(
TimeUnit
.
MINUTES
.
toSeconds
(
5
))
.
ageBuckets
(
5
)
.
register
();
@Override
public
SummaryMetricsTrackerDelegate
startTimer
(
final
String
...
labelValues
)
{
Summary
.
Timer
timer
=
REQUEST_LATENCY
.
labels
(
labelValues
).
startTimer
();
return
new
PrometheusSummaryMetricsTrackerDelegate
(
timer
);
}
@Override
public
String
metricsLabel
()
{
return
MetricsLabelEnum
.
REQUEST_LATENCY
.
getName
();
}
}
sharding-metrics/sharding-metrics-prometheus/src/main/resources/META-INF/services/org.apache.shardingsphere.metrics.spi.MetricsTrackerManager
0 → 100644
浏览文件 @
40e57c04
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
org.apache.shardingsphere.metrics.prometheus.PrometheusMetricsTrackerManager
sharding-metrics/sharding-metrics-prometheus/src/test/java/org/apache/shardingsphere/metrics/prometheus/PrometheusMetricsTrackerFactoryTest.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.prometheus
;
import
org.apache.shardingsphere.metrics.enums.MetricsLabelEnum
;
import
org.apache.shardingsphere.metrics.enums.MetricsTypeEnum
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
PrometheusMetricsTrackerFactoryTest
{
@Test
public
void
assertCreate
()
{
PrometheusMetricsTrackerFactory
factory
=
new
PrometheusMetricsTrackerFactory
();
assertThat
(
factory
.
create
(
MetricsTypeEnum
.
COUNTER
.
name
(),
MetricsLabelEnum
.
REQUEST_LATENCY
.
getName
()).
isPresent
(),
is
(
false
));
assertThat
(
factory
.
create
(
MetricsTypeEnum
.
COUNTER
.
name
(),
MetricsLabelEnum
.
REQUEST_TOTAL
.
getName
()).
isPresent
(),
is
(
true
));
}
}
sharding-metrics/sharding-metrics-spi/pom.xml
0 → 100644
浏览文件 @
40e57c04
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
sharding-metrics
</artifactId>
<groupId>
org.apache.shardingsphere
</groupId>
<version>
5.0.0-RC1-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
sharding-metrics-spi
</artifactId>
<dependencies>
<dependency>
<groupId>
org.apache.shardingsphere
</groupId>
<artifactId>
shardingsphere-spi
</artifactId>
<version>
${project.version}
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/CounterMetricsTracker.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.api
;
import
org.apache.shardingsphere.metrics.enums.MetricsTypeEnum
;
/**
* Counter metrics tracker interface.
*/
public
interface
CounterMetricsTracker
extends
MetricsTracker
{
/**
* Increment the counter with label values by the given amount.
*
* @param amount amount
* @param labelValues label values
*/
void
inc
(
double
amount
,
String
...
labelValues
);
/**
* Metrics type.
*
* @return metrics type
*/
default
String
metricsType
()
{
return
MetricsTypeEnum
.
COUNTER
.
name
();
}
}
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/GaugeMetricsTracker.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.api
;
import
org.apache.shardingsphere.metrics.enums.MetricsTypeEnum
;
/**
* Gauge metrics tracker interface.
*/
public
interface
GaugeMetricsTracker
extends
MetricsTracker
{
/**
* Increment the Gauge with label values by the given amount.
*
* @param amount amount
* @param labelValues label values
*/
void
inc
(
double
amount
,
String
...
labelValues
);
/**
* Decrement the Gauge with label values by the given amount.
*
* @param amount amount
* @param labelValues label values
*/
void
dec
(
double
amount
,
String
...
labelValues
);
/**
* Metrics type.
*
* @return metrics type
*/
default
String
metricsType
()
{
return
MetricsTypeEnum
.
GAUGE
.
name
();
}
}
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/HistogramMetricsTracker.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.api
;
import
org.apache.shardingsphere.metrics.enums.MetricsTypeEnum
;
/**
* Histogram metrics tracker.
*/
public
interface
HistogramMetricsTracker
extends
MetricsTracker
{
/**
* Start timer with histogram.
*
* @param labelValues label values
* @return histogram metrics tracker delegate
*/
default
HistogramMetricsTrackerDelegate
startTimer
(
String
...
labelValues
)
{
return
new
NoneHistogramMetricsTrackerDelegate
();
}
/**
* Observe the given amount.
*
* @param amount amount
*/
default
void
observer
(
long
amount
)
{
}
/**
* Metrics type.
*
* @return metrics type
*/
default
String
metricsType
()
{
return
MetricsTypeEnum
.
HISTOGRAM
.
name
();
}
}
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/HistogramMetricsTrackerDelegate.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.api
;
/**
* Histogram metrics tracker delegate.
*/
public
interface
HistogramMetricsTrackerDelegate
{
/**
* Observe amount of time since start time.
*/
default
void
observeDuration
()
{
}
}
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/MetricsTracker.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.api
;
/**
* Metrics tracker.
*/
public
interface
MetricsTracker
{
/**
* Metrics label.
*
* @return metrics label
*/
String
metricsLabel
();
/**
* Metrics type.
*
* @return metrics type
*/
String
metricsType
();
}
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/MetricsTrackerFactory.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.api
;
import
java.util.Optional
;
/**
* Metrics tracker factory.
*/
public
interface
MetricsTrackerFactory
{
/**
* Create of metrics tracker.
*
* @param metricsType metrics type
* @param metricsLabel metrics label
* @return metrics tracker
*/
Optional
<
MetricsTracker
>
create
(
String
metricsType
,
String
metricsLabel
);
}
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/NoneHistogramMetricsTrackerDelegate.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.api
;
public
class
NoneHistogramMetricsTrackerDelegate
implements
HistogramMetricsTrackerDelegate
{
}
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/NoneSummaryMetricsTrackerDelegate.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.api
;
/**
* None summary metrics tracker delegate.
*/
public
class
NoneSummaryMetricsTrackerDelegate
implements
SummaryMetricsTrackerDelegate
{
}
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/SummaryMetricsTracker.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.api
;
import
org.apache.shardingsphere.metrics.enums.MetricsTypeEnum
;
/**
* Summary metrics tracker.
*/
public
interface
SummaryMetricsTracker
extends
MetricsTracker
{
/**
* Start timer with summary.
*
* @param labelValues label values
* @return Summary metrics tracker delegate
*/
default
SummaryMetricsTrackerDelegate
startTimer
(
String
...
labelValues
)
{
return
new
NoneSummaryMetricsTrackerDelegate
();
}
/**
* Observe the given amount.
*
* @param amount amount
*/
default
void
observer
(
long
amount
)
{
}
/**
* Metrics type.
*
* @return metrics type
*/
default
String
metricsType
()
{
return
MetricsTypeEnum
.
SUMMARY
.
name
();
}
}
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/api/SummaryMetricsTrackerDelegate.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.api
;
/**
* Summary metrics tracker delegate.
*/
public
interface
SummaryMetricsTrackerDelegate
{
/**
* Observe amount of time in seconds since start time.
*/
default
void
observeDuration
()
{
}
}
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/enums/MetricsLabelEnum.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.enums
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
/**
* Metrics label enum.
*/
@RequiredArgsConstructor
@Getter
public
enum
MetricsLabelEnum
{
/**
* Request total metrics label.
*/
REQUEST_TOTAL
(
"request_total"
),
/**
* SQL statement count metrics label.
*/
SQL_STATEMENT_COUNT
(
"sql_statement_count"
),
/**
* Channel count metrics label.
*/
CHANNEL_COUNT
(
"channel_count"
),
/**
* Request latency metrics label.
*/
REQUEST_LATENCY
(
"request_latency"
);
private
final
String
name
;
}
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/enums/MetricsTypeEnum.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.enums
;
/**
* Metrics type enum.
*/
public
enum
MetricsTypeEnum
{
/**
* Counter metrics type.
*/
COUNTER
,
/**
* Gauge metrics type.
*/
GAUGE
,
/**
* Histogram metrics type.
*/
HISTOGRAM
,
/**
* Summary metrics type.
*/
SUMMARY
}
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/spi/MetricsTrackerManager.java
0 → 100644
浏览文件 @
40e57c04
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.metrics.spi
;
import
org.apache.shardingsphere.metrics.api.MetricsTrackerFactory
;
import
org.apache.shardingsphere.spi.type.TypedSPI
;
/**
* Metrics tracker manager.
*/
public
interface
MetricsTrackerManager
extends
TypedSPI
{
/**
* Init metrics tracker.
*
* @param port port
*/
void
init
(
int
port
);
/**
* Gets metrics tracker factory.
*
* @return metrics tracker factory
*/
MetricsTrackerFactory
getMetricsTrackerFactory
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录