提交 24a03753 编写于 作者: P peng-yongsheng

Add the implement of UI module.

上级 0664a619
......@@ -23,7 +23,7 @@ package org.skywalking.apm.collector.core.data;
*/
public class CommonTable {
public static final String TABLE_TYPE = "type";
public static final String COLUMN_ID = "getId";
public static final String COLUMN_ID = "id";
public static final String COLUMN_AGG = "agg";
public static final String COLUMN_TIME_BUCKET = "time_bucket";
}
......@@ -19,9 +19,9 @@
package org.skywalking.apm.collector.remote;
import org.skywalking.apm.collector.core.module.Module;
import org.skywalking.apm.collector.remote.service.RemoteClientService;
import org.skywalking.apm.collector.remote.service.RemoteServerService;
import org.skywalking.apm.collector.remote.service.RemoteSenderService;
import org.skywalking.apm.collector.remote.service.RemoteSerializeService;
import org.skywalking.apm.collector.remote.service.RemoteServerService;
/**
* @author peng-yongsheng
......@@ -35,6 +35,6 @@ public class RemoteModule extends Module {
}
@Override public Class[] services() {
return new Class[] {RemoteServerService.class, RemoteClientService.class, RemoteSerializeService.class};
return new Class[] {RemoteServerService.class, RemoteSerializeService.class, RemoteSenderService.class};
}
}
......@@ -18,11 +18,9 @@
package org.skywalking.apm.collector.remote.service;
import org.skywalking.apm.collector.core.module.Service;
/**
* @author peng-yongsheng
*/
public interface RemoteClientService extends Service {
public interface RemoteClientService {
RemoteClient create(String host, int port);
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.remote.service;
import org.skywalking.apm.collector.core.data.Data;
import org.skywalking.apm.collector.core.module.Service;
/**
* @author peng-yongsheng
*/
public interface RemoteSenderService extends Service {
void send(int graph, int nodeId, Data data);
}
......@@ -19,11 +19,10 @@
package org.skywalking.apm.collector.remote.service;
import org.skywalking.apm.collector.core.data.Data;
import org.skywalking.apm.collector.core.module.Service;
/**
* @author peng-yongsheng
*/
public interface RemoteSerializeService<Builder> extends Service {
public interface RemoteSerializeService<Builder> {
Builder serialize(Data data);
}
......@@ -12,13 +12,10 @@ import org.skywalking.apm.collector.grpc.manager.GRPCManagerModule;
import org.skywalking.apm.collector.grpc.manager.service.GRPCManagerService;
import org.skywalking.apm.collector.remote.RemoteModule;
import org.skywalking.apm.collector.remote.grpc.handler.RemoteCommonServiceHandler;
import org.skywalking.apm.collector.remote.grpc.service.GRPCRemoteClientService;
import org.skywalking.apm.collector.remote.grpc.service.GRPCRemoteListener;
import org.skywalking.apm.collector.remote.grpc.service.GRPCRemoteSerializeService;
import org.skywalking.apm.collector.remote.grpc.service.GRPCRemoteSenderService;
import org.skywalking.apm.collector.remote.grpc.service.GRPCRemoteServerService;
import org.skywalking.apm.collector.remote.service.DataReceiverRegisterListener;
import org.skywalking.apm.collector.remote.service.RemoteClientService;
import org.skywalking.apm.collector.remote.service.RemoteSerializeService;
import org.skywalking.apm.collector.remote.service.RemoteSenderService;
import org.skywalking.apm.collector.remote.service.RemoteServerService;
import org.skywalking.apm.collector.server.Server;
......@@ -31,6 +28,7 @@ public class RemoteModuleGRPCProvider extends ModuleProvider {
private static final String HOST = "host";
private static final String PORT = "port";
private final DataReceiverRegisterListener listener = new DataReceiverRegisterListener();
private GRPCRemoteSenderService remoteSenderService;
@Override public String name() {
return NAME;
......@@ -41,9 +39,9 @@ public class RemoteModuleGRPCProvider extends ModuleProvider {
}
@Override public void prepare(Properties config) throws ServiceNotProvidedException {
remoteSenderService = new GRPCRemoteSenderService();
this.registerServiceImplementation(RemoteServerService.class, new GRPCRemoteServerService(listener));
this.registerServiceImplementation(RemoteClientService.class, new GRPCRemoteClientService());
this.registerServiceImplementation(RemoteSerializeService.class, new GRPCRemoteSerializeService());
this.registerServiceImplementation(RemoteSenderService.class, remoteSenderService);
}
@Override public void start(Properties config) throws ServiceNotProvidedException {
......@@ -59,7 +57,7 @@ public class RemoteModuleGRPCProvider extends ModuleProvider {
moduleRegisterService.register(RemoteModule.NAME, this.name(), new RemoteModuleGRPCRegistration(host, port));
ModuleListenerService moduleListenerService = getManager().find(ClusterModule.NAME).getService(ModuleListenerService.class);
moduleListenerService.addListener(new GRPCRemoteListener());
moduleListenerService.addListener(remoteSenderService);
} catch (ModuleNotFoundException e) {
throw new ServiceNotProvidedException(e.getMessage());
}
......
......@@ -21,20 +21,26 @@ package org.skywalking.apm.collector.remote.grpc.service;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.skywalking.apm.collector.cluster.ClusterModuleListener;
import org.skywalking.apm.collector.core.data.Data;
import org.skywalking.apm.collector.remote.RemoteModule;
import org.skywalking.apm.collector.remote.grpc.RemoteModuleGRPCProvider;
import org.skywalking.apm.collector.remote.service.RemoteClient;
import org.skywalking.apm.collector.remote.service.RemoteSenderService;
/**
* @author peng-yongsheng
*/
public class GRPCRemoteListener extends ClusterModuleListener {
public class GRPCRemoteSenderService extends ClusterModuleListener implements RemoteSenderService {
public static final String PATH = "/" + RemoteModule.NAME + "/" + RemoteModuleGRPCProvider.NAME;
private final GRPCRemoteClientService service;
private final Map<String, RemoteClient> clientMap;
public GRPCRemoteListener() {
@Override public void send(int graph, int nodeId, Data data) {
}
public GRPCRemoteSenderService() {
this.service = new GRPCRemoteClientService();
this.clientMap = new ConcurrentHashMap<>();
}
......
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.base.dao;
import org.skywalking.apm.collector.client.Client;
/**
* @author peng-yongsheng
*/
public abstract class AbstractDAO<C extends Client> implements DAO {
private C client;
public final C getClient() {
return client;
}
public final void setClient(C client) {
this.client = client;
}
}
......@@ -18,19 +18,8 @@
package org.skywalking.apm.collector.storage.base.dao;
import org.skywalking.apm.collector.client.Client;
/**
* @author peng-yongsheng
*/
public abstract class DAO<C extends Client> {
private C client;
public final C getClient() {
return client;
}
public final void setClient(C client) {
this.client = client;
}
public interface DAO {
}
......@@ -25,13 +25,13 @@ import java.util.Map;
* @author peng-yongsheng
*/
public class DAOContainer {
private Map<String, DAO> daos = new HashMap<>();
private Map<String, AbstractDAO> daos = new HashMap<>();
public void put(String interfaceName, DAO dao) {
daos.put(interfaceName, dao);
public void put(String interfaceName, AbstractDAO abstractDao) {
daos.put(interfaceName, abstractDao);
}
public DAO get(String interfaceName) {
public AbstractDAO get(String interfaceName) {
return daos.get(interfaceName);
}
}
......@@ -18,10 +18,12 @@
package org.skywalking.apm.collector.storage.dao;
import org.skywalking.apm.collector.storage.base.dao.DAO;
/**
* @author peng-yongsheng
*/
public interface IApplicationCacheDAO {
public interface IApplicationCacheDAO extends DAO {
int getApplicationId(String applicationCode);
String getApplicationCode(int applicationId);
......
......@@ -23,7 +23,7 @@ import org.skywalking.apm.collector.storage.table.register.Application;
/**
* @author peng-yongsheng
*/
public interface IApplicationDAO {
public interface IApplicationStreamDAO {
int getMaxApplicationId();
int getMinApplicationId();
......
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.dao;
import com.google.gson.JsonArray;
import org.skywalking.apm.collector.storage.base.dao.DAO;
/**
* @author peng-yongsheng
*/
public interface ICpuMetricUIDAO extends DAO {
int getMetric(int instanceId, long timeBucket);
JsonArray getMetric(int instanceId, long startTimeBucket, long endTimeBucket);
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.dao;
import com.google.gson.JsonObject;
import org.skywalking.apm.collector.storage.base.dao.DAO;
/**
* @author peng-yongsheng
*/
public interface IGCMetricUIDAO extends DAO {
GCCount getGCCount(long[] timeBuckets, int instanceId);
JsonObject getMetric(int instanceId, long timeBucket);
JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket);
class GCCount {
private int young;
private int old;
private int full;
public int getYoung() {
return young;
}
public int getOld() {
return old;
}
public int getFull() {
return full;
}
public void setYoung(int young) {
this.young = young;
}
public void setOld(int old) {
this.old = old;
}
public void setFull(int full) {
this.full = full;
}
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.dao;
import java.util.List;
import org.skywalking.apm.collector.storage.base.dao.DAO;
/**
* @author peng-yongsheng
*/
public interface IGlobalTraceUIDAO extends DAO {
List<String> getGlobalTraceId(String segmentId);
List<String> getSegmentIds(String globalTraceId);
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.dao;
import com.google.gson.JsonArray;
import org.skywalking.apm.collector.storage.base.dao.DAO;
/**
* @author peng-yongsheng
*/
public interface IInstPerformanceUIDAO extends DAO {
InstPerformance get(long[] timeBuckets, int instanceId);
int getTpsMetric(int instanceId, long timeBucket);
JsonArray getTpsMetric(int instanceId, long startTimeBucket, long endTimeBucket);
int getRespTimeMetric(int instanceId, long timeBucket);
JsonArray getRespTimeMetric(int instanceId, long startTimeBucket, long endTimeBucket);
class InstPerformance {
private final int instanceId;
private final int calls;
private final long costTotal;
public InstPerformance(int instanceId, int calls, long costTotal) {
this.instanceId = instanceId;
this.calls = calls;
this.costTotal = costTotal;
}
public int getInstanceId() {
return instanceId;
}
public int getCalls() {
return calls;
}
public long getCostTotal() {
return costTotal;
}
}
}
......@@ -23,7 +23,7 @@ import org.skywalking.apm.collector.storage.table.register.Instance;
/**
* @author peng-yongsheng
*/
public interface IInstanceDAO {
public interface IInstanceStreamDAO {
int getInstanceId(int applicationId, String agentUUID);
int getMaxInstanceId();
......
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.dao;
import com.google.gson.JsonArray;
import java.util.List;
import org.skywalking.apm.collector.storage.base.dao.DAO;
import org.skywalking.apm.collector.storage.table.register.Instance;
/**
* @author peng-yongsheng
*/
public interface IInstanceUIDAO extends DAO {
Long lastHeartBeatTime();
Long instanceLastHeartBeatTime(long applicationInstanceId);
JsonArray getApplications(long startTime, long endTime);
Instance getInstance(int instanceId);
List<Instance> getInstances(int applicationId, long timeBucket);
class Application {
private final int applicationId;
private final long count;
public Application(int applicationId, long count) {
this.applicationId = applicationId;
this.count = count;
}
public int getApplicationId() {
return applicationId;
}
public long getCount() {
return count;
}
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.dao;
import com.google.gson.JsonObject;
import org.skywalking.apm.collector.storage.base.dao.DAO;
/**
* @author peng-yongsheng
*/
public interface IMemoryMetricUIDAO extends DAO {
JsonObject getMetric(int instanceId, long timeBucket, boolean isHeap);
JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, boolean isHeap);
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.dao;
import com.google.gson.JsonObject;
import org.skywalking.apm.collector.storage.base.dao.DAO;
/**
* @author peng-yongsheng
*/
public interface IMemoryPoolMetricUIDAO extends DAO {
JsonObject getMetric(int instanceId, long timeBucket, int poolType);
JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, int poolType);
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.dao;
import com.google.gson.JsonArray;
import org.skywalking.apm.collector.storage.base.dao.DAO;
/**
* @author peng-yongsheng
*/
public interface INodeComponentUIDAO extends DAO {
JsonArray load(long startTime, long endTime);
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.dao;
import com.google.gson.JsonArray;
import org.skywalking.apm.collector.storage.base.dao.DAO;
/**
* @author peng-yongsheng
*/
public interface INodeMappingUIDAO extends DAO {
JsonArray load(long startTime, long endTime);
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.dao;
import com.google.gson.JsonArray;
import org.skywalking.apm.collector.storage.base.dao.DAO;
/**
* @author peng-yongsheng
*/
public interface INodeReferenceUIDAO extends DAO {
JsonArray load(long startTime, long endTime);
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.dao;
import com.google.gson.JsonObject;
import java.util.List;
import org.skywalking.apm.collector.storage.base.dao.DAO;
/**
* @author peng-yongsheng
*/
public interface ISegmentCostUIDAO extends DAO {
JsonObject loadTop(long startTime, long endTime, long minCost, long maxCost, String operationName,
Error error, int applicationId, List<String> segmentIds, int limit, int from, Sort sort);
enum Sort {
Cost, Time
}
enum Error {
All, True, False
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.dao;
import org.skywalking.apm.collector.storage.base.dao.DAO;
import org.skywalking.apm.network.proto.TraceSegmentObject;
/**
* @author peng-yongsheng
*/
public interface ISegmentUIDAO extends DAO {
TraceSegmentObject load(String segmentId);
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.dao;
import com.google.gson.JsonObject;
import org.skywalking.apm.collector.storage.base.dao.DAO;
/**
* @author peng-yongsheng
*/
public interface IServiceEntryUIDAO extends DAO {
JsonObject load(int applicationId, String entryServiceName, long startTime, long endTime, int from, int size);
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.dao;
import com.google.gson.JsonObject;
import java.util.Map;
import org.skywalking.apm.collector.storage.base.dao.DAO;
/**
* @author peng-yongsheng
*/
public interface IServiceReferenceUIDAO extends DAO {
Map<String, JsonObject> load(int entryServiceId, long startTime, long endTime);
}
......@@ -25,5 +25,5 @@ import org.skywalking.apm.collector.storage.base.dao.DAO;
* @author peng-yongsheng
*/
public interface DAOService extends Service {
DAO get(Class<DAO> daoInterfaceClass);
DAO get(Class<? extends DAO> daoInterfaceClass);
}
......@@ -26,12 +26,12 @@ import org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.min.Min;
import org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder;
import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.skywalking.apm.collector.storage.base.dao.DAO;
import org.skywalking.apm.collector.storage.base.dao.AbstractDAO;
/**
* @author peng-yongsheng
*/
public abstract class EsDAO extends DAO<ElasticSearchClient> {
public abstract class EsDAO extends AbstractDAO<ElasticSearchClient> {
public final int getMaxId(String indexName, String columnName) {
ElasticSearchClient client = getClient();
......
......@@ -23,7 +23,7 @@ import java.util.Map;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.support.WriteRequest;
import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.skywalking.apm.collector.storage.dao.IApplicationDAO;
import org.skywalking.apm.collector.storage.dao.IApplicationStreamDAO;
import org.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.skywalking.apm.collector.storage.table.register.Application;
import org.skywalking.apm.collector.storage.table.register.ApplicationTable;
......@@ -33,9 +33,9 @@ import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class ApplicationEsDAO extends EsDAO implements IApplicationDAO {
public class ApplicationEsStreamDAO extends EsDAO implements IApplicationStreamDAO {
private final Logger logger = LoggerFactory.getLogger(ApplicationEsDAO.class);
private final Logger logger = LoggerFactory.getLogger(ApplicationEsStreamDAO.class);
@Override public int getMaxApplicationId() {
return getMaxId(ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID);
......
......@@ -23,7 +23,7 @@ import java.util.Map;
import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.update.UpdateRequestBuilder;
import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO;
import org.skywalking.apm.collector.storage.dao.ICpuMetricDAO;
import org.skywalking.apm.collector.storage.dao.ICpuMetricStreamDAO;
import org.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.skywalking.apm.collector.storage.table.jvm.CpuMetric;
import org.skywalking.apm.collector.storage.table.jvm.CpuMetricTable;
......@@ -33,9 +33,9 @@ import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class CpuMetricEsDAO extends EsDAO implements ICpuMetricDAO, IPersistenceDAO<IndexRequestBuilder, UpdateRequestBuilder, CpuMetric> {
public class CpuMetricEsStreamDAO extends EsDAO implements ICpuMetricStreamDAO, IPersistenceDAO<IndexRequestBuilder, UpdateRequestBuilder, CpuMetric> {
private final Logger logger = LoggerFactory.getLogger(CpuMetricEsDAO.class);
private final Logger logger = LoggerFactory.getLogger(CpuMetricEsStreamDAO.class);
@Override public CpuMetric get(String id) {
return null;
......
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.es.dao;
import com.google.gson.JsonArray;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.get.MultiGetItemResponse;
import org.elasticsearch.action.get.MultiGetRequestBuilder;
import org.elasticsearch.action.get.MultiGetResponse;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO;
import org.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.skywalking.apm.collector.storage.table.jvm.CpuMetricTable;
/**
* @author peng-yongsheng
*/
public class CpuMetricEsUIDAO extends EsDAO implements ICpuMetricUIDAO {
@Override public int getMetric(int instanceId, long timeBucket) {
String id = timeBucket + Const.ID_SPLIT + instanceId;
GetResponse getResponse = getClient().prepareGet(CpuMetricTable.TABLE, id).get();
if (getResponse.isExists()) {
return ((Number)getResponse.getSource().get(CpuMetricTable.COLUMN_USAGE_PERCENT)).intValue();
}
return 0;
}
@Override public JsonArray getMetric(int instanceId, long startTimeBucket, long endTimeBucket) {
MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet();
long timeBucket = startTimeBucket;
do {
timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1);
String id = timeBucket + Const.ID_SPLIT + instanceId;
prepareMultiGet.add(CpuMetricTable.TABLE, CpuMetricTable.TABLE_TYPE, id);
}
while (timeBucket <= endTimeBucket);
JsonArray metrics = new JsonArray();
MultiGetResponse multiGetResponse = prepareMultiGet.get();
for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
if (response.getResponse().isExists()) {
double cpuUsed = ((Number)response.getResponse().getSource().get(CpuMetricTable.COLUMN_USAGE_PERCENT)).doubleValue();
metrics.add((int)(cpuUsed * 100));
} else {
metrics.add(0);
}
}
return metrics;
}
}
......@@ -23,7 +23,7 @@ import java.util.Map;
import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.update.UpdateRequestBuilder;
import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO;
import org.skywalking.apm.collector.storage.dao.IGCMetricDAO;
import org.skywalking.apm.collector.storage.dao.IGCMetricStreamDAO;
import org.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.skywalking.apm.collector.storage.table.jvm.GCMetric;
import org.skywalking.apm.collector.storage.table.jvm.GCMetricTable;
......@@ -31,7 +31,7 @@ import org.skywalking.apm.collector.storage.table.jvm.GCMetricTable;
/**
* @author peng-yongsheng
*/
public class GCMetricEsDAO extends EsDAO implements IGCMetricDAO, IPersistenceDAO<IndexRequestBuilder, UpdateRequestBuilder, GCMetric> {
public class GCMetricEsStreamDAO extends EsDAO implements IGCMetricStreamDAO, IPersistenceDAO<IndexRequestBuilder, UpdateRequestBuilder, GCMetric> {
@Override public GCMetric get(String id) {
return null;
......
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.es.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.get.MultiGetItemResponse;
import org.elasticsearch.action.get.MultiGetRequestBuilder;
import org.elasticsearch.action.get.MultiGetResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.dao.IGCMetricUIDAO;
import org.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.skywalking.apm.collector.storage.table.jvm.GCMetricTable;
import org.skywalking.apm.network.proto.GCPhrase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class GCMetricEsUIDAO extends EsDAO implements IGCMetricUIDAO {
private final Logger logger = LoggerFactory.getLogger(GCMetricEsUIDAO.class);
@Override public GCCount getGCCount(long[] timeBuckets, int instanceId) {
logger.debug("get gc count, timeBuckets: {}, instanceId: {}", timeBuckets, instanceId);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(GCMetricTable.TABLE);
searchRequestBuilder.setTypes(GCMetricTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must().add(QueryBuilders.termQuery(GCMetricTable.COLUMN_INSTANCE_ID, instanceId));
boolQuery.must().add(QueryBuilders.termsQuery(GCMetricTable.COLUMN_TIME_BUCKET, timeBuckets));
searchRequestBuilder.setQuery(boolQuery);
searchRequestBuilder.setSize(0);
searchRequestBuilder.addAggregation(
AggregationBuilders.terms(GCMetricTable.COLUMN_PHRASE).field(GCMetricTable.COLUMN_PHRASE)
.subAggregation(AggregationBuilders.sum(GCMetricTable.COLUMN_COUNT).field(GCMetricTable.COLUMN_COUNT)));
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
GCCount gcCount = new GCCount();
Terms phraseAggregation = searchResponse.getAggregations().get(GCMetricTable.COLUMN_PHRASE);
for (Terms.Bucket phraseBucket : phraseAggregation.getBuckets()) {
int phrase = phraseBucket.getKeyAsNumber().intValue();
Sum sumAggregation = phraseBucket.getAggregations().get(GCMetricTable.COLUMN_COUNT);
int count = (int)sumAggregation.getValue();
if (phrase == GCPhrase.NEW_VALUE) {
gcCount.setYoung(count);
} else if (phrase == GCPhrase.OLD_VALUE) {
gcCount.setOld(count);
}
}
return gcCount;
}
@Override public JsonObject getMetric(int instanceId, long timeBucket) {
JsonObject response = new JsonObject();
String youngId = timeBucket + Const.ID_SPLIT + GCPhrase.NEW_VALUE + instanceId;
GetResponse youngResponse = getClient().prepareGet(GCMetricTable.TABLE, youngId).get();
if (youngResponse.isExists()) {
response.addProperty("ygc", ((Number)youngResponse.getSource().get(GCMetricTable.COLUMN_COUNT)).intValue());
}
String oldId = timeBucket + Const.ID_SPLIT + GCPhrase.OLD_VALUE + instanceId;
GetResponse oldResponse = getClient().prepareGet(GCMetricTable.TABLE, oldId).get();
if (oldResponse.isExists()) {
response.addProperty("ogc", ((Number)oldResponse.getSource().get(GCMetricTable.COLUMN_COUNT)).intValue());
}
return response;
}
@Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket) {
JsonObject response = new JsonObject();
MultiGetRequestBuilder youngPrepareMultiGet = getClient().prepareMultiGet();
long timeBucket = startTimeBucket;
do {
timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1);
String youngId = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + GCPhrase.NEW_VALUE;
youngPrepareMultiGet.add(GCMetricTable.TABLE, GCMetricTable.TABLE_TYPE, youngId);
}
while (timeBucket <= endTimeBucket);
JsonArray youngArray = new JsonArray();
MultiGetResponse multiGetResponse = youngPrepareMultiGet.get();
for (MultiGetItemResponse itemResponse : multiGetResponse.getResponses()) {
if (itemResponse.getResponse().isExists()) {
youngArray.add(((Number)itemResponse.getResponse().getSource().get(GCMetricTable.COLUMN_COUNT)).intValue());
} else {
youngArray.add(0);
}
}
response.add("ygc", youngArray);
MultiGetRequestBuilder oldPrepareMultiGet = getClient().prepareMultiGet();
timeBucket = startTimeBucket;
do {
timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1);
String oldId = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + GCPhrase.OLD_VALUE;
oldPrepareMultiGet.add(GCMetricTable.TABLE, GCMetricTable.TABLE_TYPE, oldId);
}
while (timeBucket <= endTimeBucket);
JsonArray oldArray = new JsonArray();
multiGetResponse = oldPrepareMultiGet.get();
for (MultiGetItemResponse itemResponse : multiGetResponse.getResponses()) {
if (itemResponse.getResponse().isExists()) {
oldArray.add(((Number)itemResponse.getResponse().getSource().get(GCMetricTable.COLUMN_COUNT)).intValue());
} else {
oldArray.add(0);
}
}
response.add("ogc", oldArray);
return response;
}
}
......@@ -24,7 +24,7 @@ import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.update.UpdateRequestBuilder;
import org.skywalking.apm.collector.core.UnexpectedException;
import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO;
import org.skywalking.apm.collector.storage.dao.IGlobalTraceDAO;
import org.skywalking.apm.collector.storage.dao.IGlobalTraceStreamDAO;
import org.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.skywalking.apm.collector.storage.table.global.GlobalTrace;
import org.skywalking.apm.collector.storage.table.global.GlobalTraceTable;
......@@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class GlobalTraceEsDAO extends EsDAO implements IGlobalTraceDAO, IPersistenceDAO<IndexRequestBuilder, UpdateRequestBuilder, GlobalTrace> {
public class GlobalTraceEsDAO extends EsDAO implements IGlobalTraceStreamDAO, IPersistenceDAO<IndexRequestBuilder, UpdateRequestBuilder, GlobalTrace> {
private final Logger logger = LoggerFactory.getLogger(GlobalTraceEsDAO.class);
......
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.es.dao;
import java.util.ArrayList;
import java.util.List;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO;
import org.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.skywalking.apm.collector.storage.table.global.GlobalTraceTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class GlobalTraceEsUIDAO extends EsDAO implements IGlobalTraceUIDAO {
private final Logger logger = LoggerFactory.getLogger(GlobalTraceEsUIDAO.class);
@Override public List<String> getGlobalTraceId(String segmentId) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(GlobalTraceTable.TABLE);
searchRequestBuilder.setTypes(GlobalTraceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setQuery(QueryBuilders.termQuery(GlobalTraceTable.COLUMN_SEGMENT_ID, segmentId));
searchRequestBuilder.setSize(10);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
List<String> globalTraceIds = new ArrayList<>();
SearchHit[] searchHits = searchResponse.getHits().getHits();
for (SearchHit searchHit : searchHits) {
String globalTraceId = (String)searchHit.getSource().get(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID);
logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId);
globalTraceIds.add(globalTraceId);
}
return globalTraceIds;
}
@Override public List<String> getSegmentIds(String globalTraceId) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(GlobalTraceTable.TABLE);
searchRequestBuilder.setTypes(GlobalTraceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setQuery(QueryBuilders.termQuery(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, globalTraceId));
searchRequestBuilder.setSize(10);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
List<String> segmentIds = new ArrayList<>();
SearchHit[] searchHits = searchResponse.getHits().getHits();
for (SearchHit searchHit : searchHits) {
String segmentId = (String)searchHit.getSource().get(GlobalTraceTable.COLUMN_SEGMENT_ID);
logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId);
segmentIds.add(segmentId);
}
return segmentIds;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.es.dao;
import com.google.gson.JsonArray;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.get.MultiGetItemResponse;
import org.elasticsearch.action.get.MultiGetRequestBuilder;
import org.elasticsearch.action.get.MultiGetResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
import org.elasticsearch.search.sort.SortOrder;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.dao.IInstPerformanceUIDAO;
import org.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.skywalking.apm.collector.storage.table.instance.InstPerformanceTable;
/**
* @author peng-yongsheng
*/
public class InstPerformanceEsUIDAO extends EsDAO implements IInstPerformanceUIDAO {
@Override public InstPerformance get(long[] timeBuckets, int instanceId) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstPerformanceTable.TABLE);
searchRequestBuilder.setTypes(InstPerformanceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must().add(QueryBuilders.termQuery(InstPerformanceTable.COLUMN_INSTANCE_ID, instanceId));
boolQuery.must().add(QueryBuilders.termsQuery(InstPerformanceTable.COLUMN_TIME_BUCKET, timeBuckets));
searchRequestBuilder.setQuery(boolQuery);
searchRequestBuilder.setSize(0);
searchRequestBuilder.addSort(InstPerformanceTable.COLUMN_INSTANCE_ID, SortOrder.ASC);
searchRequestBuilder.addAggregation(AggregationBuilders.sum(InstPerformanceTable.COLUMN_CALLS).field(InstPerformanceTable.COLUMN_CALLS));
searchRequestBuilder.addAggregation(AggregationBuilders.sum(InstPerformanceTable.COLUMN_COST_TOTAL).field(InstPerformanceTable.COLUMN_COST_TOTAL));
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
Sum sumCalls = searchResponse.getAggregations().get(InstPerformanceTable.COLUMN_CALLS);
Sum sumCostTotal = searchResponse.getAggregations().get(InstPerformanceTable.COLUMN_CALLS);
return new InstPerformance(instanceId, (int)sumCalls.getValue(), (long)sumCostTotal.getValue());
}
@Override public int getTpsMetric(int instanceId, long timeBucket) {
String id = timeBucket + Const.ID_SPLIT + instanceId;
GetResponse getResponse = getClient().prepareGet(InstPerformanceTable.TABLE, id).get();
if (getResponse.isExists()) {
return ((Number)getResponse.getSource().get(InstPerformanceTable.COLUMN_CALLS)).intValue();
}
return 0;
}
@Override public JsonArray getTpsMetric(int instanceId, long startTimeBucket, long endTimeBucket) {
MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet();
long timeBucket = startTimeBucket;
do {
String id = timeBucket + Const.ID_SPLIT + instanceId;
prepareMultiGet.add(InstPerformanceTable.TABLE, InstPerformanceTable.TABLE_TYPE, id);
timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1);
}
while (timeBucket <= endTimeBucket);
JsonArray metrics = new JsonArray();
MultiGetResponse multiGetResponse = prepareMultiGet.get();
for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
if (response.getResponse().isExists()) {
metrics.add(((Number)response.getResponse().getSource().get(InstPerformanceTable.COLUMN_CALLS)).intValue());
} else {
metrics.add(0);
}
}
return metrics;
}
@Override public int getRespTimeMetric(int instanceId, long timeBucket) {
String id = timeBucket + Const.ID_SPLIT + instanceId;
GetResponse getResponse = getClient().prepareGet(InstPerformanceTable.TABLE, id).get();
if (getResponse.isExists()) {
int callTimes = ((Number)getResponse.getSource().get(InstPerformanceTable.COLUMN_CALLS)).intValue();
int costTotal = ((Number)getResponse.getSource().get(InstPerformanceTable.COLUMN_COST_TOTAL)).intValue();
return costTotal / callTimes;
}
return 0;
}
@Override public JsonArray getRespTimeMetric(int instanceId, long startTimeBucket, long endTimeBucket) {
MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet();
int i = 0;
long timeBucket;
do {
timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), startTimeBucket, i);
String id = timeBucket + Const.ID_SPLIT + instanceId;
prepareMultiGet.add(InstPerformanceTable.TABLE, InstPerformanceTable.TABLE_TYPE, id);
i++;
}
while (timeBucket <= endTimeBucket);
JsonArray metrics = new JsonArray();
MultiGetResponse multiGetResponse = prepareMultiGet.get();
for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
if (response.getResponse().isExists()) {
int callTimes = ((Number)response.getResponse().getSource().get(InstPerformanceTable.COLUMN_CALLS)).intValue();
int costTotal = ((Number)response.getResponse().getSource().get(InstPerformanceTable.COLUMN_COST_TOTAL)).intValue();
metrics.add(costTotal / callTimes);
} else {
metrics.add(0);
}
}
return metrics;
}
}
......@@ -30,7 +30,7 @@ import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.skywalking.apm.collector.storage.dao.IInstanceDAO;
import org.skywalking.apm.collector.storage.dao.IInstanceStreamDAO;
import org.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.skywalking.apm.collector.storage.table.register.Instance;
import org.skywalking.apm.collector.storage.table.register.InstanceTable;
......@@ -40,9 +40,9 @@ import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class InstanceEsDAO extends EsDAO implements IInstanceDAO {
public class InstanceEsStreamDAO extends EsDAO implements IInstanceStreamDAO {
private final Logger logger = LoggerFactory.getLogger(InstanceEsDAO.class);
private final Logger logger = LoggerFactory.getLogger(InstanceEsStreamDAO.class);
@Override public int getInstanceId(int applicationId, String agentUUID) {
ElasticSearchClient client = getClient();
......
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.es.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.LinkedList;
import java.util.List;
import org.elasticsearch.action.get.GetRequestBuilder;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.AbstractQueryBuilder;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortMode;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.dao.IInstanceUIDAO;
import org.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.skywalking.apm.collector.storage.table.register.Instance;
import org.skywalking.apm.collector.storage.table.register.InstanceTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class InstanceEsUIDAO extends EsDAO implements IInstanceUIDAO {
private final Logger logger = LoggerFactory.getLogger(InstanceEsUIDAO.class);
@Override public Long lastHeartBeatTime() {
long fiveMinuteBefore = System.currentTimeMillis() - 5 * 60 * 1000;
fiveMinuteBefore = TimeBucketUtils.INSTANCE.getSecondTimeBucket(fiveMinuteBefore);
RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gt(fiveMinuteBefore);
return heartBeatTime(rangeQueryBuilder);
}
@Override public Long instanceLastHeartBeatTime(long applicationInstanceId) {
long fiveMinuteBefore = System.currentTimeMillis() - 5 * 60 * 1000;
fiveMinuteBefore = TimeBucketUtils.INSTANCE.getSecondTimeBucket(fiveMinuteBefore);
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
boolQueryBuilder.must(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gt(fiveMinuteBefore));
boolQueryBuilder.must(QueryBuilders.termQuery(InstanceTable.COLUMN_INSTANCE_ID, applicationInstanceId));
return heartBeatTime(boolQueryBuilder);
}
private Long heartBeatTime(AbstractQueryBuilder queryBuilder) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE);
searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setQuery(queryBuilder);
searchRequestBuilder.setSize(1);
searchRequestBuilder.setFetchSource(InstanceTable.COLUMN_HEARTBEAT_TIME, null);
searchRequestBuilder.addSort(SortBuilders.fieldSort(InstanceTable.COLUMN_HEARTBEAT_TIME).sortMode(SortMode.MAX));
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
SearchHit[] searchHits = searchResponse.getHits().getHits();
Long heartBeatTime = 0L;
for (SearchHit searchHit : searchHits) {
heartBeatTime = (Long)searchHit.getSource().get(InstanceTable.COLUMN_HEARTBEAT_TIME);
logger.debug("heartBeatTime: {}", heartBeatTime);
heartBeatTime = heartBeatTime - 5;
}
return heartBeatTime;
}
@Override public JsonArray getApplications(long startTime, long endTime) {
logger.debug("application list get, start time: {}, end time: {}", startTime, endTime);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE);
searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setQuery(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(startTime));
searchRequestBuilder.setSize(0);
searchRequestBuilder.addAggregation(AggregationBuilders.terms(InstanceTable.COLUMN_APPLICATION_ID).field(InstanceTable.COLUMN_APPLICATION_ID).size(100)
.subAggregation(AggregationBuilders.count(InstanceTable.COLUMN_INSTANCE_ID).field(InstanceTable.COLUMN_INSTANCE_ID)));
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
Terms genders = searchResponse.getAggregations().get(InstanceTable.COLUMN_APPLICATION_ID);
JsonArray applications = new JsonArray();
for (Terms.Bucket applicationsBucket : genders.getBuckets()) {
Integer applicationId = applicationsBucket.getKeyAsNumber().intValue();
logger.debug("applicationId: {}", applicationId);
ValueCount instanceCount = applicationsBucket.getAggregations().get(InstanceTable.COLUMN_INSTANCE_ID);
JsonObject application = new JsonObject();
application.addProperty("applicationId", applicationId);
application.addProperty("instanceCount", instanceCount.getValue());
applications.add(application);
}
return applications;
}
@Override public Instance getInstance(int instanceId) {
logger.debug("get instance info, instance id: {}", instanceId);
GetRequestBuilder requestBuilder = getClient().prepareGet(InstanceTable.TABLE, String.valueOf(instanceId));
GetResponse getResponse = requestBuilder.get();
if (getResponse.isExists()) {
Instance instance = new Instance(getResponse.getId());
instance.setApplicationId(((Number)getResponse.getSource().get(InstanceTable.COLUMN_APPLICATION_ID)).intValue());
instance.setAgentUUID((String)getResponse.getSource().get(InstanceTable.COLUMN_AGENT_UUID));
instance.setRegisterTime(((Number)getResponse.getSource().get(InstanceTable.COLUMN_REGISTER_TIME)).longValue());
instance.setHeartBeatTime(((Number)getResponse.getSource().get(InstanceTable.COLUMN_HEARTBEAT_TIME)).longValue());
instance.setOsInfo((String)getResponse.getSource().get(InstanceTable.COLUMN_OS_INFO));
return instance;
}
return null;
}
@Override public List<Instance> getInstances(int applicationId, long timeBucket) {
logger.debug("get instances info, application id: {}, timeBucket: {}", applicationId, timeBucket);
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));
searchRequestBuilder.setQuery(boolQuery);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
SearchHit[] searchHits = searchResponse.getHits().getHits();
List<Instance> instanceList = new LinkedList<>();
for (SearchHit searchHit : searchHits) {
Instance instance = new Instance(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);
}
return instanceList;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.es.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.get.MultiGetItemResponse;
import org.elasticsearch.action.get.MultiGetRequestBuilder;
import org.elasticsearch.action.get.MultiGetResponse;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO;
import org.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable;
/**
* @author peng-yongsheng
*/
public class MemoryMetricEsUIDAO extends EsDAO implements IMemoryMetricUIDAO {
@Override public JsonObject getMetric(int instanceId, long timeBucket, boolean isHeap) {
String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap;
GetResponse getResponse = getClient().prepareGet(MemoryMetricTable.TABLE, id).get();
JsonObject metric = new JsonObject();
if (getResponse.isExists()) {
metric.addProperty("max", ((Number)getResponse.getSource().get(MemoryMetricTable.COLUMN_MAX)).intValue());
metric.addProperty("init", ((Number)getResponse.getSource().get(MemoryMetricTable.COLUMN_INIT)).intValue());
metric.addProperty("used", ((Number)getResponse.getSource().get(MemoryMetricTable.COLUMN_USED)).intValue());
} else {
metric.addProperty("max", 0);
metric.addProperty("init", 0);
metric.addProperty("used", 0);
}
return metric;
}
@Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, boolean isHeap) {
MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet();
int i = 0;
long timeBucket = startTimeBucket;
do {
timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1);
String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap;
prepareMultiGet.add(MemoryMetricTable.TABLE, MemoryMetricTable.TABLE_TYPE, id);
}
while (timeBucket <= endTimeBucket);
JsonObject metric = new JsonObject();
JsonArray usedMetric = new JsonArray();
MultiGetResponse multiGetResponse = prepareMultiGet.get();
for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
if (response.getResponse().isExists()) {
metric.addProperty("max", ((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_MAX)).longValue());
metric.addProperty("init", ((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_INIT)).longValue());
usedMetric.add(((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_USED)).longValue());
} else {
metric.addProperty("max", 0);
metric.addProperty("init", 0);
usedMetric.add(0);
}
}
metric.add("used", usedMetric);
return metric;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.es.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.dao.INodeComponentUIDAO;
import org.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.skywalking.apm.collector.storage.table.node.NodeComponentTable;
import org.skywalking.apm.network.trace.component.ComponentsDefine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class NodeComponentEsUIDAO extends EsDAO implements INodeComponentUIDAO {
private final Logger logger = LoggerFactory.getLogger(NodeComponentEsDAO.class);
@Override public JsonArray load(long startTime, long endTime) {
logger.debug("node component load, start time: {}, end time: {}", startTime, endTime);
JsonArray nodeComponentArray = new JsonArray();
nodeComponentArray.addAll(aggregationByComponentId(startTime, endTime));
nodeComponentArray.addAll(aggregationByComponentName(startTime, endTime));
return nodeComponentArray;
}
private JsonArray aggregationByComponentId(long startTime, long endTime) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(NodeComponentTable.TABLE);
searchRequestBuilder.setTypes(NodeComponentTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setQuery(QueryBuilders.rangeQuery(NodeComponentTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
searchRequestBuilder.setSize(0);
searchRequestBuilder.addAggregation(AggregationBuilders.terms(NodeComponentTable.COLUMN_COMPONENT_ID).field(NodeComponentTable.COLUMN_COMPONENT_ID).size(100)
.subAggregation(AggregationBuilders.terms(NodeComponentTable.COLUMN_PEER).field(NodeComponentTable.COLUMN_PEER).size(100))
.subAggregation(AggregationBuilders.terms(NodeComponentTable.COLUMN_PEER_ID).field(NodeComponentTable.COLUMN_PEER_ID).size(100)));
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
Terms componentIdTerms = searchResponse.getAggregations().get(NodeComponentTable.COLUMN_COMPONENT_ID);
JsonArray nodeComponentArray = new JsonArray();
for (Terms.Bucket componentIdBucket : componentIdTerms.getBuckets()) {
int componentId = componentIdBucket.getKeyAsNumber().intValue();
String componentName = ComponentsDefine.getInstance().getComponentName(componentId);
if (componentId != 0) {
buildComponentArray(componentIdBucket, componentName, nodeComponentArray);
}
}
return nodeComponentArray;
}
private JsonArray aggregationByComponentName(long startTime, long endTime) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(NodeComponentTable.TABLE);
searchRequestBuilder.setTypes(NodeComponentTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setQuery(QueryBuilders.rangeQuery(NodeComponentTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
searchRequestBuilder.setSize(0);
searchRequestBuilder.addAggregation(AggregationBuilders.terms(NodeComponentTable.COLUMN_COMPONENT_NAME).field(NodeComponentTable.COLUMN_COMPONENT_NAME).size(100)
.subAggregation(AggregationBuilders.terms(NodeComponentTable.COLUMN_PEER).field(NodeComponentTable.COLUMN_PEER).size(100))
.subAggregation(AggregationBuilders.terms(NodeComponentTable.COLUMN_PEER_ID).field(NodeComponentTable.COLUMN_PEER_ID).size(100)));
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
Terms componentNameTerms = searchResponse.getAggregations().get(NodeComponentTable.COLUMN_COMPONENT_NAME);
JsonArray nodeComponentArray = new JsonArray();
for (Terms.Bucket componentNameBucket : componentNameTerms.getBuckets()) {
String componentName = componentNameBucket.getKeyAsString();
if (StringUtils.isNotEmpty(componentName)) {
buildComponentArray(componentNameBucket, componentName, nodeComponentArray);
}
}
return nodeComponentArray;
}
private void buildComponentArray(Terms.Bucket componentBucket, String componentName, JsonArray nodeComponentArray) {
Terms peerIdTerms = componentBucket.getAggregations().get(NodeComponentTable.COLUMN_PEER_ID);
for (Terms.Bucket peerIdBucket : peerIdTerms.getBuckets()) {
int peerId = peerIdBucket.getKeyAsNumber().intValue();
if (peerId != 0) {
//TODO ApplicationCache
// String peer = ApplicationCache.get(peerId);
JsonObject nodeComponentObj = new JsonObject();
nodeComponentObj.addProperty("componentName", componentName);
// nodeComponentObj.addProperty("peer", peer);
nodeComponentArray.add(nodeComponentObj);
}
}
Terms peerTerms = componentBucket.getAggregations().get(NodeComponentTable.COLUMN_PEER);
for (Terms.Bucket peerBucket : peerTerms.getBuckets()) {
String peer = peerBucket.getKeyAsString();
if (StringUtils.isNotEmpty(peer)) {
JsonObject nodeComponentObj = new JsonObject();
nodeComponentObj.addProperty("componentName", componentName);
nodeComponentObj.addProperty("peer", peer);
nodeComponentArray.add(nodeComponentObj);
}
}
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.es.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.dao.INodeMappingUIDAO;
import org.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.skywalking.apm.collector.storage.table.node.NodeMappingTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class NodeMappingEsUIDAO extends EsDAO implements INodeMappingUIDAO {
private final Logger logger = LoggerFactory.getLogger(NodeMappingEsUIDAO.class);
@Override public JsonArray load(long startTime, long endTime) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(NodeMappingTable.TABLE);
searchRequestBuilder.setTypes(NodeMappingTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setQuery(QueryBuilders.rangeQuery(NodeMappingTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
searchRequestBuilder.setSize(0);
searchRequestBuilder.addAggregation(
AggregationBuilders.terms(NodeMappingTable.COLUMN_APPLICATION_ID).field(NodeMappingTable.COLUMN_APPLICATION_ID).size(100)
.subAggregation(AggregationBuilders.terms(NodeMappingTable.COLUMN_ADDRESS_ID).field(NodeMappingTable.COLUMN_ADDRESS_ID).size(100))
.subAggregation(AggregationBuilders.terms(NodeMappingTable.COLUMN_ADDRESS).field(NodeMappingTable.COLUMN_ADDRESS).size(100)));
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
Terms applicationIdTerms = searchResponse.getAggregations().get(NodeMappingTable.COLUMN_APPLICATION_ID);
JsonArray nodeMappingArray = new JsonArray();
for (Terms.Bucket applicationIdBucket : applicationIdTerms.getBuckets()) {
int applicationId = applicationIdBucket.getKeyAsNumber().intValue();
//TODO ApplicationCache
// String applicationCode = ApplicationCache.get(applicationId);
Terms addressIdTerms = applicationIdBucket.getAggregations().get(NodeMappingTable.COLUMN_ADDRESS_ID);
for (Terms.Bucket addressIdBucket : addressIdTerms.getBuckets()) {
int addressId = addressIdBucket.getKeyAsNumber().intValue();
//TODO ApplicationCache
// String address = ApplicationCache.get(addressId);
if (addressId != 0) {
JsonObject nodeMappingObj = new JsonObject();
// nodeMappingObj.addProperty("applicationCode", applicationCode);
// nodeMappingObj.addProperty("address", address);
nodeMappingArray.add(nodeMappingObj);
}
}
Terms addressTerms = applicationIdBucket.getAggregations().get(NodeMappingTable.COLUMN_ADDRESS);
for (Terms.Bucket addressBucket : addressTerms.getBuckets()) {
String address = addressBucket.getKeyAsString();
if (StringUtils.isNotEmpty(address)) {
JsonObject nodeMappingObj = new JsonObject();
// nodeMappingObj.addProperty("applicationCode", applicationCode);
nodeMappingObj.addProperty("address", address);
nodeMappingArray.add(nodeMappingObj);
}
}
}
logger.debug("node mapping data: {}", nodeMappingArray.toString());
return nodeMappingArray;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.es.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.dao.INodeReferenceUIDAO;
import org.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.skywalking.apm.collector.storage.table.noderef.NodeReferenceTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class NodeReferenceEsUIDAO extends EsDAO implements INodeReferenceUIDAO {
private final Logger logger = LoggerFactory.getLogger(NodeReferenceEsUIDAO.class);
@Override public JsonArray load(long startTime, long endTime) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(NodeReferenceTable.TABLE);
searchRequestBuilder.setTypes(NodeReferenceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setQuery(QueryBuilders.rangeQuery(NodeReferenceTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
searchRequestBuilder.setSize(0);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(NodeReferenceTable.COLUMN_FRONT_APPLICATION_ID).field(NodeReferenceTable.COLUMN_FRONT_APPLICATION_ID).size(100);
aggregationBuilder.subAggregation(AggregationBuilders.terms(NodeReferenceTable.COLUMN_BEHIND_APPLICATION_ID).field(NodeReferenceTable.COLUMN_BEHIND_APPLICATION_ID).size(100)
.subAggregation(AggregationBuilders.sum(NodeReferenceTable.COLUMN_S1_LTE).field(NodeReferenceTable.COLUMN_S1_LTE))
.subAggregation(AggregationBuilders.sum(NodeReferenceTable.COLUMN_S3_LTE).field(NodeReferenceTable.COLUMN_S3_LTE))
.subAggregation(AggregationBuilders.sum(NodeReferenceTable.COLUMN_S5_LTE).field(NodeReferenceTable.COLUMN_S5_LTE))
.subAggregation(AggregationBuilders.sum(NodeReferenceTable.COLUMN_S5_GT).field(NodeReferenceTable.COLUMN_S5_GT))
.subAggregation(AggregationBuilders.sum(NodeReferenceTable.COLUMN_SUMMARY).field(NodeReferenceTable.COLUMN_SUMMARY))
.subAggregation(AggregationBuilders.sum(NodeReferenceTable.COLUMN_ERROR).field(NodeReferenceTable.COLUMN_ERROR)));
aggregationBuilder.subAggregation(AggregationBuilders.terms(NodeReferenceTable.COLUMN_BEHIND_PEER).field(NodeReferenceTable.COLUMN_BEHIND_PEER).size(100)
.subAggregation(AggregationBuilders.sum(NodeReferenceTable.COLUMN_S1_LTE).field(NodeReferenceTable.COLUMN_S1_LTE))
.subAggregation(AggregationBuilders.sum(NodeReferenceTable.COLUMN_S3_LTE).field(NodeReferenceTable.COLUMN_S3_LTE))
.subAggregation(AggregationBuilders.sum(NodeReferenceTable.COLUMN_S5_LTE).field(NodeReferenceTable.COLUMN_S5_LTE))
.subAggregation(AggregationBuilders.sum(NodeReferenceTable.COLUMN_S5_GT).field(NodeReferenceTable.COLUMN_S5_GT))
.subAggregation(AggregationBuilders.sum(NodeReferenceTable.COLUMN_SUMMARY).field(NodeReferenceTable.COLUMN_SUMMARY))
.subAggregation(AggregationBuilders.sum(NodeReferenceTable.COLUMN_ERROR).field(NodeReferenceTable.COLUMN_ERROR)));
searchRequestBuilder.addAggregation(aggregationBuilder);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
JsonArray nodeRefResSumArray = new JsonArray();
Terms frontApplicationIdTerms = searchResponse.getAggregations().get(NodeReferenceTable.COLUMN_FRONT_APPLICATION_ID);
for (Terms.Bucket frontApplicationIdBucket : frontApplicationIdTerms.getBuckets()) {
int applicationId = frontApplicationIdBucket.getKeyAsNumber().intValue();
//TODO ApplicationCache
// String applicationCode = ApplicationCache.get(applicationId);
Terms behindApplicationIdTerms = frontApplicationIdBucket.getAggregations().get(NodeReferenceTable.COLUMN_BEHIND_APPLICATION_ID);
for (Terms.Bucket behindApplicationIdBucket : behindApplicationIdTerms.getBuckets()) {
int behindApplicationId = behindApplicationIdBucket.getKeyAsNumber().intValue();
if (behindApplicationId != 0) {
// String behindApplicationCode = ApplicationCache.get(behindApplicationId);
Sum s1LTE = behindApplicationIdBucket.getAggregations().get(NodeReferenceTable.COLUMN_S1_LTE);
Sum s3LTE = behindApplicationIdBucket.getAggregations().get(NodeReferenceTable.COLUMN_S3_LTE);
Sum s5LTE = behindApplicationIdBucket.getAggregations().get(NodeReferenceTable.COLUMN_S5_LTE);
Sum s5GT = behindApplicationIdBucket.getAggregations().get(NodeReferenceTable.COLUMN_S5_GT);
Sum summary = behindApplicationIdBucket.getAggregations().get(NodeReferenceTable.COLUMN_SUMMARY);
Sum error = behindApplicationIdBucket.getAggregations().get(NodeReferenceTable.COLUMN_ERROR);
logger.debug("applicationId: {}, behindApplicationId: {}, s1LTE: {}, s3LTE: {}, s5LTE: {}, s5GT: {}, error: {}, summary: {}", applicationId,
behindApplicationId, s1LTE.getValue(), s3LTE.getValue(), s5LTE.getValue(), s5GT.getValue(), error.getValue(), summary.getValue());
JsonObject nodeRefResSumObj = new JsonObject();
// nodeRefResSumObj.addProperty("front", applicationCode);
// nodeRefResSumObj.addProperty("behind", behindApplicationCode);
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_S1_LTE, s1LTE.getValue());
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_S3_LTE, s3LTE.getValue());
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_S5_LTE, s5LTE.getValue());
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_S5_GT, s5GT.getValue());
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_ERROR, error.getValue());
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_SUMMARY, summary.getValue());
nodeRefResSumArray.add(nodeRefResSumObj);
}
}
Terms behindPeerTerms = frontApplicationIdBucket.getAggregations().get(NodeReferenceTable.COLUMN_BEHIND_PEER);
for (Terms.Bucket behindPeerBucket : behindPeerTerms.getBuckets()) {
String behindPeer = behindPeerBucket.getKeyAsString();
if (StringUtils.isNotEmpty(behindPeer)) {
Sum s1LTE = behindPeerBucket.getAggregations().get(NodeReferenceTable.COLUMN_S1_LTE);
Sum s3LTE = behindPeerBucket.getAggregations().get(NodeReferenceTable.COLUMN_S3_LTE);
Sum s5LTE = behindPeerBucket.getAggregations().get(NodeReferenceTable.COLUMN_S5_LTE);
Sum s5GT = behindPeerBucket.getAggregations().get(NodeReferenceTable.COLUMN_S5_GT);
Sum summary = behindPeerBucket.getAggregations().get(NodeReferenceTable.COLUMN_SUMMARY);
Sum error = behindPeerBucket.getAggregations().get(NodeReferenceTable.COLUMN_ERROR);
logger.debug("applicationId: {}, behindPeer: {}, s1LTE: {}, s3LTE: {}, s5LTE: {}, s5GT: {}, error: {}, summary: {}", applicationId,
behindPeer, s1LTE.getValue(), s3LTE.getValue(), s5LTE.getValue(), s5GT.getValue(), error.getValue(), summary.getValue());
JsonObject nodeRefResSumObj = new JsonObject();
// nodeRefResSumObj.addProperty("front", applicationCode);
nodeRefResSumObj.addProperty("behind", behindPeer);
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_S1_LTE, s1LTE.getValue());
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_S3_LTE, s3LTE.getValue());
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_S5_LTE, s5LTE.getValue());
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_S5_GT, s5GT.getValue());
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_ERROR, error.getValue());
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_SUMMARY, summary.getValue());
nodeRefResSumArray.add(nodeRefResSumObj);
}
}
}
return nodeRefResSumArray;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.es.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.List;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.sort.SortOrder;
import org.skywalking.apm.collector.core.util.CollectionUtils;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO;
import org.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.skywalking.apm.collector.storage.table.segment.SegmentCostTable;
/**
* @author peng-yongsheng
*/
public class SegmentCostEsUIDAO extends EsDAO implements ISegmentCostUIDAO {
@Override public JsonObject loadTop(long startTime, long endTime, long minCost, long maxCost, String operationName,
Error error, int applicationId, List<String> segmentIds, int limit, int from, Sort sort) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(SegmentCostTable.TABLE);
searchRequestBuilder.setTypes(SegmentCostTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
searchRequestBuilder.setQuery(boolQueryBuilder);
List<QueryBuilder> mustQueryList = boolQueryBuilder.must();
mustQueryList.add(QueryBuilders.rangeQuery(SegmentCostTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
if (minCost != -1 || maxCost != -1) {
RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(SegmentCostTable.COLUMN_COST);
if (minCost != -1) {
rangeQueryBuilder.gte(minCost);
}
if (maxCost != -1) {
rangeQueryBuilder.lte(maxCost);
}
boolQueryBuilder.must().add(rangeQueryBuilder);
}
if (StringUtils.isNotEmpty(operationName)) {
mustQueryList.add(QueryBuilders.matchQuery(SegmentCostTable.COLUMN_SERVICE_NAME, operationName));
}
if (CollectionUtils.isNotEmpty(segmentIds)) {
boolQueryBuilder.must().add(QueryBuilders.termsQuery(SegmentCostTable.COLUMN_SEGMENT_ID, segmentIds.toArray(new String[0])));
}
if (Error.True.equals(error)) {
boolQueryBuilder.must().add(QueryBuilders.termQuery(SegmentCostTable.COLUMN_IS_ERROR, true));
} else if (Error.False.equals(error)) {
boolQueryBuilder.must().add(QueryBuilders.termQuery(SegmentCostTable.COLUMN_IS_ERROR, false));
}
if (applicationId != 0) {
boolQueryBuilder.must().add(QueryBuilders.termQuery(SegmentCostTable.COLUMN_APPLICATION_ID, applicationId));
}
if (Sort.Cost.equals(sort)) {
searchRequestBuilder.addSort(SegmentCostTable.COLUMN_COST, SortOrder.DESC);
} else if (Sort.Time.equals(sort)) {
searchRequestBuilder.addSort(SegmentCostTable.COLUMN_START_TIME, SortOrder.DESC);
}
searchRequestBuilder.setSize(limit);
searchRequestBuilder.setFrom(from);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
JsonObject topSegPaging = new JsonObject();
topSegPaging.addProperty("recordsTotal", searchResponse.getHits().totalHits);
JsonArray topSegArray = new JsonArray();
topSegPaging.add("data", topSegArray);
int num = from;
for (SearchHit searchHit : searchResponse.getHits().getHits()) {
JsonObject topSegmentJson = new JsonObject();
topSegmentJson.addProperty("num", num);
String segmentId = (String)searchHit.getSource().get(SegmentCostTable.COLUMN_SEGMENT_ID);
topSegmentJson.addProperty(SegmentCostTable.COLUMN_SEGMENT_ID, segmentId);
topSegmentJson.addProperty(SegmentCostTable.COLUMN_START_TIME, (Number)searchHit.getSource().get(SegmentCostTable.COLUMN_START_TIME));
if (searchHit.getSource().containsKey(SegmentCostTable.COLUMN_END_TIME)) {
topSegmentJson.addProperty(SegmentCostTable.COLUMN_END_TIME, (Number)searchHit.getSource().get(SegmentCostTable.COLUMN_END_TIME));
}
//TODO IGlobalTraceUIDAO
// IGlobalTraceUIDAO globalTraceDAO = (IGlobalTraceDAO)DAOContainer.INSTANCE.get(IGlobalTraceDAO.class.getName());
// List<String> globalTraces = globalTraceDAO.getGlobalTraceId(segmentId);
// if (CollectionUtils.isNotEmpty(globalTraces)) {
// topSegmentJson.addProperty(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, globalTraces.get(0));
// }
topSegmentJson.addProperty(SegmentCostTable.COLUMN_APPLICATION_ID, (Number)searchHit.getSource().get(SegmentCostTable.COLUMN_APPLICATION_ID));
topSegmentJson.addProperty(SegmentCostTable.COLUMN_SERVICE_NAME, (String)searchHit.getSource().get(SegmentCostTable.COLUMN_SERVICE_NAME));
topSegmentJson.addProperty(SegmentCostTable.COLUMN_COST, (Number)searchHit.getSource().get(SegmentCostTable.COLUMN_COST));
topSegmentJson.addProperty(SegmentCostTable.COLUMN_IS_ERROR, (Boolean)searchHit.getSource().get(SegmentCostTable.COLUMN_IS_ERROR));
num++;
topSegArray.add(topSegmentJson);
}
return topSegPaging;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.es.dao;
import com.google.protobuf.InvalidProtocolBufferException;
import java.util.Base64;
import java.util.Map;
import org.elasticsearch.action.get.GetResponse;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.dao.ISegmentUIDAO;
import org.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.skywalking.apm.collector.storage.table.segment.SegmentTable;
import org.skywalking.apm.network.proto.TraceSegmentObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class SegmentEsUIDAO extends EsDAO implements ISegmentUIDAO {
private final Logger logger = LoggerFactory.getLogger(SegmentEsUIDAO.class);
@Override public TraceSegmentObject load(String segmentId) {
GetResponse response = getClient().prepareGet(SegmentTable.TABLE, segmentId).get();
Map<String, Object> source = response.getSource();
String dataBinaryBase64 = (String)source.get(SegmentTable.COLUMN_DATA_BINARY);
if (StringUtils.isNotEmpty(dataBinaryBase64)) {
byte[] dataBinary = Base64.getDecoder().decode(dataBinaryBase64);
try {
return TraceSegmentObject.parseFrom(dataBinary);
} catch (InvalidProtocolBufferException e) {
logger.error(e.getMessage(), e);
}
}
return null;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.es.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.skywalking.apm.collector.core.util.ColumnNameUtils;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.dao.IServiceEntryUIDAO;
import org.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.skywalking.apm.collector.storage.table.service.ServiceEntryTable;
/**
* @author peng-yongsheng
*/
public class ServiceEntryEsUIDAO extends EsDAO implements IServiceEntryUIDAO {
@Override
public JsonObject load(int applicationId, String entryServiceName, long startTime, long endTime, int from,
int size) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceEntryTable.TABLE);
searchRequestBuilder.setTypes(ServiceEntryTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must().add(QueryBuilders.rangeQuery(ServiceEntryTable.COLUMN_REGISTER_TIME).lte(endTime));
boolQueryBuilder.must().add(QueryBuilders.rangeQuery(ServiceEntryTable.COLUMN_NEWEST_TIME).gte(startTime));
if (applicationId != 0) {
boolQueryBuilder.must().add(QueryBuilders.matchQuery(ServiceEntryTable.COLUMN_APPLICATION_ID, applicationId));
}
if (StringUtils.isNotEmpty(entryServiceName)) {
boolQueryBuilder.must().add(QueryBuilders.matchQuery(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, entryServiceName));
}
searchRequestBuilder.setQuery(boolQueryBuilder);
searchRequestBuilder.setSize(size);
searchRequestBuilder.setFrom(from);
searchRequestBuilder.addSort(SortBuilders.fieldSort(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME).order(SortOrder.ASC));
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
return parseResponse(searchResponse);
}
private JsonObject parseResponse(SearchResponse searchResponse) {
SearchHits searchHits = searchResponse.getHits();
JsonArray serviceArray = new JsonArray();
for (SearchHit searchHit : searchHits.getHits()) {
int applicationId = ((Number)searchHit.getSource().get(ServiceEntryTable.COLUMN_APPLICATION_ID)).intValue();
int entryServiceId = ((Number)searchHit.getSource().get(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID)).intValue();
String entryServiceName = (String)searchHit.getSource().get(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME);
JsonObject row = new JsonObject();
row.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID), entryServiceId);
row.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME), entryServiceName);
row.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceEntryTable.COLUMN_APPLICATION_ID), applicationId);
serviceArray.add(row);
}
JsonObject response = new JsonObject();
response.addProperty("total", searchHits.totalHits);
response.add("array", serviceArray);
return response;
}
}
......@@ -18,7 +18,7 @@
package org.skywalking.apm.collector.storage.es.service;
import org.skywalking.apm.collector.storage.base.dao.DAO;
import org.skywalking.apm.collector.storage.base.dao.AbstractDAO;
import org.skywalking.apm.collector.storage.base.dao.DAOContainer;
import org.skywalking.apm.collector.storage.service.DAOService;
......@@ -33,7 +33,7 @@ public class ElasticSearchDAOService implements DAOService {
this.daoContainer = daoContainer;
}
@Override public DAO get(Class<DAO> daoInterfaceClass) {
@Override public AbstractDAO get(Class<AbstractDAO> daoInterfaceClass) {
return daoContainer.get(daoInterfaceClass.getName());
}
}
......@@ -22,14 +22,14 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.storage.base.dao.DAO;
import org.skywalking.apm.collector.storage.base.dao.AbstractDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public abstract class H2DAO extends DAO<H2Client> {
public abstract class H2DAO extends AbstractDAO<H2Client> {
private final Logger logger = LoggerFactory.getLogger(H2DAO.class);
protected final int getMaxId(String tableName, String columnName) {
......
......@@ -23,7 +23,7 @@ import java.util.Map;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.skywalking.apm.collector.storage.dao.IApplicationDAO;
import org.skywalking.apm.collector.storage.dao.IApplicationStreamDAO;
import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.skywalking.apm.collector.storage.table.register.Application;
import org.skywalking.apm.collector.storage.table.register.ApplicationTable;
......@@ -33,8 +33,8 @@ import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng, clevertension
*/
public class ApplicationH2DAO extends H2DAO implements IApplicationDAO {
private final Logger logger = LoggerFactory.getLogger(ApplicationH2DAO.class);
public class ApplicationH2StreamDAO extends H2DAO implements IApplicationStreamDAO {
private final Logger logger = LoggerFactory.getLogger(ApplicationH2StreamDAO.class);
@Override
public int getMaxApplicationId() {
......
......@@ -22,7 +22,7 @@ import java.util.HashMap;
import java.util.Map;
import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO;
import org.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.skywalking.apm.collector.storage.dao.ICpuMetricDAO;
import org.skywalking.apm.collector.storage.dao.ICpuMetricStreamDAO;
import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity;
import org.skywalking.apm.collector.storage.table.jvm.CpuMetric;
......@@ -33,8 +33,8 @@ import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng, clevertension
*/
public class CpuMetricH2DAO extends H2DAO implements ICpuMetricDAO, IPersistenceDAO<H2SqlEntity, H2SqlEntity, CpuMetric> {
private final Logger logger = LoggerFactory.getLogger(CpuMetricH2DAO.class);
public class CpuMetricH2StreamDAO extends H2DAO implements ICpuMetricStreamDAO, IPersistenceDAO<H2SqlEntity, H2SqlEntity, CpuMetric> {
private final Logger logger = LoggerFactory.getLogger(CpuMetricH2StreamDAO.class);
@Override public CpuMetric get(String id) {
return null;
......
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.h2.dao;
import com.google.gson.JsonArray;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO;
import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.skywalking.apm.collector.storage.table.jvm.CpuMetricTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng, clevertension
*/
public class CpuMetricH2UIDAO extends H2DAO implements ICpuMetricUIDAO {
private final Logger logger = LoggerFactory.getLogger(CpuMetricH2UIDAO.class);
private static final String GET_CPU_METRIC_SQL = "select * from {0} where {1} = ?";
@Override public int getMetric(int instanceId, long timeBucket) {
String id = timeBucket + Const.ID_SPLIT + instanceId;
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_CPU_METRIC_SQL, CpuMetricTable.TABLE, CpuMetricTable.COLUMN_ID);
Object[] params = new Object[] {id};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getInt(CpuMetricTable.COLUMN_USAGE_PERCENT);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
@Override public JsonArray getMetric(int instanceId, long startTimeBucket, long endTimeBucket) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_CPU_METRIC_SQL, CpuMetricTable.TABLE, CpuMetricTable.COLUMN_ID);
long timeBucket = startTimeBucket;
List<String> idList = new ArrayList<>();
do {
timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1);
String id = timeBucket + Const.ID_SPLIT + instanceId;
idList.add(id);
}
while (timeBucket <= endTimeBucket);
JsonArray metrics = new JsonArray();
idList.forEach(id -> {
try (ResultSet rs = client.executeQuery(sql, new String[] {id})) {
if (rs.next()) {
double cpuUsed = rs.getDouble(CpuMetricTable.COLUMN_USAGE_PERCENT);
metrics.add((int)(cpuUsed * 100));
} else {
metrics.add(0);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
});
return metrics;
}
}
......@@ -22,7 +22,7 @@ import java.util.HashMap;
import java.util.Map;
import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO;
import org.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.skywalking.apm.collector.storage.dao.IGCMetricDAO;
import org.skywalking.apm.collector.storage.dao.IGCMetricStreamDAO;
import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity;
import org.skywalking.apm.collector.storage.table.jvm.GCMetric;
......@@ -31,7 +31,7 @@ import org.skywalking.apm.collector.storage.table.jvm.GCMetricTable;
/**
* @author peng-yongsheng, clevertension
*/
public class GCMetricH2DAO extends H2DAO implements IGCMetricDAO, IPersistenceDAO<H2SqlEntity, H2SqlEntity, GCMetric> {
public class GCMetricH2StreamDAO extends H2DAO implements IGCMetricStreamDAO, IPersistenceDAO<H2SqlEntity, H2SqlEntity, GCMetric> {
@Override public GCMetric get(String id) {
return null;
......
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.h2.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.skywalking.apm.collector.storage.dao.IGCMetricUIDAO;
import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.skywalking.apm.collector.storage.table.jvm.GCMetricTable;
import org.skywalking.apm.network.proto.GCPhrase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng, clevertension
*/
public class GCMetricH2UIDAO extends H2DAO implements IGCMetricUIDAO {
private final Logger logger = LoggerFactory.getLogger(GCMetricH2UIDAO.class);
private static final String GET_GC_COUNT_SQL = "select {1}, sum({0}) as cnt, {1} from {2} where {3} = ? and {4} in (";
private static final String GET_GC_METRIC_SQL = "select * from {0} where {1} = ?";
@Override public GCCount getGCCount(long[] timeBuckets, int instanceId) {
GCCount gcCount = new GCCount();
H2Client client = getClient();
String sql = GET_GC_COUNT_SQL;
StringBuilder builder = new StringBuilder();
for (int i = 0; i < timeBuckets.length; i++) {
builder.append("?,");
}
builder.delete(builder.length() - 1, builder.length());
builder.append(")");
sql = sql + builder + " group by {1}";
sql = SqlBuilder.buildSql(sql, GCMetricTable.COLUMN_COUNT, GCMetricTable.COLUMN_PHRASE,
GCMetricTable.TABLE, GCMetricTable.COLUMN_INSTANCE_ID, GCMetricTable.COLUMN_ID);
Object[] params = new Object[timeBuckets.length + 1];
for (int i = 0; i < timeBuckets.length; i++) {
params[i + 1] = timeBuckets[i];
}
params[0] = instanceId;
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
int phrase = rs.getInt(GCMetricTable.COLUMN_PHRASE);
int count = rs.getInt("cnt");
if (phrase == GCPhrase.NEW_VALUE) {
gcCount.setYoung(count);
} else if (phrase == GCPhrase.OLD_VALUE) {
gcCount.setOld(count);
}
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return gcCount;
}
@Override public JsonObject getMetric(int instanceId, long timeBucket) {
JsonObject response = new JsonObject();
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_GC_METRIC_SQL, GCMetricTable.TABLE, GCMetricTable.COLUMN_ID);
String youngId = timeBucket + Const.ID_SPLIT + GCPhrase.NEW_VALUE + instanceId;
Object[] params = new Object[] {youngId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
response.addProperty("ygc", rs.getInt(GCMetricTable.COLUMN_COUNT));
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
String oldId = timeBucket + Const.ID_SPLIT + GCPhrase.OLD_VALUE + instanceId;
Object[] params1 = new Object[] {oldId};
try (ResultSet rs = client.executeQuery(sql, params1)) {
if (rs.next()) {
response.addProperty("ogc", rs.getInt(GCMetricTable.COLUMN_COUNT));
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return response;
}
@Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket) {
JsonObject response = new JsonObject();
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_GC_METRIC_SQL, GCMetricTable.TABLE, GCMetricTable.COLUMN_ID);
long timeBucket = startTimeBucket;
List<String> youngIdsList = new ArrayList<>();
do {
timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1);
String youngId = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + GCPhrase.NEW_VALUE;
youngIdsList.add(youngId);
}
while (timeBucket <= endTimeBucket);
JsonArray youngArray = new JsonArray();
forEachRs(client, youngIdsList, sql, youngArray);
response.add("ygc", youngArray);
List<String> oldIdsList = new ArrayList<>();
timeBucket = startTimeBucket;
do {
timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1);
String oldId = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + GCPhrase.OLD_VALUE;
oldIdsList.add(oldId);
}
while (timeBucket <= endTimeBucket);
JsonArray oldArray = new JsonArray();
forEachRs(client, oldIdsList, sql, oldArray);
response.add("ogc", oldArray);
return response;
}
private void forEachRs(H2Client client, List<String> idsList, String sql, JsonArray metricArray) {
idsList.forEach(id -> {
try (ResultSet rs = client.executeQuery(sql, new String[] {id})) {
if (rs.next()) {
metricArray.add(rs.getInt(GCMetricTable.COLUMN_COUNT));
} else {
metricArray.add(0);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
});
}
}
......@@ -23,7 +23,7 @@ import java.util.Map;
import org.skywalking.apm.collector.core.UnexpectedException;
import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO;
import org.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.skywalking.apm.collector.storage.dao.IGlobalTraceDAO;
import org.skywalking.apm.collector.storage.dao.IGlobalTraceStreamDAO;
import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity;
import org.skywalking.apm.collector.storage.table.global.GlobalTrace;
......@@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng, clevertension
*/
public class GlobalTraceH2DAO extends H2DAO implements IGlobalTraceDAO, IPersistenceDAO<H2SqlEntity, H2SqlEntity, GlobalTrace> {
public class GlobalTraceH2DAO extends H2DAO implements IGlobalTraceStreamDAO, IPersistenceDAO<H2SqlEntity, H2SqlEntity, GlobalTrace> {
private final Logger logger = LoggerFactory.getLogger(GlobalTraceH2DAO.class);
@Override public GlobalTrace get(String id) {
......
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.h2.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO;
import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.skywalking.apm.collector.storage.table.global.GlobalTraceTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng, clevertension
*/
public class GlobalTraceH2UIDAO extends H2DAO implements IGlobalTraceUIDAO {
private final Logger logger = LoggerFactory.getLogger(GlobalTraceH2UIDAO.class);
private static final String GET_GLOBAL_TRACE_ID_SQL = "select {0} from {1} where {2} = ? limit 10";
private static final String GET_SEGMENT_IDS_SQL = "select {0} from {1} where {2} = ? limit 10";
@Override public List<String> getGlobalTraceId(String segmentId) {
List<String> globalTraceIds = new ArrayList<>();
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_GLOBAL_TRACE_ID_SQL, GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID,
GlobalTraceTable.TABLE, GlobalTraceTable.COLUMN_SEGMENT_ID);
Object[] params = new Object[] {segmentId};
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
String globalTraceId = rs.getString(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID);
logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId);
globalTraceIds.add(globalTraceId);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return globalTraceIds;
}
@Override public List<String> getSegmentIds(String globalTraceId) {
List<String> segmentIds = new ArrayList<>();
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_SEGMENT_IDS_SQL, GlobalTraceTable.COLUMN_SEGMENT_ID,
GlobalTraceTable.TABLE, GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID);
Object[] params = new Object[] {globalTraceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
String segmentId = rs.getString(GlobalTraceTable.COLUMN_SEGMENT_ID);
logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId);
segmentIds.add(segmentId);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return segmentIds;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.h2.dao;
import com.google.gson.JsonArray;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.skywalking.apm.collector.storage.dao.IInstPerformanceUIDAO;
import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.skywalking.apm.collector.storage.table.instance.InstPerformanceTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng, clevertension
*/
public class InstPerformanceH2UIDAO extends H2DAO implements IInstPerformanceUIDAO {
private final Logger logger = LoggerFactory.getLogger(InstPerformanceH2UIDAO.class);
private static final String GET_INST_PERF_SQL = "select * from {0} where {1} = ? and {2} in (";
private static final String GET_TPS_METRIC_SQL = "select * from {0} where {1} = ?";
@Override public InstPerformance get(long[] timeBuckets, int instanceId) {
H2Client client = getClient();
logger.info("the inst performance inst id = {}", instanceId);
String sql = SqlBuilder.buildSql(GET_INST_PERF_SQL, InstPerformanceTable.TABLE, InstPerformanceTable.COLUMN_INSTANCE_ID, InstPerformanceTable.COLUMN_TIME_BUCKET);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < timeBuckets.length; i++) {
builder.append("?,");
}
builder.delete(builder.length() - 1, builder.length());
builder.append(")");
sql = sql + builder;
Object[] params = new Object[timeBuckets.length + 1];
for (int i = 0; i < timeBuckets.length; i++) {
params[i + 1] = timeBuckets[i];
}
params[0] = instanceId;
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
int callTimes = rs.getInt(InstPerformanceTable.COLUMN_CALLS);
int costTotal = rs.getInt(InstPerformanceTable.COLUMN_COST_TOTAL);
return new InstPerformance(instanceId, callTimes, costTotal);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return null;
}
@Override public int getTpsMetric(int instanceId, long timeBucket) {
logger.info("getTpMetric instanceId = {}, startTimeBucket = {}", instanceId, timeBucket);
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_TPS_METRIC_SQL, InstPerformanceTable.TABLE, InstPerformanceTable.COLUMN_ID);
Object[] params = new Object[] {instanceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getInt(InstPerformanceTable.COLUMN_CALLS);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
@Override public JsonArray getTpsMetric(int instanceId, long startTimeBucket, long endTimeBucket) {
logger.info("getTpsMetric instanceId = {}, startTimeBucket = {}, endTimeBucket = {}", instanceId, startTimeBucket, endTimeBucket);
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_TPS_METRIC_SQL, InstPerformanceTable.TABLE, InstPerformanceTable.COLUMN_ID);
long timeBucket = startTimeBucket;
List<String> idList = new ArrayList<>();
do {
String id = timeBucket + Const.ID_SPLIT + instanceId;
timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1);
idList.add(id);
}
while (timeBucket <= endTimeBucket);
JsonArray metrics = new JsonArray();
idList.forEach(id -> {
try (ResultSet rs = client.executeQuery(sql, new Object[] {id})) {
if (rs.next()) {
int calls = rs.getInt(InstPerformanceTable.COLUMN_CALLS);
metrics.add(calls);
} else {
metrics.add(0);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
});
return metrics;
}
@Override public int getRespTimeMetric(int instanceId, long timeBucket) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_TPS_METRIC_SQL, InstPerformanceTable.TABLE, InstPerformanceTable.COLUMN_ID);
Object[] params = new Object[] {instanceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
int callTimes = rs.getInt(InstPerformanceTable.COLUMN_CALLS);
int costTotal = rs.getInt(InstPerformanceTable.COLUMN_COST_TOTAL);
return costTotal / callTimes;
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
@Override public JsonArray getRespTimeMetric(int instanceId, long startTimeBucket, long endTimeBucket) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_TPS_METRIC_SQL, InstPerformanceTable.TABLE, InstPerformanceTable.COLUMN_ID);
long timeBucket = startTimeBucket;
List<String> idList = new ArrayList<>();
do {
String id = timeBucket + Const.ID_SPLIT + instanceId;
timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1);
idList.add(id);
}
while (timeBucket <= endTimeBucket);
JsonArray metrics = new JsonArray();
idList.forEach(id -> {
try (ResultSet rs = client.executeQuery(sql, new Object[] {id})) {
if (rs.next()) {
int callTimes = rs.getInt(InstPerformanceTable.COLUMN_CALLS);
int costTotal = rs.getInt(InstPerformanceTable.COLUMN_COST_TOTAL);
metrics.add(costTotal / callTimes);
} else {
metrics.add(0);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
});
return metrics;
}
}
......@@ -25,7 +25,7 @@ import java.util.Map;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.skywalking.apm.collector.storage.dao.IInstanceDAO;
import org.skywalking.apm.collector.storage.dao.IInstanceStreamDAO;
import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.skywalking.apm.collector.storage.table.register.Instance;
import org.skywalking.apm.collector.storage.table.register.InstanceTable;
......@@ -35,8 +35,8 @@ import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng, clevertension
*/
public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
private final Logger logger = LoggerFactory.getLogger(InstanceH2DAO.class);
public class InstanceH2StreamDAO extends H2DAO implements IInstanceStreamDAO {
private final Logger logger = LoggerFactory.getLogger(InstanceH2StreamDAO.class);
private static final String GET_INSTANCE_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ?";
private static final String UPDATE_HEARTBEAT_TIME_SQL = "update {0} set {1} = ? where {2} = ?";
......
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.h2.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.skywalking.apm.collector.storage.dao.IInstanceUIDAO;
import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.skywalking.apm.collector.storage.table.register.Instance;
import org.skywalking.apm.collector.storage.table.register.InstanceTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng, clevertension
*/
public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO {
private final Logger logger = LoggerFactory.getLogger(InstanceH2UIDAO.class);
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_APPLICATIONS_SQL = "select {3}, count({0}) as cnt from {1} where {2} >= ? group by {3} limit 100";
@Override
public Long lastHeartBeatTime() {
H2Client client = getClient();
long fiveMinuteBefore = System.currentTimeMillis() - 5 * 60 * 1000;
fiveMinuteBefore = TimeBucketUtils.INSTANCE.getSecondTimeBucket(fiveMinuteBefore);
String sql = SqlBuilder.buildSql(GET_LAST_HEARTBEAT_TIME_SQL, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME);
Object[] params = new Object[] {fiveMinuteBefore};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getLong(1);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return 0L;
}
@Override
public Long instanceLastHeartBeatTime(long applicationInstanceId) {
H2Client client = getClient();
long fiveMinuteBefore = System.currentTimeMillis() - 5 * 60 * 1000;
fiveMinuteBefore = TimeBucketUtils.INSTANCE.getSecondTimeBucket(fiveMinuteBefore);
String sql = SqlBuilder.buildSql(GET_INST_LAST_HEARTBEAT_TIME_SQL, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.TABLE,
InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_INSTANCE_ID);
Object[] params = new Object[] {fiveMinuteBefore, applicationInstanceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getLong(1);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return 0L;
}
@Override
public JsonArray getApplications(long startTime, long endTime) {
H2Client client = getClient();
JsonArray applications = new JsonArray();
String sql = SqlBuilder.buildSql(GET_APPLICATIONS_SQL, InstanceTable.COLUMN_INSTANCE_ID,
InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_APPLICATION_ID);
Object[] params = new Object[] {startTime};
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
Integer applicationId = rs.getInt(InstanceTable.COLUMN_APPLICATION_ID);
logger.debug("applicationId: {}", applicationId);
JsonObject application = new JsonObject();
application.addProperty("applicationId", applicationId);
application.addProperty("applicationCode", ApplicationCache.get(applicationId));
application.addProperty("instanceCount", rs.getInt("cnt"));
applications.add(application);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return applications;
}
@Override
public Instance getInstance(int instanceId) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_INSTANCE_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID);
Object[] params = new Object[] {instanceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
Instance instance = new Instance(rs.getString(InstanceTable.COLUMN_ID));
instance.setApplicationId(rs.getInt(InstanceTable.COLUMN_APPLICATION_ID));
instance.setAgentUUID(rs.getString(InstanceTable.COLUMN_AGENT_UUID));
instance.setRegisterTime(rs.getLong(InstanceTable.COLUMN_REGISTER_TIME));
instance.setHeartBeatTime(rs.getLong(InstanceTable.COLUMN_HEARTBEAT_TIME));
instance.setOsInfo(rs.getString(InstanceTable.COLUMN_OS_INFO));
return instance;
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
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<>();
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};
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
Instance instance = new Instance(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);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return instanceList;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.h2.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO;
import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author clevertension
*/
public class MemoryMetricH2UIDAO extends H2DAO implements IMemoryMetricUIDAO {
private final Logger logger = LoggerFactory.getLogger(MemoryMetricH2UIDAO.class);
private static final String GET_MEMORY_METRIC_SQL = "select * from {0} where {1} =?";
@Override public JsonObject getMetric(int instanceId, long timeBucket, boolean isHeap) {
H2Client client = getClient();
String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap;
String sql = SqlBuilder.buildSql(GET_MEMORY_METRIC_SQL, MemoryMetricTable.TABLE, MemoryMetricTable.COLUMN_ID);
Object[] params = new Object[] {id};
JsonObject metric = new JsonObject();
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
metric.addProperty("max", rs.getInt(MemoryMetricTable.COLUMN_MAX));
metric.addProperty("init", rs.getInt(MemoryMetricTable.COLUMN_INIT));
metric.addProperty("used", rs.getInt(MemoryMetricTable.COLUMN_USED));
} else {
metric.addProperty("max", 0);
metric.addProperty("init", 0);
metric.addProperty("used", 0);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return metric;
}
@Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, boolean isHeap) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_MEMORY_METRIC_SQL, MemoryMetricTable.TABLE, MemoryMetricTable.COLUMN_ID);
List<String> idList = new ArrayList<>();
long timeBucket = startTimeBucket;
do {
timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1);
String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap;
idList.add(id);
}
while (timeBucket <= endTimeBucket);
JsonObject metric = new JsonObject();
JsonArray usedMetric = new JsonArray();
idList.forEach(id -> {
try (ResultSet rs = client.executeQuery(sql, new String[] {id})) {
if (rs.next()) {
metric.addProperty("max", rs.getLong(MemoryMetricTable.COLUMN_MAX));
metric.addProperty("init", rs.getLong(MemoryMetricTable.COLUMN_INIT));
usedMetric.add(rs.getLong(MemoryMetricTable.COLUMN_USED));
} else {
metric.addProperty("max", 0);
metric.addProperty("init", 0);
usedMetric.add(0);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
});
metric.add("used", usedMetric);
return metric;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.h2.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.skywalking.apm.collector.storage.dao.INodeComponentUIDAO;
import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.skywalking.apm.collector.storage.table.node.NodeComponentTable;
import org.skywalking.apm.network.trace.component.ComponentsDefine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng, clevertension
*/
public class NodeComponentH2UIDAO extends H2DAO implements INodeComponentUIDAO {
private final Logger logger = LoggerFactory.getLogger(NodeComponentH2UIDAO.class);
private static final String AGGREGATE_COMPONENT_SQL = "select {0}, {1}, {2} from {3} where {4} >= ? and {4} <= ? group by {0}, {1}, {2} limit 100";
@Override public JsonArray load(long startTime, long endTime) {
JsonArray nodeComponentArray = new JsonArray();
nodeComponentArray.addAll(aggregationComponent(startTime, endTime));
return nodeComponentArray;
}
private JsonArray aggregationComponent(long startTime, long endTime) {
H2Client client = getClient();
JsonArray nodeComponentArray = new JsonArray();
String sql = SqlBuilder.buildSql(AGGREGATE_COMPONENT_SQL, NodeComponentTable.COLUMN_COMPONENT_ID,
NodeComponentTable.COLUMN_PEER, NodeComponentTable.COLUMN_PEER_ID,
NodeComponentTable.TABLE, NodeComponentTable.COLUMN_TIME_BUCKET);
Object[] params = new Object[] {startTime, endTime};
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
int peerId = rs.getInt(NodeComponentTable.COLUMN_PEER_ID);
int componentId = rs.getInt(NodeComponentTable.COLUMN_COMPONENT_ID);
String componentName = ComponentsDefine.getInstance().getComponentName(componentId);
if (peerId != 0) {
//TODO ApplicationCache
// String peer = ApplicationCache.get(peerId);
// nodeComponentArray.add(buildNodeComponent(peer, componentName));
}
String peer = rs.getString(NodeComponentTable.COLUMN_PEER);
if (StringUtils.isNotEmpty(peer)) {
nodeComponentArray.add(buildNodeComponent(peer, componentName));
}
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return nodeComponentArray;
}
private JsonObject buildNodeComponent(String peer, String componentName) {
JsonObject nodeComponentObj = new JsonObject();
nodeComponentObj.addProperty("componentName", componentName);
nodeComponentObj.addProperty("peer", peer);
return nodeComponentObj;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.h2.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.skywalking.apm.collector.storage.dao.INodeMappingUIDAO;
import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.skywalking.apm.collector.storage.table.node.NodeMappingTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng, clevertension
*/
public class NodeMappingH2UIDAO extends H2DAO implements INodeMappingUIDAO {
private final Logger logger = LoggerFactory.getLogger(NodeMappingH2UIDAO.class);
private static final String NODE_MAPPING_SQL = "select {0}, {1}, {2} from {3} where {4} >= ? and {4} <= ? group by {0}, {1}, {2} limit 100";
@Override public JsonArray load(long startTime, long endTime) {
H2Client client = getClient();
JsonArray nodeMappingArray = new JsonArray();
String sql = SqlBuilder.buildSql(NODE_MAPPING_SQL, NodeMappingTable.COLUMN_APPLICATION_ID,
NodeMappingTable.COLUMN_ADDRESS_ID, NodeMappingTable.COLUMN_ADDRESS,
NodeMappingTable.TABLE, NodeMappingTable.COLUMN_TIME_BUCKET);
Object[] params = new Object[] {startTime, endTime};
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
int applicationId = rs.getInt(NodeMappingTable.COLUMN_APPLICATION_ID);
//TODO ApplicationCache
// String applicationCode = ApplicationCache.get(applicationId);
int addressId = rs.getInt(NodeMappingTable.COLUMN_ADDRESS_ID);
if (addressId != 0) {
// String address = ApplicationCache.get(addressId);
JsonObject nodeMappingObj = new JsonObject();
// nodeMappingObj.addProperty("applicationCode", applicationCode);
// nodeMappingObj.addProperty("address", address);
nodeMappingArray.add(nodeMappingObj);
}
String address = rs.getString(NodeMappingTable.COLUMN_ADDRESS);
if (StringUtils.isNotEmpty(address)) {
JsonObject nodeMappingObj = new JsonObject();
// nodeMappingObj.addProperty("applicationCode", applicationCode);
nodeMappingObj.addProperty("address", address);
nodeMappingArray.add(nodeMappingObj);
}
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
logger.debug("node mapping data: {}", nodeMappingArray.toString());
return nodeMappingArray;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.h2.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.skywalking.apm.collector.storage.dao.INodeReferenceUIDAO;
import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.skywalking.apm.collector.storage.table.noderef.NodeReferenceTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng, clevertension
*/
public class NodeReferenceH2UIDAO extends H2DAO implements INodeReferenceUIDAO {
private final Logger logger = LoggerFactory.getLogger(NodeReferenceH2UIDAO.class);
private static final String NODE_REFERENCE_SQL = "select {8}, {9}, {10}, sum({0}) as {0}, sum({1}) as {1}, sum({2}) as {2}, " +
"sum({3}) as {3}, sum({4}) as {4}, sum({5}) as {5} from {6} where {7} >= ? and {7} <= ? group by {8}, {9}, {10} limit 100";
@Override public JsonArray load(long startTime, long endTime) {
H2Client client = getClient();
JsonArray nodeRefResSumArray = new JsonArray();
String sql = SqlBuilder.buildSql(NODE_REFERENCE_SQL, NodeReferenceTable.COLUMN_S1_LTE,
NodeReferenceTable.COLUMN_S3_LTE, NodeReferenceTable.COLUMN_S5_LTE,
NodeReferenceTable.COLUMN_S5_GT, NodeReferenceTable.COLUMN_SUMMARY,
NodeReferenceTable.COLUMN_ERROR, NodeReferenceTable.TABLE, NodeReferenceTable.COLUMN_TIME_BUCKET,
NodeReferenceTable.COLUMN_FRONT_APPLICATION_ID, NodeReferenceTable.COLUMN_BEHIND_APPLICATION_ID, NodeReferenceTable.COLUMN_BEHIND_PEER);
Object[] params = new Object[] {startTime, endTime};
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
int applicationId = rs.getInt(NodeReferenceTable.COLUMN_FRONT_APPLICATION_ID);
//TODO ApplicationCache
// String applicationCode = ApplicationCache.get(applicationId);
int behindApplicationId = rs.getInt(NodeReferenceTable.COLUMN_BEHIND_APPLICATION_ID);
if (behindApplicationId != 0) {
// String behindApplicationCode = ApplicationCache.get(behindApplicationId);
JsonObject nodeRefResSumObj = new JsonObject();
// nodeRefResSumObj.addProperty("front", applicationCode);
// nodeRefResSumObj.addProperty("behind", behindApplicationCode);
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_S1_LTE, rs.getDouble(NodeReferenceTable.COLUMN_S1_LTE));
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_S3_LTE, rs.getDouble(NodeReferenceTable.COLUMN_S3_LTE));
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_S5_LTE, rs.getDouble(NodeReferenceTable.COLUMN_S5_LTE));
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_S5_GT, rs.getDouble(NodeReferenceTable.COLUMN_S5_GT));
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_ERROR, rs.getDouble(NodeReferenceTable.COLUMN_ERROR));
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_SUMMARY, rs.getDouble(NodeReferenceTable.COLUMN_SUMMARY));
nodeRefResSumArray.add(nodeRefResSumObj);
}
String behindPeer = rs.getString(NodeReferenceTable.COLUMN_BEHIND_PEER);
if (StringUtils.isNotEmpty(behindPeer)) {
JsonObject nodeRefResSumObj = new JsonObject();
// nodeRefResSumObj.addProperty("front", applicationCode);
nodeRefResSumObj.addProperty("behind", behindPeer);
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_S1_LTE, rs.getDouble(NodeReferenceTable.COLUMN_S1_LTE));
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_S3_LTE, rs.getDouble(NodeReferenceTable.COLUMN_S3_LTE));
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_S5_LTE, rs.getDouble(NodeReferenceTable.COLUMN_S5_LTE));
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_S5_GT, rs.getDouble(NodeReferenceTable.COLUMN_S5_GT));
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_ERROR, rs.getDouble(NodeReferenceTable.COLUMN_ERROR));
nodeRefResSumObj.addProperty(NodeReferenceTable.COLUMN_SUMMARY, rs.getDouble(NodeReferenceTable.COLUMN_SUMMARY));
nodeRefResSumArray.add(nodeRefResSumObj);
}
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return nodeRefResSumArray;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.h2.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.elasticsearch.search.sort.SortOrder;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.CollectionUtils;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO;
import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.skywalking.apm.collector.storage.table.segment.SegmentCostTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng, clevertension
*/
public class SegmentCostH2UIDAO extends H2DAO implements ISegmentCostUIDAO {
private final Logger logger = LoggerFactory.getLogger(SegmentCostH2UIDAO.class);
private static final String GET_SEGMENT_COST_SQL = "select * from {0} where {1} >= ? and {1} <= ?";
@Override public JsonObject loadTop(long startTime, long endTime, long minCost, long maxCost, String operationName,
Error error, int applicationId, List<String> segmentIds, int limit, int from, Sort sort) {
H2Client client = getClient();
String sql = GET_SEGMENT_COST_SQL;
List<Object> params = new ArrayList<>();
List<Object> columns = new ArrayList<>();
columns.add(SegmentCostTable.TABLE);
columns.add(SegmentCostTable.COLUMN_TIME_BUCKET);
params.add(startTime);
params.add(endTime);
int paramIndex = 1;
if (minCost != -1 || maxCost != -1) {
if (minCost != -1) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} >= ?";
params.add(minCost);
columns.add(SegmentCostTable.COLUMN_COST);
}
if (maxCost != -1) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} <= ?";
params.add(maxCost);
columns.add(SegmentCostTable.COLUMN_COST);
}
}
if (StringUtils.isNotEmpty(operationName)) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} = ?";
params.add(operationName);
columns.add(SegmentCostTable.COLUMN_SERVICE_NAME);
}
if (CollectionUtils.isNotEmpty(segmentIds)) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} in (";
columns.add(SegmentCostTable.COLUMN_SEGMENT_ID);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < segmentIds.size(); i++) {
builder.append("?,");
}
builder.delete(builder.length() - 1, builder.length());
builder.append(")");
sql = sql + builder;
for (String segmentId : segmentIds) {
params.add(segmentId);
}
}
if (Error.True.equals(error)) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} = ?";
params.add(true);
columns.add(SegmentCostTable.COLUMN_IS_ERROR);
} else if (Error.False.equals(error)) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} = ?";
params.add(false);
columns.add(SegmentCostTable.COLUMN_IS_ERROR);
}
if (applicationId != 0) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} = ?";
params.add(applicationId);
columns.add(SegmentCostTable.COLUMN_APPLICATION_ID);
}
if (Sort.Cost.equals(sort)) {
sql = sql + " order by " + SegmentCostTable.COLUMN_COST + " " + SortOrder.DESC;
} else if (Sort.Time.equals(sort)) {
sql = sql + " order by " + SegmentCostTable.COLUMN_START_TIME + " " + SortOrder.DESC;
}
sql = sql + " limit " + from + "," + limit;
sql = SqlBuilder.buildSql(sql, columns);
Object[] p = params.toArray(new Object[0]);
JsonObject topSegPaging = new JsonObject();
JsonArray topSegArray = new JsonArray();
topSegPaging.add("data", topSegArray);
int cnt = 0;
int num = from;
try (ResultSet rs = client.executeQuery(sql, p)) {
while (rs.next()) {
JsonObject topSegmentJson = new JsonObject();
topSegmentJson.addProperty("num", num);
String segmentId = rs.getString(SegmentCostTable.COLUMN_SEGMENT_ID);
topSegmentJson.addProperty(SegmentCostTable.COLUMN_SEGMENT_ID, segmentId);
topSegmentJson.addProperty(SegmentCostTable.COLUMN_START_TIME, rs.getLong(SegmentCostTable.COLUMN_START_TIME));
topSegmentJson.addProperty(SegmentCostTable.COLUMN_END_TIME, rs.getLong(SegmentCostTable.COLUMN_END_TIME));
//TODO IGlobalTraceDAO
// IGlobalTraceDAO globalTraceDAO = (IGlobalTraceDAO)DAOContainer.INSTANCE.get(IGlobalTraceDAO.class.getName());
// List<String> globalTraces = globalTraceDAO.getGlobalTraceId(segmentId);
// if (CollectionUtils.isNotEmpty(globalTraces)) {
// topSegmentJson.addProperty(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, globalTraces.get(0));
// }
topSegmentJson.addProperty(SegmentCostTable.COLUMN_APPLICATION_ID, rs.getInt(SegmentCostTable.COLUMN_APPLICATION_ID));
topSegmentJson.addProperty(SegmentCostTable.COLUMN_SERVICE_NAME, rs.getString(SegmentCostTable.COLUMN_SERVICE_NAME));
topSegmentJson.addProperty(SegmentCostTable.COLUMN_COST, rs.getLong(SegmentCostTable.COLUMN_COST));
topSegmentJson.addProperty(SegmentCostTable.COLUMN_IS_ERROR, rs.getBoolean(SegmentCostTable.COLUMN_IS_ERROR));
num++;
topSegArray.add(topSegmentJson);
cnt++;
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
topSegPaging.addProperty("recordsTotal", cnt);
return topSegPaging;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.h2.dao;
import com.google.protobuf.InvalidProtocolBufferException;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.skywalking.apm.collector.storage.dao.ISegmentUIDAO;
import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.skywalking.apm.collector.storage.table.segment.SegmentTable;
import org.skywalking.apm.network.proto.TraceSegmentObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng, clevertension
*/
public class SegmentH2UIDAO extends H2DAO implements ISegmentUIDAO {
private final Logger logger = LoggerFactory.getLogger(SegmentH2UIDAO.class);
private static final String GET_SEGMENT_SQL = "select {0} from {1} where {2} = ?";
@Override public TraceSegmentObject load(String segmentId) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_SEGMENT_SQL, SegmentTable.COLUMN_DATA_BINARY,
SegmentTable.TABLE, SegmentTable.COLUMN_ID);
Object[] params = new Object[] {segmentId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
byte[] dataBinary = rs.getBytes(SegmentTable.COLUMN_DATA_BINARY);
try {
return TraceSegmentObject.parseFrom(dataBinary);
} catch (InvalidProtocolBufferException e) {
logger.error(e.getMessage(), e);
}
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return null;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.storage.h2.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.ColumnNameUtils;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.skywalking.apm.collector.storage.dao.IServiceEntryUIDAO;
import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.skywalking.apm.collector.storage.table.service.ServiceEntryTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class ServiceEntryH2UIDAO extends H2DAO implements IServiceEntryUIDAO {
private final Logger logger = LoggerFactory.getLogger(ServiceEntryH2UIDAO.class);
private static final String GET_SERVICE_ENTRY_SQL = "select * from {0} where {1} >= ? and {2} <= ?";
@Override public JsonObject load(int applicationId, String entryServiceName, long startTime, long endTime, int from,
int size) {
H2Client client = getClient();
String sql = GET_SERVICE_ENTRY_SQL;
List<Object> params = new ArrayList<>();
List<Object> columns = new ArrayList<>();
columns.add(ServiceEntryTable.TABLE);
columns.add(ServiceEntryTable.COLUMN_NEWEST_TIME);
columns.add(ServiceEntryTable.COLUMN_REGISTER_TIME);
params.add(startTime);
params.add(endTime);
int paramIndex = 2;
if (applicationId != 0) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} = ?";
params.add(applicationId);
columns.add(ServiceEntryTable.COLUMN_APPLICATION_ID);
}
if (StringUtils.isNotEmpty(entryServiceName)) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} = ?";
params.add(entryServiceName);
columns.add(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME);
}
sql = sql + " limit " + from + "," + size;
sql = SqlBuilder.buildSql(sql, columns);
Object[] p = params.toArray(new Object[0]);
JsonArray serviceArray = new JsonArray();
JsonObject response = new JsonObject();
int index = 0;
try (ResultSet rs = client.executeQuery(sql, p)) {
while (rs.next()) {
int appId = rs.getInt(ServiceEntryTable.COLUMN_APPLICATION_ID);
int entryServiceId = rs.getInt(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID);
String entryServiceName1 = rs.getString(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME);
JsonObject row = new JsonObject();
row.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID), entryServiceId);
row.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME), entryServiceName1);
row.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceEntryTable.COLUMN_APPLICATION_ID), appId);
serviceArray.add(row);
index++;
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
response.addProperty("total", index);
response.add("array", serviceArray);
return response;
}
}
......@@ -18,7 +18,7 @@
package org.skywalking.apm.collector.storage.h2.service;
import org.skywalking.apm.collector.storage.base.dao.DAO;
import org.skywalking.apm.collector.storage.base.dao.AbstractDAO;
import org.skywalking.apm.collector.storage.base.dao.DAOContainer;
import org.skywalking.apm.collector.storage.service.DAOService;
......@@ -33,7 +33,7 @@ public class H2DAOService implements DAOService {
this.daoContainer = daoContainer;
}
@Override public DAO get(Class<DAO> daoInterfaceClass) {
@Override public AbstractDAO get(Class<AbstractDAO> daoInterfaceClass) {
return daoContainer.get(daoInterfaceClass.getName());
}
}
......@@ -26,7 +26,7 @@ import org.skywalking.apm.collector.core.module.ServiceNotProvidedException;
import org.skywalking.apm.collector.queue.QueueModule;
import org.skywalking.apm.collector.queue.service.QueueCreatorService;
import org.skywalking.apm.collector.remote.RemoteModule;
import org.skywalking.apm.collector.remote.service.RemoteClientService;
import org.skywalking.apm.collector.remote.service.RemoteSenderService;
import org.skywalking.apm.collector.storage.StorageModule;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.skywalking.apm.collector.stream.timer.PersistenceTimer;
......@@ -51,7 +51,7 @@ public class StreamModuleProvider extends ModuleProvider {
PersistenceTimer persistenceTimer = new PersistenceTimer();
try {
QueueCreatorService queueCreatorService = getManager().find(QueueModule.NAME).getService(QueueCreatorService.class);
RemoteClientService remoteClientService = getManager().find(RemoteModule.NAME).getService(RemoteClientService.class);
RemoteSenderService remoteSenderService = getManager().find(RemoteModule.NAME).getService(RemoteSenderService.class);
DAOService daoService = getManager().find(StorageModule.NAME).getService(DAOService.class);
persistenceTimer.start(daoService);
} catch (ModuleNotFoundException e) {
......
......@@ -51,5 +51,10 @@
<artifactId>collector-naming-define</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>collector-storage-define</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -31,10 +31,24 @@ import org.skywalking.apm.collector.jetty.manager.service.JettyManagerService;
import org.skywalking.apm.collector.naming.NamingModule;
import org.skywalking.apm.collector.naming.service.NamingHandlerRegisterService;
import org.skywalking.apm.collector.server.Server;
import org.skywalking.apm.collector.storage.StorageModule;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.skywalking.apm.collector.ui.UIModule;
import org.skywalking.apm.collector.ui.jetty.handler.SegmentTopGetHandler;
import org.skywalking.apm.collector.ui.jetty.handler.SpanGetHandler;
import org.skywalking.apm.collector.ui.jetty.handler.TraceDagGetHandler;
import org.skywalking.apm.collector.ui.jetty.handler.TraceStackGetHandler;
import org.skywalking.apm.collector.ui.jetty.handler.application.ApplicationsGetHandler;
import org.skywalking.apm.collector.ui.jetty.handler.instancehealth.InstanceHealthGetHandler;
import org.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceMetricGetOneTimeBucketHandler;
import org.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceMetricGetRangeTimeBucketHandler;
import org.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceOsInfoGetHandler;
import org.skywalking.apm.collector.ui.jetty.handler.naming.UIJettyNamingHandler;
import org.skywalking.apm.collector.ui.jetty.handler.naming.UIJettyNamingListener;
import org.skywalking.apm.collector.ui.jetty.handler.servicetree.EntryServiceGetHandler;
import org.skywalking.apm.collector.ui.jetty.handler.servicetree.ServiceTreeGetByIdHandler;
import org.skywalking.apm.collector.ui.jetty.handler.time.AllInstanceLastTimeGetHandler;
import org.skywalking.apm.collector.ui.jetty.handler.time.OneInstanceLastTimeGetHandler;
/**
* @author peng-yongsheng
......@@ -62,10 +76,6 @@ public class UIModuleJettyProvider extends ModuleProvider {
Integer port = (Integer)config.get(PORT);
String contextPath = config.getProperty(CONTEXT_PATH);
try {
JettyManagerService managerService = getManager().find(JettyManagerModule.NAME).getService(JettyManagerService.class);
Server jettyServer = managerService.getOrCreateIfAbsent(host, port, contextPath);
jettyServer.addHandler(new ApplicationsGetHandler());
ModuleRegisterService moduleRegisterService = getManager().find(ClusterModule.NAME).getService(ModuleRegisterService.class);
moduleRegisterService.register(UIModule.NAME, this.name(), new UIModuleJettyRegistration(host, port, contextPath));
......@@ -75,6 +85,12 @@ public class UIModuleJettyProvider extends ModuleProvider {
NamingHandlerRegisterService namingHandlerRegisterService = getManager().find(NamingModule.NAME).getService(NamingHandlerRegisterService.class);
namingHandlerRegisterService.register(new UIJettyNamingHandler(namingListener));
DAOService daoService = getManager().find(StorageModule.NAME).getService(DAOService.class);
JettyManagerService managerService = getManager().find(JettyManagerModule.NAME).getService(JettyManagerService.class);
Server jettyServer = managerService.getOrCreateIfAbsent(host, port, contextPath);
addHandlers(daoService, jettyServer);
} catch (ModuleNotFoundException e) {
throw new ServiceNotProvidedException(e.getMessage());
}
......@@ -87,4 +103,20 @@ public class UIModuleJettyProvider extends ModuleProvider {
@Override public String[] requiredModules() {
return new String[] {ClusterModule.NAME, JettyManagerModule.NAME, NamingModule.NAME};
}
private void addHandlers(DAOService daoService, Server jettyServer) {
jettyServer.addHandler(new ApplicationsGetHandler(daoService));
jettyServer.addHandler(new InstanceHealthGetHandler(daoService));
jettyServer.addHandler(new InstanceMetricGetOneTimeBucketHandler(daoService));
jettyServer.addHandler(new InstanceMetricGetRangeTimeBucketHandler(daoService));
jettyServer.addHandler(new InstanceOsInfoGetHandler(daoService));
jettyServer.addHandler(new EntryServiceGetHandler(daoService));
jettyServer.addHandler(new ServiceTreeGetByIdHandler(daoService));
jettyServer.addHandler(new AllInstanceLastTimeGetHandler(daoService));
jettyServer.addHandler(new OneInstanceLastTimeGetHandler(daoService));
jettyServer.addHandler(new SegmentTopGetHandler(daoService));
jettyServer.addHandler(new SpanGetHandler(daoService));
jettyServer.addHandler(new TraceDagGetHandler(daoService));
jettyServer.addHandler(new TraceStackGetHandler(daoService));
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.ui.jetty.handler;
import com.google.gson.JsonElement;
import javax.servlet.http.HttpServletRequest;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.server.jetty.ArgumentsParseException;
import org.skywalking.apm.collector.server.jetty.JettyHandler;
import org.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.skywalking.apm.collector.ui.service.SegmentTopService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class SegmentTopGetHandler extends JettyHandler {
private final Logger logger = LoggerFactory.getLogger(SegmentTopGetHandler.class);
@Override public String pathSpec() {
return "/segment/top";
}
private final SegmentTopService service;
public SegmentTopGetHandler(DAOService daoService) {
this.service = new SegmentTopService(daoService);
}
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
if (!req.getParameterMap().containsKey("startTime") || !req.getParameterMap().containsKey("endTime") || !req.getParameterMap().containsKey("from") || !req.getParameterMap().containsKey("limit")) {
throw new ArgumentsParseException("the request parameter must contains startTime, endTime, from, limit");
}
if (logger.isDebugEnabled()) {
logger.debug("startTime: {}, endTime: {}, from: {}", req.getParameter("startTime"), req.getParameter("endTime"), req.getParameter("from"));
}
long startTime;
try {
startTime = Long.valueOf(req.getParameter("startTime"));
} catch (NumberFormatException e) {
throw new ArgumentsParseException("the request parameter startTime must be a long");
}
long endTime;
try {
endTime = Long.valueOf(req.getParameter("endTime"));
} catch (NumberFormatException e) {
throw new ArgumentsParseException("the request parameter endTime must be a long");
}
int from;
try {
from = Integer.valueOf(req.getParameter("from"));
} catch (NumberFormatException e) {
throw new ArgumentsParseException("the request parameter from must be an integer");
}
int limit;
try {
limit = Integer.valueOf(req.getParameter("limit"));
} catch (NumberFormatException e) {
throw new ArgumentsParseException("the request parameter from must be an integer");
}
int minCost = -1;
if (req.getParameterMap().containsKey("minCost")) {
minCost = Integer.valueOf(req.getParameter("minCost"));
}
int maxCost = -1;
if (req.getParameterMap().containsKey("maxCost")) {
maxCost = Integer.valueOf(req.getParameter("maxCost"));
}
String globalTraceId = null;
if (req.getParameterMap().containsKey("globalTraceId")) {
globalTraceId = req.getParameter("globalTraceId");
}
String operationName = null;
if (req.getParameterMap().containsKey("operationName")) {
operationName = req.getParameter("operationName");
}
int applicationId;
try {
applicationId = Integer.valueOf(req.getParameter("applicationId"));
} catch (NumberFormatException e) {
throw new ArgumentsParseException("the request parameter applicationId must be a int");
}
ISegmentCostUIDAO.Error error;
String errorStr = req.getParameter("error");
if (StringUtils.isNotEmpty(errorStr)) {
if ("true".equals(errorStr)) {
error = ISegmentCostUIDAO.Error.True;
} else if ("false".equals(errorStr)) {
error = ISegmentCostUIDAO.Error.False;
} else {
error = ISegmentCostUIDAO.Error.All;
}
} else {
error = ISegmentCostUIDAO.Error.All;
}
ISegmentCostUIDAO.Sort sort = ISegmentCostUIDAO.Sort.Cost;
if (req.getParameterMap().containsKey("sort")) {
String sortStr = req.getParameter("sort");
if (sortStr.toLowerCase().equals(ISegmentCostUIDAO.Sort.Time.name().toLowerCase())) {
sort = ISegmentCostUIDAO.Sort.Time;
}
}
return service.loadTop(startTime, endTime, minCost, maxCost, operationName, globalTraceId, error, applicationId, limit, from, sort);
}
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
throw new UnsupportedOperationException();
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.ui.jetty.handler;
import com.google.gson.JsonElement;
import javax.servlet.http.HttpServletRequest;
import org.skywalking.apm.collector.server.jetty.ArgumentsParseException;
import org.skywalking.apm.collector.server.jetty.JettyHandler;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.skywalking.apm.collector.ui.service.SpanService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class SpanGetHandler extends JettyHandler {
private final Logger logger = LoggerFactory.getLogger(SpanGetHandler.class);
@Override public String pathSpec() {
return "/span/spanId";
}
private final SpanService service;
public SpanGetHandler(DAOService daoService) {
this.service = new SpanService(daoService);
}
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
String segmentId = req.getParameter("segmentId");
String spanIdStr = req.getParameter("spanId");
logger.debug("segmentSpanId: {}, spanIdStr: {}", segmentId, spanIdStr);
int spanId;
try {
spanId = Integer.parseInt(spanIdStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("span id must be integer");
}
return service.load(segmentId, spanId);
}
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
throw new UnsupportedOperationException();
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.ui.jetty.handler;
import com.google.gson.JsonElement;
import javax.servlet.http.HttpServletRequest;
import org.skywalking.apm.collector.server.jetty.ArgumentsParseException;
import org.skywalking.apm.collector.server.jetty.JettyHandler;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.skywalking.apm.collector.ui.service.TraceDagService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class TraceDagGetHandler extends JettyHandler {
private final Logger logger = LoggerFactory.getLogger(TraceDagGetHandler.class);
@Override public String pathSpec() {
return "/traceDag";
}
private final TraceDagService service;
public TraceDagGetHandler(DAOService daoService) {
this.service = new TraceDagService(daoService);
}
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
if (!req.getParameterMap().containsKey("startTime") || !req.getParameterMap().containsKey("endTime")) {
throw new ArgumentsParseException("the request parameter must contains startTime, endTime");
}
String startTimeStr = req.getParameter("startTime");
String endTimeStr = req.getParameter("endTime");
logger.debug("startTime: {}, endTimeStr: {}", startTimeStr, endTimeStr);
long startTime;
try {
startTime = Long.valueOf(req.getParameter("startTime"));
} catch (NumberFormatException e) {
throw new ArgumentsParseException("the request parameter startTime must be a long");
}
long endTime;
try {
endTime = Long.valueOf(req.getParameter("endTime"));
} catch (NumberFormatException e) {
throw new ArgumentsParseException("the request parameter endTime must be a long");
}
return service.load(startTime, endTime);
}
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
throw new UnsupportedOperationException();
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.ui.jetty.handler;
import com.google.gson.JsonElement;
import javax.servlet.http.HttpServletRequest;
import org.skywalking.apm.collector.server.jetty.ArgumentsParseException;
import org.skywalking.apm.collector.server.jetty.JettyHandler;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.skywalking.apm.collector.ui.service.TraceStackService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class TraceStackGetHandler extends JettyHandler {
private final Logger logger = LoggerFactory.getLogger(TraceStackGetHandler.class);
@Override public String pathSpec() {
return "/traceStack/globalTraceId";
}
private final TraceStackService service;
public TraceStackGetHandler(DAOService daoService) {
this.service = new TraceStackService(daoService);
}
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
String globalTraceId = req.getParameter("globalTraceId");
logger.debug("globalTraceId: {}", globalTraceId);
return service.load(globalTraceId);
}
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
throw new UnsupportedOperationException();
}
}
......@@ -19,10 +19,11 @@
package org.skywalking.apm.collector.ui.jetty.handler.application;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import javax.servlet.http.HttpServletRequest;
import org.skywalking.apm.collector.server.jetty.ArgumentsParseException;
import org.skywalking.apm.collector.server.jetty.JettyHandler;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.skywalking.apm.collector.ui.service.ApplicationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -37,7 +38,11 @@ public class ApplicationsGetHandler extends JettyHandler {
return "/applications";
}
// private ApplicationService service = new ApplicationService();
private final ApplicationService applicationService;
public ApplicationsGetHandler(DAOService daoService) {
this.applicationService = new ApplicationService(daoService);
}
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
if (!req.getParameterMap().containsKey("startTime") || !req.getParameterMap().containsKey("endTime")) {
......@@ -62,11 +67,7 @@ public class ApplicationsGetHandler extends JettyHandler {
throw new ArgumentsParseException("end time must be long");
}
// return service.getApplications(startTime, endTime);
JsonObject result = new JsonObject();
result.addProperty("result", "Yes");
return result;
return applicationService.getApplications(startTime, endTime);
}
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
......
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.ui.jetty.handler.instancehealth;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import javax.servlet.http.HttpServletRequest;
import org.skywalking.apm.collector.server.jetty.ArgumentsParseException;
import org.skywalking.apm.collector.server.jetty.JettyHandler;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.skywalking.apm.collector.ui.service.InstanceHealthService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class InstanceHealthGetHandler extends JettyHandler {
private final Logger logger = LoggerFactory.getLogger(InstanceHealthGetHandler.class);
@Override public String pathSpec() {
return "/instance/health/applicationId";
}
private final InstanceHealthService service;
public InstanceHealthGetHandler(DAOService daoService) {
this.service = new InstanceHealthService(daoService);
}
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
String timeBucketStr = req.getParameter("timeBucket");
String[] applicationIdsStr = req.getParameterValues("applicationIds");
logger.debug("instance health get timeBucket: {}, applicationIdsStr: {}", timeBucketStr, applicationIdsStr);
long timeBucket;
try {
timeBucket = Long.parseLong(timeBucketStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("timestamp must be long");
}
int[] applicationIds = new int[applicationIdsStr.length];
for (int i = 0; i < applicationIdsStr.length; i++) {
try {
applicationIds[i] = Integer.parseInt(applicationIdsStr[i]);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("application id must be integer");
}
}
JsonObject response = new JsonObject();
response.addProperty("timeBucket", timeBucket);
JsonArray appInstances = new JsonArray();
response.add("appInstances", appInstances);
for (int applicationId : applicationIds) {
appInstances.add(service.getInstances(timeBucket, applicationId));
}
return response;
}
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
throw new UnsupportedOperationException();
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.ui.jetty.handler.instancemetric;
import com.google.gson.JsonElement;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.skywalking.apm.collector.server.jetty.ArgumentsParseException;
import org.skywalking.apm.collector.server.jetty.JettyHandler;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.skywalking.apm.collector.ui.service.InstanceJVMService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class InstanceMetricGetOneTimeBucketHandler extends JettyHandler {
private final Logger logger = LoggerFactory.getLogger(InstanceMetricGetOneTimeBucketHandler.class);
@Override public String pathSpec() {
return "/instance/jvm/instanceId/oneBucket";
}
private final InstanceJVMService service;
public InstanceMetricGetOneTimeBucketHandler(DAOService daoService) {
this.service = new InstanceJVMService(daoService);
}
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
String timeBucketStr = req.getParameter("timeBucket");
String instanceIdStr = req.getParameter("instanceId");
String[] metricTypes = req.getParameterValues("metricTypes");
logger.debug("instance jvm metric get timeBucket: {}, instance id: {}, metric types: {}", timeBucketStr, instanceIdStr, metricTypes);
long timeBucket;
try {
timeBucket = Long.parseLong(timeBucketStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("timeBucket must be long");
}
int instanceId;
try {
instanceId = Integer.parseInt(instanceIdStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("instance id must be integer");
}
if (metricTypes.length == 0) {
throw new ArgumentsParseException("at least one metric type");
}
Set<String> metricTypeSet = new LinkedHashSet<>();
for (String metricType : metricTypes) {
metricTypeSet.add(metricType);
}
return service.getInstanceJvmMetric(instanceId, metricTypeSet, timeBucket);
}
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
throw new UnsupportedOperationException();
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.ui.jetty.handler.instancemetric;
import com.google.gson.JsonElement;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.skywalking.apm.collector.server.jetty.ArgumentsParseException;
import org.skywalking.apm.collector.server.jetty.JettyHandler;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.skywalking.apm.collector.ui.service.InstanceJVMService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class InstanceMetricGetRangeTimeBucketHandler extends JettyHandler {
private final Logger logger = LoggerFactory.getLogger(InstanceMetricGetRangeTimeBucketHandler.class);
@Override public String pathSpec() {
return "/instance/jvm/instanceId/rangeBucket";
}
private final InstanceJVMService service;
public InstanceMetricGetRangeTimeBucketHandler(DAOService daoService) {
this.service = new InstanceJVMService(daoService);
}
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
String startTimeBucketStr = req.getParameter("startTimeBucket");
String endTimeBucketStr = req.getParameter("endTimeBucket");
String instanceIdStr = req.getParameter("instanceId");
String[] metricTypes = req.getParameterValues("metricTypes");
logger.debug("instance jvm metric get start timeBucket: {}, end timeBucket:{} , instance id: {}, metric types: {}", startTimeBucketStr, endTimeBucketStr, instanceIdStr, metricTypes);
long startTimeBucket;
try {
startTimeBucket = Long.parseLong(startTimeBucketStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("start timeBucket must be long");
}
long endTimeBucket;
try {
endTimeBucket = Long.parseLong(endTimeBucketStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("end timeBucket must be long");
}
int instanceId;
try {
instanceId = Integer.parseInt(instanceIdStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("instance id must be integer");
}
if (metricTypes.length == 0) {
throw new ArgumentsParseException("at least one metric type");
}
Set<String> metricTypeSet = new LinkedHashSet<>();
for (String metricType : metricTypes) {
metricTypeSet.add(metricType);
}
return service.getInstanceJvmMetrics(instanceId, metricTypeSet, startTimeBucket, endTimeBucket);
}
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
throw new UnsupportedOperationException();
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.ui.jetty.handler.instancemetric;
import com.google.gson.JsonElement;
import javax.servlet.http.HttpServletRequest;
import org.skywalking.apm.collector.server.jetty.ArgumentsParseException;
import org.skywalking.apm.collector.server.jetty.JettyHandler;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.skywalking.apm.collector.ui.service.InstanceJVMService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class InstanceOsInfoGetHandler extends JettyHandler {
private final Logger logger = LoggerFactory.getLogger(InstanceOsInfoGetHandler.class);
@Override public String pathSpec() {
return "/instance/os/instanceId";
}
private final InstanceJVMService service;
public InstanceOsInfoGetHandler(DAOService daoService) {
this.service = new InstanceJVMService(daoService);
}
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
String instanceIdStr = req.getParameter("instanceId");
logger.debug("instance os info get, instance id: {}", instanceIdStr);
int instanceId;
try {
instanceId = Integer.parseInt(instanceIdStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("instance id must be integer");
}
return service.getInstanceOsInfo(instanceId);
}
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
throw new UnsupportedOperationException();
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.ui.jetty.handler.servicetree;
import com.google.gson.JsonElement;
import javax.servlet.http.HttpServletRequest;
import org.skywalking.apm.collector.server.jetty.ArgumentsParseException;
import org.skywalking.apm.collector.server.jetty.JettyHandler;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.skywalking.apm.collector.ui.service.ServiceTreeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class EntryServiceGetHandler extends JettyHandler {
private final Logger logger = LoggerFactory.getLogger(EntryServiceGetHandler.class);
@Override public String pathSpec() {
return "/service/entry";
}
private final ServiceTreeService service;
public EntryServiceGetHandler(DAOService daoService) {
this.service = new ServiceTreeService(daoService);
}
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
if (!req.getParameterMap().containsKey("applicationId") || !req.getParameterMap().containsKey("entryServiceName")
|| !req.getParameterMap().containsKey("startTime") || !req.getParameterMap().containsKey("endTime")
|| !req.getParameterMap().containsKey("from") || !req.getParameterMap().containsKey("size")) {
throw new ArgumentsParseException("must contains parameters: applicationId, entryServiceName, startTime, endTime, from, size");
}
String applicationIdStr = req.getParameter("applicationId");
String entryServiceName = req.getParameter("entryServiceName");
String startTimeStr = req.getParameter("startTime");
String endTimeStr = req.getParameter("endTime");
String fromStr = req.getParameter("from");
String sizeStr = req.getParameter("size");
logger.debug("service entry get applicationId: {}, entryServiceName: {}, startTime: {}, endTime: {}, from: {}, size: {}", applicationIdStr, entryServiceName, startTimeStr, endTimeStr, fromStr, sizeStr);
int applicationId;
try {
applicationId = Integer.parseInt(applicationIdStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("application id must be integer");
}
long startTime;
try {
startTime = Long.parseLong(startTimeStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("start time must be long");
}
long endTime;
try {
endTime = Long.parseLong(endTimeStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("end time must be long");
}
int from;
try {
from = Integer.parseInt(fromStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("from must be integer");
}
int size;
try {
size = Integer.parseInt(sizeStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("size must be integer");
}
return service.loadEntryService(applicationId, entryServiceName, startTime, endTime, from, size);
}
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
throw new UnsupportedOperationException();
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.ui.jetty.handler.servicetree;
import com.google.gson.JsonElement;
import javax.servlet.http.HttpServletRequest;
import org.skywalking.apm.collector.server.jetty.ArgumentsParseException;
import org.skywalking.apm.collector.server.jetty.JettyHandler;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.skywalking.apm.collector.ui.service.ServiceTreeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class ServiceTreeGetByIdHandler extends JettyHandler {
private final Logger logger = LoggerFactory.getLogger(ServiceTreeGetByIdHandler.class);
@Override public String pathSpec() {
return "/service/tree/entryServiceId";
}
private final ServiceTreeService service;
public ServiceTreeGetByIdHandler(DAOService daoService) {
this.service = new ServiceTreeService(daoService);
}
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
if (!req.getParameterMap().containsKey("entryServiceId") || !req.getParameterMap().containsKey("startTime") || !req.getParameterMap().containsKey("endTime")) {
throw new ArgumentsParseException("must contains parameters: entryServiceId, startTime, endTime");
}
String entryServiceIdStr = req.getParameter("entryServiceId");
String startTimeStr = req.getParameter("startTime");
String endTimeStr = req.getParameter("endTime");
logger.debug("service entry get entryServiceId: {}, startTime: {}, endTime: {}", entryServiceIdStr, startTimeStr, endTimeStr);
int entryServiceId;
try {
entryServiceId = Integer.parseInt(entryServiceIdStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("entry service id must be integer");
}
long startTime;
try {
startTime = Long.parseLong(startTimeStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("start time must be long");
}
long endTime;
try {
endTime = Long.parseLong(endTimeStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("end time must be long");
}
return service.loadServiceTree(entryServiceId, startTime, endTime);
}
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
throw new UnsupportedOperationException();
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.ui.jetty.handler.time;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.Calendar;
import javax.servlet.http.HttpServletRequest;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.server.jetty.ArgumentsParseException;
import org.skywalking.apm.collector.server.jetty.JettyHandler;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.skywalking.apm.collector.ui.service.TimeSynchronousService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class AllInstanceLastTimeGetHandler extends JettyHandler {
private final Logger logger = LoggerFactory.getLogger(AllInstanceLastTimeGetHandler.class);
@Override public String pathSpec() {
return "/time/allInstance";
}
private final TimeSynchronousService service;
public AllInstanceLastTimeGetHandler(DAOService daoService) {
this.service = new TimeSynchronousService(daoService);
}
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
Long timeBucket = service.allInstanceLastTime();
logger.debug("all instance last time: {}", timeBucket);
if (timeBucket == 0) {
timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(System.currentTimeMillis());
}
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(TimeBucketUtils.INSTANCE.changeTimeBucket2TimeStamp(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket));
calendar.add(Calendar.SECOND, -5);
timeBucket = calendar.getTimeInMillis();
JsonObject timeJson = new JsonObject();
timeJson.addProperty("timeBucket", TimeBucketUtils.INSTANCE.getSecondTimeBucket(timeBucket));
return timeJson;
}
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
throw new UnsupportedOperationException();
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.ui.jetty.handler.time;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import javax.servlet.http.HttpServletRequest;
import org.skywalking.apm.collector.server.jetty.ArgumentsParseException;
import org.skywalking.apm.collector.server.jetty.JettyHandler;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.skywalking.apm.collector.ui.service.TimeSynchronousService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class OneInstanceLastTimeGetHandler extends JettyHandler {
private final Logger logger = LoggerFactory.getLogger(OneInstanceLastTimeGetHandler.class);
@Override public String pathSpec() {
return "/time/oneInstance";
}
private final TimeSynchronousService service;
public OneInstanceLastTimeGetHandler(DAOService daoService) {
this.service = new TimeSynchronousService(daoService);
}
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
String instanceIdStr = req.getParameter("instanceId");
logger.debug("instanceId: {}", instanceIdStr);
int instanceId;
try {
instanceId = Integer.parseInt(instanceIdStr);
} catch (NumberFormatException e) {
throw new ArgumentsParseException("application instance id must be integer");
}
Long time = service.instanceLastTime(instanceId);
logger.debug("application instance id: {}, instance last time: {}", instanceId, time);
JsonObject timeJson = new JsonObject();
timeJson.addProperty("timeBucket", time);
return timeJson;
}
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
throw new UnsupportedOperationException();
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.ui.service;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.skywalking.apm.collector.cache.ApplicationCache;
import org.skywalking.apm.collector.storage.dao.IInstanceUIDAO;
import org.skywalking.apm.collector.storage.service.DAOService;
/**
* @author peng-yongsheng
*/
public class ApplicationService {
private final DAOService daoService;
public ApplicationService(DAOService daoService) {
this.daoService = daoService;
}
public JsonArray getApplications(long startTime, long endTime) {
IInstanceUIDAO instanceDAO = (IInstanceUIDAO)daoService.get(IInstanceUIDAO.class);
JsonArray applications = instanceDAO.getApplications(startTime, endTime);
applications.forEach(jsonElement -> {
JsonObject application = jsonElement.getAsJsonObject();
int applicationId = application.get("applicationId").getAsInt();
String applicationCode = ApplicationCache.get(applicationId);
application.addProperty("applicationCode", applicationCode);
});
return applications;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.ui.service;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.List;
import org.skywalking.apm.collector.cache.ApplicationCache;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.dao.IGCMetricUIDAO;
import org.skywalking.apm.collector.storage.dao.IInstPerformanceUIDAO;
import org.skywalking.apm.collector.storage.dao.IInstanceUIDAO;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.skywalking.apm.collector.storage.table.register.Instance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class InstanceHealthService {
private final Logger logger = LoggerFactory.getLogger(InstanceHealthService.class);
private final DAOService daoService;
public InstanceHealthService(DAOService daoService) {
this.daoService = daoService;
}
public JsonObject getInstances(long timeBucket, int applicationId) {
JsonObject response = new JsonObject();
long[] timeBuckets = TimeBucketUtils.INSTANCE.getFiveSecondTimeBuckets(timeBucket);
long halfHourBeforeTimeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, -60 * 30);
IInstanceUIDAO instanceDAO = (IInstanceUIDAO)daoService.get(IInstanceUIDAO.class);
List<Instance> instanceList = instanceDAO.getInstances(applicationId, halfHourBeforeTimeBucket);
JsonArray instances = new JsonArray();
response.add("instances", instances);
instanceList.forEach(instance -> {
response.addProperty("applicationCode", ApplicationCache.get(applicationId));
response.addProperty("applicationId", applicationId);
IInstPerformanceUIDAO instPerformanceDAO = (IInstPerformanceUIDAO)daoService.get(IInstPerformanceUIDAO.class);
IInstPerformanceUIDAO.InstPerformance performance = instPerformanceDAO.get(timeBuckets, instance.getInstanceId());
IGCMetricUIDAO gcMetricDAO = (IGCMetricUIDAO)daoService.get(IGCMetricUIDAO.class);
JsonObject instanceJson = new JsonObject();
instanceJson.addProperty("id", instance.getInstanceId());
if (performance != null) {
instanceJson.addProperty("tps", performance.getCalls());
} else {
instanceJson.addProperty("tps", 0);
}
int avg = 0;
if (performance != null && performance.getCalls() != 0) {
avg = (int)(performance.getCostTotal() / performance.getCalls());
}
instanceJson.addProperty("avg", avg);
if (avg > 5000) {
instanceJson.addProperty("healthLevel", 0);
} else if (avg > 3000 && avg <= 5000) {
instanceJson.addProperty("healthLevel", 1);
} else if (avg > 1000 && avg <= 3000) {
instanceJson.addProperty("healthLevel", 2);
} else {
instanceJson.addProperty("healthLevel", 3);
}
long heartBeatTime = TimeBucketUtils.INSTANCE.changeTimeBucket2TimeStamp(TimeBucketUtils.TimeBucketType.SECOND.name(), instance.getHeartBeatTime());
long currentTime = TimeBucketUtils.INSTANCE.changeTimeBucket2TimeStamp(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket);
if (currentTime - heartBeatTime < 1000 * 60 * 2) {
instanceJson.addProperty("status", 0);
} else {
instanceJson.addProperty("status", 1);
}
IGCMetricUIDAO.GCCount gcCount = gcMetricDAO.getGCCount(timeBuckets, instance.getInstanceId());
instanceJson.addProperty("ygc", gcCount.getYoung());
instanceJson.addProperty("ogc", gcCount.getOld());
instances.add(instanceJson);
});
return response;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.ui.service;
import com.google.gson.JsonObject;
import java.util.LinkedList;
import java.util.List;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO;
import org.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class SegmentTopService {
private final Logger logger = LoggerFactory.getLogger(SegmentTopService.class);
private final DAOService daoService;
public SegmentTopService(DAOService daoService) {
this.daoService = daoService;
}
public JsonObject loadTop(long startTime, long endTime, long minCost, long maxCost, String operationName,
String globalTraceId, ISegmentCostUIDAO.Error error, int applicationId, int limit, int from,
ISegmentCostUIDAO.Sort sort) {
logger.debug("startTime: {}, endTime: {}, minCost: {}, maxCost: {}, operationName: {}, globalTraceId: {}, error: {}, applicationId: {}, limit: {}, from: {}", startTime, endTime, minCost, maxCost, operationName, globalTraceId, error, applicationId, limit, from);
List<String> segmentIds = new LinkedList<>();
if (StringUtils.isNotEmpty(globalTraceId)) {
IGlobalTraceUIDAO globalTraceDAO = (IGlobalTraceUIDAO)daoService.get(IGlobalTraceUIDAO.class);
segmentIds = globalTraceDAO.getSegmentIds(globalTraceId);
}
ISegmentCostUIDAO segmentCostDAO = (ISegmentCostUIDAO)daoService.get(ISegmentCostUIDAO.class);
return segmentCostDAO.loadTop(startTime, endTime, minCost, maxCost, operationName, error, applicationId, segmentIds, limit, from, sort);
}
}
......@@ -22,5 +22,10 @@
<artifactId>apm-collector-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>apm-collector-cache</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册