Authored by jack.xue

Merge branch 'master' of http://git.yoho.cn/ops/monitor-service

... ... @@ -2,7 +2,6 @@ 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;
... ... @@ -29,11 +28,11 @@ public class RedisMonitorCtrl {
public BaseResponse<Object> getRedisMonitors() throws Exception {
log.info("into getRedisInfo");
// 查询列表
String response = redisMonitorService.getRedisMonitors();
if (StringUtils.isBlank(response)) {
Object response = redisMonitorService.getRedisMonitors();
if (null==response) {
return null;
}
log.info("getRedisInfo success and value {}", response);
log.info("getRedisInfo success and data {}", response);
return new BaseResponse<Object>(response);
}
... ...
... ... @@ -35,7 +35,7 @@ public class ZkMonitorCtrl {
if (response == null || CollectionUtils.isEmpty(response)) {
return null;
}
log.info("getHostInfos success and total={}", response);
log.info("getZkMonitorRecords success and data={}", response);
return new BaseResponse<Object>(response);
}
... ...
... ... @@ -37,19 +37,23 @@ public class RedisMonitorServiceImpl implements IRedisMonitorService {
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){
String color="62D0FE";
if(info.getIsFailed()==0){
color="FF0000";
}
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");
buff.append("<set x=\""+width1+"\" y=\"80\" width=\"120\" height=\"40\" name=\""+info.getNodeFrom()+"\" color=\""+color+"\" 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");
buff.append("<set x=\""+width21+"\" y=\"70\" width=\"120\" height=\"40\" name=\""+info.getNodeTo()+"\" color=\""+color+"\" 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");
buff.append("<set x=\""+width2+"\" y=\"70\" width=\"120\" height=\"40\" name=\""+info.getNodeTo()+"\" color=\""+color+"\" 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");
buff.append("<set x=\""+width3+"\" y=\"55\" width=\"55\" height=\"40\" name=\""+info.getNodeTo() + "\" color=\""+color+"\" id=\""+info.getNodeTo()+"\" />\\n\\\n");
width3+=4;
}
}
... ...
... ... @@ -38,7 +38,7 @@ public class ZkMapper extends InfluxDBQuery implements IZkMapper {
@Override
public void insert(ZkInfo zkInfo) {
log.info("insert zkInfo param ip is {},isLive {}",zkInfo.getHostIp(),zkInfo.getIsLive());
Point point = Point.measurement(InfluxDBContants.ZOOKEEPER_ALARM)
.addField("hostIp", zkInfo.getHostIp())
.addField("cloudType", zkInfo.getCloudType())
... ...
... ... @@ -44,8 +44,8 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
*1、处理twemproxy
***********************************************************************/
List<RedisMonitor> redisInfoList=new ArrayList<RedisMonitor>();
redisInfoList.add(new RedisMonitor("AWS","AWS",0,null));
redisInfoList.add(new RedisMonitor("Qcloud","Qcloud",0,null));
redisInfoList.add(new RedisMonitor("AWS","AWS",0,1,null));
redisInfoList.add(new RedisMonitor("Qcloud","Qcloud",0,1,null));
RedisMonitor redisMonitor=null;
//List<MObjectInfo> mlist= mObjectInfoMapper.getMoInfosByAlias("com_twemproxy");
MObjectInfo a=new MObjectInfo();
... ... @@ -64,31 +64,36 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
for(MObjectInfo obj:mlist){
paramMonitor=new StringBuffer();
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");
if(total_connections>0){
paramMonitor.append("总连接数:"+total_connections);
}
if (total_connections > 0) {
paramMonitor.append("当前接数:"+curr_connections);
}
//查看代理下的redis
JSONObject alpha=response.getJSONObject("alpha");
ipList=new ArrayList<String>();
for (Map.Entry<String, Object> entry : alpha.entrySet()) {
String key=entry.getKey();
if(key.indexOf(":")>1){
ipList.add(key);
redisMonitor = new RedisMonitor();
if(StringUtils.isNotBlank(result)){
//取舍成功重新设为1
JSONObject response=JSONObject.parseObject(result);
if(null != response){
int total_connections=(Integer)response.get("total_connections");
int curr_connections=(Integer)response.get("curr_connections");
if(total_connections>0){
paramMonitor.append("总连接数:"+total_connections);
}
if (total_connections > 0) {
paramMonitor.append("当前接数:"+curr_connections);
}
//查看代理下的redis
JSONObject alpha=response.getJSONObject("alpha");
ipList=new ArrayList<String>();
for (Map.Entry<String, Object> entry : alpha.entrySet()) {
String key=entry.getKey();
if(key.indexOf(":")>1){
ipList.add(key);
}
}
tMap.put(obj.getMoHostIp(),ipList);
redisMonitor.setIsFailed(1);
redisMonitor.setParamMonitor(paramMonitor.toString());
}
tMap.put(obj.getMoHostIp(),ipList);
}else{
redisMonitor.setIsFailed(0);
redisMonitor.setParamMonitor("状态:宕机;");
}
redisMonitor = new RedisMonitor();
if(StringUtils.isNotBlank(obj.getMoName()) && obj.getMoName().contains("aws")){
redisMonitor.setNodeFrom("AWS");
}else if(obj.getMoName().contains("qq")){
... ... @@ -96,10 +101,7 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
}
redisMonitor.setNodeTo(obj.getMoHostIp());
redisMonitor.setLevel(1);
redisMonitor.setParamMonitor(paramMonitor.toString());
redisInfoList.add(redisMonitor);
//obj.setParamMonitor(paramMonitor.toString());
//redisMonitorMapper.updateByPrimaryKey(obj);
}
/**********************************************************************
... ... @@ -117,18 +119,20 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
String[] ipConfig=ipStr.split(":");
Map<String,Object> result=null;
if(ipConfig.length==2){
int isFailed=0;
result= RedisInfoUtil.getRedisInfo(ipConfig[0], Integer.valueOf(ipConfig[1]));
paramMonitor=new StringBuffer();
if(null==result){
paramMonitor.append("状态:宕机;");
}else{
isFailed=1;
String role=(String)result.get("role");
paramMonitor.append("角色:"+role+";");
paramMonitor.append("用量:"+result.get("used_memory_rss")+";");
paramMonitor.append("内存碎片比率:" + result.get("mem_fragmentation_ratio") + ";");
// paramMonitor.append(":"+isSlave+";");
}
redisInfoList.add(new RedisMonitor(key,ipStr,2,paramMonitor.toString()));
redisInfoList.add(new RedisMonitor(key,ipStr,2,isFailed,paramMonitor.toString()));
}
}
}
... ...
package com.monitor.middleware.zookeeper.service.iml;
import com.model.MObjectInfo;
import com.monitor.common.config.SnsMobileConfig;
import com.monitor.common.service.AlarmMsgService;
import com.monitor.influxdb.mapper.IZkMapper;
import com.monitor.influxdb.model.ZkInfo;
import com.monitor.middleware.zookeeper.service.IZkMonitorHandleService;
... ... @@ -35,11 +37,11 @@ public class ZkMonitorHandleServiceImpl implements IZkMonitorHandleService {
@Autowired
MObjectInfoMapper mObjectInfoMapper;
/*@Autowired
@Autowired
public AlarmMsgService alarmMsgService;
@Autowired
private SnsMobileConfig snsMobileConfig;*/
private SnsMobileConfig snsMobileConfig;
public void zookeeperMonitor(){
... ... @@ -56,7 +58,8 @@ public class ZkMonitorHandleServiceImpl implements IZkMonitorHandleService {
for(MObjectInfo obj:mlist){
zk=new ZkInfo();
String ip=obj.getMoHostIp();
int result=checkConnection1(ip);
int result=checkConnection(ip);
log.info("get zookeeper connection is value {}",result);
if(result==0){
alarmList.add(obj);
}
... ... @@ -71,32 +74,34 @@ public class ZkMonitorHandleServiceImpl implements IZkMonitorHandleService {
}
/**********************************************************************
*2、处理zookeeper告警
*2、处理zookeeper告警,统计有哪几台机器挂了
***********************************************************************/
if(CollectionUtils.isEmpty(alarmList)){
return;
}
StringBuffer alarmMsg=new StringBuffer();
for(MObjectInfo alarmObj:alarmList){
alarmMsg.append(alarmObj.getMoHostIp()).append(",");
}
//alarmMsgService.sendSms("zookeeper",alarmMsg.toString(), snsMobileConfig.getOpsManagerDeveloper());
String alarmMsg="[有货监控]您好,zookeeper挂了"+alarmList.size()+"台,请及时查看!";
alarmMsgService.sendSms("zookeeper",alarmMsg, snsMobileConfig.getOpsManagerDeveloper());
log.info("task end...");
}
private int checkConnection1(String ip){
private int checkConnection(String ip){
RetryPolicy retryPolicy=new RetryOneTime(1000);
CuratorFramework client =CuratorFrameworkFactory.newClient(ip+":2181", 5*1000, 5*1000, retryPolicy);
CuratorFramework client =null;
try {
client=CuratorFrameworkFactory.newClient(ip+":2181", 5*1000, 5*1000, retryPolicy);
client.start();
List<String> children = client.getChildren().forPath("/");
log.info("get zookeeper ip {} success",ip);
} catch (Exception e) {
log.error("get zookeeper children failed param ip {}.",ip,e);
return 0;
}finally {
client.close();
if(client!=null){
client.close();
}
}
return 1;
return 1;
}
}
... ...
... ... @@ -19,10 +19,9 @@ public class ZookeeperMonitorTask {
IZkMonitorHandleService zkMonitorService;
//@Scheduled(fixedRate=20000)
@Scheduled(cron="0 0/15 * * * ? ")
@Scheduled(cron="0 0/2 * * * ? ")
public void zookeeperMonitor() {
zkMonitorService.zookeeperMonitor();
}
}
... ...
... ... @@ -4,6 +4,7 @@ import lombok.Data;
@Data
public class RedisMonitor {
private int id;
private String nodeFrom;
... ... @@ -11,18 +12,24 @@ public class RedisMonitor {
private int level;
private int isFailed;
private String paramMonitor;
private String createTime;
private String updateTime;
public RedisMonitor() {
super();
}
public RedisMonitor(String nodeFrom,String nodeTo,int level,String paramMonitor) {
public RedisMonitor(String nodeFrom,String nodeTo,int level,int isFailed,String paramMonitor) {
super();
this.nodeFrom = nodeFrom;
this.nodeTo = nodeTo;
this.level = level;
this.isFailed=isFailed;
this.paramMonitor=paramMonitor;
}
... ...
... ... @@ -7,11 +7,12 @@
<result column="node_to" property="nodeTo" jdbcType="VARCHAR" />
<result column="level" property="level" jdbcType="TINYINT" />
<result column="param_monitor" property="paramMonitor" jdbcType="VARCHAR" />
<result column="is_failed" property="isFailed" jdbcType="TINYINT" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List" >
id, node_from, node_to, level, param_monitor, create_time, update_time
id, node_from, node_to, level,is_failed, param_monitor, create_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
... ... @@ -25,10 +26,10 @@
</delete>
<insert id="insert" parameterType="com.model.RedisMonitor" >
insert into redis_monitor (id, node_from, node_to,
level, param_monitor, create_time,
level,is_failed, param_monitor, create_time,
update_time)
values (#{id,jdbcType=BIGINT}, #{nodeFrom,jdbcType=VARCHAR}, #{nodeTo,jdbcType=VARCHAR},
#{level,jdbcType=TINYINT}, #{paramMonitor,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
#{level,jdbcType=TINYINT},#{isFailed,jdbcType=TINYINT}, #{paramMonitor,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.model.RedisMonitor" >
... ... @@ -46,6 +47,9 @@
<if test="level != null" >
level,
</if>
<if test="isFailed != null" >
is_failed,
</if>
<if test="paramMonitor != null" >
param_monitor,
</if>
... ... @@ -69,6 +73,9 @@
<if test="level != null" >
#{level,jdbcType=TINYINT},
</if>
<if test="isFailed != null" >
#{isFailed,jdbcType=TINYINT},
</if>
<if test="paramMonitor != null" >
#{paramMonitor,jdbcType=VARCHAR},
</if>
... ... @@ -92,6 +99,9 @@
<if test="level != null" >
level = #{level,jdbcType=TINYINT},
</if>
<if test="isFailed != null" >
is_failed = #{isFailed,jdbcType=TINYINT},
</if>
<if test="paramMonitor != null" >
param_monitor = #{paramMonitor,jdbcType=VARCHAR},
</if>
... ... @@ -109,6 +119,7 @@
set node_from = #{nodeFrom,jdbcType=VARCHAR},
node_to = #{nodeTo,jdbcType=VARCHAR},
level = #{level,jdbcType=TINYINT},
is_failed = #{isFailed,jdbcType=TINYINT},
param_monitor = #{paramMonitor,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}
... ... @@ -121,11 +132,11 @@
<insert id="bachInsertRedisMonitor" parameterType="com.model.RedisMonitor">
insert into redis_monitor
(node_from, node_to,level, param_monitor)
(node_from, node_to,level,is_failed,param_monitor)
values
<foreach collection="list" item="item" index="index"
separator=",">
(#{item.nodeFrom},#{item.nodeTo},#{item.level},#{item.paramMonitor})
(#{item.nodeFrom},#{item.nodeTo},#{item.level},#{item.isFailed},#{item.paramMonitor})
</foreach>
</insert>
... ...
... ... @@ -16,7 +16,7 @@
<appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.home}/logs/warn.log</file>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
<level>WARN</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
... ...
... ... @@ -2,8 +2,7 @@
influxdb.num=2
influxdb.name=test;alarm
influxdb.ip=http://192.168.102.162:8086;http://123.206.79.151:18086
#influxdb.ip=http://192.168.102.162:8086;http://192.168.99.100:32768
influxdb.ip=http://192.168.102.162:8086;http://172.16.6.104:8086
influxdb.user=yoho;root
influxdb.pwd=Yoho_9646;root
influxdb.connect.timeout=15;15
... ...