couple small changes in python. Turns out I can't use mongo in grafana
This commit is contained in:
parent
fed3c7ee6f
commit
2939999dc4
76
py/ps_fields.py
Normal file
76
py/ps_fields.py
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
field_defs = {
|
||||||
|
'PID': {
|
||||||
|
'desc': 'PID',
|
||||||
|
'dtype': str,
|
||||||
|
},
|
||||||
|
'PPID': {
|
||||||
|
'desc': 'Parent PID',
|
||||||
|
'dtype': str,
|
||||||
|
},
|
||||||
|
'UID': {
|
||||||
|
'desc': 'User ID',
|
||||||
|
'dtype': str,
|
||||||
|
},
|
||||||
|
'LXC': {
|
||||||
|
'desc': 'LXC ID',
|
||||||
|
'dtype': str,
|
||||||
|
},
|
||||||
|
'%CUU': {
|
||||||
|
'desc': 'CPU Use',
|
||||||
|
'dtype': float,
|
||||||
|
},
|
||||||
|
'%MEM': {
|
||||||
|
'desc': 'Memory Use',
|
||||||
|
'dtype': float,
|
||||||
|
},
|
||||||
|
'VSZ': {
|
||||||
|
'desc': 'Virtual Memory',
|
||||||
|
'dtype': int,
|
||||||
|
'mult': 1024,
|
||||||
|
},
|
||||||
|
'RSS': {
|
||||||
|
'desc': 'Resident Memory',
|
||||||
|
'dtype': int,
|
||||||
|
'mult': 1024,
|
||||||
|
},
|
||||||
|
'PSS': {
|
||||||
|
'desc': 'Proportional Shared Memory',
|
||||||
|
'dtype': int,
|
||||||
|
'mult': 1024,
|
||||||
|
},
|
||||||
|
'USS': {
|
||||||
|
'desc': 'Unique Memory',
|
||||||
|
'dtype': int,
|
||||||
|
'mult': 1024,
|
||||||
|
},
|
||||||
|
'SZ': {
|
||||||
|
'desc': 'Core Size',
|
||||||
|
'dtype': int,
|
||||||
|
'mult': 4096,
|
||||||
|
},
|
||||||
|
'SIZE': {
|
||||||
|
'desc': 'Approximate Memory',
|
||||||
|
'dtype': int,
|
||||||
|
'mult': 1024,
|
||||||
|
},
|
||||||
|
'THCNT': {
|
||||||
|
'desc': 'Thread Count',
|
||||||
|
'dtype': int,
|
||||||
|
},
|
||||||
|
'TIME': {
|
||||||
|
'desc': 'Execution Time',
|
||||||
|
'dtype': int,
|
||||||
|
},
|
||||||
|
'ELAPSED': {
|
||||||
|
'desc': 'Elapsed Time',
|
||||||
|
'dtype': int,
|
||||||
|
},
|
||||||
|
'STAT': {
|
||||||
|
'desc': 'Status',
|
||||||
|
'dtype': str,
|
||||||
|
},
|
||||||
|
'COMMAND': {
|
||||||
|
'desc': 'Command',
|
||||||
|
'dtype': str,
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,86 +1,8 @@
|
|||||||
field_defs = {
|
from ps_fields import *
|
||||||
'PID': {
|
import mongodb
|
||||||
'desc': 'PID',
|
|
||||||
'dtype': str,
|
|
||||||
},
|
|
||||||
'PPID': {
|
|
||||||
'desc': 'Parent PID',
|
|
||||||
'dtype': str,
|
|
||||||
},
|
|
||||||
'UID': {
|
|
||||||
'desc': 'User ID',
|
|
||||||
'dtype': str,
|
|
||||||
},
|
|
||||||
'LXC': {
|
|
||||||
'desc': 'LXC ID',
|
|
||||||
'dtype': str,
|
|
||||||
},
|
|
||||||
'%CUU': {
|
|
||||||
'desc': 'CPU Use',
|
|
||||||
'dtype': float,
|
|
||||||
},
|
|
||||||
'%MEM': {
|
|
||||||
'desc': 'Memory Use',
|
|
||||||
'dtype': float,
|
|
||||||
},
|
|
||||||
'VSZ': {
|
|
||||||
'desc': 'Virtual Memory',
|
|
||||||
'dtype': int,
|
|
||||||
'mult': 1024,
|
|
||||||
},
|
|
||||||
'RSS': {
|
|
||||||
'desc': 'Resident Memory',
|
|
||||||
'dtype': int,
|
|
||||||
'mult': 1024,
|
|
||||||
},
|
|
||||||
'PSS': {
|
|
||||||
'desc': 'Proportional Shared Memory',
|
|
||||||
'dtype': int,
|
|
||||||
'mult': 1024,
|
|
||||||
},
|
|
||||||
'USS': {
|
|
||||||
'desc': 'Unique Memory',
|
|
||||||
'dtype': int,
|
|
||||||
'mult': 1024,
|
|
||||||
},
|
|
||||||
'SZ': {
|
|
||||||
'desc': 'Core Size',
|
|
||||||
'dtype': int,
|
|
||||||
'mult': 4096,
|
|
||||||
},
|
|
||||||
'SIZE': {
|
|
||||||
'desc': 'Approximate Memory',
|
|
||||||
'dtype': int,
|
|
||||||
'mult': 1024,
|
|
||||||
},
|
|
||||||
'THCNT': {
|
|
||||||
'desc': 'Thread Count',
|
|
||||||
'dtype': int,
|
|
||||||
},
|
|
||||||
'TIME': {
|
|
||||||
'desc': 'Execution Time',
|
|
||||||
'dtype': int,
|
|
||||||
},
|
|
||||||
'ELAPSED': {
|
|
||||||
'desc': 'Elapsed Time',
|
|
||||||
'dtype': int,
|
|
||||||
},
|
|
||||||
'STAT': {
|
|
||||||
'desc': 'Status',
|
|
||||||
'dtype': str,
|
|
||||||
},
|
|
||||||
'COMMAND': {
|
|
||||||
'desc': 'Command',
|
|
||||||
'dtype': str,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def parseFile(fname):
|
def parsePsOutput(output):
|
||||||
f = open(fname, 'r')
|
data = output.split('\n')
|
||||||
data = f.read()
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
data = data.split('\n')
|
|
||||||
data = list(filter(bool, [line.split() for line in data]))
|
data = list(filter(bool, [line.split() for line in data]))
|
||||||
header = data[0]
|
header = data[0]
|
||||||
procs = []
|
procs = []
|
||||||
@ -91,11 +13,21 @@ def parseFile(fname):
|
|||||||
field = field_defs[header[i]]
|
field = field_defs[header[i]]
|
||||||
value = line[i]
|
value = line[i]
|
||||||
if i == len(header):
|
if i == len(header):
|
||||||
|
# combine command arguments together to one string
|
||||||
value = ' '.join(line[i:])
|
value = ' '.join(line[i:])
|
||||||
|
|
||||||
value = field['dtype'](value)
|
value = field['dtype'](value)
|
||||||
if 'mult' in field:
|
if 'mult' in field:
|
||||||
|
# mult if applicable
|
||||||
value *= field['mult']
|
value *= field['mult']
|
||||||
|
|
||||||
proc[header[i]] = value
|
proc[header[i]] = value
|
||||||
|
|
||||||
procs.append(proc)
|
procs.append(proc)
|
||||||
return procs
|
return procs
|
||||||
|
|
||||||
|
def parseFile(fname):
|
||||||
|
f = open(fname, 'r')
|
||||||
|
data = f.read()
|
||||||
|
f.close()
|
||||||
|
return parsePsOutput(data)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user