Authored by jack-xue

增加大数据服务接口监控

... ... @@ -30,6 +30,9 @@ public class SnsMobileConfig {
@Value("${java_api_error}")
private String javaApiError;
@Value("${bigdata_mobile}")
private String bigdataMobile;
public String getBaseMobile() {
return baseMobile;
}
... ... @@ -86,4 +89,13 @@ public class SnsMobileConfig {
public void setJavaApiError(String javaApiError) {
this.javaApiError = javaApiError;
}
public String getBigdataMobile() {
return bigdataMobile;
}
public void setBigdataMobile(String bigdataMobile) {
this.bigdataMobile = bigdataMobile;
}
}
... ...
package com.monitor.javaserver.bigdata;
import lombok.Data;
/**
* Created by jack on 2017/3/23.
*/
@Data
public class AlarmData {
public MetaData yesterday;
public MetaData today;
@Data
public static class MetaData {
public Double singlePrice;
public Long uv;
public Double totalAmount;
public Long pv;
public Long orderCount;
public Double conversionRate;
}
}
... ...
package com.monitor.javaserver.bigdata;
import com.monitor.common.config.SnsMobileConfig;
import com.monitor.common.service.AlarmMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
/**
* Created by jack on 2017/3/23.
*/
@Component
public class BigdataAlarm {
public static final String WATCH_URL = "http://h5.data.yoho.cn/rs/api/getRtChannelDataByPlatform.do?&platform=3";
public static final Integer LIMIT = 2;
@Autowired
public AlarmMsgService alarmMsgService;
@Autowired
private SnsMobileConfig snsMobileConfig;
@Resource(name = "javaapiRestTemplate")
private RestTemplate restTemplate;
private Integer count = 0;
private AlarmData lastAlarmData = null;
@Scheduled(cron = "${cron_bigdata_alarm}")
public void run() {
try {
if (!checkResp()) {
alarm("warn:Data is not update.");
}
count = 0;
} catch (Exception e) {
count++;
} finally {
if (LIMIT <= count) {
alarm("warn:Api response is not 200, continue " + count + " times.");
}
}
}
public void alarm(String content) {
alarmMsgService.sendSms("Bigdata", content, snsMobileConfig.getBigdataMobile());
}
public boolean checkResp() throws RestClientException {
AlarmData alarmData = restTemplate.getForObject(WATCH_URL, AlarmData.class);
if (null == lastAlarmData) {
lastAlarmData = alarmData;
return true;
}
return vsAlarmData(alarmData);
}
public boolean vsAlarmData(AlarmData alarmData) {
if (null == alarmData || null == lastAlarmData) {
return false;
}
if (null == alarmData.getToday() || null == lastAlarmData.getToday()) {
return false;
}
if (alarmData.getToday().equals(lastAlarmData.getToday())) {
return false;
}
this.lastAlarmData = alarmData;
return true;
}
}
... ...
... ... @@ -22,4 +22,6 @@ java_service_alarm_count_threshold=50
union_mobile=18751986615,18652008443,13515100825,18252034289,18001582955,15051889346,17361900581
bigdata_mobile=18652925653,18502542319
java_api_error=18751986615,18652008443,13515100825,18252034289,13951882433,17361900581
... ...
... ... @@ -31,4 +31,6 @@ cron_task_aplipay_voice=0 0/1 * * * ?
cron_task_device_active=0 0/5 * * * ?
device_active_period=60
cron_task_node_mem=0 0/2 * * * ?
\ No newline at end of file
cron_task_node_mem=0 0/2 * * * ?
cron_bigdata_alarm=0 0/1 * * * ?
\ No newline at end of file
... ...