use of com.alibaba.druid.admin.model.ServiceNode in project druid by alibaba.
the class MonitorStatService method getPoolingConnectionInfoByDataSourceId.
public String getPoolingConnectionInfoByDataSourceId(Integer id, String serviceId) {
getAllServiceNodeMap();
ServiceNode serviceNode = serviceIdMap.get(serviceId);
String url = "http://" + serviceNode.getAddress() + ":" + serviceNode.getPort() + "/druid/connectionInfo-" + id + ".json";
ConnectionResult connectionResult = HttpUtil.get(url, ConnectionResult.class);
return JSON.toJSONString(connectionResult);
}
use of com.alibaba.druid.admin.model.ServiceNode in project druid by alibaba.
the class MonitorStatService method getSqlStat.
/**
* 获取sql详情
*
* @param id
* @param serviceId consul获取的服务id
* @return
*/
private String getSqlStat(Integer id, String serviceId) {
log.info("serviceId:{}", serviceId);
ServiceNode serviceNode = serviceIdMap.get(serviceId);
String url = "http://" + serviceNode.getAddress() + ":" + serviceNode.getPort() + "/druid/sql-" + id + ".json";
SqlDetailResult sqlDetailResult = HttpUtil.get(url, SqlDetailResult.class);
return JSON.toJSONString(sqlDetailResult);
}
use of com.alibaba.druid.admin.model.ServiceNode in project druid by alibaba.
the class MonitorStatService method getAllServiceNodeMap.
/**
* 获取所有服务信息
*
* @return
*/
public Map<String, ServiceNode> getAllServiceNodeMap() {
List<String> services = discoveryClient.getServices();
List<ServiceNode> serviceNodes = new ArrayList<>();
for (String service : services) {
List<ServiceInstance> instances = discoveryClient.getInstances(service);
for (ServiceInstance instance : instances) {
String host = instance.getHost();
String instanceId = instance.getInstanceId();
if (instanceId == null) {
instanceId = instance.getMetadata().get("nacos.instanceId").replaceAll("#", "-").replaceAll("@@", "-");
}
int port = instance.getPort();
String serviceId = instance.getServiceId();
// 根据前端参数采集指定的服务
if (monitorProperties.getApplications().contains(serviceId)) {
ServiceNode serviceNode = new ServiceNode();
serviceNode.setId(instanceId);
serviceNode.setPort(port);
serviceNode.setAddress(host);
serviceNode.setServiceName(serviceId);
serviceNodes.add(serviceNode);
serviceIdMap.put(instanceId, serviceNode);
}
}
}
return serviceNodes.parallelStream().collect(Collectors.toMap(i -> i.getServiceName() + "-" + i.getAddress() + "-" + i.getPort(), Function.identity(), (v1, v2) -> v2));
}
use of com.alibaba.druid.admin.model.ServiceNode in project druid by alibaba.
the class MonitorStatService method getServiceAllNodeMap.
/**
* 获取指定服务名的所有节点
*
* @param parameters
* @return
*/
public Map<String, ServiceNode> getServiceAllNodeMap(Map<String, String> parameters) {
String requestServiceName = parameters.get("serviceName");
List<String> services = discoveryClient.getServices();
List<ServiceNode> serviceNodes = new ArrayList<>();
for (String service : services) {
List<ServiceInstance> instances = discoveryClient.getInstances(service);
for (ServiceInstance instance : instances) {
String host = instance.getHost();
String instanceId = instance.getInstanceId();
if (instanceId == null) {
instanceId = instance.getMetadata().get("nacos.instanceId").replaceAll("#", "-").replaceAll("@@", "-");
}
int port = instance.getPort();
String serviceId = instance.getServiceId();
// 根据前端参数采集指定的服务
if (serviceId.equalsIgnoreCase(requestServiceName)) {
ServiceNode serviceNode = new ServiceNode();
serviceNode.setId(instanceId);
serviceNode.setPort(port);
serviceNode.setAddress(host);
serviceNode.setServiceName(serviceId);
serviceNodes.add(serviceNode);
serviceIdMap.put(instanceId, serviceNode);
}
}
}
return serviceNodes.parallelStream().collect(Collectors.toMap(i -> i.getServiceName() + "-" + i.getAddress() + "-" + i.getPort(), Function.identity(), (v1, v2) -> v2));
}
use of com.alibaba.druid.admin.model.ServiceNode in project druid by alibaba.
the class MonitorStatService method getWebURIStatDataList.
@SuppressWarnings("unchecked")
private String getWebURIStatDataList(Map<String, String> parameters) {
Map<String, ServiceNode> allNodeMap = getServiceAllNodeMap(parameters);
List<Map<String, Object>> arrayMap = new ArrayList<>();
for (String nodeKey : allNodeMap.keySet()) {
ServiceNode serviceNode = allNodeMap.get(nodeKey);
String url = getRequestUrl(parameters, serviceNode, "/druid/weburi.json");
WebResult dataSourceResult = HttpUtil.get(url, WebResult.class);
if (dataSourceResult != null) {
List<WebResult.ContentBean> nodeContent = dataSourceResult.getContent();
if (nodeContent != null) {
for (WebResult.ContentBean contentBean : nodeContent) {
Map<String, Object> map = JSONObject.parseObject(JSONObject.toJSONString(contentBean), Map.class);
arrayMap.add(map);
}
}
}
}
List<Map<String, Object>> maps = comparatorOrderBy(arrayMap, parameters);
String jsonString = JSON.toJSONString(maps);
JSONArray objects = JSON.parseArray(jsonString);
JSONObject jsonObject = new JSONObject();
jsonObject.put("ResultCode", RESULT_CODE_SUCCESS);
jsonObject.put("Content", objects);
return jsonObject.toJSONString();
}
Aggregations