Stats in poche righe...

Semplice script (molto elementare) per avere una snapshot del sistema accessibile via web.

Lo script:

#!/usr/bin/python
# by mozako
import sys

WEB_PATH         =    "/var/www/htdocs/"
IFCONFIG_PATH    =    "/sbin/ifconfig"
FREE_PATH        =    "/bin/free"

def net_info():
    file = open(WEB_PATH + "olinfo.htm", 'a')
    print >> file, "Network Information:<br><hr><br>"
    cd = os.popen(IFCONFIG_PATH + " -a")
    for line in cd.readlines():
        file.write(line + "<br>")
    file.write("<br>")
    file.close()

def cpu_info():
    file = open(WEB_PATH + "olinfo.htm", 'a')
    print >> file, "CPU Information:<br><hr><br>"
    cd = os.popen("cat /proc/cpuinfo")
    for line in cd.readlines():
        file.write(line + "<br>")
    file.write("<br>")
    file.close()

def ram_info():
    file = open(WEB_PATH + "olinfo.htm", 'a')
    print >> file, "Memory Information:<br><hr><br>"
    cd = os.popen(FREE_PATH + " -m")
    for line in cd.readlines():
        file.write(line + "<br>")
    file.write("<br>")
    file.close()

def w_info():
    file = open(WEB_PATH + "olinfo.htm", 'a')
    print >> file, "Online users Information:<br><hr><br>"
    cd = os.popen('w')
    for line in cd.readlines():
        file.write(line + "<br>")
    file.write("<br>")
    file.close()

def proc_info():
    file = open(WEB_PATH + "olinfo.htm", 'a')
    print >> file, "Processes Information:<br><hr><br>"
    cd = os.popen('ps aux')
    for line in cd.readlines():
        file.write(line + "<br>")
    file.write("<br>")
    file.close()

def open_web():
    file = open(WEB_PATH + "olinfo.htm", 'w')
    print >> file, "<h2>Stats<br></h2><hr><br><br>"
    file.close()

open_web()
w_info()
ram_info()
cpu_info()
net_info()
proc_info()


Aggiungendo una regoletta allo scheduler del sistema (cron) è possibile aggiornare le statistiche ogni n minuti/ore/giorni.

Privacy Policy