迁移cloudTower监控告警
parent
7383eaaec2
commit
e51c9dbcac
|
@ -74,6 +74,12 @@
|
|||
<artifactId>snakeyaml</artifactId>
|
||||
<version>1.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.bocloud</groupId>
|
||||
<artifactId>bocloud.rpc</artifactId>
|
||||
<version>5.6.0-HBCL-RELEASE</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -20,6 +20,7 @@ import com.bocloud.common.utils.MapTools;
|
|||
import com.bocloud.ims.entity.CloudServer;
|
||||
import com.bocloud.ims.entity.Server;
|
||||
import com.bocloud.ims.enums.CloudProvider;
|
||||
import com.bocloud.rpc.interfaces.ims.ImsRpcService;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -95,6 +96,8 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|||
private AnalysisRuleRepository analysisRuleRepository;
|
||||
@Autowired
|
||||
private AmqpTemplate amqpTemplate;
|
||||
@Autowired
|
||||
private ImsRpcService imsRpcService;
|
||||
|
||||
private static Map<String, String> vmVcenterMetricMap = new HashMap<>(8);
|
||||
private static Map<String, String> hostVcenterMetricMap = new HashMap<>(4);
|
||||
|
@ -132,7 +135,7 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|||
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_vm_elf_vm_cpu_overall_usage_percent");
|
||||
hostCLoudTowerMetricMap.put(MEM_USAGE_AVERAGE, "bocloud_cloudtower_host_host_memory_usage_percent");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -163,12 +166,12 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|||
return snapshot;
|
||||
}
|
||||
|
||||
public AnalysisSnapshot hostAnalysis(JSONArray params, String type, Date start, Date end, String flag, String vendorType) {
|
||||
public AnalysisSnapshot hostAnalysis(JSONArray params, String type, Date start, Date end, String flag, String vendorType, Long vendorId) {
|
||||
AnalysisSnapshot snapshot = new AnalysisSnapshot();
|
||||
List<String> tags = this.queryHostTagsFromPrometheus(start, end, flag, vendorType, params);
|
||||
Map<String, JSONObject> paramMap = convertParamMap(params);
|
||||
//列表数据
|
||||
List<JSONObject> list = hostAnalysisList(paramMap, start, end, tags, vendorType);
|
||||
List<JSONObject> list = hostAnalysisList(paramMap, start, end, tags, vendorType, vendorId);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("list", list);
|
||||
List<JSONObject> charts = tops(paramMap, type, start, end, new HashSet<>(), tags, vendorType);
|
||||
|
@ -641,7 +644,7 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|||
return list;
|
||||
}
|
||||
|
||||
private List<JSONObject> hostAnalysisList(Map<String, JSONObject> paramMap, Date start, Date end, List<String> tags, String vendorType) {
|
||||
private List<JSONObject> hostAnalysisList(Map<String, JSONObject> paramMap, Date start, Date end, List<String> tags, String vendorType, Long vendorId) {
|
||||
if (ListTool.isEmpty(tags)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
@ -649,9 +652,18 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|||
List<Param> hostParams = Lists.newArrayList();
|
||||
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));
|
||||
BocloudResult serverResult = this.imsServerService.list(new Pager(1, Integer.MAX_VALUE, hostParams, null));
|
||||
|
||||
List<Server> serverList = ((JSONObject) serverResult.getData()).getJSONArray(Common.ROWS).toJavaList(Server.class);
|
||||
BocloudResult serverResult = new BocloudResult();
|
||||
List<Server> serverList = new ArrayList<>();
|
||||
if (CLOUDTOWER.name().equals(vendorType)) {
|
||||
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());
|
||||
for (Server server : serverList) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
|
|
@ -246,6 +246,7 @@ public class HostServiceImpl implements HostService, InitializingBean {
|
|||
// 查询主机cpu平均使用情况
|
||||
Double cpuUsage = prometheusService
|
||||
.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("cpuUsage", cpuUsage != null ? cpuUsage : "");
|
||||
if (null != serverConfig) {
|
||||
|
@ -258,10 +259,10 @@ public class HostServiceImpl implements HostService, InitializingBean {
|
|||
} else if ("mem".equals(type)) {
|
||||
Double memUsed = prometheusService
|
||||
.simpleQuery("round(vsphere_host_mem_consumed_average{source='" + name + "'}/ 1024 / 1024,0.01)");
|
||||
result.put("memUsed", memUsed != null ? memUsed : "");
|
||||
result.put("memUsed", memUsed != null ? memUsed : serverConfig.getMemUsed());
|
||||
result.put("memTotalCapacity", serverConfig != null ? serverConfig.getMemoryCapacity() : "");
|
||||
if (null != serverConfig && null != memUsed) {
|
||||
result.put("memFree", Double.parseDouble(format.format(serverConfig.getMemoryCapacity() - memUsed)));
|
||||
if (null != serverConfig && result.containsKey("memUsed")) {
|
||||
result.put("memFree", Double.parseDouble(format.format(serverConfig.getMemoryCapacity() - Double.valueOf(result.get("memUsed").toString()))));
|
||||
}
|
||||
} else if ("disk".equals(type)) {
|
||||
if (serverConfig != null) {
|
||||
|
|
|
@ -84,7 +84,7 @@ public class AnalysisHandleRunable implements Runnable {
|
|||
snapshot = monitorAnalysisService.vmAnalysis(JSONObject.parseArray(analysaisRule.getRules()), type, start, end, flag, vendor.getType(), token);
|
||||
break;
|
||||
case "serverCapacityExpansion":
|
||||
snapshot = monitorAnalysisService.hostAnalysis(JSONObject.parseArray(analysaisRule.getRules()), type, start, end, flag, vendor.getType());
|
||||
snapshot = monitorAnalysisService.hostAnalysis(JSONObject.parseArray(analysaisRule.getRules()), type, start, end, flag, vendor.getType(), vendor.getId());
|
||||
break;
|
||||
default:
|
||||
logger.error("未知的类型");
|
||||
|
|
Loading…
Reference in New Issue