Authored by Xu

敏感接口比例

... ... @@ -11,10 +11,15 @@ public class MaliciousIpCS {
/**
* 恶意ip
*/
private String ip;
private String userIP;
/**
* QPS
* 总访问次数
*/
private int aCount;
/**
* 敏感接口次数
*/
private int count;
... ... @@ -33,12 +38,20 @@ public class MaliciousIpCS {
*/
private String time;
public String getIp() {
return ip;
public String getUserIP() {
return userIP;
}
public void setUserIP(String userIP) {
this.userIP = userIP;
}
public int getaCount() {
return aCount;
}
public void setIp(String ip) {
this.ip = ip;
public void setaCount(int aCount) {
this.aCount = aCount;
}
public int getCount() {
... ... @@ -75,7 +88,7 @@ public class MaliciousIpCS {
@Override
public String toString() {
return "MaliciousIp [ip=" + ip + ", count=" + count + ", percent=" + percent + ", timestamp=" + timestamp
+ ", time=" + time + "]";
return "MaliciousIpBL [userIP=" + userIP + ", aCount=" + aCount + ", count=" + count + ", percent=" + percent
+ ", timestamp=" + timestamp + ", time=" + time + "]";
}
}
\ No newline at end of file
... ...
... ... @@ -200,6 +200,11 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
}
}
/**
* 比例排序
* @author hui.xu
*
*/
class ComparatorIpBL implements Comparator<MaliciousIpBL> {
public int compare(MaliciousIpBL e1, MaliciousIpBL e2) {
int count1 = e1.getPercent();
... ... @@ -214,6 +219,25 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
}
}
/**
* 次数排序
* @author hui.xu
*
*/
class ComparatorIpCS implements Comparator<MaliciousIpCS> {
public int compare(MaliciousIpCS e1, MaliciousIpCS e2) {
int count1 = e1.getCount();
int count2 = e2.getCount();
if (count1 < count2) {
return 1;
} else if (count1 > count2) {
return -1;
} else {
return 0;
}
}
}
class ComparatorDetailIp implements Comparator<MaliciousDetailIp> {
public int compare(MaliciousDetailIp e1, MaliciousDetailIp e2) {
int count1 = e1.getCount();
... ... @@ -316,8 +340,8 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date;
for (MaliciousIpCS maliciousIp : listMaliciousIp) {
if(StringUtils.isNotBlank(yoho_ip) && StringUtils.isNoneBlank(maliciousIp.getIp())){
String []arrIp = StringUtils.split(maliciousIp.getIp(),'.');
if(StringUtils.isNotBlank(yoho_ip) && StringUtils.isNoneBlank(maliciousIp.getUserIP())){
String []arrIp = StringUtils.split(maliciousIp.getUserIP(),'.');
String inIp = arrIp[0] + "." + arrIp[1];
if(yoho_ip.indexOf(inIp) >= 0){
continue;
... ... @@ -333,7 +357,7 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
newlistMaliciousIp.add(maliciousIp);
}
}
Comparator comp = new ComparatorIp();
Comparator comp = new ComparatorIpCS();
Collections.sort(newlistMaliciousIp, comp);
response.setData(newlistMaliciousIp);
}catch(Exception e){
... ...
... ... @@ -105,7 +105,7 @@ public class RedisReadUtil {
*/
public String getIpsCS() {
Jedis jedis = getJedis();
String value = jedis.get(String.format(MALICIOUS_IP, TIME_DIMENSION_MINUTE_KEY));
String value = jedis.get(String.format(MALICIOUS_IP_BL, TIME_DIMENSION_MINUTE_KEY));
returnResource(jedis);
return value;
}
... ...