Provide the search server query, but only completed es storage and non tps.

This commit is contained in:
peng-yongsheng 2018-01-27 09:13:48 +08:00
parent 1510f7059d
commit f177ebd909
14 changed files with 231 additions and 61 deletions

View File

@ -3,7 +3,12 @@
"au": "dubbox-consumer",
"rt": 1501858094526,
"oi": {
"any_name": "any_value",
"any_name1": "any_value1"
"osName": "MacOS XX",
"hostName": "pengys",
"processId": "1001",
"ipv4s": [
"10.0.0.3",
"10.0.0.4"
]
}
}

View File

@ -3,7 +3,12 @@
"au": "dubbox-provider",
"rt": 1501858094526,
"oi": {
"any_name": "any_value",
"any_name1": "any_value1"
"osName": "MacOS X",
"hostName": "peng-yongsheng",
"processId": "1000",
"ipv4s": [
"10.0.0.1",
"10.0.0.2"
]
}
}

View File

@ -22,6 +22,7 @@ import java.util.List;
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.table.register.Instance;
import org.apache.skywalking.apm.collector.storage.ui.application.Application;
import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo;
/**
* @author peng-yongsheng
@ -35,5 +36,5 @@ public interface IInstanceUIDAO extends DAO {
Instance getInstance(int instanceId);
List<Instance> getInstances(int applicationId, long timeBucket);
List<AppServerInfo> getInstances(String keyword, long start, long end);
}

View File

@ -27,7 +27,7 @@ public class ApplicationNode extends Node {
private Float sla;
private Long callsPerSec;
private Integer responseTimePerSec;
private Long responseTimePerSec;
private Float apdex;
private Boolean isAlarm;
private Integer numOfServer;
@ -50,11 +50,11 @@ public class ApplicationNode extends Node {
this.callsPerSec = callsPerSec;
}
public Integer getResponseTimePerSec() {
public Long getResponseTimePerSec() {
return responseTimePerSec;
}
public void setResponseTimePerSec(Integer responseTimePerSec) {
public void setResponseTimePerSec(Long responseTimePerSec) {
this.responseTimePerSec = responseTimePerSec;
}

View File

@ -28,10 +28,10 @@ public class Call {
private String targetName;
private boolean isAlert;
private String callType;
private int calls;
private int callsPerSec;
private long calls;
private long callsPerSec;
private long responseTimes;
private int responseTimePerSec;
private long responseTimePerSec;
public int getSource() {
return source;
@ -81,19 +81,19 @@ public class Call {
this.callType = callType;
}
public int getCalls() {
public long getCalls() {
return calls;
}
public void setCalls(int calls) {
public void setCalls(long calls) {
this.calls = calls;
}
public int getCallsPerSec() {
public long getCallsPerSec() {
return callsPerSec;
}
public void setCallsPerSec(int callsPerSec) {
public void setCallsPerSec(long callsPerSec) {
this.callsPerSec = callsPerSec;
}
@ -105,11 +105,11 @@ public class Call {
this.responseTimes = responseTimes;
}
public int getResponseTimePerSec() {
public long getResponseTimePerSec() {
return responseTimePerSec;
}
public void setResponseTimePerSec(int responseTimePerSec) {
public void setResponseTimePerSec(long responseTimePerSec) {
this.responseTimePerSec = responseTimePerSec;
}
}

View File

@ -18,16 +18,73 @@
package org.apache.skywalking.apm.collector.storage.ui.server;
import java.util.List;
/**
* @author peng-yongsheng
*/
public class AppServerInfo {
private int id;
private String osInfo;
private String name;
private int tps;
private String os;
private String host;
private int pid;
private String ipv4;
private String ipv6;
private List<String> ipv4;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getOsInfo() {
return osInfo;
}
public void setOsInfo(String osInfo) {
this.osInfo = osInfo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getTps() {
return tps;
}
public void setTps(int tps) {
this.tps = tps;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public int getPid() {
return pid;
}
public void setPid(int pid) {
this.pid = pid;
}
public List<String> getIpv4() {
return ipv4;
}
public void setIpv4(List<String> ipv4) {
this.ipv4 = ipv4;
}
}

View File

@ -21,12 +21,15 @@ package org.apache.skywalking.apm.collector.storage.es.dao;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.apm.collector.core.util.BooleanUtils;
import org.apache.skywalking.apm.collector.core.util.StringUtils;
import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO;
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.apache.skywalking.apm.collector.storage.table.register.Instance;
import org.apache.skywalking.apm.collector.storage.table.register.InstanceTable;
import org.apache.skywalking.apm.collector.storage.ui.application.Application;
import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo;
import org.elasticsearch.action.get.GetRequestBuilder;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
@ -146,30 +149,31 @@ public class InstanceEsUIDAO extends EsDAO implements IInstanceUIDAO {
return null;
}
@Override public List<Instance> getInstances(int applicationId, long timeBucket) {
logger.debug("get instances info, application id: {}, timeBucket: {}", applicationId, timeBucket);
@Override public List<AppServerInfo> getInstances(String keyword, long start, long end) {
logger.debug("get instances info, keyword: {}, start: {}, end: {}", keyword, start, end);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE);
searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setSize(1000);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(timeBucket));
boolQuery.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId));
boolQuery.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(start).lte(end));
if (StringUtils.isNotEmpty(keyword)) {
boolQuery.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_OS_INFO, keyword));
}
boolQuery.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_IS_ADDRESS, BooleanUtils.FALSE));
searchRequestBuilder.setQuery(boolQuery);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
SearchHit[] searchHits = searchResponse.getHits().getHits();
List<Instance> instanceList = new LinkedList<>();
List<AppServerInfo> appServerInfos = new LinkedList<>();
for (SearchHit searchHit : searchHits) {
Instance instance = new Instance();
instance.setId(searchHit.getId());
instance.setApplicationId(((Number)searchHit.getSource().get(InstanceTable.COLUMN_APPLICATION_ID)).intValue());
instance.setHeartBeatTime(((Number)searchHit.getSource().get(InstanceTable.COLUMN_HEARTBEAT_TIME)).longValue());
instance.setInstanceId(((Number)searchHit.getSource().get(InstanceTable.COLUMN_INSTANCE_ID)).intValue());
instanceList.add(instance);
AppServerInfo appServerInfo = new AppServerInfo();
appServerInfo.setId(((Number)searchHit.getSource().get(InstanceTable.COLUMN_INSTANCE_ID)).intValue());
appServerInfo.setOsInfo((String)searchHit.getSource().get(InstanceTable.COLUMN_OS_INFO));
appServerInfos.add(appServerInfo);
}
return instanceList;
return appServerInfos;
}
}

View File

@ -24,6 +24,7 @@ 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;
import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO;
@ -31,6 +32,7 @@ import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.apache.skywalking.apm.collector.storage.table.register.Instance;
import org.apache.skywalking.apm.collector.storage.table.register.InstanceTable;
import org.apache.skywalking.apm.collector.storage.ui.application.Application;
import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -48,7 +50,7 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO {
private static final String GET_LAST_HEARTBEAT_TIME_SQL = "select {0} from {1} where {2} > ? limit 1";
private static final String GET_INST_LAST_HEARTBEAT_TIME_SQL = "select {0} from {1} where {2} > ? and {3} = ? limit 1";
private static final String GET_INSTANCE_SQL = "select * from {0} where {1} = ?";
private static final String GET_INSTANCES_SQL = "select * from {0} where {1} = ? and {2} >= ?";
private static final String GET_INSTANCES_SQL = "select * from {0} where {1} like ? and {2} >= ? and {2} <= ? and {3} = ?";
private static final String GET_APPLICATIONS_SQL = "select {3}, count({0}) as cnt from {1} where {2} >= ? group by {3} limit 100";
@Override
@ -130,25 +132,22 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO {
return null;
}
@Override
public List<Instance> getInstances(int applicationId, long timeBucket) {
logger.debug("get instances info, application id: {}, timeBucket: {}", applicationId, timeBucket);
List<Instance> instanceList = new LinkedList<>();
@Override public List<AppServerInfo> getInstances(String keyword, long start, long end) {
logger.debug("get instances info, keyword: {}, start: {}, end: {}", keyword, start, end);
List<AppServerInfo> appServerInfos = new LinkedList<>();
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_INSTANCES_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.COLUMN_HEARTBEAT_TIME);
Object[] params = new Object[] {applicationId, timeBucket};
String sql = SqlBuilder.buildSql(GET_INSTANCES_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_OS_INFO, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_IS_ADDRESS);
Object[] params = new Object[] {keyword, start, end, BooleanUtils.FALSE};
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
Instance instance = new Instance();
instance.setId(rs.getString(InstanceTable.COLUMN_ID));
instance.setApplicationId(rs.getInt(InstanceTable.COLUMN_APPLICATION_ID));
instance.setHeartBeatTime(rs.getLong(InstanceTable.COLUMN_HEARTBEAT_TIME));
instance.setInstanceId(rs.getInt(InstanceTable.COLUMN_INSTANCE_ID));
instanceList.add(instance);
AppServerInfo appServerInfo = new AppServerInfo();
appServerInfo.setId(rs.getInt(InstanceTable.COLUMN_INSTANCE_ID));
appServerInfo.setOsInfo(rs.getString(InstanceTable.COLUMN_OS_INFO));
appServerInfos.add(appServerInfo);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return instanceList;
return appServerInfos;
}
}

View File

@ -60,7 +60,6 @@ public class GraphQLHandler extends JettyHandler {
private final Logger logger = LoggerFactory.getLogger(GraphQLHandler.class);
private final ModuleManager moduleManager;
private final Gson gson = new Gson();
private final GraphQL graphQL;
private static final String QUERY = "query";
@ -69,8 +68,6 @@ public class GraphQLHandler extends JettyHandler {
private static final String MESSAGE = "message";
public GraphQLHandler(ModuleManager moduleManager) {
this.moduleManager = moduleManager;
GraphQLSchema schema = SchemaParser.newParser()
.file("ui-graphql/alarm.graphqls")
.file("ui-graphql/application-layer.graphqls")
@ -81,7 +78,7 @@ public class GraphQLHandler extends JettyHandler {
.file("ui-graphql/service-layer.graphqls")
.file("ui-graphql/trace.graphqls")
.resolvers(new VersionQuery(), new VersionMutation(), new AlarmQuery(), new ApplicationQuery(moduleManager))
.resolvers(new OverViewLayerQuery(moduleManager), new ServerQuery(), new ServiceQuery(), new TraceQuery())
.resolvers(new OverViewLayerQuery(moduleManager), new ServerQuery(moduleManager), new ServiceQuery(), new TraceQuery())
.resolvers(new ConfigQuery(), new ConfigMutation())
.dictionary(ConjecturalNode.class, VisualUserNode.class, ApplicationNode.class)
.build()

View File

@ -18,8 +18,10 @@
package org.apache.skywalking.apm.collector.ui.query;
import java.text.ParseException;
import java.util.List;
import org.apache.skywalking.apm.collector.ui.graphql.Query;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.core.util.ObjectUtils;
import org.apache.skywalking.apm.collector.storage.ui.common.Duration;
import org.apache.skywalking.apm.collector.storage.ui.common.ResponseTimeTrend;
import org.apache.skywalking.apm.collector.storage.ui.common.ThroughputTrend;
@ -27,13 +29,33 @@ import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo;
import org.apache.skywalking.apm.collector.storage.ui.server.CPUTrend;
import org.apache.skywalking.apm.collector.storage.ui.server.GCTrend;
import org.apache.skywalking.apm.collector.storage.ui.server.MemoryTrend;
import org.apache.skywalking.apm.collector.ui.graphql.Query;
import org.apache.skywalking.apm.collector.ui.service.ServerService;
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
/**
* @author peng-yongsheng
*/
public class ServerQuery implements Query {
public List<AppServerInfo> searchServer(String keyword, Duration duration) {
return null;
private final ModuleManager moduleManager;
private ServerService serverService;
public ServerQuery(ModuleManager moduleManager) {
this.moduleManager = moduleManager;
}
private ServerService getServerService() {
if (ObjectUtils.isEmpty(serverService)) {
this.serverService = new ServerService(moduleManager);
}
return serverService;
}
public List<AppServerInfo> searchServer(String keyword, Duration duration) throws ParseException {
long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart());
long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd());
return getServerService().searchServer(keyword, start, end);
}
public List<AppServerInfo> getAllServer(String applicationId, Duration duration) {

View File

@ -119,10 +119,10 @@ public class ApplicationTopologyService {
Topology topology = builder.build(applicationComponents, applicationMappings, callerCalls, calleeCalls, secondsBetween);
topology.getCalls().forEach(call -> {
int calls = call.getCalls();
long calls = call.getCalls();
long responseTimes = call.getResponseTimes();
call.setCallsPerSec((int)(calls / secondsBetween));
call.setResponseTimePerSec((int)(responseTimes / secondsBetween));
call.setCallsPerSec(calls / secondsBetween);
call.setResponseTimePerSec(responseTimes / secondsBetween);
});
return topology;
}

View File

@ -0,0 +1,80 @@
/*
* 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.skywalking.apm.collector.ui.service;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.core.util.StringUtils;
import org.apache.skywalking.apm.collector.storage.StorageModule;
import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO;
import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo;
/**
* @author peng-yongsheng
*/
public class ServerService {
private final Gson gson = new Gson();
private final IInstanceUIDAO instanceDAO;
public ServerService(ModuleManager moduleManager) {
this.instanceDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceUIDAO.class);
}
public List<AppServerInfo> searchServer(String keyword, long start, long end) {
List<AppServerInfo> serverInfos = instanceDAO.getInstances(keyword, start, end);
serverInfos.forEach(serverInfo -> {
if (serverInfo.getId() == Const.NONE_INSTANCE_ID) {
serverInfos.remove(serverInfo);
}
});
serverInfos.forEach(serverInfo -> {
if (StringUtils.isNotEmpty(serverInfo.getOsInfo())) {
JsonObject osInfoJson = gson.fromJson(serverInfo.getOsInfo(), JsonObject.class);
if (osInfoJson.has("osName")) {
serverInfo.setName(osInfoJson.get("osName").getAsString());
}
if (osInfoJson.has("hostName")) {
serverInfo.setHost(osInfoJson.get("hostName").getAsString());
}
if (osInfoJson.has("processId")) {
serverInfo.setPid(osInfoJson.get("processId").getAsInt());
}
if (osInfoJson.has("ipv4s")) {
JsonArray ipv4Array = osInfoJson.get("ipv4s").getAsJsonArray();
List<String> ipv4s = new LinkedList<>();
ipv4Array.forEach(ipv4 -> {
ipv4s.add(ipv4.getAsString());
});
serverInfo.setIpv4(ipv4s);
}
}
});
return serverInfos;
}
}

View File

@ -95,10 +95,12 @@ class TopologyBuilder {
calleeCalls.forEach(call -> {
if (call.getTarget() == nodeId) {
call.setCallsPerSec((int)(call.getCalls() / secondsBetween));
call.setResponseTimePerSec((int)(call.getResponseTimes() / secondsBetween));
call.setCallsPerSec(call.getCalls() / secondsBetween);
call.setResponseTimePerSec(call.getResponseTimes() / secondsBetween);
}
});
applicationNode.setCallsPerSec(100L);
applicationNode.setResponseTimePerSec(100L);
nodes.add(applicationNode);
}
}

View File

@ -7,11 +7,9 @@ type AppServerInfo {
id: ID!
name: String!
tps: Int!
os: String
host: String
pid: Int
ipv4: String
ipv6: String
ipv4: [String!]!
}
type CPUTrend {