Menu

[r540]: / trunk / htdocs / examples / system_monitor.py  Maximize  Restore  History

Download this file

57 lines (42 with data), 1.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
import time
from matplotlib.matlab import *
def get_memory():
"Simulate a function that returns system memory"
return 100*(0.5+0.5*sin(0.5*pi*time.time()))
def get_cpu():
"Simulate a function that returns cpu usage"
return 100*(0.5+0.5*sin(0.2*pi*(time.time()-0.25)))
def get_net():
"Simulate a function that returns network bandwidth"
return 100*(0.5+0.5*sin(0.7*pi*(time.time()-0.1)))
def get_stats():
return get_memory(), get_cpu(), get_net()
fig = figure(1)
ax = subplot(111)
ind = arange(1,4)
pm, pc, pn = bar(ind, get_stats())
centers = ind + 0.5*pm.get_width()
pm.set_facecolor('r')
pc.set_facecolor('g')
pn.set_facecolor('b')
ax.set_xlim([0.5,4])
ax.set_xticks(centers)
ax.set_ylim([0,100])
ax.set_xticklabels(['Memory', 'CPU', 'Bandwidth'])
ax.set_ylabel('Percent usage')
ax.set_title('System Monitor')
manager = get_current_fig_manager()
def updatefig(*args):
m,c,n = get_stats()
pm.set_height(m)
pc.set_height(c)
pn.set_height(n)
ax.set_ylim([0,100])
manager.canvas.draw()
return gtk.TRUE
gtk.timeout_add(250, updatefig)
show()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.