Created
May 4, 2016 05:16
-
-
Save kayhayen/5b9173253dc375d910af3402c4498631 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import sys | |
import datetime | |
import sensors | |
import time | |
config = {} | |
with open("/etc/default/collect_sensors.conf") as config_file: | |
exec config_file in config | |
if "interval" not in config: | |
sys.exit("Error, need to specify period interval=<value>") | |
interval = int(config["interval"]) | |
del config["interval"] | |
if not config: | |
sys.exit("Error, no sensors specified.") | |
sensors.init() | |
def main(): | |
with open("sensors.prom", "w") as output_file: | |
while 1: | |
data = {} | |
for chip in sensors.iter_detected_chips(): | |
for feature in chip: | |
data[ "%s/%s" % ( chip, feature.label ) ] = feature.get_value() | |
when = int(time.time()) | |
output_file.seek(0) | |
output_file.truncate() | |
for name, sensor_name in config.items(): | |
if type(sensor_name) is not str: | |
continue | |
metric_name = "sensors_" + name.lower() | |
output_file.write( | |
"# TYPE %(metric_name)s gauge\n%(metric_name)s %(measured)s\n" % { | |
"metric_name" : metric_name, | |
"measured" : data[sensor_name], | |
# "timestamp" : when | |
} | |
) | |
output_file.flush() | |
time.sleep(interval) | |
if __name__ == "__main__": | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interval = 30 | |
{% if ansible_fqdn == "juschinka.home" %} | |
fan2 = "dell_smm-virtual-0/Processor Fan" | |
cpu = "dell_smm-virtual-0/CPU" | |
ambient = "dell_smm-virtual-0/Ambient" | |
{% endif %} | |
{% if ansible_fqdn == "anna.home" %} | |
fan1 = "nct6776-isa-0290/fan1" | |
fan2 = "nct6776-isa-0290/fan2" | |
gpu = "radeon-pci-0100/temp1" | |
cpu = "nct6776-isa-0290/CPUTIN" | |
{% endif %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Sensors collector service, input for prometheus node exporter | |
Conflicts=shutdown.target | |
[Service] | |
WorkingDirectory=/var/spool/prometheus | |
ExecStart=/usr/local/bin/collect_sensors.py | |
Restart=always | |
User=prometheus | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment