Authored by jack

Merge branch 'dev_memcache'

@@ -146,6 +146,7 @@ public class MemcachedCtrl { @@ -146,6 +146,7 @@ public class MemcachedCtrl {
146 temp.setCpu(temp.getCpu() + "\r\n" + vo.getCpu()); 146 temp.setCpu(temp.getCpu() + "\r\n" + vo.getCpu());
147 temp.setMem(temp.getMem() + "\r\n" + vo.getMem()); 147 temp.setMem(temp.getMem() + "\r\n" + vo.getMem());
148 temp.setNet(temp.getNet() + "\r\n" + vo.getNet()); 148 temp.setNet(temp.getNet() + "\r\n" + vo.getNet());
  149 + temp.setDiff(temp.getDiff()+"\r\n"+vo.getDiff());
149 } 150 }
150 return temp; 151 return temp;
151 } 152 }
@@ -171,7 +172,7 @@ public class MemcachedCtrl { @@ -171,7 +172,7 @@ public class MemcachedCtrl {
171 } 172 }
172 173
173 vo.setUpTime(info.getUpTime()); 174 vo.setUpTime(info.getUpTime());
174 - 175 + vo.setDiff(info.getDiff()+"ms");
175 vo.setCurItems(info.getCurItems()); 176 vo.setCurItems(info.getCurItems());
176 vo.setMaxMemory(info.getMaxMemory()); 177 vo.setMaxMemory(info.getMaxMemory());
177 vo.setCurConnections(info.getCurConnections()); 178 vo.setCurConnections(info.getCurConnections());
@@ -180,6 +181,7 @@ public class MemcachedCtrl { @@ -180,6 +181,7 @@ public class MemcachedCtrl {
180 vo.setUrl(key); 181 vo.setUrl(key);
181 vo.setName(MemConstants.MEMCACHED_NAME_MAP.get(key)); 182 vo.setName(MemConstants.MEMCACHED_NAME_MAP.get(key));
182 183
  184 +
183 //增加twemproxy的内存、cpu、网卡 185 //增加twemproxy的内存、cpu、网卡
184 186
185 ZabbixTaskService zabbixTaskService = SpringContextUtils.getBeanByClass(ZabbixTaskService.class); 187 ZabbixTaskService zabbixTaskService = SpringContextUtils.getBeanByClass(ZabbixTaskService.class);
@@ -27,4 +27,6 @@ public class MemcachedInfo { @@ -27,4 +27,6 @@ public class MemcachedInfo {
27 27
28 private Long oldSet; //前一次监控的set数 28 private Long oldSet; //前一次监控的set数
29 29
  30 + private Long diff;
  31 +
30 } 32 }
@@ -32,4 +32,7 @@ public class MemcachedVo { @@ -32,4 +32,7 @@ public class MemcachedVo {
32 private String mem = "- / -"; 32 private String mem = "- / -";
33 33
34 private String net = "- / -"; 34 private String net = "- / -";
  35 +
  36 + //get、set操作时间差
  37 + private String diff;
35 } 38 }
@@ -12,7 +12,9 @@ import com.monitor.middleware.memcached.constant.MemConstants; @@ -12,7 +12,9 @@ import com.monitor.middleware.memcached.constant.MemConstants;
12 import com.monitor.middleware.memcached.model.MemcachedInfo; 12 import com.monitor.middleware.memcached.model.MemcachedInfo;
13 import com.monitor.zabbix.comp.InfluxdbComp; 13 import com.monitor.zabbix.comp.InfluxdbComp;
14 import net.rubyeye.xmemcached.MemcachedClient; 14 import net.rubyeye.xmemcached.MemcachedClient;
  15 +import net.rubyeye.xmemcached.MemcachedClientBuilder;
15 import net.rubyeye.xmemcached.XMemcachedClient; 16 import net.rubyeye.xmemcached.XMemcachedClient;
  17 +import net.rubyeye.xmemcached.XMemcachedClientBuilder;
16 import net.rubyeye.xmemcached.exception.MemcachedException; 18 import net.rubyeye.xmemcached.exception.MemcachedException;
17 import net.rubyeye.xmemcached.utils.AddrUtil; 19 import net.rubyeye.xmemcached.utils.AddrUtil;
18 import org.apache.commons.lang.StringUtils; 20 import org.apache.commons.lang.StringUtils;
@@ -181,6 +183,19 @@ public class MemcachedMonitorImpl { @@ -181,6 +183,19 @@ public class MemcachedMonitorImpl {
181 info.setMaxMemory(new DecimalFormat("0.00").format(limit_maxbytes * 1.0 / 1024 / 1024 / 1024) + " G"); 183 info.setMaxMemory(new DecimalFormat("0.00").format(limit_maxbytes * 1.0 / 1024 / 1024 / 1024) + " G");
182 info.setUpTime(uptime / (60 * 60 * 24) + " Days"); 184 info.setUpTime(uptime / (60 * 60 * 24) + " Days");
183 info.setUseMemory(new DecimalFormat("0.00").format(bytes * 1.0 / 1024 / 1024 / 1024) + " G"); 185 info.setUseMemory(new DecimalFormat("0.00").format(bytes * 1.0 / 1024 / 1024 / 1024) + " G");
  186 + MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses(url));
  187 + try {
  188 + MemcachedClient client = builder.build();
  189 + long setTime = System.currentTimeMillis();
  190 + client.set("hello",3,"Hello");
  191 + client.get("hello");
  192 + long diff = System.currentTimeMillis()-setTime;
  193 + info.setDiff(diff);
  194 + client.shutdown();
  195 + } catch (Exception e) {
  196 + LOGGER.error("memcached get set occurs Exception"+e.getMessage());
  197 + }
  198 +
184 MemConstants.MEMCACHED_INFO_MAP.put(url, info); 199 MemConstants.MEMCACHED_INFO_MAP.put(url, info);
185 LOGGER.info("MemConstants.MEMCACHED_INFO_MAP all key is {}", MemConstants.MEMCACHED_INFO_MAP.keySet()); 200 LOGGER.info("MemConstants.MEMCACHED_INFO_MAP all key is {}", MemConstants.MEMCACHED_INFO_MAP.keySet());
186 } 201 }