Authored by jack.xue

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

... ... @@ -7,7 +7,7 @@ import java.util.HashMap;
import java.util.Map;
public class RedisInfo {
public class RedisInfoUtil {
public static Map<String,Object> getRedisInfo(String host,int port){
Jedis client = new Jedis(host, port);
... ...
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:task="http://www.springframework.org/schema/task"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
<bean id="javaapi_ConnectionManager" class="org.apache.http.impl.conn.PoolingHttpClientConnectionManager">
<property name="maxTotal" value="40" />
... ... @@ -21,8 +21,8 @@
<bean id="javaapi_clientHttpRequestFactory"
class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
<constructor-arg ref="javaapi_httpClient" />
<property name="connectTimeout" value="800" />
<property name="readTimeout" value="1200" />
<property name="connectTimeout" value="3000" />
<property name="readTimeout" value="3000" />
</bean>
<bean id="javaapiRestTemplate" class="org.springframework.web.client.RestTemplate">
... ...
package com.monitor.middleware.redis.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.model.MObjectInfo;
import com.model.RedisInfo;
import com.monitor.common.util.HttpRestClient;
import com.monitor.common.util.RedisInfo;
import com.monitor.common.util.RedisInfoUtil;
import com.monitor.middleware.redis.service.IRedisMonitorService;
import com.monitor.mysql.mapper.RedisMonitorMapper;
import com.monitor.mysql.mapper.MObjectInfoMapper;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -21,26 +24,30 @@ public class RedisMonitorServiceImpl implements IRedisMonitorService {
Logger log = LoggerFactory.getLogger(RedisMonitorServiceImpl.class);
@Autowired
RedisMonitorMapper redisMonitorMapper;
HttpRestClient httpRestClient;
@Autowired
HttpRestClient httpRestClient;
MObjectInfoMapper mObjectInfoMapper;
@Override
public void redisMonitor() {
/**********************************************************************
*1、处理twemproxy
***********************************************************************/
List<com.model.RedisInfo> proxyList=redisMonitorMapper.selectRedisMonitorByLevel(1);
if(CollectionUtils.isEmpty(proxyList)){
List<RedisInfo> redisInfoList=new ArrayList<RedisInfo>();
redisInfoList.add(new RedisInfo("AWS","AWS",0,null));
redisInfoList.add(new RedisInfo("Qcloud","Qcloud",0,null));
RedisInfo redisInfo=null;
List<MObjectInfo> mlist= mObjectInfoMapper.getMoInfosByAlias("com_twemproxy");
if(CollectionUtils.isEmpty(mlist)){
return;
}
StringBuffer paramMonitor=null;
//遍历twemproxy
Map<String,List<String>> tMap=new HashMap<String,List<String>>();
List<String> ipList=null;
for(com.model.RedisInfo obj:proxyList){
for(MObjectInfo obj:mlist){
paramMonitor=new StringBuffer();
//JSONObject response=httpRestClient.defaultPost(obj.getHostIp()+obj.getParamMonitor(), null, JSONObject.class);
JSONObject response=httpRestClient.defaultPost("http://192.168.102.222:22222", null, JSONObject.class);
... ... @@ -62,10 +69,20 @@ public class RedisMonitorServiceImpl implements IRedisMonitorService {
ipList.add(key);
}
}
tMap.put(obj.getHostIp(),ipList);
tMap.put(obj.getMoHostIp(),ipList);
}
obj.setParamMonitor(paramMonitor.toString());
redisMonitorMapper.updateByPrimaryKey(obj);
redisInfo = new RedisInfo();
if(StringUtils.isNotBlank(obj.getMoName()) && obj.getMoName().contains("aws")){
redisInfo.setNodeFrom("AWS");
}else if(obj.getMoName().contains("qq")){
redisInfo.setNodeFrom("Qcloud");
}
redisInfo.setNodeTo(obj.getMoHostIp());
redisInfo.setLevel(1);
redisInfo.setParamMonitor(paramMonitor.toString());
redisInfoList.add(redisInfo);
//obj.setParamMonitor(paramMonitor.toString());
//redisMonitorMapper.updateByPrimaryKey(obj);
}
/**********************************************************************
... ... @@ -74,7 +91,7 @@ public class RedisMonitorServiceImpl implements IRedisMonitorService {
if(tMap.size()==0){
return;
}
Map<String,Object> rMap=new HashMap<String,Object>();
for (Map.Entry<String, List<String>> entry : tMap.entrySet()) {
String key = entry.getKey().toString();
List<String> rlist = entry.getValue();
... ... @@ -83,12 +100,21 @@ public class RedisMonitorServiceImpl implements IRedisMonitorService {
String[] ipConfig=ipStr.split(":");
Map<String,Object> result=null;
if(ipConfig.length==2){
result=RedisInfo.getRedisInfo(ipConfig[0],Integer.valueOf(ipConfig[1]));
rMap.put(ipConfig[0],result);
result= RedisInfoUtil.getRedisInfo(ipConfig[0], Integer.valueOf(ipConfig[1]));
paramMonitor=new StringBuffer();
if(null==result){
paramMonitor.append("状态:宕机;");
}else{
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 RedisInfo(key,ipStr,3,paramMonitor.toString()));
}
}
}
}
}
}
... ...
... ... @@ -17,6 +17,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
/**
... ... @@ -36,15 +37,23 @@ public class ZkMonitorServiceImpl implements IZkMonitorService {
public void zookeeperMonitor(){
/**********************************************************************
*1、处理zookeeper采集数据信息
***********************************************************************/
List<MObjectInfo> mlist= mObjectInfoMapper.getMoInfosByAlias("zookeeper");
if(CollectionUtils.isEmpty(mlist)){
return;
}
ZkInfo zk=null;
List<MObjectInfo> alarmList= new ArrayList<MObjectInfo>();
for(MObjectInfo obj:mlist){
zk=new ZkInfo();
String ip=obj.getMoHostIp();
int result=checkConnection1(ip);
if(result==0){
alarmList.add(obj);
}
zk.setHostIp(ip);
zk.setIsLive(result);
if(StringUtils.isNotBlank(obj.getMoName()) && obj.getMoName().contains("aws")){
... ... @@ -55,6 +64,10 @@ public class ZkMonitorServiceImpl implements IZkMonitorService {
zookeeperMapper.insert(zk);
}
/**********************************************************************
*1、处理zookeeper告警
***********************************************************************/
log.info("task end...");
}
... ...
... ... @@ -19,7 +19,7 @@ public class ZookeeperMonitorTask {
IZkMonitorService zkMonitorService;
//@Scheduled(fixedRate=20000)
@Scheduled(cron="0 */15 * * * ?")
@Scheduled(cron="0 0/15 * * * ? ")
public void zookeeperMonitor() {
zkMonitorService.zookeeperMonitor();
}
... ...
package com.model;
import lombok.Data;
@Data
public class RedisInfo {
private String id;
private String alias;
private String hostIp;
private String port;
private int port;
private int level;
private String nodeFrom;
private String nodeTo;
... ... @@ -15,100 +18,16 @@ public class RedisInfo {
private String createTime;
private String updateTime;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public String getHostIp() {
return hostIp;
}
public void setHostIp(String hostIp) {
this.hostIp = hostIp;
}
public String getPort() {
return port;
}
public void setPort(String port) {
this.port = port;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public String getNodeFrom() {
return nodeFrom;
public RedisInfo() {
super();
}
public void setNodeFrom(String nodeFrom) {
public RedisInfo(String nodeFrom,String nodeTo,int level,String paramMonitor) {
super();
this.nodeFrom = nodeFrom;
}
public String getNodeTo() {
return nodeTo;
}
public void setNodeTo(String nodeTo) {
this.nodeTo = nodeTo;
}
public String getParamMonitor() {
return paramMonitor;
}
public void setParamMonitor(String paramMonitor) {
this.paramMonitor = paramMonitor;
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
public int getCloudType() {
return cloudType;
}
public void setCloudType(int cloudType) {
this.cloudType = cloudType;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getUpdateTime() {
return updateTime;
}
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
this.level = level;
this.paramMonitor=paramMonitor;
}
}
... ...
... ... @@ -13,42 +13,46 @@
<!-- 日志最大的文件大小 10MB-->
<property name="maxFileSize" value="10MB"/>
<!-- WARN级别日志 appender -->
<appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/Data/tomcat_logs/monitor/warn-log</file>
<!-- 过滤器,过滤掉 TRACE 和 DEBUG 和 INFO 级别的日志 -->
<file>${catalina.home}/logs/warn.log</file>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>WARN</level>
<level>ERROR</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 按天回滚 daily -->
<fileNamePattern>${catalina.home}/logs/%d{yyyy-MM-dd}/warn-log.log</fileNamePattern>
<!-- 日志最大的保存天数 -->
<!-- daily rollover -->
<fileNamePattern>
${catalina.home}/logs/warn.%d{yyyy-MM-dd}.%i.log.gz
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 100MB -->
<maxFileSize>${maxFileSize}</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 30 days' worth of history -->
<maxHistory>${maxHistory}</maxHistory>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>${maxFileSize}</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
<pattern>%-1relative - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}:%line -- %msg%n</pattern>
</encoder>
</appender>
<!-- DEBUG级别日志 appender -->
<appender name="DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/Data/tomcat_logs/monitor/debug-log</file>
<file>${catalina.home}/logs/debug.log</file>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 按天回滚 daily -->
<fileNamePattern>${catalina.home}/logs/%d{yyyy-MM-dd}/debug-log.log</fileNamePattern>
<fileNamePattern>
${catalina.home}/logs/debug.%d{yyyy-MM-dd}.%i.log.gz
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 100MB -->
<maxFileSize>${maxFileSize}</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- 日志最大的历史 60天 -->
<maxHistory>${maxHistory}</maxHistory>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>${maxFileSize}</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
... ...
# ******************** send sms common configs ********************
sendsms.url=http://221.179.180.158:9009/HttpQuickProcess_utf-8/submitMessageAll
sendsms.username=yoho
sendsms.pwd=EMKVpwoJ
sendsms.username=yohoyw
sendsms.pwd=NCftHmJ9
sendsms.notice.productid=8
#---------------国都短信业务api参数----------------------
sendsms.guodu.Url=http://221.179.180.158:9007/QxtSms/QxtFirewall
sendsms.guodu.OperID=yoho
sendsms.guodu.OperPass=EMKVpwoJ
#---------------国都短信业务api参数----------------------
base_mobile=15905144483,18751986615,18652008443
#------------------------------------------支付回调手机号------------------------------------------------
... ...