• python对日志的处理及图形显示


    1.处理日志的python程序
    
    def read(log):
        with open(log, encoding="UTF-8") as f:
            yield from f
    
    
    def make_js(log, name):
        res = {}
        for line in read(log):
            line = line.split(" ")
            if len(line) > 10:
                key = line[10]
                value = res.get(key, 0) + 1
                res[key] = value + 1
        # print(res)
        with open("{}.js".format(name), "w") as f:
            f.write("res_data={result}".format(result = res))
    
    make_js("store.log", "store")
    
    # 日志样式
    tail -n 3 /data/www/logs/nginx_log/access/store.log
    1.1.1.1 - - [07/Feb/2020:19:38:20 -0800] - - "GET /jslibs/select2/select2.full.min.js?201812 HTTP/1.1" 200 23673 "https://store.wondershare.com/checkout/myCart/?code_id=cae3046452b6d2eb7a88f31a3172d752&machine_no=eus&_ga=2.164934399.1772424582.1581129371-825859103.1580980114" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36" 0.000 
    1.1.1.1 - - [07/Feb/2020:19:38:20 -0800] - - "GET /images/checkout/btn_checkout_en_us.gif HTTP/1.1" 200 2290 "https://store.wondershare.com/checkout/myCart/?code_id=cae3046452b6d2eb7a88f31a3172d752&machine_no=eus&_ga=2.164934399.1772424582.1581129371-825859103.1580980114" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36" 0.000 
    1.1.1.1 - - [07/Feb/2020:19:38:21 -0800] - - "GET /images/cart/cart.gif HTTP/1.1" 200 86 "https://store.wondershare.com/checkout/myCart/?code_id=cae3046452b6d2eb7a88f31a3172d752&machine_no=eus&_ga=2.164934399.1772424582.1581129371-825859103.1580980114" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36" 0.000 
    
    
    2.最终生成日志的store.js
    res_data={'302': 10, '200': 90}
    
    3.日志展示的html
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>ECharts</title>
        <!-- 引入 echarts.js -->
        <script src="js/echarts.min.js"></script>
        <script src="store.js"></script>
    </head>
    <body>
        <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
        <div id="main" style=" 600px;height:400px;"></div>
        <script type="text/javascript">
            // 基于准备好的dom,初始化echarts实例
            var myChart = echarts.init(document.getElementById('main'));
    
            // 指定图表的配置项和数据
            var series_data = [], legend_data = [];
            for (var key in res_data) {
                series_data.push(res_data[key]),
                    legend_data.push(key);
            }
            var option = {
                title: {
                    text: 'ECharts 入门示例'
                },
                tooltip: {},
                legend: {
                    data:['status']
                },
                xAxis: {
                    data: legend_data
                },
                yAxis: {},
                series: [{
                    name: 'status',
                    type: 'bar',
                    data: series_data
                }]
            };
    
            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
        </script>
    </body>
    </html>
  • 相关阅读:
    HTML语言基础
    过滤器Filter
    新闻实现分页显示
    [转]Jmeter使用入门
    [转]ZK工作原理
    [转]UT-IT-ST-BBIT-SDV-SIT-SVT
    Unix编码哲学
    火星坐标、百度坐标、WGS-84坐标相互转换及墨卡托投影坐标转经纬度JavaScript版
    递归公用表表达式概述
    java写word转pdf
  • 原文地址:https://www.cnblogs.com/reblue520/p/12283427.html
Copyright © 2020-2023  润新知