Commit ab03eb2d authored by liuzengxu's avatar liuzengxu

Update FormViewService.java

parent 1d4c6622
......@@ -34,6 +34,7 @@ import com.cesgroup.cesmonitor.bean.PriorityDetail;
import com.cesgroup.cesmonitor.bean.ResponseTime;
import com.cesgroup.cesmonitor.bean.Timetemp;
import com.cesgroup.cesmonitor.common.Constant;
import com.cesgroup.cesmonitor.common.EhcacheUtil;
import com.cesgroup.cesmonitor.common.JSON;
import com.cesgroup.cesmonitor.common.Util;
import com.cesgroup.cesmonitor.dao.FormViewMapper;
......@@ -87,6 +88,10 @@ public class FormViewService {
for (int i = 0; i < names.length; i++) {
params.addGroupId(formViewMapper.findGroupIdByName(names[i]));
}
if (null == Util.getLoginUser()) {
logger.debug("Util.getLoginUser()未登录");
}
//null
final ZabbixApi zabbixApi = Util.getLoginUser().getZabbixApi();
final HostgroupGetResponse response = zabbixApi.hostgroup().get(request);
final List<com.zabbix4j.hostgroup.HostgroupGetResponse.Result> newlist = new ArrayList<>();
......@@ -529,13 +534,24 @@ public class FormViewService {
/**
*
* @param hostId
* 主机id
* @return 群组id
*/
public Long findGroupIdByHostId(final Long hostId) {
final Long groupId = formViewMapper.findGroupIdByHostId(hostId);
return groupId;
}
/**
*
* @param hosts
* 前端页面保存的ID
* 前端页面保存的ID 当前关注
* @return 单个主机的查询,返回主机CPU,磁盘,内存,可用性等信息
*/
public Map<Long, OneHostConfig> currentFocus(final String hosts) {
final long startTime = System.currentTimeMillis(); //获取开始时间
// final long startTime = System.currentTimeMillis(); //获取开始时间
if (null == hosts || "".equals(hosts.trim())) {
return null;
......@@ -585,6 +601,7 @@ public class FormViewService {
} else {
hostids = hosts.split(",");
}
currentData = new HashMap<Long, OneHostConfig>();
......@@ -596,12 +613,14 @@ public class FormViewService {
for (int i = 0; i < hostids.length; i++) {
final OneHostConfig old = currentData.get(Long.valueOf(hostids[i]));
final Long s = System.currentTimeMillis();
//memory,response,CPU
final List<OneHostConfig> myOneHostConfig = formViewMapper.findOneHostConfigByHostidandTime(
Long.valueOf(hostids[i]),
Constant.USE_MEMORY_RATE, Constant.ICMP_RESPONSE, Constant.CPU_USE_PERCENT,
new Date().getTime() / 1000 - Constant.LATEST_DATA);
System.err.println("查询时间" + (System.currentTimeMillis() - s));
//trigger
final List<OneHostConfig> listHostConfig = formViewMapper
.findOneHostConfigByHostId(Long.valueOf(hostids[i]));
......@@ -640,19 +659,41 @@ public class FormViewService {
}
//host detail
for (final OneHostConfig host : listHostConfig) {
if (null == host) {
old.setTotalException(-1);
old.setMaxPriority(-1);
} else {
old.setName(host.getName());
old.setAvailable(host.getAvailable());
old.setSnmpAvailable(host.getSnmpAvailable());
old.setJmxAvailable(host.getJmxAvailable());
old.setIpmiAvailable(host.getIpmiAvailable());
old.setTotalException(host.getTotalException());
old.setMaxPriority(host.getMaxPriority());
//groupId,hostType,hostId
old.setHostType(host.getHostType());
old.setGroupId(host.getGroupId());
old.setHostId(Long.parseLong(hostids[i]));
if (null == old.getGroupId()) {
Long groupId = this.findGroupIdByHostId(old.getHostId());
old.setGroupId(groupId);
}
//异常为0
if (Integer.valueOf(host.getTotalException()) == 0) {
old.setMaxPriority(-1);
} else if (Integer.valueOf(host.getTotalException()) > 0) {
old.setMaxPriority(host.getMaxPriority());
}
}
}
if (0 == myOneHostConfig.size()) {
......@@ -729,9 +770,6 @@ public class FormViewService {
logger.debug("查询单个主机的各项配置信息失败" + e.getMessage());
e.printStackTrace();
}
final long endTime = System.currentTimeMillis(); //获取结束时间
//System.out.println("程序运行时间:" + (endTime - startTime) + "ms"); //输出程序运行时间
return currentData;
}
......@@ -834,14 +872,26 @@ public class FormViewService {
* 主机组的名字
* @return 根据饼状图点击查出来具体哪个主机组下哪个告警等级的的触发器异常信息
*/
@SuppressWarnings("unchecked")
public List<PriorityDetail> findMessageByPriority(final Integer priority, final String name) {
final Map<Long, PriorityDetail> messagemap = new HashMap<Long, PriorityDetail>();
List<PriorityDetail> list = null;
final TriggerGetRequest request = new TriggerGetRequest();
final TriggerGetRequest.Params params = request.getParams();
params.setExpandDescription(true);
params.setExpandExpression(true);
TriggerGetResponse response = null;
final ZabbixApi zabbixApi = Util.getLoginUser().getZabbixApi();
//不同模块的缓存名称不同,带参数,便于匹配
String ehcacheKey = "messageByPriority" + priority + name;
//根据对应点击模块匹配相应的缓存内容,第一次查询SQL无缓存
if (null != EhcacheUtil.get(ehcacheKey)) {
//logger.info("ehcache:{}", EhcacheUtil.get("messageByPriority" + priority + name));
list = (ArrayList<PriorityDetail>) EhcacheUtil.get("messageByPriority" + priority + name);
Collections.sort(list);
return list;
}
try {
logger.debug("开始根据异常等级查出具体主机异常信息");
List<PriorityDetail> listPriorityDetail = new ArrayList<>();
......@@ -851,6 +901,7 @@ public class FormViewService {
} else {
listPriorityDetail = formViewMapper.findMessageByPriority(priority, "g.name='" + name + "'");
}
//logger.info("1:{}",listPriorityDetail);
final Long[] eventid = new Long[listPriorityDetail.size()];
int index = 0;
......@@ -881,21 +932,31 @@ public class FormViewService {
for (final PriorityDetail pd : lp) {
old.setStartClock(pd.getStartClock());
}
final List<PriorityDetail> acknowledge = formViewMapper.findAcknowledgeByObjectId(old.getObjectid());
for (final PriorityDetail ac : acknowledge) {
old.setAcknowledged(ac.getAcknowledged());
}
/* final List<PriorityDetail> acknowledge = formViewMapper
.findAcknowledgeByObjectId(old.getObjectid());
for (final PriorityDetail ac : acknowledge) {
old.setAcknowledged(ac.getAcknowledged());
}*/
old.setSubClock(Util.getDiff(old.getEndClock() - old.getStartClock()));
}
} catch (final Exception e) {
logger.debug("根据异常等级查出具体主机异常信息失败" + e.getMessage());
e.printStackTrace();
}
final List<PriorityDetail> list = new ArrayList<>(messagemap.values());
//final List<PriorityDetail> list = new ArrayList<>(messagemap.values());
list = new ArrayList<>(messagemap.values());
Collections.sort(list);
// logger.info("{}", ehcacheKey);
//存入缓存,方便二次查询
EhcacheUtil.put(ehcacheKey, list);
// logger.info("ehcache:{}",EhcacheUtil.get(ehcacheKey));
return list;
}
// }
/**
*
* @param str
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment