本文整理汇总了Python中monitor.Monitor.update_stats方法的典型用法代码示例。如果您正苦于以下问题:Python Monitor.update_stats方法的具体用法?Python Monitor.update_stats怎么用?Python Monitor.update_stats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类monitor.Monitor
的用法示例。
在下文中一共展示了Monitor.update_stats方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_Monitor_2
# 需要导入模块: from monitor import Monitor [as 别名]
# 或者: from monitor.Monitor import update_stats [as 别名]
def test_Monitor_2(self):
class mock_readSysStats():
def __init__(self):
self.stats = []
# 10 minutes at an average load of 1.5
for i in range(0, 60):
now = i * 10
load = float(i) % 4
up_time = i * 10
data_point = (now, load, up_time)
self.stats.append(data_point)
# 5 more minutes at an average load of 0.5
for i in range(60, 90):
now = i * 10
load = float(i) % 2
up_time = i * 10
data_point = (now, load, up_time)
self.stats.append(data_point)
self.stats_it = iter(self.stats)
def __call__(self):
return next(self.stats_it)
class mock_readData():
def __init__(self, data):
self.data = data
def __call__(self):
return self.data
class mock_saveData():
def __init__(self, data):
self.data = data
def __call__(self, new_data):
self.data.clear()
for k, v in new_data.items():
self.data[k] = new_data[k]
test_data = {
'history': [],
'alertHistory': [],
'uptime' : None,
'tenMinAvg': None,
'minLoad' : None,
'maxLoad' : None,
'tenMinMed': None,
'twoMinAvg': None
}
m = Monitor()
m.readSysStats = mock_readSysStats()
m.readData = mock_readData(test_data)
m.saveData = mock_saveData(test_data)
m.reschedule = (lambda: None)
self.assertFalse(m.high_load)
# Simulate 10 minutes of updates - running at a high load
for i in range(60):
m.update_stats()
self.assertEqual(test_data['tenMinAvg'], 1.5)
self.assertEqual(test_data['tenMinMed'], 1.5)
self.assertEqual(test_data['twoMinAvg'], 1.5)
self.assertEqual(test_data['uptime'], 590)
self.assertEqual(test_data['maxLoad'], 3.0)
self.assertEqual(test_data['minLoad'], 0.0)
self.assertEqual(len(test_data['history']), 60)
self.assertEqual(test_data['history'][0], (590, 3.0))
self.assertEqual(len(test_data['alertHistory']), 1)
self.assertEqual(test_data['alertHistory'][0][0], 110)
self.assertTrue(test_data['alertHistory'][0][1])
self.assertEqual(test_data['alertHistory'][0][2], 1.5)
self.assertTrue(m.high_load)
# Simulate 5 more minutes at low load
for i in range(60, 90):
m.update_stats()
self.assertAlmostEqual(test_data['tenMinAvg'], 1.03333333)
self.assertEqual(test_data['tenMinMed'], 1.0)
self.assertEqual(test_data['twoMinAvg'], 0.5)
self.assertEqual(test_data['uptime'], 890)
self.assertEqual(test_data['maxLoad'], 3.0)
self.assertEqual(test_data['minLoad'], 0.0)
self.assertEqual(len(test_data['history']), 60)
self.assertEqual(test_data['history'][0], (890, 1.0))
self.assertEqual(len(test_data['alertHistory']), 2)
self.assertEqual(test_data['alertHistory'][0][0], 660)
self.assertFalse(test_data['alertHistory'][0][1])
self.assertEqual(test_data['alertHistory'][0][2], 1.0)
self.assertEqual(test_data['alertHistory'][1][0], 110)
self.assertTrue(test_data['alertHistory'][1][1])
#.........这里部分代码省略.........