Search in sources :

Example 1 with ServiceNode

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);
}
Also used : ServiceNode(com.alibaba.druid.admin.model.ServiceNode) ConnectionResult(com.alibaba.druid.admin.model.dto.ConnectionResult)

Example 2 with ServiceNode

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);
}
Also used : ServiceNode(com.alibaba.druid.admin.model.ServiceNode) SqlDetailResult(com.alibaba.druid.admin.model.dto.SqlDetailResult)

Example 3 with ServiceNode

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));
}
Also used : JSONUtils(com.alibaba.druid.support.json.JSONUtils) HttpUtil(com.alibaba.druid.admin.util.HttpUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) DiscoveryClient(org.springframework.cloud.client.discovery.DiscoveryClient) HashMap(java.util.HashMap) Function(java.util.function.Function) SqlListResult(com.alibaba.druid.admin.model.dto.SqlListResult) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ServiceNode(com.alibaba.druid.admin.model.ServiceNode) JSONArray(com.alibaba.fastjson.JSONArray) MonitorProperties(com.alibaba.druid.admin.config.MonitorProperties) WebResult(com.alibaba.druid.admin.model.dto.WebResult) Map(java.util.Map) ConnectionResult(com.alibaba.druid.admin.model.dto.ConnectionResult) SpringStatManager(com.alibaba.druid.support.spring.stat.SpringStatManager) StringUtils(com.alibaba.druid.util.StringUtils) Collectors(java.util.stream.Collectors) SqlDetailResult(com.alibaba.druid.admin.model.dto.SqlDetailResult) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) JSON(com.alibaba.fastjson.JSON) MapComparator(com.alibaba.druid.util.MapComparator) DruidStatServiceMBean(com.alibaba.druid.stat.DruidStatServiceMBean) WebAppStatManager(com.alibaba.druid.support.http.stat.WebAppStatManager) WallResult(com.alibaba.druid.admin.model.dto.WallResult) JSONObject(com.alibaba.fastjson.JSONObject) ServiceInstance(org.springframework.cloud.client.ServiceInstance) DataSourceResult(com.alibaba.druid.admin.model.dto.DataSourceResult) Collections(java.util.Collections) ServiceNode(com.alibaba.druid.admin.model.ServiceNode) ArrayList(java.util.ArrayList) ServiceInstance(org.springframework.cloud.client.ServiceInstance)

Example 4 with ServiceNode

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));
}
Also used : JSONUtils(com.alibaba.druid.support.json.JSONUtils) HttpUtil(com.alibaba.druid.admin.util.HttpUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) DiscoveryClient(org.springframework.cloud.client.discovery.DiscoveryClient) HashMap(java.util.HashMap) Function(java.util.function.Function) SqlListResult(com.alibaba.druid.admin.model.dto.SqlListResult) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ServiceNode(com.alibaba.druid.admin.model.ServiceNode) JSONArray(com.alibaba.fastjson.JSONArray) MonitorProperties(com.alibaba.druid.admin.config.MonitorProperties) WebResult(com.alibaba.druid.admin.model.dto.WebResult) Map(java.util.Map) ConnectionResult(com.alibaba.druid.admin.model.dto.ConnectionResult) SpringStatManager(com.alibaba.druid.support.spring.stat.SpringStatManager) StringUtils(com.alibaba.druid.util.StringUtils) Collectors(java.util.stream.Collectors) SqlDetailResult(com.alibaba.druid.admin.model.dto.SqlDetailResult) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) JSON(com.alibaba.fastjson.JSON) MapComparator(com.alibaba.druid.util.MapComparator) DruidStatServiceMBean(com.alibaba.druid.stat.DruidStatServiceMBean) WebAppStatManager(com.alibaba.druid.support.http.stat.WebAppStatManager) WallResult(com.alibaba.druid.admin.model.dto.WallResult) JSONObject(com.alibaba.fastjson.JSONObject) ServiceInstance(org.springframework.cloud.client.ServiceInstance) DataSourceResult(com.alibaba.druid.admin.model.dto.DataSourceResult) Collections(java.util.Collections) ServiceNode(com.alibaba.druid.admin.model.ServiceNode) ArrayList(java.util.ArrayList) ServiceInstance(org.springframework.cloud.client.ServiceInstance)

Example 5 with ServiceNode

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();
}
Also used : ServiceNode(com.alibaba.druid.admin.model.ServiceNode) ArrayList(java.util.ArrayList) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) WebResult(com.alibaba.druid.admin.model.dto.WebResult) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

ServiceNode (com.alibaba.druid.admin.model.ServiceNode)8 ArrayList (java.util.ArrayList)6 JSONArray (com.alibaba.fastjson.JSONArray)4 JSONObject (com.alibaba.fastjson.JSONObject)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 ConnectionResult (com.alibaba.druid.admin.model.dto.ConnectionResult)3 DataSourceResult (com.alibaba.druid.admin.model.dto.DataSourceResult)3 SqlDetailResult (com.alibaba.druid.admin.model.dto.SqlDetailResult)3 SqlListResult (com.alibaba.druid.admin.model.dto.SqlListResult)3 WallResult (com.alibaba.druid.admin.model.dto.WallResult)3 WebResult (com.alibaba.druid.admin.model.dto.WebResult)3 MonitorProperties (com.alibaba.druid.admin.config.MonitorProperties)2 HttpUtil (com.alibaba.druid.admin.util.HttpUtil)2 DruidStatServiceMBean (com.alibaba.druid.stat.DruidStatServiceMBean)2 WebAppStatManager (com.alibaba.druid.support.http.stat.WebAppStatManager)2 JSONUtils (com.alibaba.druid.support.json.JSONUtils)2 SpringStatManager (com.alibaba.druid.support.spring.stat.SpringStatManager)2 MapComparator (com.alibaba.druid.util.MapComparator)2