找个PYTHON程序给大家瞧瞧
##检查内存、CPU运行状态,并通过网关向手机发送状态报告
import os
if os.name=='nt':
STPROFILE='c:/etc/syscheck.pf'
WEBPATH='c:\\etc\\web\\'
else:
STPROFILE='/etc/syscheck.pf'
WEBPATH='\\etc\\web\\'
import time
import smlib
import string
import srpc
import win32api
import thread
import traceback
from netman import *
syscheck_version='1.1'
threaddoing=[] #用于存放现在执行中的线程描述
file_lock=thread.allocate_lock()
threaddoing_lock=thread.allocate_lock()
sysname=smlib.getConfigStr(STPROFILE,'esys','name','landpage') #共用参数
# Logging support
# ===============
logfile = "" # Filename to log to, if not empty
logfp = None # File object to log to, if not None
def initlog(*allargs):
"""Write a log message, if there is a log file.
Even though this function is called initlog(), you should always
use log(); log is a variable that is set either to initlog
(initially), to dolog (once the log file has been opened), or to
nolog (when logging is disabled).
The first argument is a format string; the remaining arguments (if
any) are arguments to the % operator, so e.g.
log("%s: %s", "a", "b")
will write "a: b" to the log file, followed by a newline.
If the global logfp is not None, it should be a file object to
which log data is written.
If the global logfp is None, the global logfile may be a string
giving a filename to open, in append mode. This file should be
world writable!!! If the file can't be opened, logging is
silently disabled (since there is no safe place where we could
send an error message).
"""
global logfp, log
if logfile and not logfp:
try:
logfp = open(logfile, "a")
except IOError:
pass
if not logfp:
log = nolog
else:
log = dolog
apply(log, allargs)
def dolog(fmt, *args):
"""Write a log message to the log file. See initlog() for docs."""
global logfp
while 1:
if (file_lock.acquire(0)):
logfp.write(fmt%args + "\n")
logfp.close()
print '日志已记录,日志文件关闭!'
if logfile:
try:
logfp = open(logfile, "a")
print '日志文件打开!'
except IOError:
print '日志文件打开失败!'
pass
file_lock.release()
break
else:
time.sleep(1)
def nolog(*allargs):
"""Dummy function, assigned to log when logging is disabled."""
print '无日志记录!'
pass
log = initlog # The current logging function
def getcompproc():
## print 'getcompproc now!'
res=Getcompproc()
return res[0][1:],res[1][1:],res[2][1:],res[3][1:],res[4][1:]
def getdiskfree(path):
## print '---------------------------------'
## print '分区:',path,'磁盘空间情况!'
## print '---------------------------------'
res=Getdiskfree(path)
if res==None:
log( 'Args send wrong!--%s\r\n',getNowTime())
## if res[4]:
## logwrongmsg(res[4])
## return -1,-1
total=(res[0]*res[1]*res[3])/(1024*1024)
free=(res[0]*res[1]*res[2])/(1024*1024)
## print '每扇区段数:',res[0]
## print '每段字节数:',res[1]
## print '空扇区数:',res[2]
## print '扇区总数:',res[3]
## print '返回值:',res[4]
## print '\r\n'
print path
print '可用字节数:',res[0]*res[1]*res[2]
print '字节总数:',res[0]*res[1]*res[3]
return total,free
def add_stringname(name,add):
if name=='':
name+=add
else:
name+=','+add
return name