You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ma...@apache.org on 2023/03/11 12:24:01 UTC
[iotdb] 01/01: define the interface
This is an automated email from the ASF dual-hosted git repository.
marklau99 pushed a commit to branch IOTDB-5663
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit ed4f5788fe8bea1cad7fa4efbc9d2444c1fd421c
Author: LiuXuxin <li...@outlook.com>
AuthorDate: Sat Mar 11 20:23:47 2023 +0800
define the interface
---
.../iotdb/confignode/service/ConfigNode.java | 2 +
.../iotdb/metrics/metricsets/disk/DiskMetrics.java | 22 +++--
.../metrics/metricsets/net/INetMetricManager.java | 58 ++++++++++++
.../metricsets/net/LinuxNetMetricManager.java | 22 +++++
.../metricsets/net/MacNetMetricManager.java | 22 +++++
.../iotdb/metrics/metricsets/net/NetMetrics.java | 102 +++++++++++++++++++++
.../metricsets/net/WindowsNetMetricManager.java | 22 +++++
.../db/service/metrics/DataNodeMetricsHelper.java | 2 +
8 files changed, 242 insertions(+), 10 deletions(-)
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/service/ConfigNode.java b/confignode/src/main/java/org/apache/iotdb/confignode/service/ConfigNode.java
index 08455c4ac7..bd66190163 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/service/ConfigNode.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/service/ConfigNode.java
@@ -45,6 +45,7 @@ import org.apache.iotdb.db.service.metrics.SystemMetrics;
import org.apache.iotdb.metrics.metricsets.disk.DiskMetrics;
import org.apache.iotdb.metrics.metricsets.jvm.JvmMetrics;
import org.apache.iotdb.metrics.metricsets.logback.LogbackMetrics;
+import org.apache.iotdb.metrics.metricsets.net.NetMetrics;
import org.apache.iotdb.rpc.TSStatusCode;
import org.slf4j.Logger;
@@ -218,6 +219,7 @@ public class ConfigNode implements ConfigNodeMBean {
MetricService.getInstance().addMetricSet(new ProcessMetrics());
MetricService.getInstance().addMetricSet(new SystemMetrics(false));
MetricService.getInstance().addMetricSet(new DiskMetrics(IoTDBConstant.CN_ROLE));
+ MetricService.getInstance().addMetricSet(new NetMetrics(IoTDBConstant.CN_ROLE));
LOGGER.info("Successfully setup internal services.");
}
diff --git a/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/disk/DiskMetrics.java b/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/disk/DiskMetrics.java
index 92552914dd..1236ce8367 100644
--- a/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/disk/DiskMetrics.java
+++ b/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/disk/DiskMetrics.java
@@ -250,16 +250,18 @@ public class DiskMetrics implements IMetricSet {
// metrics for disks
Set<String> diskIDs = diskMetricsManager.getDiskIds();
for (String diskID : diskIDs) {
- metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_SIZE, NAME, READ, NAME, diskID);
- metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_SIZE, NAME, WRITE, NAME, diskID);
- metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_OPS, NAME, READ, NAME, diskID);
- metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_OPS, NAME, WRITE, NAME, diskID);
- metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_TIME, NAME, READ, NAME, diskID);
- metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_TIME, NAME, WRITE, NAME, diskID);
- metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_TIME, NAME, AVG_READ, NAME, diskID);
- metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_TIME, NAME, AVG_WRITE, NAME, diskID);
- metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_AVG_SIZE, NAME, READ, NAME, diskID);
- metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_AVG_SIZE, NAME, WRITE, NAME, diskID);
+ metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_SIZE, TYPE, READ, NAME, diskID);
+ metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_SIZE, TYPE, WRITE, NAME, diskID);
+ metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_OPS, TYPE, READ, NAME, diskID);
+ metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_OPS, TYPE, WRITE, NAME, diskID);
+ metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_TIME, TYPE, READ, NAME, diskID);
+ metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_TIME, TYPE, WRITE, NAME, diskID);
+ metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_TIME, TYPE, AVG_READ, NAME, diskID);
+ metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_TIME, TYPE, AVG_WRITE, NAME, diskID);
+ metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_AVG_SIZE, TYPE, READ, NAME, diskID);
+ metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_AVG_SIZE, TYPE, WRITE, NAME, diskID);
+ metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_BUSY_PERCENTAGE, NAME, diskID);
+ metricService.remove(MetricType.AUTO_GAUGE, DISK_IO_QUEUE_SIZE, NAME, diskID);
}
// metrics for datanode and config node
diff --git a/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/INetMetricManager.java b/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/INetMetricManager.java
new file mode 100644
index 0000000000..f6ae15d37c
--- /dev/null
+++ b/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/INetMetricManager.java
@@ -0,0 +1,58 @@
+/*
+ * 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.metricsets.net;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+public interface INetMetricManager {
+ static INetMetricManager getNetMetricManager() {
+ String os = System.getProperty("os.name").toLowerCase();
+
+ if (os.startsWith("windows")) {
+ return new WindowsNetMetricManager();
+ } else if (os.startsWith("linux")) {
+ return new LinuxNetMetricManager();
+ } else {
+ return new MacNetMetricManager();
+ }
+ }
+
+ default Map<String, Long> getReceivedByte() {
+ return Collections.emptyMap();
+ }
+
+ default Map<String, Long> getTransmittedBytes() {
+ return Collections.emptyMap();
+ }
+
+ default Map<String, Long> getReceivedPackets() {
+ return Collections.emptyMap();
+ }
+
+ default Map<String, Long> getTransmittedPackets() {
+ return Collections.emptyMap();
+ }
+
+ default Set<String> getIfaceSet() {
+ return Collections.emptySet();
+ }
+}
diff --git a/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/LinuxNetMetricManager.java b/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/LinuxNetMetricManager.java
new file mode 100644
index 0000000000..0c9c3da024
--- /dev/null
+++ b/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/LinuxNetMetricManager.java
@@ -0,0 +1,22 @@
+/*
+ * 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.metricsets.net;
+
+public class LinuxNetMetricManager implements INetMetricManager {}
diff --git a/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/MacNetMetricManager.java b/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/MacNetMetricManager.java
new file mode 100644
index 0000000000..bb3a31fba2
--- /dev/null
+++ b/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/MacNetMetricManager.java
@@ -0,0 +1,22 @@
+/*
+ * 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.metricsets.net;
+
+public class MacNetMetricManager implements INetMetricManager {}
diff --git a/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/NetMetrics.java b/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/NetMetrics.java
new file mode 100644
index 0000000000..0379e81644
--- /dev/null
+++ b/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/NetMetrics.java
@@ -0,0 +1,102 @@
+/*
+ * 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.metricsets.net;
+
+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.Set;
+
+public class NetMetrics implements IMetricSet {
+ private final INetMetricManager netMetricManager = INetMetricManager.getNetMetricManager();
+
+ private final String processName;
+
+ private static final String RECEIVED_BYTES = "received_bytes";
+ private static final String RECEIVED_PACKETS = "received_packets";
+ private static final String TRANSMITTED_BYTES = "transmitted_bytes";
+ private static final String TRANSMITTED_PACKETS = "transmitted_packets";
+
+ private static final String TYPE = "type";
+ private static final String NAME = "name";
+ private static final String RECEIVE = "receive";
+ private static final String TRANSMIT = "transmit";
+
+ public NetMetrics(String processName) {
+ this.processName = processName;
+ }
+
+ @Override
+ public void bindTo(AbstractMetricService metricService) {
+ // metrics for net
+ Set<String> iFaceSet = netMetricManager.getIfaceSet();
+ for (String iFace : iFaceSet) {
+ metricService.createAutoGauge(
+ RECEIVED_BYTES,
+ MetricLevel.IMPORTANT,
+ netMetricManager,
+ x -> x.getReceivedByte().get(iFace),
+ TYPE,
+ RECEIVE,
+ NAME,
+ iFace);
+ metricService.createAutoGauge(
+ TRANSMITTED_BYTES,
+ MetricLevel.IMPORTANT,
+ netMetricManager,
+ x -> x.getTransmittedBytes().get(iFace),
+ TYPE,
+ TRANSMIT,
+ NAME,
+ iFace);
+ metricService.createAutoGauge(
+ RECEIVED_PACKETS,
+ MetricLevel.IMPORTANT,
+ netMetricManager,
+ x -> x.getReceivedPackets().get(iFace),
+ TYPE,
+ RECEIVE,
+ NAME,
+ iFace);
+ metricService.createAutoGauge(
+ TRANSMITTED_PACKETS,
+ MetricLevel.IMPORTANT,
+ netMetricManager,
+ x -> x.getTransmittedPackets().get(iFace),
+ TYPE,
+ TRANSMIT,
+ NAME,
+ iFace);
+ }
+ }
+
+ @Override
+ public void unbindFrom(AbstractMetricService metricService) {
+ Set<String> iFaceSet = netMetricManager.getIfaceSet();
+ for (String iFace : iFaceSet) {
+ metricService.remove(MetricType.AUTO_GAUGE, RECEIVED_BYTES, TYPE, RECEIVE, NAME, iFace);
+ metricService.remove(MetricType.AUTO_GAUGE, TRANSMIT, TYPE, TRANSMIT, NAME, iFace);
+ metricService.remove(MetricType.AUTO_GAUGE, RECEIVED_PACKETS, TYPE, RECEIVE, NAME, iFace);
+ metricService.remove(MetricType.AUTO_GAUGE, TRANSMITTED_PACKETS, TYPE, TRANSMIT, NAME, iFace);
+ }
+ }
+}
diff --git a/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/WindowsNetMetricManager.java b/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/WindowsNetMetricManager.java
new file mode 100644
index 0000000000..c3ecb4b8d5
--- /dev/null
+++ b/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/net/WindowsNetMetricManager.java
@@ -0,0 +1,22 @@
+/*
+ * 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.metricsets.net;
+
+public class WindowsNetMetricManager implements INetMetricManager {}
diff --git a/server/src/main/java/org/apache/iotdb/db/service/metrics/DataNodeMetricsHelper.java b/server/src/main/java/org/apache/iotdb/db/service/metrics/DataNodeMetricsHelper.java
index b5bbf78136..5e76a37efb 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/metrics/DataNodeMetricsHelper.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/metrics/DataNodeMetricsHelper.java
@@ -31,6 +31,7 @@ import org.apache.iotdb.db.mpp.metric.SeriesScanCostMetricSet;
import org.apache.iotdb.metrics.metricsets.disk.DiskMetrics;
import org.apache.iotdb.metrics.metricsets.jvm.JvmMetrics;
import org.apache.iotdb.metrics.metricsets.logback.LogbackMetrics;
+import org.apache.iotdb.metrics.metricsets.net.NetMetrics;
public class DataNodeMetricsHelper {
/** Bind predefined metric sets into DataNode. */
@@ -42,6 +43,7 @@ public class DataNodeMetricsHelper {
MetricService.getInstance().addMetricSet(new ProcessMetrics());
MetricService.getInstance().addMetricSet(new SystemMetrics(true));
MetricService.getInstance().addMetricSet(new DiskMetrics(IoTDBConstant.DN_ROLE));
+ MetricService.getInstance().addMetricSet(new NetMetrics(IoTDBConstant.DN_ROLE));
MetricService.getInstance().addMetricSet(new WritingMetrics());
// bind query related metrics