Authored by saihide

monitor

... ... @@ -33,6 +33,6 @@
</select>
<select id="selectCountGroupByDateId" resultMap="MonitorResultMap">
SELECT date_id, count(*) num FROM bigdata_skn_pricearea GROUP BY date_id ORDER BY date_id desc LIMIT 3
SELECT date_id, count(*) num FROM bigdata_skn_pricearea GROUP BY date_id ORDER BY date_id desc LIMIT 2
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -71,6 +71,6 @@
select max(date_id) from product_15day_salesnum
</select>
<select id="selectCountGroupByDateId" resultMap="MonitorResultMap">
SELECT date_id, count(*) num FROM product_15day_salesnum GROUP BY date_id ORDER BY date_id desc LIMIT 3
SELECT date_id, count(*) num FROM product_15day_salesnum GROUP BY date_id ORDER BY date_id desc LIMIT 2
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -68,7 +68,7 @@
</delete>
<select id="selectCountGroupByDateId" resultMap="MonitorResultMap">
SELECT date_id, count(*) num FROM product_heat_values GROUP BY date_id ORDER BY date_id desc LIMIT 3
SELECT date_id, count(*) num FROM product_heat_values GROUP BY date_id ORDER BY date_id desc LIMIT 2
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -68,7 +68,7 @@
</delete>
<select id="selectCountGroupByDateId" resultMap="MonitorResultMap">
SELECT date_id, count(*) num FROM product_heat_values_oneday GROUP BY date_id ORDER BY date_id desc LIMIT 3
SELECT date_id, count(*) num FROM product_heat_values_oneday GROUP BY date_id ORDER BY date_id desc LIMIT 2
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -96,6 +96,6 @@
</delete>
<select id="selectCountGroupByDateId" resultMap="MonitorResultMap">
SELECT date_id, count(*) num FROM product_model_value GROUP BY date_id ORDER BY date_id desc LIMIT 3
SELECT date_id, count(*) num FROM product_model_value GROUP BY date_id ORDER BY date_id desc LIMIT 2
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -49,6 +49,6 @@
</delete>
<select id="selectCountGroupByDateId" resultMap="MonitorResultMap">
SELECT date_id, count(*) num FROM product_sales_info GROUP BY date_id ORDER BY date_id desc LIMIT 3
SELECT date_id, count(*) num FROM product_sales_info GROUP BY date_id ORDER BY date_id desc LIMIT 2
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -53,6 +53,6 @@
</foreach>
</delete>
<select id="selectCountGroupByDateId" resultMap="MonitorResultMap">
SELECT generate_date, count(*) num FROM product_vector_feature GROUP BY generate_date ORDER BY generate_date desc LIMIT 3
SELECT generate_date, count(*) num FROM product_vector_feature GROUP BY generate_date ORDER BY generate_date desc LIMIT 2
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -40,6 +40,6 @@
</delete>
<select id="selectCountGroupByDateId" resultMap="MonitorResultMap">
SELECT date_id, count(*) num FROM bigdata_similar_skn GROUP BY date_id ORDER BY date_id desc LIMIT 3
SELECT date_id, count(*) num FROM bigdata_similar_skn GROUP BY date_id ORDER BY date_id desc LIMIT 2
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -83,6 +83,6 @@
</foreach>
</delete>
<select id="selectCountGroupByDateId" resultMap="MonitorResultMap">
select date_id,flow_type,count(*) num from skn_flow group by date_id,flow_type order by date_id desc limit 6;
select date_id,flow_type,count(*) num from skn_flow group by date_id,flow_type order by date_id desc limit 4;
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -4,23 +4,27 @@
package com.yoho.search.consumer.common;
import com.sun.org.apache.regexp.internal.RE;
public class ApiResponse<T> {
private String message;
private int code;
private T data;
public static <T> ApiResponse<T> create(int code, T data) {
public static <T> ApiResponse<T> createSuccess(T data) {
ApiResponse<T> rsp = new ApiResponse<>();
rsp.setMessage("success");
rsp.setCode(code);
rsp.setCode(200);
rsp.setData(data);
return rsp;
}
public void setup(String message, int code, T data) {
this.setMessage(message);
this.setCode(code);
this.setData(data);
public static <T> ApiResponse<T> createError(String message, T data) {
ApiResponse<T> rsp = new ApiResponse<>();
rsp.setMessage(message);
rsp.setCode(500);
rsp.setData(data);
return rsp;
}
public String getMessage() {
... ...
... ... @@ -5,8 +5,10 @@ import com.yoho.search.dal.*;
import com.yoho.search.dal.model.BigdataMonitor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class BigdataMonitorService {
... ... @@ -32,65 +34,121 @@ public class BigdataMonitorService {
@Autowired
private ProductModelValueMapper productModelValueMapper;
private static final int SIMILAR_SKN_THRESHOLD = 1;
private static final int SKN_PRICEAREA_THRESHOLD = 1;
private static final int SORTBRAND_VECTOR_THRESHOLD = 1;
private static final int PRODUCT15DAY_SALESUM_THRESHOLD = 1;
private static final int PRODUCT_SALESINFO_THRESHOLD = 1;
private static final int PRODUCTHEAT_VALUES_THRESHOLD = 1;
private static final int PRODUCTHEATVALUES_ONEDAY_THRESHOLD = 1;
private static final int SKN_FLOW_THRESHOLD = 1;
private static final int PRODUCTVECTOR_FEATURE_THRESHOLD = 1;
private static final int PRODUCTMODEL_VALUE_THRESHOLD = 1;
private static final String ERROR_MESSAGE_FORMAT = "tableName: %s; data_id: %s; num: %d.";
private static final int SIMILAR_SKN_THRESHOLD = 2; //83315 / 2;
private static final int SKN_PRICEAREA_THRESHOLD = 2; //560000 / 2
private static final int SORTBRAND_VECTOR_THRESHOLD = 20000; //2513 / 2
private static final int PRODUCT15DAY_SALESUM_THRESHOLD = 2;
private static final int PRODUCT_SALESINFO_THRESHOLD = 3; //30000 / 2
private static final int PRODUCTHEAT_VALUES_THRESHOLD = 2; //60000 / 2
private static final int PRODUCTHEATVALUES_ONEDAY_THRESHOLD = 2; //30000 / 2
private static final int SKN_FLOW_1_THRESHOLD = 2; //110000 / 2
private static final int SKN_FLOW_2_THRESHOLD = 2; //12000 / 2
private static final int PRODUCTVECTOR_FEATURE_THRESHOLD = 2; //102311 / 2
private static final int PRODUCTMODEL_VALUE_THRESHOLD = 2; //81000 / 2
public ApiResponse similarSkn() {
List<BigdataMonitor> result = similarSknMapper.selectCountGroupByDateId();
return ApiResponse.create(200, result.get(0));
List<BigdataMonitor> results = similarSknMapper.selectCountGroupByDateId();
if (CollectionUtils.isEmpty(results)) {
return ApiResponse.createError("bigdata_similar_skn: 没有数据", null);
}
return ifNeedAlarm(results, SIMILAR_SKN_THRESHOLD, "bigdata_similar_skn");
}
public ApiResponse sknPricearea() {
List<BigdataMonitor> result = bigdataSknPriceareaMapper.selectCountGroupByDateId();
return ApiResponse.create(200, result.get(0));
List<BigdataMonitor> results = bigdataSknPriceareaMapper.selectCountGroupByDateId();
if (CollectionUtils.isEmpty(results)) {
return ApiResponse.createError("bigdata_skn_pricearea: 没有数据", null);
}
return ifNeedAlarm(results, SKN_PRICEAREA_THRESHOLD, "bigdata_skn_pricearea");
}
public ApiResponse sortBrandVector() {
List<BigdataMonitor> result = bigdataSortBrandVectorMapper.selectCountGroupByDateId();
return ApiResponse.create(200, result.get(0));
List<BigdataMonitor> results = bigdataSortBrandVectorMapper.selectCountGroupByDateId();
if (CollectionUtils.isEmpty(results)) {
return ApiResponse.createError("bigdata_sort_brand_vector: 没有数据", null);
}
return ifNeedAlarm(results, SORTBRAND_VECTOR_THRESHOLD, "bigdata_sort_brand_vector");
}
public ApiResponse product15daySalesnum() {
List<BigdataMonitor> result = product15DaySalesNumMapper.selectCountGroupByDateId();
return ApiResponse.create(200, result.get(0));
List<BigdataMonitor> results = product15DaySalesNumMapper.selectCountGroupByDateId();
if (CollectionUtils.isEmpty(results)) {
return ApiResponse.createError("product_15day_salesnum: 没有数据", null);
}
return ifNeedAlarm(results, PRODUCT15DAY_SALESUM_THRESHOLD, "product_15day_salesnum");
}
public ApiResponse productSalesInfo() {
List<BigdataMonitor> result = productSalesInfoMapper.selectCountGroupByDateId();
return ApiResponse.create(200, result.get(0));
List<BigdataMonitor> results = productSalesInfoMapper.selectCountGroupByDateId();
if (CollectionUtils.isEmpty(results)) {
return ApiResponse.createError("product_sales_info: 没有数据", null);
}
return ifNeedAlarm(results, PRODUCT_SALESINFO_THRESHOLD, "product_sales_info");
}
public ApiResponse productHeatValues() {
List<BigdataMonitor> result = productHeatValuesMapper.selectCountGroupByDateId();
return ApiResponse.create(200, result.get(0));
List<BigdataMonitor> results = productHeatValuesMapper.selectCountGroupByDateId();
if (CollectionUtils.isEmpty(results)) {
return ApiResponse.createError("product_heat_values: 没有数据", null);
}
return ifNeedAlarm(results, PRODUCTHEAT_VALUES_THRESHOLD, "product_heat_values");
}
public ApiResponse productHeatValuesOneday() {
List<BigdataMonitor> result = productHeatValuesOneDayMapper.selectCountGroupByDateId();
return ApiResponse.create(200, result.get(0));
List<BigdataMonitor> results = productHeatValuesOneDayMapper.selectCountGroupByDateId();
if (CollectionUtils.isEmpty(results)) {
return ApiResponse.createError("product_heat_values_oneday: 没有数据", null);
}
return ifNeedAlarm(results, PRODUCTHEATVALUES_ONEDAY_THRESHOLD, "product_heat_values_oneday");
}
public ApiResponse sknFlow() {
List<BigdataMonitor> result = sknFlowMapper.selectCountGroupByDateId();
return ApiResponse.create(200, result);
List<BigdataMonitor> results = sknFlowMapper.selectCountGroupByDateId();
if (CollectionUtils.isEmpty(results)) {
return ApiResponse.createError("skn_flow: 没有数据", null);
}
List<BigdataMonitor> results1 = results.stream().filter(e -> e.getFlowType().equals(1) && e.getNum() < SKN_FLOW_1_THRESHOLD).collect(Collectors.toList());
List<BigdataMonitor> results2 = results.stream().filter(e -> e.getFlowType().equals(2) && e.getNum() < SKN_FLOW_2_THRESHOLD).collect(Collectors.toList());
if (CollectionUtils.isEmpty(results1) && CollectionUtils.isEmpty(results1)) {
return ApiResponse.createSuccess(null);
}
String message = "";
if (!CollectionUtils.isEmpty(results1)) {
String message1 = results1.stream().map(e -> String.format(ERROR_MESSAGE_FORMAT, "skn_flow", e.getDateId(), e.getNum())).collect(Collectors.joining());
message = message1;
}
if (!CollectionUtils.isEmpty(results2)) {
String message2 = results2.stream().map(e -> String.format(ERROR_MESSAGE_FORMAT, "skn_flow", e.getDateId(), e.getNum())).collect(Collectors.joining());
message = message + message2;
}
return ApiResponse.createError(message, null);
}
public ApiResponse productVectorFeature() {
List<BigdataMonitor> result = productVectorFeatureMapper.selectCountGroupByDateId();
return ApiResponse.create(200, result.get(0));
List<BigdataMonitor> results = productVectorFeatureMapper.selectCountGroupByDateId();
if (CollectionUtils.isEmpty(results)) {
return ApiResponse.createError("product_vector_feature: 没有数据", null);
}
return ifNeedAlarm(results, PRODUCTVECTOR_FEATURE_THRESHOLD, "product_vector_feature");
}
public ApiResponse productModelValue() {
List<BigdataMonitor> result = productModelValueMapper.selectCountGroupByDateId();
return ApiResponse.create(200, result.get(0));
List<BigdataMonitor> results = productModelValueMapper.selectCountGroupByDateId();
if (CollectionUtils.isEmpty(results)) {
return ApiResponse.createError("product_model_value: 没有数据", null);
}
return ifNeedAlarm(results, PRODUCTMODEL_VALUE_THRESHOLD, "product_model_value");
}
private ApiResponse ifNeedAlarm(List<BigdataMonitor> results, int threshold, String tableName) {
results = results.stream().filter(e -> e.getNum() < threshold).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(results)) {
String message = results.stream().map(e -> String.format(ERROR_MESSAGE_FORMAT, tableName, e.getDateId(), e.getNum())).collect(Collectors.joining());
return ApiResponse.createError(message, null);
}
return ApiResponse.createSuccess(null);
}
}
... ...
package com.yoho.search.consumer.restapi;
import com.yoho.search.consumer.common.ApiResponse;
import com.yoho.search.consumer.index.common.BigdataMonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
... ... @@ -8,47 +10,47 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping(value = "/bigdataMonitor")
public class BigdataMonitorController {
@Autowired
private BigdataMonitorService bigdataMonitorService;
@RequestMapping(value = "/similarSkn")
public ApiResponse similarSkn() {
return ApiResponse.create(200, null);
return bigdataMonitorService.similarSkn();
}
@RequestMapping(value = "/sknPricearea")
public ApiResponse sknPricearea() {
return ApiResponse.create(200, null);
return bigdataMonitorService.sknPricearea();
}
@RequestMapping(value = "/sortBrandVector")
public ApiResponse sortBrandVector() {
return ApiResponse.create(200, null);
return bigdataMonitorService.sortBrandVector();
}
@RequestMapping(value = "/product15daySalesnum")
public ApiResponse product15daySalesnum() {
return ApiResponse.create(200, null);
return bigdataMonitorService.product15daySalesnum();
}
@RequestMapping(value = "/productSalesInfo")
public ApiResponse productSalesInfo() {
return ApiResponse.create(200, null);
return bigdataMonitorService.productSalesInfo();
}
@RequestMapping(value = "/productHeatValues")
public ApiResponse productHeatValues() {
return ApiResponse.create(200, null);
return bigdataMonitorService.productHeatValues();
}
@RequestMapping(value = "/productHeatValuesOneday")
public ApiResponse productHeatValuesOneday() {
return ApiResponse.create(200, null);
return bigdataMonitorService.productHeatValuesOneday();
}
@RequestMapping(value = "/sknFlow")
public ApiResponse sknFlow() {
return ApiResponse.create(200, null);
return bigdataMonitorService.sknFlow();
}
@RequestMapping(value = "/productVectorFeature")
public ApiResponse productVectorFeature() {
return ApiResponse.create(200, null);
return bigdataMonitorService.productVectorFeature();
}
@RequestMapping(value = "/productModelValue")
public ApiResponse productModelValue() {
return ApiResponse.create(200, null);
return bigdataMonitorService.productModelValue();
}
}
... ...