標籤:

mac電腦的溫度監控+PID溫控(待測試)

我tm受不了我的電腦動不動就炸毛了,而且都很迷。一會兒溫度90+然後風扇2000轉,一會兒溫度40左右風扇猛彪6000轉。於是我打算寫個溫度監控,後續可能會加PID溫控(主要看怎麼實現風扇控制)

1. 安裝istats

gem install iStatsn

調試:

iStats scanniStats enable alln

這樣所有的感測器都被載入了。特別的,溫度基本都在istats extra裡面

2. 寫python

第一步:每一定時間記錄一次,比如每1分鐘

while True:n if (int(time.time())%60 == 0):n t = int(time.time())n time.sleep(59)n

然後調用istats的結果,用到subprocess,直接輸出的格式為

Th1H NB/CPU/GPU HeatPipe 1 Proximity temp: 52.13xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mx1b[93mxe2x96x83x1b[0mx1b[93mxe2x96x85x1b[0mxe2x96x86xe2x96x87nTs0P Palm rest L temp: 35.0xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTs0S Memory Bank Proximity temp: 43.7xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTs1P Unknown temp: 33.88xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTs1S Unknown temp: 43.88xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTs2S Unknown temp: 39.56xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTA0P Ambient temperature temp: 45.0xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTBXT Unknown temp: 38.3xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTB0T Battery TS_MAX temp: 38.3xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTB1T Battery 1 temp: 38.3xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTB2T Battery 2 temp: 35.39xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTCGC PECI GPU temp: 70.0xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mx1b[93mxe2x96x83x1b[0mx1b[93mxe2x96x85x1b[0mx1b[33mxe2x96x86x1b[0mxe2x96x87nTCSA PECI SA temp: 70.0xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mx1b[93mxe2x96x83x1b[0mx1b[93mxe2x96x85x1b[0mx1b[33mxe2x96x86x1b[0mxe2x96x87nTCXC PECI CPU temp: 70.53xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mx1b[93mxe2x96x83x1b[0mx1b[93mxe2x96x85x1b[0mx1b[33mxe2x96x86x1b[0mxe2x96x87nTC0C CPU 0 Core temp: 72.0xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mx1b[93mxe2x96x83x1b[0mx1b[93mxe2x96x85x1b[0mx1b[33mxe2x96x86x1b[0mxe2x96x87nTC0E CPU 0 ?? temp: 76.95xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mx1b[93mxe2x96x83x1b[0mx1b[93mxe2x96x85x1b[0mx1b[33mxe2x96x86x1b[0mxe2x96x87nTC0F CPU 0 ?? temp: 79.06xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mx1b[93mxe2x96x83x1b[0mx1b[93mxe2x96x85x1b[0mx1b[33mxe2x96x86x1b[0mxe2x96x87nTC0P CPU 0 Proximity temp: 65.0xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mx1b[93mxe2x96x83x1b[0mx1b[93mxe2x96x85x1b[0mxe2x96x86xe2x96x87nTC1C Core 1 temp: 70.0xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mx1b[93mxe2x96x83x1b[0mx1b[93mxe2x96x85x1b[0mx1b[33mxe2x96x86x1b[0mxe2x96x87nTHSP Unknown temp: -127.0xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTH0a Unknown temp: 44.25xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTH0b Unknown temp: 43.88xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTH0c Unknown temp: 45.13xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTH0x Unknown temp: 45.13xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTH0A Unknown temp: 44.25xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTH0B Unknown temp: 43.88xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTH0C Unknown temp: 45.13xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTH0F Unknown temp: -38.88xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTH0R Unknown temp: -38.88xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTH0V Unknown temp: 43.5xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTMLB Unknown temp: -127.0xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nTM0P Memory Slot Proximity temp: 55.75xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mx1b[93mxe2x96x83x1b[0mx1b[93mxe2x96x85x1b[0mxe2x96x86xe2x96x87nTPCD Platform Controller Hub Die temp: 64.0xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mx1b[93mxe2x96x83x1b[0mx1b[93mxe2x96x85x1b[0mxe2x96x86xe2x96x87nTW0P AirPort Proximity temp: -127.0xc2xb0C x1b[32mxe2x96x81x1b[0mx1b[32mxe2x96x82x1b[0mxe2x96x83xe2x96x85xe2x96x86xe2x96x87nn

恩。。亂的一比,處理一下,按照n分,然後把奇怪的圖形扔掉就是

import subprocessndataraw = subprocess.check_output(iStats extra, shell = True).split(n)ndatanew = []nfor v in range(0,len(dataraw)-1):n datanew.append(dararaw[v].split( x1b)[0]+n)n

然後看起來滿整潔的

Th1H NB/CPU/GPU HeatPipe 1 Proximity temp: 52.13°CnTs0P Palm rest L temp: 35.0°CnTs0S Memory Bank Proximity temp: 43.7°CnTs1P Unknown temp: 33.88°CnTs1S Unknown temp: 43.88°CnTs2S Unknown temp: 39.56°CnTA0P Ambient temperature temp: 45.0°CnTBXT Unknown temp: 38.3°CnTB0T Battery TS_MAX temp: 38.3°CnTB1T Battery 1 temp: 38.3°CnTB2T Battery 2 temp: 35.39°CnTCGC PECI GPU temp: 70.0°CnTCSA PECI SA temp: 70.0°CnTCXC PECI CPU temp: 70.53°CnTC0C CPU 0 Core temp: 72.0°CnTC0E CPU 0 ?? temp: 76.95°CnTC0F CPU 0 ?? temp: 79.06°CnTC0P CPU 0 Proximity temp: 65.0°CnTC1C Core 1 temp: 70.0°CnTHSP Unknown temp: -127.0°CnTH0a Unknown temp: 44.25°CnTH0b Unknown temp: 43.88°CnTH0c Unknown temp: 45.13°CnTH0x Unknown temp: 45.13°CnTH0A Unknown temp: 44.25°CnTH0B Unknown temp: 43.88°CnTH0C Unknown temp: 45.13°CnTH0F Unknown temp: -38.88°CnTH0R Unknown temp: -38.88°CnTH0V Unknown temp: 43.5°CnTMLB Unknown temp: -127.0°CnTM0P Memory Slot Proximity temp: 55.75°CnTPCD Platform Controller Hub Die temp: 64.0°CnTW0P AirPort Proximity temp: -127.0°Cn

輸出就很簡單:

with open(record.dat, r+) as file:n orig = file.readlines()n out = orig + n + datanewn file.writelines(out)n

基本就完了。完整code:

import subprocessnimport osnimport timennnew=subprocess.check_output(iStats extra, shell = True)nnif os.path.isfile(record.dat):n while True:n if (int(time.time())%60 == 0):n t = int(time.time())n dataraw = subprocess.check_output(istats extra, shell = True).split(n)n datanew = [n, t = + str(t) +nn]n for v in range(0, len(dataraw)):n datanew.append(dataraw[v].split( x1b)[0] + n)n with open(record.dat, r+) as file:n orig = file.readlines()n file.writelines(datanew)n dataraw = []n datanew = []n orig = []n time.sleep(59)nnelse:n with open(record.dat, w) as file:n t = int(time.time())n dataraw = subprocess.check_output(istats extra, shell = True).split(n)n datanew = [t = + str(t) +nn]n for v in range(0,len(dataraw)):n datanew.append(dataraw[v].split( x1b)[0] + n)n file.writelines(datanew)n dataraw = []n datanew = []n orig = []n while True:n if (int(time.time())%60 == 0):n t = int(time.time())n dataraw = subprocess.check_output(istats extra, shell = True).split(n)n datanew = [n, t = + str(t) +nn]n for v in range(0,len(dataraw)):n datanew.append(dataraw[v].split( x1b)[0] + n)n with open(record.dat, r+) as file:n orig = file.readlines()n file.writelines(datanew)n dataraw = []n datanew = []n orig = []n time.sleep(59)n

接下來是如何畫圖。畫圖也很簡單

import osnimport matplotlib.pyplot as pltnnwith open(record.dat, r) as file:n dat = file.readlines()nnlength = len(dat)/38nt = []ntemp = []nfor v in range(0,length):n t.append(dat[v*38].split( = )[1])n temp.append(dat[v*38+2].split(: )[1].split(xc2)[0])nnplt.plot(t,temp,r-)nplt.show()n

於是我就有了下面這個圖,還是和我的預期一致的

推薦閱讀:

人體怎樣散熱最快?
為什麼電腦的做工不直接做到最好反而分成幾個檔次的?
電腦散熱不好,筆記本和Mac Notebook都是,你們的夏天不熱嗎?
如何有效解決高室溫環境下筆記本電腦的散熱問題?
筆記本外接的(墊在底下)的散熱器有用嗎?

TAG:Mac | 散热 | Python |