本文整理汇总了Python中util.Platform.is_linux方法的典型用法代码示例。如果您正苦于以下问题:Python Platform.is_linux方法的具体用法?Python Platform.is_linux怎么用?Python Platform.is_linux使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util.Platform
的用法示例。
在下文中一共展示了Platform.is_linux方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_system_stats
# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_linux [as 别名]
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):
grep = subprocess.Popen(['grep', 'model name', '/proc/cpuinfo'], stdout=subprocess.PIPE, close_fds=True)
wc = subprocess.Popen(['wc', '-l'], stdin=grep.stdout, stdout=subprocess.PIPE, close_fds=True)
systemStats['cpuCores'] = int(wc.communicate()[0])
if Platform.is_darwin(platf):
systemStats['cpuCores'] = int(subprocess.Popen(['sysctl', 'hw.ncpu'], stdout=subprocess.PIPE, close_fds=True).communicate()[0].split(': ')[1])
if Platform.is_freebsd(platf):
systemStats['cpuCores'] = int(subprocess.Popen(['sysctl', 'hw.ncpu'], stdout=subprocess.PIPE, close_fds=True).communicate()[0].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
示例2: testNetwork
# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_linux [as 别名]
def testNetwork(self):
# FIXME: cx_state to true, but needs sysstat installed
config = """
init_config:
instances:
- collect_connection_state: false
excluded_interfaces:
- lo
- lo0
"""
check, instances = get_check("network", config)
check.check(instances[0])
check.get_metrics()
metric_names = [m[0] for m in check.aggregator.metrics]
assert "system.net.bytes_rcvd" in metric_names
assert "system.net.bytes_sent" in metric_names
if Platform.is_linux():
assert "system.net.tcp.retrans_segs" in metric_names
assert "system.net.tcp.in_segs" in metric_names
assert "system.net.tcp.out_segs" in metric_names
elif Platform.is_bsd():
assert "system.net.tcp.retrans_packs" in metric_names
assert "system.net.tcp.sent_packs" in metric_names
assert "system.net.tcp.rcv_packs" in metric_names
示例3: testMemory
# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_linux [as 别名]
def testMemory(self):
global logger
res = Memory(logger).check({})
if Platform.is_linux():
MEM_METRICS = [
"swapTotal",
"swapFree",
"swapPctFree",
"swapUsed",
"physTotal",
"physFree",
"physUsed",
"physBuffers",
"physCached",
"physUsable",
"physPctUsable",
"physShared",
]
for k in MEM_METRICS:
# % metric is only here if total > 0
if k == "swapPctFree" and res["swapTotal"] == 0:
continue
assert k in res, res
assert res["swapTotal"] == res["swapFree"] + res["swapUsed"]
assert res["physTotal"] == res["physFree"] + res["physUsed"]
elif sys.platform == "darwin":
for k in ("swapFree", "swapUsed", "physFree", "physUsed"):
assert k in res, res
示例4: check
# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_linux [as 别名]
def check(self, instance):
""" Collect metrics for the given gunicorn instance. """
self.log.debug("Running instance: %s", instance)
if Platform.is_linux():
procfs_path = self.agentConfig.get('procfs_path', '/proc').rstrip('/')
psutil.PROCFS_PATH = procfs_path
# Validate the config.
if not instance or self.PROC_NAME not in instance:
raise GUnicornCheckError("instance must specify: %s" % self.PROC_NAME)
# Load the gunicorn master procedure.
proc_name = instance.get(self.PROC_NAME)
master_proc = self._get_master_proc_by_name(proc_name)
# Fetch the worker procs and count their states.
worker_procs = master_proc.children()
working, idle = self._count_workers(worker_procs)
# if no workers are running, alert CRITICAL, otherwise OK
msg = "%s working and %s idle workers for %s" % (working, idle, proc_name)
status = AgentCheck.CRITICAL if working == 0 and idle == 0 else AgentCheck.OK
self.service_check(self.SVC_NAME, status, tags=['app:' + proc_name], message=msg)
# Submit the data.
self.log.debug("instance %s procs - working:%s idle:%s" % (proc_name, working, idle))
self.gauge("gunicorn.workers", working, self.WORKING_TAGS)
self.gauge("gunicorn.workers", idle, self.IDLE_TAGS)
示例5: get_system_stats
# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_linux [as 别名]
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):
grep = subprocess.Popen(["grep", "model name", "/proc/cpuinfo"], stdout=subprocess.PIPE, close_fds=True)
wc = subprocess.Popen(["wc", "-l"], stdin=grep.stdout, stdout=subprocess.PIPE, close_fds=True)
systemStats["cpuCores"] = int(wc.communicate()[0])
if Platform.is_darwin(platf):
systemStats["cpuCores"] = int(
subprocess.Popen(["sysctl", "hw.ncpu"], stdout=subprocess.PIPE, close_fds=True)
.communicate()[0]
.split(": ")[1]
)
if Platform.is_freebsd(platf):
systemStats["cpuCores"] = int(
subprocess.Popen(["sysctl", "hw.ncpu"], stdout=subprocess.PIPE, close_fds=True)
.communicate()[0]
.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
示例6: testMemory
# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_linux [as 别名]
def testMemory(self):
global logger
res = Memory(logger).check({})
if Platform.is_linux():
for k in ("swapTotal", "swapFree", "swapPctFree", "swapUsed", "physTotal", "physFree", "physUsed", "physBuffers", "physCached", "physUsable", "physPctUsable", "physShared"):
assert k in res, res
assert res["swapTotal"] == res["swapFree"] + res["swapUsed"]
assert res["physTotal"] == res["physFree"] + res["physUsed"]
elif sys.platform == 'darwin':
for k in ("swapFree", "swapUsed", "physFree", "physUsed"):
assert k in res, res
示例7: check
# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_linux [as 别名]
def check(self, instance):
"""Get disk space/inode stats"""
# Windows and Mac will always have psutil
# (we have packaged for both of them)
if self._psutil():
if Platform.is_linux():
procfs_path = self.agentConfig.get('procfs_path', '/proc').rstrip('/')
psutil.PROCFS_PATH = procfs_path
self.collect_metrics_psutil()
else:
# FIXME: implement all_partitions (df -a)
self.collect_metrics_manually()
示例8: check
# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_linux [as 别名]
def check(self, instance):
host, port, user, password, mysql_sock, defaults_file, tags, options = self._get_config(instance)
if (not host or not user) and not defaults_file:
raise Exception("Mysql host and user are needed.")
db = self._connect(host, port, mysql_sock, user, password, defaults_file)
# Metric collection
self._collect_metrics(host, db, tags, options)
if Platform.is_linux():
self._collect_system_metrics(host, db, tags)
示例9: testLoad
# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_linux [as 别名]
def testLoad(self):
global logger
load = Load(logger)
res = load.check({'system_stats': get_system_stats()})
assert 'system.load.1' in res
if Platform.is_linux():
cores = int(get_system_stats().get('cpuCores'))
assert 'system.load.norm.1' in res
assert abs(res['system.load.1'] - cores * res['system.load.norm.1']) <= 0.1, (res['system.load.1'], cores * res['system.load.norm.1'])
# same test but without cpu count, no normalized load sent.
res = load.check({})
assert 'system.load.1' in res
assert 'system.load.norm.1' not in res
示例10: testLoad
# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_linux [as 别名]
def testLoad(self):
global logger
load = Load(logger)
res = load.check({"system_stats": get_system_stats()})
assert "system.load.1" in res
if Platform.is_linux():
cores = int(get_system_stats().get("cpuCores"))
assert "system.load.norm.1" in res
assert abs(res["system.load.1"] - cores * res["system.load.norm.1"]) <= 0.1, (
res["system.load.1"],
cores * res["system.load.norm.1"],
)
# same test but without cpu count, no normalized load sent.
res = load.check({})
assert "system.load.1" in res
assert "system.load.norm.1" not in res
示例11: check
# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_linux [as 别名]
def check(self, instance):
if instance is None:
instance = {}
self._excluded_ifaces = instance.get('excluded_interfaces', [])
self._collect_cx_state = instance.get('collect_connection_state', False)
self._exclude_iface_re = None
exclude_re = instance.get('excluded_interface_re', None)
if exclude_re:
self.log.debug("Excluding network devices matching: %s" % exclude_re)
self._exclude_iface_re = re.compile(exclude_re)
if Platform.is_linux():
self._check_linux(instance)
elif Platform.is_bsd():
self._check_bsd(instance)
elif Platform.is_solaris():
self._check_solaris(instance)
示例12: check
# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_linux [as 别名]
def check(self, agentConfig):
if Platform.is_linux():
try:
loadAvrgProc = open('/proc/loadavg', 'r')
uptime = loadAvrgProc.readlines()
loadAvrgProc.close()
except Exception:
self.logger.exception('Cannot extract load')
return False
uptime = uptime[0] # readlines() provides a list but we want a string
elif sys.platform in ('darwin', 'sunos5') or sys.platform.startswith("freebsd"):
# Get output from uptime
try:
uptime = sp.Popen(['uptime'],
stdout=sp.PIPE,
close_fds=True).communicate()[0]
except Exception:
self.logger.exception('Cannot extract load')
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])}
示例13: check
# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_linux [as 别名]
def check(self, agentConfig):
if Platform.is_linux():
with open("/proc/uptime", "r") as f:
uptime_seconds = float(f.readline().split()[0])
return {"system.uptime": uptime_seconds}
return {}