示例#1
0
    def _update_cgroups(self):
        def collect_by_name(cg, store):
            if cg.fullname not in store:
                store[cg.fullname] = []
            store[cg.fullname].append(cg)

        # Collect cgroups by group name (path)
        cgroups = {}
        for name in self.SUBSYSTEMS:
            try:
                root_cgroup = cgroup.scan_cgroups(name, self.FILTERS[name])
                cgroup.walk_cgroups(root_cgroup, collect_by_name, cgroups)
            except EnvironmentError as e:
                # Don't annoy users by showing error messages
                pass
            except cgroup.NoSuchSubsystemError as e:
                # Some systems don't support all subsystems, for example
                # Parallels Cloud Server and OpenVZ may not have memory subsystem.
                if name not in self.nosubsys_warning_showed:
                    print(e)
                    time.sleep(1)
                    self.nosubsys_warning_showed[name] = True
        self.cgroups = cgroups

        if self.options.hide_root:
            del self.cgroups['/']
示例#2
0
    def run(self, args):
        root_cgroup = cgroup.scan_cgroups(self.options.target_subsystem)

        def collect_configs(_cgroup, store):
            if self.options.debug:
                print(_cgroup)

            if self.options.hide_empty and _cgroup.n_procs == 0:
                return
            if self.options.show_default:
                if self.options.json:
                    store[_cgroup.path] = _cgroup.get_configs()
                else:
                    # To calculate rates, default values are required
                    store[_cgroup.path] = (_cgroup.get_configs(), _cgroup.get_default_configs())
                return
            configs = self._collect_changed_configs(_cgroup)
            if configs:
                if self.options.json:
                    store[_cgroup.path] = configs
                else:
                    # To calculate rates, default values are required
                    store[_cgroup.path] = (configs, _cgroup.get_default_configs())

        cgroups = {}
        cgroup.walk_cgroups(root_cgroup, collect_configs, cgroups)
        if self.options.json:
            import json
            json.dump(cgroups, sys.stdout, indent=4)
        else:
            for name, (configs, defaults) in cgroups.iteritems():
                print(name)
                self._print_configs(configs, defaults)
示例#3
0
    def run(self):
        root_cgroup = cgroup.scan_cgroups(self.args.target_subsystem)

        def print_matched(cg, dummy):
            mypid = os.getpid()
            cg.update()
            for pid in cg.pids:
                if pid == mypid:
                    continue
                proc = process.Process(pid)

                if self.args.cmdline:
                    comp = proc.cmdline
                else:
                    comp = proc.name

                if self.args.ignore_case:
                    comp = comp.lower()
                    _procname = self.args.procname.lower()
                else:
                    _procname = self.args.procname

                if _procname in comp:
                    if self.args.show_name:
                        if self.args.cmdline:
                            output = "%d %s" % (proc.pid, proc.cmdline)
                        else:
                            output = "%d %s" % (proc.pid, proc.name)
                    else:
                        output = str(proc.pid)
                    print('%s: %s' % (cg.path, output))

        cgroup.walk_cgroups(root_cgroup, print_matched, None)
示例#4
0
    def run(self):
        root_cgroup = cgroup.scan_cgroups(self.args.target_subsystem)

        def collect_configs(_cgroup, store):
            if self.args.debug:
                print(_cgroup)

            if self.args.hide_empty and _cgroup.n_procs == 0:
                return
            if self.args.show_default:
                if self.args.json:
                    store[_cgroup.path] = _cgroup.get_configs()
                else:
                    # To calculate rates, default values are required
                    store[_cgroup.path] = (_cgroup.get_configs(),
                                           _cgroup.get_default_configs())
                return
            configs = self._collect_changed_configs(_cgroup)
            if configs:
                if self.args.json:
                    store[_cgroup.path] = configs
                else:
                    # To calculate rates, default values are required
                    store[_cgroup.path] = (configs,
                                           _cgroup.get_default_configs())

        cgroups = {}
        cgroup.walk_cgroups(root_cgroup, collect_configs, cgroups)
        if self.args.json:
            import json
            json.dump(cgroups, sys.stdout, indent=4)
        else:
            for name, (configs, defaults) in cgroups.items():
                print(name)
                self._print_configs(configs, defaults)
    def run(self):
        root_cgroup = cgroup.scan_cgroups(self.target_subsystem)

        def collect_configs(_cgroup, store):
            store[_cgroup.path] = _cgroup.get_stats()

        cgroups = {}
        cgroup.walk_cgroups(root_cgroup, collect_configs, cgroups)

        if self.debug:
            json.dump(cgroups, sys.stdout, indent=4)

        return cgroups
示例#6
0
    def _update_cgroups(self):
        def collect_by_name(cg, store):
            if cg.fullname not in store:
                store[cg.fullname] = []
            store[cg.fullname].append(cg)

        # Collect cgroups by group name (path)
        cgroups = {}
        for name in self.SUBSYSTEMS:
            try:
                root_cgroup = cgroup.scan_cgroups(name, self.FILTERS[name])
                cgroup.walk_cgroups(root_cgroup, collect_by_name, cgroups)
            except EnvironmentError, e:
                # Don't annoy users by showing error messages
                pass
示例#7
0
    def _update_cgroups(self):
        def collect_by_name(cg, store):
            if cg.fullname not in store:
                store[cg.fullname] = []
            store[cg.fullname].append(cg)

        # Collect cgroups by group name (path)
        cgroups = {}
        for name in self.SUBSYSTEMS:
            try:
                root_cgroup = cgroup.scan_cgroups(name, self.FILTERS[name])
                cgroup.walk_cgroups(root_cgroup, collect_by_name, cgroups)
            except EnvironmentError, e:
                # Don't annoy users by showing error messages
                pass
示例#8
0
    def run(self):
        root_cgroup = cgroup.scan_cgroups(self.args.target_subsystem)

        def collect_configs(_cgroup, store):
            if self.args.debug:
                print(_cgroup)
            if self.args.hide_empty and _cgroup.n_procs == 0:
                pass
            else:
                store[_cgroup.path] = _cgroup.get_stats()

        cgroups = {}
        cgroup.walk_cgroups(root_cgroup, collect_configs, cgroups)

        if self.args.json:
            import json
            json.dump(cgroups, sys.stdout, indent=4)
        else:
            for cgname, stats in cgroups.items():
                self._print_stats(cgname, stats)
示例#9
0
    def run(self, args):
        root_cgroup = cgroup.scan_cgroups(self.options.target_subsystem)

        def collect_configs(_cgroup, store):
            if self.options.debug:
                print(_cgroup)
            if self.options.hide_empty and _cgroup.n_procs == 0:
                pass
            else:
                store[_cgroup.path] = _cgroup.get_stats()

        cgroups = {}
        cgroup.walk_cgroups(root_cgroup, collect_configs, cgroups)

        if self.options.json:
            import json
            json.dump(cgroups, sys.stdout, indent=4)
        else:
            for cgname, stats in cgroups.iteritems():
                self._print_stats(cgname, stats)
示例#10
0
    def run(self, args):
        if len(args) < 1:
            self.parser.error('Less argument')

        if len(args) > 1:
            self.parser.error('Too many arguments: ' + ' '.join(args))

        procname = args[0]
        root_cgroup = cgroup.scan_cgroups(self.options.target_subsystem)

        def print_matched(cg, dummy):
            mypid = os.getpid()
            cg.update()
            for pid in cg.pids:
                if pid == mypid:
                    continue
                proc = process.Process(pid)

                if self.options.cmdline:
                    comp = proc.cmdline
                else:
                    comp = proc.name

                if self.options.ignore_case:
                    comp = comp.lower()
                    _procname = procname.lower()
                else:
                    _procname = procname

                if _procname in comp:
                    if self.options.show_name:
                        if self.options.cmdline:
                            output = "%d %s" % (proc.pid, proc.cmdline)
                        else:
                            output = "%d %s" % (proc.pid, proc.name)
                    else:
                        output = str(proc.pid)
                    print('%s: %s' % (cg.path, output))

        cgroup.walk_cgroups(root_cgroup, print_matched, None)
示例#11
0
    def run(self, args):
        if len(args) < 1:
            self.parser.error('Less argument')

        if len(args) > 1:
            self.parser.error('Too many arguments: ' + ' '.join(args))

        procname = args[0]
        root_cgroup = cgroup.scan_cgroups(self.options.target_subsystem)

        def print_matched(cg, dummy):
            mypid = os.getpid()
            cg.update()
            for pid in cg.pids:
                if pid == mypid:
                    continue
                proc = process.Process(pid)

                if self.options.cmdline:
                    comp = proc.cmdline
                else:
                    comp = proc.name

                if self.options.ignore_case:
                    comp = comp.lower()
                    _procname = procname.lower()
                else:
                    _procname = procname

                if _procname in comp:
                    if self.options.show_name:
                        if self.options.cmdline:
                            output = "%d %s" % (proc.pid, proc.cmdline)
                        else:
                            output = "%d %s" % (proc.pid, proc.name)
                    else:
                        output = str(proc.pid)
                    print('%s: %s' % (cg.path, output))

        cgroup.walk_cgroups(root_cgroup, print_matched, None)