Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import json
  2. import math
  3. import requests
  4. import sys
  5. from time import sleep
  6.  
  7. IP = "s2.3cte.local" # The IP of the machine hosting your influxdb instance
  8. DB = "test_db" # The database to write to, has to exist
  9. USER = "admin" # The influxdb user to authenticate with
  10. PASSWORD = "ksemwetipg" # The password of that user
  11. TIME = 1 # Delay in seconds between two consecutive update
  12. STATUS_MOD = 5 # The interval in which the updates count will be printed to your console
  13.  
  14. n = 0
  15. temp = 0
  16. while True:
  17. for d in range(0, 360):
  18. with open('/sys/class/thermal/thermal_zone0/temp', 'r') as fin:
  19. temp = fin.read()
  20. v = 'temp_value value=%s' % temp
  21. ## without autentication
  22. #r = requests.post("http://%s:8086/write?db=%s" %(IP, DB), data=v)
  23. ## with autentication
  24. r = requests.post("http://%s/influxdb/write?db=%s" %(IP, DB), auth=(USER, PASSWORD), data=v)
  25. if r.status_code != 204:
  26. print 'Failed to add point to influxdb (%d) - aborting.' %r.status_code
  27. sys.exit(1)
  28. n += 1
  29. sleep(TIME)
  30. if n % STATUS_MOD == 0:
  31. print '%d points inserted.' % n
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement