• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python subprocess_output.get_subprocess_output函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utils.subprocess_output.get_subprocess_output函数的典型用法代码示例。如果您正苦于以下问题:Python get_subprocess_output函数的具体用法?Python get_subprocess_output怎么用?Python get_subprocess_output使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_subprocess_output函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _check_solaris

    def _check_solaris(self, instance):
        # Can't get bytes sent and received via netstat
        # Default to kstat -p link:0:
        try:
            netstat, _, _ = get_subprocess_output(["kstat", "-p", "link:0:"], self.log)
            metrics_by_interface = self._parse_solaris_netstat(netstat)
            for interface, metrics in metrics_by_interface.iteritems():
                self._submit_devicemetrics(interface, metrics)
        except SubprocessOutputEmptyError:
            self.log.exception("Error collecting kstat stats.")

        try:
            netstat, _, _ = get_subprocess_output(["netstat", "-s", "-P" "tcp"], self.log)
            # TCP: tcpRtoAlgorithm=     4 tcpRtoMin           =   200
            # tcpRtoMax           = 60000 tcpMaxConn          =    -1
            # tcpActiveOpens      =    57 tcpPassiveOpens     =    50
            # tcpAttemptFails     =     1 tcpEstabResets      =     0
            # tcpCurrEstab        =     0 tcpOutSegs          =   254
            # tcpOutDataSegs      =   995 tcpOutDataBytes     =1216733
            # tcpRetransSegs      =     0 tcpRetransBytes     =     0
            # tcpOutAck           =   185 tcpOutAckDelayed    =     4
            # ...
            self._submit_regexed_values(netstat, SOLARIS_TCP_METRICS)
        except SubprocessOutputEmptyError:
            self.log.exception("Error collecting TCP stats.")
开发者ID:ross,项目名称:dd-agent,代码行数:25,代码来源:network.py


示例2: get_system_stats

def get_system_stats():
    systemStats = {
        'machine': platform.machine(),
        'platform': sys.platform,
        'processor': platform.processor(),
        'pythonV': platform.python_version(),
    }

    platf = sys.platform

    try:
        if Platform.is_linux(platf):
            output, _, _ = get_subprocess_output(['grep', 'model name', '/proc/cpuinfo'], log)
            systemStats['cpuCores'] = len(output.splitlines())

        if Platform.is_darwin(platf) or Platform.is_freebsd(platf):
            output, _, _ = get_subprocess_output(['sysctl', 'hw.ncpu'], log)
            systemStats['cpuCores'] = int(output.split(': ')[1])
    except SubprocessOutputEmptyError as e:
        log.warning("unable to retrieve number of cpuCores. Failed with error %s", e)

    if Platform.is_linux(platf):
        systemStats['nixV'] = platform.dist()

    elif Platform.is_darwin(platf):
        systemStats['macV'] = platform.mac_ver()

    elif Platform.is_freebsd(platf):
        version = platform.uname()[2]
        systemStats['fbsdV'] = ('freebsd', version, '')  # no codename for FreeBSD

    elif Platform.is_win32(platf):
        systemStats['winV'] = platform.win32_ver()

    return systemStats
开发者ID:bsandvik,项目名称:dd-agent,代码行数:35,代码来源:config.py


示例3: _collect_raw

    def _collect_raw(self, ceph_cmd, instance):
        use_sudo = _is_affirmative(instance.get('use_sudo', False))
        ceph_args = []
        if use_sudo:
            test_sudo = os.system('setsid sudo -l < /dev/null')
            if test_sudo != 0:
                raise Exception('The dd-agent user does not have sudo access')
            ceph_args = ['sudo', ceph_cmd]
        else:
            ceph_args = [ceph_cmd]

        args = ceph_args + ['version']
        try:
            output,_,_ = get_subprocess_output(args, self.log)
        except Exception as e:
            raise Exception('Unable to run cmd=%s: %s' % (' '.join(args), str(e)))

        raw = {}
        for cmd in ('mon_status', 'status', 'df detail', 'osd pool stats', 'osd perf', 'health detail'):
            try:
                args = ceph_args + cmd.split() + ['-fjson']
                output,_,_ = get_subprocess_output(args, self.log)
                res = json.loads(output)
            except Exception as e:
                self.log.warning('Unable to parse data from cmd=%s: %s' % (cmd, str(e)))
                continue

            name = cmd.replace(' ', '_')
            raw[name] = res

        return raw
开发者ID:Everlane,项目名称:dd-agent,代码行数:31,代码来源:ceph.py


示例4: check

    def check(self, instance):
        # Not configured? Not a problem.
        if instance.get("varnishstat", None) is None:
            raise Exception("varnishstat is not configured")
        tags = instance.get('tags', [])
        if tags is None:
            tags = []
        else:
            tags = list(set(tags))
        varnishstat_path = instance.get("varnishstat")
        name = instance.get('name')

        # Get version and version-specific args from varnishstat -V.
        version, use_xml = self._get_version_info(varnishstat_path)

        # Parse metrics from varnishstat.
        arg = '-x' if use_xml else '-1'
        cmd = [varnishstat_path, arg]

        if name is not None:
            cmd.extend(['-n', name])
            tags += [u'varnish_name:%s' % name]
        else:
            tags += [u'varnish_name:default']

        output, _, _ = get_subprocess_output(cmd, self.log)

        self._parse_varnishstat(output, use_xml, tags)

        # Parse service checks from varnishadm.
        varnishadm_path = instance.get('varnishadm')
        if varnishadm_path:
            secretfile_path = instance.get('secretfile', '/etc/varnish/secret')

            cmd = []
            if geteuid() != 0:
                cmd.append('sudo')

            if version < LooseVersion('4.1.0'):
                cmd.extend([varnishadm_path, '-S', secretfile_path, 'debug.health'])
            else:
                cmd.extend([varnishadm_path, '-S', secretfile_path, 'backend.list', '-p'])

            try:
                output, err, _ = get_subprocess_output(cmd, self.log)
            except OSError as e:
                self.log.error("There was an error running varnishadm. Make sure 'sudo' is available. %s", e)
                output = None
            if err:
                self.log.error('Error getting service check from varnishadm: %s', err)

            if output:
                self._parse_varnishadm(output)
开发者ID:dblackdblack,项目名称:integrations-core,代码行数:53,代码来源:check.py


示例5: _get_version_info

    def _get_version_info(self, varnishstat_path):
        # Get the varnish version from varnishstat
        output, error, _ = get_subprocess_output([varnishstat_path, "-V"], self.log,
            raise_on_empty_output=False)

        # Assumptions regarding varnish's version
        use_xml = True
        version = 3

        m1 = re.search(r"varnish-(\d+)", output, re.MULTILINE)
        # v2 prints the version on stderr, v3 on stdout
        m2 = re.search(r"varnish-(\d+)", error, re.MULTILINE)

        if m1 is None and m2 is None:
            self.log.warn("Cannot determine the version of varnishstat, assuming 3 or greater")
            self.warning("Cannot determine the version of varnishstat, assuming 3 or greater")
        else:
            if m1 is not None:
                version = int(m1.group(1))
            elif m2 is not None:
                version = int(m2.group(1))

        self.log.debug("Varnish version: %d" % version)

        # Location of varnishstat
        if version <= 2:
            use_xml = False

        return version, use_xml
开发者ID:Everlane,项目名称:dd-agent,代码行数:29,代码来源:varnish.py


示例6: check

    def check(self, agentConfig):
        process_exclude_args = agentConfig.get('exclude_process_args', False)
        if process_exclude_args:
            ps_arg = 'aux'
        else:
            ps_arg = 'auxww'
        # Get output from ps
        try:
            output, _, _ = get_subprocess_output(['ps', ps_arg], self.logger)
            processLines = output.splitlines()  # Also removes a trailing empty line

            del processLines[0]  # Removes the headers
        except Exception:
            self.logger.exception('getProcesses')
            return False

        processes = []

        for line in processLines:
            line = line.split(None, 10)
            processes.append(map(lambda s: s.strip(), line))

        return {'processes':   processes,
                'apiKey':      agentConfig['api_key'],
                'host':        get_hostname(agentConfig)}
开发者ID:motusllc,项目名称:dd-agent,代码行数:25,代码来源:unix.py


示例7: check

    def check(self, instance):
        tags = instance.get('tags', [])

        state_counts = defaultdict(int)

        prio_counts = defaultdict(int)

        proc_location = self.agentConfig.get('procfs_path', '/proc').rstrip('/')

        proc_path_map = {
            "inode_info": "sys/fs/inode-nr",
            "stat_info": "stat",
            "entropy_info": "sys/kernel/random/entropy_avail",
        }

        for key, path in proc_path_map.iteritems():
            proc_path_map[key] = "{procfs}/{path}".format(procfs=proc_location, path=path)

        with open(proc_path_map['inode_info'], 'r') as inode_info:
            inode_stats = inode_info.readline().split()
            self.gauge('system.inodes.total', float(inode_stats[0]), tags=tags)
            self.gauge('system.inodes.used', float(inode_stats[1]), tags=tags)

        with open(proc_path_map['stat_info'], 'r') as stat_info:
            lines = [line.strip() for line in stat_info.readlines()]

            for line in lines:
                if line.startswith('ctxt'):
                    ctxt_count = float(line.split(' ')[1])
                    self.monotonic_count('system.linux.context_switches', ctxt_count, tags=tags)
                elif line.startswith('processes'):
                    process_count = int(line.split(' ')[1])
                    self.monotonic_count('system.linux.processes_created', process_count, tags=tags)
                elif line.startswith('intr'):
                    interrupts = int(line.split(' ')[1])
                    self.monotonic_count('system.linux.interrupts', interrupts, tags=tags)

        with open(proc_path_map['entropy_info'], 'r') as entropy_info:
            entropy = entropy_info.readline()
            self.gauge('system.entropy.available', float(entropy), tags=tags)

        ps = get_subprocess_output(['ps', '--no-header', '-eo', 'stat'], self.log)
        for state in ps[0]:
            # Each process state is a flag in a list of characters. See ps(1) for details.
            for flag in list(state):
                if state in PROCESS_STATES:
                    state_counts[PROCESS_STATES[state]] += 1
                elif state in PROCESS_PRIOS:
                    prio_counts[PROCESS_PRIOS[state]] += 1

        for state in state_counts:
            state_tags = list(tags)
            state_tags.append("state:" + state)
            self.gauge('system.processes.states', float(state_counts[state]), state_tags)

        for prio in prio_counts:
            prio_tags = list(tags)
            prio_tags.append("priority:" + prio)
            self.gauge('system.processes.priorities', float(prio_counts[prio]), prio_tags)
开发者ID:AltSchool,项目名称:dd-agent,代码行数:59,代码来源:linux_proc_extras.py


示例8: _get_hostname_unix

 def _get_hostname_unix():
     try:
         # try fqdn
         out, _, rtcode = get_subprocess_output(['/bin/hostname', '-f'], log)
         if rtcode == 0:
             return out.strip()
     except Exception:
         return None
开发者ID:jalaziz,项目名称:dd-agent,代码行数:8,代码来源:util.py


示例9: collect_metrics_manually

 def collect_metrics_manually(self):
     df_out, _, _ = get_subprocess_output(self.DF_COMMAND + ["-k"], self.log)
     self.log.debug(df_out)
     for device in self._list_devices(df_out):
         self.log.debug("Passed: {0}".format(device))
         tags = [device[1]] if self._tag_by_filesystem else []
         device_name = device[-1] if self._use_mount else device[0]
         for metric_name, value in self._collect_metrics_manually(device).iteritems():
             self.gauge(metric_name, value, tags=tags, device_name=device_name)
开发者ID:dadicool,项目名称:dd-agent,代码行数:9,代码来源:disk.py


示例10: _get_proc_list

 def _get_proc_list(self):
     # Get output from ps
     try:
         process_exclude_args = self.config.get('exclude_process_args', False)
         if process_exclude_args:
             ps_arg = 'aux'
         else:
             ps_arg = 'auxww'
         output, _, _ = get_subprocess_output(['ps', ps_arg], self.log)
         processLines = output.splitlines()  # Also removes a trailing empty line
     except Exception, e:
         self.log.exception('Cannot get process list')
         return False
开发者ID:remind101,项目名称:dd-agent,代码行数:13,代码来源:processes.py


示例11: check

    def check(self, instance):
        # Not configured? Not a problem.
        if instance.get("varnishstat", None) is None:
            raise Exception("varnishstat is not configured")
        tags = instance.get("tags", [])
        if tags is None:
            tags = []
        else:
            tags = list(set(tags))
        varnishstat_path = instance.get("varnishstat")
        name = instance.get("name")

        # Get version and version-specific args from varnishstat -V.
        version, use_xml = self._get_version_info(varnishstat_path)

        # Parse metrics from varnishstat.
        arg = "-x" if use_xml else "-1"
        cmd = [varnishstat_path, arg]

        if name is not None:
            cmd.extend(["-n", name])
            tags += [u"varnish_name:%s" % name]
        else:
            tags += [u"varnish_name:default"]

        output, _, _ = get_subprocess_output(cmd, self.log)

        self._parse_varnishstat(output, use_xml, tags)

        # Parse service checks from varnishadm.
        varnishadm_path = instance.get("varnishadm")
        if varnishadm_path:
            secretfile_path = instance.get("secretfile", "/etc/varnish/secret")
            cmd = ["sudo", varnishadm_path, "-S", secretfile_path, "debug.health"]
            output, _, _ = get_subprocess_output(cmd, self.log)
            if output:
                self._parse_varnishadm(output)
开发者ID:dadicool,项目名称:dd-agent,代码行数:37,代码来源:varnish.py


示例12: get_system_stats

def get_system_stats():
    systemStats = {
        'machine': platform.machine(),
        'platform': sys.platform,
        'processor': platform.processor(),
        'pythonV': platform.python_version(),
    }

    platf = sys.platform

    if Platform.is_linux(platf):
        output, _, _ = get_subprocess_output(['grep', 'model name', '/proc/cpuinfo'], log)
        systemStats['cpuCores'] = len(output.splitlines())

    if Platform.is_darwin(platf):
        output, _, _ = get_subprocess_output(['sysctl', 'hw.ncpu'], log)
        systemStats['cpuCores'] = int(output.split(': ')[1])

    if Platform.is_freebsd(platf):
        output, _, _ = get_subprocess_output(['sysctl', 'hw.ncpu'], log)
        systemStats['cpuCores'] = int(output.split(': ')[1])

    if Platform.is_linux(platf):
        systemStats['nixV'] = platform.dist()

    elif Platform.is_darwin(platf):
        systemStats['macV'] = platform.mac_ver()

    elif Platform.is_freebsd(platf):
        version = platform.uname()[2]
        systemStats['fbsdV'] = ('freebsd', version, '')  # no codename for FreeBSD

    elif Platform.is_win32(platf):
        systemStats['winV'] = platform.win32_ver()

    return systemStats
开发者ID:jszwedko,项目名称:dd-agent,代码行数:36,代码来源:config.py


示例13: _run_gohai

    def _run_gohai(self, options):
        output = None
        try:
            output, err, _ = get_subprocess_output(["gohai"] + options, log)
            if err:
                log.debug("GOHAI LOG | %s", err)
        except OSError as e:
            if e.errno == 2:  # file not found, expected when install from source
                log.info("gohai file not found")
            else:
                log.warning("Unexpected OSError when running gohai %s", e)
        except Exception as e:
            log.warning("gohai command failed with error %s", e)

        return output
开发者ID:ross,项目名称:dd-agent,代码行数:15,代码来源:collector.py


示例14: get_system_stats

def get_system_stats():
    systemStats = {
        "machine": platform.machine(),
        "platform": sys.platform,
        "processor": platform.processor(),
        "pythonV": platform.python_version(),
    }

    platf = sys.platform

    if Platform.is_linux(platf):
        output, _, _ = get_subprocess_output(["grep", "model name", "/proc/cpuinfo"], log)
        systemStats["cpuCores"] = len(output.splitlines())

    if Platform.is_darwin(platf):
        output, _, _ = get_subprocess_output(["sysctl", "hw.ncpu"], log)
        systemStats["cpuCores"] = int(output.split(": ")[1])

    if Platform.is_freebsd(platf):
        output, _, _ = get_subprocess_output(["sysctl", "hw.ncpu"], log)
        systemStats["cpuCores"] = int(output.split(": ")[1])

    if Platform.is_linux(platf):
        systemStats["nixV"] = platform.dist()

    elif Platform.is_darwin(platf):
        systemStats["macV"] = platform.mac_ver()

    elif Platform.is_freebsd(platf):
        version = platform.uname()[2]
        systemStats["fbsdV"] = ("freebsd", version, "")  # no codename for FreeBSD

    elif Platform.is_win32(platf):
        systemStats["winV"] = platform.win32_ver()

    return systemStats
开发者ID:dadicool,项目名称:dd-agent,代码行数:36,代码来源:config.py


示例15: _collect_raw

    def _collect_raw(self, ceph_cmd, instance):
        use_sudo = _is_affirmative(instance.get('use_sudo', False))
        ceph_args = []
        if use_sudo:
            test_sudo = os.system('setsid sudo -l < /dev/null')
            if test_sudo != 0:
                raise Exception('The dd-agent user does not have sudo access')
            ceph_args = ['sudo', ceph_cmd]
        else:
            ceph_args = [ceph_cmd]

        args = ceph_args + ['version']
        try:
            output,_,_ = get_subprocess_output(args, self.log)
        except Exception, e:
            raise Exception('Unable to run cmd=%s: %s' % (' '.join(args), str(e)))
开发者ID:7040210,项目名称:dd-agent,代码行数:16,代码来源:ceph.py


示例16: _run_gohai

    def _run_gohai(self, options):
        # Gohai is disabled on Mac for now
        if Platform.is_mac() or not self.agentConfig.get('enable_gohai'):
            return None
        output = None
        try:
            output, err, _ = get_subprocess_output(["gohai"] + options, log)
            if err:
                log.debug("GOHAI LOG | %s", err)
        except OSError as e:
            if e.errno == 2:  # file not found, expected when install from source
                log.info("gohai file not found")
            else:
                log.warning("Unexpected OSError when running gohai %s", e)
        except Exception as e:
            log.warning("gohai command failed with error %s", e)

        return output
开发者ID:DataDog,项目名称:dd-agent,代码行数:18,代码来源:collector.py


示例17: _run_gohai

    def _run_gohai(self, options):
        output = None
        try:
            if not Platform.is_windows():
                command = "gohai"
            else:
                command = "gohai\gohai.exe"
            output, err, _ = get_subprocess_output([command] + options, log)
            if err:
                log.warning("GOHAI LOG | {0}".format(err))
        except OSError as e:
            if e.errno == 2:  # file not found, expected when install from source
                log.info("gohai file not found")
            else:
                log.warning("Unexpected OSError when running gohai %s", e)
        except Exception as e:
            log.warning("gohai command failed with error %s", e)

        return output
开发者ID:p1r4te,项目名称:dd-agent,代码行数:19,代码来源:collector.py


示例18: _get_queue_count

    def _get_queue_count(self, directory, queues, tags):
        for queue in queues:
            queue_path = os.path.join(directory, queue)
            if not os.path.exists(queue_path):
                raise Exception('%s does not exist' % queue_path)

            count = 0
            if os.geteuid() == 0:
                # dd-agent is running as root (not recommended)
                count = sum(len(files) for root, dirs, files in os.walk(queue_path))
            else:
                # can dd-agent user run sudo?
                test_sudo = os.system('setsid sudo -l < /dev/null')
                if test_sudo == 0:
                    output, _, _ = get_subprocess_output(['sudo', 'find', queue_path, '-type', 'f'], self.log, False)
                    count = len(output.splitlines())
                else:
                    raise Exception('The dd-agent user does not have sudo access')

            # emit an individually tagged metric
            self.gauge('postfix.queue.size', count, tags=tags + ['queue:%s' % queue, 'instance:%s' % os.path.basename(directory)])
开发者ID:Everlane,项目名称:dd-agent,代码行数:21,代码来源:postfix.py


示例19: __init__

    def __init__(self, logger):
        Check.__init__(self, logger)
        macV = None
        if sys.platform == 'darwin':
            macV = platform.mac_ver()
            macV_minor_version = int(re.match(r'10\.(\d+)\.?.*', macV[0]).group(1))

        # Output from top is slightly modified on OS X 10.6 (case #28239) and greater
        if macV and (macV_minor_version >= 6):
            self.topIndex = 6
        else:
            self.topIndex = 5

        self.pagesize = 0
        if sys.platform == 'sunos5':
            try:
                pgsz, _, _ = get_subprocess_output(['pagesize'], self.logger)
                self.pagesize = int(pgsz.strip())
            except Exception:
                # No page size available
                pass
开发者ID:motusllc,项目名称:dd-agent,代码行数:21,代码来源:unix.py


示例20: check

    def check(self, agentConfig):
        if Platform.is_linux():
            proc_location = agentConfig.get('procfs_path', '/proc').rstrip('/')
            try:
                proc_loadavg = "{0}/loadavg".format(proc_location)
                with open(proc_loadavg, 'r') as load_avg:
                    uptime = load_avg.readline().strip()
            except Exception:
                self.log.exception('Cannot extract load')
                return False

        elif sys.platform in ('darwin', 'sunos5') or sys.platform.startswith("freebsd"):
            # Get output from uptime
            try:
                uptime, _, _ = get_subprocess_output(['uptime'], self.log)
            except Exception:
                self.log.exception('Cannot extract load')
                return False
        else:
            return False

        # Split out the 3 load average values
        load = [res.replace(',', '.') for res in re.findall(r'([0-9]+[\.,]\d+)', uptime)]
        # Normalize load by number of cores
        try:
            cores = int(agentConfig.get('system_stats').get('cpuCores'))
            assert cores >= 1, "Cannot determine number of cores"
            # Compute a normalized load, named .load.norm to make it easy to find next to .load
            return {'system.load.1': float(load[0]),
                    'system.load.5': float(load[1]),
                    'system.load.15': float(load[2]),
                    'system.load.norm.1': float(load[0])/cores,
                    'system.load.norm.5': float(load[1])/cores,
                    'system.load.norm.15': float(load[2])/cores,
                    }
        except Exception:
            # No normalized load available
            return {'system.load.1': float(load[0]),
                    'system.load.5': float(load[1]),
                    'system.load.15': float(load[2])}
开发者ID:htgeis,项目名称:mystore,代码行数:40,代码来源:unix.py



注:本文中的utils.subprocess_output.get_subprocess_output函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python td_helper.send_td_event函数代码示例发布时间:2022-05-26
下一篇:
Python story_functions.pre_process_story函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap