Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Sensors #255

Merged
merged 7 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 116 additions & 14 deletions tests/unit/test_vmware_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,6 @@ def test_collect_hosts():
},
'triggeredAlarmState': '',
'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo': '',
'runtime.healthSystemRuntime.hardwareStatusInfo.memoryStatusInfo': '',
'runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo': '',
},
'host:2': {
'id': 'host:2',
Expand All @@ -667,8 +665,6 @@ def test_collect_hosts():
'summary.customValue': {},
'triggeredAlarmState': '',
'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo': '',
'runtime.healthSystemRuntime.hardwareStatusInfo.memoryStatusInfo': '',
'runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo': '',
},
'host:3': {
'id': 'host:3',
Expand All @@ -690,8 +686,6 @@ def test_collect_hosts():
'summary.customValue': {},
'triggeredAlarmState': '',
'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo': '',
'runtime.healthSystemRuntime.hardwareStatusInfo.memoryStatusInfo': '',
'runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo': '',
},
'host:4': {
'id': 'host:4',
Expand All @@ -713,8 +707,6 @@ def test_collect_hosts():
'summary.customValue': {},
'triggeredAlarmState': '',
'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo': '',
'runtime.healthSystemRuntime.hardwareStatusInfo.memoryStatusInfo': '',
'runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo': '',
},
'host:5': {
'id': 'host:5',
Expand All @@ -740,9 +732,27 @@ def test_collect_hosts():
'triggeredAlarm:HostCPUUsageAlarm:yellow'
)
),
'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo': 'sensorInfo:OtherAlarm:red',
'runtime.healthSystemRuntime.hardwareStatusInfo.memoryStatusInfo': 'memoryStatusInfo:OtherAlarm:yellow',
'runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo': 'cpuStatusInfo:OtherAlarm:yellow'
'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo': ','.join(
(
'numericSensorInfo:name=Fan Device 12 System Fan '
'6B:type=fan:sensorStatus=yellow:value=821700:unitModifier=-2:unit=rpm',
'numericSensorInfo:name=Power Supply 2 PS2 '
'Temperature:type=temperature:sensorStatus=green:value=2900:unitModifier=-2:unit=degrees c',
'numericSensorInfo:name=System Board 1 VR Watchdog '
'0:type=voltage:sensorStatus=red:value=2000:unitModifier=0:unit=volts',
'numericSensorInfo:name=Power Supply 2 Current '
'2:type=power:sensorStatus=green:value=20:unitModifier=-2:unit=amps',
'numericSensorInfo:name=System Board 1 Pwr '
'Consumption:type=power:sensorStatus=green:value=7000:unitModifier=-2:unit=watts',
'numericSensorInfo:name=Cooling Unit 1 Fan Redundancy '
'0:type=power:sensorStatus=green:value=1:unitModifier=0:unit=redundancy-discrete',
'numericSensorInfo:name=Management Controller Firmware 2 NM '
'Capabilities:type=other:sensorStatus=unknown:value=5:unitModifier=0:unit=unspecified',
'cpuStatusInfo:name=CPU 1:type=n/a:sensorStatus=green:value=n/a:unitModifier=n/a:unit=n/a',
'memoryStatusInfo:name=Memory 12:type=n/a:sensorStatus=yellow:value=n/a:unitModifier=n/a'
':unit=n/a',
)
),
},
})
yield collector._vmware_get_hosts(metrics)
Expand Down Expand Up @@ -845,16 +855,108 @@ def test_collect_hosts():
}

# Host:5 testing alarms
assert metrics['vmware_host_yellow_alarms'].samples[4][2] == 3
assert metrics['vmware_host_red_alarms'].samples[4][2] == 2
assert metrics['vmware_host_yellow_alarms'].samples[4][2] == 1
assert metrics['vmware_host_red_alarms'].samples[4][2] == 1

assert metrics['vmware_host_yellow_alarms'].samples[4][1] == {
'cluster_name': 'cluster',
'customValue1': 'n/a',
'customValue2': 'n/a',
'dc_name': 'dc',
'host_name': 'host-5',
'alarms': 'triggeredAlarm:HostCPUUsageAlarm,cpuStatusInfo:OtherAlarm,memoryStatusInfo:OtherAlarm'
'alarms': 'triggeredAlarm:HostCPUUsageAlarm'
}

# Host:5 testing sensors
assert len(metrics['vmware_host_sensor_state'].samples) == 9
assert metrics['vmware_host_sensor_state'].samples[3][1] == {
'cluster_name': 'cluster',
'customValue1': 'n/a',
'customValue2': 'n/a',
'dc_name': 'dc',
'host_name': 'host-5',
'name': 'Power Supply 2 Current 2',
'type': 'power'
}

assert metrics['vmware_host_sensor_fan'].samples[0][2] == 8217
assert metrics['vmware_host_sensor_fan'].samples[0][1] == {
'cluster_name': 'cluster',
'customValue1': 'n/a',
'customValue2': 'n/a',
'dc_name': 'dc',
'host_name': 'host-5',
'name': 'Fan Device 12 System Fan 6B',
}

assert metrics['vmware_host_sensor_temperature'].samples[0][2] == 29
assert metrics['vmware_host_sensor_temperature'].samples[0][1] == {
'cluster_name': 'cluster',
'customValue1': 'n/a',
'customValue2': 'n/a',
'dc_name': 'dc',
'host_name': 'host-5',
'name': 'Power Supply 2 PS2 Temperature',
}

assert metrics['vmware_host_sensor_power_voltage'].samples[0][2] == 2000
assert metrics['vmware_host_sensor_power_voltage'].samples[0][1] == {
'cluster_name': 'cluster',
'customValue1': 'n/a',
'customValue2': 'n/a',
'dc_name': 'dc',
'host_name': 'host-5',
'name': 'System Board 1 VR Watchdog 0',
}

assert metrics['vmware_host_sensor_power_current'].samples[0][2] == 0.2
assert metrics['vmware_host_sensor_power_current'].samples[0][1] == {
'cluster_name': 'cluster',
'customValue1': 'n/a',
'customValue2': 'n/a',
'dc_name': 'dc',
'host_name': 'host-5',
'name': 'Power Supply 2 Current 2',
}

assert metrics['vmware_host_sensor_power_watt'].samples[0][2] == 70
assert metrics['vmware_host_sensor_power_watt'].samples[0][1] == {
'cluster_name': 'cluster',
'customValue1': 'n/a',
'customValue2': 'n/a',
'dc_name': 'dc',
'host_name': 'host-5',
'name': 'System Board 1 Pwr Consumption',
}

assert metrics['vmware_host_sensor_redundancy'].samples[0][2] == 1
assert metrics['vmware_host_sensor_redundancy'].samples[0][1] == {
'cluster_name': 'cluster',
'customValue1': 'n/a',
'customValue2': 'n/a',
'dc_name': 'dc',
'host_name': 'host-5',
'name': 'Cooling Unit 1 Fan Redundancy 0',
}

assert metrics['vmware_host_sensor_state'].samples[7][1] == {
'cluster_name': 'cluster',
'customValue1': 'n/a',
'customValue2': 'n/a',
'dc_name': 'dc',
'host_name': 'host-5',
'name': 'CPU 1',
'type': 'n/a'
}

assert metrics['vmware_host_sensor_state'].samples[8][1] == {
'cluster_name': 'cluster',
'customValue1': 'n/a',
'customValue2': 'n/a',
'dc_name': 'dc',
'host_name': 'host-5',
'name': 'Memory 12',
'type': 'n/a'
}


Expand Down
70 changes: 28 additions & 42 deletions vmware_exporter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,55 +107,41 @@ def batch_fetch_properties(content, obj_type, properties):

elif 'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo' == prop.name:
"""
host hardware sensors alarms
handle numericSensorInfo
"""
try:
alarms = list(
'sensorInfo:{}:{}'.format(item.name.replace(' ', ''), item.healthState.key.lower())
for item in prop.val if item.healthState.key.lower() not in ('green', 'unknown')
)
except Exception:
alarms = ['sensorInfo:AlarmsUnavailable:yellow']

properties[prop.name] = ','.join(alarms)

elif 'runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo' == prop.name:
"""
cpu status info alarms
"""
try:
alarms = list(
'cpuStatusInfo:{}:{}'.format(item.name.replace(' ', ''), item.status.key.lower())
for item in prop.val if item.status.key.lower() not in ('green', 'unknown')
sensors = list(
'numericSensorInfo:name={}:type={}:sensorStatus={}:value={}:unitModifier={}:unit={}'.format(
item.name,
item.sensorType,
item.healthState.key,
item.currentReading,
item.unitModifier,
item.baseUnits.lower()
)
except Exception:
alarms = ['cpuStatusInfo:AlarmsUnavailable:yellow']

properties[prop.name] = ','.join(alarms)
for item in prop.val
)
properties[prop.name] = ','.join(sensors)

elif 'runtime.healthSystemRuntime.hardwareStatusInfo.memoryStatusInfo' == prop.name:
elif prop.name in [
'runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo',
'runtime.healthSystemRuntime.hardwareStatusInfo.memoryStatusInfo',
]:
"""
memory status info alarms
handle hardwareStatusInfo
"""
try:
alarms = list(
'memoryStatusInfo:{}:{}'.format(item.name.replace(' ', ''), item.status.key.lower())
for item in prop.val if item.status.key.lower() not in ('green', 'unknown')
sensors = list(
'numericSensorInfo:name={}:type={}:sensorStatus={}:value={}:unitModifier={}:unit={}'.format(
item.name,
"n/a",
item.status.key,
"n/a",
"n/a",
"n/a",
)
except Exception:
alarms = ['memoryStatusInfo:AlarmsUnavailable:yellow']

properties[prop.name] = ','.join(alarms)
for item in prop.val
)
properties[prop.name] = ','.join(sensors)

# storage status info alarms - not included because they made no sense in here
# sine there are specific datastore alarms
#
# elif 'runtime.healthSystemRuntime.hardwareStatusInfo.storageStatusInfo' == prop.name:
# alarms = list(
# 'storageStatusInfo:{}:{}'.format(item.name.replace(' ',''), item.status.key.lower())
# for item in prop.val if item.status.key.lower() not in ('green', 'unknown')
# )
# properties[prop.name] = ','.join(alarms)
else:
properties[prop.name] = prop.val

Expand Down
Loading