wu-sheng closed pull request #967: Wengang ji branch
URL: https://github.com/apache/incubator-skywalking/pull/967
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/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/InstanceH2UIDAO.java
b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/InstanceH2UIDAO.java
index f520734fe..e34233748 100644
---
a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/InstanceH2UIDAO.java
+++
b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/InstanceH2UIDAO.java
@@ -18,10 +18,6 @@
package org.apache.skywalking.apm.collector.storage.h2.dao.ui;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.LinkedList;
-import java.util.List;
import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.client.h2.H2ClientException;
import org.apache.skywalking.apm.collector.core.util.BooleanUtils;
@@ -36,6 +32,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.LinkedList;
+import java.util.List;
+
/**
* @author peng-yongsheng, clevertension
*/
@@ -53,7 +54,7 @@ public InstanceH2UIDAO(H2Client client) {
private static final String GET_APPLICATIONS_SQL = "select {3}, count({0})
as cnt from {1} where {2} >= ? group by {3} limit 100";
@Override
- public Long lastHeartBeatTime() {
+ public Long lastHeartBeatTime() {
H2Client client = getClient();
long fiveMinuteBefore = System.currentTimeMillis() - 5 * 60 * 1000;
fiveMinuteBefore =
TimeBucketUtils.INSTANCE.getSecondTimeBucket(fiveMinuteBefore);
diff --git
a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/InstanceMetricH2UIDAO.java
b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/InstanceMetricH2UIDAO.java
index 410ccd366..d1f2c5e89 100644
---
a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/InstanceMetricH2UIDAO.java
+++
b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/InstanceMetricH2UIDAO.java
@@ -18,10 +18,6 @@
package org.apache.skywalking.apm.collector.storage.h2.dao.ui;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.LinkedList;
-import java.util.List;
import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.client.h2.H2ClientException;
import org.apache.skywalking.apm.collector.core.util.Const;
@@ -37,13 +33,21 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.LinkedList;
+import java.util.List;
+
/**
* @author peng-yongsheng, clevertension
*/
public class InstanceMetricH2UIDAO extends H2DAO implements
IInstanceMetricUIDAO {
-
private final Logger logger =
LoggerFactory.getLogger(InstanceMetricH2UIDAO.class);
private static final String GET_TPS_METRIC_SQL = "select * from {0} where
{1} = ?";
+ private static final String GET_SERVER_THROUGHPUT_SQL=
+ "select {0}, sum({1}) as transaction_calls,sum({2}) as
transaction_error_calls " +
+ "from {3} where {4} >= ? and {4} <= ? " +
+ "and {5}=? and {6}=? group by {0} limit ?";
public InstanceMetricH2UIDAO(H2Client client) {
super(client);
@@ -51,9 +55,33 @@ public InstanceMetricH2UIDAO(H2Client client) {
@Override public List<AppServerInfo> getServerThroughput(int
applicationId, Step step, long startTimeBucket, long endTimeBucket,
int secondBetween, int topN, MetricSource metricSource) {
- return null;
+ H2Client client = getClient();
+ String tableName = TimePyramidTableNameBuilder.build(step,
InstanceMetricTable.TABLE);
+ String sql =
SqlBuilder.buildSql(GET_SERVER_THROUGHPUT_SQL,InstanceMetricTable.COLUMN_INSTANCE_ID,
+
InstanceMetricTable.COLUMN_TRANSACTION_CALLS,InstanceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS,tableName,
+
InstanceMetricTable.COLUMN_TIME_BUCKET,InstanceMetricTable.COLUMN_APPLICATION_ID,InstanceMetricTable.COLUMN_SOURCE_VALUE);
+ List<AppServerInfo> appServerInfos = new LinkedList<>();
+ Object[] params = new Object[] {startTimeBucket,
endTimeBucket,applicationId,metricSource.getValue(),topN};
+ try (ResultSet rs = client.executeQuery(sql, params)) {
+ while (rs.next()) {
+ int instanceId =
rs.getInt(InstanceMetricTable.COLUMN_INSTANCE_ID);
+ int transactionCallsSum =
rs.getInt(InstanceMetricTable.COLUMN_TRANSACTION_CALLS);
+ int transactionErrorCallsSum =
rs.getInt(InstanceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS);
+ int simpleValue = (transactionCallsSum
-transactionErrorCallsSum)/secondBetween;
+ AppServerInfo appServerInfo = new AppServerInfo();
+ appServerInfo.setId(instanceId);
+ appServerInfo.setCallsPerSec(simpleValue);
+ appServerInfos.add(appServerInfo);
+ }
+ } catch (SQLException | H2ClientException e) {
+ logger.error(e.getMessage(), e);
+ }
+ return appServerInfos;
}
+
+
+
@Override public List<Integer> getServerTPSTrend(int instanceId, Step
step, List<DurationPoint> durationPoints) {
H2Client client = getClient();
String tableName = TimePyramidTableNameBuilder.build(step,
InstanceMetricTable.TABLE);
diff --git
a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceMetricH2UIDAO.java
b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceMetricH2UIDAO.java
index 247283b86..8ed2e97a4 100644
---
a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceMetricH2UIDAO.java
+++
b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceMetricH2UIDAO.java
@@ -18,11 +18,6 @@
package org.apache.skywalking.apm.collector.storage.h2.dao.ui;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.client.h2.H2ClientException;
import org.apache.skywalking.apm.collector.core.util.Const;
@@ -30,15 +25,21 @@
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
+import
org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable;
import
org.apache.skywalking.apm.collector.storage.table.service.ServiceMetricTable;
import org.apache.skywalking.apm.collector.storage.ui.common.Node;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric;
+import org.apache.skywalking.apm.collector.storage.ui.service.ServiceNode;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
import
org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.*;
+
/**
* @author peng-yongsheng
*/
@@ -79,9 +80,33 @@ public ServiceMetricH2UIDAO(H2Client client) {
return trends;
}
-
+ /**
+ * @author wen-gang.ji
+ */
@Override public List<Integer> getServiceTPSTrend(int serviceId, Step
step, List<DurationPoint> durationPoints) {
- return null;
+ String tableName = TimePyramidTableNameBuilder.build(step,
ServiceMetricTable.TABLE);
+ H2Client client = getClient();
+ String dynamicSql = "select * from {0} where {1} = ?";
+ String sql = SqlBuilder.buildSql(dynamicSql, tableName,
ServiceMetricTable.COLUMN_ID);
+
+ List<Integer> trends = new LinkedList<>();
+ durationPoints.forEach(durationPoint -> {
+ String id = durationPoint.getPoint() + Const.ID_SPLIT + serviceId
+ Const.ID_SPLIT + MetricSource.Callee.getValue();
+ try (ResultSet rs = client.executeQuery(sql, new String[] {id})) {
+ int index = 0;
+ if (rs.next()) {
+ long calls =
rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_CALLS);
+ long secondBetween =
durationPoints.get(index).getSecondsBetween();
+ trends.add((int)(calls / secondBetween));
+ } else {
+ trends.add(0);
+ }
+ index++;
+ } catch (SQLException | H2ClientException e) {
+ logger.error(e.getMessage(), e);
+ }
+ });
+ return trends;
}
@Override public List<Integer> getServiceSLATrend(int serviceId, Step
step, List<DurationPoint> durationPoints) {
@@ -110,14 +135,73 @@ public ServiceMetricH2UIDAO(H2Client client) {
return trends;
}
-
+ /**
+ * @author wen-gang.ji
+ */
@Override public List<Node> getServicesMetric(Step step, long startTime,
long endTime, MetricSource metricSource,
Collection<Integer> serviceIds) {
- return null;
+ String tableName = TimePyramidTableNameBuilder.build(step,
ServiceMetricTable.TABLE);
+ H2Client client = getClient();
+ String dynamicSql = "select {2},sum({4}) as {4}, sum({5}) as {5}, from
{0} where {1} >= ? and {1} <= ? and {2} in ? and {3} = ? group by {2} limit
100";
+ String sql = SqlBuilder.buildSql(dynamicSql, tableName,
ServiceMetricTable.COLUMN_TIME_BUCKET,ServiceMetricTable.COLUMN_SERVICE_ID,ServiceMetricTable.COLUMN_SOURCE_VALUE,
+
ServiceMetricTable.COLUMN_TRANSACTION_CALLS,ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS);
+
+ Object[] params = new Object[] {startTime, endTime, serviceIds,
metricSource.getValue()};
+ List<Node> nodes = new LinkedList<>();
+ try (ResultSet rs = client.executeQuery(sql, params)) {
+ while (rs.next()) {
+ int serviceId =rs.getInt(ServiceMetricTable.COLUMN_SERVICE_ID);
+ Long callsSum =
rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_CALLS);
+ Long errorCallsSum =
rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS);
+
+ ServiceNode serviceNode = new ServiceNode();
+ serviceNode.setId(serviceId);
+ serviceNode.setCalls(callsSum);
+ serviceNode.setSla((int)(((callsSum - errorCallsSum) /
callsSum) * 10000));
+ nodes.add(serviceNode);
+ }
+ } catch (SQLException | H2ClientException e) {
+ logger.error(e.getMessage(), e);
+ }
+
+ return nodes;
+
}
+ /**
+ * @author wen-gang.ji
+ */
@Override public List<ServiceMetric> getSlowService(int applicationId,
Step step, long startTimeBucket, long endTimeBucket, Integer topN,
MetricSource metricSource) {
- return null;
+ topN = topN * 60;
+ String tableName = TimePyramidTableNameBuilder.build(step,
ServiceMetricTable.TABLE);
+ H2Client client = getClient();
+ String dynamicSql = "select {0},{1},{2} from {3} where {4} >= ? and
{4} <= ? and {5} = ? and {6} = ? order by {7} desc limit ?";
+ String sql = SqlBuilder.buildSql(dynamicSql,
ServiceMetricTable.COLUMN_SERVICE_ID,ServiceMetricTable.COLUMN_TRANSACTION_CALLS,ServiceMetricTable.COLUMN_TRANSACTION_AVERAGE_DURATION
+
,tableName,ServiceMetricTable.COLUMN_TIME_BUCKET,ServiceMetricTable.COLUMN_APPLICATION_ID,ServiceMetricTable.COLUMN_SOURCE_VALUE,ServiceMetricTable.COLUMN_TRANSACTION_AVERAGE_DURATION);
+ Object[] params = new Object[]
{startTimeBucket,endTimeBucket,applicationId,metricSource.getValue(),topN};
+ Set<Integer> serviceIds = new HashSet<>();
+ List<ServiceMetric> serviceMetrics = new LinkedList<>();
+ try (ResultSet rs = client.executeQuery(sql, params)) {
+ while (rs.next()) {
+ int serviceId = rs.getInt(ServiceNameTable.COLUMN_SERVICE_ID);
+ if (!serviceIds.contains(serviceId)){
+ ServiceMetric serviceMetric = new ServiceMetric();
+ serviceMetric.setId(serviceId);
+
serviceMetric.setCalls(rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_CALLS));
+
serviceMetric.setAvgResponseTime(rs.getInt(ServiceMetricTable.COLUMN_TRANSACTION_AVERAGE_DURATION));
+ serviceMetrics.add(serviceMetric);
+
+ serviceIds.add(serviceId);
+ }
+ if (topN == serviceIds.size()) {
+ break;
+ }
+ }
+ } catch (SQLException | H2ClientException e) {
+ logger.error(e.getMessage(), e);
+ }
+ return serviceMetrics;
+
}
}
----------------------------------------------------------------
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