尝试打造数据分析与自动化运维系统(一)

2018-06-13  本文已影响0人  笛声hk

前言

本系列文章记录尝试数据分析与自动化运维系统.

目标功能要点:

  • 前端日志接受存储分析
  • 根据日志分析结果和docker运行信息提供报警
  • 提供操纵分布式宿主机上的docker容器的能力
  • ..................

本章主题

(一)前端日志数据


结构化,提交足够信息,方便复现错误


 let reportLog={
    project:"",//项目名称
    version:"",//用户版本信息
    module:"",//模块信息
    content:"",//主要信息,
    clientInfo:{},//用户端信息,
    type:"",//日志信息类型,确定是全局错误还是主动报错或者普通埋点信息.
    time:"",//前端报错时间戳,
    extPayload:{
      localStorage:{},//小程序前端存储
     // ......
    }
  }

统一提交 (以小程序为例)

module.exports=function(...messages){
  let logType=messages[messages.length-1]
  let reportLog={
    project:"",//项目名称
    version:"",//用户版本信息
    module:"",//模块信息
    content:"",//主要信息,
    clientInfo:wx.getSystemInfoSync(),//用户端信息,
    type:"info",//日志信息类型,确定是全局错误还是主动报错或者普通埋点信息.
    time:Date.parse(new Date()),//前端报错时间戳,
    extPayload:{
      localStorage:{},//小程序前端存储
      
    }
  }
  reportLog.module=messages[0]
  if(logType==1||logType==2){
    let logMessages=messages.slice(0,messages.length-1)
    reportLog.content=logMessages.join("/")
    reportLog.type="LogError"
    console.group("error:")
    logMessages.forEach(item=>{
      console.error(item)
    })
    console.groupEnd()
    uploadReportLog(reportLog)
    return
  }
  if(logType==2){
    reportLog.type="AppError"
  }
  reportLog.content=messages.join("/")
  console.group("info:")
  messages.forEach((item)=>{
    console.log(item)
  })
  uploadReportLog(reportLog)
  console.groupEnd()
  
}
function uploadReportLog(reportLog){
  wx.request({
    url:"https://log.dishenghk.cn",
    data:reportLog
  })
}
上一篇下一篇

猜你喜欢

热点阅读