-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsreport4.py
75 lines (70 loc) · 2.57 KB
/
sreport4.py
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
#!/usr/bin/python
import matplotlib.pyplot as plt
import subprocess
from datetime import *
from calendar import *
from calendar import monthrange
import calendar
def get_all_report():
cluster_list=[]
for i in range(1, 13):
start = datetime(2017, i, 1).date()
res = calendar.monthrange(2017, i)
end = start + timedelta(days=(res[1] - 1))
var1 = str(start)
var2 = str(end)
cmd = " sreport cluster utilisation -n --tres=gres/gpu -t percent start=" + var1 + " end=" + var2
cmd2 = cmd + "| awk -F \" \" '{print $3,$4,$5,$6,$7}'"
cluster_raw = subprocess.Popen(cmd2, stdout=subprocess.PIPE, shell=True).communicate()[0].strip().split('\n')
cluster_raw = cluster_raw[0].split(' ')
if len(cluster_raw) > 1:
cluster_list.append(cluster_raw)
else:
cluster_list.append(['0.0%'])
#cluster_raw = subprocess.Popen(['sh /u/mamlouka/sreport3.sh'], stdout=subprocess.PIPE, shell=True).communicate()[0].strip().split('\n')
#while i < len(cluster_list):
# cluster_list[i] = cluster_list[i].split()
# i=i+1
i=0
j=0
for i in range(0,len(cluster_list)):
for j in range(0,len(cluster_list[i])):
cluster_list[i][j] = cluster_list[i][j].replace('%', ' ').strip()
cluster_list[i][j] = float(cluster_list[i][j])
return cluster_list
print(get_all_report())
stat=get_all_report()
state = ('Allo', 'Down', 'DownP', 'Idle', 'Resd')
mois=['janvier', 'fevrier', 'mars', 'avril', 'mai', 'juin', 'juillet', 'aout', 'septembre', 'octobre', 'novembre', 'decembre']
fig = plt.figure()
fig.subplots_adjust(hspace=0.4, wspace=0.4)
j=1
n=1
print(len(stat))
for i in range(0,(len(stat)-4)):
if len(stat[i]) > 1:
plt.subplot(2, 3, n)
explode = (0, 0.15, 0, 0, 0)
plt.title(mois[i])
plt.pie(stat[i], explode=explode, labels=state, autopct='%1.1f%%', startangle=90, shadow=True)
plt.axis('equal')
n+=1
#else:
#plt.subplot(2, 3, n)
#explode = (0, 0, 0, 0, 0)
#plt.title(mois[i])
#circle=plt.Circle((0,0),2)
#plt.pie(1 , explode=explode, labels=state, autopct='%1.1f%%', startangle=90, shadow=True)
#plt.axis('equal')
plt.tight_layout()
plt.show()
for i in range(8,len(stat)):
if len(stat[i]) > 1:
plt.subplot(2, 3, j)
explode = (0, 0.15, 0, 0, 0)
plt.title(mois[i])
plt.pie(stat[i], explode=explode, labels=state, autopct='%1.1f%%', startangle=90, shadow=True)
plt.axis('equal')
j+=1
plt.tight_layout()
plt.show()