My favorites | Sign in
Project Logo
                
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/python

"""
Description:
Eyecandy for some visual effects ;-)Extra credits maybe

Displays the rrd graphs in the webpage
Displays the netstat -s output using googleChartsAPI
Author: KishTaylor <kriskmm@gmail.com>, (C) 2008

Copyright: See COPYING file that comes with this distribution
"""

import subProcess
import layout
import cook

def printchart(label):
layout.printhead()
layout.printlayout()
layout.sidepanenew()
print "<center>"
print "<font color=green size='5'> Network statistics</font><br/>"

print'''<img src="http://chart.apis.google.com/chart?chs=350x150&amp;chd=t:%s,%s,%s&amp;cht=p3&amp;chl=ICMP|TCP|UDP">'''%(label[0],label[1],label[2])

print '''<br/></center>''' # will not work if not connected to inet

def printmem(label):


print "<center>"
print "<font color=green size='5'> Mem stats </font><br/>"
print '''<img src="http://chart.apis.google.com/chart?chs=350x150&amp;chd=t:%s,%s&amp;cht=p3&amp;chl=Used|Free">''' %(label[0],label[1])
print "</center>"




def printimg():

# will be generated daily

print "<center>"
print "<br/><br/><font color=green size='5'> Lan connection daily</font><br/>"
print """<img src="../rrd/landay.png" ><br/>"""

# Takes atleast a day to see the graph
print "<br/><br/><font color=green size='5'> Lan connection weekly</font><br/>"
print """<img src="../rrd/lanweek.png" alt="no image yet"><br/> """

# Takes a month to create the first image

print "<br/><br/><font color=green size='5'> Lan connection monthly</font><br/>"
print """<img src="../rrd/lanmonth.png" alt="no image yet"> <br/>"""

# Takes a year to creat the first image

print "<br/><br/><font color=green size='5'> Lan connection yearly</font><br/>"
print """<img src="../rrd/lanyear.png" alt="no image yet"><br/> """
print "</center>"



def printend():
print """</body></html>"""

def main():
if cook.isvalid(cook.read_client_Cookie()):

label=[0,1,2,3,4,5,6] # this looks dumb even to me but works

# God save us if netstat changes the way it displays the results

cmd = ("netstat -s|grep total|grep -v error|awk '{print $1}'",
"netstat -s|grep ICMP|grep -v error|awk '{print $1}'|head -n 1",
"netstat -s|grep active|grep -v error|awk '{print $1}'",
"netstat -s --udp|grep packets|head -n 1|awk '{print $1}'",
"free -m|grep Mem|awk '{print $2}'",
"free -m|grep Mem|awk '{print $3}'",
"free -m|grep Mem|awk '{print $4}'")

# I love loops

for i in range(0, len(cmd)):
process = subProcess.subProcess(cmd[i])
process.read() #timeeout optional
text = process.outdata
text = text.replace('\n','') # cut out the end line char
label[i] = int(text)
del(process)

label2 = [0,1,2]
label3 = [0,1]
label[0] = float( str(label[0])+'.0')

label2[0] = (label[1]*100)/label[0]
label2[1] = (label[2]*100)/label[0]
label2[2] = (label[3]*100)/label[0]


label3[0] = (label[5]*100)/label[4]
label3[1] = (label[6]*100)/label[4]


printchart(label2)
printmem(label3)
printimg()
printend()

else:
layout.printhead()
layout.printlayout()
print 'Alas! session has expired.<a href= ../admin_login.html> Relogin</a>'


main()

Show details Hide details

Change log

r39 by kishorekumar.mm on Apr 09, 2008   Diff
improved charts with memory availablitly
Go to: 
Sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 3244 bytes, 118 lines

File properties

svn:executable
*
Hosted by Google Code