1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #!/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 = "GTW009002019"
- 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)
- 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)
-
- while True:
- get_cpuusage()
- time.sleep(3)
|