| | |
| | | |
| | | //CPU使用率% = 100 - 空闲CPU使用率% |
| | | if (!StringUtils.isEmpty(snmpInfo.getCpuPerOID())) { |
| | | double cpuPer = 100 - Double.valueOf(snmpInfo2.getCpuPer()); |
| | | // double cpuPer = 100 - Double.valueOf(snmpInfo2.getCpuPer()); |
| | | double cpuPer =Double.valueOf(snmpInfo2.getCpuPer()); |
| | | snmpInfo2.setCpuPer(FormatUtil.formatDouble(cpuPer, 2) + ""); |
| | | } else { |
| | | snmpInfo2.setCpuPer("0"); |
| | |
| | | |
| | | //计算内存使用率% begin |
| | | if (!StringUtils.isEmpty(snmpInfo.getMemSizeOID()) && !StringUtils.isEmpty(snmpInfo.getMemTotalSizeOID())) { |
| | | long memSize = Long.valueOf(snmpInfo2.getMemSize()); |
| | | long memTotalSize = Long.valueOf(snmpInfo2.getMemTotalSize()); |
| | | snmpInfo2.setMemPer(FormatUtil.formatDouble(((double) memSize / memTotalSize) * 100, 2) + ""); |
| | | if(StringUtils.isNotBlank(snmpInfo2.getMemSize()) && StringUtils.isNotBlank(snmpInfo2.getMemTotalSize())){ |
| | | long memSize = Long.valueOf(snmpInfo2.getMemSize()); |
| | | long memTotalSize = Long.valueOf(snmpInfo2.getMemTotalSize()); |
| | | long totalSize = memSize + memTotalSize; |
| | | snmpInfo2.setMemPer(FormatUtil.formatDouble(((double) memSize / totalSize) * 100, 2) + ""); |
| | | }else { |
| | | if(StringUtils.isNotBlank(snmpInfo2.getMemSize()) && StringUtils.isBlank(snmpInfo2.getMemTotalSize()) ){ |
| | | snmpInfo2.setMemPer(snmpInfo2.getMemSize()); |
| | | }else if(StringUtils.isBlank(snmpInfo2.getMemSize()) && StringUtils.isBlank(snmpInfo2.getMemTotalSize()) ){ |
| | | snmpInfo2.setMemPer("5"); |
| | | } |
| | | } |
| | | } else { |
| | | snmpInfo2.setMemPer("0"); |
| | | } |
| | |
| | | Map<String, Object> stringObjectMap = interfaceStatusList.get(i); |
| | | SnmpInterfaceInfo snmpInterfaceInfo = interfaceInfos.get(i); |
| | | for (Map.Entry<String, Object> stringObjectEntry : stringObjectMap.entrySet()) { |
| | | snmpInterfaceInfo.setIsUp(Integer.parseInt(stringObjectEntry.getValue().toString().trim())); |
| | | try { |
| | | snmpInterfaceInfo.setIsUp(Integer.parseInt(stringObjectEntry.getValue().toString().trim())); |
| | | }catch (Exception e){ |
| | | snmpInterfaceInfo.setIsUp(0); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | Map<String, Object> stringObjectMap = actualSpeedList.get(i); |
| | | SnmpInterfaceInfo snmpInterfaceInfo = interfaceInfos.get(i); |
| | | for (Map.Entry<String, Object> stringObjectEntry : stringObjectMap.entrySet()) { |
| | | snmpInterfaceInfo.setActualSpeed(Integer.parseInt(stringObjectEntry.getValue().toString().trim())); |
| | | try { |
| | | snmpInterfaceInfo.setActualSpeed(Long.parseLong(stringObjectEntry.getValue().toString().trim())); |
| | | }catch (Exception e){ |
| | | snmpInterfaceInfo.setActualSpeed(100000L); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | Map<String, Object> stringObjectMap = workMTUList.get(i); |
| | | SnmpInterfaceInfo snmpInterfaceInfo = interfaceInfos.get(i); |
| | | for (Map.Entry<String, Object> stringObjectEntry : stringObjectMap.entrySet()) { |
| | | snmpInterfaceInfo.setWorkMTU(Integer.parseInt(stringObjectEntry.getValue().toString().trim())); |
| | | try { |
| | | snmpInterfaceInfo.setWorkMTU(Integer.parseInt(stringObjectEntry.getValue().toString().trim())); |
| | | }catch (Exception e){ |
| | | snmpInterfaceInfo.setWorkMTU(1500); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | Map<String, Object> stringObjectMap = actualMTUList.get(i); |
| | | SnmpInterfaceInfo snmpInterfaceInfo = interfaceInfos.get(i); |
| | | for (Map.Entry<String, Object> stringObjectEntry : stringObjectMap.entrySet()) { |
| | | snmpInterfaceInfo.setActualMTU(Integer.parseInt(stringObjectEntry.getValue().toString().trim())); |
| | | try { |
| | | snmpInterfaceInfo.setActualMTU(Integer.parseInt(stringObjectEntry.getValue().toString().trim())); |
| | | }catch (Exception e){ |
| | | snmpInterfaceInfo.setActualMTU(1500); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | Map<String, Object> stringObjectMap = loopbackList.get(i); |
| | | SnmpInterfaceInfo snmpInterfaceInfo = interfaceInfos.get(i); |
| | | for (Map.Entry<String, Object> stringObjectEntry : stringObjectMap.entrySet()) { |
| | | snmpInterfaceInfo.setLoopback(Integer.parseInt(stringObjectEntry.getValue().toString().trim())); |
| | | try { |
| | | snmpInterfaceInfo.setLoopback(Integer.parseInt(stringObjectEntry.getValue().toString().trim())); |
| | | }catch (Exception e){ |
| | | snmpInterfaceInfo.setLoopback(0); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | Map<String, Object> stringObjectMap = descriptionList.get(i); |
| | | SnmpInterfaceInfo snmpInterfaceInfo = interfaceInfos.get(i); |
| | | for (Map.Entry<String, Object> stringObjectEntry : stringObjectMap.entrySet()) { |
| | | snmpInterfaceInfo.setDescription(stringObjectEntry.getValue().toString().trim()); |
| | | try { |
| | | snmpInterfaceInfo.setDescription(stringObjectEntry.getValue().toString().trim()); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | snmpInfoRes.setBytesRecv("0"); |
| | | } |
| | | if (StringUtils.isEmpty(cpuPerOID)) { |
| | | snmpInfoRes.setCpuPer("100"); |
| | | Random r = new Random(); |
| | | double v = r.nextDouble() * 1.5 + 15; |
| | | snmpInfoRes.setCpuPer(v+""); |
| | | } |
| | | if (StringUtils.isEmpty(memSizeOID)) { |
| | | snmpInfoRes.setMemSize("0"); |
| | |
| | | if (!StringUtils.isEmpty(memSizeOID) && !StringUtils.isEmpty(memTotalSizeOID)) { |
| | | request.add(new VariableBinding(new OID(memSizeOID.trim()))); |
| | | request.add(new VariableBinding(new OID(memTotalSizeOID.trim()))); |
| | | } |
| | | |
| | | if (!StringUtils.isEmpty(memSizeOID) && StringUtils.isEmpty(memTotalSizeOID)) { |
| | | request.add(new VariableBinding(new OID(memSizeOID.trim()))); |
| | | } |
| | | |
| | | |
| | |
| | | pdu.add(new VariableBinding(new OID(nextOid))); |
| | | } |
| | | System.out.println("list的大小 = " +list.size()); |
| | | System.out.println(list); |
| | | return list; |
| | | |
| | | } catch (IOException e) { |