Advertisement
Typhoon

Raspberry Pi temp to ELK

Mar 23rd, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import sys
  4. from datetime import datetime
  5. from elasticsearch import Elasticsearch
  6. import RPi.GPIO as GPIO
  7. import ipgetter
  8. GPIO.setmode(GPIO.BCM)
  9. GPIO.setup(17, GPIO.OUT)
  10.  
  11. tFile = open('/sys/class/thermal/thermal_zone0/temp')
  12. temp = float(tFile.read())
  13. tempC = temp/1000
  14. tFile.close()
  15. GPIO.cleanup()
  16. ext_ip = ipgetter.myip()
  17.  
  18. es = Elasticsearch(host='my.server.com', port=9200, http_auth=('admin', 'admin'))
  19. doc = {
  20.     'temperature': tempC,
  21.     'external_ip': ext_ip,
  22.     'author': 'tomas',
  23.     'timestamp': datetime.now()
  24.        }
  25. res = es.index(index="raspberry", doc_type='sys_stats', body=doc)
  26. print datetime.now()
  27. print tempC
  28. print ext_ip
  29. print(res['created'])
  30.  
  31. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement