Created
November 14, 2012 07:16
-
-
Save caoxudong/4070782 to your computer and use it in GitHub Desktop.
测试播放器P2P统计中对sid个数的统计,这里的问题是,所有日志中sid集合的个数与warning类型的日志中sid集合个数不同
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
''' | |
This script is used to test sid stats in player p2p stats. | |
Created on 2012-11-14 | |
@author: caoxudong | |
''' | |
import sys | |
import datetime | |
import os | |
import getopt | |
import json | |
today = datetime.date.today() | |
targetDateStringParam = str(today) | |
try: | |
#check parameter | |
opts, args = getopt.getopt(sys.argv[1:], "d:o:h:", ["date=", "offset=", "hour="]) | |
for opt, arg in opts: | |
if opt in ("-o", "-offset"): | |
targetDateStringParam = str(today - datetime.timedelta(days = int(arg))) | |
if opt in ("-d", "--date"): | |
targetDateStringParam = arg | |
except Exception,data: | |
print Exception,":",data | |
logPath = '/opt/workspace/logs/original/p2p/1hour' | |
logPrefix = 'ykp2pdata-' | |
sidDictInAllLog = {} | |
sidDictInWarningLog = {} | |
sidDictInWarningLogWithCumulusGetID = {} | |
fileNames = os.listdir(logPath); | |
qulifiedFileNames = [] | |
for f in fileNames: | |
try: | |
f.index(logPrefix + targetDateStringParam) | |
qulifiedFileNames.append(f) | |
except ValueError: | |
pass | |
for fileName in qulifiedFileNames: | |
fileObject = open(logPath + os.sep + fileName, 'r') | |
for line in fileObject: | |
elements = line.split(' ') | |
targetString = ''.join(elements[3:]) | |
try: | |
tempDict = json.loads(targetString) | |
except: | |
sys.exit(1) | |
logType = tempDict.get('logType') | |
sid = tempDict.get('sid') | |
sidDictInAllLog[sid] = 1 | |
if (logType == 'warning') : | |
sidDictInWarningLog[sid] = 1 | |
errorType = tempDict.get('errorType') | |
if errorType == 'CumulusGetIDError' or errorType == 'CumulusGetIDSuccess': | |
sidDictInWarningLogWithCumulusGetID[sid] = 1 | |
print 'sidDictInAllLog : ',len(sidDictInAllLog) | |
print 'sidDictInWarningLog : ', len(sidDictInWarningLog) | |
print 'sidDictInWarningLogWithCumulusGetID : ', len(sidDictInWarningLogWithCumulusGetID) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment