123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- #pip3 install psutil
- #pip3 install gpiozero
- import psutil
- import time
- import os
- import datetime
- import requests
- import urllib
- import time
- from gpiozero import CPUTemperature
- path ="http://www.aisky.com.tw/field/reboot.php"
- nr = "GTW009002013"
- def get_cpuusage():
- cpu_usage_core = psutil.cpu_count()
- cpu_usage = psutil.cpu_percent(interval=0.3)
- print('cpu count: {}'.format(cpu_usage_core))
- print('cpu percent: {}'.format(cpu_usage))
-
- cpu = CPUTemperature()
- cpu_temp = cpu.temperature
- print('temperature is :{}'.format(cpu_temp))
-
- if cpu_temp >= 70:
- data = {'nr': nr, 'info': 'overheat', 'data': str(cpu_temp)}
- data = urllib.parse.urlencode(data)
- data = data.encode('utf-8')
- req = urllib.request.Request(path, data)
- req.add_header('User-Agent', 'Magic Browser')
- resp = urllib.request.urlopen(req)
- respData = resp.read()
- print(data)
- time.sleep(1)
- os.system('sudo reboot')
- elif cpu_usage > 60:
- data = {'nr': nr, 'info': 'overload', 'data': str(cpu_usage)}
- data = urllib.parse.urlencode(data)
- data = data.encode('utf-8')
- req = urllib.request.Request(path, data)
- req.add_header('User-Agent', 'Magic Browser')
- resp = urllib.request.urlopen(req)
- respData = resp.read()
- print(data)
- time.sleep(1)
- os.system('sudo reboot')
- while True:
- get_cpuusage()
- time.sleep(3)
|