Authored by simba

update

... ... @@ -107,6 +107,12 @@
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
... ...
package com.monitor.common.util;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.net.telnet.TelnetClient;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class TelnetUtils {
public final static void main(String[] args) throws Exception {
String string=getResult("192.168.102.222",22222);
JSONObject response=JSONObject.parseObject(string);
System.out.println(string);
System.out.println(response);
}
public static String getResult(String ip, int port) {
TelnetClient telnet = null;
InputStream in = null;
ByteArrayOutputStream baos = null;
try {
telnet = new TelnetClient();
telnet.connect(ip, port);
in = telnet.getInputStream();
baos = new ByteArrayOutputStream();
int i = -1;
while ((i = in.read()) != -1) {
baos.write(i);
}
return baos.toString();
} catch (Exception e) {
return null;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (baos != null) {
try {
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (telnet != null) {
try {
telnet.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
... ...
... ... @@ -5,6 +5,7 @@ import com.model.MObjectInfo;
import com.model.RedisMonitor;
import com.monitor.common.util.HttpRestClient;
import com.monitor.common.util.RedisInfoUtil;
import com.monitor.common.util.TelnetUtils;
import com.monitor.middleware.redis.service.IRedisMonitorHandleService;
import com.monitor.mysql.mapper.MObjectInfoMapper;
import com.monitor.mysql.mapper.RedisMonitorMapper;
... ... @@ -62,8 +63,11 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
List<String> ipList=null;
for(MObjectInfo obj:mlist){
paramMonitor=new StringBuffer();
JSONObject response=httpRestClient.defaultGet("http://" + obj.getMoHostIp() + ":22222/", JSONObject.class);
//JSONObject response=httpRestClient.defaultPost("http://192.168.102.222:22222", null, JSONObject.class);
String result= TelnetUtils.getResult(obj.getMoHostIp(),22222);
if(StringUtils.isBlank(result)){
continue;
}
JSONObject response=JSONObject.parseObject(result);
if(null != response){
int total_connections=(Integer)response.get("total_connections");
int curr_connections=(Integer)response.get("curr_connections");
... ... @@ -124,7 +128,7 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
paramMonitor.append("内存碎片比率:" + result.get("mem_fragmentation_ratio") + ";");
// paramMonitor.append(":"+isSlave+";");
}
redisInfoList.add(new RedisMonitor(key,ipStr,3,paramMonitor.toString()));
redisInfoList.add(new RedisMonitor(key,ipStr,2,paramMonitor.toString()));
}
}
}
... ...
... ... @@ -2,7 +2,6 @@ package com.monitor.middleware.redis.task;
import com.monitor.middleware.redis.service.IRedisMonitorHandleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
... ... @@ -12,7 +11,7 @@ public class RedisMonitorTask {
@Autowired
private IRedisMonitorHandleService redisMonitorService;
@Scheduled(fixedRate=20000)
//@Scheduled(fixedRate=20000)
//@Scheduled(cron="0 0/15 * * * ? ")
public void redisMonitor(){
redisMonitorService.redisMonitor();
... ...