3 szs/load - a load and cpu usage module for SZS a statusbar script for WMI
11 * added support for 2.4 Kernels
14 * implemented configurable label
18 * implemented cpu/io utilisation
22 * implemented system load
31 Copyright 2004 Christoph Wegscheider <cw@wegi.net>
36 This program is free software; you can redistribute it and/or modify
37 it under the terms of the GNU General Public License as published by
38 the Free Software Foundation; either version 2 of the License, or
39 (at your option) any later version.
41 This program is distributed in the hope that it will be useful,
42 but WITHOUT ANY WARRANTY; without even the implied warranty of
43 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 GNU General Public License for more details.
46 You should have received a copy of the GNU General Public License
47 along with this program; if not, write to the Free Software
48 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
56 oldcpusum = oldcpuutil = oldioutil = 0
59 cfg = szstoolbox.CFG('load')
60 loadlabel = cfg.read('loadlabel')
61 cpulabel = cfg.read('cpulabel')
62 showcpu = int(cfg.read('showcpu'))
63 maxload = int(cfg.read('maxload'))
75 file = open('/proc/stat')
76 values = [int(it) for it in file.readline().split()[1:]]
78 newcpusum = newcpuutil = newioutil = 0
79 for it in values: newcpusum += it
80 for it in values[:3]: newcpuutil += it
81 if szstoolbox.kernel_version[:3] == '2.6':
82 for it in values[4:]: newioutil += it
83 cpusum = newcpusum - oldcpusum
84 bars.append(str((newcpuutil - oldcpuutil) * 100 / cpusum) + '%')
85 if szstoolbox.kernel_version[:3] == '2.6':
86 bars.append(str((newioutil - oldioutil) * 100 / cpusum) + '%' + cpulabel)
88 oldcpuutil = newcpuutil
93 load = os.getloadavg()
95 bars.append(str(int(it / maxload * 100)) + '%')
104 if __name__ == '__main__':
109 time.sleep(szstoolbox.interval)