最近發現家裡的 server 工作得蠻辛苦的,load 大概都在 0.5~1.0 附近徘徊。不過也不可能一直去 'uptime' 看 load,所以我就寫了一個簡單的 python script 'logload.py',丟到 cron 裡每 15 分鐘跑一次::
#!/usr/bin/env python
import sys
from popen2 import popen2
from time import strftime
if __name__ == '__main__':
myout, myin = popen2( "uptime" )
rawloads = myout.readlines()[0].split()[-3:]
loads = []
for value in rawloads:
try:
load = value.split(',')[0]
except:
load = value
loads.append( float(load) )
try:
outdev = file( sys.argv[1], 'a' )
except:
outdev = sys.stdout
outdev.write( "%s " % strftime('%Y%m%d-%H:%M:%S') )
for load in loads:
outdev.write( "%.2f " % load )
outdev.write( "\n" )
outdev.close()
我想 15 分鐘的周期,至少可以把第三個 load value 的值接起來,應該算是有代表性了吧。
#!/usr/bin/env python
import sys
from popen2 import popen2
from time import strftime
if __name__ == '__main__':
myout, myin = popen2( "uptime" )
rawloads = myout.readlines()[0].split()[-3:]
loads = []
for value in rawloads:
try:
load = value.split(',')[0]
except:
load = value
loads.append( float(load) )
try:
outdev = file( sys.argv[1], 'a' )
except:
outdev = sys.stdout
outdev.write( "%s " % strftime('%Y%m%d-%H:%M:%S') )
for load in loads:
outdev.write( "%.2f " % load )
outdev.write( "\n" )
outdev.close()
我想 15 分鐘的周期,至少可以把第三個 load value 的值接起來,應該算是有代表性了吧。
Navigate
- Previous: Jython Webapp Tutorial @2004/12/04
- Next: げんしけん 第六話 「サブカルチャーをめぐる他者との関係論」 @2004/12/04
Add a trackback
Please send trackback to: http://blog.seety.org/everydaywork/2004/12/4/127/trackback/.
Comments
Add a comment
現在這種寫法好像很難看...
-----