heyile closed pull request #987: [SCB-1017]add os cpu net info in the metrics
with linux os
URL: https://github.com/apache/servicecomb-java-chassis/pull/987
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsBootstrap.java
b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsBootstrap.java
index 7f13bf17c..b218ea741 100644
---
a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsBootstrap.java
+++
b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsBootstrap.java
@@ -18,12 +18,17 @@
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
+import org.apache.servicecomb.foundation.metrics.publish.spectator.CpuNode;
+import org.apache.servicecomb.foundation.metrics.publish.spectator.NetNode;
+import org.apache.servicecomb.foundation.metrics.util.SystemOsUtil;
import com.google.common.collect.Lists;
import com.google.common.eventbus.EventBus;
@@ -33,6 +38,7 @@
import com.netflix.spectator.api.Meter;
public class MetricsBootstrap {
+
private CompositeRegistry globalRegistry;
private EventBus eventBus;
@@ -41,13 +47,37 @@
private ScheduledExecutorService executorService;
+ //cpu
+ private ScheduledExecutorService cpuExcutorService;
+
+ //network
+ private ScheduledExecutorService netExcutorService;
+
+ private CpuNode cpuNode;
+
+ private final Map<String, NetNode> netNodeMap = new HashMap<>();
+
public void start(CompositeRegistry globalRegistry, EventBus eventBus) {
this.globalRegistry = globalRegistry;
this.eventBus = eventBus;
+ cpuNode = CpuNode.getINSTANCE();
this.executorService = Executors.newScheduledThreadPool(1,
new ThreadFactoryBuilder()
.setNameFormat("spectator-poller-%d")
.build());
+ if (!System.getProperty("os.name").toLowerCase().startsWith("win")) {
+ // linux OS
+ this.cpuExcutorService = Executors.newScheduledThreadPool(1,
+ new ThreadFactoryBuilder()
+ .setNameFormat("cpu-poller-%d")
+ .build()
+ );
+ this.netExcutorService = Executors.newScheduledThreadPool(1,
+ new ThreadFactoryBuilder()
+ .setNameFormat("net-poller-%d")
+ .build()
+ );
+ }
loadMetricsInitializers();
startPoll();
@@ -76,6 +106,17 @@ protected void startPoll() {
0,
config.getMsPollInterval(),
TimeUnit.MILLISECONDS);
+ if (!System.getProperty("os.name").toLowerCase().startsWith("win")) {
+ //Linux OS
+ cpuExcutorService.scheduleAtFixedRate(this::pollCpu,
+ 0,
+ config.getMsCPUInterval(),
+ TimeUnit.MILLISECONDS);
+ netExcutorService.scheduleAtFixedRate(this::pollNet,
+ 0,
+ config.getMsNetInterval(),
+ TimeUnit.MILLISECONDS);
+ }
}
protected void pollMeters() {
@@ -86,8 +127,17 @@ protected void pollMeters() {
for (Meter meter : meters) {
meter.measure().forEach(measurements::add);
}
- PolledEvent event = new PolledEvent(meters, measurements);
+
+ PolledEvent event = new PolledEvent(meters, measurements, cpuNode,
netNodeMap, config.isPrintOsInfo());
eventBus.post(event);
}
+
+ protected void pollCpu() {
+ SystemOsUtil.refreshCpu(this.cpuNode);
+ }
+
+ protected void pollNet() {
+ SystemOsUtil.refreshNet(this.netNodeMap, config.getMsNetInterval());
+ }
}
diff --git
a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsBootstrapConfig.java
b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsBootstrapConfig.java
index d1b6be72f..17ddd090b 100644
---
a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsBootstrapConfig.java
+++
b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsBootstrapConfig.java
@@ -21,16 +21,54 @@
public class MetricsBootstrapConfig {
public static final String METRICS_WINDOW_TIME =
"servicecomb.metrics.window_time";
+ public static final String METRICS_CPU_TIME = "servicecomb.metrics.cpu_time";
+
+ public static final String METRICS_NET_TIME = "servicecomb.metrics.net_time";
+
+ public static final String METRICS_ENABLED =
"servicecomb.metrics.printOs.enabled";
+
public static final int DEFAULT_METRICS_WINDOW_TIME = 60000;
+ // 1 s
+ public static final int DEFAULT_METRICS_CPU_TIME = 1000;
+
+ //2 s
+ public static final int DEFAULT_METRICS_NET_TIME = 2000;
+
+ public static final boolean DEFAULT_METRICS_ENABLED = false;
+
private long msPollInterval;
+ private long msCPUInterval;
+
+ private long msNetInterval;
+
+ private boolean printOsInfo;
+
public MetricsBootstrapConfig() {
msPollInterval =
DynamicPropertyFactory.getInstance().getIntProperty(METRICS_WINDOW_TIME,
DEFAULT_METRICS_WINDOW_TIME).get();
+ msCPUInterval =
+ DynamicPropertyFactory.getInstance().getIntProperty(METRICS_CPU_TIME,
DEFAULT_METRICS_CPU_TIME).get();
+ msNetInterval =
+ DynamicPropertyFactory.getInstance().getIntProperty(METRICS_NET_TIME,
DEFAULT_METRICS_NET_TIME).get();
+ printOsInfo =
DynamicPropertyFactory.getInstance().getBooleanProperty(METRICS_ENABLED,
DEFAULT_METRICS_ENABLED)
+ .get();
}
public long getMsPollInterval() {
return msPollInterval;
}
+
+ public long getMsCPUInterval() {
+ return msCPUInterval;
+ }
+
+ public long getMsNetInterval() {
+ return msNetInterval;
+ }
+
+ public boolean isPrintOsInfo() {
+ return printOsInfo;
+ }
}
diff --git
a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/PolledEvent.java
b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/PolledEvent.java
index 6b7c3018c..cc3129a7d 100644
---
a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/PolledEvent.java
+++
b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/PolledEvent.java
@@ -17,6 +17,10 @@
package org.apache.servicecomb.foundation.metrics;
import java.util.List;
+import java.util.Map;
+
+import org.apache.servicecomb.foundation.metrics.publish.spectator.CpuNode;
+import org.apache.servicecomb.foundation.metrics.publish.spectator.NetNode;
import com.netflix.spectator.api.Measurement;
import com.netflix.spectator.api.Meter;
@@ -24,10 +28,20 @@
public class PolledEvent {
private List<Meter> meters;
+ private boolean printOsInfo;
+
private List<Measurement> measurements;
- public PolledEvent(List<Meter> meters, List<Measurement> measurements) {
+ private CpuNode cpuNode;
+
+ private Map<String, NetNode> netNodeMap;
+
+ public PolledEvent(List<Meter> meters, List<Measurement> measurements,
CpuNode cpuNode,
+ Map<String, NetNode> netNodeMap, boolean printOsInfo) {
+ this.cpuNode = cpuNode;
+ this.netNodeMap = netNodeMap;
this.meters = meters;
+ this.printOsInfo = printOsInfo;
this.measurements = measurements;
}
@@ -46,4 +60,24 @@ public void setMeters(List<Meter> meters) {
public void setMeasurements(List<Measurement> measurements) {
this.measurements = measurements;
}
+
+ public CpuNode getCpuNode() {
+ return cpuNode;
+ }
+
+ public void setCpuNode(CpuNode cpuNode) {
+ this.cpuNode = cpuNode;
+ }
+
+ public Map<String, NetNode> getNetNodeMap() {
+ return netNodeMap;
+ }
+
+ public void setNetNodeMap(Map<String, NetNode> netNodeMap) {
+ this.netNodeMap = netNodeMap;
+ }
+
+ public boolean isPrintOsInfo() {
+ return printOsInfo;
+ }
}
diff --git
a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/publish/spectator/CpuNode.java
b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/publish/spectator/CpuNode.java
new file mode 100644
index 000000000..f33feb900
--- /dev/null
+++
b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/publish/spectator/CpuNode.java
@@ -0,0 +1,107 @@
+/*
+ * 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.servicecomb.foundation.metrics.publish.spectator;
+
+import java.text.NumberFormat;
+
+public class CpuNode {
+
+ private static CpuNode INSTANCE = new CpuNode();
+
+ private NumberFormat nt = NumberFormat.getPercentInstance();
+
+ private long lastCpuTotalTime = -1L;
+
+ private long lastIdleTime = -1L;
+
+ private float cpuRate = -1.0f;
+
+ private CpuNode() {
+
+ }
+
+
+ public static CpuNode getINSTANCE() {
+ return INSTANCE;
+ }
+
+ public long getLastCpuTotalTime() {
+ return lastCpuTotalTime;
+ }
+
+ private boolean isFirstTime() {
+ return lastCpuTotalTime == -1L || lastIdleTime == -1L;
+ }
+
+ public void setLastCpuTotalTime(long lastCpuTotalTime) {
+ this.lastCpuTotalTime = lastCpuTotalTime;
+ }
+
+ public long getLastIdleTime() {
+ return lastIdleTime;
+ }
+
+ public void setLastIdleTime(long lastIdleTime) {
+ this.lastIdleTime = lastIdleTime;
+ }
+
+
+ public String getCpuPercent(int num) {
+ if (cpuRate == -1.0f) {
+ return "calculate is not finished yet. please wait ...";
+ }
+ nt.setMaximumFractionDigits(num);
+ nt.setMinimumFractionDigits(num);
+ return nt.format(cpuRate);
+ }
+
+ public void setCpuRate(float cpuRate) {
+ this.cpuRate = cpuRate;
+ }
+
+ public void parseFromCpu(String cpuInfo) {
+ long total = -1L;
+ long idle = -1L;
+ /*
+ * unit : 1 jiffies = 10ms = 0.01 s
+ * more details :
+ * http://man7.org/linux/man-pages/man5/proc.5.html
+ * cpu 2445171 599297 353967 24490633 11242 0 10780 2993
0 0
+ * cpu user nice system idle iowait irq softirq stealstolen
guest guest_nice
+ * cpuTotal = user + nice + system + idle + wowait + itq + softirq +
stealstolen
+ */
+ String[] cpuInfos = cpuInfo.trim().split("\\s+");
+ for (int i = 1; i <= 8; i++) {
+ long value = Long.parseLong(cpuInfos[i]);
+ if (i == 4) {
+ idle = value;
+ }
+ total += value;
+ }
+ //check
+ if (total != -1L && idle != -1L) {
+ if (isFirstTime()) {
+ lastCpuTotalTime = total;
+ lastIdleTime = idle;
+ } else {
+ cpuRate = 1.0f - (float) (idle - lastIdleTime) / (total -
lastCpuTotalTime);
+ lastIdleTime = idle;
+ lastCpuTotalTime = total;
+ }
+ }
+ }
+}
diff --git
a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/publish/spectator/NetNode.java
b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/publish/spectator/NetNode.java
new file mode 100644
index 000000000..1b9aa1118
--- /dev/null
+++
b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/publish/spectator/NetNode.java
@@ -0,0 +1,131 @@
+/*
+ * 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.servicecomb.foundation.metrics.publish.spectator;
+
+import java.text.NumberFormat;
+
+public class NetNode {
+ private NumberFormat nf = NumberFormat.getNumberInstance();
+
+ //receive bytes
+ private long lastRxBytes = -1L;
+
+ //transmit bytes
+ private long lastTxBytes = -1L;
+
+ private String netName;
+
+ // ms
+ private double interval;
+
+ // bytes per second
+ private double sendRate = -1.0;
+
+ private double receiveRate = -1.0;
+
+ public double getInterval() {
+ return interval;
+ }
+
+ public NetNode(String netName, double interval) {
+ this.netName = netName;
+ this.interval = interval;
+ }
+
+ public void setInterval(double interval) {
+ this.interval = interval;
+ }
+
+ private boolean isFirstTime() {
+ return lastRxBytes == -1L || lastTxBytes == -1L;
+ }
+
+ public long getLastRxBytes() {
+ return lastRxBytes;
+ }
+
+ public void setLastRxBytes(long lastRxBytes) {
+ this.lastRxBytes = lastRxBytes;
+ }
+
+ public long getLastTxBytes() {
+ return lastTxBytes;
+ }
+
+ public void setLastTxBytes(long lastTxBytes) {
+ this.lastTxBytes = lastTxBytes;
+ }
+
+ public String getNetName() {
+ return netName;
+ }
+
+ public void setNetName(String netName) {
+ this.netName = netName;
+ }
+
+ public String getSendRate(int num) {
+ if (sendRate == -1.0) {
+ return "calculate ...";
+ }
+ nf.setMaximumFractionDigits(num);
+ nf.setMinimumFractionDigits(num);
+
+ return nf.format(sendRate);
+ }
+
+ public void setSendRate(double sendRate) {
+ this.sendRate = sendRate;
+ }
+
+ public String getReceiveRate(int num) {
+ if (receiveRate == -1.0) {
+ return "calculate ...";
+ }
+ nf.setMaximumFractionDigits(num);
+ nf.setMinimumFractionDigits(num);
+
+ return nf.format(receiveRate);
+ }
+
+ public void setReceiveRate(double receiveRate) {
+ this.receiveRate = receiveRate;
+ }
+
+
+ public void parseFromNetInfo(String netInfo) {
+ String[] netInfos = netInfo.trim().split("\\s+");
+ /*
+ * Inter-| Receive
| Transmit
+ * face |bytes packets errs drop fifo frame compressed
multicast|bytes packets errs drop fifo colls carrier compressed
+ * eth0: 2615248100 32148518 0 0 0 0 0 0
87333034794 21420267 0 0 0 0 0 0
+ * 0 1 2 3 4 5 6 7
8
+ */
+ if (isFirstTime()) {
+ lastRxBytes = Long.parseLong(netInfos[0]);
+ lastTxBytes = Long.parseLong(netInfos[8]);
+ } else {
+ //not first time
+ long latestRxBytes = Long.parseLong(netInfos[0]);
+ long latestTxBytes = Long.parseLong(netInfos[8]);
+ sendRate = (latestTxBytes - lastTxBytes) * 1000 / interval;
+ receiveRate = (latestRxBytes - lastRxBytes) * 1000 / interval;
+ lastRxBytes = latestRxBytes;
+ lastTxBytes = latestTxBytes;
+ }
+ }
+}
diff --git
a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/util/SystemOsUtil.java
b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/util/SystemOsUtil.java
new file mode 100644
index 000000000..bc8edaa8e
--- /dev/null
+++
b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/util/SystemOsUtil.java
@@ -0,0 +1,74 @@
+package org.apache.servicecomb.foundation.metrics.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Map;
+
+import org.apache.servicecomb.foundation.metrics.publish.spectator.CpuNode;
+import org.apache.servicecomb.foundation.metrics.publish.spectator.NetNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SystemOsUtil {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(SystemOsUtil.class);
+
+ private static final String linuxCpuCmd = "cat /proc/stat";
+
+ private static final String linuxNetCmd = "cat /proc/net/dev";
+
+ private static final String error = "error";
+
+ // refresh linux os cpu
+ public static void refreshCpu(CpuNode cpuNode) {
+ String cpuInfo = runCommand(linuxCpuCmd);
+ if (error.equals(cpuInfo)) {
+ // can not get cpu info
+ return;
+ }
+ //get only the first line
+ cpuNode.parseFromCpu(cpuInfo.substring(0, cpuInfo.indexOf("\n")));
+ }
+
+ // refresh linux os net
+ public static void refreshNet(Map<String, NetNode> netNodeMap, long
interval) {
+ String netInfo = runCommand(linuxNetCmd);
+ if (error.equals(netInfo)) {
+ // can not get net info
+ return;
+ }
+ String[] netInfos = netInfo.split("\n");
+ //the first two lines is needless
+ for (int i = 2; i < netInfos.length; i++) {
+ String netStr = netInfos[i];
+ String[] strings = netStr.split(":");
+ if (strings.length != 2) {
+ LOGGER.warn(" there is something wrong with {} ", netStr);
+ continue;
+ }
+ NetNode netNode = netNodeMap.computeIfAbsent(strings[0].trim(), key ->
new NetNode(key, interval));
+ netNode.parseFromNetInfo(strings[1]);
+ }
+ }
+
+ private static String runCommand(String cmd) {
+ try {
+ Process pos = Runtime.getRuntime().exec(cmd);
+ pos.waitFor();
+ InputStreamReader inputStreamReader = new
InputStreamReader(pos.getInputStream());
+ BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
+ String line;
+ StringBuilder stringBuilder = new StringBuilder();
+ while ((line = bufferedReader.readLine()) != null) {
+ stringBuilder.append(line)
+ .append("\n");
+ }
+ return stringBuilder.toString();
+ } catch (InterruptedException | IOException e) {
+ LOGGER.error("run cmd {} failed", cmd);
+ e.printStackTrace();
+ }
+ return error;
+ }
+}
diff --git
a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/TestMetricsBootstrap.java
b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/TestMetricsBootstrap.java
index 50cb30c72..b90f7c597 100644
---
a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/TestMetricsBootstrap.java
+++
b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/TestMetricsBootstrap.java
@@ -84,7 +84,7 @@ public void pollMeters(@Mocked Meter meter, @Mocked
Measurement measurement,
};
bootstrap.start(globalRegistry, eventBus);
- PolledEvent result = new PolledEvent(null, null);
+ PolledEvent result = new PolledEvent(null, null, null, null, false);
eventBus.register(new Object() {
@Subscribe
public void onEvent(PolledEvent event) {
diff --git
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/DefaultLogPublisher.java
b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/DefaultLogPublisher.java
index e9575fc65..76636e43a 100644
---
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/DefaultLogPublisher.java
+++
b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/DefaultLogPublisher.java
@@ -23,6 +23,8 @@
import org.apache.servicecomb.foundation.metrics.MetricsBootstrapConfig;
import org.apache.servicecomb.foundation.metrics.MetricsInitializer;
import org.apache.servicecomb.foundation.metrics.PolledEvent;
+import org.apache.servicecomb.foundation.metrics.publish.spectator.CpuNode;
+import org.apache.servicecomb.foundation.metrics.publish.spectator.NetNode;
import org.apache.servicecomb.foundation.vertx.VertxUtils;
import
org.apache.servicecomb.metrics.core.meter.invocation.MeterInvocationConst;
import org.apache.servicecomb.metrics.core.publish.model.DefaultPublishModel;
@@ -47,6 +49,11 @@
public static final String ENABLED =
"servicecomb.metrics.publisher.defaultLog.enabled";
+ //os
+ public static final String NET_HEADER = " interface
send recv\n";
+
+ public static final String NET_CONTENT_FORMAT = " %-29s %-42s %s\n";
+
//sample
private static final String SIMPLE_HEADER = "%s:\n simple:\n"
+ " status tps latency
operation\n";
@@ -85,14 +92,15 @@ public void init(CompositeRegistry globalRegistry, EventBus
eventBus, MetricsBoo
@Subscribe
public void onPolledEvent(PolledEvent event) {
try {
- printLog(event.getMeters());
+ printLog(event.getMeters(), event.getCpuNode(), event.getNetNodeMap(),
event.isPrintOsInfo());
} catch (Throwable e) {
// make development easier
LOGGER.error("Failed to print perf log.", e);
}
}
- protected void printLog(List<Meter> meters) {
+ protected void printLog(List<Meter> meters, CpuNode cpuNode, Map<String,
NetNode> netNodeMap, boolean printOsInfo) {
+
StringBuilder sb = new StringBuilder();
sb.append("\n");
@@ -102,6 +110,7 @@ protected void printLog(List<Meter> meters) {
DefaultPublishModel model = factory.createDefaultPublishModel();
printThreadPoolMetrics(model, sb);
+ printOsLog(cpuNode, netNodeMap, printOsInfo, sb);
printConsumerLog(model, sb);
printProducerLog(model, sb);
@@ -110,6 +119,20 @@ protected void printLog(List<Meter> meters) {
LOGGER.info(sb.toString());
}
+ protected void printOsLog(CpuNode cpuNode, Map<String, NetNode> netNodeMap,
boolean printOsInfo, StringBuilder sb) {
+ //print os
+ if (printOsInfo) {
+ sb.append("os:\n")
+ .append(String.format(" cpu: %s\n", cpuNode.getCpuPercent(3)))
+ .append(" net:\n")
+ .append(NET_HEADER);
+ for (NetNode netNode : netNodeMap.values()) {
+ sb.append(String.format(NET_CONTENT_FORMAT,
+ netNode.getNetName(), netNode.getSendRate(0),
netNode.getReceiveRate(0)));
+ }
+ }
+ }
+
protected void printThreadPoolMetrics(DefaultPublishModel model,
StringBuilder sb) {
if (model.getThreadPools().isEmpty()) {
return;
diff --git
a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/TestDefaultLogPublisher.java
b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/TestDefaultLogPublisher.java
index 2accd3473..a8bd949a6 100644
---
a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/TestDefaultLogPublisher.java
+++
b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/TestDefaultLogPublisher.java
@@ -17,6 +17,7 @@
package org.apache.servicecomb.metrics.core.publish;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
@@ -27,6 +28,8 @@
import org.apache.servicecomb.core.Const;
import org.apache.servicecomb.foundation.metrics.MetricsBootstrapConfig;
import org.apache.servicecomb.foundation.metrics.PolledEvent;
+import org.apache.servicecomb.foundation.metrics.publish.spectator.CpuNode;
+import org.apache.servicecomb.foundation.metrics.publish.spectator.NetNode;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector;
import org.apache.servicecomb.foundation.vertx.VertxUtils;
@@ -180,7 +183,9 @@ DefaultPublishModel createDefaultPublishModel() {
}
};
- publisher.onPolledEvent(new PolledEvent(Collections.emptyList(),
Collections.emptyList()));
+ publisher.onPolledEvent(
+ new PolledEvent(Collections.emptyList(), Collections.emptyList(),
CpuNode.getINSTANCE(), new HashMap<String, NetNode>(),
+ false));
List<LoggingEvent> events = collector.getEvents().stream().filter(e -> {
return DefaultLogPublisher.class.getName().equals(e.getLoggerName());
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services