traffic and backfill

#!/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()

时间: 2024-10-27 15:02:58

traffic and backfill的相关文章

ural 2020 Traffic Jam in Flower Town

2020. Traffic Jam in Flower Town Time limit: 1.0 secondMemory limit: 64 MB Having returned from Sun City, Dunno told all his friends that every shorty may have a personal automobile. Immediately after that so many citizens took a fancy of becoming ro

icinga2监控netapp、ubuntu、windows的traffic流量

插件下载网址:https://github.com/cloved/check_traffic/blob/master/check_traffic.sh # mv check_traffic.sh /usr/lib64/nagios/plugins/ # chmod +x /usr/lib64/nagios/plugins/check_traffic.sh # cd /usr/lib64/nagios/plugins/ # cp check_traffic.sh check_traffic_in.

Monitor traffic to localhost from IE or .NET

原文:http://docs.telerik.com/fiddler/Configure-Fiddler/Tasks/MonitorLocalTraffic Monitor traffic to localhost from IE or .NET To monitor traffic sent to http://localhost or http://127.0.0.1 from IE8 or below or the .NET Framework: Use your machine name

两步让你的mobile traffic通过fiddler代理传送

mobile app运行时由于调试网络相关的内容非常不便,所以如果能够让iphone通过桌面主机来跑traffic,那么在pc上就能非常清楚地检查mobile app和后端之间有什么问题了. 幸运的是fiddler有一个proxy的功能可以胜任,在这个场景中运行fiddler的pc作为proxy, mobile通过wifi和PC在一个局域网中 1.配置fiddler enable proxy的功能 2.配置iphone的wifi proxy使能: 随后在iphone上浏览网页时都会经过192.1

使用微软Traffic Manage---实验

官方介绍说Azure Traffic Manager是为了分担流量,但是也可以这样 Traffic Manager 可帮助你: 提高关键应用程序的可用性 - 使用 Traffic Manager,可以通过监视 Azure 中的终结点并在 Azure 云服务.Azure 网站或其他位置关闭时提供自动故障转移功能来提高关键应用程序的可用性. 提高高性能应用程序的响应能力 – Azure 允许你在世界各地的数据中心内运行云服务或网站.通过从客户端将最终用户定向到网络延迟最低的终结点,Traffic M

Cellular Traffic Offloading

Reference: [1] Mobile Data Offload for 3G Networks [2] Mobile Data Offloading through Opportunistic Communications and Social Participation [3] Femtocell Networks: A Survey There are two types of existing solutions to alleviate the traffic load on ce

UVA 10693 10693 - Traffic Volume(数论)

题目链接:10693 - Traffic Volume 根据物理知识, 车经过的时间等于,距离/速度,所以可以列出公式t = (l + d)/v,v/2f + d/v,只有当v / 2f = d/v时,时间最小,v = sqrt(2df),之后时间也能算了. #include <stdio.h> #include <string.h> #include <math.h> double l, f; int main() { while (~scanf("%lf%

Linux下按程序查实时流量 network traffic

实然看到下载速度多达几M/s,但实际上并没有什么占用带宽的进程. 相查看每个程序占用的网络流量, 但系统自带的 System Monitor 只能查看全局的流量, 不能具体看某个程序的...... key words: network traffic, process specific, nethogs 工具: nethogs (要用sudo运行) Description : NetHogs is a small "net top" tool. /* 像top 一样的工具, 实时更新

流量工程 traffic engineering (TE)

什么是流量工程 流量工程是指根据各种数据业务流量的特性选取传输路径的处理过程.流量工程用于平衡网络中的不同交换机.路由器以及链路之间的负载. [编辑] 流量工程的内容 流量工程在复杂的网络环境中,控制不同的业务流走不同的路径,关键的业务走可靠的路径并保证服务质量,并且在某段网络拥塞的情况下,动态调整路由,整个网络如同一个"可控的城市交通系统". 流量工程理念在上世纪90年代末提出,最初起源于互联网.其原理是在MPLS环境中,充分利用标签交换系统来为不同的业务流着色,通过LDP来传递LS