1
2
3
4
5
6
7
8
9 """
10 Agent zephir pour afficher les partitions montées et leur utilisation
11 """
12
13 from twisted.python import log
14 from twisted.internet import defer
15 from twisted.internet.utils import getProcessOutput
16
17 from zephir.monitor.agentmanager.agent import Agent
18 from zephir.monitor.agentmanager import status
19 from zephir.monitor.agentmanager.data import HTMLData, TableData
20 from zephir.monitor.agentmanager.util import percent
21
22
23 SOFT_LIMIT = 90
24 HARD_LIMIT = 96
25
28
30 p = int(perc[0:-1])
31 if p >= HARD_LIMIT :
32 color = 'red'
33 elif p >= SOFT_LIMIT :
34 color = 'orange'
35 else:
36 color = 'green'
37
38 return """<img src="/static/img/%spix.gif" height="16" width="%s">
39 <img src="/static/img/whitepix.gif" height="16" width="%s">""" % (color,str(p),str(100-p))
40
41
43
46 Agent.__init__(self, name, **params)
47 self.table = TableData([
48 ('name', 'Montage', {'align':'right'}, None),
49 ('device', 'Partition', {'align':'left'}, None),
50 ('type', 'Type', {'align':'right'}, None),
51 ('perc', 'Utilisation', {'align':'right'}, None),
52 ('used', 'Utilisé (Mo)', {'align':'right'}, None),
53 ('free', 'Libre (Mo)', {'align':'right'}, None),
54 ('size', 'Taille (Mo)', {'align':'right'}, None),
55 ('graph', 'Graphe', {'align':'left'}, None) ])
56 self.data = [self.table]
57
59 cmd = getProcessOutput('df',
60 args = ['-kP','--print-type','--exclude-type=tmpfs','--exclude-type=usbfs'],
61 env = {'LC_ALL': 'C'})
62 cmd.addCallback(self.measure_process)
63 return cmd
64
66
67 lmnt = mnt.splitlines()
68
69 lmnt = lmnt[1:]
70 liste=[]
71 for lmn in lmnt :
72 try:
73 l = {}
74 l['name'] = lmn.split()[6]
75 l['device'] = lmn.split()[0]
76 l['type'] = lmn.split()[1]
77 l['perc'] = lmn.split()[5]
78 l['free'] = int(lmn.split()[4])/1024
79 l['used'] = int(lmn.split()[3])/1024
80 l['size'] = int(lmn.split()[2])/1024
81 l['graph'] = perc2img(l['perc'])
82 except:
83 pass
84 liste.append(l)
85 self.measure_data[l['name']] = (int(l['perc'][:-1]), int(l['size']), int(l['used']), int(l['free']), l['type'])
86
87 return {'statistics': liste}
88
90 err = 0
91 warn = 0
92 if self.last_measure is not None:
93
94 for device in self.last_measure.value['statistics']:
95
96 if device['type'] != 'iso9660':
97 if int(device['perc'][:-1]) >= HARD_LIMIT :
98 err+=1
99 if int(device['perc'][:-1]) >= SOFT_LIMIT :
100 warn+=1
101 if err == 1:
102 return status.Error("%d partition remplie à plus de %d %%"%(err,HARD_LIMIT))
103 if err > 1:
104 return status.Error("%d partitions remplies à plus de %d %%"%(err,HARD_LIMIT))
105 if warn == 1:
106 return status.Warn("%d partition remplie à plus de %d %%"%(warn,SOFT_LIMIT))
107 if warn > 1:
108 return status.Warn("%d partitions remplies à plus de %d %%"%(warn,SOFT_LIMIT))
109 return status.OK()
110
112 Agent.write_data(self)
113 if self.last_measure is not None:
114 self.table.table_data = self.last_measure.value['statistics']
115