Search in sources :

Example 6 with ServiceNode

use of com.alibaba.druid.admin.model.ServiceNode in project druid by alibaba.

the class MonitorStatService method getWallStatMap.

public String getWallStatMap(Map<String, String> parameters) {
    Map<String, ServiceNode> allNodeMap = getServiceAllNodeMap(parameters);
    List<WallResult> countResult = new ArrayList<>();
    for (String nodeKey : allNodeMap.keySet()) {
        ServiceNode serviceNode = allNodeMap.get(nodeKey);
        String url = getRequestUrl(parameters, serviceNode, "/druid/wall.json");
        WallResult wallResult = HttpUtil.get(url, WallResult.class);
        countResult.add(wallResult);
    }
    WallResult lastCount = new WallResult();
    for (WallResult wallResult : countResult) {
        lastCount.sum(wallResult, lastCount);
    }
    return JSON.toJSONString(lastCount);
}
Also used : ServiceNode(com.alibaba.druid.admin.model.ServiceNode) WallResult(com.alibaba.druid.admin.model.dto.WallResult) ArrayList(java.util.ArrayList)

Example 7 with ServiceNode

use of com.alibaba.druid.admin.model.ServiceNode in project druid by alibaba.

the class MonitorStatService method getSqlStatDataList.

/**
 * SQL监控列表
 *
 * @param parameters
 * @return
 */
@SuppressWarnings("unchecked")
public String getSqlStatDataList(Map<String, String> parameters) {
    Map<String, ServiceNode> serviceAllNodeMap = getServiceAllNodeMap(parameters);
    List<Map<String, Object>> arrayMap = new ArrayList<>();
    for (String nodeKey : serviceAllNodeMap.keySet()) {
        ServiceNode serviceNode = serviceAllNodeMap.get(nodeKey);
        String serviceName = serviceNode.getServiceName();
        String url = getRequestUrl(parameters, serviceNode, "/druid/sql.json");
        SqlListResult sqlListResult = HttpUtil.get(url, SqlListResult.class);
        if (sqlListResult != null) {
            List<SqlListResult.ContentBean> nodeContent = sqlListResult.getContent();
            if (nodeContent != null) {
                for (SqlListResult.ContentBean contentBean : nodeContent) {
                    contentBean.setName(serviceName);
                    contentBean.setAddress(serviceNode.getAddress());
                    contentBean.setPort(serviceNode.getPort());
                    contentBean.setServiceId(serviceNode.getId());
                    Map 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) JSONObject(com.alibaba.fastjson.JSONObject) SqlListResult(com.alibaba.druid.admin.model.dto.SqlListResult) ArrayList(java.util.ArrayList) JSONArray(com.alibaba.fastjson.JSONArray) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 8 with ServiceNode

use of com.alibaba.druid.admin.model.ServiceNode in project druid by alibaba.

the class MonitorStatService method getDataSourceStatData.

/**
 * 数据源监控
 *
 * @param
 * @return
 */
public String getDataSourceStatData() {
    Map<String, ServiceNode> allNodeMap = getAllServiceNodeMap();
    DataSourceResult lastResult = new DataSourceResult();
    List<DataSourceResult.ContentBean> contentBeans = new ArrayList<>();
    for (String nodeKey : allNodeMap.keySet()) {
        ServiceNode serviceNode = allNodeMap.get(nodeKey);
        String serviceName = serviceNode.getServiceName();
        String url = "http://" + serviceNode.getAddress() + ":" + serviceNode.getPort() + "/druid/datasource.json";
        DataSourceResult dataSourceResult = HttpUtil.get(url, lastResult.getClass());
        if (dataSourceResult != null) {
            List<DataSourceResult.ContentBean> nodeContent = dataSourceResult.getContent();
            if (nodeContent != null) {
                for (DataSourceResult.ContentBean contentBean : nodeContent) {
                    contentBean.setName(serviceName);
                    contentBean.setServiceId(serviceNode.getId());
                }
                contentBeans.addAll(nodeContent);
            }
        }
    }
    lastResult.setContent(contentBeans);
    return JSON.toJSONString(lastResult);
}
Also used : ServiceNode(com.alibaba.druid.admin.model.ServiceNode) ArrayList(java.util.ArrayList) DataSourceResult(com.alibaba.druid.admin.model.dto.DataSourceResult)

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