Skip to content

Commit da2f489

Browse files
M0NsTeRRRpryorda
andauthored
feat(sensors): Adding sensor metrics
* [Update] Refactor alarm fetching system * [Update] Add sensors vmware_host_sensor_state vmware_host_sensor_fan vmware_host_sensor_temperature vmware_host_sensor_power_voltage vmware_host_sensor_power_current vmware_host_sensor_power_watt vmware_host_sensor_redundancy * [Fix] Pipeline flake8 * [Fix] Pipeline flake8 * [Fix] Pipeline LGTM * [Update] handle 2 others metrics runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo runtime.healthSystemRuntime.hardwareStatusInfo.memoryStatusInfo Co-authored-by: Daniel Pryor <[email protected]>
1 parent dc6c807 commit da2f489

File tree

3 files changed

+254
-85
lines changed

3 files changed

+254
-85
lines changed

tests/unit/test_vmware_exporter.py

Lines changed: 116 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,6 @@ def test_collect_hosts():
656656
},
657657
'triggeredAlarmState': '',
658658
'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo': '',
659-
'runtime.healthSystemRuntime.hardwareStatusInfo.memoryStatusInfo': '',
660-
'runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo': '',
661659
},
662660
'host:2': {
663661
'id': 'host:2',
@@ -667,8 +665,6 @@ def test_collect_hosts():
667665
'summary.customValue': {},
668666
'triggeredAlarmState': '',
669667
'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo': '',
670-
'runtime.healthSystemRuntime.hardwareStatusInfo.memoryStatusInfo': '',
671-
'runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo': '',
672668
},
673669
'host:3': {
674670
'id': 'host:3',
@@ -690,8 +686,6 @@ def test_collect_hosts():
690686
'summary.customValue': {},
691687
'triggeredAlarmState': '',
692688
'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo': '',
693-
'runtime.healthSystemRuntime.hardwareStatusInfo.memoryStatusInfo': '',
694-
'runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo': '',
695689
},
696690
'host:4': {
697691
'id': 'host:4',
@@ -713,8 +707,6 @@ def test_collect_hosts():
713707
'summary.customValue': {},
714708
'triggeredAlarmState': '',
715709
'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo': '',
716-
'runtime.healthSystemRuntime.hardwareStatusInfo.memoryStatusInfo': '',
717-
'runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo': '',
718710
},
719711
'host:5': {
720712
'id': 'host:5',
@@ -740,9 +732,27 @@ def test_collect_hosts():
740732
'triggeredAlarm:HostCPUUsageAlarm:yellow'
741733
)
742734
),
743-
'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo': 'sensorInfo:OtherAlarm:red',
744-
'runtime.healthSystemRuntime.hardwareStatusInfo.memoryStatusInfo': 'memoryStatusInfo:OtherAlarm:yellow',
745-
'runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo': 'cpuStatusInfo:OtherAlarm:yellow'
735+
'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo': ','.join(
736+
(
737+
'numericSensorInfo:name=Fan Device 12 System Fan '
738+
'6B:type=fan:sensorStatus=yellow:value=821700:unitModifier=-2:unit=rpm',
739+
'numericSensorInfo:name=Power Supply 2 PS2 '
740+
'Temperature:type=temperature:sensorStatus=green:value=2900:unitModifier=-2:unit=degrees c',
741+
'numericSensorInfo:name=System Board 1 VR Watchdog '
742+
'0:type=voltage:sensorStatus=red:value=2000:unitModifier=0:unit=volts',
743+
'numericSensorInfo:name=Power Supply 2 Current '
744+
'2:type=power:sensorStatus=green:value=20:unitModifier=-2:unit=amps',
745+
'numericSensorInfo:name=System Board 1 Pwr '
746+
'Consumption:type=power:sensorStatus=green:value=7000:unitModifier=-2:unit=watts',
747+
'numericSensorInfo:name=Cooling Unit 1 Fan Redundancy '
748+
'0:type=power:sensorStatus=green:value=1:unitModifier=0:unit=redundancy-discrete',
749+
'numericSensorInfo:name=Management Controller Firmware 2 NM '
750+
'Capabilities:type=other:sensorStatus=unknown:value=5:unitModifier=0:unit=unspecified',
751+
'cpuStatusInfo:name=CPU 1:type=n/a:sensorStatus=green:value=n/a:unitModifier=n/a:unit=n/a',
752+
'memoryStatusInfo:name=Memory 12:type=n/a:sensorStatus=yellow:value=n/a:unitModifier=n/a'
753+
':unit=n/a',
754+
)
755+
),
746756
},
747757
})
748758
yield collector._vmware_get_hosts(metrics)
@@ -845,16 +855,108 @@ def test_collect_hosts():
845855
}
846856

847857
# Host:5 testing alarms
848-
assert metrics['vmware_host_yellow_alarms'].samples[4][2] == 3
849-
assert metrics['vmware_host_red_alarms'].samples[4][2] == 2
858+
assert metrics['vmware_host_yellow_alarms'].samples[4][2] == 1
859+
assert metrics['vmware_host_red_alarms'].samples[4][2] == 1
850860

851861
assert metrics['vmware_host_yellow_alarms'].samples[4][1] == {
852862
'cluster_name': 'cluster',
853863
'customValue1': 'n/a',
854864
'customValue2': 'n/a',
855865
'dc_name': 'dc',
856866
'host_name': 'host-5',
857-
'alarms': 'triggeredAlarm:HostCPUUsageAlarm,cpuStatusInfo:OtherAlarm,memoryStatusInfo:OtherAlarm'
867+
'alarms': 'triggeredAlarm:HostCPUUsageAlarm'
868+
}
869+
870+
# Host:5 testing sensors
871+
assert len(metrics['vmware_host_sensor_state'].samples) == 9
872+
assert metrics['vmware_host_sensor_state'].samples[3][1] == {
873+
'cluster_name': 'cluster',
874+
'customValue1': 'n/a',
875+
'customValue2': 'n/a',
876+
'dc_name': 'dc',
877+
'host_name': 'host-5',
878+
'name': 'Power Supply 2 Current 2',
879+
'type': 'power'
880+
}
881+
882+
assert metrics['vmware_host_sensor_fan'].samples[0][2] == 8217
883+
assert metrics['vmware_host_sensor_fan'].samples[0][1] == {
884+
'cluster_name': 'cluster',
885+
'customValue1': 'n/a',
886+
'customValue2': 'n/a',
887+
'dc_name': 'dc',
888+
'host_name': 'host-5',
889+
'name': 'Fan Device 12 System Fan 6B',
890+
}
891+
892+
assert metrics['vmware_host_sensor_temperature'].samples[0][2] == 29
893+
assert metrics['vmware_host_sensor_temperature'].samples[0][1] == {
894+
'cluster_name': 'cluster',
895+
'customValue1': 'n/a',
896+
'customValue2': 'n/a',
897+
'dc_name': 'dc',
898+
'host_name': 'host-5',
899+
'name': 'Power Supply 2 PS2 Temperature',
900+
}
901+
902+
assert metrics['vmware_host_sensor_power_voltage'].samples[0][2] == 2000
903+
assert metrics['vmware_host_sensor_power_voltage'].samples[0][1] == {
904+
'cluster_name': 'cluster',
905+
'customValue1': 'n/a',
906+
'customValue2': 'n/a',
907+
'dc_name': 'dc',
908+
'host_name': 'host-5',
909+
'name': 'System Board 1 VR Watchdog 0',
910+
}
911+
912+
assert metrics['vmware_host_sensor_power_current'].samples[0][2] == 0.2
913+
assert metrics['vmware_host_sensor_power_current'].samples[0][1] == {
914+
'cluster_name': 'cluster',
915+
'customValue1': 'n/a',
916+
'customValue2': 'n/a',
917+
'dc_name': 'dc',
918+
'host_name': 'host-5',
919+
'name': 'Power Supply 2 Current 2',
920+
}
921+
922+
assert metrics['vmware_host_sensor_power_watt'].samples[0][2] == 70
923+
assert metrics['vmware_host_sensor_power_watt'].samples[0][1] == {
924+
'cluster_name': 'cluster',
925+
'customValue1': 'n/a',
926+
'customValue2': 'n/a',
927+
'dc_name': 'dc',
928+
'host_name': 'host-5',
929+
'name': 'System Board 1 Pwr Consumption',
930+
}
931+
932+
assert metrics['vmware_host_sensor_redundancy'].samples[0][2] == 1
933+
assert metrics['vmware_host_sensor_redundancy'].samples[0][1] == {
934+
'cluster_name': 'cluster',
935+
'customValue1': 'n/a',
936+
'customValue2': 'n/a',
937+
'dc_name': 'dc',
938+
'host_name': 'host-5',
939+
'name': 'Cooling Unit 1 Fan Redundancy 0',
940+
}
941+
942+
assert metrics['vmware_host_sensor_state'].samples[7][1] == {
943+
'cluster_name': 'cluster',
944+
'customValue1': 'n/a',
945+
'customValue2': 'n/a',
946+
'dc_name': 'dc',
947+
'host_name': 'host-5',
948+
'name': 'CPU 1',
949+
'type': 'n/a'
950+
}
951+
952+
assert metrics['vmware_host_sensor_state'].samples[8][1] == {
953+
'cluster_name': 'cluster',
954+
'customValue1': 'n/a',
955+
'customValue2': 'n/a',
956+
'dc_name': 'dc',
957+
'host_name': 'host-5',
958+
'name': 'Memory 12',
959+
'type': 'n/a'
858960
}
859961

860962

vmware_exporter/helpers.py

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -107,55 +107,41 @@ def batch_fetch_properties(content, obj_type, properties):
107107

108108
elif 'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo' == prop.name:
109109
"""
110-
host hardware sensors alarms
110+
handle numericSensorInfo
111111
"""
112-
try:
113-
alarms = list(
114-
'sensorInfo:{}:{}'.format(item.name.replace(' ', ''), item.healthState.key.lower())
115-
for item in prop.val if item.healthState.key.lower() not in ('green', 'unknown')
116-
)
117-
except Exception:
118-
alarms = ['sensorInfo:AlarmsUnavailable:yellow']
119-
120-
properties[prop.name] = ','.join(alarms)
121-
122-
elif 'runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo' == prop.name:
123-
"""
124-
cpu status info alarms
125-
"""
126-
try:
127-
alarms = list(
128-
'cpuStatusInfo:{}:{}'.format(item.name.replace(' ', ''), item.status.key.lower())
129-
for item in prop.val if item.status.key.lower() not in ('green', 'unknown')
112+
sensors = list(
113+
'numericSensorInfo:name={}:type={}:sensorStatus={}:value={}:unitModifier={}:unit={}'.format(
114+
item.name,
115+
item.sensorType,
116+
item.healthState.key,
117+
item.currentReading,
118+
item.unitModifier,
119+
item.baseUnits.lower()
130120
)
131-
except Exception:
132-
alarms = ['cpuStatusInfo:AlarmsUnavailable:yellow']
133-
134-
properties[prop.name] = ','.join(alarms)
121+
for item in prop.val
122+
)
123+
properties[prop.name] = ','.join(sensors)
135124

136-
elif 'runtime.healthSystemRuntime.hardwareStatusInfo.memoryStatusInfo' == prop.name:
125+
elif prop.name in [
126+
'runtime.healthSystemRuntime.hardwareStatusInfo.cpuStatusInfo',
127+
'runtime.healthSystemRuntime.hardwareStatusInfo.memoryStatusInfo',
128+
]:
137129
"""
138-
memory status info alarms
130+
handle hardwareStatusInfo
139131
"""
140-
try:
141-
alarms = list(
142-
'memoryStatusInfo:{}:{}'.format(item.name.replace(' ', ''), item.status.key.lower())
143-
for item in prop.val if item.status.key.lower() not in ('green', 'unknown')
132+
sensors = list(
133+
'numericSensorInfo:name={}:type={}:sensorStatus={}:value={}:unitModifier={}:unit={}'.format(
134+
item.name,
135+
"n/a",
136+
item.status.key,
137+
"n/a",
138+
"n/a",
139+
"n/a",
144140
)
145-
except Exception:
146-
alarms = ['memoryStatusInfo:AlarmsUnavailable:yellow']
147-
148-
properties[prop.name] = ','.join(alarms)
141+
for item in prop.val
142+
)
143+
properties[prop.name] = ','.join(sensors)
149144

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

0 commit comments

Comments
 (0)