本文整理汇总了Python中psutil.boot_time方法的典型用法代码示例。如果您正苦于以下问题:Python psutil.boot_time方法的具体用法?Python psutil.boot_time怎么用?Python psutil.boot_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psutil
的用法示例。
在下文中一共展示了psutil.boot_time方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getSystemInfo
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import boot_time [as 别名]
def getSystemInfo(cls):
system = {
'boot_time': psutil.boot_time(),
'cpu_count': psutil.cpu_count(),
'cpu_stats': psutil.cpu_stats().__dict__,
'cpu_times': [k.__dict__ for k in psutil.cpu_times(percpu=True)],
'disk_io_counters': psutil.disk_io_counters().__dict__,
'disk_usage': [],
'net_io_counters': psutil.net_io_counters().__dict__,
'swap_memory': psutil.swap_memory().__dict__,
'virtual_memory': psutil.virtual_memory().__dict__
}
partitions = psutil.disk_partitions()
for p in partitions:
if p.mountpoint in cls.INCLUDED_PARTITIONS:
usage = psutil.disk_usage(p.mountpoint)
system['disk_usage'].append({
'mountpoint': p.mountpoint,
'total': usage.total,
'used': usage.used
})
return system
示例2: __init__
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import boot_time [as 别名]
def __init__(self):
self.datetime_format = '%H:%M:%S %d/%m/%Y'
self.__raw_boot_time = psutil.boot_time()
self.__boot_time = datetime.fromtimestamp(self.raw_boot_time)
self.__boot_time = self.__boot_time.strftime(self.datetime_format)
self.__hostname = platform.node()
self.__os = Computer.__get_os_name()
self.__architecture = platform.machine()
self.__python_version = '{} ver. {}'.format(
platform.python_implementation(), platform.python_version()
)
self.__processor = Cpu(monitoring_latency=1)
self.__nonvolatile_memory = NonvolatileMemory.instances_connected_devices(monitoring_latency=10)
self.__nonvolatile_memory_devices = set(
[dev_info.device for dev_info in self.__nonvolatile_memory]
)
self.__virtual_memory = VirtualMemory(monitoring_latency=1)
self.__swap_memory = SwapMemory(monitoring_latency=1)
self.__network_interface = NetworkInterface(monitoring_latency=3)
super().__init__(monitoring_latency=3)
示例3: run
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import boot_time [as 别名]
def run(self, flow_obj=None):
if not self.is_active():
return []
if not self._config.client.writeback.client_id:
self.enroll()
message = client.StartupMessage.from_keywords(
client_id=self._config.client.writeback.client_id,
boot_time=psutil.boot_time(),
agent_start_time=START_TIME,
timestamp=time.time(),
labels=self._config.client.labels,
system_info=UnameImpl.from_current_system(session=self._session),
)
self._session.logging.debug("Sending client startup message to server.")
self.location.write_file(message.to_json())
示例4: test_procfs_path
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import boot_time [as 别名]
def test_procfs_path(self):
tdir = tempfile.mkdtemp()
try:
psutil.PROCFS_PATH = tdir
self.assertRaises(IOError, psutil.virtual_memory)
self.assertRaises(IOError, psutil.cpu_times)
self.assertRaises(IOError, psutil.cpu_times, percpu=True)
self.assertRaises(IOError, psutil.boot_time)
# self.assertRaises(IOError, psutil.pids)
self.assertRaises(IOError, psutil.net_connections)
self.assertRaises(IOError, psutil.net_io_counters)
self.assertRaises(IOError, psutil.net_if_stats)
self.assertRaises(IOError, psutil.disk_io_counters)
self.assertRaises(IOError, psutil.disk_partitions)
self.assertRaises(psutil.NoSuchProcess, psutil.Process)
finally:
psutil.PROCFS_PATH = "/proc"
os.rmdir(tdir)
示例5: test_procfs_path
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import boot_time [as 别名]
def test_procfs_path(self):
tdir = self.get_testfn()
os.mkdir(tdir)
try:
psutil.PROCFS_PATH = tdir
self.assertRaises(IOError, psutil.virtual_memory)
self.assertRaises(IOError, psutil.cpu_times)
self.assertRaises(IOError, psutil.cpu_times, percpu=True)
self.assertRaises(IOError, psutil.boot_time)
# self.assertRaises(IOError, psutil.pids)
self.assertRaises(IOError, psutil.net_connections)
self.assertRaises(IOError, psutil.net_io_counters)
self.assertRaises(IOError, psutil.net_if_stats)
# self.assertRaises(IOError, psutil.disk_io_counters)
self.assertRaises(IOError, psutil.disk_partitions)
self.assertRaises(psutil.NoSuchProcess, psutil.Process)
finally:
psutil.PROCFS_PATH = "/proc"
示例6: tell_system_status
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import boot_time [as 别名]
def tell_system_status(self):
import psutil
import platform
import datetime
os, name, version, _, _, _ = platform.uname()
version = version.split('-')[0]
cores = psutil.cpu_count()
cpu_percent = psutil.cpu_percent()
memory_percent = psutil.virtual_memory()[2]
disk_percent = psutil.disk_usage('/')[3]
boot_time = datetime.datetime.fromtimestamp(psutil.boot_time())
running_since = boot_time.strftime("%A %d. %B %Y")
response = "I am currently running on %s version %s. " % (os, version)
response += "This system is named %s and has %s CPU cores. " % (name, cores)
response += "Current disk_percent is %s percent. " % disk_percent
response += "Current CPU utilization is %s percent. " % cpu_percent
response += "Current memory utilization is %s percent. " % memory_percent
response += "it's running since %s." % running_since
return response
示例7: get_all_stats
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import boot_time [as 别名]
def get_all_stats(self):
now = to_posix_time(datetime.datetime.utcnow())
network_stats = self.get_network_stats()
self.network_stats_hist.append((now, network_stats))
self.network_stats_hist = self.network_stats_hist[-7:]
then, prev_network_stats = self.network_stats_hist[0]
netstats = ((network_stats[0] - prev_network_stats[0]) / (now - then),
(network_stats[1] - prev_network_stats[1]) / (now - then))
return {
"now": now,
"hostname": self.hostname,
"ip": self.ip,
"cpu": self.get_cpu_percent(),
"cpus": self.cpu_counts,
"mem": self.get_mem_usage(),
"workers": self.get_workers(),
"boot_time": self.get_boot_time(),
"load_avg": self.get_load_avg(),
"disk": self.get_disk_usage(),
"gpus": self.get_gpu_usage(),
"net": netstats,
}
示例8: update
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import boot_time [as 别名]
def update(self):
"""Function to update the entire class information."""
self.cpu["percentage"] = psutil.cpu_percent(interval=0.7)
self.boot = datetime.datetime.fromtimestamp(psutil.boot_time()).strftime(
"%Y-%m-%d %H:%M:%S")
virtual_memory = psutil.virtual_memory()
self.memory["used"] = int(virtual_memory.used/1024)
self.memory["free"] = int(virtual_memory.free/1024)
self.memory["cached"] = int(virtual_memory.cached/1024)
net_io_counters = psutil.net_io_counters()
self.network["packet_sent"] = net_io_counters.packets_sent
self.network["packet_recv"] = net_io_counters.packets_recv
disk_usage = psutil.disk_usage('/')
self.disk["total"] = int(disk_usage.total/1024)
self.disk["used"] = int(disk_usage.used/1024)
self.disk["free"] = int(disk_usage.free/1024)
self.timestamp = time.time()
示例9: check
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import boot_time [as 别名]
def check(request):
return {
'hostname': socket.gethostname(),
'ips': ips,
'cpus': psutil.cpu_count(),
'uptime': timesince(datetime.fromtimestamp(psutil.boot_time())),
'memory': {
'total': filesizeformat(psutil.virtual_memory().total),
'available': filesizeformat(psutil.virtual_memory().available),
'used': filesizeformat(psutil.virtual_memory().used),
'free': filesizeformat(psutil.virtual_memory().free),
'percent': psutil.virtual_memory().percent
},
'swap': {
'total': filesizeformat(psutil.swap_memory().total),
'used': filesizeformat(psutil.swap_memory().used),
'free': filesizeformat(psutil.swap_memory().free),
'percent': psutil.swap_memory().percent
}
}
示例10: enable
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import boot_time [as 别名]
def enable(self):
self.data['cpu_count'] = psutil.cpu_count()
self.data['hostname'] = socket.gethostname()
self.data['boot_time'] = psutil.boot_time()
super(Plugin, self).enable()
示例11: update
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import boot_time [as 别名]
def update(self):
self.data['cpu_percent'] = psutil.cpu_percent()
self.data['cpu_percents'] = psutil.cpu_percent(percpu=True)
self.data['memory'] = self._virtual_memory()
self.data['swap'] = self._swap_memory()
self.data['uptime'] = int(time.time() - self.data['boot_time'])
super(Plugin, self).update()
示例12: boot_time
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import boot_time [as 别名]
def boot_time(self):
return self.__boot_time
示例13: get_uptime
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import boot_time [as 别名]
def get_uptime():
return psutil.boot_time()
示例14: collect_system_information
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import boot_time [as 别名]
def collect_system_information(self):
values = {}
mem = psutil.virtual_memory()
values['memory_total'] = mem.total
import cpuinfo
cpu = cpuinfo.get_cpu_info()
values['resources_limit'] = self.resources_limit
values['cpu_name'] = cpu['brand']
values['cpu'] = [cpu['hz_advertised_raw'][0], cpu['count']]
values['nets'] = {}
values['disks'] = {}
values['gpus'] = {}
values['boot_time'] = psutil.boot_time()
try:
for gpu_id, gpu in enumerate(aetros.cuda_gpu.get_ordered_devices()):
gpu['available'] = gpu_id in self.enabled_gpus
values['gpus'][gpu_id] = gpu
except aetros.cuda_gpu.CudaNotImplementedException: pass
for disk in psutil.disk_partitions():
try:
name = self.get_disk_name(disk[1])
values['disks'][name] = psutil.disk_usage(disk[1]).total
except Exception:
# suppress Operation not permitted
pass
try:
for id, net in psutil.net_if_stats().items():
if 0 != id.find('lo') and net.isup:
self.nets.append(id)
values['nets'][id] = net.speed or 1000
except Exception:
# suppress Operation not permitted
pass
return values
示例15: crawl_os
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import boot_time [as 别名]
def crawl_os():
feature_key = platform.system().lower()
try:
os_kernel = platform.platform()
except:
os_kernel = 'unknown'
result = osinfo.get_osinfo(mount_point='/')
os_distro = result['os'] if 'os' in result else 'unknown'
os_version = result['version'] if 'version' in result else 'unknown'
ips = utils.misc.get_host_ip4_addresses()
boot_time = psutil.boot_time()
uptime = int(time.time()) - boot_time
feature_attributes = OSFeature(
boot_time,
uptime,
ips,
os_distro,
os_version,
os_kernel,
platform.machine()
)
return [(feature_key, feature_attributes, 'os')]