Added host overload logging
This commit is contained in:
parent
1ba9d5d8be
commit
34ee836a9d
@ -165,6 +165,7 @@ def init_state(config):
|
||||
return {'previous_time': 0.,
|
||||
'previous_cpu_time': dict(),
|
||||
'vir_connection': vir_connection,
|
||||
'hostname': hostname,
|
||||
'physical_cpus': physical_cpus,
|
||||
'physical_cpu_mhz': host_cpu_mhz,
|
||||
'physical_core_mhz': host_cpu_mhz / physical_cpus,
|
||||
@ -256,6 +257,11 @@ def execute(config, state):
|
||||
append_data_remotely(state['db'], cpu_mhz)
|
||||
if log.isEnabledFor(logging.DEBUG):
|
||||
log.debug('Collected new data: %s', str(cpu_mhz))
|
||||
log_host_overload(state['db'],
|
||||
config['host_cpu_overload_threshold'],
|
||||
state['hostname'],
|
||||
state['physical_cpu_mhz'],
|
||||
cpu_mhz.values())
|
||||
state['previous_time'] = current_time
|
||||
state['previous_cpu_time'] = cpu_time
|
||||
return state
|
||||
@ -553,3 +559,28 @@ def get_host_characteristics(vir_connection):
|
||||
"""
|
||||
info = vir_connection.getInfo()
|
||||
return info[2] * info[3], info[1]
|
||||
|
||||
|
||||
@contract()
|
||||
def log_host_overload(db, overload_threshold,
|
||||
hostname, host_mhz, vms_mhz):
|
||||
""" Log to the DB whether the host is overloaded.
|
||||
|
||||
:param db: The database object.
|
||||
:type db: Database
|
||||
|
||||
:param overload_threshold: The host overload threshold.
|
||||
:type overload_threshold: float
|
||||
|
||||
:param hostname: The host name.
|
||||
:type hostname: str
|
||||
|
||||
:param host_mhz: The total frequency of the CPU in MHz.
|
||||
:type host_mhz: int
|
||||
|
||||
:param vms_mhz: A list of CPU utilization of VMs in MHz.
|
||||
:type vms_mhz: list(int)
|
||||
"""
|
||||
db.insert_host_overload(
|
||||
hostname,
|
||||
overload_threshold * host_mhz < sum(vms_mhz))
|
||||
|
@ -78,6 +78,7 @@ class Collector(TestCase):
|
||||
assert state['previous_time'] == 0
|
||||
assert isinstance(state['previous_cpu_time'], dict)
|
||||
assert state['vir_connection'] == vir_connection
|
||||
assert state['hostname'] == hostname
|
||||
assert state['physical_cpus'] == physical_cpus
|
||||
assert state['physical_cpu_mhz'] == mhz
|
||||
assert state['physical_core_mhz'] == mhz / physical_cpus
|
||||
@ -453,3 +454,16 @@ class Collector(TestCase):
|
||||
['x86_64', ram, cores, mhz, 1, 1, 4, 2]).once()
|
||||
assert collector.get_host_characteristics(connection) == \
|
||||
(cores * mhz, ram)
|
||||
|
||||
@qc(1)
|
||||
def log_host_overload():
|
||||
db = db_utils.init_db('sqlite:///:memory:')
|
||||
with MockTransaction:
|
||||
expect(db).insert_host_overload('host', True).once()
|
||||
collector.log_host_overload(db, 0.9, 'host', 3000,
|
||||
[1000, 1000, 800])
|
||||
|
||||
with MockTransaction:
|
||||
expect(db).insert_host_overload('host', False).once()
|
||||
collector.log_host_overload(db, 0.9, 'host', 3000,
|
||||
[1000, 1000, 600])
|
||||
|
Loading…
x
Reference in New Issue
Block a user