-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsensor_exporter.py
More file actions
24 lines (18 loc) · 791 Bytes
/
sensor_exporter.py
File metadata and controls
24 lines (18 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3
import subprocess
import re
def get_sensor_data():
# Run the sensors command and capture its output
output = subprocess.check_output(['sensors'], universal_newlines=True)
# Find lines with temperature readings using regular expressions
temp_readings = re.findall(r'^(.*):\s+\+(\d+\.\d+)°C', output, re.MULTILINE)
return temp_readings
def format_prometheus(temp_readings):
# Prometheus format for temperature readings
for label, value in temp_readings:
# Replace spaces with underscores in sensor names
label = label.replace(' ', '_').lower()
print(f'sensor_temperature_celsius{{sensor="{label}"}} {value}')
if __name__ == '__main__':
temp_readings = get_sensor_data()
format_prometheus(temp_readings)