nginx 로그 에서 URL 을 읽 어 성능 테스트 를 합 니 다.
2750 단어 nginx
222.210.49.198 - 209sdj3lufa7sf32 -c2b3lp - [14/Sep/2012:22:59:02 +0800]"GET /search/?page=33&kw=%E6%B5%B7%E8%B4%BC&type=feed&_type= HTTP/1.1" 200 14466 "http://www.duitang.com/search/?kw=%E6%B5%B7%E8%B4%BC&type=feed" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.84 Safari/535.11 LBBROWSER"
nginx 에서 URL 을 읽 고 성능 테스트 를 하기 위해 간단 한 python 스 크 립 트 를 썼 습 니 다.
# -*- coding: utf-8 -*-
import re
import urllib2
import json
import threading
import Queue
import os
host="http://7199.t.duitang.com"
thread_count = 1
running = True
def check(uri):
try:
url = "%s%s"%(host,uri)
content = urllib2.urlopen(url=url,timeout=2)
#print '%s %s'%(content.code,uri)
#print content.info()
#print content.msg
#print content.readlines()
#json.loads(content.readlines())
#print 'ok'
except Exception,e:
#print e
print '%s %s'%(e,uri)
#out = StringIO()
#print_exc(file=out)
#logger.info("check %s fail %s"%(server,out.getvalue()))
class Executor(threading.Thread):
def __init__(self,queue):
threading.Thread.__init__(self)
self.queue = queue
def run(self):
while running:
url = self.queue.get()
print queue.qsize()
check(url)
self.queue.task_done()
def analysis(readline,queue):
r = re.compile("\d+")
mc_url = re.compile("GET /[a-zA-Z/0-9_?=&]*")
result = {}
for read in readline:
ip=url=http_code=http_time = None
match = mc_url.search(read)
if match:
url = str(match.group())[4:].strip()
queue.put(url)
def clean(a,b):
print 'exit'
running=False
exit(1)
from signal import signal,SIGTERM,SIGINT,SIGQUIT
signal(SIGTERM,clean)
signal(SIGINT,clean)
signal(SIGQUIT,clean)
if __name__ == "__main__":
queue = Queue.Queue()
for i in range(thread_count):
t = Executor(queue)
t.setDaemon(True)
t.start()
f = open("by_category","r")
analysis(f.readlines(),queue)
print "total %s" %queue.qsize()
queue.join()
print 'exit'
running = False
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
간단! Certbot을 사용하여 웹 사이트를 SSL(HTTPS)화하는 방법초보자가 인프라 주위를 정돈하는 것은 매우 어렵습니다. 이번은 사이트를 간단하게 SSL화(HTTP에서 HTTPS통신)로 변경하는 방법을 소개합니다! 이번에는 소프트웨어 시스템 Nginx CentOS7 의 환경에서 S...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.