当前位置: 首页 > news >正文

traffic and backfill

为什么80%的码农都做不了架构师?>>>   hot3.png

#!/usr/bin/python
#coding=utf-8
import time
import re
import os
#############################################
# Name: TRAFFIC AND BACKFILL    
# Author: LCY
# Version: 1.0.20150828
# Feature: xxxxxx
#############################################




#appoint sgwip and report the traffic
def check_traffic():
    TODAY14 = get_endtime()
    YESTERDAY14 = get_starttime()
    os.system("impala-shell -q \"refresh pqtxdr.lteu1_ftp_zc ; refresh pqtxdr.lteu1_rtsp_zc ; refresh pqtxdr.lteu1_s1u_zc ; refresh pqtxdr.lteu1_voip_zc ; refresh pqtxdr.lteu1_http_zc ;  with h2 as (select     startdate,u32sgwip_4,u32ultraffic,u32dltraffic from pqtxdr.lteu1_ftp_zc where startdate>=\'"+YESTERDAY14+ "\' and startdate<=\'"+TODAY14+"\'), h3 as (select startdate,u32sgwip_4,u32ultraffic,u32dltraffic from     pqtxdr.lteu1_rtsp_zc where startdate>=\'"+YESTERDAY14+ "\' and startdate<=\'"+TODAY14+"\'), h4 as (select startdate,u32sgwip_4,u32ultraffic,u32dltraffic from pqtxdr.lteu1_s1u_zc where startdate>=\'"+YESTERDAY14+     "\' and startdate<=\'"+TODAY14+"\'), h5 as (select startdate,u32sgwip_4,u32ultraffic,u32dltraffic from pqtxdr.lteu1_voip_zc where startdate>=\'"+YESTERDAY14+ "\' and startdate<=\'"+TODAY14+"\'), h6 as (select     startdate,u32sgwip_4,u32ultraffic,u32dltraffic from pqtxdr.lteu1_http_zc where startdate>=\'"+YESTERDAY14+ "\' and startdate<=\'"+TODAY14+"\'), h21 as ( select * from h2 union all select * from h3 union all select *     h4 union all select * from h5 union all select * from h6 ), h22 as (select startdate,u32sgwip_4,SUM(u32ultraffic) as ul_traffic,SUM(u32dltraffic) as dl_traffic,sum(u32ultraffic+u32dltraffic) as total_traffic from h21 group by     startdate,u32sgwip_4) select h22.startdate,h22.u32sgwip_4,h22.ul_traffic,h22.dl_traffic,h22.total_traffic from h22 ;\" > /tmp/Log_traffic.log")
    sgwip=open('/tmp/sgwip','r')#path of sgwip
    lines=sgwip.readlines()
    for l in lines:
        list=l.split()
        IP=list[0]
        NAME=list[1]
        print IP,NAME
        os.chdir('/tmp/')##save path
        name=open(NAME+'tmp','w+')
        log=open('/tmp/Log_traffic.log','r')#import the ip,traffic in this file
        lines_log=log.readlines()
        for L in lines_log:
        match=re.search(IP,L)
        if match:
                plit_line=L.split('|')
                del split_line[3]
                del split_line[3]
                str=''.join(split_line)
                name.write(str)
        name.close()


    finalfile=open(NAME,'w')
    finalname=open(NAME+'tmp','r')
    lines_finalfile=finalname.readlines()
    lines_finalfile.sort()
    for l_finalfile in lines_finalfile:
        finalfile.write(l_finalfile)
        os.remove(NAME+'tmp')
        print '%s download success'%NAME





#get start and  end time
def get_endtime():
        TODAY=time.strftime('%Y%m%d',time.localtime(time.time()))
        CHECKTIME=TODAY+"14"
        return CHECKTIME


def get_starttime():
        YESTERDAY=time.strftime('%Y%m%d',time.localtime(time.time()-24*3600))
        #time.time()
        CHECKTIME=YESTERDAY+"14"
        return CHECKTIME


def check_backfill():
        try:
            CITYCORE=sys.argv[1]
        except Exception,e:
            CITYCORE=25
        print "CITYCORE=",CITYCORE
        TODAY14=get_endtime()
        YESTERDAY14=get_starttime()
        os.system("impala-shell -q"+"refresh pqtxdr.lteu1_http_zc;select startdate,'imsi' as type,count(*) from pqtxdr.lteu1_http_zc where startdate>=" +YESTERDAY14+ " and startdate<="+TODAY14+ " and         u64imsi>1000000000000 and u16citycode=" +CITYCORE+ " group by startdateunion all select startdate,'msisdn' as type,count(*) from lteu1_http_zc where startdate>="+YESTERDAY14+ " and startdate<="+TODAY14+         "and u64msisdn>13000000000 and u16citycode="+CITYCORE+" group by startdateunion allselect startdate,'count_cnt' as type,count(*) from lteu1_http_zc where startdate>="+YESTERDAY14+ " and         startdate<="+TODAY14+ " and u16citycode=25 group by startdate"+" >/tmp/Log_backfill.log")
        os.chdir('/tmp/')
        tmpfile=open('Log_backfill.log','r')
        tmpfile_lines=tmpfile.readlines()
        tmpfile2=open('imsitmp','w')
        tmpfile3=open('msisdntmp','w')
        tmpfile4=open('count_cnttmp','w')
        for tmpfile_line in tmpfile_lines:
                match1=re.search(r'imsi',tmpfile_line)
                if match1:
           tmpfile2.write(tmpfile_line)
                match2=re.search(r'msisdn',tmpfile_line)
                if match2:
                        tmpfile3.write(tmpfile_line)
                match3=re.search(r'count_cnt',tmpfile_line)
                if match3:
                        tmpfile4.write(tmpfile_line)
        tmpfile2.close()
        tmpfile3.close()
        tmpfile4.close()
        tmpfile5=open('imsitmp','r')
        tmpfile6=open('msisdntmp','r')
        tmpfile7=open('count_cnttmp','r')
        tmpfile8=open('imsi','w')
        tmpfile9=open('msisdn','w')
        tmpfile0=open('count_cnt','w')
        tmpfile5_line=tmpfile5.readlines()
        tmpfile5_line.sort()
        for tmpfile5_line_l in tmpfile5_line:
                tmpfile8.write(tmpfile5_line_l)
        os.remove('imsitmp')
        print 'imsi success'
        tmpfile6_line=tmpfile6.readlines()
        tmpfile6_line.sort()
        for tmpfile6_line_l in tmpfile6_line:
                tmpfile9.write(tmpfile6_line_l)
        os.remove('msisdntmp')
        print 'msisdn success'
        tmpfile7_line=tmpfile7.readlines()
        tmpfile7_line.sort()
        for tmpfile7_line_l in tmpfile7_line:
               tmpfile0.write(tmpfile7_line_l)
        os.remove('count_cnttmp')
        print 'count_cnt success'


if __name__ == '__main__':
    get_endtime()
    get_starttime()
    check_traffic()
    check_backfill()

转载于:https://my.oschina.net/pppi/blog/501530

相关文章:

  • 简单的转义字符
  • Eclipse自动补全设置
  • ${factoryList }后面有空格不影响
  • 再看BP神经网络
  • JavaScript深浅拷贝
  • 节约内存:Instagram的Redis实践
  • 智云大咖秀:怎样的稳定器才是摄影师的“灵魂辅助”?
  • Bootstrap vs Foundation如何选择靠谱前端框架
  • 双管齐下,VMware的容器新战略
  • 退役前的记录(2018.10.14-NOIP2018)
  • CENTOS 6.6 nfs 服务器搭建
  • JQuery Mobile难点备忘
  • C++语法小技巧
  • MeiTuanLocateCity仿美团城市列表选择界面
  • React Native安卓模拟器调出Dev Setting菜单
  • 【159天】尚学堂高琪Java300集视频精华笔记(128)
  • C++11: atomic 头文件
  • download使用浅析
  • HashMap剖析之内部结构
  • iOS | NSProxy
  • js作用域和this的理解
  • vue:响应原理
  • Vue全家桶实现一个Web App
  • 可能是历史上最全的CC0版权可以免费商用的图片网站
  • 如何将自己的网站分享到QQ空间,微信,微博等等
  • 新版博客前端前瞻
  • 学习使用ExpressJS 4.0中的新Router
  • Redis4.x新特性 -- 萌萌的MEMORY DOCTOR
  • (01)ORB-SLAM2源码无死角解析-(66) BA优化(g2o)→闭环线程:Optimizer::GlobalBundleAdjustemnt→全局优化
  • (6)STL算法之转换
  • (AtCoder Beginner Contest 340) -- F - S = 1 -- 题解
  • (DenseNet)Densely Connected Convolutional Networks--Gao Huang
  • (Mac上)使用Python进行matplotlib 画图时,中文显示不出来
  • (ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY)讲解
  • (附源码)springboot人体健康检测微信小程序 毕业设计 012142
  • (附源码)基于SSM多源异构数据关联技术构建智能校园-计算机毕设 64366
  • (更新)A股上市公司华证ESG评级得分稳健性校验ESG得分年均值中位数(2009-2023年.12)
  • (黑客游戏)HackTheGame1.21 过关攻略
  • (力扣记录)235. 二叉搜索树的最近公共祖先
  • (十二)springboot实战——SSE服务推送事件案例实现
  • (一)Neo4j下载安装以及初次使用
  • (最简单,详细,直接上手)uniapp/vue中英文多语言切换
  • .NET CORE 第一节 创建基本的 asp.net core
  • .NET Core 成都线下面基会拉开序幕
  • .NET Core引入性能分析引导优化
  • .w文件怎么转成html文件,使用pandoc进行Word与Markdown文件转化
  • @KafkaListener注解详解(一)| 常用参数详解
  • [ Algorithm ] N次方算法 N Square 动态规划解决
  • [ 攻防演练演示篇 ] 利用通达OA 文件上传漏洞上传webshell获取主机权限
  • [20161214]如何确定dbid.txt
  • [ABC294Ex] K-Coloring
  • [Angular 基础] - 自定义指令,深入学习 directive
  • [C++]二叉搜索树
  • [CakePHP] 在Controller中使用Helper
  • [Gradle] 在 Eclipse 下利用 gradle 构建系统