Skip to content

Instantly share code, notes, and snippets.

@wulab
Last active April 26, 2020 15:59
Show Gist options
  • Save wulab/69d42dd830a6a49bbc8bbe66f223fb91 to your computer and use it in GitHub Desktop.
Save wulab/69d42dd830a6a49bbc8bbe66f223fb91 to your computer and use it in GitHub Desktop.
from elasticsearch import Elasticsearch
import time
THERMAL_ZONES = [
"/sys/class/thermal/thermal_zone0",
"/sys/class/thermal/thermal_zone1",
"/sys/class/thermal/thermal_zone2",
]
def build_doc():
doc = {}
doc.update(current_temp())
doc.update(current_time())
return doc
def current_temp():
readings = {}
for thermal_zone in THERMAL_ZONES:
name = read_file(f"{thermal_zone}/type")
temp = read_file(f"{thermal_zone}/temp")
readings[name] = int(temp) / 1000
return readings
def current_time():
return {"timestamp": int(time.time())}
def read_file(file_path):
file_content = ""
with open(file_path) as f:
file_content = f.read()
return file_content.strip()
def main():
es = Elasticsearch()
es.cluster.health(wait_for_status="yellow")
es.index(index="thermals", body=build_doc())
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment