forked from stfc/telegraf-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics-influxdb-htcondor-groups
executable file
·49 lines (41 loc) · 1.26 KB
/
metrics-influxdb-htcondor-groups
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
#!/usr/bin/python
import sys
import subprocess
p = subprocess.Popen(["condor_config_val", "-negotiator", "GROUP_NAMES"], stdout=subprocess.PIPE)
output, err = p.communicate()
output = output.replace(" ", "")
groups = output.split(',')
p = subprocess.Popen(["condor_userprio", "-grouprollup", "-allusers"], stdout=subprocess.PIPE)
output, err = p.communicate()
lines = output.splitlines(True)
quotas = {}
usage = {}
for line in lines:
if 'ByQuota' in line:
pieces = line.split()
group = pieces[0]
quota = pieces[1]
inuse = pieces[3]
quotas[group] = quota
usage[group] = inuse
if 'Number of users' in line:
pieces = line.split()
total = pieces[5]
data = ''
for group in groups:
if group in quotas and group in usage:
pieces = group.split('.')
percent = 1.0
name = ''
for piece in pieces:
if len(name) > 0:
name = name + '.' + piece
else:
name = piece
percent = percent*float(quotas[name])
cpus = percent*float(total)
fairness = 0
if cpus > 0:
fairness = 100.0*float(usage[group])/cpus
data += "groups,name=%s allocation=%d,usage=%d,fairness=%d\n" % (group, cpus, int(usage[group]), fairness)
print data