Authored by qinchao

增加接口大数据上报

package com.monitor.influxdb.mapper;
/**
* Created by craig.qin 2018-04-09
*/
public interface BigDataKeyInfoMapper {
/**
* 写入influxdb
*/
void write(String name,String script,String status,String task_id,String count_name,double count);
}
\ No newline at end of file
... ...
package com.monitor.influxdb.mapper.impl;
import com.monitor.influxdb.InfluxDataReporter;
import com.monitor.influxdb.contants.InfluxDBContants;
import com.monitor.influxdb.mapper.BigDataKeyInfoMapper;
import org.influxdb.dto.Point;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Created by craig.qin 2018-04-09
*/
@Component
public class BigDataKeyInfoMapperImpl implements BigDataKeyInfoMapper {
Logger logger = LoggerFactory.getLogger("commonAlarmDataLogger");
@Autowired
private InfluxDataReporter influxDataReporter;
/**
* 写入influxdb
*/
@Override
public void write(String name,String script,String status,String task_id,String count_name,double count){
Point point = Point.measurement("bigdata_key_info")
.tag("name",name)
.tag("script", script)
.tag("status",status)
.tag("task_id,",task_id)
.tag("count_name",count_name)
.addField("count",count)
.build();
try{
influxDataReporter.report(InfluxDBContants.AWS,InfluxDBContants.MONITOR_SYSTEM,point);
}catch(Exception e){
logger.error(" - BigDataKeyInfoMapperImpl - write - error {}", e);
}
}
}
... ...
package com.monitor.other.bigdata.ctrl;
import com.alibaba.fastjson.JSONObject;
import com.monitor.influxdb.mapper.BigDataKeyInfoMapper;
import com.monitor.model.response.BaseResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
... ... @@ -11,10 +18,52 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/bigdata")
public class BigdataCtrl {
public static final Logger logger = LoggerFactory.getLogger(BigdataCtrl.class);
@Value("${bigdata.web.url}")
private String accessUrl;
@Autowired
private BigDataKeyInfoMapper bigDataKeyInfoMapper;
/**
* 大数据上报的数据
*
{
"name": "搜素用户word2vector特征"
"script": “word-2-vector.sh”
"status" : "success"
"task_id" : 123 //对应任务系统中的id
"count_name": "xxxx" ,//统计项目
"count": 1000; //统计数量
}
*/
@RequestMapping("/bigDataKeyInfoReport")
@ResponseBody
public BaseResponse bigDataKeyInfoReport(@RequestBody JSONObject jsonObject) {
String name=jsonObject.getString("name");
String script=jsonObject.getString("script");
String status=jsonObject.getString("status");
String task_id=jsonObject.getString("task_id");
String count_name=jsonObject.getString("count_name");
double count=0d;
Object countValue=jsonObject.get("count");
if(countValue!=null){
try{
count = Double.parseDouble(""+countValue);
}catch (Exception e){
logger.error("bigDataKeyInfoReport change count error {} ,{}",countValue,e);
}
}else{
logger.error("bigDataKeyInfoReport count is null ");
}
//上报给influxdb
bigDataKeyInfoMapper.write(name,script,status,task_id,count_name,count);
return new BaseResponse();
}
/**
* 获取访问url
* @return
... ...