Authored by qinchao

增加接口大数据上报

  1 +package com.monitor.influxdb.mapper;
  2 +
  3 +/**
  4 + * Created by craig.qin 2018-04-09
  5 + */
  6 +public interface BigDataKeyInfoMapper {
  7 +
  8 + /**
  9 + * 写入influxdb
  10 + */
  11 + void write(String name,String script,String status,String task_id,String count_name,double count);
  12 +}
  1 +package com.monitor.influxdb.mapper.impl;
  2 +
  3 +import com.monitor.influxdb.InfluxDataReporter;
  4 +import com.monitor.influxdb.contants.InfluxDBContants;
  5 +import com.monitor.influxdb.mapper.BigDataKeyInfoMapper;
  6 +import org.influxdb.dto.Point;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +/**
  13 + * Created by craig.qin 2018-04-09
  14 + */
  15 +@Component
  16 +public class BigDataKeyInfoMapperImpl implements BigDataKeyInfoMapper {
  17 + Logger logger = LoggerFactory.getLogger("commonAlarmDataLogger");
  18 +
  19 + @Autowired
  20 + private InfluxDataReporter influxDataReporter;
  21 +
  22 + /**
  23 + * 写入influxdb
  24 + */
  25 + @Override
  26 + public void write(String name,String script,String status,String task_id,String count_name,double count){
  27 + Point point = Point.measurement("bigdata_key_info")
  28 + .tag("name",name)
  29 + .tag("script", script)
  30 + .tag("status",status)
  31 + .tag("task_id,",task_id)
  32 + .tag("count_name",count_name)
  33 + .addField("count",count)
  34 + .build();
  35 +
  36 + try{
  37 + influxDataReporter.report(InfluxDBContants.AWS,InfluxDBContants.MONITOR_SYSTEM,point);
  38 + }catch(Exception e){
  39 + logger.error(" - BigDataKeyInfoMapperImpl - write - error {}", e);
  40 + }
  41 + }
  42 +}
1 package com.monitor.other.bigdata.ctrl; 1 package com.monitor.other.bigdata.ctrl;
2 2
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.monitor.influxdb.mapper.BigDataKeyInfoMapper;
  5 +import com.monitor.model.response.BaseResponse;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +import org.springframework.beans.factory.annotation.Autowired;
3 import org.springframework.beans.factory.annotation.Value; 9 import org.springframework.beans.factory.annotation.Value;
4 import org.springframework.stereotype.Controller; 10 import org.springframework.stereotype.Controller;
  11 +import org.springframework.web.bind.annotation.RequestBody;
5 import org.springframework.web.bind.annotation.RequestMapping; 12 import org.springframework.web.bind.annotation.RequestMapping;
6 import org.springframework.web.bind.annotation.ResponseBody; 13 import org.springframework.web.bind.annotation.ResponseBody;
7 14
@@ -11,10 +18,52 @@ import org.springframework.web.bind.annotation.ResponseBody; @@ -11,10 +18,52 @@ import org.springframework.web.bind.annotation.ResponseBody;
11 @Controller 18 @Controller
12 @RequestMapping("/bigdata") 19 @RequestMapping("/bigdata")
13 public class BigdataCtrl { 20 public class BigdataCtrl {
  21 + public static final Logger logger = LoggerFactory.getLogger(BigdataCtrl.class);
14 22
15 @Value("${bigdata.web.url}") 23 @Value("${bigdata.web.url}")
16 private String accessUrl; 24 private String accessUrl;
17 25
  26 + @Autowired
  27 + private BigDataKeyInfoMapper bigDataKeyInfoMapper;
  28 +
  29 + /**
  30 + * 大数据上报的数据
  31 + *
  32 + {
  33 + "name": "搜素用户word2vector特征"
  34 + "script": “word-2-vector.sh”
  35 + "status" : "success"
  36 + "task_id" : 123 //对应任务系统中的id
  37 + "count_name": "xxxx" ,//统计项目
  38 + "count": 1000; //统计数量
  39 + }
  40 + */
  41 + @RequestMapping("/bigDataKeyInfoReport")
  42 + @ResponseBody
  43 + public BaseResponse bigDataKeyInfoReport(@RequestBody JSONObject jsonObject) {
  44 + String name=jsonObject.getString("name");
  45 + String script=jsonObject.getString("script");
  46 + String status=jsonObject.getString("status");
  47 + String task_id=jsonObject.getString("task_id");
  48 + String count_name=jsonObject.getString("count_name");
  49 + double count=0d;
  50 +
  51 + Object countValue=jsonObject.get("count");
  52 + if(countValue!=null){
  53 + try{
  54 + count = Double.parseDouble(""+countValue);
  55 + }catch (Exception e){
  56 + logger.error("bigDataKeyInfoReport change count error {} ,{}",countValue,e);
  57 + }
  58 + }else{
  59 + logger.error("bigDataKeyInfoReport count is null ");
  60 + }
  61 +
  62 + //上报给influxdb
  63 + bigDataKeyInfoMapper.write(name,script,status,task_id,count_name,count);
  64 + return new BaseResponse();
  65 + }
  66 +
18 /** 67 /**
19 * 获取访问url 68 * 获取访问url
20 * @return 69 * @return