我们的使命

助力跨境卖家高效建立全球销售网络

喜报2021年我司获《江苏省国家高新技术企业》认定

分类目录

文章标签

热门推荐

相关咨讯

怎么测试到amazonaws全球各可用区域时延

2022-08-04 10:51:14 - 米境通跨境电商

    

    因为最近发现aws服务器网络不是特别稳定,所以想监控一下网络的联通性和延迟。但是发现并没有可以直接用的工具。

    搭建了smartping,worldping,smokeping这三个工具发现都不能使用

    于是就使用tcpping来不断的将日志保存到本地文件,然后使用python解析数据生成自己需要的数据,放到echarts里面来展示。能够达到和上述的三种工具的相同效果。

    部分效果:

    image.png

    日志默认输出格式

    2020年06月07日星期日00:56:13CST

    tracerouteto54.189.110.117(54.189.110.117),255hopsmax,60bytepackets

    seq119049:tcpresponsefromec2-54-189-110-117.us-west-2.compute.amazonaws.com(54.189.110.117)186.962ms

    2020年06月07日星期日00:56:14CST

    tracerouteto54.189.110.117(54.189.110.117),255hopsmax,60bytepackets

    seq119050:tcpresponsefromec2-54-189-110-117.us-west-2.compute.amazonaws.com(54.189.110.117)183.514ms

    2020年06月07日星期日00:56:15CST

    tracerouteto54.189.110.117(54.189.110.117),255hopsmax,60bytepackets

    seq119051:tcpresponsefromec2-54-189-110-117.us-west-2.compute.amazonaws.com(54.189.110.117)183.347ms

    2020年06月07日星期日00:56:16CST

    python3日志数据分析代码

    importtime

    """

    日期转时间戳

    """

    defunix_time(dt):

    #转换成时间数组

    timeArray=time.strptime(dt,"%Y年%m月%d日%H:%M:%S")

    #转换成时间戳

    timestamp=int(time.mktime(timeArray))

    returntimestamp

    """

    时间戳转日期

    """

    defcustom_time(timestamp):

    #转换成localtime

    time_local=time.localtime(timestamp)

    #转换成新的时间格式(2016-05-0520:28:54)

    dt=time.strftime("%Y/%m/%d%H:%M:%S",time_local)

    returndt

    """

    输出日志结果

    """

    defdata_handle(date_key,data_dict):

    date_key_sorted=sorted(date_key)

    date=[]

    data=[]

    forkeyindate_key_sorted:

    date.append(key)

    data.append(data_dict[key])

    #print(len(data_dict))

    date_fout=open(date_file_result,'w',encoding='utf8')

    date_fout.write(str(date))

    date_fout.close()

    #print(date)

    data_fout=open(data_file_result,'w',encoding='utf8')

    data_fout.write(str(data))

    data_fout.close()

    #print(data)

    log_file="/Users/hfy/work/python/tools/analysis/111.log"

    data_file_result="/Users/hfy/work/python/tools/analysis/data_file_result.txt"

    date_file_result="/Users/hfy/work/python/tools/analysis/date_file_result.txt"

    if__name__=='__main__':

    file=open(log_file,'r')

    data_dict={}

    date_key=[]

    time_str=""

    delay=0

    forlineinfile:

    ifline.find("CST")!=-1:

    #时间格式转换

    date_list=line.split("")

    date_str=date_list[0]+date_list[1]+date_list[2]+date_list[4]

    time_str=custom_time(unix_time(date_str))

    ifline.find("seq")!=-1:

    line_list=line.split("")

    iflen(line_list)<12andline.find("timeout")!=-1:

    delay=0

    else:

    delay=float(line_list[9])

    #收集延迟大于500和超时的日志信息

    ifdelay==0ordelay>500:

    date_key.append(time_str)

    data_dict[time_str]=delay

    time_str=""

    delay=0

    data_handle(date_key,data_dict)

    #echarhttps://echarts.apache.org/examples/zh/editor.html?c=area-simple数据分析

    echars数据展示地址:

    https://echarts.apache.org/examples/zh/editor.html

    只需要将输出的data和date放到正确的位置就会自动渲染数据

    demo:

    varbase=+newDate(1968,9,3);

    varoneDay=24*3600*1000;

    vardate=[];

    vardata=[Math.random()*300];

    //for(vari=1;i<20000;i++){

    //varnow=newDate(base+=oneDay);

    //date.push([now.getFullYear(),now.getMonth()+1,now.getDate()].join('/'));

    //data.push(Math.round((Math.random()-0.5)*20+data[i-1]));

    //}

    vardata=[1201.895,1201.895,120.895,1201.895,12.895,1201.895,120.895,1201.895,12.895,1201.895]

    vardate=['2020/06/0515:17:15','2020/06/0515:17:15','2020/06/0515:17:15','2020/06/0515:17:15','2020/06/0515:17:15','2020/06/0515:17:15','2020/06/0515:17:15','2020/06/0515:17:15','2020/06/0515:17:15','2020/06/0515:17:15']

    option={

    tooltip:{

    trigger:'axis',

    position:function(pt){

    return[pt[0],'10%'];

    }

    },

    title:{

    left:'center',

    text:'大数据量面积图',

    },

    toolbox:{

    feature:{

    dataZoom:{

    yAxisIndex:'none'

    },

    restore:{},

    saveAsImage:{}

    }

    },

    xAxis:{

    type:'category',

    boundaryGap:false,

    data:date

    },

    yAxis:{

    type:'value',

    boundaryGap:[0,'100%']

    },

    dataZoom:[{

    type:'inside',

    start:0,

    end:10

    },{

    start:0,

    end:10,

    handleIcon:'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9zM13.3,24.4H6.7V23h6.6V24.4zM13.3,19.6H6.7v-1.4h6.6V19.6z',

    handleSize:'80%',

    handleStyle:{

    color:'#fff',

    shadowBlur:3,

    shadowColor:'rgba(0,0,0,0.6)',

    shadowOffsetX:2,

    shadowOffsetY:2

    }

    }],

    series:[

    {

    name:'网络延迟',

    type:'line',

    smooth:true,

    symbol:'none',

    sampling:'average',

    itemStyle:{

    color:'rgb(255,70,131)'

    },

    areaStyle:{

    color:newecharts.graphic.LinearGradient(0,0,0,1,[{

    offset:0,

    color:'rgb(255,158,68)'

    },{

    offset:1,

    color:'rgb(255,70,131)'

    }])

    },

    data:data

    }

    ]

    };
    联系我们
  • 24H客服
  • 联系电话:16651690460(龙经理)
  • 微信咨询:
南京天遥路联网络科技有限公司,版权所有 Copyright By ©米境通ERP4.0,2015-2025,苏ICP备:苏ICP备15044100号-4, 苏公网安备:32011402011043