Search in sources :

Example 16 with JSONArray

use of com.alibaba.fastjson2.JSONArray 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.fastjson2.JSONObject) SqlListResult(com.alibaba.druid.admin.model.dto.SqlListResult) ArrayList(java.util.ArrayList) JSONArray(com.alibaba.fastjson2.JSONArray) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

JSONArray (com.alibaba.fastjson2.JSONArray)16 ArrayList (java.util.ArrayList)13 DbType (com.alibaba.druid.DbType)10 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)10 SQLASTOutputVisitor (com.alibaba.druid.sql.visitor.SQLASTOutputVisitor)10 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)8 JSONObject (com.alibaba.fastjson2.JSONObject)4 Map (java.util.Map)3 ServiceNode (com.alibaba.druid.admin.model.ServiceNode)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 SqlListResult (com.alibaba.druid.admin.model.dto.SqlListResult)1 WebResult (com.alibaba.druid.admin.model.dto.WebResult)1 MySqlSchemaStatVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor)1 SchemaStatVisitor (com.alibaba.druid.sql.visitor.SchemaStatVisitor)1 TableStat (com.alibaba.druid.stat.TableStat)1 JSONException (com.alibaba.fastjson2.JSONException)1 CanalCluster (com.alibaba.otter.canal.admin.model.CanalCluster)1 NodeServer (com.alibaba.otter.canal.admin.model.NodeServer)1 ESException (com.sakura.common.es.exception.ESException)1