1、优化子网卡流量图形展示。
2、优化接口名称存储逻辑,减少死锁。 3、增加cpu利用率内存利用率字段。
This commit is contained in:
+52
@@ -416,4 +416,56 @@ public class EchartsMoreDataUtils {
|
||||
long timeMillis = time.getTime();
|
||||
return (timeMillis / interval) * interval;
|
||||
}
|
||||
public static Map<String, String> sortInterfaceMap(Map<String, String> interfaceMap, String mainName, boolean hasSub) {
|
||||
List<Map.Entry<String, String>> list = new ArrayList<>(interfaceMap.entrySet());
|
||||
|
||||
list.sort((a, b) -> {
|
||||
String ka = a.getKey(), kb = b.getKey();
|
||||
|
||||
// 总流量优先
|
||||
if (hasSub) {
|
||||
if (ka.startsWith("total")) return -1;
|
||||
if (kb.startsWith("total")) return 1;
|
||||
}
|
||||
|
||||
// 提取接口名
|
||||
String na = ka.replace("netInTraffic", "").replace("netOutTraffic", "");
|
||||
String nb = kb.replace("netInTraffic", "").replace("netOutTraffic", "");
|
||||
|
||||
// 主接口优先
|
||||
if (na.equals(mainName) && !nb.equals(mainName)) return -1;
|
||||
if (!na.equals(mainName) && nb.equals(mainName)) return 1;
|
||||
|
||||
// 点号数量排序
|
||||
int da = na.length() - na.replace(".", "").length();
|
||||
int db = nb.length() - nb.replace(".", "").length();
|
||||
if (da != db) return da - db;
|
||||
|
||||
// 数字排序
|
||||
String[] sa = na.split("\\.");
|
||||
String[] sb = nb.split("\\.");
|
||||
for (int i = 0; i < Math.min(sa.length, sb.length); i++) {
|
||||
try {
|
||||
int numa = Integer.parseInt(sa[i]);
|
||||
int numb = Integer.parseInt(sb[i]);
|
||||
if (numa != numb) return Integer.compare(numa, numb);
|
||||
} catch (Exception e) {
|
||||
int cmp = sa[i].compareTo(sb[i]);
|
||||
if (cmp != 0) return cmp;
|
||||
}
|
||||
}
|
||||
|
||||
// 接口名相同,出站优先
|
||||
if (na.equals(nb)) {
|
||||
if (ka.contains("Out") && kb.contains("In")) return -1; // 出站在前
|
||||
if (ka.contains("In") && kb.contains("Out")) return 1; // 入站在后
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
Map<String, String> result = new LinkedHashMap<>();
|
||||
list.forEach(e -> result.put(e.getKey(), e.getValue()));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user