7 from resource
import VzUbcMonResource
10 ###########################################################################
11 class VzUbcMonParser(object):
13 Parser to read /proc/user_beancounters and hold the values
14 in a sequence of VzUbcMonResource
17 #----------------------------------------------------------------------
18 def __init__(self
, filename
):
19 self
._filename
= filename
20 self
._bc
_version
= None
21 self
._resources
= None
23 #----------------------------------------------------------------------
24 def get_resources(self
):
26 Parse and return the current UBC values for the system
28 | **return** resources (dict)
30 if self
._resources
is None:
33 return self
._resources
35 #----------------------------------------------------------------------
36 def get_information(self
):
38 Return the version field of the parsed bean counters file and the container ID
40 | **return** beancounter_version, container_id (tuple)
42 if self
._resources
is None:
45 return self
._bc
_version
47 #----------------------------------------------------------------------
50 Parse /proc/user_beancounters and store the values in the object
52 ubc_file
= open(self
._filename
, 'r')
56 values
= line
.strip().split()
57 values_len
= len(values
)
59 self
._bc
_version
= values
[1]
64 # we got the container id
66 self
._resources
[current_ctid
] = {}
71 resource_name
= values
[0]
72 resource_values
= values
[1:] # skip the name
73 self
._resources
[current_ctid
][resource_name
] = \
74 VzUbcMonResource(resource_seq
=resource_values
)
79 if __name__
== '__main__':
80 from pprint
import pprint
81 pprint(VzUbcMonParser('sample_host').get_resources())