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) 0.45.0 (2014-11-24)
=================== ===================
......
...@@ -2,7 +2,7 @@ from setuptools import setup, find_packages ...@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
import glob import glob
import os import os
version = '0.45.0' version = '0.45.1'
name = 'slapos.toolbox' name = 'slapos.toolbox'
long_description = open("README.txt").read() + "\n" + \ long_description = open("README.txt").read() + "\n" + \
open("CHANGES.txt").read() + "\n" open("CHANGES.txt").read() + "\n"
......
...@@ -9,13 +9,10 @@ import re ...@@ -9,13 +9,10 @@ import re
import sys import sys
import shutil import shutil
import netifaces import netifaces
import random
botname = socket.gethostname() 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 # rtt min/avg/max/mdev = 1.102/1.493/2.203/0.438 ms
ping_re = re.compile( ping_re = re.compile(
".*" ".*"
...@@ -25,6 +22,8 @@ ping_re = re.compile( ...@@ -25,6 +22,8 @@ ping_re = re.compile(
"(?P<mdev>[\d\.]+) ms" "(?P<mdev>[\d\.]+) ms"
) )
date_reg_exp = re.compile('\d{4}[-/]\d{2}[-/]\d{2}')
def _get_network_gateway(self): def _get_network_gateway(self):
return netifaces.gateways()["default"][netifaces.AF_INET][0] return netifaces.gateways()["default"][netifaces.AF_INET][0]
...@@ -92,8 +91,12 @@ def is_rotate_log(log_file_path): ...@@ -92,8 +91,12 @@ def is_rotate_log(log_file_path):
today = time.strftime("%Y-%m-%d") today = time.strftime("%Y-%m-%d")
for line in reversed(log_file.read().split('\n')): for line in reversed(log_file.read().split('\n')):
if len(line.strip()) and not line.startswith(today): if len(line.strip()):
return line.split(" ")[0] match_list = date_reg_exp.findall(line)
if len(match_list):
if match_list[0] != today:
return ValueError(match_list[0])
break
except IOError: except IOError:
return False return False
...@@ -138,13 +141,17 @@ def main(): ...@@ -138,13 +141,17 @@ def main():
else: else:
log_folder = "." log_folder = "."
delay = random.randint(0, 30)
name_list = config.get("network_bench", "dns") name_list = config.get("network_bench", "dns")
url_list = config.get("network_bench", "url") url_list = config.get("network_bench", "url")
ping_list = config.get("network_bench", "ping") ping_list = config.get("network_bench", "ping")
logger = create_logger("info", log_folder) 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(): for name in name_list.split():
info_list = _test_dns(name) 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