最近發現家裡的 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 的值接起來,應該算是有代表性了吧。
Posted by yungyuc at 12:12, 1 comments, 0 trackback.
Add a trackback
Comments
Re: log debian load
應該要用 re 來抓 load value 才對,剛剛沒想到 ^^;
現在這種寫法好像很難看...
-----
酷狗喵千代 at 2004-12-04 12:15.
Add a comment

Your name. (required)

Your personal website. (optional)

Your email address. Will not show in page. (suggested, but optional)

Text format is "Plain Text".

Enter "MyjMx"
© hover year to navigate month: powered by django