Compare commits
No commits in common. "develop" and "master" have entirely different histories.
|
@ -86,7 +86,5 @@ public class StorageConfig {
|
||||||
@Value("${upload.storage.path:/home/cmp}/prometheus/xsky")
|
@Value("${upload.storage.path:/home/cmp}/prometheus/xsky")
|
||||||
private File xskyDir;
|
private File xskyDir;
|
||||||
|
|
||||||
@Value("${upload.storage.path:/home/cmp}/prometheus/cloudTower")
|
|
||||||
private File cloudTowerDir;
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -208,12 +208,4 @@ public enum MonitorResourceType {
|
||||||
* smartX云主机
|
* smartX云主机
|
||||||
*/
|
*/
|
||||||
MONITOR_SMARTX_VM,
|
MONITOR_SMARTX_VM,
|
||||||
/**
|
|
||||||
* CLOUDTOWER云主机
|
|
||||||
*/
|
|
||||||
MONITOR_CLOUDTOWER_VM,
|
|
||||||
/**
|
|
||||||
* CLOUDTOWER宿主机
|
|
||||||
*/
|
|
||||||
MONITOR_CLOUDTOWER_HOST,
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,8 +149,6 @@ public enum CloudProvider {
|
||||||
/**
|
/**
|
||||||
* SMARTX
|
* SMARTX
|
||||||
*/
|
*/
|
||||||
SMARTX,
|
SMARTX;
|
||||||
|
|
||||||
CLOUDTOWER;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,12 +74,6 @@
|
||||||
<artifactId>snakeyaml</artifactId>
|
<artifactId>snakeyaml</artifactId>
|
||||||
<version>1.25</version>
|
<version>1.25</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.bocloud</groupId>
|
|
||||||
<artifactId>bocloud.rpc</artifactId>
|
|
||||||
<version>5.6.0-HBCL-RELEASE</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,6 +0,0 @@
|
||||||
package com.bocloud.cms.intf;
|
|
||||||
|
|
||||||
import com.bocloud.cms.model.ServerModel;
|
|
||||||
|
|
||||||
public interface CloudTowerHostService extends MonitoringAble<ServerModel>{
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package com.bocloud.cms.intf;
|
|
||||||
|
|
||||||
|
|
||||||
import com.bocloud.ims.entity.CloudServer;
|
|
||||||
|
|
||||||
public interface CloudTowerVmService extends MonitoringAble<CloudServer>{
|
|
||||||
}
|
|
|
@ -20,7 +20,6 @@ import com.bocloud.common.utils.MapTools;
|
||||||
import com.bocloud.ims.entity.CloudServer;
|
import com.bocloud.ims.entity.CloudServer;
|
||||||
import com.bocloud.ims.entity.Server;
|
import com.bocloud.ims.entity.Server;
|
||||||
import com.bocloud.ims.enums.CloudProvider;
|
import com.bocloud.ims.enums.CloudProvider;
|
||||||
import com.bocloud.rpc.interfaces.ims.ImsRpcService;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -96,8 +95,6 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||||
private AnalysisRuleRepository analysisRuleRepository;
|
private AnalysisRuleRepository analysisRuleRepository;
|
||||||
@Autowired
|
@Autowired
|
||||||
private AmqpTemplate amqpTemplate;
|
private AmqpTemplate amqpTemplate;
|
||||||
@Autowired
|
|
||||||
private ImsRpcService imsRpcService;
|
|
||||||
|
|
||||||
private static Map<String, String> vmVcenterMetricMap = new HashMap<>(8);
|
private static Map<String, String> vmVcenterMetricMap = new HashMap<>(8);
|
||||||
private static Map<String, String> hostVcenterMetricMap = new HashMap<>(4);
|
private static Map<String, String> hostVcenterMetricMap = new HashMap<>(4);
|
||||||
|
@ -106,9 +103,6 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||||
private static Map<String, String> vmManageOneMetricMap = new HashMap<>(4);
|
private static Map<String, String> vmManageOneMetricMap = new HashMap<>(4);
|
||||||
private static Map<String, String> hostManageOneMetricMap = new HashMap<>(4);
|
private static Map<String, String> hostManageOneMetricMap = new HashMap<>(4);
|
||||||
private static Map<String, String> vmTianyiMetricMap = new HashMap<>(4);
|
private static Map<String, String> vmTianyiMetricMap = new HashMap<>(4);
|
||||||
private static Map<String, String> vmCloudTowerMetricMap = new HashMap<>(4);
|
|
||||||
private static Map<String, String> hostCLoudTowerMetricMap = new HashMap<>(4);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -132,10 +126,6 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||||
vmTianyiMetricMap.put(CPU_USAGE_AVERAGE, "round(tianyi_agt_ecs_cpu_usage{} or tianyi_sys_ecs_cpu_util{},0.01)");
|
vmTianyiMetricMap.put(CPU_USAGE_AVERAGE, "round(tianyi_agt_ecs_cpu_usage{} or tianyi_sys_ecs_cpu_util{},0.01)");
|
||||||
vmTianyiMetricMap.put(MEM_USAGE_AVERAGE, "round(tianyi_agt_ecs_mem_usedPercent{} or tianyi_sys_ecs_mem_util{},0.01)");
|
vmTianyiMetricMap.put(MEM_USAGE_AVERAGE, "round(tianyi_agt_ecs_mem_usedPercent{} or tianyi_sys_ecs_mem_util{},0.01)");
|
||||||
vmTianyiMetricMap.put(DISK_USED_PERCENT, "round(tianyi_agt_ecs_disk_usedPercent{},0.01)");
|
vmTianyiMetricMap.put(DISK_USED_PERCENT, "round(tianyi_agt_ecs_disk_usedPercent{},0.01)");
|
||||||
vmCloudTowerMetricMap.put(CPU_USAGE_AVERAGE, "bocloud_cloudtower_vm_elf_vm_cpu_overall_usage_percent");
|
|
||||||
vmCloudTowerMetricMap.put(MEM_USAGE_AVERAGE, "bocloud_cloudtower_vm_elf_vm_memory_usage_percent");
|
|
||||||
hostCLoudTowerMetricMap.put(CPU_USAGE_AVERAGE, "bocloud_cloudtower_host_host_cpu_overall_usage_percent");
|
|
||||||
hostCLoudTowerMetricMap.put(MEM_USAGE_AVERAGE, "bocloud_cloudtower_host_host_memory_usage_percent");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -166,12 +156,12 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||||
return snapshot;
|
return snapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AnalysisSnapshot hostAnalysis(JSONArray params, String type, Date start, Date end, String flag, String vendorType, Long vendorId) {
|
public AnalysisSnapshot hostAnalysis(JSONArray params, String type, Date start, Date end, String flag, String vendorType) {
|
||||||
AnalysisSnapshot snapshot = new AnalysisSnapshot();
|
AnalysisSnapshot snapshot = new AnalysisSnapshot();
|
||||||
List<String> tags = this.queryHostTagsFromPrometheus(start, end, flag, vendorType, params);
|
List<String> tags = this.queryHostTagsFromPrometheus(start, end, flag, vendorType, params);
|
||||||
Map<String, JSONObject> paramMap = convertParamMap(params);
|
Map<String, JSONObject> paramMap = convertParamMap(params);
|
||||||
//列表数据
|
//列表数据
|
||||||
List<JSONObject> list = hostAnalysisList(paramMap, start, end, tags, vendorType, vendorId);
|
List<JSONObject> list = hostAnalysisList(paramMap, start, end, tags, vendorType);
|
||||||
JSONObject result = new JSONObject();
|
JSONObject result = new JSONObject();
|
||||||
result.put("list", list);
|
result.put("list", list);
|
||||||
List<JSONObject> charts = tops(paramMap, type, start, end, new HashSet<>(), tags, vendorType);
|
List<JSONObject> charts = tops(paramMap, type, start, end, new HashSet<>(), tags, vendorType);
|
||||||
|
@ -281,20 +271,6 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||||
charts.add(vmLineChart(time, "云主机内存利用率Bottom", expr8, "%", TIANYI.name()));
|
charts.add(vmLineChart(time, "云主机内存利用率Bottom", expr8, "%", TIANYI.name()));
|
||||||
charts.add(vmLineChart(time, "云主机磁盘利用率Bottom", expr81, "%", TIANYI.name()));
|
charts.add(vmLineChart(time, "云主机磁盘利用率Bottom", expr81, "%", TIANYI.name()));
|
||||||
break;
|
break;
|
||||||
case CLOUDTOWER:
|
|
||||||
String expr12 = "sort_desc(bottomk(10,round(sum by (id,name) (" + MessageFormat.format(template,
|
|
||||||
paramMap.get(CPU_USAGE_AVERAGE).getString(VALUE_TYPE),
|
|
||||||
"bocloud_cloudtower_vm_elf_vm_cpu_overall_usage_percent{instanceId=~'" + vmText + "'}", duration,
|
|
||||||
paramMap.get(CPU_USAGE_AVERAGE).getString(OPERATOR),
|
|
||||||
paramMap.get(CPU_USAGE_AVERAGE).getString(Common.VALUE)) + "),0.01)))";
|
|
||||||
String expr13 = "sort_desc(bottomk(10,round(sum by (id,name) (" + MessageFormat.format(template,
|
|
||||||
paramMap.get(MEM_USAGE_AVERAGE).getString(VALUE_TYPE),
|
|
||||||
"bocloud_cloudtower_vm_elf_vm_memory_usage_percent{instanceId=~'" + vmText + "'}", duration,
|
|
||||||
paramMap.get(MEM_USAGE_AVERAGE).getString(OPERATOR),
|
|
||||||
paramMap.get(MEM_USAGE_AVERAGE).getString(Common.VALUE)) + "),0.01)))";
|
|
||||||
charts.add(vmLineChart(time, "云主机CPU利用率Bottom", expr12, "%", CLOUDTOWER.name()));
|
|
||||||
charts.add(vmLineChart(time, "云主机内存利用率Bottom", expr13, "%", CLOUDTOWER.name()));
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + vendorType);
|
throw new IllegalStateException("Unexpected value: " + vendorType);
|
||||||
}
|
}
|
||||||
|
@ -381,20 +357,6 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||||
charts.add(vmLineChart(time, "云主机内存利用率Top", expr9, "%", TIANYI.name()));
|
charts.add(vmLineChart(time, "云主机内存利用率Top", expr9, "%", TIANYI.name()));
|
||||||
charts.add(vmLineChart(time, "云主机磁盘利用率Top", expr91, "%", TIANYI.name()));
|
charts.add(vmLineChart(time, "云主机磁盘利用率Top", expr91, "%", TIANYI.name()));
|
||||||
break;
|
break;
|
||||||
case CLOUDTOWER:
|
|
||||||
String expr13 = "sort(topk(10,round(sum by (id,name) (" + MessageFormat.format(template,
|
|
||||||
paramMap.get(CPU_USAGE_AVERAGE).getString(VALUE_TYPE),
|
|
||||||
"bocloud_cloudtower_vm_elf_vm_cpu_overall_usage_percent{instanceId=~'" + vmText + "'}", duration,
|
|
||||||
paramMap.get(CPU_USAGE_AVERAGE).getString(OPERATOR),
|
|
||||||
paramMap.get(CPU_USAGE_AVERAGE).getString(Common.VALUE)) + "),0.01)))";
|
|
||||||
String expr14 = "sort(topk(10,round(sum by (id,name) (" + MessageFormat.format(template,
|
|
||||||
paramMap.get(MEM_USAGE_AVERAGE).getString(VALUE_TYPE),
|
|
||||||
"bocloud_cloudtower_vm_elf_vm_memory_usage_percent{instanceId=~'" + vmText + "'}", duration,
|
|
||||||
paramMap.get(MEM_USAGE_AVERAGE).getString(OPERATOR),
|
|
||||||
paramMap.get(MEM_USAGE_AVERAGE).getString(Common.VALUE)) + "),0.01)))";
|
|
||||||
charts.add(vmLineChart(time, "云主机CPU利用率Top", expr13, "%", CLOUDTOWER.name()));
|
|
||||||
charts.add(vmLineChart(time, "云主机内存利用率Top", expr14, "%", CLOUDTOWER.name()));
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + vendorType);
|
throw new IllegalStateException("Unexpected value: " + vendorType);
|
||||||
}
|
}
|
||||||
|
@ -448,20 +410,6 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||||
charts.add(hostLineChart(time, "宿主机CPU利用率Top", expr6, MANAGEONE.name(), "%"));
|
charts.add(hostLineChart(time, "宿主机CPU利用率Top", expr6, MANAGEONE.name(), "%"));
|
||||||
charts.add(hostLineChart(time, "宿主机内存利用率Top", expr7, MANAGEONE.name(), "%"));
|
charts.add(hostLineChart(time, "宿主机内存利用率Top", expr7, MANAGEONE.name(), "%"));
|
||||||
break;
|
break;
|
||||||
case CLOUDTOWER:
|
|
||||||
String expr11 = "sort_desc(bottomk(10,round(sum by (id,name) (" + MessageFormat.format(template,
|
|
||||||
paramMap.get(CPU_USAGE_AVERAGE).getString(VALUE_TYPE),
|
|
||||||
"bocloud_cloudtower_host_host_cpu_overall_usage_percent{name=~'" + hostText + "'}", duration,
|
|
||||||
paramMap.get(CPU_USAGE_AVERAGE).getString(OPERATOR),
|
|
||||||
paramMap.get(CPU_USAGE_AVERAGE).getString(Common.VALUE)) + "),0.01)))";
|
|
||||||
String expr12 = "sort_desc(bottomk(10,round(sum by (id,name) (" + MessageFormat.format(template,
|
|
||||||
paramMap.get(MEM_USAGE_AVERAGE).getString(VALUE_TYPE),
|
|
||||||
"bocloud_cloudtower_host_host_memory_usage_percent{name=~'" + hostText + "'}", duration,
|
|
||||||
paramMap.get(MEM_USAGE_AVERAGE).getString(OPERATOR),
|
|
||||||
paramMap.get(MEM_USAGE_AVERAGE).getString(Common.VALUE)) + "),0.01)))";
|
|
||||||
charts.add(vmLineChart(time, "宿主机CPU利用率Bottom", expr11, "%", CLOUDTOWER.name()));
|
|
||||||
charts.add(vmLineChart(time, "宿云主机内存利用率Bottom", expr12, "%", CLOUDTOWER.name()));
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + vendorType);
|
throw new IllegalStateException("Unexpected value: " + vendorType);
|
||||||
}
|
}
|
||||||
|
@ -521,9 +469,6 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||||
String ip = cloudServer.getPrivateIps() != null ? StringUtils.join(JSONArray.parseArray(cloudServer.getPrivateIps(), String.class).toArray(), ",") : "";
|
String ip = cloudServer.getPrivateIps() != null ? StringUtils.join(JSONArray.parseArray(cloudServer.getPrivateIps(), String.class).toArray(), ",") : "";
|
||||||
jsonObject.put("ip", ip);
|
jsonObject.put("ip", ip);
|
||||||
break;
|
break;
|
||||||
case CLOUDTOWER:
|
|
||||||
jsonObject.put("ip", cloudServer.getManagerIp());
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + vendorType);
|
throw new IllegalStateException("Unexpected value: " + vendorType);
|
||||||
}
|
}
|
||||||
|
@ -621,20 +566,6 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||||
convertCloudServer(diskUsedPercentResult, tempList, TIANYI.name(), "diskUsedPercent");
|
convertCloudServer(diskUsedPercentResult, tempList, TIANYI.name(), "diskUsedPercent");
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case CLOUDTOWER:
|
|
||||||
Optional.ofNullable(paramMap.get(CPU_USAGE_AVERAGE)).ifPresent(jsonObject -> {
|
|
||||||
String cpuUsageAverageFilter = "round(" + MessageFormat.format(template, jsonObject.getString(VALUE_TYPE),
|
|
||||||
"bocloud_cloudtower_vm_elf_vm_cpu_overall_usage_percent{instanceId=~'" + tag + "'}", duration) + ",0.01)";
|
|
||||||
List<PrometheusResult> cpuUsageAverageResult = prometheusService.query(cpuUsageAverageFilter, time);
|
|
||||||
convertCloudServer(cpuUsageAverageResult, tempList, CLOUDTOWER.name(), "cpuUsage");
|
|
||||||
});
|
|
||||||
Optional.ofNullable(paramMap.get(MEM_USAGE_AVERAGE)).ifPresent(jsonObject -> {
|
|
||||||
String memUsageAverageFilter = "round(" + MessageFormat.format(template, jsonObject.getString(VALUE_TYPE),
|
|
||||||
"bocloud_cloudtower_vm_elf_vm_memory_usage_percent{instanceId=~'" + tag + "'}", duration) + ",0.01)";
|
|
||||||
List<PrometheusResult> memUsageAverageResult = prometheusService.query(memUsageAverageFilter, time);
|
|
||||||
convertCloudServer(memUsageAverageResult, tempList, CLOUDTOWER.name(), "memUsage");
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + vendorType);
|
throw new IllegalStateException("Unexpected value: " + vendorType);
|
||||||
}
|
}
|
||||||
|
@ -644,7 +575,7 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<JSONObject> hostAnalysisList(Map<String, JSONObject> paramMap, Date start, Date end, List<String> tags, String vendorType, Long vendorId) {
|
private List<JSONObject> hostAnalysisList(Map<String, JSONObject> paramMap, Date start, Date end, List<String> tags, String vendorType) {
|
||||||
if (ListTool.isEmpty(tags)) {
|
if (ListTool.isEmpty(tags)) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
@ -652,18 +583,9 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||||
List<Param> hostParams = Lists.newArrayList();
|
List<Param> hostParams = Lists.newArrayList();
|
||||||
String key = vendorType.equals(OPENSTACK.name()) ? "id" : vendorType.equals(VMWARE.name()) ? "name" : "hostname";
|
String key = vendorType.equals(OPENSTACK.name()) ? "id" : vendorType.equals(VMWARE.name()) ? "name" : "hostname";
|
||||||
hostParams.add(new Param(MapTools.simpleMap(key, JSONObject.toJSONString(tags).substring(1, JSONObject.toJSONString(tags).length() - 1)), Sign.IN));
|
hostParams.add(new Param(MapTools.simpleMap(key, JSONObject.toJSONString(tags).substring(1, JSONObject.toJSONString(tags).length() - 1)), Sign.IN));
|
||||||
BocloudResult serverResult = new BocloudResult();
|
BocloudResult serverResult = this.imsServerService.list(new Pager(1, Integer.MAX_VALUE, hostParams, null));
|
||||||
List<Server> serverList = new ArrayList<>();
|
|
||||||
if (CLOUDTOWER.name().equals(vendorType)) {
|
List<Server> serverList = ((JSONObject) serverResult.getData()).getJSONArray(Common.ROWS).toJavaList(Server.class);
|
||||||
JSONArray serverArray = JSONArray.parseArray(JSONObject.toJSONString(imsRpcService.getServerByName(tags, vendorId)));
|
|
||||||
for (Object o : serverArray) {
|
|
||||||
Server server = JSONObject.parseObject(o.toString(), Server.class);
|
|
||||||
serverList.add(server);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
serverResult = this.imsServerService.list(new Pager(1, Integer.MAX_VALUE, hostParams, null));
|
|
||||||
serverList = ((JSONObject) serverResult.getData()).getJSONArray(Common.ROWS).toJavaList(Server.class);
|
|
||||||
}
|
|
||||||
List<JSONObject> list = new ArrayList<>(serverList.size());
|
List<JSONObject> list = new ArrayList<>(serverList.size());
|
||||||
for (Server server : serverList) {
|
for (Server server : serverList) {
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
@ -726,20 +648,6 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||||
convertServer(memUsageAverageResult, list, MANAGEONE.name(), "memUsage");
|
convertServer(memUsageAverageResult, list, MANAGEONE.name(), "memUsage");
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case CLOUDTOWER:
|
|
||||||
Optional.ofNullable(paramMap.get(CPU_USAGE_AVERAGE)).ifPresent(jsonObject -> {
|
|
||||||
String cpuUsageAverageFilter = "round(" + MessageFormat.format(template, paramMap.get(CPU_USAGE_AVERAGE).getString(VALUE_TYPE),
|
|
||||||
"bocloud_cloudtower_host_host_cpu_overall_usage_percent{name=~'" + tag + "'}", duration) + ",0.01)";
|
|
||||||
List<PrometheusResult> cpuUsageAverageResult = prometheusService.query(cpuUsageAverageFilter, time);
|
|
||||||
convertServer(cpuUsageAverageResult, list, CLOUDTOWER.name(), "cpuUsage");
|
|
||||||
});
|
|
||||||
Optional.ofNullable(paramMap.get(MEM_USAGE_AVERAGE)).ifPresent(jsonObject -> {
|
|
||||||
String memUsageAverageFilter = "round(" + MessageFormat.format(template, paramMap.get(MEM_USAGE_AVERAGE).getString(VALUE_TYPE),
|
|
||||||
"bocloud_cloudtower_host_host_memory_usage_percent{name=~'" + tag + "'}", duration) + ",0.01)";
|
|
||||||
List<PrometheusResult> memUsageAverageResult = prometheusService.query(memUsageAverageFilter, time);
|
|
||||||
convertServer(memUsageAverageResult, list, CLOUDTOWER.name(), "memUsage");
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + vendorType);
|
throw new IllegalStateException("Unexpected value: " + vendorType);
|
||||||
}
|
}
|
||||||
|
@ -788,13 +696,6 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||||
tags.add(String.valueOf(prometheusResult.getMetric().get("instance_id")));
|
tags.add(String.valueOf(prometheusResult.getMetric().get("instance_id")));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CLOUDTOWER:
|
|
||||||
expr = getPerformanceExpr(params, start, end, flag, CLOUDTOWER, "vm");
|
|
||||||
prometheusResultList = prometheusService.query(expr, String.valueOf(end.getTime() / 1000L));
|
|
||||||
for (PrometheusResult prometheusResult : prometheusResultList) {
|
|
||||||
tags.add(String.valueOf(prometheusResult.getMetric().get("instanceId")));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + vendorType);
|
throw new IllegalStateException("Unexpected value: " + vendorType);
|
||||||
}
|
}
|
||||||
|
@ -836,13 +737,6 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||||
tags.add(String.valueOf(prometheusResult.getMetric().get("id")));
|
tags.add(String.valueOf(prometheusResult.getMetric().get("id")));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CLOUDTOWER:
|
|
||||||
expr = getPerformanceExpr(params, start, end, flag, CLOUDTOWER, "host");
|
|
||||||
prometheusResultList = prometheusService.query(expr, String.valueOf(end.getTime() / 1000L));
|
|
||||||
for (PrometheusResult prometheusResult : prometheusResultList) {
|
|
||||||
tags.add(String.valueOf(prometheusResult.getMetric().get("name")));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + vendorType);
|
throw new IllegalStateException("Unexpected value: " + vendorType);
|
||||||
}
|
}
|
||||||
|
@ -1003,49 +897,6 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CLOUDTOWER:
|
|
||||||
if ("vm".equals(type) && vmCloudTowerMetricMap.containsKey(param.getString(METRIC))) {
|
|
||||||
String metric = vmCloudTowerMetricMap.get(param.getString(METRIC));
|
|
||||||
Map<String, String> map = new HashMap<>(2);
|
|
||||||
map.put("vendorId", vendorTags);
|
|
||||||
if (StringUtils.isBlank(expr)) {
|
|
||||||
expr = MessageFormat.format(template, param.getString(VALUE_TYPE),
|
|
||||||
PrometheusUtils.putParams(metric, map), duration, param.getString(OPERATOR),
|
|
||||||
param.getString(Common.VALUE));
|
|
||||||
} else {
|
|
||||||
expr = expr + MessageFormat.format(template, param.getString(VALUE_TYPE),
|
|
||||||
vmCloudTowerMetricMap.get(param.getString(METRIC)), duration,
|
|
||||||
param.getString(OPERATOR), param.getString(Common.VALUE));
|
|
||||||
}
|
|
||||||
// 因为cloudTower云平台没有disk平均使用率的监控信息 所以需要特殊处理
|
|
||||||
if (i == params.size() - 1) {
|
|
||||||
result.append(" sum by (instanceId)(").append(expr).append(")");
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
result.append(" sum by (instanceId)(").append(expr).append(") ").append(param.getString("relation"));
|
|
||||||
}
|
|
||||||
} else if ("host".equals(type) && hostCLoudTowerMetricMap.containsKey(param.getString(METRIC))) {
|
|
||||||
String metric = hostCLoudTowerMetricMap.get(param.getString(METRIC));
|
|
||||||
Map<String, String> map = new HashMap<>(2);
|
|
||||||
map.put("vendorId", vendorTags);
|
|
||||||
if (StringUtils.isBlank(expr)) {
|
|
||||||
expr = MessageFormat.format(template, param.getString(VALUE_TYPE),
|
|
||||||
PrometheusUtils.putParams(metric, map), duration, param.getString(OPERATOR),
|
|
||||||
param.getString(Common.VALUE));
|
|
||||||
} else {
|
|
||||||
expr = expr + MessageFormat.format(template, param.getString(VALUE_TYPE),
|
|
||||||
hostCLoudTowerMetricMap.get(param.getString(METRIC)), duration,
|
|
||||||
param.getString(OPERATOR), param.getString(Common.VALUE));
|
|
||||||
}
|
|
||||||
if (i == params.size() - 1) {
|
|
||||||
result.append(" sum by (name)(").append(expr).append(")");
|
|
||||||
} else {
|
|
||||||
result.append(" sum by (name)(").append(expr).append(") ").append(param.getString("relation"));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result = new StringBuilder(result.substring(0, result.length() - 3));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + vendorTags);
|
throw new IllegalStateException("Unexpected value: " + vendorTags);
|
||||||
}
|
}
|
||||||
|
@ -1082,7 +933,6 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||||
private void convertCloudServer(List<PrometheusResult> results, List<JSONObject> list, String vendorType, String key) {
|
private void convertCloudServer(List<PrometheusResult> results, List<JSONObject> list, String vendorType, String key) {
|
||||||
switch (CloudProvider.valueOf(vendorType)) {
|
switch (CloudProvider.valueOf(vendorType)) {
|
||||||
case OPENSTACK:
|
case OPENSTACK:
|
||||||
case CLOUDTOWER:
|
|
||||||
for (PrometheusResult result : results) {
|
for (PrometheusResult result : results) {
|
||||||
for (JSONObject jsonObject : list) {
|
for (JSONObject jsonObject : list) {
|
||||||
if (String.valueOf(jsonObject.get("instanceId"))
|
if (String.valueOf(jsonObject.get("instanceId"))
|
||||||
|
@ -1159,16 +1009,6 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CLOUDTOWER:
|
|
||||||
for (PrometheusResult result : results) {
|
|
||||||
for (JSONObject jsonObject : list) {
|
|
||||||
if (String.valueOf(jsonObject.get("name"))
|
|
||||||
.equals(String.valueOf(result.getMetric().get("name")))) {
|
|
||||||
jsonObject.put(key, result.getValue()[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + vendorType);
|
throw new IllegalStateException("Unexpected value: " + vendorType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,106 +0,0 @@
|
||||||
package com.bocloud.cms.service;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.bocloud.cms.entity.Alarm;
|
|
||||||
import com.bocloud.cms.entity.Metric;
|
|
||||||
import com.bocloud.cms.entity.Rule;
|
|
||||||
import com.bocloud.cms.entity.RuleGroup;
|
|
||||||
import com.bocloud.cms.enums.MonitorResourceType;
|
|
||||||
import com.bocloud.cms.intf.CloudTowerHostService;
|
|
||||||
import com.bocloud.cms.intf.PrometheusService;
|
|
||||||
import com.bocloud.cms.intf.ResourceAlarmStatusService;
|
|
||||||
import com.bocloud.cms.model.PrometheusAlarm;
|
|
||||||
import com.bocloud.cms.model.ServerModel;
|
|
||||||
import com.bocloud.cms.repository.ResourceAlarmStatusRepository;
|
|
||||||
import com.bocloud.cms.service.internal.ImsServerService;
|
|
||||||
import com.bocloud.common.model.BocloudResult;
|
|
||||||
import com.bocloud.common.model.Pager;
|
|
||||||
import com.bocloud.common.model.Param;
|
|
||||||
import com.bocloud.common.model.Sign;
|
|
||||||
import com.bocloud.common.utils.Common;
|
|
||||||
import com.bocloud.common.utils.MapTools;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class CloudTowerHostServiceImpl implements CloudTowerHostService, InitializingBean {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(CloudTowerHostServiceImpl.class);
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
CloudTowerHostService cloudTowerHostService;
|
|
||||||
/**
|
|
||||||
* 查询宿主机列表时使用
|
|
||||||
*/
|
|
||||||
@Autowired
|
|
||||||
private ImsServerService imsServerService;
|
|
||||||
@Autowired
|
|
||||||
private PrometheusService prometheusService;
|
|
||||||
@Autowired
|
|
||||||
private ResourceAlarmStatusRepository alarmStatusRepository;
|
|
||||||
@Autowired
|
|
||||||
private ResourceAlarmStatusService resourceAlarmStatusService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterPropertiesSet() throws Exception {
|
|
||||||
MonitoringAbleRegistry.register(MonitorResourceType.MONITOR_CLOUDTOWER_HOST, this);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public List<ServerModel> listTargetObjects(List<String> targetIds, MonitorResourceType resourceType) {
|
|
||||||
List<Integer> targetList = new ArrayList<>();
|
|
||||||
Optional.ofNullable(targetIds).orElse(new ArrayList<>()).forEach(targetId -> targetList.add(Integer.valueOf(targetId)));
|
|
||||||
Param param = new Param(MapTools.simpleMap("id", JSONObject.toJSONString(targetList).substring(1, JSONObject.toJSONString(targetList).length() - 1)), Sign.IN);
|
|
||||||
|
|
||||||
List<Param> params = Collections.singletonList(param);
|
|
||||||
BocloudResult result = imsServerService.list(new Pager(1, Integer.MAX_VALUE, params, null));
|
|
||||||
Assert.isTrue(result.isSuccess(), result.getMessage());
|
|
||||||
JSONObject data = (JSONObject) result.getData();
|
|
||||||
return data.getJSONArray(Common.ROWS).toJavaList(ServerModel.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, String> getPrometheusExprParam(ServerModel targetObject, Metric metric) {
|
|
||||||
Map<String, String> params = new HashMap<>(16, 0.75F);
|
|
||||||
params.put("name", targetObject.getName());
|
|
||||||
params.put("vendorId",targetObject.getVendorId().toString());
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ServerModel parseObjectFromAlert(PrometheusAlarm.PrometheusAlert alert, RuleGroup ruleGroup, Rule rule, Metric metric) {
|
|
||||||
String instanceId = String.valueOf(alert.getLabels().get("instanceId"));
|
|
||||||
// 通过主机名称去查找对应的主机信息
|
|
||||||
List<Param> params = Collections.singletonList(new Param(MapTools.simpleMap("name", alert.getLabels().get("name")), Sign.EQ));
|
|
||||||
BocloudResult result = imsServerService.list(new Pager(1, 1, params, null));
|
|
||||||
Assert.isTrue(result.isSuccess(), result.getMessage());
|
|
||||||
JSONObject data = (JSONObject) result.getData();
|
|
||||||
List<ServerModel> list = data.getJSONArray(Common.ROWS).toJavaList(ServerModel.class);
|
|
||||||
Assert.isTrue(list != null && !list.isEmpty(), "cloudTowerHost not found,instanceId:" + instanceId);
|
|
||||||
return list.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroy(ServerModel object, String catalog) throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void wrapAlarm(Alarm alarm, ServerModel object) {
|
|
||||||
alarm.setTarget(object.getId());
|
|
||||||
alarm.setVendorId(object.getVendorId());
|
|
||||||
alarm.setOwnerId(object.getCreatorId());
|
|
||||||
String targetName = object.getManageIp() == null ? object.getName() : object.getName() + "(" + object.getManageIp() + ")";
|
|
||||||
alarm.setTargetName(targetName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean alarmEnable(RuleGroup ruleGroup, ServerModel object) {
|
|
||||||
return resourceAlarmStatusService.alarmEnable(ruleGroup.getResourceType(), String.valueOf(object.getId()), ruleGroup.getTenantId());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,100 +0,0 @@
|
||||||
package com.bocloud.cms.service;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.bocloud.cms.entity.Alarm;
|
|
||||||
import com.bocloud.cms.entity.Metric;
|
|
||||||
import com.bocloud.cms.entity.Rule;
|
|
||||||
import com.bocloud.cms.entity.RuleGroup;
|
|
||||||
import com.bocloud.cms.enums.MonitorResourceType;
|
|
||||||
import com.bocloud.cms.intf.AlarmService;
|
|
||||||
import com.bocloud.cms.intf.CloudTowerVmService;
|
|
||||||
import com.bocloud.cms.intf.ResourceAlarmStatusService;
|
|
||||||
import com.bocloud.cms.model.PrometheusAlarm;
|
|
||||||
import com.bocloud.cms.service.internal.ImsCloudServerService;
|
|
||||||
import com.bocloud.common.model.BocloudResult;
|
|
||||||
import com.bocloud.common.model.Pager;
|
|
||||||
import com.bocloud.common.model.Param;
|
|
||||||
import com.bocloud.common.model.Sign;
|
|
||||||
import com.bocloud.common.utils.Common;
|
|
||||||
import com.bocloud.common.utils.MapTools;
|
|
||||||
import com.bocloud.ims.entity.CloudServer;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class CloudTowerVmServiceImpl implements CloudTowerVmService, InitializingBean {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(CloudTowerVmServiceImpl.class);
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
CloudTowerVmService cloudTowerVmService;
|
|
||||||
@Autowired
|
|
||||||
private ImsCloudServerService imsCloudServerService;
|
|
||||||
@Autowired
|
|
||||||
private ResourceAlarmStatusService resourceAlarmStatusService;
|
|
||||||
@Autowired
|
|
||||||
private AlarmService alarmService;
|
|
||||||
@Override
|
|
||||||
public void afterPropertiesSet() throws Exception {
|
|
||||||
MonitoringAbleRegistry.register(MonitorResourceType.MONITOR_CLOUDTOWER_VM, this);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public List<CloudServer> listTargetObjects(List<String> targetIds, MonitorResourceType resourceType) {
|
|
||||||
List<Integer> targetList = new ArrayList<>();
|
|
||||||
Optional.ofNullable(targetIds).orElse(new ArrayList<>()).forEach(targetId -> targetList.add(Integer.valueOf(targetId)));
|
|
||||||
Param param = new Param(MapTools.simpleMap("id", JSONObject.toJSONString(targetList).substring(1, JSONObject.toJSONString(targetList).length() - 1)), Sign.IN);
|
|
||||||
|
|
||||||
List<Param> params = Collections.singletonList(param);
|
|
||||||
BocloudResult result = imsCloudServerService.list(new Pager(1, Integer.MAX_VALUE, params, null), null);
|
|
||||||
Assert.isTrue(result.isSuccess(), result.getMessage());
|
|
||||||
JSONObject data = (JSONObject) result.getData();
|
|
||||||
return data.getJSONArray(Common.ROWS).toJavaList(CloudServer.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, String> getPrometheusExprParam(CloudServer targetObject, Metric metric) {
|
|
||||||
Map<String, String> params = new HashMap<>(16, 0.75F);
|
|
||||||
params.put("instanceId", targetObject.getInstanceId());
|
|
||||||
params.put("vendorId",targetObject.getVendorId().toString());
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CloudServer parseObjectFromAlert(PrometheusAlarm.PrometheusAlert alert, RuleGroup ruleGroup, Rule rule, Metric metric) {
|
|
||||||
String instanceId = String.valueOf(alert.getLabels().get("instanceId"));
|
|
||||||
// 通过vmName去查找对应的云主机信息
|
|
||||||
List<Param> params = Collections.singletonList(new Param(MapTools.simpleMap("instanceId", instanceId), Sign.EQ));
|
|
||||||
BocloudResult result = imsCloudServerService.list(new Pager(1, 1, params, null), null);
|
|
||||||
Assert.isTrue(result.isSuccess(), result.getMessage());
|
|
||||||
JSONObject data = (JSONObject) result.getData();
|
|
||||||
List<CloudServer> list = data.getJSONArray(Common.ROWS).toJavaList(CloudServer.class);
|
|
||||||
Assert.isTrue(list != null && !list.isEmpty(), "cloudTowerVm not found,instanceId:" + instanceId);
|
|
||||||
return list.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroy(CloudServer cloudServer, String catalog) throws Exception {
|
|
||||||
logger.info("destroy cloudTower vm : " + cloudServer.getId());
|
|
||||||
alarmService.solveByCloudServer(cloudServer.getId(),catalog,1L,"系统解决");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void wrapAlarm(Alarm alarm, CloudServer object) {
|
|
||||||
alarm.setTarget(object.getId());
|
|
||||||
alarm.setVendorId(object.getVendorId());
|
|
||||||
alarm.setOwnerId(object.getCreatorId());
|
|
||||||
String targetName = object.getManagerIp() == null ? object.getName() : object.getName() + "(" + object.getManagerIp() + ")";
|
|
||||||
alarm.setTargetName(targetName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean alarmEnable(RuleGroup ruleGroup, CloudServer object) {
|
|
||||||
return resourceAlarmStatusService.alarmEnable(ruleGroup.getResourceType(), String.valueOf(object.getId()), ruleGroup.getTenantId());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -117,7 +117,6 @@ public class HostServiceImpl implements HostService, InitializingBean {
|
||||||
handleOpenStackList(context, list);
|
handleOpenStackList(context, list);
|
||||||
handleManageOneList(context, list);
|
handleManageOneList(context, list);
|
||||||
handleH3cList(context, list);
|
handleH3cList(context, list);
|
||||||
handleCloudTower(context, list);
|
|
||||||
|
|
||||||
String ips = StringUtils.join(ipList.toArray(), "|");
|
String ips = StringUtils.join(ipList.toArray(), "|");
|
||||||
//主机通断状态
|
//主机通断状态
|
||||||
|
@ -149,33 +148,6 @@ public class HostServiceImpl implements HostService, InitializingBean {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleCloudTower(RequestContext context, List<ServerModel> list) {
|
|
||||||
List<String> names = list.stream().filter(s -> s.getVendorType().equalsIgnoreCase(CloudProvider.CLOUDTOWER.name()))
|
|
||||||
.map(s -> String.valueOf(s.getName())).collect(Collectors.toList());
|
|
||||||
if (ListTool.isEmpty(names)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<String> target = list.stream().map(m -> String.valueOf(m.getId())).collect(Collectors.toList());
|
|
||||||
List<ResourceAlarmStatus> alarmStatuses = this.alarmStatusRepository.list(MonitorResourceType.MONITOR_CLOUDTOWER_HOST.name(), target, context);
|
|
||||||
|
|
||||||
for (ServerModel server : list) {
|
|
||||||
String cpuExpr = "bocloud_cloudtower_host_host_cpu_overall_usage_percent{name='" +server.getName()+"'}";
|
|
||||||
List<PrometheusResult> cpu = prometheusService.query(cpuExpr);
|
|
||||||
for (PrometheusResult cpuUsage : cpu) {
|
|
||||||
server.setCpuUsage(String.valueOf(cpuUsage.getValue()[1]));
|
|
||||||
}
|
|
||||||
String memoryExpr = "bocloud_cloudtower_host_host_memory_usage_percent{name='" +server.getName() +"'}";
|
|
||||||
List<PrometheusResult> memory = prometheusService.query(memoryExpr);
|
|
||||||
for (PrometheusResult memUsage : memory) {
|
|
||||||
server.setMemUsage(String.valueOf(memUsage.getValue()[1]));
|
|
||||||
}
|
|
||||||
//告警启用状态,默认开启
|
|
||||||
boolean alarmEnable = !Optional.ofNullable(alarmStatuses).orElse(new ArrayList<>()).stream()
|
|
||||||
.filter(a -> a.getResourceId().equals(server.getId().toString()))
|
|
||||||
.findAny().isPresent();
|
|
||||||
server.setAlarmEnable(alarmEnable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BocloudResult hostOverview(Long id, String type) {
|
public BocloudResult hostOverview(Long id, String type) {
|
||||||
|
@ -183,7 +155,7 @@ public class HostServiceImpl implements HostService, InitializingBean {
|
||||||
BocloudResult<Server> server = imsServerService.detail(id);
|
BocloudResult<Server> server = imsServerService.detail(id);
|
||||||
Assert.isTrue(server.isSuccess(), " 未查询到该主机相关信息");
|
Assert.isTrue(server.isSuccess(), " 未查询到该主机相关信息");
|
||||||
HashMap<String, Object> result = new HashMap<>(16, 0.75F);
|
HashMap<String, Object> result = new HashMap<>(16, 0.75F);
|
||||||
if (type.equals(CloudProvider.VMWARE.name()) || type.equals(CloudProvider.CLOUDTOWER.name())) {
|
if (type.equals(CloudProvider.VMWARE.name())) {
|
||||||
result.put("name", server.getData().getName());
|
result.put("name", server.getData().getName());
|
||||||
result.put("powerState", server.getData().getPowerState());
|
result.put("powerState", server.getData().getPowerState());
|
||||||
result.put("ip", server.getData().getManageIp());
|
result.put("ip", server.getData().getManageIp());
|
||||||
|
@ -246,7 +218,6 @@ public class HostServiceImpl implements HostService, InitializingBean {
|
||||||
// 查询主机cpu平均使用情况
|
// 查询主机cpu平均使用情况
|
||||||
Double cpuUsage = prometheusService
|
Double cpuUsage = prometheusService
|
||||||
.simpleQuery("vsphere_host_cpu_usage_average{cpu='instance-total',source='" + name + "'}");
|
.simpleQuery("vsphere_host_cpu_usage_average{cpu='instance-total',source='" + name + "'}");
|
||||||
cpuUsed = cpuUsed != null ? cpuUsed : serverConfig.getCpuUsed();
|
|
||||||
result.put("cpuUsed", cpuUsed != null ? cpuUsed : "");
|
result.put("cpuUsed", cpuUsed != null ? cpuUsed : "");
|
||||||
result.put("cpuUsage", cpuUsage != null ? cpuUsage : "");
|
result.put("cpuUsage", cpuUsage != null ? cpuUsage : "");
|
||||||
if (null != serverConfig) {
|
if (null != serverConfig) {
|
||||||
|
@ -259,10 +230,10 @@ public class HostServiceImpl implements HostService, InitializingBean {
|
||||||
} else if ("mem".equals(type)) {
|
} else if ("mem".equals(type)) {
|
||||||
Double memUsed = prometheusService
|
Double memUsed = prometheusService
|
||||||
.simpleQuery("round(vsphere_host_mem_consumed_average{source='" + name + "'}/ 1024 / 1024,0.01)");
|
.simpleQuery("round(vsphere_host_mem_consumed_average{source='" + name + "'}/ 1024 / 1024,0.01)");
|
||||||
result.put("memUsed", memUsed != null ? memUsed : serverConfig.getMemUsed());
|
result.put("memUsed", memUsed != null ? memUsed : "");
|
||||||
result.put("memTotalCapacity", serverConfig != null ? serverConfig.getMemoryCapacity() : "");
|
result.put("memTotalCapacity", serverConfig != null ? serverConfig.getMemoryCapacity() : "");
|
||||||
if (null != serverConfig && result.containsKey("memUsed")) {
|
if (null != serverConfig && null != memUsed) {
|
||||||
result.put("memFree", Double.parseDouble(format.format(serverConfig.getMemoryCapacity() - Double.valueOf(result.get("memUsed").toString()))));
|
result.put("memFree", Double.parseDouble(format.format(serverConfig.getMemoryCapacity() - memUsed)));
|
||||||
}
|
}
|
||||||
} else if ("disk".equals(type)) {
|
} else if ("disk".equals(type)) {
|
||||||
if (serverConfig != null) {
|
if (serverConfig != null) {
|
||||||
|
|
|
@ -77,8 +77,6 @@ public class TopServiceImpl implements TopService {
|
||||||
return hostLineChart("宿主机CPU利用率", "round(sort_desc(topk(" + limit + ",bocloud_fusioncloud_host_cpuUsage{vendorId='" + vendorId + "'})),0.01)");
|
return hostLineChart("宿主机CPU利用率", "round(sort_desc(topk(" + limit + ",bocloud_fusioncloud_host_cpuUsage{vendorId='" + vendorId + "'})),0.01)");
|
||||||
case SMARTX:
|
case SMARTX:
|
||||||
return hostLineChart("宿主机CPU利用率", "round(sort_desc(topk(" + limit + ",smartx_host_cpu_overall_usage_percent{vendorId='" + vendorId + "'})),0.01)");
|
return hostLineChart("宿主机CPU利用率", "round(sort_desc(topk(" + limit + ",smartx_host_cpu_overall_usage_percent{vendorId='" + vendorId + "'})),0.01)");
|
||||||
case CLOUDTOWER:
|
|
||||||
return hostLineChart("宿主机CPU利用率", "round(sort_desc(topk(" + limit + ",bocloud_cloudtower_host_host_cpu_overall_usage_percent{vendorId='" + vendorId + "'})),0.01)");
|
|
||||||
default:
|
default:
|
||||||
return new LineChartResult(null, new Values[]{new Values("宿主机cpu利用率", null)}, null);
|
return new LineChartResult(null, new Values[]{new Values("宿主机cpu利用率", null)}, null);
|
||||||
}
|
}
|
||||||
|
@ -106,8 +104,6 @@ public class TopServiceImpl implements TopService {
|
||||||
return hostLineChart("宿主机内存利用率", "round(sort_desc(topk(" + limit + ",bocloud_fusioncloud_host_memoryUsage{vendorId='" + vendorId + "'})),0.01)");
|
return hostLineChart("宿主机内存利用率", "round(sort_desc(topk(" + limit + ",bocloud_fusioncloud_host_memoryUsage{vendorId='" + vendorId + "'})),0.01)");
|
||||||
case SMARTX:
|
case SMARTX:
|
||||||
return hostLineChart("宿主机内存利用率", "round(sort_desc(topk(" + limit + ",smartx_host_memory_usage_percent{vendorId='" + vendorId + "'})),0.01)");
|
return hostLineChart("宿主机内存利用率", "round(sort_desc(topk(" + limit + ",smartx_host_memory_usage_percent{vendorId='" + vendorId + "'})),0.01)");
|
||||||
case CLOUDTOWER:
|
|
||||||
return hostLineChart("宿主机内存利用率", "round(sort_desc(topk(" + limit + ",bocloud_cloudtower_host_host_memory_usage_percent{vendorId='" + vendorId + "'})),0.01)");
|
|
||||||
default:
|
default:
|
||||||
return new LineChartResult(null, new Values[]{new Values("宿主机内存利用率", null)}, null);
|
return new LineChartResult(null, new Values[]{new Values("宿主机内存利用率", null)}, null);
|
||||||
}
|
}
|
||||||
|
@ -142,9 +138,6 @@ public class TopServiceImpl implements TopService {
|
||||||
case SMARTX:
|
case SMARTX:
|
||||||
expr = "round(sort(topk(" + limit * 3 + ",smartx_elf_vm_cpu_overall_usage_percent{vendorId='" + vendor.getId() + "'})),0.01)";
|
expr = "round(sort(topk(" + limit * 3 + ",smartx_elf_vm_cpu_overall_usage_percent{vendorId='" + vendor.getId() + "'})),0.01)";
|
||||||
break;
|
break;
|
||||||
case CLOUDTOWER:
|
|
||||||
expr = "round(sort(topk(" + limit * 3 + ",bocloud_cloudtower_vm_elf_vm_cpu_overall_usage_percent{vendorId='" + vendor.getId() + "'})),0.01)";
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -181,9 +174,6 @@ public class TopServiceImpl implements TopService {
|
||||||
case SMARTX:
|
case SMARTX:
|
||||||
expr = "round(sort(topk(" + limit * 3 + ",smartx_elf_vm_memory_usage_percent{vendorId='" + vendor.getId() + "'})),0.01)";
|
expr = "round(sort(topk(" + limit * 3 + ",smartx_elf_vm_memory_usage_percent{vendorId='" + vendor.getId() + "'})),0.01)";
|
||||||
break;
|
break;
|
||||||
case CLOUDTOWER:
|
|
||||||
expr = "round(sort(topk(" + limit * 3 + ",bocloud_cloudtower_vm_elf_vm_memory_usage_percent{vendorId='" + vendor.getId() + "'})),0.01)";
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -299,11 +289,6 @@ public class TopServiceImpl implements TopService {
|
||||||
vmName = String.valueOf(result.getMetric().get("vm"));
|
vmName = String.valueOf(result.getMetric().get("vm"));
|
||||||
String instanceId = String.valueOf(result.getMetric().get("vm"));
|
String instanceId = String.valueOf(result.getMetric().get("vm"));
|
||||||
paramList.add(new Param(MapTools.simpleMap("instanceId", instanceId), Sign.EQ));
|
paramList.add(new Param(MapTools.simpleMap("instanceId", instanceId), Sign.EQ));
|
||||||
} else if (result.getMetric().containsKey("vendorId") && CloudProvider.CLOUDTOWER == vendorType) {
|
|
||||||
//cloudTower 使用vm查询
|
|
||||||
vmName = String.valueOf(result.getMetric().get("name"));
|
|
||||||
String instanceId = String.valueOf(result.getMetric().get("instanceId"));
|
|
||||||
paramList.add(new Param(MapTools.simpleMap("instanceId", instanceId), Sign.EQ));
|
|
||||||
} else {
|
} else {
|
||||||
//manageone 使用instanceId查询
|
//manageone 使用instanceId查询
|
||||||
vmName = String.valueOf(result.getMetric().get("name"));
|
vmName = String.valueOf(result.getMetric().get("name"));
|
||||||
|
|
|
@ -86,9 +86,6 @@ public class VendorServiceImpl implements VendorService {
|
||||||
case XSKY:
|
case XSKY:
|
||||||
openXsky(vendor);
|
openXsky(vendor);
|
||||||
break;
|
break;
|
||||||
case CLOUDTOWER:
|
|
||||||
openCloudTower(vendor);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
BocloudResult result = imsCloudVendorService.openMonitoring(idsList);
|
BocloudResult result = imsCloudVendorService.openMonitoring(idsList);
|
||||||
Assert.isTrue(result.isSuccess(), result.getMessage());
|
Assert.isTrue(result.isSuccess(), result.getMessage());
|
||||||
|
@ -266,47 +263,6 @@ public class VendorServiceImpl implements VendorService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 开启cloudTower监控
|
|
||||||
*
|
|
||||||
* @param vendor
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private void openCloudTower(CloudVendor vendor) throws Exception {
|
|
||||||
List<Param> params = new ArrayList<>();
|
|
||||||
params.add(new Param(MapTools.simpleMap("vendorId", vendor.getId()), Sign.EQ));
|
|
||||||
params.add(new Param(MapTools.simpleMap("exporterInstalled", true), Sign.EQ));
|
|
||||||
BocloudResult serversResult = imsServerService.list(new Pager(1, Integer.MAX_VALUE, false, params, null));
|
|
||||||
JSONObject data = (JSONObject) serversResult.getData();
|
|
||||||
List<Server> list = data.getJSONArray(Common.ROWS).toJavaList(Server.class);
|
|
||||||
List<File> files = new ArrayList<>();
|
|
||||||
for (Server server : list) {
|
|
||||||
Map<String, String> labels = new HashMap<>(16, 0.75F);
|
|
||||||
labels.put("id", String.valueOf(server.getId()));
|
|
||||||
labels.put("name", server.getName());
|
|
||||||
labels.put("vendor_id", String.valueOf(vendor.getId()));
|
|
||||||
labels.put("instanceId", server.getUuid());
|
|
||||||
JSONObject config = new JSONObject();
|
|
||||||
config.put("targets", Arrays.asList(server.getManageIp() + ":" + port));
|
|
||||||
config.put("labels", labels);
|
|
||||||
JSONArray array = new JSONArray();
|
|
||||||
array.add(config);
|
|
||||||
File file = new File(storageConfig.getCloudTowerDir(), "server_" + server.getId() + ".json");
|
|
||||||
FileUtils.write(file, array.toJSONString(), "UTF-8");
|
|
||||||
files.add(file);
|
|
||||||
}
|
|
||||||
BocloudResult result = imsCloudVendorService.openMonitoring(Collections.singletonList(vendor.getId()));
|
|
||||||
if (result.isFailed()) {
|
|
||||||
files.forEach(file -> {
|
|
||||||
if (file.exists() && !file.delete()) {
|
|
||||||
logger.error("file delete failed, path:{} " + file.getPath());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
throw new RuntimeException(result.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开启xsky监控
|
* 开启xsky监控
|
||||||
*
|
*
|
||||||
|
|
|
@ -98,7 +98,6 @@ public class VmServiceImpl implements VmService, InitializingBean {
|
||||||
handleHmcList(list, context);
|
handleHmcList(list, context);
|
||||||
handleTencentList(list, context);
|
handleTencentList(list, context);
|
||||||
handleSmartxList(list, context);
|
handleSmartxList(list, context);
|
||||||
handleCloudTower(list, context);
|
|
||||||
data.put(Common.ROWS, list);
|
data.put(Common.ROWS, list);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -385,48 +384,6 @@ public class VmServiceImpl implements VmService, InitializingBean {
|
||||||
MonitoringAbleRegistry.register(MonitorResourceType.MONITOR_VCENTER_VM, this);
|
MonitoringAbleRegistry.register(MonitorResourceType.MONITOR_VCENTER_VM, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleCloudTower(List<CloudServerModel> list, RequestContext context) {
|
|
||||||
List<String> instanceIds = list.stream()
|
|
||||||
.filter(s -> s.getVendorType().equalsIgnoreCase(CloudProvider.CLOUDTOWER.name()))
|
|
||||||
.map(CloudServer::getInstanceId).collect(Collectors.toList());
|
|
||||||
if (ListTool.isEmpty(instanceIds)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String instanceId = StringUtils.join(instanceIds.toArray(), "|");
|
|
||||||
List<PrometheusResult> cpuList = prometheusService.query("round(bocloud_cloudtower_vm_elf_vm_cpu_overall_usage_percent{instanceId=~'" + instanceId + "'},0.01)");
|
|
||||||
List<PrometheusResult> memoryList = prometheusService.query("round(bocloud_cloudtower_vm_elf_vm_memory_usage_percent{instanceId=~'" + instanceId + "'},0.01)");
|
|
||||||
|
|
||||||
List<String> target = list.stream().map(m -> String.valueOf(m.getId())).collect(Collectors.toList());
|
|
||||||
List<ResourceAlarmStatus> alarmStatuses = this.alarmStatusRepository.list(MonitorResourceType.MONITOR_CLOUDTOWER_VM.name(), target, context);
|
|
||||||
|
|
||||||
for (CloudServerModel cloudServer : list) {
|
|
||||||
cloudServer.setMemTotal(String.valueOf(cloudServer.getMemory()));
|
|
||||||
//CPU利用率
|
|
||||||
for (PrometheusResult cpuUsage : cpuList) {
|
|
||||||
if (cpuUsage.getMetric().get("instanceId").equals(cloudServer.getInstanceId())) {
|
|
||||||
cloudServer.setCpuUsage(String.valueOf(cpuUsage.getValue()[1]));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//内存利用率
|
|
||||||
for (PrometheusResult memoryUsage : memoryList) {
|
|
||||||
if (memoryUsage.getMetric().get("instanceId").equals(cloudServer.getInstanceId())) {
|
|
||||||
cloudServer.setMemUsage(String.valueOf(memoryUsage.getValue()[1]));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//告警启用状态,默认开启
|
|
||||||
if ( alarmStatuses.size()>0 ){
|
|
||||||
for (ResourceAlarmStatus alarmStatus : alarmStatuses) {
|
|
||||||
if (alarmStatus.getResourceId().equals(cloudServer.getId().toString())){
|
|
||||||
cloudServer.setAlarmEnable(alarmStatus.getEnable());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleVmwareList(RequestContext context, List<CloudServerModel> list) {
|
private void handleVmwareList(RequestContext context, List<CloudServerModel> list) {
|
||||||
List<CloudServerModel> vmwareVms = list.stream().filter(s -> s.getVendorType().equalsIgnoreCase(CloudProvider.VMWARE.name())).collect(Collectors.toList());
|
List<CloudServerModel> vmwareVms = list.stream().filter(s -> s.getVendorType().equalsIgnoreCase(CloudProvider.VMWARE.name())).collect(Collectors.toList());
|
||||||
|
|
|
@ -71,7 +71,6 @@ public class AnalysisHandleRunable implements Runnable {
|
||||||
break;
|
break;
|
||||||
case MANAGEONE:
|
case MANAGEONE:
|
||||||
case TIANYI:
|
case TIANYI:
|
||||||
case CLOUDTOWER:
|
|
||||||
flag = String.valueOf(vendorId);
|
flag = String.valueOf(vendorId);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -84,7 +83,7 @@ public class AnalysisHandleRunable implements Runnable {
|
||||||
snapshot = monitorAnalysisService.vmAnalysis(JSONObject.parseArray(analysaisRule.getRules()), type, start, end, flag, vendor.getType(), token);
|
snapshot = monitorAnalysisService.vmAnalysis(JSONObject.parseArray(analysaisRule.getRules()), type, start, end, flag, vendor.getType(), token);
|
||||||
break;
|
break;
|
||||||
case "serverCapacityExpansion":
|
case "serverCapacityExpansion":
|
||||||
snapshot = monitorAnalysisService.hostAnalysis(JSONObject.parseArray(analysaisRule.getRules()), type, start, end, flag, vendor.getType(), vendor.getId());
|
snapshot = monitorAnalysisService.hostAnalysis(JSONObject.parseArray(analysaisRule.getRules()), type, start, end, flag, vendor.getType());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
logger.error("未知的类型");
|
logger.error("未知的类型");
|
||||||
|
|
Loading…
Reference in New Issue