no message
This commit is contained in:
parent
c1c7d9b8a5
commit
a6d9111d7c
|
|
@ -1,6 +1,7 @@
|
|||
package org.skywalking.apm.collector.ui.dao;
|
||||
|
||||
import java.util.List;
|
||||
import org.skywalking.apm.collector.storage.table.instance.Instance;
|
||||
|
||||
/**
|
||||
* @author pengys5
|
||||
|
|
@ -12,6 +13,8 @@ public interface IInstanceDAO {
|
|||
|
||||
List<Application> getApplications(long time);
|
||||
|
||||
Instance getInstance(int instanceId);
|
||||
|
||||
class Application {
|
||||
private final int applicationId;
|
||||
private final long count;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package org.skywalking.apm.collector.ui.dao;
|
|||
|
||||
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;
|
||||
|
|
@ -16,6 +18,7 @@ import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
|||
import org.elasticsearch.search.sort.SortBuilders;
|
||||
import org.elasticsearch.search.sort.SortMode;
|
||||
import org.skywalking.apm.collector.storage.elasticsearch.dao.EsDAO;
|
||||
import org.skywalking.apm.collector.storage.table.instance.Instance;
|
||||
import org.skywalking.apm.collector.storage.table.register.InstanceTable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -93,4 +96,21 @@ public class InstanceEsDAO extends EsDAO implements IInstanceDAO {
|
|||
}
|
||||
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();
|
||||
instance.setId(String.valueOf(instanceId));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package org.skywalking.apm.collector.ui.dao;
|
|||
|
||||
import java.util.List;
|
||||
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
|
||||
import org.skywalking.apm.collector.storage.table.instance.Instance;
|
||||
|
||||
/**
|
||||
* @author pengys5
|
||||
|
|
@ -18,4 +19,8 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
|
|||
@Override public List<Application> getApplications(long time) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public Instance getInstance(int instanceId) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
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.ui.service.InstanceHealthService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author pengys5
|
||||
*/
|
||||
public class InstanceMetricGetHandler extends JettyHandler {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(InstanceMetricGetHandler.class);
|
||||
|
||||
@Override public String pathSpec() {
|
||||
return "/instance/jvm/instanceId";
|
||||
}
|
||||
|
||||
private InstanceHealthService service = new InstanceHealthService();
|
||||
|
||||
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
|
||||
String timestampStr = req.getParameter("timestamp");
|
||||
String applicationIdStr = req.getParameter("applicationId");
|
||||
logger.debug("instance health get timestamp: {}", timestampStr);
|
||||
|
||||
long timestamp;
|
||||
try {
|
||||
timestamp = Long.parseLong(timestampStr);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ArgumentsParseException("timestamp must be long");
|
||||
}
|
||||
|
||||
int applicationId;
|
||||
try {
|
||||
applicationId = Integer.parseInt(applicationIdStr);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ArgumentsParseException("application id must be integer");
|
||||
}
|
||||
|
||||
return service.getInstances(timestamp, applicationId);
|
||||
}
|
||||
|
||||
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
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.ui.service.InstanceJVMService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author pengys5
|
||||
*/
|
||||
public class InstanceOsInfoGetHandler extends JettyHandler {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(InstanceOsInfoGetHandler.class);
|
||||
|
||||
@Override public String pathSpec() {
|
||||
return "/instance/os/instanceId";
|
||||
}
|
||||
|
||||
private InstanceJVMService service = new InstanceJVMService();
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package org.skywalking.apm.collector.ui.service;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.skywalking.apm.collector.core.framework.UnexpectedException;
|
||||
import org.skywalking.apm.collector.core.util.ObjectUtils;
|
||||
import org.skywalking.apm.collector.storage.dao.DAOContainer;
|
||||
import org.skywalking.apm.collector.storage.table.instance.Instance;
|
||||
import org.skywalking.apm.collector.ui.dao.IInstanceDAO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author pengys5
|
||||
*/
|
||||
public class InstanceJVMService {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(InstanceJVMService.class);
|
||||
|
||||
private Gson gson = new Gson();
|
||||
|
||||
public JsonObject getInstanceOsInfo(int instanceId) {
|
||||
IInstanceDAO instanceDAO = (IInstanceDAO)DAOContainer.INSTANCE.get(IInstanceDAO.class.getName());
|
||||
Instance instance = instanceDAO.getInstance(instanceId);
|
||||
if (ObjectUtils.isEmpty(instance)) {
|
||||
throw new UnexpectedException("instance id: " + instance + " not exist.");
|
||||
}
|
||||
|
||||
JsonObject response = gson.fromJson(instance.getOsInfo(), JsonObject.class);
|
||||
return response;
|
||||
}
|
||||
|
||||
public JsonObject getInstanceJvmMetric(int instanceId, String metricType) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public enum MetricType {
|
||||
cpu, gc, tps, heapmemory, heappermgen, heapmetaspace, heapnewgen,
|
||||
heapoldgen, heapsurvivor, nonheap, memory, nonheappermgen, nonheapmetaspace,
|
||||
nonheapnewgen, nonheapoldgen, nonheapsurvivor
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue