Commit 144d41b6 authored by Rafael Monnerat's avatar Rafael Monnerat

networkbench: Fix log rotating and add a delay

 Include a minor random delay before start to not request all
 sites at same time from multiple computers.
parent d3e58f3c
0.45.1 (2014-11-24)
===================
* Fix logrotate and introduce a delay for `networkbench`.
0.45.0 (2014-11-24)
===================
......
......@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
import glob
import os
version = '0.45.0'
version = '0.45.1'
name = 'slapos.toolbox'
long_description = open("README.txt").read() + "\n" + \
open("CHANGES.txt").read() + "\n"
......
......@@ -9,13 +9,10 @@ import re
import sys
import shutil
import netifaces
import random
botname = socket.gethostname()
# IP adress of the internet box in the LAN, likely found in the output of
# route command
interval = 60 * 5
# rtt min/avg/max/mdev = 1.102/1.493/2.203/0.438 ms
ping_re = re.compile(
".*"
......@@ -25,6 +22,8 @@ ping_re = re.compile(
"(?P<mdev>[\d\.]+) ms"
)
date_reg_exp = re.compile('\d{4}[-/]\d{2}[-/]\d{2}')
def _get_network_gateway(self):
return netifaces.gateways()["default"][netifaces.AF_INET][0]
......@@ -92,8 +91,12 @@ def is_rotate_log(log_file_path):
today = time.strftime("%Y-%m-%d")
for line in reversed(log_file.read().split('\n')):
if len(line.strip()) and not line.startswith(today):
return line.split(" ")[0]
if len(line.strip()):
match_list = date_reg_exp.findall(line)
if len(match_list):
if match_list[0] != today:
return ValueError(match_list[0])
break
except IOError:
return False
......@@ -138,13 +141,17 @@ def main():
else:
log_folder = "."
delay = random.randint(0, 30)
name_list = config.get("network_bench", "dns")
url_list = config.get("network_bench", "url")
ping_list = config.get("network_bench", "ping")
logger = create_logger("info", log_folder)
logger.debug('Starting a new test..')
logger.debug('Starting a new test in %s seconds' % delay)
time.sleep(delay)
for name in name_list.split():
info_list = _test_dns(name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment