Skip to content

Commit 3a4c085

Browse files
authored
Add OFF level (#11530)
* Add OFF * Fix comment
1 parent 726c473 commit 3a4c085

File tree

8 files changed

+109
-38
lines changed

8 files changed

+109
-38
lines changed

iotdb-core/confignode/src/assembly/resources/conf/iotdb-confignode.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ cn_seed_config_node=127.0.0.1:10710
125125
# cn_metric_reporter_list=
126126

127127
# The level of metric module
128-
# Options: [CORE, IMPORTANT, NORMAL, ALL]
128+
# Options: [OFF, CORE, IMPORTANT, NORMAL, ALL]
129129
# Datatype: String
130130
# cn_metric_level=CORE
131131

iotdb-core/datanode/src/assembly/resources/conf/iotdb-datanode.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ dn_seed_config_node=127.0.0.1:10710
261261
# dn_metric_reporter_list=
262262

263263
# The level of metric module
264-
# Options: [CORE, IMPORTANT, NORMAL, ALL]
264+
# Options: [OFF, CORE, IMPORTANT, NORMAL, ALL]
265265
# Datatype: String
266266
# dn_metric_level=CORE
267267

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.metrics.metricsets.disk;
21+
22+
public class DoNothingDiskMetricsManager implements IDiskMetricsManager {}

iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/disk/IDiskMetricsManager.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
package org.apache.iotdb.metrics.metricsets.disk;
2121

22+
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
23+
import org.apache.iotdb.metrics.utils.MetricLevel;
24+
2225
import java.util.Collections;
2326
import java.util.Map;
2427
import java.util.Set;
@@ -110,14 +113,21 @@ default Set<String> getDiskIds() {
110113

111114
/** Return different implementation of DiskMetricsManager according to OS type. */
112115
static IDiskMetricsManager getDiskMetricsManager() {
113-
String os = System.getProperty("os.name").toLowerCase();
114-
115-
if (os.startsWith("windows")) {
116-
return new WindowsDiskMetricsManager();
117-
} else if (os.startsWith("linux")) {
118-
return new LinuxDiskMetricsManager();
116+
if (MetricConfigDescriptor.getInstance()
117+
.getMetricConfig()
118+
.getMetricLevel()
119+
.equals(MetricLevel.OFF)) {
120+
return new DoNothingDiskMetricsManager();
119121
} else {
120-
return new MacDiskMetricsManager();
122+
String os = System.getProperty("os.name").toLowerCase();
123+
124+
if (os.startsWith("windows")) {
125+
return new WindowsDiskMetricsManager();
126+
} else if (os.startsWith("linux")) {
127+
return new LinuxDiskMetricsManager();
128+
} else {
129+
return new MacDiskMetricsManager();
130+
}
121131
}
122132
}
123133
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.metrics.metricsets.net;
21+
22+
public class DoNothingNetMetricManager implements INetMetricManager {}

iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/INetMetricManager.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,14 @@
1919

2020
package org.apache.iotdb.metrics.metricsets.net;
2121

22+
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
23+
import org.apache.iotdb.metrics.utils.MetricLevel;
24+
2225
import java.util.Collections;
2326
import java.util.Map;
2427
import java.util.Set;
2528

2629
public interface INetMetricManager {
27-
static INetMetricManager getNetMetricManager() {
28-
String os = System.getProperty("os.name").toLowerCase();
29-
30-
if (os.startsWith("windows")) {
31-
return new WindowsNetMetricManager();
32-
} else if (os.startsWith("linux")) {
33-
return new LinuxNetMetricManager();
34-
} else {
35-
return new MacNetMetricManager();
36-
}
37-
}
3830

3931
default Map<String, Long> getReceivedByte() {
4032
return Collections.emptyMap();
@@ -59,4 +51,23 @@ default Set<String> getIfaceSet() {
5951
default int getConnectionNum() {
6052
return 0;
6153
}
54+
55+
static INetMetricManager getNetMetricManager() {
56+
if (MetricConfigDescriptor.getInstance()
57+
.getMetricConfig()
58+
.getMetricLevel()
59+
.equals(MetricLevel.OFF)) {
60+
return new DoNothingNetMetricManager();
61+
} else {
62+
String os = System.getProperty("os.name").toLowerCase();
63+
64+
if (os.startsWith("windows")) {
65+
return new WindowsNetMetricManager();
66+
} else if (os.startsWith("linux")) {
67+
return new LinuxNetMetricManager();
68+
} else {
69+
return new MacNetMetricManager();
70+
}
71+
}
72+
}
6273
}

iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/system/SystemMetrics.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.apache.iotdb.metrics.metricsets.system;
2121

2222
import org.apache.iotdb.metrics.AbstractMetricService;
23+
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
2324
import org.apache.iotdb.metrics.metricsets.IMetricSet;
2425
import org.apache.iotdb.metrics.utils.MetricLevel;
2526
import org.apache.iotdb.metrics.utils.MetricType;
@@ -57,26 +58,31 @@ public SystemMetrics() {
5758
}
5859

5960
public void setDiskDirs(List<String> diskDirs) {
60-
this.diskDirs.set(diskDirs);
61-
for (String diskDir : this.diskDirs.get()) {
62-
if (!FSUtils.isLocal(diskDir)) {
63-
continue;
64-
}
65-
Path path = Paths.get(diskDir);
66-
FileStore fileStore = null;
67-
try {
68-
fileStore = Files.getFileStore(path);
69-
} catch (IOException e) {
70-
// check parent if path is not exists
71-
path = path.getParent();
61+
if (!MetricConfigDescriptor.getInstance()
62+
.getMetricConfig()
63+
.getMetricLevel()
64+
.equals(MetricLevel.OFF)) {
65+
this.diskDirs.set(diskDirs);
66+
for (String diskDir : this.diskDirs.get()) {
67+
if (!FSUtils.isLocal(diskDir)) {
68+
continue;
69+
}
70+
Path path = Paths.get(diskDir);
71+
FileStore fileStore = null;
7272
try {
7373
fileStore = Files.getFileStore(path);
74-
} catch (IOException innerException) {
75-
logger.error("Failed to get storage path of {}, because", diskDir, innerException);
74+
} catch (IOException e) {
75+
// check parent if path is not exists
76+
path = path.getParent();
77+
try {
78+
fileStore = Files.getFileStore(path);
79+
} catch (IOException innerException) {
80+
logger.error("Failed to get storage path of {}, because", diskDir, innerException);
81+
}
82+
}
83+
if (null != fileStore) {
84+
fileStores.add(fileStore);
7685
}
77-
}
78-
if (null != fileStore) {
79-
fileStores.add(fileStore);
8086
}
8187
}
8288
}

iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/utils/MetricLevel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public enum MetricLevel {
2424
NORMAL(1),
2525
IMPORTANT(2),
2626
CORE(3),
27-
DO_NOTHING(4);
27+
OFF(4);
2828

2929
/** Level of metric service. */
3030
final int level;

0 commit comments

Comments
 (0)