Search in sources :

Example 1 with DataSourceResult

use of com.alibaba.druid.admin.model.dto.DataSourceResult 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)1 DataSourceResult (com.alibaba.druid.admin.model.dto.DataSourceResult)1 ArrayList (java.util.ArrayList)1