Authored by simba

update

Showing 12 changed files with 161 additions and 34 deletions
package com.monitor.cmdb.ctrl;
import com.monitor.cmdb.service.IRedisMonitorService;
import com.monitor.model.response.BaseResponse;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by yoho on 2016/6/14.
* 查询机器信息
*/
@Controller
@RequestMapping("redisMonitor")
public class RedisMonitorCtrl {
Logger log = LoggerFactory.getLogger(RedisMonitorCtrl.class);
@Autowired
IRedisMonitorService redisMonitorService;
@RequestMapping("/getRedisInfo")
@ResponseBody
public BaseResponse<Object> getRedisMonitors() throws Exception {
log.info("into getRedisInfo");
// 查询列表
String response = redisMonitorService.getRedisMonitors();
if (StringUtils.isBlank(response)) {
return null;
}
log.info("getRedisInfo success and value {}", response);
return new BaseResponse<Object>(response);
}
}
... ...
package com.monitor.cmdb.service;
/**
* Created by yoho on 2016/7/5.
*/
public interface IRedisMonitorService {
String getRedisMonitors();
}
... ...
package com.monitor.cmdb.service.impl;
import com.model.RedisMonitor;
import com.monitor.cmdb.service.IRedisMonitorService;
import com.monitor.mysql.mapper.RedisMonitorMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
/**
* Created by yoho on 2016/7/5.
*/
@Service
public class RedisMonitorServiceImpl implements IRedisMonitorService {
@Autowired
RedisMonitorMapper redisMonitorMapper;
@Override
public String getRedisMonitors() {
List<RedisMonitor> list= redisMonitorMapper.selectAllRedisMonitors();
if(CollectionUtils.isEmpty(list)){
return null;
}
return backChart(list);
}
private String backChart(List<RedisMonitor> list){
StringBuffer buff = new StringBuffer();
int width1=12;
int width2=8;
int width21=30;
int width3=4;
buff.append("'<chart charttopmargin=\"0\" chartBottomMargin=\"0\" chartleftmargin=\"0\" chartrightmargin=\"0\" bordercolor=\"#FFFFFF\" border=\"0\" borderAlpha=\"0\" borderThickness=\"0\" canvasBorderThickness=\"0\" canvasBorderColor=\"#FFFFFF\" showFormBtn=\"0\">\\n\\\n");
buff.append("<dataset plotborderAlpha=\"0\" >\\n\\\n");
for(RedisMonitor info : list){
if(info.getLevel()==0){
buff.append("<set x=\""+width1+"\" y=\"80\" width=\"120\" height=\"40\" name=\""+info.getNodeFrom()+"\" color=\"62D0FE\" id=\""+info.getNodeTo()+"\" tooltext= \""+info.getParamMonitor()+"\" />\\n\\\n");
width1+=18;
}else if(info.getLevel()==1){
if(info.getNodeFrom().equals("Qcloud")){
buff.append("<set x=\""+width21+"\" y=\"70\" width=\"120\" height=\"40\" name=\""+info.getNodeFrom()+"\" color=\"62D0FE\" id=\""+info.getNodeTo()+"\" />\\n\\\n");
width21+=8;
}else{
buff.append("<set x=\""+width2+"\" y=\"70\" width=\"120\" height=\"40\" name=\""+info.getNodeFrom()+"\" color=\"62D0FE\" id=\""+info.getNodeTo()+"\" />\\n\\\n");
width2+=8;
}
}else if(info.getLevel()==2){
buff.append("<set x=\""+width3+"\" y=\"55\" width=\"55\" height=\"40\" name=\""+info.getNodeFrom()+"\" color=\"62D0FE\" id=\""+info.getNodeTo()+"\" />\\n\\\n");
width3+=4;
}
}
buff.append("</dataset>\\n\\\n");
buff.append("<connectors color=\"83C6E1\" stdThickness=\"8\">\\n\\\n");
for(RedisMonitor info : list){
buff.append("<connector strength=\"0.45\" from=\""+info.getNodeFrom()+"\" to=\""+info.getNodeTo()+"\" arrowAtStart=\"0\" arrowAtEnd=\"0\"/>\\n\\\n");
}
buff.append("</connectors>\\n\\\n</chart>'");
System.out.println(buff.toString());
return buff.toString();
}
}
... ...
package com.monitor.middleware.redis.service;
public interface IRedisMonitorService {
public interface IRedisMonitorHandleService {
void redisMonitor();
... ...
... ... @@ -5,13 +5,14 @@ import com.model.MObjectInfo;
import com.model.RedisMonitor;
import com.monitor.common.util.HttpRestClient;
import com.monitor.common.util.RedisInfoUtil;
import com.monitor.middleware.redis.service.IRedisMonitorService;
import com.monitor.middleware.redis.service.IRedisMonitorHandleService;
import com.monitor.mysql.mapper.MObjectInfoMapper;
import com.monitor.mysql.mapper.RedisMonitorMapper;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
... ... @@ -20,10 +21,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
@EnableScheduling
@Service
public class RedisMonitorServiceImpl implements IRedisMonitorService {
public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService {
Logger log = LoggerFactory.getLogger(RedisMonitorServiceImpl.class);
Logger log = LoggerFactory.getLogger(RedisMonitorHandleServiceImpl.class);
@Autowired
HttpRestClient httpRestClient;
... ...
package com.monitor.middleware.redis.service.impl;
import com.model.RedisMonitor;
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer();
List<RedisInfo> list = new ArrayList<RedisInfo>();
List<RedisMonitor> list = new ArrayList<RedisMonitor>();
int width1=12;
int width2=8;
int width21=30;
int width3=4;
RedisInfo redis1 = new RedisInfo();
RedisMonitor redis1 = new RedisMonitor();
redis1.setNodeFrom("AWS");
redis1.setNodeTo("172.31.19.49:6379");
redis1.setLevel(1);
list.add(redis1);
RedisInfo redis2 = new RedisInfo();
RedisMonitor redis2 = new RedisMonitor();
redis2.setNodeFrom("AWS");
redis2.setNodeTo("172.31.24.61:6379");
redis2.setLevel(1);
list.add(redis2);
RedisInfo redis3 = new RedisInfo();
RedisMonitor redis3 = new RedisMonitor();
redis3.setNodeFrom("172.31.19.49:6379");
redis3.setNodeTo("172.31.19.49:16379");
redis3.setLevel(2);
list.add(redis3);
RedisInfo redis4 = new RedisInfo();
RedisMonitor redis4 = new RedisMonitor();
redis4.setNodeFrom("172.31.19.49:6379");
redis4.setNodeTo("172.31.19.49:26379");
redis4.setLevel(2);
list.add(redis4);
RedisInfo redis5 = new RedisInfo();
RedisMonitor redis5 = new RedisMonitor();
redis5.setNodeFrom("172.31.24.61:6379");
redis5.setNodeTo("172.31.24.61:16379");
redis5.setLevel(2);
list.add(redis5);
RedisInfo redis6 = new RedisInfo();
RedisMonitor redis6 = new RedisMonitor();
redis6.setNodeFrom("172.31.24.61:6379");
redis6.setNodeTo("172.31.24.61:26379");
redis6.setLevel(2);
list.add(redis6);
RedisInfo redis7 = new RedisInfo();
RedisMonitor redis7 = new RedisMonitor();
redis7.setNodeFrom("AWS");
redis7.setNodeTo("AWS");
redis7.setLevel(0);
redis7.setParamMonitor("AWS");
list.add(redis7);
RedisInfo redis10 = new RedisInfo();
RedisMonitor redis10 = new RedisMonitor();
redis10.setNodeFrom("Qcloud");
redis10.setNodeTo("10.66.4.2:6379");
redis10.setLevel(1);
list.add(redis10);
RedisInfo redis20 = new RedisInfo();
RedisMonitor redis20 = new RedisMonitor();
redis20.setNodeFrom("10.66.4.2:6379");
redis20.setNodeTo("10.66.4.2:16379");
redis20.setLevel(2);
list.add(redis20);
RedisInfo redis30 = new RedisInfo();
RedisMonitor redis30 = new RedisMonitor();
redis30.setNodeFrom("10.66.4.2:6379");
redis30.setNodeTo("10.66.4.2:26379");
redis30.setLevel(2);
list.add(redis30);
RedisInfo redis40 = new RedisInfo();
RedisMonitor redis40 = new RedisMonitor();
redis40.setNodeFrom("10.66.4.2:6379");
redis40.setNodeTo("10.66.4.10:16379");
redis40.setLevel(2);
list.add(redis40);
RedisInfo redis50 = new RedisInfo();
RedisMonitor redis50 = new RedisMonitor();
redis50.setNodeFrom("10.66.4.2:6379");
redis50.setNodeTo("10.66.4.10:26379");
redis50.setLevel(2);
list.add(redis50);
RedisInfo redis60 = new RedisInfo();
RedisMonitor redis60 = new RedisMonitor();
redis60.setNodeFrom("10.66.4.2:6379");
redis60.setNodeTo("10.66.4.11:16379");
redis60.setLevel(2);
list.add(redis60);
RedisInfo redis70 = new RedisInfo();
RedisMonitor redis70 = new RedisMonitor();
redis70.setNodeFrom("Qcloud");
redis70.setNodeTo("Qcloud");
redis70.setLevel(0);
... ... @@ -88,12 +90,12 @@ public class Test {
buff.append("'<chart charttopmargin=\"0\" chartBottomMargin=\"0\" chartleftmargin=\"0\" chartrightmargin=\"0\" bordercolor=\"#FFFFFF\" border=\"0\" borderAlpha=\"0\" borderThickness=\"0\" canvasBorderThickness=\"0\" canvasBorderColor=\"#FFFFFF\" showFormBtn=\"0\">\\n\\\n");
buff.append("<dataset plotborderAlpha=\"0\" >\\n\\\n");
for(RedisInfo info : list){
for(RedisMonitor info : list){
if(info.getLevel()==0){
buff.append("<set x=\""+width1+"\" y=\"80\" width=\"120\" height=\"40\" name=\""+info.getNodeFrom()+"\" color=\"62D0FE\" id=\""+info.getNodeTo()+"\" tooltext= \""+info.getParamMonitor()+"\" />\\n\\\n");
width1+=18;
}else if(info.getLevel()==1){
if(info.getId().equals("Qcloud")){
if(info.getNodeFrom().equals("Qcloud")){
buff.append("<set x=\""+width21+"\" y=\"70\" width=\"120\" height=\"40\" name=\""+info.getNodeFrom()+"\" color=\"62D0FE\" id=\""+info.getNodeTo()+"\" />\\n\\\n");
width21+=8;
}else{
... ... @@ -107,7 +109,7 @@ public class Test {
}
buff.append("</dataset>\\n\\\n");
buff.append("<connectors color=\"83C6E1\" stdThickness=\"8\">\\n\\\n");
for(RedisInfo info : list){
for(RedisMonitor info : list){
buff.append("<connector strength=\"0.45\" from=\""+info.getNodeFrom()+"\" to=\""+info.getNodeTo()+"\" arrowAtStart=\"0\" arrowAtEnd=\"0\"/>\\n\\\n");
}
buff.append("</connectors>\\n\\\n</chart>'");
... ...
package com.monitor.middleware.redis.task;
import com.monitor.middleware.redis.service.IRedisMonitorService;
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;
@Component
public class RedisMonitorTask {
@Autowired
private IRedisMonitorService redisMonitorService;
private IRedisMonitorHandleService redisMonitorService;
//@Scheduled(fixedRate=20000)
// @Scheduled(cron="0 */5 * * * ?")
@Scheduled(cron="0 0/15 * * * ? ")
public void redisMonitor(){
redisMonitorService.redisMonitor();
}
... ...
... ... @@ -3,7 +3,7 @@ package com.monitor.middleware.zookeeper.service;
/**
* Created by yoho on 2016/6/21.
*/
public interface IZkMonitorService {
public interface IZkMonitorHandleService {
public void zookeeperMonitor();
... ...
... ... @@ -3,7 +3,7 @@ package com.monitor.middleware.zookeeper.service.iml;
import com.model.MObjectInfo;
import com.monitor.influxdb.mapper.IZkMapper;
import com.monitor.influxdb.model.ZkInfo;
import com.monitor.middleware.zookeeper.service.IZkMonitorService;
import com.monitor.middleware.zookeeper.service.IZkMonitorHandleService;
import com.monitor.mysql.mapper.MObjectInfoMapper;
import org.apache.commons.lang.StringUtils;
import org.apache.curator.RetryPolicy;
... ... @@ -25,9 +25,9 @@ import java.util.List;
*/
@EnableScheduling
@Service
public class ZkMonitorServiceImpl implements IZkMonitorService {
public class ZkMonitorHandleServiceImpl implements IZkMonitorHandleService {
Logger log = LoggerFactory.getLogger(ZkMonitorServiceImpl.class);
Logger log = LoggerFactory.getLogger(ZkMonitorHandleServiceImpl.class);
@Autowired
IZkMapper zookeeperMapper;
... ...
package com.monitor.middleware.zookeeper.task;
import com.monitor.middleware.zookeeper.service.IZkMonitorService;
import com.monitor.middleware.zookeeper.service.IZkMonitorHandleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -16,7 +16,7 @@ public class ZookeeperMonitorTask {
Logger log = LoggerFactory.getLogger(ZookeeperMonitorTask.class);
@Autowired
IZkMonitorService zkMonitorService;
IZkMonitorHandleService zkMonitorService;
//@Scheduled(fixedRate=20000)
@Scheduled(cron="0 0/15 * * * ? ")
... ...
... ... @@ -20,4 +20,6 @@ public interface RedisMonitorMapper {
int updateByPrimaryKey(RedisMonitor record);
int bachInsertRedisMonitor(@Param("list") List<RedisMonitor> list);
List<RedisMonitor> selectAllRedisMonitors();
}
\ No newline at end of file
... ...
... ... @@ -114,6 +114,7 @@
update_time = #{updateTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=BIGINT}
</update>
<insert id="bachInsertRedisMonitor" parameterType="com.model.RedisMonitor">
insert into redis_monitor
(node_from, node_to,level, param_monitor)
... ... @@ -124,4 +125,10 @@
</foreach>
</insert>
<select id="selectAllRedisMonitors" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from redis_monitor
</select>
</mapper>
\ No newline at end of file
... ...