How to use the psutil.boot_time function in psutil

To help you get started, we’ve selected a few psutil examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github giampaolo / psutil / tests / test_memory_leaks.py View on Github external
    @skip_if_linux()
    def test_boot_time(self):
        self.execute(psutil.boot_time)
github DingGuodong / LinuxBashShellScriptForOps / projects / performances / Linux / getLoadAverage.py View on Github external
import sys
import time

try:
    import psutil
except ImportError:
    try:
        command_to_execute = "pip install psutil"
        os.system(command_to_execute)
    except OSError:
        print "failed install psutil"
        sys.exit(1)
    import psutil


boot_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(psutil.boot_time()))
print "system start at: %s" % boot_time
print "now: %s" % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))

uptime_total_seconds = time.time() - psutil.boot_time()
uptime_days = int(uptime_total_seconds / 24 / 60 / 60)
uptime_hours = int(uptime_total_seconds / 60 / 60 % 24)
uptime_minutes = int(uptime_total_seconds / 60 % 60)
uptime_seconds = int(uptime_total_seconds % 60)
print "uptime: %d days %d hours %d minutes %d seconds" % (uptime_days, uptime_hours, uptime_minutes, uptime_seconds)

user_number = len(psutil.users())
print "%d user:" % user_number
print "\t\\"
for user_tuple in psutil.users():
    user_name = user_tuple[0]
    user_terminal = user_tuple[1]
github NIXStats / nixstatsagent / nixstatsagent / plugins / system.py View on Github external
systeminfo['os'] = "Mac OS %s" % platform.mac_ver()[0]
            cpu['brand'] = str(systemCommand('sysctl machdep.cpu.brand_string', False)[0]).split(': ')[1]
            #cpu['count'] = systemCommand('sysctl hw.ncpu')
        elif sys.platform == "freebsd10" or sys.platform == "freebsd11":
            systeminfo['os'] = "FreeBSD %s" % platform.release()
            cpu['brand'] = str(systemCommand('sysctl hw.model', False)[0]).split(': ')[1]
            cpu['count'] = systemCommand('sysctl hw.ncpu')
        elif sys.platform == "win32":
            systeminfo['os'] = "{} {}".format(platform.uname()[0], platform.uname()[2])
        systeminfo['cpu'] = cpu['brand']
        systeminfo['cores'] = cpu['count']
        systeminfo['memory'] = mem.total
        systeminfo['psutil'] = '.'.join(map(str, psutil.version_info))
        systeminfo['python_version'] = sys.version
        systeminfo['platform'] = platform.platform()
        systeminfo['uptime'] = int(time.time()-psutil.boot_time())
        systeminfo['ip_addresses'] = ip_addresses()
        return systeminfo
github arkOScloud / core / arkos / system / stats.py View on Github external
def get_uptime():
    """Get system uptime."""
    n = datetime.datetime.now() - datetime.datetime.fromtimestamp(psutil.boot_time())
    m, s = divmod(n.seconds, 60)
    h, m = divmod(m, 60)
    d, h = divmod(h, 24)

    return [s, m, h, n.days]
github powerline / powerline / powerline / segments / common / sys.py View on Github external
def _get_uptime():
			return int(time() - psutil.boot_time())
	else:
github keras-team / keras-tuner / kerastuner / system.py View on Github external
def _get_uptime(self):
        return int(time() - psutil.boot_time())
github microsoft / ELL / tools / utilities / pythonlibs / procmon.py View on Github external
def start(self):
        """While the process is running, monitor its vitals (e.g. resource usage)
           and log the results
        """
        stats = []
        try:
            firstcall = True
            while True:
                stat = self.process.as_dict(attrs=[
                    'cpu_times', 'cpu_percent', 'num_threads', 'memory_info'])
                stat['timestamp'] = psutil.boot_time()
                stat['system_cpu_percent'] = psutil.cpu_percent(interval=None, percpu=True)
                stat['system_cpu_freq'] = psutil.cpu_freq(percpu=True)

                if firstcall:
                    # first call is throwaway (see documentation for cpu_percent on why)
                    firstcall = False
                else:
                    stats.append(stat)

                sleep(self.interval)

        except psutil.NoSuchProcess:
            print("Process has exited")
        finally:
            summary = self.summarize(stats)
github pbs / django-heartbeat / src / heartbeat / checkers / host.py View on Github external
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
            }
github Morgan-Stanley / treadmill / lib / python / treadmill / sysinfo.py View on Github external
def up_since():
    """Returns time of last reboot."""
    return psutil.boot_time()