# @author andrealmeida import netifaces, time, json, os, psutil data = {} def network_info (): interfaces = netifaces.interfaces() tmp_data = {} interface = "" mac_address = "" ip = "" i = 0 for interface in interfaces: if interface != 'lo': mac_address = netifaces.ifaddresses(interface)[netifaces.AF_LINK][0]['addr'], try: ip = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['addr'] except KeyError: continue tmp_data[i] = { "interface": interface, "mac_address": mac_address, "IP": ip } i += 1 data['interfaces'] = tmp_data data['timestamp'] = time.time() data['machine_status'] = True return data; def measure_temp_info (): temp = os.popen("vcgencmd measure_temp").readline() cpu_temp = temp.replace("temp=","") data['cpu_temp'] = cpu_temp return data; def disk_info(dirname): st = os.statvfs(dirname) tmp_data = {} tmp_data['used_disk_space'] = psutil.disk_usage("/").used / 1024 / 1024 tmp_data['free_disk_space'] = psutil.disk_usage("/").free / 1024 / 1024 tmp_data['total_disk_space'] = psutil.disk_usage(".").total / 1024 / 1024 data['disk'] = tmp_data return data; def memory_info (): data['memory'] = psutil.virtual_memory() return data; def shutdown_pie (): os.system('sudo shutdown now')