Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Iotdb
提交
91aa0341
I
Iotdb
项目概览
apache
/
Iotdb
12 个月 前同步成功
通知
25
Star
3344
Fork
916
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
Iotdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
91aa0341
编写于
11月 25, 2022
作者:
Z
ZhangHongYin
提交者:
GitHub
11月 25, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[IOTDB-4994] Unify reporter (#8144)
上级
9f12b58c
变更
83
隐藏空白更改
内联
并排
Showing
83 changed file
with
1079 addition
and
1599 deletion
+1079
-1599
confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
...va/org/apache/iotdb/confignode/manager/ConfigManager.java
+0
-1
confignode/src/main/java/org/apache/iotdb/confignode/manager/load/LoadManagerMetrics.java
...che/iotdb/confignode/manager/load/LoadManagerMetrics.java
+66
-38
confignode/src/main/java/org/apache/iotdb/confignode/manager/node/NodeManager.java
...org/apache/iotdb/confignode/manager/node/NodeManager.java
+0
-6
confignode/src/main/java/org/apache/iotdb/confignode/persistence/metric/NodeInfoMetrics.java
.../iotdb/confignode/persistence/metric/NodeInfoMetrics.java
+0
-95
confignode/src/main/java/org/apache/iotdb/confignode/persistence/metric/PartitionInfoMetrics.java
...b/confignode/persistence/metric/PartitionInfoMetrics.java
+7
-7
confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceHandlerMetrics.java
...de/service/thrift/ConfigNodeRPCServiceHandlerMetrics.java
+1
-1
confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceMetrics.java
...onfignode/service/thrift/ConfigNodeRPCServiceMetrics.java
+1
-1
confignode/src/test/resources/confignode1conf/iotdb-confignode.properties
...est/resources/confignode1conf/iotdb-confignode.properties
+2
-3
confignode/src/test/resources/confignode2conf/iotdb-confignode.properties
...est/resources/confignode2conf/iotdb-confignode.properties
+1
-2
confignode/src/test/resources/confignode3conf/iotdb-confignode.properties
...est/resources/confignode3conf/iotdb-confignode.properties
+1
-2
consensus/src/main/java/org/apache/iotdb/consensus/multileader/MultiLeaderServerMetrics.java
...iotdb/consensus/multileader/MultiLeaderServerMetrics.java
+2
-2
consensus/src/main/java/org/apache/iotdb/consensus/multileader/logdispatcher/LogDispatcherThreadMetrics.java
...multileader/logdispatcher/LogDispatcherThreadMetrics.java
+2
-2
consensus/src/main/java/org/apache/iotdb/consensus/multileader/logdispatcher/MultiLeaderMemoryManagerMetrics.java
...leader/logdispatcher/MultiLeaderMemoryManagerMetrics.java
+1
-1
metrics/dropwizard-metrics/pom.xml
metrics/dropwizard-metrics/pom.xml
+0
-5
metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/reporter/DropwizardIoTDBReporter.java
.../metrics/dropwizard/reporter/DropwizardIoTDBReporter.java
+0
-79
metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/reporter/DropwizardJmxReporter.java
...db/metrics/dropwizard/reporter/DropwizardJmxReporter.java
+4
-5
metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/reporter/DropwizardMetricsExporter.java
...etrics/dropwizard/reporter/DropwizardMetricsExporter.java
+0
-168
metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/reporter/IoTDBReporter.java
...ache/iotdb/metrics/dropwizard/reporter/IoTDBReporter.java
+0
-278
metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/type/DropwizardHistogramSnapshot.java
.../metrics/dropwizard/type/DropwizardHistogramSnapshot.java
+0
-7
metrics/dropwizard-metrics/src/main/resources/META-INF/services/org.apache.iotdb.metrics.reporter.JmxReporter
...NF/services/org.apache.iotdb.metrics.reporter.JmxReporter
+1
-3
metrics/interface/pom.xml
metrics/interface/pom.xml
+6
-5
metrics/interface/src/main/java/org/apache/iotdb/metrics/AbstractMetricManager.java
.../java/org/apache/iotdb/metrics/AbstractMetricManager.java
+17
-82
metrics/interface/src/main/java/org/apache/iotdb/metrics/AbstractMetricService.java
.../java/org/apache/iotdb/metrics/AbstractMetricService.java
+63
-90
metrics/interface/src/main/java/org/apache/iotdb/metrics/CompositeReporter.java
...main/java/org/apache/iotdb/metrics/CompositeReporter.java
+2
-1
metrics/interface/src/main/java/org/apache/iotdb/metrics/DoNothingMetricService.java
...java/org/apache/iotdb/metrics/DoNothingMetricService.java
+2
-2
metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingHistogramSnapshot.java
...apache/iotdb/metrics/impl/DoNothingHistogramSnapshot.java
+0
-7
metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/jvm/JvmClassLoaderMetrics.java
...e/iotdb/metrics/metricsets/jvm/JvmClassLoaderMetrics.java
+2
-2
metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/jvm/JvmCompileMetrics.java
...pache/iotdb/metrics/metricsets/jvm/JvmCompileMetrics.java
+1
-1
metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/jvm/JvmGcMetrics.java
...org/apache/iotdb/metrics/metricsets/jvm/JvmGcMetrics.java
+2
-2
metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/jvm/JvmMemoryMetrics.java
...apache/iotdb/metrics/metricsets/jvm/JvmMemoryMetrics.java
+16
-6
metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/jvm/JvmThreadMetrics.java
...apache/iotdb/metrics/metricsets/jvm/JvmThreadMetrics.java
+4
-4
metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/JmxReporter.java
...n/java/org/apache/iotdb/metrics/reporter/JmxReporter.java
+6
-17
metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/Reporter.java
...main/java/org/apache/iotdb/metrics/reporter/Reporter.java
+0
-4
metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/iotdb/InternalIoTDBReporter.java
...e/iotdb/metrics/reporter/iotdb/InternalIoTDBReporter.java
+67
-0
metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/iotdb/IoTDBReporter.java
...rg/apache/iotdb/metrics/reporter/iotdb/IoTDBReporter.java
+103
-0
metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/iotdb/MemoryInternalIoTDBReporter.java
...b/metrics/reporter/iotdb/MemoryInternalIoTDBReporter.java
+15
-15
metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/iotdb/SessionIoTDBReporter.java
...he/iotdb/metrics/reporter/iotdb/SessionIoTDBReporter.java
+175
-0
metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/prometheus/PrometheusReporter.java
...iotdb/metrics/reporter/prometheus/PrometheusReporter.java
+222
-0
metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/prometheus/PrometheusTextWriter.java
...tdb/metrics/reporter/prometheus/PrometheusTextWriter.java
+23
-21
metrics/interface/src/main/java/org/apache/iotdb/metrics/type/AutoGauge.java
...rc/main/java/org/apache/iotdb/metrics/type/AutoGauge.java
+7
-0
metrics/interface/src/main/java/org/apache/iotdb/metrics/type/Counter.java
.../src/main/java/org/apache/iotdb/metrics/type/Counter.java
+7
-0
metrics/interface/src/main/java/org/apache/iotdb/metrics/type/Gauge.java
...ce/src/main/java/org/apache/iotdb/metrics/type/Gauge.java
+7
-0
metrics/interface/src/main/java/org/apache/iotdb/metrics/type/Histogram.java
...rc/main/java/org/apache/iotdb/metrics/type/Histogram.java
+8
-0
metrics/interface/src/main/java/org/apache/iotdb/metrics/type/HistogramSnapshot.java
...java/org/apache/iotdb/metrics/type/HistogramSnapshot.java
+14
-4
metrics/interface/src/main/java/org/apache/iotdb/metrics/type/IMetric.java
.../src/main/java/org/apache/iotdb/metrics/type/IMetric.java
+5
-1
metrics/interface/src/main/java/org/apache/iotdb/metrics/type/Rate.java
...ace/src/main/java/org/apache/iotdb/metrics/type/Rate.java
+11
-0
metrics/interface/src/main/java/org/apache/iotdb/metrics/type/Timer.java
...ce/src/main/java/org/apache/iotdb/metrics/type/Timer.java
+7
-0
metrics/interface/src/main/java/org/apache/iotdb/metrics/utils/IoTDBMetricsUtils.java
...ava/org/apache/iotdb/metrics/utils/IoTDBMetricsUtils.java
+27
-48
metrics/interface/src/main/java/org/apache/iotdb/metrics/utils/MetricInfo.java
.../main/java/org/apache/iotdb/metrics/utils/MetricInfo.java
+5
-4
metrics/interface/src/main/java/org/apache/iotdb/metrics/utils/MetricType.java
.../main/java/org/apache/iotdb/metrics/utils/MetricType.java
+1
-0
metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/MicrometerMetricManager.java
...che/iotdb/metrics/micrometer/MicrometerMetricManager.java
+1
-0
metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/reporter/IoTDBMeterRegistry.java
...iotdb/metrics/micrometer/reporter/IoTDBMeterRegistry.java
+0
-149
metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/reporter/IoTDBRegistryConfig.java
...otdb/metrics/micrometer/reporter/IoTDBRegistryConfig.java
+0
-50
metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/reporter/MicrometerIoTDBReporter.java
.../metrics/micrometer/reporter/MicrometerIoTDBReporter.java
+0
-92
metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/reporter/MicrometerJmxReporter.java
...db/metrics/micrometer/reporter/MicrometerJmxReporter.java
+3
-4
metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/reporter/MicrometerPrometheusReporter.java
...ics/micrometer/reporter/MicrometerPrometheusReporter.java
+0
-118
metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerHistogramSnapshot.java
.../metrics/micrometer/type/MicrometerHistogramSnapshot.java
+0
-7
metrics/micrometer-metrics/src/main/resources/META-INF/services/org.apache.iotdb.metrics.reporter.JmxReporter
...NF/services/org.apache.iotdb.metrics.reporter.JmxReporter
+1
-3
node-commons/src/main/java/org/apache/iotdb/commons/service/metric/MetricService.java
...rg/apache/iotdb/commons/service/metric/MetricService.java
+5
-5
server/src/assembly/resources/conf/iotdb-datanode.properties
server/src/assembly/resources/conf/iotdb-datanode.properties
+1
-1
server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
...c/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
+4
-4
server/src/main/java/org/apache/iotdb/db/engine/cache/ChunkCacheMetrics.java
...a/org/apache/iotdb/db/engine/cache/ChunkCacheMetrics.java
+1
-1
server/src/main/java/org/apache/iotdb/db/engine/cache/TimeSeriesMetadataCacheMetrics.java
...iotdb/db/engine/cache/TimeSeriesMetadataCacheMetrics.java
+2
-2
server/src/main/java/org/apache/iotdb/db/engine/flush/FlushManagerMetrics.java
...org/apache/iotdb/db/engine/flush/FlushManagerMetrics.java
+2
-2
server/src/main/java/org/apache/iotdb/db/engine/storagegroup/DataRegionMetrics.java
...pache/iotdb/db/engine/storagegroup/DataRegionMetrics.java
+1
-1
server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessorInfoMetrics.java
...db/db/engine/storagegroup/TsFileProcessorInfoMetrics.java
+1
-1
server/src/main/java/org/apache/iotdb/db/metadata/cache/DataNodeSchemaCacheMetrics.java
...e/iotdb/db/metadata/cache/DataNodeSchemaCacheMetrics.java
+1
-1
server/src/main/java/org/apache/iotdb/db/metadata/rescon/SchemaStatisticsManagerMetrics.java
...db/db/metadata/rescon/SchemaStatisticsManagerMetrics.java
+1
-1
server/src/main/java/org/apache/iotdb/db/mpp/execution/exchange/MPPDataExchangeServiceMetrics.java
...mpp/execution/exchange/MPPDataExchangeServiceMetrics.java
+1
-1
server/src/main/java/org/apache/iotdb/db/mpp/execution/exchange/MppDataExchangeServiceThriftHandlerMetrics.java
.../exchange/MppDataExchangeServiceThriftHandlerMetrics.java
+1
-1
server/src/main/java/org/apache/iotdb/db/query/pool/RawQueryReadTaskPoolManagerMetrics.java
...tdb/db/query/pool/RawQueryReadTaskPoolManagerMetrics.java
+2
-2
server/src/main/java/org/apache/iotdb/db/service/DataNodeInternalRPCServiceMetrics.java
...e/iotdb/db/service/DataNodeInternalRPCServiceMetrics.java
+1
-1
server/src/main/java/org/apache/iotdb/db/service/RPCServiceMetrics.java
...n/java/org/apache/iotdb/db/service/RPCServiceMetrics.java
+1
-1
server/src/main/java/org/apache/iotdb/db/service/metrics/FileMetrics.java
...java/org/apache/iotdb/db/service/metrics/FileMetrics.java
+8
-6
server/src/main/java/org/apache/iotdb/db/service/metrics/IoTDBInternalReporter.java
...pache/iotdb/db/service/metrics/IoTDBInternalReporter.java
+59
-67
server/src/main/java/org/apache/iotdb/db/service/metrics/ProcessMetrics.java
...a/org/apache/iotdb/db/service/metrics/ProcessMetrics.java
+12
-9
server/src/main/java/org/apache/iotdb/db/service/metrics/SystemMetrics.java
...va/org/apache/iotdb/db/service/metrics/SystemMetrics.java
+16
-7
server/src/main/java/org/apache/iotdb/db/service/thrift/handler/InternalServiceThriftHandlerMetrics.java
...e/thrift/handler/InternalServiceThriftHandlerMetrics.java
+4
-1
server/src/main/java/org/apache/iotdb/db/service/thrift/handler/RPCServiceThriftHandlerMetrics.java
...ervice/thrift/handler/RPCServiceThriftHandlerMetrics.java
+1
-1
server/src/test/java/org/apache/iotdb/db/metric/MetricServiceTest.java
...st/java/org/apache/iotdb/db/metric/MetricServiceTest.java
+32
-32
server/src/test/resources/datanode1conf/iotdb-datanode.properties
...rc/test/resources/datanode1conf/iotdb-datanode.properties
+1
-2
server/src/test/resources/datanode2conf/iotdb-datanode.properties
...rc/test/resources/datanode2conf/iotdb-datanode.properties
+1
-2
server/src/test/resources/datanode3conf/iotdb-datanode.properties
...rc/test/resources/datanode3conf/iotdb-datanode.properties
+1
-2
未找到文件。
confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
浏览文件 @
91aa0341
...
@@ -1044,7 +1044,6 @@ public class ConfigManager implements IManager {
...
@@ -1044,7 +1044,6 @@ public class ConfigManager implements IManager {
@Override
@Override
public
void
addMetrics
()
{
public
void
addMetrics
()
{
partitionManager
.
addMetrics
();
partitionManager
.
addMetrics
();
nodeManager
.
addMetrics
();
}
}
@Override
@Override
...
...
confignode/src/main/java/org/apache/iotdb/confignode/manager/load/LoadManagerMetrics.java
浏览文件 @
91aa0341
...
@@ -41,6 +41,7 @@ import java.util.concurrent.ConcurrentHashMap;
...
@@ -41,6 +41,7 @@ import java.util.concurrent.ConcurrentHashMap;
import
static
org
.
apache
.
iotdb
.
confignode
.
conf
.
ConfigNodeConstant
.
METRIC_CONFIG_NODE
;
import
static
org
.
apache
.
iotdb
.
confignode
.
conf
.
ConfigNodeConstant
.
METRIC_CONFIG_NODE
;
import
static
org
.
apache
.
iotdb
.
confignode
.
conf
.
ConfigNodeConstant
.
METRIC_DATA_NODE
;
import
static
org
.
apache
.
iotdb
.
confignode
.
conf
.
ConfigNodeConstant
.
METRIC_DATA_NODE
;
import
static
org
.
apache
.
iotdb
.
confignode
.
conf
.
ConfigNodeConstant
.
METRIC_STATUS_ONLINE
;
import
static
org
.
apache
.
iotdb
.
confignode
.
conf
.
ConfigNodeConstant
.
METRIC_STATUS_ONLINE
;
import
static
org
.
apache
.
iotdb
.
confignode
.
conf
.
ConfigNodeConstant
.
METRIC_STATUS_REGISTER
;
import
static
org
.
apache
.
iotdb
.
confignode
.
conf
.
ConfigNodeConstant
.
METRIC_STATUS_UNKNOWN
;
import
static
org
.
apache
.
iotdb
.
confignode
.
conf
.
ConfigNodeConstant
.
METRIC_STATUS_UNKNOWN
;
import
static
org
.
apache
.
iotdb
.
confignode
.
conf
.
ConfigNodeConstant
.
METRIC_TAG_TOTAL
;
import
static
org
.
apache
.
iotdb
.
confignode
.
conf
.
ConfigNodeConstant
.
METRIC_TAG_TOTAL
;
...
@@ -55,11 +56,26 @@ public class LoadManagerMetrics implements IMetricSet {
...
@@ -55,11 +56,26 @@ public class LoadManagerMetrics implements IMetricSet {
@Override
@Override
public
void
bindTo
(
AbstractMetricService
metricService
)
{
public
void
bindTo
(
AbstractMetricService
metricService
)
{
addNodeMetrics
(
metricService
);
metricService
.
createAutoGauge
(
addLeaderCount
(
metricService
);
Metric
.
CONFIG_NODE
.
toString
(),
}
MetricLevel
.
CORE
,
this
,
o
->
getRegisterConfigNodesNum
(
metricService
),
Tag
.
NAME
.
toString
(),
METRIC_TAG_TOTAL
,
Tag
.
STATUS
.
toString
(),
METRIC_STATUS_REGISTER
);
metricService
.
createAutoGauge
(
Metric
.
DATA_NODE
.
toString
(),
MetricLevel
.
CORE
,
this
,
o
->
getRegisterDataNodesNum
(
metricService
),
Tag
.
NAME
.
toString
(),
METRIC_TAG_TOTAL
,
Tag
.
STATUS
.
toString
(),
METRIC_STATUS_REGISTER
);
private
void
addNodeMetrics
(
AbstractMetricService
metricService
)
{
metricService
.
createAutoGauge
(
metricService
.
createAutoGauge
(
Metric
.
CONFIG_NODE
.
toString
(),
Metric
.
CONFIG_NODE
.
toString
(),
MetricLevel
.
CORE
,
MetricLevel
.
CORE
,
...
@@ -101,40 +117,26 @@ public class LoadManagerMetrics implements IMetricSet {
...
@@ -101,40 +117,26 @@ public class LoadManagerMetrics implements IMetricSet {
METRIC_STATUS_UNKNOWN
);
METRIC_STATUS_UNKNOWN
);
}
}
/** Get the LeaderCount of Specific DataNodeId */
private
Integer
getLeadershipCountByDatanode
(
int
dataNodeId
)
{
Map
<
Integer
,
Integer
>
idToCountMap
=
new
ConcurrentHashMap
<>();
getLoadManager
()
.
getLatestRegionLeaderMap
()
.
forEach
((
consensusGroupId
,
nodeId
)
->
idToCountMap
.
merge
(
nodeId
,
1
,
Integer:
:
sum
));
return
idToCountMap
.
get
(
dataNodeId
);
}
private
void
addLeaderCount
(
AbstractMetricService
metricService
)
{
getNodeManager
()
.
getRegisteredDataNodes
()
.
forEach
(
dataNodeInfo
->
{
TDataNodeLocation
dataNodeLocation
=
dataNodeInfo
.
getLocation
();
int
dataNodeId
=
dataNodeLocation
.
getDataNodeId
();
String
name
=
NodeUrlUtils
.
convertTEndPointUrl
(
dataNodeLocation
.
getClientRpcEndPoint
());
metricService
.
createAutoGauge
(
Metric
.
CLUSTER_NODE_LEADER_COUNT
.
toString
(),
MetricLevel
.
IMPORTANT
,
this
,
o
->
getLeadershipCountByDatanode
(
dataNodeId
),
Tag
.
NAME
.
toString
(),
name
);
});
}
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_GAUGE
,
Metric
.
CONFIG_NODE
.
toString
(),
Tag
.
NAME
.
toString
(),
METRIC_TAG_TOTAL
,
Tag
.
STATUS
.
toString
(),
METRIC_STATUS_REGISTER
);
metricService
.
remove
(
MetricType
.
AUTO_GAUGE
,
Metric
.
DATA_NODE
.
toString
(),
Tag
.
NAME
.
toString
(),
METRIC_TAG_TOTAL
,
Tag
.
STATUS
.
toString
(),
METRIC_STATUS_REGISTER
);
metricService
.
remove
(
MetricType
.
AUTO_GAUGE
,
Metric
.
CONFIG_NODE
.
toString
(),
Metric
.
CONFIG_NODE
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
METRIC_TAG_TOTAL
,
METRIC_TAG_TOTAL
,
...
@@ -142,7 +144,7 @@ public class LoadManagerMetrics implements IMetricSet {
...
@@ -142,7 +144,7 @@ public class LoadManagerMetrics implements IMetricSet {
METRIC_STATUS_ONLINE
);
METRIC_STATUS_ONLINE
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
DATA_NODE
.
toString
(),
Metric
.
DATA_NODE
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
METRIC_TAG_TOTAL
,
METRIC_TAG_TOTAL
,
...
@@ -150,7 +152,7 @@ public class LoadManagerMetrics implements IMetricSet {
...
@@ -150,7 +152,7 @@ public class LoadManagerMetrics implements IMetricSet {
METRIC_STATUS_ONLINE
);
METRIC_STATUS_ONLINE
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
CONFIG_NODE
.
toString
(),
Metric
.
CONFIG_NODE
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
METRIC_TAG_TOTAL
,
METRIC_TAG_TOTAL
,
...
@@ -158,7 +160,7 @@ public class LoadManagerMetrics implements IMetricSet {
...
@@ -158,7 +160,7 @@ public class LoadManagerMetrics implements IMetricSet {
METRIC_STATUS_UNKNOWN
);
METRIC_STATUS_UNKNOWN
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
DATA_NODE
.
toString
(),
Metric
.
DATA_NODE
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
METRIC_TAG_TOTAL
,
METRIC_TAG_TOTAL
,
...
@@ -193,6 +195,32 @@ public class LoadManagerMetrics implements IMetricSet {
...
@@ -193,6 +195,32 @@ public class LoadManagerMetrics implements IMetricSet {
return
configManager
.
getLoadManager
();
return
configManager
.
getLoadManager
();
}
}
private
int
getRegisterConfigNodesNum
(
AbstractMetricService
metricService
)
{
return
getNodeManager
().
getRegisteredConfigNodes
().
size
();
}
private
int
getRegisterDataNodesNum
(
AbstractMetricService
metricService
)
{
List
<
TDataNodeConfiguration
>
dataNodeConfigurations
=
getNodeManager
().
getRegisteredDataNodes
();
Map
<
Integer
,
Integer
>
idToCountMap
=
new
ConcurrentHashMap
<>();
getLoadManager
()
.
getLatestRegionLeaderMap
()
.
forEach
((
consensusGroupId
,
nodeId
)
->
idToCountMap
.
merge
(
nodeId
,
1
,
Integer:
:
sum
));
for
(
TDataNodeConfiguration
dataNodeInfo
:
dataNodeConfigurations
)
{
TDataNodeLocation
dataNodeLocation
=
dataNodeInfo
.
getLocation
();
int
dataNodeId
=
dataNodeLocation
.
getDataNodeId
();
String
name
=
NodeUrlUtils
.
convertTEndPointUrl
(
dataNodeLocation
.
getClientRpcEndPoint
());
metricService
.
getOrCreateGauge
(
Metric
.
CLUSTER_NODE_LEADER_COUNT
.
toString
(),
MetricLevel
.
IMPORTANT
,
Tag
.
NAME
.
toString
(),
name
)
.
set
(
idToCountMap
.
getOrDefault
(
dataNodeId
,
0
));
}
return
dataNodeConfigurations
.
size
();
}
private
int
getRunningConfigNodesNum
(
AbstractMetricService
metricService
)
{
private
int
getRunningConfigNodesNum
(
AbstractMetricService
metricService
)
{
List
<
TConfigNodeLocation
>
runningConfigNodes
=
List
<
TConfigNodeLocation
>
runningConfigNodes
=
getNodeManager
().
filterConfigNodeThroughStatus
(
NodeStatus
.
Running
);
getNodeManager
().
filterConfigNodeThroughStatus
(
NodeStatus
.
Running
);
...
...
confignode/src/main/java/org/apache/iotdb/confignode/manager/node/NodeManager.java
浏览文件 @
91aa0341
...
@@ -31,7 +31,6 @@ import org.apache.iotdb.commons.concurrent.threadpool.ScheduledExecutorUtil;
...
@@ -31,7 +31,6 @@ import org.apache.iotdb.commons.concurrent.threadpool.ScheduledExecutorUtil;
import
org.apache.iotdb.commons.conf.CommonConfig
;
import
org.apache.iotdb.commons.conf.CommonConfig
;
import
org.apache.iotdb.commons.conf.CommonDescriptor
;
import
org.apache.iotdb.commons.conf.CommonDescriptor
;
import
org.apache.iotdb.commons.consensus.ConsensusGroupId
;
import
org.apache.iotdb.commons.consensus.ConsensusGroupId
;
import
org.apache.iotdb.commons.service.metric.MetricService
;
import
org.apache.iotdb.commons.utils.StatusUtils
;
import
org.apache.iotdb.commons.utils.StatusUtils
;
import
org.apache.iotdb.confignode.client.DataNodeRequestType
;
import
org.apache.iotdb.confignode.client.DataNodeRequestType
;
import
org.apache.iotdb.confignode.client.async.AsyncConfigNodeHeartbeatClientPool
;
import
org.apache.iotdb.confignode.client.async.AsyncConfigNodeHeartbeatClientPool
;
...
@@ -61,7 +60,6 @@ import org.apache.iotdb.confignode.manager.node.heartbeat.BaseNodeCache;
...
@@ -61,7 +60,6 @@ import org.apache.iotdb.confignode.manager.node.heartbeat.BaseNodeCache;
import
org.apache.iotdb.confignode.manager.node.heartbeat.ConfigNodeHeartbeatCache
;
import
org.apache.iotdb.confignode.manager.node.heartbeat.ConfigNodeHeartbeatCache
;
import
org.apache.iotdb.confignode.manager.node.heartbeat.DataNodeHeartbeatCache
;
import
org.apache.iotdb.confignode.manager.node.heartbeat.DataNodeHeartbeatCache
;
import
org.apache.iotdb.confignode.manager.partition.PartitionManager
;
import
org.apache.iotdb.confignode.manager.partition.PartitionManager
;
import
org.apache.iotdb.confignode.persistence.metric.NodeInfoMetrics
;
import
org.apache.iotdb.confignode.persistence.node.NodeInfo
;
import
org.apache.iotdb.confignode.persistence.node.NodeInfo
;
import
org.apache.iotdb.confignode.procedure.env.DataNodeRemoveHandler
;
import
org.apache.iotdb.confignode.procedure.env.DataNodeRemoveHandler
;
import
org.apache.iotdb.confignode.rpc.thrift.TCQConfig
;
import
org.apache.iotdb.confignode.rpc.thrift.TCQConfig
;
...
@@ -550,10 +548,6 @@ public class NodeManager {
...
@@ -550,10 +548,6 @@ public class NodeManager {
getConsensusManager
().
write
(
applyConfigNodePlan
);
getConsensusManager
().
write
(
applyConfigNodePlan
);
}
}
public
void
addMetrics
()
{
MetricService
.
getInstance
().
addMetricSet
(
new
NodeInfoMetrics
(
nodeInfo
));
}
/**
/**
* Only leader use this interface, check the ConfigNode before remove it
* Only leader use this interface, check the ConfigNode before remove it
*
*
...
...
confignode/src/main/java/org/apache/iotdb/confignode/persistence/metric/NodeInfoMetrics.java
已删除
100644 → 0
浏览文件 @
9f12b58c
/*
* 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.iotdb.confignode.persistence.metric
;
import
org.apache.iotdb.commons.service.metric.enums.Metric
;
import
org.apache.iotdb.commons.service.metric.enums.Tag
;
import
org.apache.iotdb.confignode.persistence.node.NodeInfo
;
import
org.apache.iotdb.metrics.AbstractMetricService
;
import
org.apache.iotdb.metrics.metricsets.IMetricSet
;
import
org.apache.iotdb.metrics.utils.MetricLevel
;
import
org.apache.iotdb.metrics.utils.MetricType
;
import
java.util.Objects
;
import
static
org
.
apache
.
iotdb
.
confignode
.
conf
.
ConfigNodeConstant
.
METRIC_STATUS_REGISTER
;
import
static
org
.
apache
.
iotdb
.
confignode
.
conf
.
ConfigNodeConstant
.
METRIC_TAG_TOTAL
;
public
class
NodeInfoMetrics
implements
IMetricSet
{
private
final
NodeInfo
nodeInfo
;
public
NodeInfoMetrics
(
NodeInfo
nodeInfo
)
{
this
.
nodeInfo
=
nodeInfo
;
}
@Override
public
void
bindTo
(
AbstractMetricService
metricService
)
{
metricService
.
createAutoGauge
(
Metric
.
CONFIG_NODE
.
toString
(),
MetricLevel
.
CORE
,
this
,
o
->
nodeInfo
.
getRegisteredConfigNodeCount
(),
Tag
.
NAME
.
toString
(),
METRIC_TAG_TOTAL
,
Tag
.
STATUS
.
toString
(),
METRIC_STATUS_REGISTER
);
metricService
.
createAutoGauge
(
Metric
.
DATA_NODE
.
toString
(),
MetricLevel
.
CORE
,
this
,
o
->
nodeInfo
.
getRegisteredDataNodeCount
(),
Tag
.
NAME
.
toString
(),
METRIC_TAG_TOTAL
,
Tag
.
STATUS
.
toString
(),
METRIC_STATUS_REGISTER
);
}
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
CONFIG_NODE
.
toString
(),
Tag
.
NAME
.
toString
(),
METRIC_TAG_TOTAL
,
Tag
.
STATUS
.
toString
(),
METRIC_STATUS_REGISTER
);
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
DATA_NODE
.
toString
(),
Tag
.
NAME
.
toString
(),
METRIC_TAG_TOTAL
,
Tag
.
STATUS
.
toString
(),
METRIC_STATUS_REGISTER
);
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
NodeInfoMetrics
that
=
(
NodeInfoMetrics
)
o
;
return
Objects
.
equals
(
nodeInfo
,
that
.
nodeInfo
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
nodeInfo
);
}
}
confignode/src/main/java/org/apache/iotdb/confignode/persistence/metric/PartitionInfoMetrics.java
浏览文件 @
91aa0341
...
@@ -70,16 +70,16 @@ public class PartitionInfoMetrics implements IMetricSet {
...
@@ -70,16 +70,16 @@ public class PartitionInfoMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
QUANTITY
.
toString
(),
Tag
.
NAME
.
toString
(),
"storageGroup"
);
MetricType
.
AUTO_
GAUGE
,
Metric
.
QUANTITY
.
toString
(),
Tag
.
NAME
.
toString
(),
"storageGroup"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
REGION
.
toString
(),
Metric
.
REGION
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
"total"
,
"total"
,
Tag
.
TYPE
.
toString
(),
Tag
.
TYPE
.
toString
(),
TConsensusGroupType
.
SchemaRegion
.
toString
());
TConsensusGroupType
.
SchemaRegion
.
toString
());
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
REGION
.
toString
(),
Metric
.
REGION
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
"total"
,
"total"
,
...
@@ -152,14 +152,14 @@ public class PartitionInfoMetrics implements IMetricSet {
...
@@ -152,14 +152,14 @@ public class PartitionInfoMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
REGION
.
toString
(),
Metric
.
REGION
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
storageGroupPartitionTable
.
getStorageGroupName
(),
storageGroupPartitionTable
.
getStorageGroupName
(),
Tag
.
TYPE
.
toString
(),
Tag
.
TYPE
.
toString
(),
TConsensusGroupType
.
SchemaRegion
.
toString
());
TConsensusGroupType
.
SchemaRegion
.
toString
());
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
REGION
.
toString
(),
Metric
.
REGION
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
storageGroupPartitionTable
.
getStorageGroupName
(),
storageGroupPartitionTable
.
getStorageGroupName
(),
...
@@ -167,14 +167,14 @@ public class PartitionInfoMetrics implements IMetricSet {
...
@@ -167,14 +167,14 @@ public class PartitionInfoMetrics implements IMetricSet {
TConsensusGroupType
.
DataRegion
.
toString
());
TConsensusGroupType
.
DataRegion
.
toString
());
// TODO slot will be updated in the future
// TODO slot will be updated in the future
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
SLOT
.
toString
(),
Metric
.
SLOT
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
storageGroupPartitionTable
.
getStorageGroupName
(),
storageGroupPartitionTable
.
getStorageGroupName
(),
Tag
.
TYPE
.
toString
(),
Tag
.
TYPE
.
toString
(),
"schemaSlotNumber"
);
"schemaSlotNumber"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
SLOT
.
toString
(),
Metric
.
SLOT
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
storageGroupPartitionTable
.
getStorageGroupName
(),
storageGroupPartitionTable
.
getStorageGroupName
(),
...
...
confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceHandlerMetrics.java
浏览文件 @
91aa0341
...
@@ -48,7 +48,7 @@ public class ConfigNodeRPCServiceHandlerMetrics implements IMetricSet {
...
@@ -48,7 +48,7 @@ public class ConfigNodeRPCServiceHandlerMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
THRIFT_CONNECTIONS
.
toString
(),
Metric
.
THRIFT_CONNECTIONS
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
"ConfigNodeRPC"
);
"ConfigNodeRPC"
);
...
...
confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceMetrics.java
浏览文件 @
91aa0341
...
@@ -49,7 +49,7 @@ public class ConfigNodeRPCServiceMetrics implements IMetricSet {
...
@@ -49,7 +49,7 @@ public class ConfigNodeRPCServiceMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
THRIFT_ACTIVE_THREADS
.
toString
(),
Metric
.
THRIFT_ACTIVE_THREADS
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
ThreadName
.
CONFIGNODE_RPC_SERVICE
.
getName
());
ThreadName
.
CONFIGNODE_RPC_SERVICE
.
getName
());
...
...
confignode/src/test/resources/confignode1conf/iotdb-confignode.properties
浏览文件 @
91aa0341
...
@@ -25,10 +25,9 @@ cn_system_dir=target/confignode1/system
...
@@ -25,10 +25,9 @@ cn_system_dir=target/confignode1/system
cn_data_dirs
=
target/confignode1/data
cn_data_dirs
=
target/confignode1/data
cn_consensus_dir
=
target/confignode1/consensus
cn_consensus_dir
=
target/confignode1/consensus
cn_enable_metric
=
true
cn_enable_performance_stat
=
false
cn_enable_performance_stat
=
false
cn_metric_reporter_list
=
PROMETHEUS
cn_metric_reporter_list
=
JMX,
PROMETHEUS
cn_metric_frame_type
=
MICROMETER
cn_metric_frame_type
=
MICROMETER
cn_metric_level
=
CORE
cn_metric_level
=
IMPORTANT
cn_metric_async_collect_period
=
5
cn_metric_async_collect_period
=
5
cn_metric_prometheus_reporter_port
=
9091
cn_metric_prometheus_reporter_port
=
9091
\ No newline at end of file
confignode/src/test/resources/confignode2conf/iotdb-confignode.properties
浏览文件 @
91aa0341
...
@@ -25,10 +25,9 @@ cn_system_dir=target/confignode2/system
...
@@ -25,10 +25,9 @@ cn_system_dir=target/confignode2/system
cn_data_dirs
=
target/confignode2/data
cn_data_dirs
=
target/confignode2/data
cn_consensus_dir
=
target/confignode2/consensus
cn_consensus_dir
=
target/confignode2/consensus
cn_enable_metric
=
true
cn_enable_performance_stat
=
false
cn_enable_performance_stat
=
false
cn_metric_reporter_list
=
PROMETHEUS
cn_metric_reporter_list
=
PROMETHEUS
cn_metric_frame_type
=
MICROMETER
cn_metric_frame_type
=
MICROMETER
cn_metric_level
=
CORE
cn_metric_level
=
IMPORTANT
cn_metric_async_collect_period
=
5
cn_metric_async_collect_period
=
5
cn_metric_prometheus_reporter_port
=
9093
cn_metric_prometheus_reporter_port
=
9093
\ No newline at end of file
confignode/src/test/resources/confignode3conf/iotdb-confignode.properties
浏览文件 @
91aa0341
...
@@ -25,10 +25,9 @@ cn_system_dir=target/confignode3/system
...
@@ -25,10 +25,9 @@ cn_system_dir=target/confignode3/system
cn_data_dirs
=
target/confignode3/data
cn_data_dirs
=
target/confignode3/data
cn_consensus_dir
=
target/confignode3/consensus
cn_consensus_dir
=
target/confignode3/consensus
cn_enable_metric
=
true
cn_enable_performance_stat
=
false
cn_enable_performance_stat
=
false
cn_metric_reporter_list
=
PROMETHEUS
cn_metric_reporter_list
=
PROMETHEUS
cn_metric_frame_type
=
MICROMETER
cn_metric_frame_type
=
MICROMETER
cn_metric_level
=
CORE
cn_metric_level
=
IMPORTANT
cn_metric_async_collect_period
=
5
cn_metric_async_collect_period
=
5
cn_metric_prometheus_reporter_port
=
9095
cn_metric_prometheus_reporter_port
=
9095
\ No newline at end of file
consensus/src/main/java/org/apache/iotdb/consensus/multileader/MultiLeaderServerMetrics.java
浏览文件 @
91aa0341
...
@@ -66,7 +66,7 @@ public class MultiLeaderServerMetrics implements IMetricSet {
...
@@ -66,7 +66,7 @@ public class MultiLeaderServerMetrics implements IMetricSet {
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
MetricService
.
getInstance
()
MetricService
.
getInstance
()
.
remove
(
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
MULTI_LEADER
.
toString
(),
Metric
.
MULTI_LEADER
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
"multiLeaderServerImpl"
,
"multiLeaderServerImpl"
,
...
@@ -76,7 +76,7 @@ public class MultiLeaderServerMetrics implements IMetricSet {
...
@@ -76,7 +76,7 @@ public class MultiLeaderServerMetrics implements IMetricSet {
"searchIndex"
);
"searchIndex"
);
MetricService
.
getInstance
()
MetricService
.
getInstance
()
.
remove
(
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
MULTI_LEADER
.
toString
(),
Metric
.
MULTI_LEADER
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
"multiLeaderServerImpl"
,
"multiLeaderServerImpl"
,
...
...
consensus/src/main/java/org/apache/iotdb/consensus/multileader/logdispatcher/LogDispatcherThreadMetrics.java
浏览文件 @
91aa0341
...
@@ -66,7 +66,7 @@ public class LogDispatcherThreadMetrics implements IMetricSet {
...
@@ -66,7 +66,7 @@ public class LogDispatcherThreadMetrics implements IMetricSet {
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
MetricService
.
getInstance
()
MetricService
.
getInstance
()
.
remove
(
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
MULTI_LEADER
.
toString
(),
Metric
.
MULTI_LEADER
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
formatName
(),
formatName
(),
...
@@ -76,7 +76,7 @@ public class LogDispatcherThreadMetrics implements IMetricSet {
...
@@ -76,7 +76,7 @@ public class LogDispatcherThreadMetrics implements IMetricSet {
"currentSyncIndex"
);
"currentSyncIndex"
);
MetricService
.
getInstance
()
MetricService
.
getInstance
()
.
remove
(
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
MULTI_LEADER
.
toString
(),
Metric
.
MULTI_LEADER
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
formatName
(),
formatName
(),
...
...
consensus/src/main/java/org/apache/iotdb/consensus/multileader/logdispatcher/MultiLeaderMemoryManagerMetrics.java
浏览文件 @
91aa0341
...
@@ -47,6 +47,6 @@ public class MultiLeaderMemoryManagerMetrics implements IMetricSet {
...
@@ -47,6 +47,6 @@ public class MultiLeaderMemoryManagerMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
MEM
.
toString
(),
Tag
.
NAME
.
toString
(),
"MultiLeaderConsensus"
);
MetricType
.
AUTO_
GAUGE
,
Metric
.
MEM
.
toString
(),
Tag
.
NAME
.
toString
(),
"MultiLeaderConsensus"
);
}
}
}
}
metrics/dropwizard-metrics/pom.xml
浏览文件 @
91aa0341
...
@@ -43,11 +43,6 @@
...
@@ -43,11 +43,6 @@
<artifactId>
metrics-jmx
</artifactId>
<artifactId>
metrics-jmx
</artifactId>
<version>
${dropwizard.metrics.version}
</version>
<version>
${dropwizard.metrics.version}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
io.projectreactor.netty
</groupId>
<artifactId>
reactor-netty-http
</artifactId>
<version>
${reactor-netty-http.version}
</version>
</dependency>
</dependencies>
</dependencies>
<properties>
<properties>
<jersey-core.version>
1.9
</jersey-core.version>
<jersey-core.version>
1.9
</jersey-core.version>
...
...
metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/reporter/DropwizardIoTDBReporter.java
已删除
100644 → 0
浏览文件 @
9f12b58c
/*
* 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.iotdb.metrics.dropwizard.reporter
;
import
org.apache.iotdb.metrics.AbstractMetricManager
;
import
org.apache.iotdb.metrics.config.MetricConfigDescriptor
;
import
org.apache.iotdb.metrics.dropwizard.DropwizardMetricManager
;
import
org.apache.iotdb.metrics.reporter.Reporter
;
import
org.apache.iotdb.metrics.utils.ReporterType
;
import
com.codahale.metrics.MetricFilter
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.concurrent.TimeUnit
;
public
class
DropwizardIoTDBReporter
implements
Reporter
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
DropwizardIoTDBReporter
.
class
);
private
AbstractMetricManager
dropwizardMetricManager
=
null
;
private
IoTDBReporter
reporter
;
@Override
public
boolean
start
()
{
if
(
reporter
!=
null
)
{
LOGGER
.
warn
(
"Dropwizard IoTDBReporter already start!"
);
return
false
;
}
reporter
=
IoTDBReporter
.
forRegistry
(
((
DropwizardMetricManager
)
dropwizardMetricManager
).
getMetricRegistry
())
.
prefixedWith
(
"dropwizard:"
)
.
filter
(
MetricFilter
.
ALL
)
.
build
();
reporter
.
start
(
MetricConfigDescriptor
.
getInstance
()
.
getMetricConfig
()
.
getIoTDBReporterConfig
()
.
getPushPeriodInSecond
(),
TimeUnit
.
SECONDS
);
return
true
;
}
@Override
public
boolean
stop
()
{
if
(
reporter
!=
null
)
{
reporter
.
stop
();
reporter
=
null
;
}
return
true
;
}
@Override
public
ReporterType
getReporterType
()
{
return
ReporterType
.
IOTDB
;
}
@Override
public
void
setMetricManager
(
AbstractMetricManager
metricManager
)
{
this
.
dropwizardMetricManager
=
metricManager
;
}
}
metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/reporter/DropwizardJmxReporter.java
浏览文件 @
91aa0341
...
@@ -21,18 +21,17 @@ package org.apache.iotdb.metrics.dropwizard.reporter;
...
@@ -21,18 +21,17 @@ package org.apache.iotdb.metrics.dropwizard.reporter;
import
org.apache.iotdb.metrics.AbstractMetricManager
;
import
org.apache.iotdb.metrics.AbstractMetricManager
;
import
org.apache.iotdb.metrics.dropwizard.DropwizardMetricManager
;
import
org.apache.iotdb.metrics.dropwizard.DropwizardMetricManager
;
import
org.apache.iotdb.metrics.reporter.Reporter
;
import
org.apache.iotdb.metrics.reporter.
Jmx
Reporter
;
import
org.apache.iotdb.metrics.utils.ReporterType
;
import
org.apache.iotdb.metrics.utils.ReporterType
;
import
com.codahale.metrics.jmx.JmxReporter
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
public
class
DropwizardJmxReporter
implements
Reporter
{
public
class
DropwizardJmxReporter
implements
Jmx
Reporter
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
DropwizardJmxReporter
.
class
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
DropwizardJmxReporter
.
class
);
private
AbstractMetricManager
dropwizardMetricManager
=
null
;
private
AbstractMetricManager
dropwizardMetricManager
=
null
;
private
JmxReporter
jmxReporter
=
null
;
private
com
.
codahale
.
metrics
.
jmx
.
JmxReporter
jmxReporter
=
null
;
@Override
@Override
public
boolean
start
()
{
public
boolean
start
()
{
...
@@ -42,7 +41,7 @@ public class DropwizardJmxReporter implements Reporter {
...
@@ -42,7 +41,7 @@ public class DropwizardJmxReporter implements Reporter {
}
}
try
{
try
{
jmxReporter
=
jmxReporter
=
JmxReporter
.
forRegistry
(
com
.
codahale
.
metrics
.
jmx
.
JmxReporter
.
forRegistry
(
((
DropwizardMetricManager
)
dropwizardMetricManager
).
getMetricRegistry
())
((
DropwizardMetricManager
)
dropwizardMetricManager
).
getMetricRegistry
())
.
inDomain
(
"org.apache.iotdb.metrics"
)
.
inDomain
(
"org.apache.iotdb.metrics"
)
.
build
();
.
build
();
...
...
metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/reporter/DropwizardMetricsExporter.java
已删除
100644 → 0
浏览文件 @
9f12b58c
/*
* 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.iotdb.metrics.dropwizard.reporter
;
import
org.apache.iotdb.metrics.dropwizard.DropwizardMetricNameTool
;
import
org.apache.iotdb.metrics.utils.MetricInfo
;
import
org.apache.iotdb.metrics.utils.MetricType
;
import
com.codahale.metrics.Counter
;
import
com.codahale.metrics.Gauge
;
import
com.codahale.metrics.Histogram
;
import
com.codahale.metrics.Meter
;
import
com.codahale.metrics.Metered
;
import
com.codahale.metrics.Metric
;
import
com.codahale.metrics.MetricRegistry
;
import
com.codahale.metrics.Snapshot
;
import
com.codahale.metrics.Timer
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
class
DropwizardMetricsExporter
{
private
final
MetricRegistry
metricRegistry
;
private
final
PrometheusTextWriter
writer
;
public
DropwizardMetricsExporter
(
MetricRegistry
metricRegistry
,
PrometheusTextWriter
writer
)
{
this
.
metricRegistry
=
metricRegistry
;
this
.
writer
=
writer
;
}
public
void
scrape
()
throws
IOException
{
for
(
Map
.
Entry
<
String
,
Gauge
>
entry
:
metricRegistry
.
getGauges
().
entrySet
())
{
writeGauge
(
entry
.
getKey
(),
entry
.
getValue
());
}
for
(
Map
.
Entry
<
String
,
Counter
>
entry
:
metricRegistry
.
getCounters
().
entrySet
())
{
writeCounter
(
entry
.
getKey
(),
entry
.
getValue
());
}
for
(
Map
.
Entry
<
String
,
Histogram
>
entry
:
metricRegistry
.
getHistograms
().
entrySet
())
{
writeHistogram
(
entry
.
getKey
(),
entry
.
getValue
());
}
for
(
Map
.
Entry
<
String
,
Meter
>
entry
:
metricRegistry
.
getMeters
().
entrySet
())
{
writeMeter
(
entry
.
getKey
(),
entry
.
getValue
());
}
for
(
Map
.
Entry
<
String
,
Timer
>
entry
:
metricRegistry
.
getTimers
().
entrySet
())
{
writeTimer
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
/** Export Gauge as Prometheus Gauge */
public
void
writeGauge
(
String
dropwizardName
,
Gauge
<?>
gauge
)
throws
IOException
{
MetricInfo
metricInfo
=
DropwizardMetricNameTool
.
transformFromString
(
MetricType
.
GAUGE
,
dropwizardName
);
String
sanitizeName
=
metricInfo
.
getName
();
writer
.
writeHelp
(
sanitizeName
,
getHelpMessage
(
dropwizardName
,
gauge
));
writer
.
writeType
(
sanitizeName
,
DropwizardMetricType
.
GAUGE
);
Object
obj
=
gauge
.
getValue
();
double
value
;
if
(
obj
instanceof
Number
)
{
value
=
((
Number
)
obj
).
doubleValue
();
}
else
if
(
obj
instanceof
Boolean
)
{
value
=
((
Boolean
)
obj
)
?
1
:
0
;
}
else
{
return
;
}
writer
.
writeSample
(
sanitizeName
,
metricInfo
.
getTags
(),
value
);
}
/** Export counter as Prometheus Gauge */
public
void
writeCounter
(
String
dropwizardName
,
Counter
counter
)
throws
IOException
{
MetricInfo
metricInfo
=
DropwizardMetricNameTool
.
transformFromString
(
MetricType
.
COUNTER
,
dropwizardName
);
String
sanitizeName
=
metricInfo
.
getName
()
+
"_total"
;
writer
.
writeHelp
(
sanitizeName
,
getHelpMessage
(
dropwizardName
,
counter
));
writer
.
writeType
(
sanitizeName
,
DropwizardMetricType
.
GAUGE
);
writer
.
writeSample
(
sanitizeName
,
metricInfo
.
getTags
(),
counter
.
getCount
());
}
/** Export histogram snapshot as Prometheus SUMMARY */
public
void
writeHistogram
(
String
dropwizardName
,
Histogram
histogram
)
throws
IOException
{
writeSnapshotAndCount
(
DropwizardMetricNameTool
.
transformFromString
(
MetricType
.
HISTOGRAM
,
dropwizardName
),
histogram
.
getSnapshot
(),
histogram
.
getCount
(),
1.0
,
getHelpMessage
(
dropwizardName
,
histogram
));
}
/** Export histogram snapshot */
private
void
writeSnapshotAndCount
(
MetricInfo
metricInfo
,
Snapshot
snapshot
,
long
count
,
double
factor
,
String
helpMessage
)
throws
IOException
{
String
sanitizeName
=
metricInfo
.
getName
()
+
"_seconds"
;
writer
.
writeHelp
(
sanitizeName
,
helpMessage
);
writer
.
writeType
(
sanitizeName
,
DropwizardMetricType
.
SUMMARY
);
Map
<
String
,
String
>
tags
=
metricInfo
.
getTags
();
writer
.
writeSample
(
sanitizeName
+
"_max"
,
tags
,
snapshot
.
getMax
()
*
factor
);
writer
.
writeSample
(
sanitizeName
+
"_sum"
,
tags
,
Arrays
.
stream
(
snapshot
.
getValues
()).
sum
()
*
factor
);
writer
.
writeSample
(
sanitizeName
+
"_count"
,
tags
,
count
);
}
/** Export Timer as Prometheus Summary */
public
void
writeTimer
(
String
dropwizardName
,
Timer
timer
)
throws
IOException
{
writeSnapshotAndCount
(
DropwizardMetricNameTool
.
transformFromString
(
MetricType
.
TIMER
,
dropwizardName
),
timer
.
getSnapshot
(),
timer
.
getCount
(),
1.0
D
/
TimeUnit
.
SECONDS
.
toNanos
(
1L
),
getHelpMessage
(
dropwizardName
,
timer
));
}
/** Export Meter as Prometheus Counter */
public
void
writeMeter
(
String
dropwizardName
,
Meter
meter
)
throws
IOException
{
MetricInfo
metricInfo
=
DropwizardMetricNameTool
.
transformFromString
(
MetricType
.
COUNTER
,
dropwizardName
);
String
sanitizeName
=
metricInfo
.
getName
()
+
"_total"
;
writer
.
writeHelp
(
sanitizeName
,
getHelpMessage
(
dropwizardName
,
meter
));
writer
.
writeType
(
sanitizeName
,
DropwizardMetricType
.
COUNTER
);
writer
.
writeSample
(
sanitizeName
,
metricInfo
.
getTags
(),
meter
.
getCount
());
writeMetered
(
metricInfo
,
meter
);
}
/** Export meter for multi type */
private
void
writeMetered
(
MetricInfo
metricInfo
,
Metered
metered
)
throws
IOException
{
String
sanitizeName
=
metricInfo
.
getName
();
Map
<
String
,
String
>
tags
=
metricInfo
.
getTags
();
writer
.
writeSample
(
sanitizeName
,
addTags
(
tags
,
"rate"
,
"m1"
),
metered
.
getOneMinuteRate
());
writer
.
writeSample
(
sanitizeName
,
addTags
(
tags
,
"rate"
,
"m5"
),
metered
.
getFiveMinuteRate
());
writer
.
writeSample
(
sanitizeName
,
addTags
(
tags
,
"rate"
,
"m15"
),
metered
.
getFifteenMinuteRate
());
writer
.
writeSample
(
sanitizeName
,
addTags
(
tags
,
"rate"
,
"mean"
),
metered
.
getMeanRate
());
}
private
Map
<
String
,
String
>
addTags
(
Map
<
String
,
String
>
tags
,
String
key
,
String
value
)
{
HashMap
<
String
,
String
>
result
=
new
HashMap
<>(
tags
);
result
.
put
(
key
,
value
);
return
result
;
}
private
static
String
getHelpMessage
(
String
metricName
,
Metric
metric
)
{
return
String
.
format
(
"Generated from Dropwizard metric import (metric=%s, type=%s)"
,
metricName
,
metric
.
getClass
().
getName
());
}
}
metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/reporter/IoTDBReporter.java
已删除
100644 → 0
浏览文件 @
9f12b58c
/*
* 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.iotdb.metrics.dropwizard.reporter
;
import
org.apache.iotdb.metrics.config.MetricConfig
;
import
org.apache.iotdb.metrics.config.MetricConfigDescriptor
;
import
org.apache.iotdb.metrics.dropwizard.DropwizardMetricNameTool
;
import
org.apache.iotdb.metrics.utils.IoTDBMetricsUtils
;
import
org.apache.iotdb.metrics.utils.MetricInfo
;
import
org.apache.iotdb.metrics.utils.MetricType
;
import
org.apache.iotdb.rpc.IoTDBConnectionException
;
import
org.apache.iotdb.rpc.StatementExecutionException
;
import
org.apache.iotdb.session.pool.SessionPool
;
import
org.apache.iotdb.tsfile.file.metadata.enums.TSDataType
;
import
com.codahale.metrics.Counter
;
import
com.codahale.metrics.Gauge
;
import
com.codahale.metrics.Histogram
;
import
com.codahale.metrics.Meter
;
import
com.codahale.metrics.MetricFilter
;
import
com.codahale.metrics.MetricRegistry
;
import
com.codahale.metrics.ScheduledReporter
;
import
com.codahale.metrics.Snapshot
;
import
com.codahale.metrics.Timer
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.SortedMap
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
public
class
IoTDBReporter
extends
ScheduledReporter
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
IoTDBReporter
.
class
);
private
static
final
MetricConfig
.
IoTDBReporterConfig
ioTDBReporterConfig
=
MetricConfigDescriptor
.
getInstance
().
getMetricConfig
().
getIoTDBReporterConfig
();
private
static
final
TimeUnit
DURATION_UNIT
=
TimeUnit
.
MILLISECONDS
;
private
static
final
TimeUnit
RATE_UNIT
=
TimeUnit
.
SECONDS
;
private
final
String
prefix
;
private
final
SessionPool
sessionPool
;
protected
IoTDBReporter
(
MetricRegistry
registry
,
String
prefix
,
MetricFilter
filter
,
ScheduledExecutorService
executor
,
boolean
shutdownExecutorOnStop
)
{
super
(
registry
,
"iotdb-reporter"
,
filter
,
RATE_UNIT
,
DURATION_UNIT
,
executor
,
shutdownExecutorOnStop
);
this
.
prefix
=
prefix
;
this
.
sessionPool
=
new
SessionPool
(
ioTDBReporterConfig
.
getHost
(),
ioTDBReporterConfig
.
getPort
(),
ioTDBReporterConfig
.
getUsername
(),
ioTDBReporterConfig
.
getPassword
(),
ioTDBReporterConfig
.
getMaxConnectionNumber
());
IoTDBMetricsUtils
.
checkOrCreateStorageGroup
(
sessionPool
);
}
@Override
public
void
stop
()
{
super
.
stop
();
if
(
sessionPool
!=
null
)
{
sessionPool
.
close
();
}
}
public
static
class
Builder
{
private
final
MetricRegistry
metricRegistry
;
private
String
prefix
;
private
MetricFilter
metricFilter
;
private
ScheduledExecutorService
executorService
;
private
boolean
shutdownExecutorOnStop
;
private
Builder
(
MetricRegistry
metricRegistry
)
{
this
.
metricRegistry
=
metricRegistry
;
this
.
prefix
=
null
;
this
.
metricFilter
=
MetricFilter
.
ALL
;
this
.
executorService
=
null
;
this
.
shutdownExecutorOnStop
=
true
;
}
public
Builder
shutdownExecutorOnStop
(
boolean
shutdownExecutorOnStop
)
{
this
.
shutdownExecutorOnStop
=
shutdownExecutorOnStop
;
return
this
;
}
public
Builder
scheduleOn
(
ScheduledExecutorService
executorService
)
{
this
.
executorService
=
executorService
;
return
this
;
}
public
Builder
prefixedWith
(
String
prefix
)
{
this
.
prefix
=
prefix
;
return
this
;
}
public
Builder
filter
(
MetricFilter
metricFilter
)
{
this
.
metricFilter
=
metricFilter
;
return
this
;
}
public
IoTDBReporter
build
()
{
return
new
IoTDBReporter
(
metricRegistry
,
prefix
,
metricFilter
,
executorService
,
shutdownExecutorOnStop
);
}
}
@Override
public
void
report
(
SortedMap
<
String
,
Gauge
>
gauges
,
SortedMap
<
String
,
Counter
>
counters
,
SortedMap
<
String
,
Histogram
>
histograms
,
SortedMap
<
String
,
Meter
>
meters
,
SortedMap
<
String
,
Timer
>
timers
)
{
for
(
Map
.
Entry
<
String
,
Gauge
>
entry
:
gauges
.
entrySet
())
{
sendGauge
(
entry
.
getKey
(),
entry
.
getValue
());
}
for
(
Map
.
Entry
<
String
,
Counter
>
entry
:
counters
.
entrySet
())
{
sendCounter
(
entry
.
getKey
(),
entry
.
getValue
());
}
for
(
Map
.
Entry
<
String
,
Histogram
>
entry
:
histograms
.
entrySet
())
{
sendHistogram
(
entry
.
getKey
(),
entry
.
getValue
());
}
for
(
Map
.
Entry
<
String
,
Meter
>
entry
:
meters
.
entrySet
())
{
sendMeter
(
entry
.
getKey
(),
entry
.
getValue
());
}
for
(
Map
.
Entry
<
String
,
Timer
>
entry
:
timers
.
entrySet
())
{
sendTimer
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
private
void
sendGauge
(
String
name
,
Gauge
gauge
)
{
if
(
null
==
gauge
)
{
return
;
}
MetricInfo
metricInfo
=
DropwizardMetricNameTool
.
transformFromString
(
MetricType
.
GAUGE
,
name
);
Object
obj
=
gauge
.
getValue
();
double
value
;
if
(
obj
instanceof
Number
)
{
value
=
((
Number
)
obj
).
doubleValue
();
updateValue
(
prefixed
(
metricInfo
.
getName
()),
metricInfo
.
getTags
(),
value
);
}
else
if
(
obj
instanceof
Boolean
)
{
updateValue
(
prefixed
(
metricInfo
.
getName
()),
metricInfo
.
getTags
(),
obj
);
}
}
private
void
sendCounter
(
String
name
,
Counter
counter
)
{
if
(
null
==
counter
)
{
return
;
}
MetricInfo
metricInfo
=
DropwizardMetricNameTool
.
transformFromString
(
MetricType
.
COUNTER
,
name
);
double
value
=
counter
.
getCount
();
updateValue
(
prefixed
(
metricInfo
.
getName
()),
metricInfo
.
getTags
(),
value
);
}
private
void
sendHistogram
(
String
name
,
Histogram
histogram
)
{
if
(
null
==
histogram
)
{
return
;
}
MetricInfo
metricInfo
=
DropwizardMetricNameTool
.
transformFromString
(
MetricType
.
HISTOGRAM
,
name
);
writeSnapshotAndCount
(
prefixed
(
metricInfo
.
getName
()),
metricInfo
.
getTags
(),
histogram
.
getSnapshot
(),
histogram
.
getCount
(),
1.0
);
}
private
void
sendMeter
(
String
name
,
Meter
meter
)
{
if
(
null
==
meter
)
{
return
;
}
MetricInfo
metricInfo
=
DropwizardMetricNameTool
.
transformFromString
(
MetricType
.
GAUGE
,
name
);
double
value
=
meter
.
getCount
();
updateValue
(
prefixed
(
metricInfo
.
getName
()),
metricInfo
.
getTags
(),
value
);
}
private
void
sendTimer
(
String
name
,
Timer
timer
)
{
if
(
null
==
timer
)
{
return
;
}
MetricInfo
metricInfo
=
DropwizardMetricNameTool
.
transformFromString
(
MetricType
.
GAUGE
,
name
);
writeSnapshotAndCount
(
prefixed
(
metricInfo
.
getName
()),
metricInfo
.
getTags
(),
timer
.
getSnapshot
(),
timer
.
getCount
(),
1.0
D
/
TimeUnit
.
SECONDS
.
toNanos
(
1L
));
}
private
void
writeSnapshotAndCount
(
String
name
,
Map
<
String
,
String
>
tags
,
Snapshot
snapshot
,
long
count
,
double
factor
)
{
updateValue
(
name
,
addTags
(
tags
,
"quantile"
,
"0.5"
),
snapshot
.
getMedian
()
*
factor
);
updateValue
(
name
,
addTags
(
tags
,
"quantile"
,
"0.75"
),
snapshot
.
get75thPercentile
()
*
factor
);
updateValue
(
name
,
addTags
(
tags
,
"quantile"
,
"0.95"
),
snapshot
.
get95thPercentile
()
*
factor
);
updateValue
(
name
,
addTags
(
tags
,
"quantile"
,
"0.98"
),
snapshot
.
get98thPercentile
()
*
factor
);
updateValue
(
name
,
addTags
(
tags
,
"quantile"
,
"0.99"
),
snapshot
.
get99thPercentile
()
*
factor
);
updateValue
(
name
,
addTags
(
tags
,
"quantile"
,
"0.999"
),
snapshot
.
get999thPercentile
()
*
factor
);
updateValue
(
name
+
"_min"
,
tags
,
snapshot
.
getMin
());
updateValue
(
name
+
"_max"
,
tags
,
snapshot
.
getMax
());
updateValue
(
name
+
"_median"
,
tags
,
snapshot
.
getMedian
());
updateValue
(
name
+
"_mean"
,
tags
,
snapshot
.
getMean
());
updateValue
(
name
+
"_stddev"
,
tags
,
snapshot
.
getStdDev
());
updateValue
(
name
+
"_count"
,
tags
,
count
);
}
private
void
updateValue
(
String
name
,
Map
<
String
,
String
>
labels
,
Object
value
)
{
if
(
value
!=
null
)
{
String
deviceId
=
IoTDBMetricsUtils
.
generatePath
(
name
,
labels
);
List
<
String
>
sensors
=
Collections
.
singletonList
(
"value"
);
List
<
TSDataType
>
dataTypes
=
new
ArrayList
<>();
if
(
value
instanceof
Boolean
)
{
dataTypes
.
add
(
TSDataType
.
BOOLEAN
);
}
else
if
(
value
instanceof
Integer
)
{
dataTypes
.
add
(
TSDataType
.
INT32
);
}
else
if
(
value
instanceof
Long
)
{
dataTypes
.
add
(
TSDataType
.
INT64
);
}
else
if
(
value
instanceof
Double
)
{
dataTypes
.
add
(
TSDataType
.
DOUBLE
);
}
else
{
dataTypes
.
add
(
TSDataType
.
TEXT
);
value
=
value
.
toString
();
}
List
<
Object
>
values
=
Collections
.
singletonList
(
value
);
try
{
sessionPool
.
insertRecord
(
deviceId
,
System
.
currentTimeMillis
(),
sensors
,
dataTypes
,
values
);
}
catch
(
IoTDBConnectionException
|
StatementExecutionException
e
)
{
logger
.
warn
(
"Failed to insert record"
);
}
}
}
private
String
prefixed
(
String
name
)
{
return
prefix
==
null
?
name
:
(
prefix
+
name
);
}
private
Map
<
String
,
String
>
addTags
(
Map
<
String
,
String
>
tags
,
String
key
,
String
value
)
{
HashMap
<
String
,
String
>
result
=
new
HashMap
<>(
tags
);
result
.
put
(
key
,
value
);
return
result
;
}
public
static
Builder
forRegistry
(
MetricRegistry
metricRegistry
)
{
return
new
Builder
(
metricRegistry
);
}
}
metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/type/DropwizardHistogramSnapshot.java
浏览文件 @
91aa0341
...
@@ -21,8 +21,6 @@ package org.apache.iotdb.metrics.dropwizard.type;
...
@@ -21,8 +21,6 @@ package org.apache.iotdb.metrics.dropwizard.type;
import
org.apache.iotdb.metrics.type.HistogramSnapshot
;
import
org.apache.iotdb.metrics.type.HistogramSnapshot
;
import
java.io.OutputStream
;
public
class
DropwizardHistogramSnapshot
implements
HistogramSnapshot
{
public
class
DropwizardHistogramSnapshot
implements
HistogramSnapshot
{
com
.
codahale
.
metrics
.
Snapshot
snapshot
;
com
.
codahale
.
metrics
.
Snapshot
snapshot
;
...
@@ -65,9 +63,4 @@ public class DropwizardHistogramSnapshot implements HistogramSnapshot {
...
@@ -65,9 +63,4 @@ public class DropwizardHistogramSnapshot implements HistogramSnapshot {
public
long
getMin
()
{
public
long
getMin
()
{
return
snapshot
.
getMin
();
return
snapshot
.
getMin
();
}
}
@Override
public
void
dump
(
OutputStream
output
)
{
snapshot
.
dump
(
output
);
}
}
}
metrics/dropwizard-metrics/src/main/resources/META-INF/services/org.apache.iotdb.metrics.reporter.Reporter
→
metrics/dropwizard-metrics/src/main/resources/META-INF/services/org.apache.iotdb.metrics.reporter.
Jmx
Reporter
浏览文件 @
91aa0341
...
@@ -15,6 +15,4 @@
...
@@ -15,6 +15,4 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
#
#
org.apache.iotdb.metrics.dropwizard.reporter.DropwizardJmxReporter
org.apache.iotdb.metrics.dropwizard.reporter.DropwizardJmxReporter
org.apache.iotdb.metrics.dropwizard.reporter.DropwizardPrometheusReporter
\ No newline at end of file
org.apache.iotdb.metrics.dropwizard.reporter.DropwizardIoTDBReporter
\ No newline at end of file
metrics/interface/pom.xml
浏览文件 @
91aa0341
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
<properties>
<properties>
<snakeyaml.version>
1.31
</snakeyaml.version>
<snakeyaml.version>
1.31
</snakeyaml.version>
<reactor-netty-http.version>
1.0.24
</reactor-netty-http.version>
</properties>
</properties>
<parent>
<parent>
<groupId>
org.apache.iotdb
</groupId>
<groupId>
org.apache.iotdb
</groupId>
...
@@ -35,16 +36,16 @@
...
@@ -35,16 +36,16 @@
<description>
Metrics interface for IoTDB
</description>
<description>
Metrics interface for IoTDB
</description>
<url>
https://github.com/thulab/iotdb/tree/master/tsfile
</url>
<url>
https://github.com/thulab/iotdb/tree/master/tsfile
</url>
<dependencies>
<dependencies>
<dependency>
<groupId>
org.yaml
</groupId>
<artifactId>
snakeyaml
</artifactId>
<version>
${snakeyaml.version}
</version>
</dependency>
<dependency>
<dependency>
<groupId>
org.apache.iotdb
</groupId>
<groupId>
org.apache.iotdb
</groupId>
<artifactId>
iotdb-session
</artifactId>
<artifactId>
iotdb-session
</artifactId>
<version>
${project.version}
</version>
<version>
${project.version}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
io.projectreactor.netty
</groupId>
<artifactId>
reactor-netty-http
</artifactId>
<version>
${reactor-netty-http.version}
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
<plugins>
<plugins>
...
...
metrics/interface/src/main/java/org/apache/iotdb/metrics/AbstractMetricManager.java
浏览文件 @
91aa0341
...
@@ -32,6 +32,7 @@ import org.apache.iotdb.metrics.type.Timer;
...
@@ -32,6 +32,7 @@ import org.apache.iotdb.metrics.type.Timer;
import
org.apache.iotdb.metrics.utils.MetricInfo
;
import
org.apache.iotdb.metrics.utils.MetricInfo
;
import
org.apache.iotdb.metrics.utils.MetricLevel
;
import
org.apache.iotdb.metrics.utils.MetricLevel
;
import
org.apache.iotdb.metrics.utils.MetricType
;
import
org.apache.iotdb.metrics.utils.MetricType
;
import
org.apache.iotdb.tsfile.utils.Pair
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -102,7 +103,7 @@ public abstract class AbstractMetricManager {
...
@@ -102,7 +103,7 @@ public abstract class AbstractMetricManager {
if
(!
isValid
(
metricLevel
,
name
,
tags
))
{
if
(!
isValid
(
metricLevel
,
name
,
tags
))
{
return
DoNothingMetricManager
.
doNothingAutoGauge
;
return
DoNothingMetricManager
.
doNothingAutoGauge
;
}
}
MetricInfo
metricInfo
=
new
MetricInfo
(
MetricType
.
GAUGE
,
name
,
tags
);
MetricInfo
metricInfo
=
new
MetricInfo
(
MetricType
.
AUTO_
GAUGE
,
name
,
tags
);
AutoGauge
gauge
=
createAutoGauge
(
metricInfo
,
obj
,
mapper
);
AutoGauge
gauge
=
createAutoGauge
(
metricInfo
,
obj
,
mapper
);
nameToMetaInfo
.
put
(
name
,
metricInfo
.
getMetaInfo
());
nameToMetaInfo
.
put
(
name
,
metricInfo
.
getMetaInfo
());
metrics
.
put
(
metricInfo
,
gauge
);
metrics
.
put
(
metricInfo
,
gauge
);
...
@@ -119,7 +120,7 @@ public abstract class AbstractMetricManager {
...
@@ -119,7 +120,7 @@ public abstract class AbstractMetricManager {
if
(!
isValid
(
metricLevel
,
name
,
tags
))
{
if
(!
isValid
(
metricLevel
,
name
,
tags
))
{
return
DoNothingMetricManager
.
doNothingAutoGauge
;
return
DoNothingMetricManager
.
doNothingAutoGauge
;
}
}
MetricInfo
metricInfo
=
new
MetricInfo
(
MetricType
.
GAUGE
,
name
,
tags
);
MetricInfo
metricInfo
=
new
MetricInfo
(
MetricType
.
AUTO_
GAUGE
,
name
,
tags
);
IMetric
metric
=
metrics
.
get
(
metricInfo
);
IMetric
metric
=
metrics
.
get
(
metricInfo
);
if
(
metric
==
null
)
{
if
(
metric
==
null
)
{
return
DoNothingMetricManager
.
doNothingAutoGauge
;
return
DoNothingMetricManager
.
doNothingAutoGauge
;
...
@@ -360,102 +361,36 @@ public abstract class AbstractMetricManager {
...
@@ -360,102 +361,36 @@ public abstract class AbstractMetricManager {
/**
/**
* Get all metric keys.
* Get all metric keys.
*
*
* @return [[name,
tags...], ..., [name, tags...
]]
* @return [[name,
[tags...]], ..., [name, [tags...]
]]
*/
*/
p
rotected
List
<
String
[]
>
getAllMetricKeys
()
{
p
ublic
List
<
Pair
<
String
,
String
[]>
>
getAllMetricKeys
()
{
List
<
String
[]
>
keys
=
new
ArrayList
<>(
metrics
.
size
());
List
<
Pair
<
String
,
String
[]>
>
keys
=
new
ArrayList
<>(
metrics
.
size
());
metrics
.
keySet
().
forEach
(
k
->
keys
.
add
(
k
.
toStringArray
()));
metrics
.
keySet
().
forEach
(
k
->
keys
.
add
(
k
.
toStringArray
()));
return
keys
;
return
keys
;
}
}
/**
/**
* Get all counters
* Get all metrics.
*
* @return [name, tags...] -> counter
*/
protected
Map
<
String
[],
Counter
>
getAllCounters
()
{
Map
<
String
[],
Counter
>
counterMap
=
new
HashMap
<>();
for
(
Map
.
Entry
<
MetricInfo
,
IMetric
>
entry
:
metrics
.
entrySet
())
{
if
(
entry
.
getValue
()
instanceof
Counter
)
{
counterMap
.
put
(
entry
.
getKey
().
toStringArray
(),
(
Counter
)
entry
.
getValue
());
}
}
return
counterMap
;
}
/**
* Get all gauges
*
*
* @return [name,
tags...] -> gauge
* @return [name,
[tags...]] -> metric
*/
*/
protected
Map
<
String
[],
Gauge
>
getAllGauges
()
{
public
Map
<
MetricInfo
,
IMetric
>
getAllMetrics
()
{
Map
<
String
[],
Gauge
>
gaugeMap
=
new
HashMap
<>();
return
metrics
;
for
(
Map
.
Entry
<
MetricInfo
,
IMetric
>
entry
:
metrics
.
entrySet
())
{
if
(
entry
.
getValue
()
instanceof
Gauge
)
{
gaugeMap
.
put
(
entry
.
getKey
().
toStringArray
(),
(
Gauge
)
entry
.
getValue
());
}
}
return
gaugeMap
;
}
/**
* Get all autoGauges
*
* @return [name, tags...] -> autoGauge
*/
protected
Map
<
String
[],
AutoGauge
>
getAllAutoGauges
()
{
Map
<
String
[],
AutoGauge
>
gaugeMap
=
new
HashMap
<>();
for
(
Map
.
Entry
<
MetricInfo
,
IMetric
>
entry
:
metrics
.
entrySet
())
{
if
(
entry
.
getValue
()
instanceof
AutoGauge
)
{
gaugeMap
.
put
(
entry
.
getKey
().
toStringArray
(),
(
AutoGauge
)
entry
.
getValue
());
}
}
return
gaugeMap
;
}
/**
* Get all rates
*
* @return [name, tags...] -> rate
*/
protected
Map
<
String
[],
Rate
>
getAllRates
()
{
Map
<
String
[],
Rate
>
rateMap
=
new
HashMap
<>();
for
(
Map
.
Entry
<
MetricInfo
,
IMetric
>
entry
:
metrics
.
entrySet
())
{
if
(
entry
.
getValue
()
instanceof
Rate
)
{
rateMap
.
put
(
entry
.
getKey
().
toStringArray
(),
(
Rate
)
entry
.
getValue
());
}
}
return
rateMap
;
}
/**
* Get all histograms
*
* @return [name, tags...] -> histogram
*/
protected
Map
<
String
[],
Histogram
>
getAllHistograms
()
{
Map
<
String
[],
Histogram
>
histogramMap
=
new
HashMap
<>();
for
(
Map
.
Entry
<
MetricInfo
,
IMetric
>
entry
:
metrics
.
entrySet
())
{
if
(
entry
.
getValue
()
instanceof
Histogram
)
{
histogramMap
.
put
(
entry
.
getKey
().
toStringArray
(),
(
Histogram
)
entry
.
getValue
());
}
}
return
histogramMap
;
}
}
/**
/**
* Get
all timers
* Get
metrics by type
*
*
* @return [name,
tags...] -> timer
* @return [name,
[tags...]] -> metric
*/
*/
p
rotected
Map
<
String
[],
Timer
>
getAllTimers
(
)
{
p
ublic
Map
<
MetricInfo
,
IMetric
>
getMetricsByType
(
MetricType
metricType
)
{
Map
<
String
[],
Timer
>
timerMap
=
new
HashMap
<>();
Map
<
MetricInfo
,
IMetric
>
result
=
new
HashMap
<>();
for
(
Map
.
Entry
<
MetricInfo
,
IMetric
>
entry
:
metrics
.
entrySet
())
{
for
(
Map
.
Entry
<
MetricInfo
,
IMetric
>
entry
:
metrics
.
entrySet
())
{
if
(
entry
.
get
Value
()
instanceof
Timer
)
{
if
(
entry
.
get
Key
().
getMetaInfo
().
getType
()
==
metricType
)
{
timerMap
.
put
(
entry
.
getKey
().
toStringArray
(),
(
Timer
)
entry
.
getValue
());
result
.
put
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
}
}
return
timerMap
;
return
result
;
}
}
// endregion
// endregion
...
...
metrics/interface/src/main/java/org/apache/iotdb/metrics/AbstractMetricService.java
浏览文件 @
91aa0341
...
@@ -22,13 +22,14 @@ package org.apache.iotdb.metrics;
...
@@ -22,13 +22,14 @@ package org.apache.iotdb.metrics;
import
org.apache.iotdb.metrics.config.MetricConfig
;
import
org.apache.iotdb.metrics.config.MetricConfig
;
import
org.apache.iotdb.metrics.config.MetricConfigDescriptor
;
import
org.apache.iotdb.metrics.config.MetricConfigDescriptor
;
import
org.apache.iotdb.metrics.config.ReloadLevel
;
import
org.apache.iotdb.metrics.config.ReloadLevel
;
import
org.apache.iotdb.metrics.impl.DoNothingMetric
;
import
org.apache.iotdb.metrics.impl.DoNothingMetricManager
;
import
org.apache.iotdb.metrics.impl.DoNothingMetricManager
;
import
org.apache.iotdb.metrics.metricsets.IMetricSet
;
import
org.apache.iotdb.metrics.metricsets.IMetricSet
;
import
org.apache.iotdb.metrics.reporter.CompositeReporter
;
import
org.apache.iotdb.metrics.reporter.JmxReporter
;
import
org.apache.iotdb.metrics.reporter.InternalReporter
;
import
org.apache.iotdb.metrics.reporter.MemoryInternalReporter
;
import
org.apache.iotdb.metrics.reporter.Reporter
;
import
org.apache.iotdb.metrics.reporter.Reporter
;
import
org.apache.iotdb.metrics.reporter.iotdb.InternalIoTDBReporter
;
import
org.apache.iotdb.metrics.reporter.iotdb.MemoryInternalIoTDBReporter
;
import
org.apache.iotdb.metrics.reporter.iotdb.SessionIoTDBReporter
;
import
org.apache.iotdb.metrics.reporter.prometheus.PrometheusReporter
;
import
org.apache.iotdb.metrics.type.AutoGauge
;
import
org.apache.iotdb.metrics.type.AutoGauge
;
import
org.apache.iotdb.metrics.type.Counter
;
import
org.apache.iotdb.metrics.type.Counter
;
import
org.apache.iotdb.metrics.type.Gauge
;
import
org.apache.iotdb.metrics.type.Gauge
;
...
@@ -36,10 +37,11 @@ import org.apache.iotdb.metrics.type.Histogram;
...
@@ -36,10 +37,11 @@ import org.apache.iotdb.metrics.type.Histogram;
import
org.apache.iotdb.metrics.type.IMetric
;
import
org.apache.iotdb.metrics.type.IMetric
;
import
org.apache.iotdb.metrics.type.Rate
;
import
org.apache.iotdb.metrics.type.Rate
;
import
org.apache.iotdb.metrics.type.Timer
;
import
org.apache.iotdb.metrics.type.Timer
;
import
org.apache.iotdb.metrics.utils.MetricInfo
;
import
org.apache.iotdb.metrics.utils.MetricLevel
;
import
org.apache.iotdb.metrics.utils.MetricLevel
;
import
org.apache.iotdb.metrics.utils.MetricType
;
import
org.apache.iotdb.metrics.utils.MetricType
;
import
org.apache.iotdb.metrics.utils.ReporterType
;
import
org.apache.iotdb.metrics.utils.ReporterType
;
import
org.apache.iotdb.tsfile.
file.metadata.enums.TSDataType
;
import
org.apache.iotdb.tsfile.
utils.Pair
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -62,7 +64,7 @@ public abstract class AbstractMetricService {
...
@@ -62,7 +64,7 @@ public abstract class AbstractMetricService {
/** The metric reporter of metric service */
/** The metric reporter of metric service */
protected
CompositeReporter
compositeReporter
=
new
CompositeReporter
();
protected
CompositeReporter
compositeReporter
=
new
CompositeReporter
();
/** The internal reporter of metric service */
/** The internal reporter of metric service */
protected
Internal
Reporter
internalReporter
=
new
MemoryInternal
Reporter
();
protected
Internal
IoTDBReporter
internalReporter
=
new
MemoryInternalIoTDB
Reporter
();
/** The list of metric sets */
/** The list of metric sets */
protected
List
<
IMetricSet
>
metricSets
=
new
ArrayList
<>();
protected
List
<
IMetricSet
>
metricSets
=
new
ArrayList
<>();
...
@@ -125,7 +127,7 @@ public abstract class AbstractMetricService {
...
@@ -125,7 +127,7 @@ public abstract class AbstractMetricService {
if
(
size
==
0
||
metricManager
==
null
)
{
if
(
size
==
0
||
metricManager
==
null
)
{
metricManager
=
new
DoNothingMetricManager
();
metricManager
=
new
DoNothingMetricManager
();
}
else
if
(
size
>
1
)
{
}
else
if
(
size
>
1
)
{
logger
.
warn
(
logger
.
info
(
"Detect more than one MetricManager, will use {}"
,
metricManager
.
getClass
().
getName
());
"Detect more than one MetricManager, will use {}"
,
metricManager
.
getClass
().
getName
());
}
}
}
}
...
@@ -134,18 +136,39 @@ public abstract class AbstractMetricService {
...
@@ -134,18 +136,39 @@ public abstract class AbstractMetricService {
protected
void
loadReporter
()
{
protected
void
loadReporter
()
{
logger
.
info
(
"Load metric reporters, type: {}"
,
metricConfig
.
getMetricReporterList
());
logger
.
info
(
"Load metric reporters, type: {}"
,
metricConfig
.
getMetricReporterList
());
compositeReporter
.
clearReporter
();
compositeReporter
.
clearReporter
();
ServiceLoader
<
Reporter
>
reporters
=
ServiceLoader
.
load
(
Reporter
.
class
);
if
(
metricConfig
.
getMetricReporterList
()
==
null
)
{
for
(
Reporter
reporter
:
reporters
)
{
return
;
if
(
metricConfig
.
getMetricReporterList
()
!=
null
}
&&
metricConfig
.
getMetricReporterList
().
contains
(
reporter
.
getReporterType
())
for
(
ReporterType
reporterType
:
metricConfig
.
getMetricReporterList
())
{
&&
reporter
Reporter
reporter
=
null
;
.
getClass
()
switch
(
reporterType
)
{
.
getName
()
case
JMX:
.
toLowerCase
()
ServiceLoader
<
JmxReporter
>
reporters
=
ServiceLoader
.
load
(
JmxReporter
.
class
);
.
contains
(
metricConfig
.
getMetricFrameType
().
name
().
toLowerCase
()))
{
for
(
JmxReporter
jmxReporter
:
reporters
)
{
reporter
.
setMetricManager
(
metricManager
);
if
(
jmxReporter
compositeReporter
.
addReporter
(
reporter
);
.
getClass
()
.
getName
()
.
toLowerCase
()
.
contains
(
metricConfig
.
getMetricFrameType
().
name
().
toLowerCase
()))
{
jmxReporter
.
setMetricManager
(
metricManager
);
reporter
=
jmxReporter
;
}
}
break
;
case
PROMETHEUS:
reporter
=
new
PrometheusReporter
(
metricManager
);
break
;
case
IOTDB:
reporter
=
new
SessionIoTDBReporter
(
metricManager
);
break
;
default
:
continue
;
}
if
(
reporter
==
null
)
{
logger
.
error
(
"Failed to load reporter which type is {}"
,
reporterType
);
continue
;
}
}
compositeReporter
.
addReporter
(
reporter
);
}
}
}
}
...
@@ -154,7 +177,7 @@ public abstract class AbstractMetricService {
...
@@ -154,7 +177,7 @@ public abstract class AbstractMetricService {
*
*
* @param internalReporter the new internal reporter
* @param internalReporter the new internal reporter
*/
*/
public
abstract
void
reloadInternalReporter
(
InternalReporter
internalReporter
);
public
abstract
void
reloadInternalReporter
(
Internal
IoTDB
Reporter
internalReporter
);
/**
/**
* Reload metric service
* Reload metric service
...
@@ -243,7 +266,7 @@ public abstract class AbstractMetricService {
...
@@ -243,7 +266,7 @@ public abstract class AbstractMetricService {
public
Counter
getOrCreateCounterWithInternalReport
(
public
Counter
getOrCreateCounterWithInternalReport
(
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
Counter
counter
=
metricManager
.
getOrCreateCounter
(
metric
,
metricLevel
,
tags
);
Counter
counter
=
metricManager
.
getOrCreateCounter
(
metric
,
metricLevel
,
tags
);
report
(
counter
,
metric
,
tags
);
internalReporter
.
writeMetricToIoTDB
(
counter
,
metric
,
tags
);
return
counter
;
return
counter
;
}
}
...
@@ -251,7 +274,7 @@ public abstract class AbstractMetricService {
...
@@ -251,7 +274,7 @@ public abstract class AbstractMetricService {
public
<
T
>
AutoGauge
createAutoGaugeWithInternalReport
(
public
<
T
>
AutoGauge
createAutoGaugeWithInternalReport
(
String
metric
,
MetricLevel
metricLevel
,
T
obj
,
ToLongFunction
<
T
>
mapper
,
String
...
tags
)
{
String
metric
,
MetricLevel
metricLevel
,
T
obj
,
ToLongFunction
<
T
>
mapper
,
String
...
tags
)
{
AutoGauge
gauge
=
metricManager
.
createAutoGauge
(
metric
,
metricLevel
,
obj
,
mapper
,
tags
);
AutoGauge
gauge
=
metricManager
.
createAutoGauge
(
metric
,
metricLevel
,
obj
,
mapper
,
tags
);
report
(
gauge
,
metric
,
tags
);
internalReporter
.
addAutoGauge
(
gauge
,
metric
,
tags
);
return
gauge
;
return
gauge
;
}
}
...
@@ -259,7 +282,7 @@ public abstract class AbstractMetricService {
...
@@ -259,7 +282,7 @@ public abstract class AbstractMetricService {
public
Gauge
getOrCreateGaugeWithInternalReport
(
public
Gauge
getOrCreateGaugeWithInternalReport
(
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
Gauge
gauge
=
metricManager
.
getOrCreateGauge
(
metric
,
metricLevel
,
tags
);
Gauge
gauge
=
metricManager
.
getOrCreateGauge
(
metric
,
metricLevel
,
tags
);
report
(
gauge
,
metric
,
tags
);
internalReporter
.
writeMetricToIoTDB
(
gauge
,
metric
,
tags
);
return
gauge
;
return
gauge
;
}
}
...
@@ -267,7 +290,7 @@ public abstract class AbstractMetricService {
...
@@ -267,7 +290,7 @@ public abstract class AbstractMetricService {
public
Rate
getOrCreateRateWithInternalReport
(
public
Rate
getOrCreateRateWithInternalReport
(
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
Rate
rate
=
metricManager
.
getOrCreateRate
(
metric
,
metricLevel
,
tags
);
Rate
rate
=
metricManager
.
getOrCreateRate
(
metric
,
metricLevel
,
tags
);
report
(
rate
,
metric
,
tags
);
internalReporter
.
writeMetricToIoTDB
(
rate
,
metric
,
tags
);
return
rate
;
return
rate
;
}
}
...
@@ -275,7 +298,7 @@ public abstract class AbstractMetricService {
...
@@ -275,7 +298,7 @@ public abstract class AbstractMetricService {
public
Histogram
getOrCreateHistogramWithInternalReport
(
public
Histogram
getOrCreateHistogramWithInternalReport
(
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
Histogram
histogram
=
metricManager
.
getOrCreateHistogram
(
metric
,
metricLevel
,
tags
);
Histogram
histogram
=
metricManager
.
getOrCreateHistogram
(
metric
,
metricLevel
,
tags
);
report
(
histogram
,
metric
,
tags
);
internalReporter
.
writeMetricToIoTDB
(
histogram
,
metric
,
tags
);
return
histogram
;
return
histogram
;
}
}
...
@@ -283,105 +306,55 @@ public abstract class AbstractMetricService {
...
@@ -283,105 +306,55 @@ public abstract class AbstractMetricService {
public
Timer
getOrCreateTimerWithInternalReport
(
public
Timer
getOrCreateTimerWithInternalReport
(
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
Timer
timer
=
metricManager
.
getOrCreateTimer
(
metric
,
metricLevel
,
tags
);
Timer
timer
=
metricManager
.
getOrCreateTimer
(
metric
,
metricLevel
,
tags
);
report
(
timer
,
metric
,
tags
);
internalReporter
.
writeMetricToIoTDB
(
timer
,
metric
,
tags
);
return
timer
;
return
timer
;
}
}
/** Count with internal report */
/** Count with internal report */
public
void
countWithInternalReport
(
public
void
countWithInternalReport
(
long
delta
,
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
long
delta
,
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
report
(
metricManager
.
count
(
delta
,
metric
,
metricLevel
,
tags
),
metric
,
tags
);
internalReporter
.
writeMetricToIoTDB
(
metricManager
.
count
(
delta
,
metric
,
metricLevel
,
tags
),
metric
,
tags
);
}
}
/** Gauge value with internal report */
/** Gauge value with internal report */
public
void
gaugeWithInternalReport
(
public
void
gaugeWithInternalReport
(
long
value
,
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
long
value
,
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
report
(
metricManager
.
gauge
(
value
,
metric
,
metricLevel
,
tags
),
metric
,
tags
);
internalReporter
.
writeMetricToIoTDB
(
metricManager
.
gauge
(
value
,
metric
,
metricLevel
,
tags
),
metric
,
tags
);
}
}
/** Rate with internal report */
/** Rate with internal report */
public
void
rateWithInternalReport
(
public
void
rateWithInternalReport
(
long
value
,
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
long
value
,
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
report
(
metricManager
.
rate
(
value
,
metric
,
metricLevel
,
tags
),
metric
,
tags
);
internalReporter
.
writeMetricToIoTDB
(
metricManager
.
rate
(
value
,
metric
,
metricLevel
,
tags
),
metric
,
tags
);
}
}
/** Histogram with internal report */
/** Histogram with internal report */
public
void
histogramWithInternalReport
(
public
void
histogramWithInternalReport
(
long
value
,
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
long
value
,
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
report
(
metricManager
.
histogram
(
value
,
metric
,
metricLevel
,
tags
),
metric
,
tags
);
internalReporter
.
writeMetricToIoTDB
(
metricManager
.
histogram
(
value
,
metric
,
metricLevel
,
tags
),
metric
,
tags
);
}
}
/** Timer with internal report */
/** Timer with internal report */
public
void
timerWithInternalReport
(
public
void
timerWithInternalReport
(
long
delta
,
TimeUnit
timeUnit
,
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
long
delta
,
TimeUnit
timeUnit
,
String
metric
,
MetricLevel
metricLevel
,
String
...
tags
)
{
report
(
metricManager
.
timer
(
delta
,
timeUnit
,
metric
,
metricLevel
,
tags
),
metric
,
tags
);
internalReporter
.
writeMetricToIoTDB
(
metricManager
.
timer
(
delta
,
timeUnit
,
metric
,
metricLevel
,
tags
),
metric
,
tags
);
}
}
/**
public
List
<
Pair
<
String
,
String
[]>>
getAllMetricKeys
()
{
* Reporter metric internally
*
* @param metric the metric that need to report
* @param name the name of metric
* @param tags the tags of metric
*/
protected
void
report
(
IMetric
metric
,
String
name
,
String
...
tags
)
{
if
(
metric
instanceof
DoNothingMetric
)
{
return
;
}
if
(
metric
instanceof
Counter
)
{
Counter
counter
=
(
Counter
)
metric
;
internalReporter
.
updateValue
(
name
,
counter
.
count
(),
TSDataType
.
INT64
,
tags
);
}
else
if
(
metric
instanceof
AutoGauge
)
{
internalReporter
.
addAutoGauge
((
AutoGauge
)
metric
,
name
,
tags
);
}
else
if
(
metric
instanceof
Gauge
)
{
internalReporter
.
updateValue
(
name
,
((
Gauge
)
metric
).
value
(),
TSDataType
.
INT64
,
tags
);
}
else
if
(
metric
instanceof
Rate
)
{
Rate
rate
=
(
Rate
)
metric
;
Long
time
=
System
.
currentTimeMillis
();
internalReporter
.
updateValue
(
name
+
"_count"
,
rate
.
getCount
(),
TSDataType
.
INT64
,
time
,
tags
);
internalReporter
.
updateValue
(
name
+
"_mean"
,
rate
.
getMeanRate
(),
TSDataType
.
DOUBLE
,
time
,
tags
);
internalReporter
.
updateValue
(
name
+
"_1min"
,
rate
.
getOneMinuteRate
(),
TSDataType
.
DOUBLE
,
time
,
tags
);
internalReporter
.
updateValue
(
name
+
"_5min"
,
rate
.
getFiveMinuteRate
(),
TSDataType
.
DOUBLE
,
time
,
tags
);
internalReporter
.
updateValue
(
name
+
"_15min"
,
rate
.
getFifteenMinuteRate
(),
TSDataType
.
DOUBLE
,
time
,
tags
);
}
else
if
(
metric
instanceof
Histogram
)
{
Histogram
histogram
=
(
Histogram
)
metric
;
internalReporter
.
writeSnapshotAndCount
(
name
,
histogram
.
takeSnapshot
(),
tags
);
}
else
if
(
metric
instanceof
Timer
)
{
Timer
timer
=
(
Timer
)
metric
;
internalReporter
.
writeSnapshotAndCount
(
name
,
timer
.
takeSnapshot
(),
tags
);
}
}
public
List
<
String
[]>
getAllMetricKeys
()
{
return
metricManager
.
getAllMetricKeys
();
return
metricManager
.
getAllMetricKeys
();
}
}
public
Map
<
String
[],
Counter
>
getAllCounters
()
{
public
Map
<
MetricInfo
,
IMetric
>
getAllMetrics
()
{
return
metricManager
.
getAllCounters
();
return
metricManager
.
getAllMetrics
();
}
public
Map
<
String
[],
Gauge
>
getAllGauges
()
{
return
metricManager
.
getAllGauges
();
}
public
Map
<
String
[],
AutoGauge
>
getAllAutoGauges
()
{
return
metricManager
.
getAllAutoGauges
();
}
public
Map
<
String
[],
Rate
>
getAllRates
()
{
return
metricManager
.
getAllRates
();
}
public
Map
<
String
[],
Histogram
>
getAllHistograms
()
{
return
metricManager
.
getAllHistograms
();
}
}
public
Map
<
String
[],
Timer
>
getAllTimers
(
)
{
public
Map
<
MetricInfo
,
IMetric
>
getMetricsByType
(
MetricType
metricType
)
{
return
metricManager
.
get
AllTimers
(
);
return
metricManager
.
get
MetricsByType
(
metricType
);
}
}
public
void
remove
(
MetricType
type
,
String
metric
,
String
...
tags
)
{
public
void
remove
(
MetricType
type
,
String
metric
,
String
...
tags
)
{
...
...
metrics/interface/src/main/java/org/apache/iotdb/metrics/
reporter/
CompositeReporter.java
→
metrics/interface/src/main/java/org/apache/iotdb/metrics/CompositeReporter.java
浏览文件 @
91aa0341
...
@@ -17,8 +17,9 @@
...
@@ -17,8 +17,9 @@
* under the License.
* under the License.
*/
*/
package
org.apache.iotdb.metrics
.reporter
;
package
org.apache.iotdb.metrics
;
import
org.apache.iotdb.metrics.reporter.Reporter
;
import
org.apache.iotdb.metrics.utils.ReporterType
;
import
org.apache.iotdb.metrics.utils.ReporterType
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
...
metrics/interface/src/main/java/org/apache/iotdb/metrics/DoNothingMetricService.java
浏览文件 @
91aa0341
...
@@ -20,12 +20,12 @@
...
@@ -20,12 +20,12 @@
package
org.apache.iotdb.metrics
;
package
org.apache.iotdb.metrics
;
import
org.apache.iotdb.metrics.config.ReloadLevel
;
import
org.apache.iotdb.metrics.config.ReloadLevel
;
import
org.apache.iotdb.metrics.reporter.
Internal
Reporter
;
import
org.apache.iotdb.metrics.reporter.
iotdb.InternalIoTDB
Reporter
;
public
class
DoNothingMetricService
extends
AbstractMetricService
{
public
class
DoNothingMetricService
extends
AbstractMetricService
{
@Override
@Override
public
void
reloadInternalReporter
(
InternalReporter
internalReporter
)
{
public
void
reloadInternalReporter
(
Internal
IoTDB
Reporter
internalReporter
)
{
// do nothing
// do nothing
}
}
...
...
metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingHistogramSnapshot.java
浏览文件 @
91aa0341
...
@@ -21,8 +21,6 @@ package org.apache.iotdb.metrics.impl;
...
@@ -21,8 +21,6 @@ package org.apache.iotdb.metrics.impl;
import
org.apache.iotdb.metrics.type.HistogramSnapshot
;
import
org.apache.iotdb.metrics.type.HistogramSnapshot
;
import
java.io.OutputStream
;
public
class
DoNothingHistogramSnapshot
implements
HistogramSnapshot
,
DoNothingMetric
{
public
class
DoNothingHistogramSnapshot
implements
HistogramSnapshot
,
DoNothingMetric
{
@Override
@Override
public
double
getValue
(
double
quantile
)
{
public
double
getValue
(
double
quantile
)
{
...
@@ -58,9 +56,4 @@ public class DoNothingHistogramSnapshot implements HistogramSnapshot, DoNothingM
...
@@ -58,9 +56,4 @@ public class DoNothingHistogramSnapshot implements HistogramSnapshot, DoNothingM
public
long
getMin
()
{
public
long
getMin
()
{
return
0
;
return
0
;
}
}
@Override
public
void
dump
(
OutputStream
output
)
{
// do nothing
}
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/jvm/JvmClassLoaderMetrics.java
浏览文件 @
91aa0341
...
@@ -46,7 +46,7 @@ public class JvmClassLoaderMetrics implements IMetricSet {
...
@@ -46,7 +46,7 @@ public class JvmClassLoaderMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
MetricType
.
GAUGE
,
"jvm.classes.loaded.classes"
);
metricService
.
remove
(
MetricType
.
AUTO_
GAUGE
,
"jvm.classes.loaded.classes"
);
metricService
.
remove
(
MetricType
.
GAUGE
,
"jvm.classes.unloaded.classes"
);
metricService
.
remove
(
MetricType
.
AUTO_
GAUGE
,
"jvm.classes.unloaded.classes"
);
}
}
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/jvm/JvmCompileMetrics.java
浏览文件 @
91aa0341
...
@@ -48,7 +48,7 @@ public class JvmCompileMetrics implements IMetricSet {
...
@@ -48,7 +48,7 @@ public class JvmCompileMetrics implements IMetricSet {
CompilationMXBean
compilationBean
=
ManagementFactory
.
getCompilationMXBean
();
CompilationMXBean
compilationBean
=
ManagementFactory
.
getCompilationMXBean
();
if
(
compilationBean
!=
null
&&
compilationBean
.
isCompilationTimeMonitoringSupported
())
{
if
(
compilationBean
!=
null
&&
compilationBean
.
isCompilationTimeMonitoringSupported
())
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
"jvm.compilation.time.ms"
,
"compiler"
,
compilationBean
.
getName
());
MetricType
.
AUTO_
GAUGE
,
"jvm.compilation.time.ms"
,
"compiler"
,
compilationBean
.
getName
());
}
}
}
}
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/jvm/JvmGcMetrics.java
浏览文件 @
91aa0341
...
@@ -204,8 +204,8 @@ public class JvmGcMetrics implements IMetricSet, AutoCloseable {
...
@@ -204,8 +204,8 @@ public class JvmGcMetrics implements IMetricSet, AutoCloseable {
return
;
return
;
}
}
metricService
.
remove
(
MetricType
.
GAUGE
,
"jvm.gc.max.data.size.bytes"
);
metricService
.
remove
(
MetricType
.
AUTO_
GAUGE
,
"jvm.gc.max.data.size.bytes"
);
metricService
.
remove
(
MetricType
.
GAUGE
,
"jvm.gc.live.data.size.bytes"
);
metricService
.
remove
(
MetricType
.
AUTO_
GAUGE
,
"jvm.gc.live.data.size.bytes"
);
metricService
.
remove
(
MetricType
.
COUNTER
,
"jvm.gc.memory.allocated.bytes"
);
metricService
.
remove
(
MetricType
.
COUNTER
,
"jvm.gc.memory.allocated.bytes"
);
if
(
oldGenPoolName
!=
null
)
{
if
(
oldGenPoolName
!=
null
)
{
...
...
metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/jvm/JvmMemoryMetrics.java
浏览文件 @
91aa0341
...
@@ -102,13 +102,13 @@ public class JvmMemoryMetrics implements IMetricSet {
...
@@ -102,13 +102,13 @@ public class JvmMemoryMetrics implements IMetricSet {
for
(
BufferPoolMXBean
bufferPoolBean
:
for
(
BufferPoolMXBean
bufferPoolBean
:
ManagementFactory
.
getPlatformMXBeans
(
BufferPoolMXBean
.
class
))
{
ManagementFactory
.
getPlatformMXBeans
(
BufferPoolMXBean
.
class
))
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
"jvm.buffer.count.buffers"
,
"id"
,
bufferPoolBean
.
getName
());
MetricType
.
AUTO_
GAUGE
,
"jvm.buffer.count.buffers"
,
"id"
,
bufferPoolBean
.
getName
());
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
"jvm.buffer.memory.used.bytes"
,
"id"
,
bufferPoolBean
.
getName
());
MetricType
.
AUTO_
GAUGE
,
"jvm.buffer.memory.used.bytes"
,
"id"
,
bufferPoolBean
.
getName
());
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
"jvm.buffer.total.capacity.bytes"
,
"id"
,
bufferPoolBean
.
getName
());
MetricType
.
AUTO_
GAUGE
,
"jvm.buffer.total.capacity.bytes"
,
"id"
,
bufferPoolBean
.
getName
());
}
}
for
(
MemoryPoolMXBean
memoryPoolBean
:
for
(
MemoryPoolMXBean
memoryPoolBean
:
...
@@ -116,10 +116,15 @@ public class JvmMemoryMetrics implements IMetricSet {
...
@@ -116,10 +116,15 @@ public class JvmMemoryMetrics implements IMetricSet {
String
area
=
MemoryType
.
HEAP
.
equals
(
memoryPoolBean
.
getType
())
?
"heap"
:
"nonheap"
;
String
area
=
MemoryType
.
HEAP
.
equals
(
memoryPoolBean
.
getType
())
?
"heap"
:
"nonheap"
;
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
"jvm.memory.used.bytes"
,
"id"
,
memoryPoolBean
.
getName
(),
"area"
,
area
);
MetricType
.
AUTO_GAUGE
,
"jvm.memory.used.bytes"
,
"id"
,
memoryPoolBean
.
getName
(),
"area"
,
area
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
"jvm.memory.committed.bytes"
,
"jvm.memory.committed.bytes"
,
"id"
,
"id"
,
memoryPoolBean
.
getName
(),
memoryPoolBean
.
getName
(),
...
@@ -127,7 +132,12 @@ public class JvmMemoryMetrics implements IMetricSet {
...
@@ -127,7 +132,12 @@ public class JvmMemoryMetrics implements IMetricSet {
area
);
area
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
"jvm.memory.max.bytes"
,
"id"
,
memoryPoolBean
.
getName
(),
"area"
,
area
);
MetricType
.
AUTO_GAUGE
,
"jvm.memory.max.bytes"
,
"id"
,
memoryPoolBean
.
getName
(),
"area"
,
area
);
}
}
}
}
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/jvm/JvmThreadMetrics.java
浏览文件 @
91aa0341
...
@@ -73,15 +73,15 @@ public class JvmThreadMetrics implements IMetricSet {
...
@@ -73,15 +73,15 @@ public class JvmThreadMetrics implements IMetricSet {
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
ThreadMXBean
threadBean
=
ManagementFactory
.
getThreadMXBean
();
ThreadMXBean
threadBean
=
ManagementFactory
.
getThreadMXBean
();
metricService
.
remove
(
MetricType
.
GAUGE
,
"jvm.threads.peak.threads"
);
metricService
.
remove
(
MetricType
.
AUTO_
GAUGE
,
"jvm.threads.peak.threads"
);
metricService
.
remove
(
MetricType
.
GAUGE
,
"jvm.threads.daemon.threads"
);
metricService
.
remove
(
MetricType
.
AUTO_
GAUGE
,
"jvm.threads.daemon.threads"
);
metricService
.
remove
(
MetricType
.
GAUGE
,
"jvm.threads.live.threads"
);
metricService
.
remove
(
MetricType
.
AUTO_
GAUGE
,
"jvm.threads.live.threads"
);
try
{
try
{
threadBean
.
getAllThreadIds
();
threadBean
.
getAllThreadIds
();
for
(
Thread
.
State
state
:
Thread
.
State
.
values
())
{
for
(
Thread
.
State
state
:
Thread
.
State
.
values
())
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
"jvm.threads.states.threads"
,
"state"
,
getStateTagValue
(
state
));
MetricType
.
AUTO_
GAUGE
,
"jvm.threads.states.threads"
,
"state"
,
getStateTagValue
(
state
));
}
}
}
catch
(
Error
error
)
{
}
catch
(
Error
error
)
{
// An error will be thrown for unsupported operations
// An error will be thrown for unsupported operations
...
...
metrics/
dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/reporter/DropwizardMetricType
.java
→
metrics/
interface/src/main/java/org/apache/iotdb/metrics/reporter/JmxReporter
.java
浏览文件 @
91aa0341
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
* "License"); you may not use this file except in compliance
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* with the License. You may obtain a copy of the License at
*
*
*
http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* software distributed under the License is distributed on an
...
@@ -17,22 +17,11 @@
...
@@ -17,22 +17,11 @@
* under the License.
* under the License.
*/
*/
package
org.apache.iotdb.metrics.
dropwizard.
reporter
;
package
org.apache.iotdb.metrics.reporter
;
public
enum
DropwizardMetricType
{
import
org.apache.iotdb.metrics.AbstractMetricManager
;
COUNTER
(
"counter"
),
GAUGE
(
"gauge"
),
SUMMARY
(
"summary"
),
HISTOGRAM
(
"histogram"
),
UNTYPED
(
"untyped"
);
private
final
String
text
;
public
interface
JmxReporter
extends
Reporter
{
/** Set metric manager into reporter */
DropwizardMetricType
(
String
text
)
{
void
setMetricManager
(
AbstractMetricManager
metricManager
);
this
.
text
=
text
;
}
public
String
getText
()
{
return
text
;
}
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/Reporter.java
浏览文件 @
91aa0341
...
@@ -19,7 +19,6 @@
...
@@ -19,7 +19,6 @@
package
org.apache.iotdb.metrics.reporter
;
package
org.apache.iotdb.metrics.reporter
;
import
org.apache.iotdb.metrics.AbstractMetricManager
;
import
org.apache.iotdb.metrics.utils.ReporterType
;
import
org.apache.iotdb.metrics.utils.ReporterType
;
public
interface
Reporter
{
public
interface
Reporter
{
...
@@ -31,7 +30,4 @@ public interface Reporter {
...
@@ -31,7 +30,4 @@ public interface Reporter {
/** Get the type of reporter */
/** Get the type of reporter */
ReporterType
getReporterType
();
ReporterType
getReporterType
();
/** Set metric manager into reporter */
void
setMetricManager
(
AbstractMetricManager
metricManager
);
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/
Internal
Reporter.java
→
metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/
iotdb/InternalIoTDB
Reporter.java
浏览文件 @
91aa0341
...
@@ -17,19 +17,19 @@
...
@@ -17,19 +17,19 @@
* under the License.
* under the License.
*/
*/
package
org.apache.iotdb.metrics.reporter
;
package
org.apache.iotdb.metrics.reporter
.iotdb
;
import
org.apache.iotdb.metrics.type.AutoGauge
;
import
org.apache.iotdb.metrics.type.AutoGauge
;
import
org.apache.iotdb.metrics.type.
HistogramSnapshot
;
import
org.apache.iotdb.metrics.type.
IMetric
;
import
org.apache.iotdb.metrics.utils.InternalReporterType
;
import
org.apache.iotdb.metrics.utils.InternalReporterType
;
import
org.apache.iotdb.
tsfile.file.metadata.enums.TSDataType
;
import
org.apache.iotdb.
metrics.utils.MetricInfo
;
import
org.apache.iotdb.
tsfile.utils.Pair
;
import
org.apache.iotdb.
metrics.utils.MetricType
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
public
abstract
class
InternalReporter
{
public
abstract
class
Internal
IoTDBReporter
extends
IoTDB
Reporter
{
protected
final
Map
<
Pair
<
String
,
String
[]>,
AutoGauge
>
autoGauges
=
new
ConcurrentHashMap
<>();
protected
final
Map
<
MetricInfo
,
IMetric
>
autoGauges
=
new
ConcurrentHashMap
<>();
/**
/**
* Add autoGauge into internal reporter
* Add autoGauge into internal reporter
...
@@ -39,7 +39,8 @@ public abstract class InternalReporter {
...
@@ -39,7 +39,8 @@ public abstract class InternalReporter {
* @param tags the tags of autoGauge
* @param tags the tags of autoGauge
*/
*/
public
void
addAutoGauge
(
AutoGauge
autoGauge
,
String
name
,
String
...
tags
)
{
public
void
addAutoGauge
(
AutoGauge
autoGauge
,
String
name
,
String
...
tags
)
{
autoGauges
.
put
(
new
Pair
<>(
name
,
tags
),
autoGauge
);
MetricInfo
metricInfo
=
new
MetricInfo
(
MetricType
.
AUTO_GAUGE
,
name
,
tags
);
autoGauges
.
put
(
metricInfo
,
autoGauge
);
}
}
/**
/**
...
@@ -47,12 +48,12 @@ public abstract class InternalReporter {
...
@@ -47,12 +48,12 @@ public abstract class InternalReporter {
*
*
* @param gauges the map of autoGauge
* @param gauges the map of autoGauge
*/
*/
public
void
addAutoGauge
(
Map
<
Pair
<
String
,
String
[]>,
AutoGauge
>
gauges
)
{
public
void
addAutoGauge
(
Map
<
MetricInfo
,
IMetric
>
gauges
)
{
autoGauges
.
putAll
(
gauges
);
autoGauges
.
putAll
(
gauges
);
}
}
/** Get all autoGauges */
/** Get all autoGauges */
public
Map
<
Pair
<
String
,
String
[]>,
AutoGauge
>
getAllAutoGauge
()
{
public
Map
<
MetricInfo
,
IMetric
>
getAllAutoGauge
()
{
return
autoGauges
;
return
autoGauges
;
}
}
...
@@ -61,44 +62,6 @@ public abstract class InternalReporter {
...
@@ -61,44 +62,6 @@ public abstract class InternalReporter {
autoGauges
.
clear
();
autoGauges
.
clear
();
}
}
/**
* Update value of metric without specific time
*
* @param name the name of metric
* @param value the value of metric
* @param type the type of value
* @param tags the tags of metric
*/
public
abstract
void
updateValue
(
String
name
,
Object
value
,
TSDataType
type
,
String
...
tags
);
/**
* Update value of metric with specific time
*
* @param name the name of metric
* @param value the value of metric
* @param type the type of value
* @param time the time of value
* @param tags the tags of metric
*/
public
abstract
void
updateValue
(
String
name
,
Object
value
,
TSDataType
type
,
Long
time
,
String
...
tags
);
/**
* Update the value of HistogramSnapshot
*
* @param name the name of metric
* @param snapshot the snapshot of metric
* @param tags the tags of metric
*/
public
abstract
void
writeSnapshotAndCount
(
String
name
,
HistogramSnapshot
snapshot
,
String
...
tags
);
/** Get the type of internal reporter */
/** Get the type of internal reporter */
public
abstract
InternalReporterType
getType
();
public
abstract
InternalReporterType
getType
();
/** Start internal reporter */
public
abstract
void
start
();
/** Stop internal reporter */
public
abstract
void
stop
();
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/iotdb/IoTDBReporter.java
0 → 100644
浏览文件 @
91aa0341
/*
* 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.iotdb.metrics.reporter.iotdb
;
import
org.apache.iotdb.metrics.impl.DoNothingMetric
;
import
org.apache.iotdb.metrics.reporter.Reporter
;
import
org.apache.iotdb.metrics.type.IMetric
;
import
org.apache.iotdb.metrics.utils.IoTDBMetricsUtils
;
import
org.apache.iotdb.metrics.utils.MetricInfo
;
import
org.apache.iotdb.tsfile.file.metadata.enums.TSDataType
;
import
java.util.HashMap
;
import
java.util.Map
;
/** The reporter to IoTDB */
public
abstract
class
IoTDBReporter
implements
Reporter
{
/**
* Write metric into IoTDB
*
* @param metric the target metric
* @param name the name of metric
* @param tags the tags of metric
*/
public
void
writeMetricToIoTDB
(
IMetric
metric
,
String
name
,
String
...
tags
)
{
if
(!(
metric
instanceof
DoNothingMetric
))
{
Map
<
String
,
Object
>
values
=
new
HashMap
<>();
metric
.
constructValueMap
(
values
);
writeMetricToIoTDB
(
values
,
IoTDBMetricsUtils
.
generatePath
(
name
,
tags
),
System
.
currentTimeMillis
());
}
}
/**
* Write metric into IoTDB
*
* @param valueMap sensor -> value
* @param prefix device
* @param time write time
*/
protected
abstract
void
writeMetricToIoTDB
(
Map
<
String
,
Object
>
valueMap
,
String
prefix
,
long
time
);
/**
* Write metrics into IoTDB
*
* @param metricMap metricInfo -> IMetric
*/
public
void
writeMetricToIoTDB
(
Map
<
MetricInfo
,
IMetric
>
metricMap
)
{
Map
<
String
,
Map
<
String
,
Object
>>
values
=
new
HashMap
<>();
for
(
Map
.
Entry
<
MetricInfo
,
IMetric
>
metricEntry
:
metricMap
.
entrySet
())
{
String
prefix
=
IoTDBMetricsUtils
.
generatePath
(
metricEntry
.
getKey
());
IMetric
metric
=
metricEntry
.
getValue
();
if
(!(
metric
instanceof
DoNothingMetric
))
{
Map
<
String
,
Object
>
value
=
new
HashMap
<>();
metric
.
constructValueMap
(
value
);
values
.
put
(
prefix
,
value
);
}
}
writeMetricsToIoTDB
(
values
,
System
.
currentTimeMillis
());
}
/**
* Write metrics into IoTDB
*
* @param valueMap device -> sensor -> value
* @param time write time
*/
protected
abstract
void
writeMetricsToIoTDB
(
Map
<
String
,
Map
<
String
,
Object
>>
valueMap
,
long
time
);
/** Infer type from object */
protected
TSDataType
inferType
(
Object
value
)
{
TSDataType
dataType
;
if
(
value
instanceof
Boolean
)
{
dataType
=
TSDataType
.
BOOLEAN
;
}
else
if
(
value
instanceof
Integer
)
{
dataType
=
TSDataType
.
INT32
;
}
else
if
(
value
instanceof
Long
)
{
dataType
=
TSDataType
.
INT64
;
}
else
if
(
value
instanceof
Double
)
{
dataType
=
TSDataType
.
DOUBLE
;
}
else
{
dataType
=
TSDataType
.
TEXT
;
}
return
dataType
;
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/
MemoryInternal
Reporter.java
→
metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/
iotdb/MemoryInternalIoTDB
Reporter.java
浏览文件 @
91aa0341
...
@@ -17,41 +17,41 @@
...
@@ -17,41 +17,41 @@
* under the License.
* under the License.
*/
*/
package
org.apache.iotdb.metrics.reporter
;
package
org.apache.iotdb.metrics.reporter
.iotdb
;
import
org.apache.iotdb.metrics.type.HistogramSnapshot
;
import
org.apache.iotdb.metrics.utils.InternalReporterType
;
import
org.apache.iotdb.metrics.utils.InternalReporterType
;
import
org.apache.iotdb.
tsfile.file.metadata.enums.TSData
Type
;
import
org.apache.iotdb.
metrics.utils.Reporter
Type
;
public
class
MemoryInternalReporter
extends
InternalReporter
{
import
java.util.Map
;
public
class
MemoryInternalIoTDBReporter
extends
InternalIoTDBReporter
{
@Override
@Override
public
void
updateValue
(
String
name
,
Object
value
,
TSDataType
type
,
String
...
tags
)
{
public
InternalReporterType
getType
(
)
{
// do nothing
return
InternalReporterType
.
MEMORY
;
}
}
@Override
@Override
p
ublic
void
updateValue
(
String
name
,
Object
value
,
TSDataType
type
,
Long
time
,
String
...
tags
)
{
p
rotected
void
writeMetricToIoTDB
(
Map
<
String
,
Object
>
valueMap
,
String
prefix
,
long
time
)
{
// do nothing
// do nothing
}
}
@Override
@Override
p
ublic
void
writeSnapshotAndCount
(
String
name
,
HistogramSnapshot
snapshot
,
String
...
tags
)
{
p
rotected
void
writeMetricsToIoTDB
(
Map
<
String
,
Map
<
String
,
Object
>>
valueMap
,
long
time
)
{
// do nothing
// do nothing
}
}
@Override
@Override
public
InternalReporterType
getType
()
{
public
boolean
start
()
{
return
InternalReporterType
.
MEMORY
;
return
false
;
}
}
@Override
@Override
public
void
start
()
{
public
boolean
stop
()
{
// do nothing
return
false
;
}
}
@Override
@Override
public
void
stop
()
{
public
ReporterType
getReporterType
()
{
clear
()
;
return
ReporterType
.
IOTDB
;
}
}
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/iotdb/SessionIoTDBReporter.java
0 → 100644
浏览文件 @
91aa0341
/*
* 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.iotdb.metrics.reporter.iotdb
;
import
org.apache.iotdb.metrics.AbstractMetricManager
;
import
org.apache.iotdb.metrics.config.MetricConfig
;
import
org.apache.iotdb.metrics.config.MetricConfigDescriptor
;
import
org.apache.iotdb.metrics.type.IMetric
;
import
org.apache.iotdb.metrics.utils.IoTDBMetricsUtils
;
import
org.apache.iotdb.metrics.utils.MetricInfo
;
import
org.apache.iotdb.metrics.utils.ReporterType
;
import
org.apache.iotdb.rpc.IoTDBConnectionException
;
import
org.apache.iotdb.rpc.StatementExecutionException
;
import
org.apache.iotdb.session.pool.SessionDataSetWrapper
;
import
org.apache.iotdb.session.pool.SessionPool
;
import
org.apache.iotdb.tsfile.file.metadata.enums.TSDataType
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
public
class
SessionIoTDBReporter
extends
IoTDBReporter
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
SessionIoTDBReporter
.
class
);
private
static
final
MetricConfig
.
IoTDBReporterConfig
ioTDBReporterConfig
=
MetricConfigDescriptor
.
getInstance
().
getMetricConfig
().
getIoTDBReporterConfig
();
private
Future
<?>
currentServiceFuture
;
private
final
ScheduledExecutorService
service
=
Executors
.
newSingleThreadScheduledExecutor
();
/** The manager of metrics */
protected
AbstractMetricManager
metricManager
;
/** The session pool to write metrics */
protected
SessionPool
sessionPool
;
public
SessionIoTDBReporter
(
AbstractMetricManager
metricManager
)
{
this
.
metricManager
=
metricManager
;
this
.
sessionPool
=
new
SessionPool
(
ioTDBReporterConfig
.
getHost
(),
ioTDBReporterConfig
.
getPort
(),
ioTDBReporterConfig
.
getUsername
(),
ioTDBReporterConfig
.
getPassword
(),
ioTDBReporterConfig
.
getMaxConnectionNumber
());
try
(
SessionDataSetWrapper
result
=
this
.
sessionPool
.
executeQueryStatement
(
"SHOW DATABASES "
+
IoTDBMetricsUtils
.
DATABASE
))
{
if
(!
result
.
hasNext
())
{
this
.
sessionPool
.
createDatabase
(
IoTDBMetricsUtils
.
DATABASE
);
}
}
catch
(
IoTDBConnectionException
e
)
{
LOGGER
.
error
(
"CheckOrCreateStorageGroup failed because "
,
e
);
}
catch
(
StatementExecutionException
e
)
{
// do nothing
}
}
@Override
@SuppressWarnings
(
"unsafeThreadSchedule"
)
public
boolean
start
()
{
if
(
currentServiceFuture
==
null
)
{
currentServiceFuture
=
service
.
scheduleAtFixedRate
(
()
->
{
try
{
Map
<
String
,
Map
<
String
,
Object
>>
values
=
new
HashMap
<>();
for
(
Map
.
Entry
<
MetricInfo
,
IMetric
>
metricEntry
:
metricManager
.
getAllMetrics
().
entrySet
())
{
String
prefix
=
IoTDBMetricsUtils
.
generatePath
(
metricEntry
.
getKey
());
Map
<
String
,
Object
>
value
=
new
HashMap
<>();
metricEntry
.
getValue
().
constructValueMap
(
value
);
values
.
put
(
prefix
,
value
);
}
writeMetricsToIoTDB
(
values
,
System
.
currentTimeMillis
());
}
catch
(
Throwable
t
)
{
LOGGER
.
error
(
"Schedule task failed"
,
t
);
}
},
1
,
MetricConfigDescriptor
.
getInstance
()
.
getMetricConfig
()
.
getAsyncCollectPeriodInSecond
(),
TimeUnit
.
SECONDS
);
}
return
true
;
}
@Override
public
boolean
stop
()
{
if
(
currentServiceFuture
!=
null
)
{
currentServiceFuture
.
cancel
(
true
);
currentServiceFuture
=
null
;
}
if
(
sessionPool
!=
null
)
{
sessionPool
.
close
();
}
return
true
;
}
@Override
public
ReporterType
getReporterType
()
{
return
ReporterType
.
IOTDB
;
}
@Override
protected
void
writeMetricToIoTDB
(
Map
<
String
,
Object
>
valueMap
,
String
prefix
,
long
time
)
{
List
<
String
>
sensors
=
new
ArrayList
<>();
List
<
TSDataType
>
dataTypes
=
new
ArrayList
<>();
List
<
Object
>
values
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
String
,
Object
>
sensor
:
valueMap
.
entrySet
())
{
sensors
.
add
(
sensor
.
getKey
());
dataTypes
.
add
(
inferType
(
sensor
.
getValue
()));
values
.
add
(
sensor
.
getValue
());
}
try
{
sessionPool
.
insertRecord
(
prefix
,
time
,
sensors
,
dataTypes
,
values
);
}
catch
(
IoTDBConnectionException
|
StatementExecutionException
e
)
{
LOGGER
.
warn
(
"Failed to insert record"
);
}
}
@Override
protected
void
writeMetricsToIoTDB
(
Map
<
String
,
Map
<
String
,
Object
>>
valueMap
,
long
time
)
{
List
<
String
>
deviceIds
=
new
ArrayList
<>();
List
<
Long
>
times
=
new
ArrayList
<>();
List
<
List
<
String
>>
sensors
=
new
ArrayList
<>();
List
<
List
<
TSDataType
>>
dataTypes
=
new
ArrayList
<>();
List
<
List
<
Object
>>
values
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
String
,
Map
<
String
,
Object
>>
metric
:
valueMap
.
entrySet
())
{
deviceIds
.
add
(
metric
.
getKey
());
times
.
add
(
time
);
List
<
String
>
metricSensors
=
new
ArrayList
<>();
List
<
TSDataType
>
metricDataTypes
=
new
ArrayList
<>();
List
<
Object
>
metricValues
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
String
,
Object
>
sensor
:
metric
.
getValue
().
entrySet
())
{
metricSensors
.
add
(
sensor
.
getKey
());
metricDataTypes
.
add
(
inferType
(
sensor
.
getValue
()));
metricValues
.
add
(
sensor
.
getValue
());
}
sensors
.
add
(
metricSensors
);
dataTypes
.
add
(
metricDataTypes
);
values
.
add
(
metricValues
);
}
try
{
sessionPool
.
insertRecords
(
deviceIds
,
times
,
sensors
,
dataTypes
,
values
);
}
catch
(
IoTDBConnectionException
|
StatementExecutionException
e
)
{
LOGGER
.
warn
(
"Failed to insert record"
);
}
}
}
metrics/
dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/reporter/Dropwizard
PrometheusReporter.java
→
metrics/
interface/src/main/java/org/apache/iotdb/metrics/reporter/prometheus/
PrometheusReporter.java
浏览文件 @
91aa0341
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
* "License"); you may not use this file except in compliance
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* with the License. You may obtain a copy of the License at
*
*
*
http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* software distributed under the License is distributed on an
...
@@ -17,15 +17,24 @@
...
@@ -17,15 +17,24 @@
* under the License.
* under the License.
*/
*/
package
org.apache.iotdb.metrics.
dropwizard.reporter
;
package
org.apache.iotdb.metrics.
reporter.prometheus
;
import
org.apache.iotdb.metrics.AbstractMetricManager
;
import
org.apache.iotdb.metrics.AbstractMetricManager
;
import
org.apache.iotdb.metrics.config.MetricConfig
;
import
org.apache.iotdb.metrics.config.MetricConfigDescriptor
;
import
org.apache.iotdb.metrics.config.MetricConfigDescriptor
;
import
org.apache.iotdb.metrics.dropwizard.DropwizardMetricManager
;
import
org.apache.iotdb.metrics.reporter.Reporter
;
import
org.apache.iotdb.metrics.reporter.Reporter
;
import
org.apache.iotdb.metrics.type.AutoGauge
;
import
org.apache.iotdb.metrics.type.Counter
;
import
org.apache.iotdb.metrics.type.Gauge
;
import
org.apache.iotdb.metrics.type.Histogram
;
import
org.apache.iotdb.metrics.type.HistogramSnapshot
;
import
org.apache.iotdb.metrics.type.IMetric
;
import
org.apache.iotdb.metrics.type.Rate
;
import
org.apache.iotdb.metrics.type.Timer
;
import
org.apache.iotdb.metrics.utils.MetricInfo
;
import
org.apache.iotdb.metrics.utils.MetricType
;
import
org.apache.iotdb.metrics.utils.ReporterType
;
import
org.apache.iotdb.metrics.utils.ReporterType
;
import
com.codahale.metrics.MetricRegistry
;
import
io.netty.channel.ChannelOption
;
import
io.netty.channel.ChannelOption
;
import
io.netty.channel.group.DefaultChannelGroup
;
import
io.netty.channel.group.DefaultChannelGroup
;
import
io.netty.util.concurrent.GlobalEventExecutor
;
import
io.netty.util.concurrent.GlobalEventExecutor
;
...
@@ -39,45 +48,107 @@ import java.io.IOException;
...
@@ -39,45 +48,107 @@ import java.io.IOException;
import
java.io.StringWriter
;
import
java.io.StringWriter
;
import
java.io.Writer
;
import
java.io.Writer
;
import
java.time.Duration
;
import
java.time.Duration
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Map
;
public
class
DropwizardPrometheusReporter
implements
Reporter
{
public
class
PrometheusReporter
implements
Reporter
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
DropwizardPrometheusReporter
.
class
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
PrometheusReporter
.
class
);
private
static
final
MetricConfig
metricConfig
=
MetricConfigDescriptor
.
getInstance
().
getMetricConfig
();
private
AbstractMetricManager
metricManager
;
private
DisposableServer
httpServer
;
private
AbstractMetricManager
dropwizardMetricManager
=
null
;
public
PrometheusReporter
(
AbstractMetricManager
metricManager
)
{
private
DisposableServer
httpServer
=
null
;
this
.
metricManager
=
metricManager
;
}
@Override
@Override
public
boolean
start
()
{
public
boolean
start
()
{
if
(
httpServer
!=
null
)
{
if
(
httpServer
!=
null
)
{
return
false
;
return
false
;
}
}
int
port
=
MetricConfigDescriptor
.
getInstance
().
getMetricConfig
().
getPrometheusReporterPort
();
httpServer
=
httpServer
=
HttpServer
.
create
()
HttpServer
.
create
()
.
option
(
ChannelOption
.
CONNECT_TIMEOUT_MILLIS
,
2000
)
.
option
(
ChannelOption
.
CONNECT_TIMEOUT_MILLIS
,
2000
)
.
channelGroup
(
new
DefaultChannelGroup
(
GlobalEventExecutor
.
INSTANCE
))
.
channelGroup
(
new
DefaultChannelGroup
(
GlobalEventExecutor
.
INSTANCE
))
.
port
(
port
)
.
port
(
metricConfig
.
getPrometheusReporterPort
()
)
.
route
(
.
route
(
routes
->
routes
->
routes
.
get
(
routes
.
get
(
"/metrics"
,
"/metrics"
,
(
request
,
response
)
->
response
.
sendString
(
Mono
.
just
(
scrape
()))))
(
request
,
response
)
->
response
.
sendString
(
Mono
.
just
(
scrape
()))))
.
bindNow
();
.
bindNow
();
LOGGER
.
info
(
LOGGER
.
info
(
"http server for metrics started, listen on {}"
,
port
);
"http server for metrics started, listen on {}"
,
metricConfig
.
getPrometheusReporterPort
()
);
return
true
;
return
true
;
}
}
private
String
scrape
()
{
private
String
scrape
()
{
MetricRegistry
metricRegistry
=
((
DropwizardMetricManager
)
dropwizardMetricManager
).
getMetricRegistry
();
Writer
writer
=
new
StringWriter
();
Writer
writer
=
new
StringWriter
();
PrometheusTextWriter
prometheusTextWriter
=
new
PrometheusTextWriter
(
writer
);
PrometheusTextWriter
prometheusTextWriter
=
new
PrometheusTextWriter
(
writer
);
DropwizardMetricsExporter
dropwizardMetricsExporter
=
new
DropwizardMetricsExporter
(
metricRegistry
,
prometheusTextWriter
);
String
result
;
String
result
=
""
;
try
{
try
{
dropwizardMetricsExporter
.
scrape
();
for
(
Map
.
Entry
<
MetricInfo
,
IMetric
>
metricEntry
:
metricManager
.
getAllMetrics
().
entrySet
())
{
MetricInfo
metricInfo
=
metricEntry
.
getKey
();
IMetric
metric
=
metricEntry
.
getValue
();
String
name
=
metricInfo
.
getName
().
replaceAll
(
"[^a-zA-Z0-9:_\\]\\[]"
,
"_"
);
MetricType
metricType
=
metricInfo
.
getMetaInfo
().
getType
();
if
(
metric
instanceof
Counter
)
{
name
+=
"_total"
;
prometheusTextWriter
.
writeHelp
(
name
);
prometheusTextWriter
.
writeType
(
name
,
metricInfo
.
getMetaInfo
().
getType
());
Counter
counter
=
(
Counter
)
metric
;
prometheusTextWriter
.
writeSample
(
name
,
metricInfo
.
getTags
(),
counter
.
count
());
}
else
if
(
metric
instanceof
Gauge
)
{
prometheusTextWriter
.
writeHelp
(
name
);
prometheusTextWriter
.
writeType
(
name
,
metricInfo
.
getMetaInfo
().
getType
());
Gauge
gauge
=
(
Gauge
)
metric
;
prometheusTextWriter
.
writeSample
(
name
,
metricInfo
.
getTags
(),
gauge
.
value
());
}
else
if
(
metric
instanceof
AutoGauge
)
{
prometheusTextWriter
.
writeHelp
(
name
);
prometheusTextWriter
.
writeType
(
name
,
metricInfo
.
getMetaInfo
().
getType
());
AutoGauge
gauge
=
(
AutoGauge
)
metric
;
prometheusTextWriter
.
writeSample
(
name
,
metricInfo
.
getTags
(),
gauge
.
value
());
}
else
if
(
metric
instanceof
Histogram
)
{
Histogram
histogram
=
(
Histogram
)
metric
;
HistogramSnapshot
snapshot
=
histogram
.
takeSnapshot
();
writeSnapshotAndCount
(
name
,
metricInfo
.
getTags
(),
metricType
,
snapshot
,
histogram
.
count
(),
prometheusTextWriter
);
}
else
if
(
metric
instanceof
Rate
)
{
name
+=
"_total"
;
prometheusTextWriter
.
writeHelp
(
name
);
prometheusTextWriter
.
writeType
(
name
,
metricInfo
.
getMetaInfo
().
getType
());
Rate
rate
=
(
Rate
)
metric
;
prometheusTextWriter
.
writeSample
(
name
,
metricInfo
.
getTags
(),
rate
.
getCount
());
prometheusTextWriter
.
writeSample
(
name
,
addTags
(
metricInfo
.
getTags
(),
"rate"
,
"m1"
),
rate
.
getOneMinuteRate
());
prometheusTextWriter
.
writeSample
(
name
,
addTags
(
metricInfo
.
getTags
(),
"rate"
,
"m5"
),
rate
.
getFiveMinuteRate
());
prometheusTextWriter
.
writeSample
(
name
,
addTags
(
metricInfo
.
getTags
(),
"rate"
,
"m15"
),
rate
.
getFifteenMinuteRate
());
prometheusTextWriter
.
writeSample
(
name
,
addTags
(
metricInfo
.
getTags
(),
"rate"
,
"mean"
),
rate
.
getMeanRate
());
}
else
if
(
metric
instanceof
Timer
)
{
Timer
timer
=
(
Timer
)
metric
;
HistogramSnapshot
snapshot
=
timer
.
takeSnapshot
();
name
+=
"_seconds"
;
writeSnapshotAndCount
(
name
,
metricInfo
.
getTags
(),
metricType
,
snapshot
,
timer
.
getImmutableRate
().
getCount
(),
prometheusTextWriter
);
}
}
result
=
writer
.
toString
();
result
=
writer
.
toString
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
// This actually never happens since StringWriter::write() doesn't throw any IOException
// This actually never happens since StringWriter::write() doesn't throw any IOException
...
@@ -92,6 +163,44 @@ public class DropwizardPrometheusReporter implements Reporter {
...
@@ -92,6 +163,44 @@ public class DropwizardPrometheusReporter implements Reporter {
return
result
;
return
result
;
}
}
private
void
writeSnapshotAndCount
(
String
name
,
Map
<
String
,
String
>
tags
,
MetricType
type
,
HistogramSnapshot
snapshot
,
long
count
,
PrometheusTextWriter
prometheusTextWriter
)
throws
IOException
{
prometheusTextWriter
.
writeHelp
(
name
);
prometheusTextWriter
.
writeType
(
name
,
type
);
prometheusTextWriter
.
writeSample
(
name
+
"_max"
,
tags
,
snapshot
.
getMax
());
prometheusTextWriter
.
writeSample
(
name
+
"_sum"
,
tags
,
Arrays
.
stream
(
snapshot
.
getValues
()).
sum
());
prometheusTextWriter
.
writeSample
(
name
+
"_count"
,
tags
,
count
);
prometheusTextWriter
.
writeSample
(
name
,
addTags
(
tags
,
"quantile"
,
"0.0"
),
snapshot
.
getValue
(
0.0
));
prometheusTextWriter
.
writeSample
(
name
,
addTags
(
tags
,
"quantile"
,
"0.25"
),
snapshot
.
getValue
(
0.25
));
prometheusTextWriter
.
writeSample
(
name
,
addTags
(
tags
,
"quantile"
,
"0.5"
),
snapshot
.
getValue
(
0.5
));
prometheusTextWriter
.
writeSample
(
name
,
addTags
(
tags
,
"quantile"
,
"0.75"
),
snapshot
.
getValue
(
0.75
));
prometheusTextWriter
.
writeSample
(
name
,
addTags
(
tags
,
"quantile"
,
"1.0"
),
snapshot
.
getValue
(
1.0
));
}
private
Map
<
String
,
String
>
addTags
(
Map
<
String
,
String
>
tags
,
String
key
,
String
value
)
{
HashMap
<
String
,
String
>
result
=
new
HashMap
<>(
tags
);
result
.
put
(
key
,
value
);
return
result
;
}
private
static
String
getHelpMessage
(
String
metric
,
MetricType
type
)
{
return
String
.
format
(
"Generated from metric import (metric=%s, type=%s)"
,
metric
,
type
.
toString
());
}
@Override
@Override
public
boolean
stop
()
{
public
boolean
stop
()
{
if
(
httpServer
!=
null
)
{
if
(
httpServer
!=
null
)
{
...
@@ -110,9 +219,4 @@ public class DropwizardPrometheusReporter implements Reporter {
...
@@ -110,9 +219,4 @@ public class DropwizardPrometheusReporter implements Reporter {
public
ReporterType
getReporterType
()
{
public
ReporterType
getReporterType
()
{
return
ReporterType
.
PROMETHEUS
;
return
ReporterType
.
PROMETHEUS
;
}
}
@Override
public
void
setMetricManager
(
AbstractMetricManager
metricManager
)
{
this
.
dropwizardMetricManager
=
metricManager
;
}
}
}
metrics/
dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/reporter
/PrometheusTextWriter.java
→
metrics/
interface/src/main/java/org/apache/iotdb/metrics/reporter/prometheus
/PrometheusTextWriter.java
浏览文件 @
91aa0341
...
@@ -17,7 +17,9 @@
...
@@ -17,7 +17,9 @@
* under the License.
* under the License.
*/
*/
package
org.apache.iotdb.metrics.dropwizard.reporter
;
package
org.apache.iotdb.metrics.reporter.prometheus
;
import
org.apache.iotdb.metrics.utils.MetricType
;
import
java.io.FilterWriter
;
import
java.io.FilterWriter
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -30,23 +32,36 @@ class PrometheusTextWriter extends FilterWriter {
...
@@ -30,23 +32,36 @@ class PrometheusTextWriter extends FilterWriter {
super
(
out
);
super
(
out
);
}
}
public
void
writeHelp
(
String
name
,
String
value
)
throws
IOException
{
public
void
writeHelp
(
String
name
)
throws
IOException
{
write
(
"# HELP "
);
write
(
"# HELP "
);
write
(
name
);
write
(
name
);
write
(
' '
);
write
(
value
);
write
(
'\n'
);
write
(
'\n'
);
}
}
public
void
writeType
(
String
name
,
Dropwizard
MetricType
type
)
throws
IOException
{
public
void
writeType
(
String
name
,
MetricType
type
)
throws
IOException
{
write
(
"# TYPE "
);
write
(
"# TYPE "
);
write
(
name
);
write
(
name
);
write
(
' '
);
write
(
' '
);
write
(
type
.
getText
());
switch
(
type
)
{
case
GAUGE:
case
AUTO_GAUGE:
write
(
"gauge"
);
break
;
case
COUNTER:
case
RATE:
write
(
"counter"
);
break
;
case
TIMER:
case
HISTOGRAM:
write
(
"summary"
);
break
;
default
:
break
;
}
write
(
'\n'
);
write
(
'\n'
);
}
}
public
void
writeSample
(
String
name
,
Map
<
String
,
String
>
labels
,
double
value
)
public
void
writeSample
(
String
name
,
Map
<
String
,
String
>
labels
,
Object
value
)
throws
IOException
{
throws
IOException
{
write
(
name
);
write
(
name
);
if
(
labels
.
size
()
>
0
)
{
if
(
labels
.
size
()
>
0
)
{
...
@@ -60,20 +75,7 @@ class PrometheusTextWriter extends FilterWriter {
...
@@ -60,20 +75,7 @@ class PrometheusTextWriter extends FilterWriter {
write
(
'}'
);
write
(
'}'
);
}
}
write
(
' '
);
write
(
' '
);
write
(
doubleToGoString
(
value
));
write
(
value
.
toString
(
));
write
(
'\n'
);
write
(
'\n'
);
}
}
private
static
String
doubleToGoString
(
double
d
)
{
if
(
d
==
Double
.
POSITIVE_INFINITY
)
{
return
"+Inf"
;
}
if
(
d
==
Double
.
NEGATIVE_INFINITY
)
{
return
"-Inf"
;
}
if
(
Double
.
isNaN
(
d
))
{
return
"NaN"
;
}
return
Double
.
toString
(
d
);
}
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/type/AutoGauge.java
浏览文件 @
91aa0341
...
@@ -19,7 +19,14 @@
...
@@ -19,7 +19,14 @@
package
org.apache.iotdb.metrics.type
;
package
org.apache.iotdb.metrics.type
;
import
java.util.Map
;
public
interface
AutoGauge
extends
IMetric
{
public
interface
AutoGauge
extends
IMetric
{
/** get value according to the state of obj */
/** get value according to the state of obj */
long
value
();
long
value
();
@Override
default
void
constructValueMap
(
Map
<
String
,
Object
>
result
)
{
result
.
put
(
"value"
,
value
());
}
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/type/Counter.java
浏览文件 @
91aa0341
...
@@ -19,6 +19,8 @@
...
@@ -19,6 +19,8 @@
package
org.apache.iotdb.metrics.type
;
package
org.apache.iotdb.metrics.type
;
import
java.util.Map
;
public
interface
Counter
extends
IMetric
{
public
interface
Counter
extends
IMetric
{
/** Counter add 1 */
/** Counter add 1 */
...
@@ -29,4 +31,9 @@ public interface Counter extends IMetric {
...
@@ -29,4 +31,9 @@ public interface Counter extends IMetric {
/** Get the value of counter */
/** Get the value of counter */
long
count
();
long
count
();
@Override
default
void
constructValueMap
(
Map
<
String
,
Object
>
result
)
{
result
.
put
(
"value"
,
count
());
}
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/type/Gauge.java
浏览文件 @
91aa0341
...
@@ -19,6 +19,8 @@
...
@@ -19,6 +19,8 @@
package
org.apache.iotdb.metrics.type
;
package
org.apache.iotdb.metrics.type
;
import
java.util.Map
;
public
interface
Gauge
extends
IMetric
{
public
interface
Gauge
extends
IMetric
{
/** Set value */
/** Set value */
...
@@ -32,4 +34,9 @@ public interface Gauge extends IMetric {
...
@@ -32,4 +34,9 @@ public interface Gauge extends IMetric {
/** Decrease the value stored in gauge */
/** Decrease the value stored in gauge */
void
decr
(
long
value
);
void
decr
(
long
value
);
@Override
default
void
constructValueMap
(
Map
<
String
,
Object
>
result
)
{
result
.
put
(
"value"
,
value
());
}
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/type/Histogram.java
浏览文件 @
91aa0341
...
@@ -19,6 +19,8 @@
...
@@ -19,6 +19,8 @@
package
org.apache.iotdb.metrics.type
;
package
org.apache.iotdb.metrics.type
;
import
java.util.Map
;
public
interface
Histogram
extends
IMetric
{
public
interface
Histogram
extends
IMetric
{
/** Update histogram by value */
/** Update histogram by value */
...
@@ -29,4 +31,10 @@ public interface Histogram extends IMetric {
...
@@ -29,4 +31,10 @@ public interface Histogram extends IMetric {
/** Take snapshot of histogram */
/** Take snapshot of histogram */
HistogramSnapshot
takeSnapshot
();
HistogramSnapshot
takeSnapshot
();
@Override
default
void
constructValueMap
(
Map
<
String
,
Object
>
result
)
{
result
.
put
(
"count"
,
count
());
takeSnapshot
().
constructValueMap
(
result
);
}
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/type/HistogramSnapshot.java
浏览文件 @
91aa0341
...
@@ -19,10 +19,11 @@
...
@@ -19,10 +19,11 @@
package
org.apache.iotdb.metrics.type
;
package
org.apache.iotdb.metrics.type
;
import
java.io.OutputStream
;
import
java.util.Arrays
;
import
java.util.Map
;
/** Used by timer and histogram. */
/** Used by timer and histogram. */
public
interface
HistogramSnapshot
{
public
interface
HistogramSnapshot
extends
IMetric
{
/** Get value by quantile */
/** Get value by quantile */
double
getValue
(
double
quantile
);
double
getValue
(
double
quantile
);
...
@@ -45,6 +46,15 @@ public interface HistogramSnapshot {
...
@@ -45,6 +46,15 @@ public interface HistogramSnapshot {
/** Get max value in values */
/** Get max value in values */
long
getMax
();
long
getMax
();
/** Writes the values of the snapshot to the given stream */
@Override
void
dump
(
OutputStream
output
);
default
void
constructValueMap
(
Map
<
String
,
Object
>
result
)
{
result
.
put
(
"max"
,
getMax
());
result
.
put
(
"sum"
,
Arrays
.
stream
(
getValues
()).
sum
());
result
.
put
(
"p0"
,
getValue
(
0.0
));
result
.
put
(
"p25"
,
getValue
(
0.25
));
result
.
put
(
"p50"
,
getValue
(
0.5
));
result
.
put
(
"p75"
,
getValue
(
0.75
));
result
.
put
(
"p100"
,
getValue
(
1.0
));
}
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/type/IMetric.java
浏览文件 @
91aa0341
...
@@ -19,4 +19,8 @@
...
@@ -19,4 +19,8 @@
package
org.apache.iotdb.metrics.type
;
package
org.apache.iotdb.metrics.type
;
public
interface
IMetric
{}
import
java.util.Map
;
public
interface
IMetric
{
void
constructValueMap
(
Map
<
String
,
Object
>
result
);
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/type/Rate.java
浏览文件 @
91aa0341
...
@@ -19,6 +19,8 @@
...
@@ -19,6 +19,8 @@
package
org.apache.iotdb.metrics.type
;
package
org.apache.iotdb.metrics.type
;
import
java.util.Map
;
public
interface
Rate
extends
IMetric
{
public
interface
Rate
extends
IMetric
{
/** Get the value of rate */
/** Get the value of rate */
...
@@ -41,4 +43,13 @@ public interface Rate extends IMetric {
...
@@ -41,4 +43,13 @@ public interface Rate extends IMetric {
/** Mark n in rate */
/** Mark n in rate */
void
mark
(
long
n
);
void
mark
(
long
n
);
@Override
default
void
constructValueMap
(
Map
<
String
,
Object
>
result
)
{
result
.
put
(
"count"
,
getCount
());
result
.
put
(
"mean"
,
getMeanRate
());
result
.
put
(
"m1"
,
getOneMinuteRate
());
result
.
put
(
"m5"
,
getFiveMinuteRate
());
result
.
put
(
"m15"
,
getFifteenMinuteRate
());
}
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/type/Timer.java
浏览文件 @
91aa0341
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
package
org.apache.iotdb.metrics.type
;
package
org.apache.iotdb.metrics.type
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
public
interface
Timer
extends
IMetric
{
public
interface
Timer
extends
IMetric
{
...
@@ -46,4 +47,10 @@ public interface Timer extends IMetric {
...
@@ -46,4 +47,10 @@ public interface Timer extends IMetric {
/** It's not safe to use the update interface of this rate */
/** It's not safe to use the update interface of this rate */
Rate
getImmutableRate
();
Rate
getImmutableRate
();
@Override
default
void
constructValueMap
(
Map
<
String
,
Object
>
result
)
{
takeSnapshot
().
constructValueMap
(
result
);
getImmutableRate
().
constructValueMap
(
result
);
}
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/utils/IoTDBMetricsUtils.java
浏览文件 @
91aa0341
...
@@ -21,37 +21,22 @@ package org.apache.iotdb.metrics.utils;
...
@@ -21,37 +21,22 @@ package org.apache.iotdb.metrics.utils;
import
org.apache.iotdb.metrics.config.MetricConfig
;
import
org.apache.iotdb.metrics.config.MetricConfig
;
import
org.apache.iotdb.metrics.config.MetricConfigDescriptor
;
import
org.apache.iotdb.metrics.config.MetricConfigDescriptor
;
import
org.apache.iotdb.rpc.IoTDBConnectionException
;
import
org.apache.iotdb.rpc.StatementExecutionException
;
import
org.apache.iotdb.session.pool.SessionDataSetWrapper
;
import
org.apache.iotdb.session.pool.SessionPool
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.Map
;
import
java.util.Map
;
public
class
IoTDBMetricsUtils
{
public
class
IoTDBMetricsUtils
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
IoTDBMetricsUtils
.
class
);
private
static
final
MetricConfig
metricConfig
=
private
static
final
MetricConfig
metricConfig
=
MetricConfigDescriptor
.
getInstance
().
getMetricConfig
();
MetricConfigDescriptor
.
getInstance
().
getMetricConfig
();
private
static
final
String
STORAGE_GROUP
=
"root.__system"
;
public
static
final
String
DATABASE
=
"root.__system"
;
/** Generate the path of metric by metricInfo */
public
static
String
generatePath
(
MetricInfo
metricInfo
)
{
return
generatePath
(
metricInfo
.
getName
(),
metricInfo
.
getTags
());
}
/** Generate the path of metric with tags array */
public
static
String
generatePath
(
String
name
,
String
...
tags
)
{
public
static
String
generatePath
(
String
name
,
String
...
tags
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
StringBuilder
stringBuilder
=
generateMetric
(
name
);
stringBuilder
.
append
(
STORAGE_GROUP
)
.
append
(
"."
)
.
append
(
metricConfig
.
getIoTDBReporterConfig
().
getLocation
())
.
append
(
".`"
)
.
append
(
metricConfig
.
getRpcAddress
())
.
append
(
":"
)
.
append
(
metricConfig
.
getRpcPort
())
.
append
(
"`"
)
.
append
(
"."
)
.
append
(
"`"
)
.
append
(
name
)
.
append
(
"`"
);
for
(
int
i
=
0
;
i
<
tags
.
length
;
i
+=
2
)
{
for
(
int
i
=
0
;
i
<
tags
.
length
;
i
+=
2
)
{
stringBuilder
stringBuilder
.
append
(
"."
)
.
append
(
"."
)
...
@@ -64,10 +49,26 @@ public class IoTDBMetricsUtils {
...
@@ -64,10 +49,26 @@ public class IoTDBMetricsUtils {
return
stringBuilder
.
toString
();
return
stringBuilder
.
toString
();
}
}
public
static
String
generatePath
(
String
name
,
Map
<
String
,
String
>
labels
)
{
/** Generate the path of metric with tags map */
public
static
String
generatePath
(
String
name
,
Map
<
String
,
String
>
tags
)
{
StringBuilder
stringBuilder
=
generateMetric
(
name
);
for
(
Map
.
Entry
<
String
,
String
>
entry
:
tags
.
entrySet
())
{
stringBuilder
.
append
(
"."
)
.
append
(
"`"
)
.
append
(
entry
.
getKey
())
.
append
(
"="
)
.
append
(
entry
.
getValue
())
.
append
(
"`"
);
}
return
stringBuilder
.
toString
();
}
/** Generate the path of metric */
private
static
StringBuilder
generateMetric
(
String
name
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
StringBuilder
stringBuilder
=
new
StringBuilder
();
stringBuilder
stringBuilder
.
append
(
STORAGE_GROUP
)
.
append
(
DATABASE
)
.
append
(
"."
)
.
append
(
"."
)
.
append
(
metricConfig
.
getIoTDBReporterConfig
().
getLocation
())
.
append
(
metricConfig
.
getIoTDBReporterConfig
().
getLocation
())
.
append
(
".`"
)
.
append
(
".`"
)
...
@@ -79,28 +80,6 @@ public class IoTDBMetricsUtils {
...
@@ -79,28 +80,6 @@ public class IoTDBMetricsUtils {
.
append
(
"`"
)
.
append
(
"`"
)
.
append
(
name
)
.
append
(
name
)
.
append
(
"`"
);
.
append
(
"`"
);
for
(
Map
.
Entry
<
String
,
String
>
entry
:
labels
.
entrySet
())
{
return
stringBuilder
;
stringBuilder
.
append
(
"."
)
.
append
(
"`"
)
.
append
(
entry
.
getKey
())
.
append
(
"="
)
.
append
(
entry
.
getValue
())
.
append
(
"`"
);
}
return
stringBuilder
.
toString
();
}
public
static
void
checkOrCreateStorageGroup
(
SessionPool
session
)
{
try
(
SessionDataSetWrapper
result
=
session
.
executeQueryStatement
(
"SHOW DATABASES "
+
STORAGE_GROUP
))
{
if
(!
result
.
hasNext
())
{
session
.
setStorageGroup
(
STORAGE_GROUP
);
}
}
catch
(
IoTDBConnectionException
e
)
{
logger
.
error
(
"CheckOrCreateStorageGroup failed because "
,
e
);
}
catch
(
StatementExecutionException
e
)
{
// do nothing
}
}
}
}
}
metrics/interface/src/main/java/org/apache/iotdb/metrics/utils/MetricInfo.java
浏览文件 @
91aa0341
...
@@ -19,6 +19,8 @@
...
@@ -19,6 +19,8 @@
package
org.apache.iotdb.metrics.utils
;
package
org.apache.iotdb.metrics.utils
;
import
org.apache.iotdb.tsfile.utils.Pair
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -74,16 +76,15 @@ public class MetricInfo {
...
@@ -74,16 +76,15 @@ public class MetricInfo {
return
metaInfo
;
return
metaInfo
;
}
}
/** Convert the metric name
to string array.
*/
/** Convert the metric name
and tag into pair
*/
public
String
[]
toStringArray
()
{
public
Pair
<
String
,
String
[]>
toStringArray
()
{
List
<
String
>
allNames
=
new
ArrayList
<>();
List
<
String
>
allNames
=
new
ArrayList
<>();
allNames
.
add
(
name
);
tags
.
forEach
(
tags
.
forEach
(
(
k
,
v
)
->
{
(
k
,
v
)
->
{
allNames
.
add
(
k
);
allNames
.
add
(
k
);
allNames
.
add
(
v
);
allNames
.
add
(
v
);
});
});
return
allNames
.
toArray
(
new
String
[
0
]
);
return
new
Pair
<>(
name
,
allNames
.
toArray
(
new
String
[
0
])
);
}
}
@Override
@Override
...
...
metrics/interface/src/main/java/org/apache/iotdb/metrics/utils/MetricType.java
浏览文件 @
91aa0341
...
@@ -21,6 +21,7 @@ package org.apache.iotdb.metrics.utils;
...
@@ -21,6 +21,7 @@ package org.apache.iotdb.metrics.utils;
public
enum
MetricType
{
public
enum
MetricType
{
COUNTER
,
COUNTER
,
AUTO_GAUGE
,
GAUGE
,
GAUGE
,
RATE
,
RATE
,
HISTOGRAM
,
HISTOGRAM
,
...
...
metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/MicrometerMetricManager.java
浏览文件 @
91aa0341
...
@@ -117,6 +117,7 @@ public class MicrometerMetricManager extends AbstractMetricManager {
...
@@ -117,6 +117,7 @@ public class MicrometerMetricManager extends AbstractMetricManager {
switch
(
type
)
{
switch
(
type
)
{
case
COUNTER:
case
COUNTER:
return
Meter
.
Type
.
COUNTER
;
return
Meter
.
Type
.
COUNTER
;
case
AUTO_GAUGE:
case
GAUGE:
case
GAUGE:
case
RATE:
case
RATE:
return
Meter
.
Type
.
GAUGE
;
return
Meter
.
Type
.
GAUGE
;
...
...
metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/reporter/IoTDBMeterRegistry.java
已删除
100644 → 0
浏览文件 @
9f12b58c
/*
* 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.iotdb.metrics.micrometer.reporter
;
import
org.apache.iotdb.metrics.config.MetricConfig
;
import
org.apache.iotdb.metrics.config.MetricConfigDescriptor
;
import
org.apache.iotdb.metrics.utils.IoTDBMetricsUtils
;
import
org.apache.iotdb.rpc.IoTDBConnectionException
;
import
org.apache.iotdb.rpc.StatementExecutionException
;
import
org.apache.iotdb.session.pool.SessionPool
;
import
org.apache.iotdb.tsfile.file.metadata.enums.TSDataType
;
import
io.micrometer.core.instrument.Clock
;
import
io.micrometer.core.instrument.Meter
;
import
io.micrometer.core.instrument.Tag
;
import
io.micrometer.core.instrument.distribution.HistogramSnapshot
;
import
io.micrometer.core.instrument.step.StepMeterRegistry
;
import
io.micrometer.core.instrument.step.StepRegistryConfig
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
public
class
IoTDBMeterRegistry
extends
StepMeterRegistry
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
IoTDBMeterRegistry
.
class
);
private
static
final
MetricConfig
.
IoTDBReporterConfig
ioTDBReporterConfig
=
MetricConfigDescriptor
.
getInstance
().
getMetricConfig
().
getIoTDBReporterConfig
();
private
final
SessionPool
sessionPool
;
public
IoTDBMeterRegistry
(
StepRegistryConfig
config
,
Clock
clock
)
{
super
(
config
,
clock
);
this
.
sessionPool
=
new
SessionPool
(
ioTDBReporterConfig
.
getHost
(),
ioTDBReporterConfig
.
getPort
(),
ioTDBReporterConfig
.
getUsername
(),
ioTDBReporterConfig
.
getPassword
(),
ioTDBReporterConfig
.
getMaxConnectionNumber
());
IoTDBMetricsUtils
.
checkOrCreateStorageGroup
(
sessionPool
);
}
@Override
public
void
stop
()
{
super
.
stop
();
if
(
sessionPool
!=
null
)
{
sessionPool
.
close
();
}
}
@Override
protected
void
publish
()
{
Long
time
=
System
.
currentTimeMillis
();
getMeters
()
.
forEach
(
meter
->
{
if
(
null
!=
meter
)
{
Meter
.
Id
id
=
meter
.
getId
();
String
name
=
id
.
getName
();
List
<
Tag
>
tags
=
id
.
getTags
();
Map
<
String
,
String
>
labels
=
tagsConvertToMap
(
tags
);
meter
.
use
(
gauge
->
{
updateValue
(
name
,
labels
,
gauge
.
value
(),
time
);
},
counter
->
{
updateValue
(
name
,
labels
,
counter
.
count
(),
time
);
},
timer
->
{
writeSnapshotAndCount
(
name
,
labels
,
timer
.
takeSnapshot
(),
time
);
},
summary
->
{
writeSnapshotAndCount
(
name
,
labels
,
summary
.
takeSnapshot
(),
time
);
},
longTaskTimer
->
{
updateValue
(
name
,
labels
,
(
double
)
longTaskTimer
.
activeTasks
(),
time
);
},
timeGauge
->
{
updateValue
(
name
,
labels
,
timeGauge
.
value
(
getBaseTimeUnit
()),
time
);
},
functionCounter
->
{
updateValue
(
name
,
labels
,
functionCounter
.
count
(),
time
);
},
functionTimer
->
{
updateValue
(
name
,
labels
,
functionTimer
.
count
(),
time
);
},
m
->
{
logger
.
debug
(
"unknown meter:"
+
meter
);
});
}
});
}
private
void
writeSnapshotAndCount
(
String
name
,
Map
<
String
,
String
>
labels
,
HistogramSnapshot
snapshot
,
Long
time
)
{
updateValue
(
name
+
"_max"
,
labels
,
snapshot
.
max
(),
time
);
updateValue
(
name
+
"_mean"
,
labels
,
snapshot
.
mean
(),
time
);
updateValue
(
name
+
"_total"
,
labels
,
snapshot
.
total
(),
time
);
updateValue
(
name
+
"_count"
,
labels
,
(
double
)
snapshot
.
count
(),
time
);
}
private
Map
<
String
,
String
>
tagsConvertToMap
(
List
<
Tag
>
tags
)
{
Map
<
String
,
String
>
labels
=
new
HashMap
<>();
for
(
Tag
tag
:
tags
)
{
labels
.
put
(
tag
.
getKey
(),
tag
.
getValue
());
}
return
labels
;
}
private
void
updateValue
(
String
name
,
Map
<
String
,
String
>
labels
,
Double
value
,
Long
time
)
{
if
(
value
!=
null
)
{
String
deviceId
=
IoTDBMetricsUtils
.
generatePath
(
name
,
labels
);
List
<
String
>
sensors
=
Collections
.
singletonList
(
"value"
);
List
<
TSDataType
>
dataTypes
=
Collections
.
singletonList
(
TSDataType
.
DOUBLE
);
List
<
Object
>
values
=
Collections
.
singletonList
(
value
);
try
{
sessionPool
.
insertRecord
(
deviceId
,
time
,
sensors
,
dataTypes
,
values
);
}
catch
(
IoTDBConnectionException
|
StatementExecutionException
e
)
{
logger
.
warn
(
"Failed to insert record"
);
}
}
}
@Override
protected
TimeUnit
getBaseTimeUnit
()
{
return
TimeUnit
.
MILLISECONDS
;
}
}
metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/reporter/IoTDBRegistryConfig.java
已删除
100644 → 0
浏览文件 @
9f12b58c
/*
* 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.iotdb.metrics.micrometer.reporter
;
import
org.apache.iotdb.metrics.config.MetricConfigDescriptor
;
import
io.micrometer.core.instrument.step.StepRegistryConfig
;
import
java.time.Duration
;
public
interface
IoTDBRegistryConfig
extends
StepRegistryConfig
{
IoTDBRegistryConfig
DEFAULT
=
new
IoTDBRegistryConfig
()
{
@Override
public
String
get
(
String
key
)
{
return
null
;
}
@Override
public
Duration
step
()
{
return
Duration
.
ofSeconds
(
MetricConfigDescriptor
.
getInstance
()
.
getMetricConfig
()
.
getIoTDBReporterConfig
()
.
getPushPeriodInSecond
());
}
};
@Override
default
String
prefix
()
{
return
"iotdb"
;
}
}
metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/reporter/MicrometerIoTDBReporter.java
已删除
100644 → 0
浏览文件 @
9f12b58c
/*
* 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.iotdb.metrics.micrometer.reporter
;
import
org.apache.iotdb.metrics.AbstractMetricManager
;
import
org.apache.iotdb.metrics.reporter.Reporter
;
import
org.apache.iotdb.metrics.utils.ReporterType
;
import
io.micrometer.core.instrument.Clock
;
import
io.micrometer.core.instrument.MeterRegistry
;
import
io.micrometer.core.instrument.Metrics
;
import
io.micrometer.core.instrument.util.NamedThreadFactory
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
public
class
MicrometerIoTDBReporter
implements
Reporter
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
MicrometerIoTDBReporter
.
class
);
private
AbstractMetricManager
metricManager
;
@Override
public
boolean
start
()
{
try
{
Set
<
MeterRegistry
>
meterRegistrySet
=
Metrics
.
globalRegistry
.
getRegistries
().
stream
()
.
filter
(
reporter
->
reporter
instanceof
IoTDBMeterRegistry
)
.
collect
(
Collectors
.
toSet
());
IoTDBMeterRegistry
ioTDBMeterRegistry
;
if
(
meterRegistrySet
.
size
()
==
0
)
{
ioTDBMeterRegistry
=
new
IoTDBMeterRegistry
(
IoTDBRegistryConfig
.
DEFAULT
,
Clock
.
SYSTEM
);
Metrics
.
addRegistry
(
ioTDBMeterRegistry
);
}
else
{
ioTDBMeterRegistry
=
(
IoTDBMeterRegistry
)
meterRegistrySet
.
toArray
()[
0
];
}
ioTDBMeterRegistry
.
start
(
new
NamedThreadFactory
(
"iotdb-metrics-publisher"
));
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"Failed to start Micrometer IoTDBReporter, because {}"
,
e
.
getMessage
());
return
false
;
}
return
true
;
}
@Override
public
boolean
stop
()
{
try
{
Set
<
MeterRegistry
>
meterRegistrySet
=
Metrics
.
globalRegistry
.
getRegistries
().
stream
()
.
filter
(
reporter
->
reporter
instanceof
IoTDBMeterRegistry
)
.
collect
(
Collectors
.
toSet
());
for
(
MeterRegistry
meterRegistry
:
meterRegistrySet
)
{
if
(!
meterRegistry
.
isClosed
())
{
meterRegistry
.
close
();
Metrics
.
removeRegistry
(
meterRegistry
);
}
}
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"Failed to stop Micrometer IoTDBReporter, because {}"
,
e
.
getMessage
());
return
false
;
}
return
true
;
}
@Override
public
ReporterType
getReporterType
()
{
return
ReporterType
.
IOTDB
;
}
@Override
public
void
setMetricManager
(
AbstractMetricManager
metricManager
)
{
this
.
metricManager
=
metricManager
;
}
}
metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/reporter/MicrometerJmxReporter.java
浏览文件 @
91aa0341
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
package
org.apache.iotdb.metrics.micrometer.reporter
;
package
org.apache.iotdb.metrics.micrometer.reporter
;
import
org.apache.iotdb.metrics.AbstractMetricManager
;
import
org.apache.iotdb.metrics.AbstractMetricManager
;
import
org.apache.iotdb.metrics.reporter.Reporter
;
import
org.apache.iotdb.metrics.reporter.
Jmx
Reporter
;
import
org.apache.iotdb.metrics.utils.ReporterType
;
import
org.apache.iotdb.metrics.utils.ReporterType
;
import
io.micrometer.core.instrument.Clock
;
import
io.micrometer.core.instrument.Clock
;
...
@@ -33,9 +33,8 @@ import org.slf4j.LoggerFactory;
...
@@ -33,9 +33,8 @@ import org.slf4j.LoggerFactory;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
public
class
MicrometerJmxReporter
implements
Reporter
{
public
class
MicrometerJmxReporter
implements
Jmx
Reporter
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
MicrometerJmxReporter
.
class
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
MicrometerJmxReporter
.
class
);
private
AbstractMetricManager
metricManager
;
@Override
@Override
public
boolean
start
()
{
public
boolean
start
()
{
...
@@ -82,6 +81,6 @@ public class MicrometerJmxReporter implements Reporter {
...
@@ -82,6 +81,6 @@ public class MicrometerJmxReporter implements Reporter {
@Override
@Override
public
void
setMetricManager
(
AbstractMetricManager
metricManager
)
{
public
void
setMetricManager
(
AbstractMetricManager
metricManager
)
{
this
.
metricManager
=
metricManager
;
// do nothing
}
}
}
}
metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/reporter/MicrometerPrometheusReporter.java
已删除
100644 → 0
浏览文件 @
9f12b58c
/*
* 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.iotdb.metrics.micrometer.reporter
;
import
org.apache.iotdb.metrics.AbstractMetricManager
;
import
org.apache.iotdb.metrics.config.MetricConfig
;
import
org.apache.iotdb.metrics.config.MetricConfigDescriptor
;
import
org.apache.iotdb.metrics.reporter.Reporter
;
import
org.apache.iotdb.metrics.utils.ReporterType
;
import
io.micrometer.core.instrument.MeterRegistry
;
import
io.micrometer.core.instrument.Metrics
;
import
io.micrometer.prometheus.PrometheusConfig
;
import
io.micrometer.prometheus.PrometheusMeterRegistry
;
import
io.netty.channel.ChannelOption
;
import
io.netty.channel.group.DefaultChannelGroup
;
import
io.netty.util.concurrent.GlobalEventExecutor
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
reactor.core.publisher.Mono
;
import
reactor.netty.DisposableServer
;
import
reactor.netty.http.server.HttpServer
;
import
java.time.Duration
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
public
class
MicrometerPrometheusReporter
implements
Reporter
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
MicrometerPrometheusReporter
.
class
);
private
static
final
MetricConfig
metricConfig
=
MetricConfigDescriptor
.
getInstance
().
getMetricConfig
();
private
AbstractMetricManager
metricManager
;
private
DisposableServer
httpServer
;
@Override
public
boolean
start
()
{
if
(
httpServer
!=
null
)
{
return
false
;
}
Set
<
MeterRegistry
>
meterRegistrySet
=
Metrics
.
globalRegistry
.
getRegistries
().
stream
()
.
filter
(
reporter
->
reporter
instanceof
PrometheusMeterRegistry
)
.
collect
(
Collectors
.
toSet
());
PrometheusMeterRegistry
prometheusMeterRegistry
;
if
(
meterRegistrySet
.
size
()
==
0
)
{
prometheusMeterRegistry
=
new
PrometheusMeterRegistry
(
PrometheusConfig
.
DEFAULT
);
prometheusMeterRegistry
.
throwExceptionOnRegistrationFailure
();
Metrics
.
addRegistry
(
prometheusMeterRegistry
);
}
else
{
prometheusMeterRegistry
=
(
PrometheusMeterRegistry
)
meterRegistrySet
.
toArray
()[
0
];
}
httpServer
=
HttpServer
.
create
()
.
option
(
ChannelOption
.
CONNECT_TIMEOUT_MILLIS
,
2000
)
.
channelGroup
(
new
DefaultChannelGroup
(
GlobalEventExecutor
.
INSTANCE
))
.
port
(
metricConfig
.
getPrometheusReporterPort
())
.
route
(
routes
->
routes
.
get
(
"/metrics"
,
(
request
,
response
)
->
response
.
sendString
(
Mono
.
just
(
prometheusMeterRegistry
.
scrape
()))))
.
bindNow
();
LOGGER
.
info
(
"http server for metrics started, listen on {}"
,
metricConfig
.
getPrometheusReporterPort
());
return
true
;
}
@Override
public
boolean
stop
()
{
if
(
httpServer
!=
null
)
{
try
{
Set
<
MeterRegistry
>
meterRegistrySet
=
Metrics
.
globalRegistry
.
getRegistries
().
stream
()
.
filter
(
reporter
->
reporter
instanceof
PrometheusMeterRegistry
)
.
collect
(
Collectors
.
toSet
());
for
(
MeterRegistry
meterRegistry
:
meterRegistrySet
)
{
meterRegistry
.
close
();
Metrics
.
removeRegistry
(
meterRegistry
);
}
httpServer
.
disposeNow
(
Duration
.
ofSeconds
(
10
));
httpServer
=
null
;
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"failed to stop server"
,
e
);
return
false
;
}
}
return
true
;
}
@Override
public
ReporterType
getReporterType
()
{
return
ReporterType
.
PROMETHEUS
;
}
@Override
public
void
setMetricManager
(
AbstractMetricManager
metricManager
)
{
this
.
metricManager
=
metricManager
;
}
}
metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerHistogramSnapshot.java
浏览文件 @
91aa0341
...
@@ -21,8 +21,6 @@ package org.apache.iotdb.metrics.micrometer.type;
...
@@ -21,8 +21,6 @@ package org.apache.iotdb.metrics.micrometer.type;
import
org.apache.iotdb.metrics.type.HistogramSnapshot
;
import
org.apache.iotdb.metrics.type.HistogramSnapshot
;
import
java.io.OutputStream
;
import
java.io.PrintStream
;
import
java.util.Arrays
;
import
java.util.Arrays
;
public
class
MicrometerHistogramSnapshot
implements
HistogramSnapshot
{
public
class
MicrometerHistogramSnapshot
implements
HistogramSnapshot
{
...
@@ -82,9 +80,4 @@ public class MicrometerHistogramSnapshot implements HistogramSnapshot {
...
@@ -82,9 +80,4 @@ public class MicrometerHistogramSnapshot implements HistogramSnapshot {
// need distributionSummary to push 0 percentiles
// need distributionSummary to push 0 percentiles
return
(
long
)
getValue
(
0.0
);
return
(
long
)
getValue
(
0.0
);
}
}
@Override
public
void
dump
(
OutputStream
output
)
{
this
.
histogramSnapshot
.
outputSummary
((
PrintStream
)
output
,
100
);
}
}
}
metrics/micrometer-metrics/src/main/resources/META-INF/services/org.apache.iotdb.metrics.reporter.Reporter
→
metrics/micrometer-metrics/src/main/resources/META-INF/services/org.apache.iotdb.metrics.reporter.
Jmx
Reporter
浏览文件 @
91aa0341
...
@@ -15,6 +15,4 @@
...
@@ -15,6 +15,4 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
#
#
org.apache.iotdb.metrics.micrometer.reporter.MicrometerJmxReporter
org.apache.iotdb.metrics.micrometer.reporter.MicrometerJmxReporter
org.apache.iotdb.metrics.micrometer.reporter.MicrometerPrometheusReporter
\ No newline at end of file
org.apache.iotdb.metrics.micrometer.reporter.MicrometerIoTDBReporter
\ No newline at end of file
node-commons/src/main/java/org/apache/iotdb/commons/service/metric/MetricService.java
浏览文件 @
91aa0341
...
@@ -27,8 +27,8 @@ import org.apache.iotdb.commons.service.ServiceType;
...
@@ -27,8 +27,8 @@ import org.apache.iotdb.commons.service.ServiceType;
import
org.apache.iotdb.metrics.AbstractMetricService
;
import
org.apache.iotdb.metrics.AbstractMetricService
;
import
org.apache.iotdb.metrics.config.ReloadLevel
;
import
org.apache.iotdb.metrics.config.ReloadLevel
;
import
org.apache.iotdb.metrics.metricsets.IMetricSet
;
import
org.apache.iotdb.metrics.metricsets.IMetricSet
;
import
org.apache.iotdb.metrics.reporter.
Internal
Reporter
;
import
org.apache.iotdb.metrics.reporter.
iotdb.InternalIoTDB
Reporter
;
import
org.apache.iotdb.metrics.reporter.
MemoryInternal
Reporter
;
import
org.apache.iotdb.metrics.reporter.
iotdb.MemoryInternalIoTDB
Reporter
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -72,14 +72,14 @@ public class MetricService extends AbstractMetricService implements MetricServic
...
@@ -72,14 +72,14 @@ public class MetricService extends AbstractMetricService implements MetricServic
public
void
stop
()
{
public
void
stop
()
{
logger
.
info
(
"Stop metric service"
);
logger
.
info
(
"Stop metric service"
);
internalReporter
.
stop
();
internalReporter
.
stop
();
internalReporter
=
new
MemoryInternalReporter
();
internalReporter
=
new
MemoryInternal
IoTDB
Reporter
();
stopService
();
stopService
();
JMXService
.
deregisterMBean
(
mbeanName
);
JMXService
.
deregisterMBean
(
mbeanName
);
logger
.
info
(
"Finish stopping metric service"
);
logger
.
info
(
"Finish stopping metric service"
);
}
}
@Override
@Override
public
void
reloadInternalReporter
(
InternalReporter
internalReporter
)
{
public
void
reloadInternalReporter
(
Internal
IoTDB
Reporter
internalReporter
)
{
logger
.
info
(
"Reload internal reporter"
);
logger
.
info
(
"Reload internal reporter"
);
internalReporter
.
addAutoGauge
(
this
.
internalReporter
.
getAllAutoGauge
());
internalReporter
.
addAutoGauge
(
this
.
internalReporter
.
getAllAutoGauge
());
this
.
internalReporter
.
stop
();
this
.
internalReporter
.
stop
();
...
@@ -115,7 +115,7 @@ public class MetricService extends AbstractMetricService implements MetricServic
...
@@ -115,7 +115,7 @@ public class MetricService extends AbstractMetricService implements MetricServic
return
ServiceType
.
METRIC_SERVICE
;
return
ServiceType
.
METRIC_SERVICE
;
}
}
public
void
updateInternalReporter
(
InternalReporter
InternalReporter
)
{
public
void
updateInternalReporter
(
Internal
IoTDB
Reporter
InternalReporter
)
{
this
.
internalReporter
=
InternalReporter
;
this
.
internalReporter
=
InternalReporter
;
}
}
...
...
server/src/assembly/resources/conf/iotdb-datanode.properties
浏览文件 @
91aa0341
...
@@ -230,7 +230,7 @@ dn_target_config_node_list=127.0.0.1:22277
...
@@ -230,7 +230,7 @@ dn_target_config_node_list=127.0.0.1:22277
# dn_metric_frame_type=MICROMETER
# dn_metric_frame_type=MICROMETER
# The level of metric module
# The level of metric module
# Options: [C
ore, Important, Normal, All
]
# Options: [C
ORE, IMPORTANT, NORMAL, ALL
]
# Datatype: String
# Datatype: String
# dn_metric_level=CORE
# dn_metric_level=CORE
...
...
server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
浏览文件 @
91aa0341
...
@@ -48,8 +48,8 @@ import org.apache.iotdb.db.wal.utils.WALMode;
...
@@ -48,8 +48,8 @@ import org.apache.iotdb.db.wal.utils.WALMode;
import
org.apache.iotdb.external.api.IPropertiesLoader
;
import
org.apache.iotdb.external.api.IPropertiesLoader
;
import
org.apache.iotdb.metrics.config.MetricConfigDescriptor
;
import
org.apache.iotdb.metrics.config.MetricConfigDescriptor
;
import
org.apache.iotdb.metrics.config.ReloadLevel
;
import
org.apache.iotdb.metrics.config.ReloadLevel
;
import
org.apache.iotdb.metrics.reporter.
Internal
Reporter
;
import
org.apache.iotdb.metrics.reporter.
iotdb.InternalIoTDB
Reporter
;
import
org.apache.iotdb.metrics.reporter.
MemoryInternal
Reporter
;
import
org.apache.iotdb.metrics.reporter.
iotdb.MemoryInternalIoTDB
Reporter
;
import
org.apache.iotdb.metrics.utils.InternalReporterType
;
import
org.apache.iotdb.metrics.utils.InternalReporterType
;
import
org.apache.iotdb.rpc.RpcTransportFactory
;
import
org.apache.iotdb.rpc.RpcTransportFactory
;
import
org.apache.iotdb.tsfile.common.conf.TSFileDescriptor
;
import
org.apache.iotdb.tsfile.common.conf.TSFileDescriptor
;
...
@@ -1544,12 +1544,12 @@ public class IoTDBDescriptor {
...
@@ -1544,12 +1544,12 @@ public class IoTDBDescriptor {
ReloadLevel
reloadLevel
=
MetricConfigDescriptor
.
getInstance
().
loadHotProps
(
commonProperties
);
ReloadLevel
reloadLevel
=
MetricConfigDescriptor
.
getInstance
().
loadHotProps
(
commonProperties
);
logger
.
info
(
"Reload metric service in level {}"
,
reloadLevel
);
logger
.
info
(
"Reload metric service in level {}"
,
reloadLevel
);
if
(
reloadLevel
==
ReloadLevel
.
RESTART_INTERNAL_REPORTER
)
{
if
(
reloadLevel
==
ReloadLevel
.
RESTART_INTERNAL_REPORTER
)
{
InternalReporter
internalReporter
;
Internal
IoTDB
Reporter
internalReporter
;
if
(
MetricConfigDescriptor
.
getInstance
().
getMetricConfig
().
getInternalReportType
()
if
(
MetricConfigDescriptor
.
getInstance
().
getMetricConfig
().
getInternalReportType
()
==
InternalReporterType
.
IOTDB
)
{
==
InternalReporterType
.
IOTDB
)
{
internalReporter
=
new
IoTDBInternalReporter
();
internalReporter
=
new
IoTDBInternalReporter
();
}
else
{
}
else
{
internalReporter
=
new
MemoryInternalReporter
();
internalReporter
=
new
MemoryInternal
IoTDB
Reporter
();
}
}
MetricService
.
getInstance
().
reloadInternalReporter
(
internalReporter
);
MetricService
.
getInstance
().
reloadInternalReporter
(
internalReporter
);
}
else
{
}
else
{
...
...
server/src/main/java/org/apache/iotdb/db/engine/cache/ChunkCacheMetrics.java
浏览文件 @
91aa0341
...
@@ -49,7 +49,7 @@ public class ChunkCacheMetrics implements IMetricSet {
...
@@ -49,7 +49,7 @@ public class ChunkCacheMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
CACHE_HIT
.
toString
(),
Tag
.
NAME
.
toString
(),
"chunk"
);
MetricType
.
AUTO_
GAUGE
,
Metric
.
CACHE_HIT
.
toString
(),
Tag
.
NAME
.
toString
(),
"chunk"
);
}
}
@Override
@Override
...
...
server/src/main/java/org/apache/iotdb/db/engine/cache/TimeSeriesMetadataCacheMetrics.java
浏览文件 @
91aa0341
...
@@ -57,9 +57,9 @@ public class TimeSeriesMetadataCacheMetrics implements IMetricSet {
...
@@ -57,9 +57,9 @@ public class TimeSeriesMetadataCacheMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
CACHE_HIT
.
toString
(),
Tag
.
NAME
.
toString
(),
"timeSeriesMeta"
);
MetricType
.
AUTO_
GAUGE
,
Metric
.
CACHE_HIT
.
toString
(),
Tag
.
NAME
.
toString
(),
"timeSeriesMeta"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
CACHE_HIT
.
toString
(),
Tag
.
NAME
.
toString
(),
"bloomFilter"
);
MetricType
.
AUTO_
GAUGE
,
Metric
.
CACHE_HIT
.
toString
(),
Tag
.
NAME
.
toString
(),
"bloomFilter"
);
}
}
@Override
@Override
...
...
server/src/main/java/org/apache/iotdb/db/engine/flush/FlushManagerMetrics.java
浏览文件 @
91aa0341
...
@@ -60,14 +60,14 @@ public class FlushManagerMetrics implements IMetricSet {
...
@@ -60,14 +60,14 @@ public class FlushManagerMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
QUEUE
.
toString
(),
Metric
.
QUEUE
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
"flush"
,
"flush"
,
Tag
.
STATUS
.
toString
(),
Tag
.
STATUS
.
toString
(),
"waiting"
);
"waiting"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
QUEUE
.
toString
(),
Metric
.
QUEUE
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
"flush"
,
"flush"
,
...
...
server/src/main/java/org/apache/iotdb/db/engine/storagegroup/DataRegionMetrics.java
浏览文件 @
91aa0341
...
@@ -51,7 +51,7 @@ public class DataRegionMetrics implements IMetricSet {
...
@@ -51,7 +51,7 @@ public class DataRegionMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
MEM
.
toString
(),
Metric
.
MEM
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
"storageGroup_"
+
storageGroupName
);
"storageGroup_"
+
storageGroupName
);
...
...
server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessorInfoMetrics.java
浏览文件 @
91aa0341
...
@@ -53,7 +53,7 @@ public class TsFileProcessorInfoMetrics implements IMetricSet {
...
@@ -53,7 +53,7 @@ public class TsFileProcessorInfoMetrics implements IMetricSet {
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
MetricService
.
getInstance
()
MetricService
.
getInstance
()
.
remove
(
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
MEM
.
toString
(),
Metric
.
MEM
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
"chunkMetaData_"
+
storageGroupName
);
"chunkMetaData_"
+
storageGroupName
);
...
...
server/src/main/java/org/apache/iotdb/db/metadata/cache/DataNodeSchemaCacheMetrics.java
浏览文件 @
91aa0341
...
@@ -49,7 +49,7 @@ public class DataNodeSchemaCacheMetrics implements IMetricSet {
...
@@ -49,7 +49,7 @@ public class DataNodeSchemaCacheMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
CACHE_HIT
.
toString
(),
Tag
.
NAME
.
toString
(),
"schemaCache"
);
MetricType
.
AUTO_
GAUGE
,
Metric
.
CACHE_HIT
.
toString
(),
Tag
.
NAME
.
toString
(),
"schemaCache"
);
}
}
@Override
@Override
...
...
server/src/main/java/org/apache/iotdb/db/metadata/rescon/SchemaStatisticsManagerMetrics.java
浏览文件 @
91aa0341
...
@@ -49,7 +49,7 @@ public class SchemaStatisticsManagerMetrics implements IMetricSet {
...
@@ -49,7 +49,7 @@ public class SchemaStatisticsManagerMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
QUANTITY
.
toString
(),
Tag
.
NAME
.
toString
(),
"timeSeries"
);
MetricType
.
AUTO_
GAUGE
,
Metric
.
QUANTITY
.
toString
(),
Tag
.
NAME
.
toString
(),
"timeSeries"
);
}
}
@Override
@Override
...
...
server/src/main/java/org/apache/iotdb/db/mpp/execution/exchange/MPPDataExchangeServiceMetrics.java
浏览文件 @
91aa0341
...
@@ -49,7 +49,7 @@ public class MPPDataExchangeServiceMetrics implements IMetricSet {
...
@@ -49,7 +49,7 @@ public class MPPDataExchangeServiceMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
THRIFT_ACTIVE_THREADS
.
toString
(),
Metric
.
THRIFT_ACTIVE_THREADS
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
ThreadName
.
MPP_DATA_EXCHANGE_RPC_SERVICE
.
getName
());
ThreadName
.
MPP_DATA_EXCHANGE_RPC_SERVICE
.
getName
());
...
...
server/src/main/java/org/apache/iotdb/db/mpp/execution/exchange/MppDataExchangeServiceThriftHandlerMetrics.java
浏览文件 @
91aa0341
...
@@ -53,7 +53,7 @@ public class MppDataExchangeServiceThriftHandlerMetrics implements IMetricSet {
...
@@ -53,7 +53,7 @@ public class MppDataExchangeServiceThriftHandlerMetrics implements IMetricSet {
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
MetricService
.
getInstance
()
MetricService
.
getInstance
()
.
remove
(
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
THRIFT_CONNECTIONS
.
toString
(),
Metric
.
THRIFT_CONNECTIONS
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
"MPPDataExchange"
);
"MPPDataExchange"
);
...
...
server/src/main/java/org/apache/iotdb/db/query/pool/RawQueryReadTaskPoolManagerMetrics.java
浏览文件 @
91aa0341
...
@@ -62,14 +62,14 @@ public class RawQueryReadTaskPoolManagerMetrics implements IMetricSet {
...
@@ -62,14 +62,14 @@ public class RawQueryReadTaskPoolManagerMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
QUEUE
.
toString
(),
Metric
.
QUEUE
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
ThreadName
.
SUB_RAW_QUERY_SERVICE
.
getName
(),
ThreadName
.
SUB_RAW_QUERY_SERVICE
.
getName
(),
Tag
.
STATUS
.
toString
(),
Tag
.
STATUS
.
toString
(),
"running"
);
"running"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
QUEUE
.
toString
(),
Metric
.
QUEUE
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
ThreadName
.
SUB_RAW_QUERY_SERVICE
.
getName
(),
ThreadName
.
SUB_RAW_QUERY_SERVICE
.
getName
(),
...
...
server/src/main/java/org/apache/iotdb/db/service/DataNodeInternalRPCServiceMetrics.java
浏览文件 @
91aa0341
...
@@ -51,7 +51,7 @@ public class DataNodeInternalRPCServiceMetrics implements IMetricSet {
...
@@ -51,7 +51,7 @@ public class DataNodeInternalRPCServiceMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
THRIFT_ACTIVE_THREADS
.
toString
(),
Metric
.
THRIFT_ACTIVE_THREADS
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
ThreadName
.
DATANODE_INTERNAL_RPC_SERVICE
.
getName
());
ThreadName
.
DATANODE_INTERNAL_RPC_SERVICE
.
getName
());
...
...
server/src/main/java/org/apache/iotdb/db/service/RPCServiceMetrics.java
浏览文件 @
91aa0341
...
@@ -50,7 +50,7 @@ public class RPCServiceMetrics implements IMetricSet {
...
@@ -50,7 +50,7 @@ public class RPCServiceMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
THRIFT_ACTIVE_THREADS
.
toString
(),
Metric
.
THRIFT_ACTIVE_THREADS
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
ThreadName
.
CLIENT_RPC_SERVICE
.
getName
());
ThreadName
.
CLIENT_RPC_SERVICE
.
getName
());
...
...
server/src/main/java/org/apache/iotdb/db/service/metrics/FileMetrics.java
浏览文件 @
91aa0341
...
@@ -120,16 +120,18 @@ public class FileMetrics implements IMetricSet {
...
@@ -120,16 +120,18 @@ public class FileMetrics implements IMetricSet {
currentServiceFuture
=
null
;
currentServiceFuture
=
null
;
}
}
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
FILE_SIZE
.
toString
(),
Tag
.
NAME
.
toString
(),
"wal"
);
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
FILE_SIZE
.
toString
(),
Tag
.
NAME
.
toString
(),
"seq"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
FILE_SIZE
.
toString
(),
Tag
.
NAME
.
toString
(),
"unseq
"
);
MetricType
.
AUTO_GAUGE
,
Metric
.
FILE_SIZE
.
toString
(),
Tag
.
NAME
.
toString
(),
"wal
"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
FILE_COUNT
.
toString
(),
Tag
.
NAME
.
toString
(),
"wal
"
);
MetricType
.
AUTO_GAUGE
,
Metric
.
FILE_SIZE
.
toString
(),
Tag
.
NAME
.
toString
(),
"seq
"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
FILE_COUNT
.
toString
(),
Tag
.
NAME
.
toString
(),
"
seq"
);
MetricType
.
AUTO_GAUGE
,
Metric
.
FILE_SIZE
.
toString
(),
Tag
.
NAME
.
toString
(),
"un
seq"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
FILE_COUNT
.
toString
(),
Tag
.
NAME
.
toString
(),
"unseq"
);
MetricType
.
AUTO_GAUGE
,
Metric
.
FILE_COUNT
.
toString
(),
Tag
.
NAME
.
toString
(),
"wal"
);
metricService
.
remove
(
MetricType
.
AUTO_GAUGE
,
Metric
.
FILE_COUNT
.
toString
(),
Tag
.
NAME
.
toString
(),
"seq"
);
metricService
.
remove
(
MetricType
.
AUTO_GAUGE
,
Metric
.
FILE_COUNT
.
toString
(),
Tag
.
NAME
.
toString
(),
"unseq"
);
}
}
private
void
collect
()
{
private
void
collect
()
{
...
...
server/src/main/java/org/apache/iotdb/db/service/metrics/IoTDBInternalReporter.java
浏览文件 @
91aa0341
...
@@ -37,24 +37,21 @@ import org.apache.iotdb.db.mpp.plan.parser.StatementGenerator;
...
@@ -37,24 +37,21 @@ import org.apache.iotdb.db.mpp.plan.parser.StatementGenerator;
import
org.apache.iotdb.db.mpp.plan.statement.Statement
;
import
org.apache.iotdb.db.mpp.plan.statement.Statement
;
import
org.apache.iotdb.db.query.control.SessionManager
;
import
org.apache.iotdb.db.query.control.SessionManager
;
import
org.apache.iotdb.metrics.config.MetricConfigDescriptor
;
import
org.apache.iotdb.metrics.config.MetricConfigDescriptor
;
import
org.apache.iotdb.metrics.reporter.InternalReporter
;
import
org.apache.iotdb.metrics.reporter.iotdb.InternalIoTDBReporter
;
import
org.apache.iotdb.metrics.type.AutoGauge
;
import
org.apache.iotdb.metrics.type.HistogramSnapshot
;
import
org.apache.iotdb.metrics.utils.InternalReporterType
;
import
org.apache.iotdb.metrics.utils.InternalReporterType
;
import
org.apache.iotdb.metrics.utils.
IoTDBMetricsUtils
;
import
org.apache.iotdb.metrics.utils.
ReporterType
;
import
org.apache.iotdb.rpc.IoTDBConnectionException
;
import
org.apache.iotdb.rpc.IoTDBConnectionException
;
import
org.apache.iotdb.rpc.TSStatusCode
;
import
org.apache.iotdb.rpc.TSStatusCode
;
import
org.apache.iotdb.service.rpc.thrift.TSInsertRecordReq
;
import
org.apache.iotdb.service.rpc.thrift.TSInsertRecordReq
;
import
org.apache.iotdb.session.util.SessionUtils
;
import
org.apache.iotdb.session.util.SessionUtils
;
import
org.apache.iotdb.tsfile.file.metadata.enums.TSDataType
;
import
org.apache.iotdb.tsfile.file.metadata.enums.TSDataType
;
import
org.apache.iotdb.tsfile.utils.Pair
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
import
java.time.ZoneId
;
import
java.time.ZoneId
;
import
java.util.
Collections
;
import
java.util.
ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Executors
;
...
@@ -62,7 +59,7 @@ import java.util.concurrent.Future;
...
@@ -62,7 +59,7 @@ import java.util.concurrent.Future;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
public
class
IoTDBInternalReporter
extends
InternalReporter
{
public
class
IoTDBInternalReporter
extends
Internal
IoTDB
Reporter
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
IoTDBInternalReporter
.
class
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
IoTDBInternalReporter
.
class
);
private
static
final
IoTDBConfig
config
=
IoTDBDescriptor
.
getInstance
().
getConfig
();
private
static
final
IoTDBConfig
config
=
IoTDBDescriptor
.
getInstance
().
getConfig
();
private
static
final
SessionManager
SESSION_MANAGER
=
SessionManager
.
getInstance
();
private
static
final
SessionManager
SESSION_MANAGER
=
SessionManager
.
getInstance
();
...
@@ -84,89 +81,84 @@ public class IoTDBInternalReporter extends InternalReporter {
...
@@ -84,89 +81,84 @@ public class IoTDBInternalReporter extends InternalReporter {
SESSION_INFO
=
new
SessionInfo
(
0
,
"root"
,
ZoneId
.
systemDefault
().
getId
());
SESSION_INFO
=
new
SessionInfo
(
0
,
"root"
,
ZoneId
.
systemDefault
().
getId
());
}
}
private
void
collectAutoGauge
()
{
for
(
Map
.
Entry
<
Pair
<
String
,
String
[]>,
AutoGauge
>
entry
:
autoGauges
.
entrySet
())
{
updateValue
(
entry
.
getKey
().
left
,
entry
.
getValue
().
value
(),
TSDataType
.
INT64
,
entry
.
getKey
().
right
);
}
}
@Override
public
void
updateValue
(
String
name
,
Object
value
,
TSDataType
type
,
String
...
tags
)
{
// TODO spricoder update iotdb reporter
updateValue
(
name
,
value
,
type
,
System
.
currentTimeMillis
(),
tags
);
}
@Override
public
void
updateValue
(
String
name
,
Object
value
,
TSDataType
type
,
Long
time
,
String
...
tags
)
{
if
(
value
!=
null
)
{
try
{
TSInsertRecordReq
request
=
new
TSInsertRecordReq
();
String
prefix
=
IoTDBMetricsUtils
.
generatePath
(
name
,
tags
);
List
<
String
>
measurements
=
Collections
.
singletonList
(
"value"
);
List
<
TSDataType
>
types
=
Collections
.
singletonList
(
type
);
List
<
Object
>
values
=
Collections
.
singletonList
(
value
);
ByteBuffer
buffer
=
SessionUtils
.
getValueBuffer
(
types
,
values
);
request
.
setPrefixPath
(
prefix
);
request
.
setTimestamp
(
time
);
request
.
setMeasurements
(
measurements
);
request
.
setValues
(
buffer
);
request
.
setIsAligned
(
false
);
Statement
s
=
StatementGenerator
.
createStatement
(
request
);
final
long
queryId
=
SESSION_MANAGER
.
requestQueryId
();
ExecutionResult
result
=
COORDINATOR
.
execute
(
s
,
queryId
,
SESSION_INFO
,
""
,
PARTITION_FETCHER
,
SCHEMA_FETCHER
);
if
(
result
.
status
.
getCode
()
!=
TSStatusCode
.
SUCCESS_STATUS
.
getStatusCode
())
{
LOGGER
.
error
(
"Failed to update the value of metric with status {}"
,
result
.
status
);
}
}
catch
(
IoTDBConnectionException
e1
)
{
LOGGER
.
error
(
"Failed to update the value of metric because of unknown type"
);
}
catch
(
IllegalPathException
|
QueryProcessException
e2
)
{
LOGGER
.
error
(
"Failed to update the value of metric because of internal error"
);
}
}
}
@Override
public
void
writeSnapshotAndCount
(
String
name
,
HistogramSnapshot
snapshot
,
String
...
tags
)
{
Long
time
=
System
.
currentTimeMillis
();
updateValue
(
name
+
"_min"
,
snapshot
.
getMin
(),
TSDataType
.
INT64
,
time
,
tags
);
updateValue
(
name
+
"_mean"
,
snapshot
.
getMean
(),
TSDataType
.
DOUBLE
,
time
,
tags
);
updateValue
(
name
+
"_median"
,
snapshot
.
getMedian
(),
TSDataType
.
DOUBLE
,
time
,
tags
);
updateValue
(
name
+
"_95"
,
snapshot
.
getValue
(
0.95
),
TSDataType
.
DOUBLE
,
time
,
tags
);
updateValue
(
name
+
"_99"
,
snapshot
.
getValue
(
0.99
),
TSDataType
.
DOUBLE
,
time
,
tags
);
updateValue
(
name
+
"_999"
,
snapshot
.
getValue
(
0.999
),
TSDataType
.
DOUBLE
,
time
,
tags
);
updateValue
(
name
+
"_max"
,
snapshot
.
getMax
(),
TSDataType
.
INT64
,
time
,
tags
);
}
@Override
@Override
public
InternalReporterType
getType
()
{
public
InternalReporterType
getType
()
{
return
InternalReporterType
.
IOTDB
;
return
InternalReporterType
.
IOTDB
;
}
}
@Override
@Override
public
void
start
()
{
public
boolean
start
()
{
if
(
currentServiceFuture
==
null
)
{
if
(
currentServiceFuture
==
null
)
{
currentServiceFuture
=
currentServiceFuture
=
ScheduledExecutorUtil
.
safelyScheduleAtFixedRate
(
ScheduledExecutorUtil
.
safelyScheduleAtFixedRate
(
service
,
service
,
this
::
collectAutoGauge
,
()
->
{
writeMetricToIoTDB
(
autoGauges
);
},
1
,
1
,
MetricConfigDescriptor
.
getInstance
()
MetricConfigDescriptor
.
getInstance
()
.
getMetricConfig
()
.
getMetricConfig
()
.
getAsyncCollectPeriodInSecond
(),
.
getAsyncCollectPeriodInSecond
(),
TimeUnit
.
SECONDS
);
TimeUnit
.
SECONDS
);
}
}
return
true
;
}
}
@Override
@Override
public
void
stop
()
{
public
boolean
stop
()
{
if
(
currentServiceFuture
!=
null
)
{
if
(
currentServiceFuture
!=
null
)
{
currentServiceFuture
.
cancel
(
true
);
currentServiceFuture
.
cancel
(
true
);
currentServiceFuture
=
null
;
currentServiceFuture
=
null
;
}
}
clear
();
clear
();
return
true
;
}
@Override
public
ReporterType
getReporterType
()
{
return
ReporterType
.
IOTDB
;
}
@Override
protected
void
writeMetricToIoTDB
(
Map
<
String
,
Object
>
valueMap
,
String
prefix
,
long
time
)
{
try
{
TSInsertRecordReq
request
=
new
TSInsertRecordReq
();
List
<
String
>
measurements
=
new
ArrayList
<>();
List
<
TSDataType
>
types
=
new
ArrayList
<>();
List
<
Object
>
values
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
valueMap
.
entrySet
())
{
String
measurement
=
entry
.
getKey
();
Object
value
=
entry
.
getValue
();
measurements
.
add
(
measurement
);
types
.
add
(
inferType
(
value
));
values
.
add
(
value
);
}
ByteBuffer
buffer
=
SessionUtils
.
getValueBuffer
(
types
,
values
);
request
.
setPrefixPath
(
prefix
);
request
.
setTimestamp
(
time
);
request
.
setMeasurements
(
measurements
);
request
.
setValues
(
buffer
);
request
.
setIsAligned
(
false
);
Statement
s
=
StatementGenerator
.
createStatement
(
request
);
final
long
queryId
=
SESSION_MANAGER
.
requestQueryId
();
ExecutionResult
result
=
COORDINATOR
.
execute
(
s
,
queryId
,
SESSION_INFO
,
""
,
PARTITION_FETCHER
,
SCHEMA_FETCHER
);
if
(
result
.
status
.
getCode
()
!=
TSStatusCode
.
SUCCESS_STATUS
.
getStatusCode
())
{
LOGGER
.
error
(
"Failed to update the value of metric with status {}"
,
result
.
status
);
}
}
catch
(
IoTDBConnectionException
e1
)
{
LOGGER
.
error
(
"Failed to update the value of metric because of unknown type"
);
}
catch
(
IllegalPathException
|
QueryProcessException
e2
)
{
LOGGER
.
error
(
"Failed to update the value of metric because of internal error"
);
}
}
@Override
protected
void
writeMetricsToIoTDB
(
Map
<
String
,
Map
<
String
,
Object
>>
valueMap
,
long
time
)
{
for
(
Map
.
Entry
<
String
,
Map
<
String
,
Object
>>
value
:
valueMap
.
entrySet
())
{
writeMetricToIoTDB
(
value
.
getValue
(),
value
.
getKey
(),
time
);
}
}
}
}
}
server/src/main/java/org/apache/iotdb/db/service/metrics/ProcessMetrics.java
浏览文件 @
91aa0341
...
@@ -76,10 +76,10 @@ public class ProcessMetrics implements IMetricSet {
...
@@ -76,10 +76,10 @@ public class ProcessMetrics implements IMetricSet {
private
void
removeProcessCPUInfo
(
AbstractMetricService
metricService
)
{
private
void
removeProcessCPUInfo
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
PROCESS_CPU_LOAD
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
MetricType
.
AUTO_
GAUGE
,
Metric
.
PROCESS_CPU_LOAD
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
PROCESS_CPU_TIME
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
MetricType
.
AUTO_
GAUGE
,
Metric
.
PROCESS_CPU_TIME
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
}
}
private
void
collectProcessMemInfo
(
AbstractMetricService
metricService
)
{
private
void
collectProcessMemInfo
(
AbstractMetricService
metricService
)
{
...
@@ -124,15 +124,15 @@ public class ProcessMetrics implements IMetricSet {
...
@@ -124,15 +124,15 @@ public class ProcessMetrics implements IMetricSet {
private
void
removeProcessMemInfo
(
AbstractMetricService
metricService
)
{
private
void
removeProcessMemInfo
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
PROCESS_MAX_MEM
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
MetricType
.
AUTO_
GAUGE
,
Metric
.
PROCESS_MAX_MEM
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
PROCESS_TOTAL_MEM
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
MetricType
.
AUTO_
GAUGE
,
Metric
.
PROCESS_TOTAL_MEM
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
PROCESS_FREE_MEM
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
MetricType
.
AUTO_
GAUGE
,
Metric
.
PROCESS_FREE_MEM
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
PROCESS_USED_MEM
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
MetricType
.
AUTO_
GAUGE
,
Metric
.
PROCESS_USED_MEM
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
PROCESS_MEM_RATIO
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
MetricType
.
AUTO_
GAUGE
,
Metric
.
PROCESS_MEM_RATIO
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
}
}
private
void
collectThreadInfo
(
AbstractMetricService
metricService
)
{
private
void
collectThreadInfo
(
AbstractMetricService
metricService
)
{
...
@@ -148,7 +148,10 @@ public class ProcessMetrics implements IMetricSet {
...
@@ -148,7 +148,10 @@ public class ProcessMetrics implements IMetricSet {
private
void
removeThreadInfo
(
AbstractMetricService
metricService
)
{
private
void
removeThreadInfo
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
PROCESS_THREADS_COUNT
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
MetricType
.
AUTO_GAUGE
,
Metric
.
PROCESS_THREADS_COUNT
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
}
}
private
void
collectProcessStatusInfo
(
AbstractMetricService
metricService
)
{
private
void
collectProcessStatusInfo
(
AbstractMetricService
metricService
)
{
...
@@ -163,7 +166,7 @@ public class ProcessMetrics implements IMetricSet {
...
@@ -163,7 +166,7 @@ public class ProcessMetrics implements IMetricSet {
private
void
removeProcessStatusInfo
(
AbstractMetricService
metricService
)
{
private
void
removeProcessStatusInfo
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
PROCESS_STATUS
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
MetricType
.
AUTO_
GAUGE
,
Metric
.
PROCESS_STATUS
.
toString
(),
Tag
.
NAME
.
toString
(),
"process"
);
}
}
private
long
getProcessUsedMemory
()
{
private
long
getProcessUsedMemory
()
{
...
...
server/src/main/java/org/apache/iotdb/db/service/metrics/SystemMetrics.java
浏览文件 @
91aa0341
...
@@ -112,7 +112,7 @@ public class SystemMetrics implements IMetricSet {
...
@@ -112,7 +112,7 @@ public class SystemMetrics implements IMetricSet {
private
void
removeSystemCpuInfo
(
AbstractMetricService
metricService
)
{
private
void
removeSystemCpuInfo
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
SYS_CPU_LOAD
.
toString
(),
Tag
.
NAME
.
toString
(),
"system"
);
MetricType
.
AUTO_
GAUGE
,
Metric
.
SYS_CPU_LOAD
.
toString
(),
Tag
.
NAME
.
toString
(),
"system"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
SYS_CPU_CORES
.
toString
(),
Tag
.
NAME
.
toString
(),
"system"
);
MetricType
.
GAUGE
,
Metric
.
SYS_CPU_CORES
.
toString
(),
Tag
.
NAME
.
toString
(),
"system"
);
...
@@ -163,22 +163,25 @@ public class SystemMetrics implements IMetricSet {
...
@@ -163,22 +163,25 @@ public class SystemMetrics implements IMetricSet {
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
"system"
);
"system"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
SYS_FREE_PHYSICAL_MEMORY_SIZE
.
toString
(),
Metric
.
SYS_FREE_PHYSICAL_MEMORY_SIZE
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
"system"
);
"system"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
SYS_TOTAL_SWAP_SPACE_SIZE
.
toString
(),
Metric
.
SYS_TOTAL_SWAP_SPACE_SIZE
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
"system"
);
"system"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
MetricType
.
AUTO_
GAUGE
,
Metric
.
SYS_FREE_SWAP_SPACE_SIZE
.
toString
(),
Metric
.
SYS_FREE_SWAP_SPACE_SIZE
.
toString
(),
Tag
.
NAME
.
toString
(),
Tag
.
NAME
.
toString
(),
"system"
);
"system"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
SYS_COMMITTED_VM_SIZE
.
toString
(),
Tag
.
NAME
.
toString
(),
"system"
);
MetricType
.
AUTO_GAUGE
,
Metric
.
SYS_COMMITTED_VM_SIZE
.
toString
(),
Tag
.
NAME
.
toString
(),
"system"
);
}
}
private
void
collectSystemDiskInfo
(
AbstractMetricService
metricService
)
{
private
void
collectSystemDiskInfo
(
AbstractMetricService
metricService
)
{
...
@@ -221,9 +224,15 @@ public class SystemMetrics implements IMetricSet {
...
@@ -221,9 +224,15 @@ public class SystemMetrics implements IMetricSet {
private
void
removeSystemDiskInfo
(
AbstractMetricService
metricService
)
{
private
void
removeSystemDiskInfo
(
AbstractMetricService
metricService
)
{
fileStores
.
clear
();
fileStores
.
clear
();
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
SYS_DISK_TOTAL_SPACE
.
toString
(),
Tag
.
NAME
.
toString
(),
"system"
);
MetricType
.
AUTO_GAUGE
,
Metric
.
SYS_DISK_TOTAL_SPACE
.
toString
(),
Tag
.
NAME
.
toString
(),
"system"
);
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
SYS_DISK_FREE_SPACE
.
toString
(),
Tag
.
NAME
.
toString
(),
"system"
);
MetricType
.
AUTO_GAUGE
,
Metric
.
SYS_DISK_FREE_SPACE
.
toString
(),
Tag
.
NAME
.
toString
(),
"system"
);
}
}
private
void
collectDiskMetrics
()
{
private
void
collectDiskMetrics
()
{
...
...
server/src/main/java/org/apache/iotdb/db/service/thrift/handler/InternalServiceThriftHandlerMetrics.java
浏览文件 @
91aa0341
...
@@ -50,7 +50,10 @@ public class InternalServiceThriftHandlerMetrics implements IMetricSet {
...
@@ -50,7 +50,10 @@ public class InternalServiceThriftHandlerMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
THRIFT_CONNECTIONS
.
toString
(),
Tag
.
NAME
.
toString
(),
"Internal"
);
MetricType
.
AUTO_GAUGE
,
Metric
.
THRIFT_CONNECTIONS
.
toString
(),
Tag
.
NAME
.
toString
(),
"Internal"
);
}
}
@Override
@Override
...
...
server/src/main/java/org/apache/iotdb/db/service/thrift/handler/RPCServiceThriftHandlerMetrics.java
浏览文件 @
91aa0341
...
@@ -47,7 +47,7 @@ public class RPCServiceThriftHandlerMetrics implements IMetricSet {
...
@@ -47,7 +47,7 @@ public class RPCServiceThriftHandlerMetrics implements IMetricSet {
@Override
@Override
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
public
void
unbindFrom
(
AbstractMetricService
metricService
)
{
metricService
.
remove
(
metricService
.
remove
(
MetricType
.
GAUGE
,
Metric
.
THRIFT_CONNECTIONS
.
toString
(),
Tag
.
NAME
.
toString
(),
"RPC"
);
MetricType
.
AUTO_
GAUGE
,
Metric
.
THRIFT_CONNECTIONS
.
toString
(),
Tag
.
NAME
.
toString
(),
"RPC"
);
}
}
@Override
@Override
...
...
server/src/test/java/org/apache/iotdb/db/metric/MetricServiceTest.java
浏览文件 @
91aa0341
...
@@ -100,13 +100,13 @@ public class MetricServiceTest {
...
@@ -100,13 +100,13 @@ public class MetricServiceTest {
assertNotEquals
(
counter1
,
counter2
);
assertNotEquals
(
counter1
,
counter2
);
counter2
=
metricService
.
getOrCreateCounter
(
"counter5"
,
MetricLevel
.
NORMAL
,
"tag"
,
"value"
);
counter2
=
metricService
.
getOrCreateCounter
(
"counter5"
,
MetricLevel
.
NORMAL
,
"tag"
,
"value"
);
assertEquals
(
DoNothingMetricManager
.
doNothingCounter
,
counter2
);
assertEquals
(
DoNothingMetricManager
.
doNothingCounter
,
counter2
);
assertEquals
(
4
,
metricService
.
get
AllCounters
(
).
size
());
assertEquals
(
4
,
metricService
.
get
MetricsByType
(
MetricType
.
COUNTER
).
size
());
metricService
.
count
(
10
,
"counter6"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
metricService
.
count
(
10
,
"counter6"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
assertEquals
(
5
,
metricService
.
get
AllCounters
(
).
size
());
assertEquals
(
5
,
metricService
.
get
MetricsByType
(
MetricType
.
COUNTER
).
size
());
metricService
.
remove
(
MetricType
.
COUNTER
,
"counter6"
);
metricService
.
remove
(
MetricType
.
COUNTER
,
"counter6"
);
assertEquals
(
5
,
metricService
.
get
AllCounters
(
).
size
());
assertEquals
(
5
,
metricService
.
get
MetricsByType
(
MetricType
.
COUNTER
).
size
());
metricService
.
remove
(
MetricType
.
COUNTER
,
"counter6"
,
"tag"
,
"value"
);
metricService
.
remove
(
MetricType
.
COUNTER
,
"counter6"
,
"tag"
,
"value"
);
assertEquals
(
4
,
metricService
.
get
AllCounters
(
).
size
());
assertEquals
(
4
,
metricService
.
get
MetricsByType
(
MetricType
.
COUNTER
).
size
());
assertEquals
(
4
,
metricService
.
getAllMetricKeys
().
size
());
assertEquals
(
4
,
metricService
.
getAllMetricKeys
().
size
());
// test gauge
// test gauge
...
@@ -126,13 +126,13 @@ public class MetricServiceTest {
...
@@ -126,13 +126,13 @@ public class MetricServiceTest {
assertNotEquals
(
gauge1
,
gauge2
);
assertNotEquals
(
gauge1
,
gauge2
);
gauge2
=
metricService
.
getOrCreateGauge
(
"gauge5"
,
MetricLevel
.
NORMAL
,
"tag"
,
"value"
);
gauge2
=
metricService
.
getOrCreateGauge
(
"gauge5"
,
MetricLevel
.
NORMAL
,
"tag"
,
"value"
);
assertEquals
(
DoNothingMetricManager
.
doNothingGauge
,
gauge2
);
assertEquals
(
DoNothingMetricManager
.
doNothingGauge
,
gauge2
);
assertEquals
(
4
,
metricService
.
get
AllGauges
(
).
size
());
assertEquals
(
4
,
metricService
.
get
MetricsByType
(
MetricType
.
GAUGE
).
size
());
metricService
.
gauge
(
10
,
"gauge6"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
metricService
.
gauge
(
10
,
"gauge6"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
assertEquals
(
5
,
metricService
.
get
AllGauges
(
).
size
());
assertEquals
(
5
,
metricService
.
get
MetricsByType
(
MetricType
.
GAUGE
).
size
());
metricService
.
remove
(
MetricType
.
GAUGE
,
"gauge6"
);
metricService
.
remove
(
MetricType
.
GAUGE
,
"gauge6"
);
assertEquals
(
5
,
metricService
.
get
AllGauges
(
).
size
());
assertEquals
(
5
,
metricService
.
get
MetricsByType
(
MetricType
.
GAUGE
).
size
());
metricService
.
remove
(
MetricType
.
GAUGE
,
"gauge6"
,
"tag"
,
"value"
);
metricService
.
remove
(
MetricType
.
GAUGE
,
"gauge6"
,
"tag"
,
"value"
);
assertEquals
(
4
,
metricService
.
get
AllGauges
(
).
size
());
assertEquals
(
4
,
metricService
.
get
MetricsByType
(
MetricType
.
GAUGE
).
size
());
assertEquals
(
8
,
metricService
.
getAllMetricKeys
().
size
());
assertEquals
(
8
,
metricService
.
getAllMetricKeys
().
size
());
// test auto gauge
// test auto gauge
...
@@ -150,10 +150,10 @@ public class MetricServiceTest {
...
@@ -150,10 +150,10 @@ public class MetricServiceTest {
list
=
null
;
list
=
null
;
System
.
gc
();
System
.
gc
();
assertEquals
(
0L
,
autoGauge
.
value
());
assertEquals
(
0L
,
autoGauge
.
value
());
assertEquals
(
4
,
metricService
.
get
AllGauges
(
).
size
());
assertEquals
(
4
,
metricService
.
get
MetricsByType
(
MetricType
.
GAUGE
).
size
());
assertEquals
(
1
,
metricService
.
get
AllAutoGauges
(
).
size
());
assertEquals
(
1
,
metricService
.
get
MetricsByType
(
MetricType
.
AUTO_GAUGE
).
size
());
metricService
.
remove
(
MetricType
.
GAUGE
,
"autoGauge"
,
"tag"
,
"value"
);
metricService
.
remove
(
MetricType
.
AUTO_
GAUGE
,
"autoGauge"
,
"tag"
,
"value"
);
assertEquals
(
4
,
metricService
.
get
AllGauges
(
).
size
());
assertEquals
(
4
,
metricService
.
get
MetricsByType
(
MetricType
.
GAUGE
).
size
());
assertEquals
(
8
,
metricService
.
getAllMetricKeys
().
size
());
assertEquals
(
8
,
metricService
.
getAllMetricKeys
().
size
());
// test rate
// test rate
...
@@ -174,14 +174,14 @@ public class MetricServiceTest {
...
@@ -174,14 +174,14 @@ public class MetricServiceTest {
"rate4"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
,
"tag2"
,
"value"
);
"rate4"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
,
"tag2"
,
"value"
);
assertNotEquals
(
rate1
,
rate2
);
assertNotEquals
(
rate1
,
rate2
);
rate2
=
metricService
.
getOrCreateRate
(
"rate5"
,
MetricLevel
.
NORMAL
,
"tag"
,
"value"
);
rate2
=
metricService
.
getOrCreateRate
(
"rate5"
,
MetricLevel
.
NORMAL
,
"tag"
,
"value"
);
assertEquals
(
4
,
metricService
.
get
AllRates
(
).
size
());
assertEquals
(
4
,
metricService
.
get
MetricsByType
(
MetricType
.
RATE
).
size
());
assertEquals
(
DoNothingMetricManager
.
doNothingRate
,
rate2
);
assertEquals
(
DoNothingMetricManager
.
doNothingRate
,
rate2
);
metricService
.
rate
(
10
,
"rate6"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
metricService
.
rate
(
10
,
"rate6"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
assertEquals
(
5
,
metricService
.
get
AllRates
(
).
size
());
assertEquals
(
5
,
metricService
.
get
MetricsByType
(
MetricType
.
RATE
).
size
());
metricService
.
remove
(
MetricType
.
RATE
,
"rate6"
);
metricService
.
remove
(
MetricType
.
RATE
,
"rate6"
);
assertEquals
(
5
,
metricService
.
get
AllRates
(
).
size
());
assertEquals
(
5
,
metricService
.
get
MetricsByType
(
MetricType
.
RATE
).
size
());
metricService
.
remove
(
MetricType
.
RATE
,
"rate6"
,
"tag"
,
"value"
);
metricService
.
remove
(
MetricType
.
RATE
,
"rate6"
,
"tag"
,
"value"
);
assertEquals
(
4
,
metricService
.
get
AllRates
(
).
size
());
assertEquals
(
4
,
metricService
.
get
MetricsByType
(
MetricType
.
RATE
).
size
());
assertEquals
(
12
,
metricService
.
getAllMetricKeys
().
size
());
assertEquals
(
12
,
metricService
.
getAllMetricKeys
().
size
());
// test histogram
// test histogram
...
@@ -212,23 +212,23 @@ public class MetricServiceTest {
...
@@ -212,23 +212,23 @@ public class MetricServiceTest {
histogram2
=
histogram2
=
metricService
.
getOrCreateHistogram
(
"histogram5"
,
MetricLevel
.
NORMAL
,
"tag"
,
"value"
);
metricService
.
getOrCreateHistogram
(
"histogram5"
,
MetricLevel
.
NORMAL
,
"tag"
,
"value"
);
assertEquals
(
DoNothingMetricManager
.
doNothingHistogram
,
histogram2
);
assertEquals
(
DoNothingMetricManager
.
doNothingHistogram
,
histogram2
);
assertEquals
(
4
,
metricService
.
get
AllHistograms
(
).
size
());
assertEquals
(
4
,
metricService
.
get
MetricsByType
(
MetricType
.
HISTOGRAM
).
size
());
metricService
.
histogram
(
10
,
"histogram6"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
metricService
.
histogram
(
10
,
"histogram6"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
assertEquals
(
5
,
metricService
.
get
AllHistograms
(
).
size
());
assertEquals
(
5
,
metricService
.
get
MetricsByType
(
MetricType
.
HISTOGRAM
).
size
());
metricService
.
remove
(
MetricType
.
HISTOGRAM
,
"histogram6"
);
metricService
.
remove
(
MetricType
.
HISTOGRAM
,
"histogram6"
);
assertEquals
(
5
,
metricService
.
get
AllHistograms
(
).
size
());
assertEquals
(
5
,
metricService
.
get
MetricsByType
(
MetricType
.
HISTOGRAM
).
size
());
metricService
.
remove
(
MetricType
.
HISTOGRAM
,
"histogram6"
,
"tag"
,
"value"
);
metricService
.
remove
(
MetricType
.
HISTOGRAM
,
"histogram6"
,
"tag"
,
"value"
);
assertEquals
(
4
,
metricService
.
get
AllHistograms
(
).
size
());
assertEquals
(
4
,
metricService
.
get
MetricsByType
(
MetricType
.
HISTOGRAM
).
size
());
assertEquals
(
16
,
metricService
.
getAllMetricKeys
().
size
());
assertEquals
(
16
,
metricService
.
getAllMetricKeys
().
size
());
// test timer
// test timer
Timer
timer1
=
metricService
.
getOrCreateTimer
(
"timer1"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
Timer
timer1
=
metricService
.
getOrCreateTimer
(
"timer1"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
assertNotNull
(
timer1
);
assertNotNull
(
timer1
);
metricService
.
timer
(
2
,
TimeUnit
.
MI
NUTE
S
,
"timer1"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
metricService
.
timer
(
2
,
TimeUnit
.
MI
LLISECOND
S
,
"timer1"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
metricService
.
timer
(
4
,
TimeUnit
.
MI
NUTE
S
,
"timer1"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
metricService
.
timer
(
4
,
TimeUnit
.
MI
LLISECOND
S
,
"timer1"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
metricService
.
timer
(
6
,
TimeUnit
.
MI
NUTE
S
,
"timer1"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
metricService
.
timer
(
6
,
TimeUnit
.
MI
LLISECOND
S
,
"timer1"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
metricService
.
timer
(
8
,
TimeUnit
.
MI
NUTE
S
,
"timer1"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
metricService
.
timer
(
8
,
TimeUnit
.
MI
LLISECOND
S
,
"timer1"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
metricService
.
timer
(
10
,
TimeUnit
.
MI
NUTE
S
,
"timer1"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
metricService
.
timer
(
10
,
TimeUnit
.
MI
LLISECOND
S
,
"timer1"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
assertEquals
(
5
,
timer1
.
getImmutableRate
().
getCount
());
assertEquals
(
5
,
timer1
.
getImmutableRate
().
getCount
());
assertEquals
(
5
,
timer1
.
takeSnapshot
().
size
());
assertEquals
(
5
,
timer1
.
takeSnapshot
().
size
());
Timer
timer2
=
metricService
.
getOrCreateTimer
(
"timer1"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
Timer
timer2
=
metricService
.
getOrCreateTimer
(
"timer1"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
...
@@ -243,13 +243,13 @@ public class MetricServiceTest {
...
@@ -243,13 +243,13 @@ public class MetricServiceTest {
assertNotEquals
(
timer1
,
timer2
);
assertNotEquals
(
timer1
,
timer2
);
timer2
=
metricService
.
getOrCreateTimer
(
"timer5"
,
MetricLevel
.
NORMAL
,
"tag"
,
"value"
);
timer2
=
metricService
.
getOrCreateTimer
(
"timer5"
,
MetricLevel
.
NORMAL
,
"tag"
,
"value"
);
assertNotEquals
(
timer1
,
timer2
);
assertNotEquals
(
timer1
,
timer2
);
assertEquals
(
4
,
metricService
.
get
AllTimers
(
).
size
());
assertEquals
(
4
,
metricService
.
get
MetricsByType
(
MetricType
.
TIMER
).
size
());
metricService
.
timer
(
10
,
TimeUnit
.
MILLISECONDS
,
"timer6"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
metricService
.
timer
(
10
,
TimeUnit
.
MILLISECONDS
,
"timer6"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value"
);
assertEquals
(
5
,
metricService
.
get
AllTimers
(
).
size
());
assertEquals
(
5
,
metricService
.
get
MetricsByType
(
MetricType
.
TIMER
).
size
());
metricService
.
remove
(
MetricType
.
TIMER
,
"timer6"
);
metricService
.
remove
(
MetricType
.
TIMER
,
"timer6"
);
assertEquals
(
5
,
metricService
.
get
AllTimers
(
).
size
());
assertEquals
(
5
,
metricService
.
get
MetricsByType
(
MetricType
.
TIMER
).
size
());
metricService
.
remove
(
MetricType
.
TIMER
,
"timer6"
,
"tag"
,
"value"
);
metricService
.
remove
(
MetricType
.
TIMER
,
"timer6"
,
"tag"
,
"value"
);
assertEquals
(
4
,
metricService
.
get
AllTimers
(
).
size
());
assertEquals
(
4
,
metricService
.
get
MetricsByType
(
MetricType
.
TIMER
).
size
());
assertEquals
(
20
,
metricService
.
getAllMetricKeys
().
size
());
assertEquals
(
20
,
metricService
.
getAllMetricKeys
().
size
());
// test remove same key and different value counter
// test remove same key and different value counter
...
@@ -259,15 +259,15 @@ public class MetricServiceTest {
...
@@ -259,15 +259,15 @@ public class MetricServiceTest {
Counter
removeCounter2
=
Counter
removeCounter2
=
metricService
.
getOrCreateCounter
(
"remove"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value2"
);
metricService
.
getOrCreateCounter
(
"remove"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value2"
);
assertNotNull
(
removeCounter2
);
assertNotNull
(
removeCounter2
);
assertEquals
(
6
,
metricService
.
get
AllCounters
(
).
size
());
assertEquals
(
6
,
metricService
.
get
MetricsByType
(
MetricType
.
COUNTER
).
size
());
assertEquals
(
22
,
metricService
.
getAllMetricKeys
().
size
());
assertEquals
(
22
,
metricService
.
getAllMetricKeys
().
size
());
metricService
.
remove
(
MetricType
.
COUNTER
,
"remove"
,
"tag"
,
"value1"
);
metricService
.
remove
(
MetricType
.
COUNTER
,
"remove"
,
"tag"
,
"value1"
);
assertEquals
(
5
,
metricService
.
get
AllCounters
(
).
size
());
assertEquals
(
5
,
metricService
.
get
MetricsByType
(
MetricType
.
COUNTER
).
size
());
assertEquals
(
21
,
metricService
.
getAllMetricKeys
().
size
());
assertEquals
(
21
,
metricService
.
getAllMetricKeys
().
size
());
removeCounter2
=
removeCounter2
=
metricService
.
getOrCreateCounter
(
"remove"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value1"
);
metricService
.
getOrCreateCounter
(
"remove"
,
MetricLevel
.
IMPORTANT
,
"tag"
,
"value1"
);
assertNotNull
(
removeCounter2
);
assertNotNull
(
removeCounter2
);
assertEquals
(
6
,
metricService
.
get
AllCounters
(
).
size
());
assertEquals
(
6
,
metricService
.
get
MetricsByType
(
MetricType
.
COUNTER
).
size
());
assertEquals
(
22
,
metricService
.
getAllMetricKeys
().
size
());
assertEquals
(
22
,
metricService
.
getAllMetricKeys
().
size
());
}
}
...
...
server/src/test/resources/datanode1conf/iotdb-datanode.properties
浏览文件 @
91aa0341
...
@@ -35,10 +35,9 @@ dn_tracing_dir=target/datanode1/data/tracing
...
@@ -35,10 +35,9 @@ dn_tracing_dir=target/datanode1/data/tracing
dn_consensus_dir
=
target/datanode1/consensus
dn_consensus_dir
=
target/datanode1/consensus
dn_sync_dir
=
target/datanode1/sync
dn_sync_dir
=
target/datanode1/sync
dn_enable_metric
=
true
dn_enable_performance_stat
=
false
dn_enable_performance_stat
=
false
dn_metric_reporter_list
=
PROMETHEUS
dn_metric_reporter_list
=
PROMETHEUS
dn_metric_frame_type
=
MICROMETER
dn_metric_frame_type
=
MICROMETER
dn_metric_level
=
CORE
dn_metric_level
=
IMPORTANT
dn_metric_async_collect_period
=
5
dn_metric_async_collect_period
=
5
dn_metric_prometheus_reporter_port
=
9097
dn_metric_prometheus_reporter_port
=
9097
\ No newline at end of file
server/src/test/resources/datanode2conf/iotdb-datanode.properties
浏览文件 @
91aa0341
...
@@ -35,10 +35,9 @@ dn_tracing_dir=target/datanode2/data/tracing
...
@@ -35,10 +35,9 @@ dn_tracing_dir=target/datanode2/data/tracing
dn_consensus_dir
=
target/datanode2/consensus
dn_consensus_dir
=
target/datanode2/consensus
dn_sync_dir
=
target/datanode2/sync
dn_sync_dir
=
target/datanode2/sync
dn_enable_metric
=
true
dn_enable_performance_stat
=
false
dn_enable_performance_stat
=
false
dn_metric_reporter_list
=
PROMETHEUS
dn_metric_reporter_list
=
PROMETHEUS
dn_metric_frame_type
=
MICROMETER
dn_metric_frame_type
=
MICROMETER
dn_metric_level
=
CORE
dn_metric_level
=
IMPORTANT
dn_metric_async_collect_period
=
5
dn_metric_async_collect_period
=
5
dn_metric_prometheus_reporter_port
=
9099
dn_metric_prometheus_reporter_port
=
9099
server/src/test/resources/datanode3conf/iotdb-datanode.properties
浏览文件 @
91aa0341
...
@@ -35,10 +35,9 @@ dn_tracing_dir=target/datanode3/data/tracing
...
@@ -35,10 +35,9 @@ dn_tracing_dir=target/datanode3/data/tracing
dn_consensus_dir
=
target/datanode3/consensus
dn_consensus_dir
=
target/datanode3/consensus
dn_sync_dir
=
target/datanode3/sync
dn_sync_dir
=
target/datanode3/sync
dn_enable_metric
=
true
dn_enable_performance_stat
=
false
dn_enable_performance_stat
=
false
dn_metric_reporter_list
=
PROMETHEUS
dn_metric_reporter_list
=
PROMETHEUS
dn_metric_frame_type
=
MICROMETER
dn_metric_frame_type
=
MICROMETER
dn_metric_level
=
CORE
dn_metric_level
=
IMPORTANT
dn_metric_async_collect_period
=
5
dn_metric_async_collect_period
=
5
dn_metric_prometheus_reporter_port
=
9101
dn_metric_prometheus_reporter_port
=
9101
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录