Python os.getloadavg() Examples
The following are 30
code examples of os.getloadavg().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.
Example #1
Source File: main.py From android_universal with MIT License | 6 votes |
def display_progress(self, test_index, test): if self.ns.quiet: return # "[ 51/405/1] test_tcl passed" line = f"{test_index:{self.test_count_width}}{self.test_count}" fails = len(self.bad) + len(self.environment_changed) if fails and not self.ns.pgo: line = f"{line}/{fails}" line = f"[{line}] {test}" # add the system load prefix: "load avg: 1.80 " if hasattr(os, 'getloadavg'): load_avg_1min = os.getloadavg()[0] line = f"load avg: {load_avg_1min:.2f} {line}" # add the timestamp prefix: "0:01:05 " test_time = time.monotonic() - self.start_time test_time = datetime.timedelta(seconds=int(test_time)) line = f"{test_time} {line}" print(line, flush=True)
Example #2
Source File: work_load.py From FACT_core with GNU General Public License v3.0 | 6 votes |
def _get_system_information(self): memory_usage = psutil.virtual_memory() try: disk_usage = psutil.disk_usage(self.config['data_storage']['firmware_file_storage_directory']) except Exception: disk_usage = psutil.disk_usage('/') try: cpu_percentage = psutil.cpu_percent() except Exception: cpu_percentage = 'unknown' result = { 'cpu_cores': psutil.cpu_count(logical=False), 'virtual_cpu_cores': psutil.cpu_count(), 'cpu_percentage': cpu_percentage, 'load_average': ', '.join(str(x) for x in os.getloadavg()), 'memory_total': memory_usage.total, 'memory_used': memory_usage.used, 'memory_percent': memory_usage.percent, 'disk_total': disk_usage.total, 'disk_used': disk_usage.used, 'disk_percent': disk_usage.percent } return result
Example #3
Source File: core.py From auto-cpufreq with GNU Lesser General Public License v3.0 | 6 votes |
def mon_performance(): # get system/CPU load load1m, _, _ = os.getloadavg() # get CPU utilization as a percentage cpuload = p.cpu_percent(interval=1) print("\nTotal CPU usage:", cpuload, "%") print("Total system load:", load1m, "\n") if cur_turbo == "0": print("Currently turbo boost is: on") print("Suggesting to set turbo boost: on") else: print("Currently turbo boost is: off") print("Suggesting to set turbo boost: on") footer(79) # set cpufreq based if device is charging
Example #4
Source File: collector_loadaverage.py From opsbro with MIT License | 6 votes |
def launch(self): self.logger.debug('getLoadAvrgs: start') # Get the triplet from the python function try: loadAvrgs_1, loadAvrgs_5, loadAvrgs_15 = os.getloadavg() except (AttributeError, OSError): self.set_not_eligible('Load average is only availabe on unix systems') return False self.logger.debug('getLoadAvrgs: parsing') loadavrgs = {'load1': loadAvrgs_1, 'load5': loadAvrgs_5, 'load15': loadAvrgs_15} self.logger.debug('getLoadAvrgs: completed, returning') return loadavrgs
Example #5
Source File: util.py From sporco with BSD 3-Clause "New" or "Revised" License | 6 votes |
def idle_cpu_count(mincpu=1): """Estimate number of idle CPUs. Estimate number of idle CPUs, for use by multiprocessing code needing to determine how many processes can be run without excessive load. This function uses :func:`os.getloadavg` which is only available under a Unix OS. Parameters ---------- mincpu : int Minimum number of CPUs to report, independent of actual estimate Returns ------- idle : int Estimate of number of idle CPUs """ if PY2: ncpu = mp.cpu_count() else: ncpu = os.cpu_count() idle = int(ncpu - np.floor(os.getloadavg()[0])) return max(mincpu, idle)
Example #6
Source File: util.py From alphacsc with BSD 3-Clause "New" or "Revised" License | 6 votes |
def idle_cpu_count(mincpu=1): """Estimate number of idle CPUs, for use by multiprocessing code needing to determine how many processes can be run without excessive load. This function uses :func:`os.getloadavg` which is only available under a Unix OS. Parameters ---------- mincpu : int Minimum number of CPUs to report, independent of actual estimate Returns ------- idle : int Estimate of number of idle CPUs """ if PY2: ncpu = mp.cpu_count() else: ncpu = os.cpu_count() idle = int(ncpu - np.floor(os.getloadavg()[0])) return max(mincpu, idle)
Example #7
Source File: load.py From landscape-client with GNU General Public License v2.0 | 6 votes |
def run(self): self._sysinfo.add_header("System load", str(os.getloadavg()[0])) return succeed(None)
Example #8
Source File: core.py From auto-cpufreq with GNU Lesser General Public License v3.0 | 5 votes |
def mon_powersave(): # get system/CPU load load1m, _, _ = os.getloadavg() # get CPU utilization as a percentage cpuload = p.cpu_percent(interval=1) print("\nTotal CPU usage:", cpuload, "%") print("Total system load:", load1m, "\n") if load1m > cpus / 7: print("High load, suggesting to set turbo boost: on") if cur_turbo == "0": print("Currently turbo boost is: on") else: print("Currently turbo boost is: off") footer(79) elif cpuload > 25: print("High CPU load, suggesting to set turbo boost: on") if cur_turbo == "0": print("Currently turbo boost is: on") else: print("Currently turbo boost is: off") footer(79) else: print("Load optimal, suggesting to set turbo boost: off") if cur_turbo == "0": print("Currently turbo boost is: on") else: print("Currently turbo boost is: off") footer(79) # set performance and enable turbo
Example #9
Source File: regrtest.py From ironpython2 with Apache License 2.0 | 5 votes |
def display_progress(test_index, test): # "[ 51/405/1] test_tcl" line = "{1:{0}}{2}".format(test_count_width, test_index, test_count) fails = len(bad) + len(environment_changed) if fails and not pgo: line = '{}/{}'.format(line, fails) line = '[{}]'.format(line) # add the system load prefix: "load avg: 1.80 " if hasattr(os, 'getloadavg'): load_avg_1min = os.getloadavg()[0] line = "load avg: {:.2f} {}".format(load_avg_1min, line) # add the timestamp prefix: "0:01:05 " test_time = time.time() - regrtest_start_time test_time = datetime.timedelta(seconds=int(test_time)) line = "%s %s" % (test_time, line) # add the test name line = "{} {}".format(line, test) print(line) sys.stdout.flush() # For a partial run, we do not need to clutter the output.
Example #10
Source File: core.py From auto-cpufreq with GNU Lesser General Public License v3.0 | 5 votes |
def set_performance(): print("Setting to use \"performance\" governor") s.run("cpufreqctl --governor --set=performance", shell=True) if (os.path.exists("/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference")): s.run("cpufreqctl --epp --set=balance_performance", shell=True) print("Setting to use: \"balance_performance\" EPP") # get system/CPU load load1m, _, _ = os.getloadavg() # get CPU utilization as a percentage cpuload = p.cpu_percent(interval=1) print("\nTotal CPU usage:", cpuload, "%") print("Total system load:", load1m, "\n") # conditions for setting turbo in performance if load1m >= cpus / 5: print("High load, setting turbo boost: on") s.run("echo 0 > " + turbo_loc, shell=True) footer(79) elif cpuload > 20: print("High CPU load, setting turbo boost: on") s.run("echo 0 > " + turbo_loc, shell=True) footer(79) else: print("Load optimal, setting turbo boost: off") s.run("echo 1 > " + turbo_loc, shell=True) footer(79) # make turbo suggestions in performance
Example #11
Source File: tools.py From sisyphus with Mozilla Public License 2.0 | 5 votes |
def get_system_informations(file=sys.stdout): print("Uname:", platform.uname(), file=file) print("Load:", os.getloadavg(), file=file)
Example #12
Source File: stats.py From core with GNU General Public License v3.0 | 5 votes |
def get_load(): """Get system load averages.""" return os.getloadavg()
Example #13
Source File: statistics.py From hazelcast-python-client with Apache License 2.0 | 5 votes |
def _collect_load_average(self, psutil_stats, probe_name): return os.getloadavg()[0]
Example #14
Source File: mininet_test_base.py From faucet with Apache License 2.0 | 5 votes |
def _wait_load(self, load_retries=120): for _ in range(load_retries): load = os.getloadavg()[0] time.sleep(random.randint(1, 7)) if load < self.max_test_load: return output('load average too high %f, waiting' % load) self.fail('load average %f consistently too high' % load)
Example #15
Source File: prt.py From Plex-Remote-Transcoder with MIT License | 5 votes |
def get_system_load_local(): """ Returns a list of float representing the percentage load of this machine. """ nproc = multiprocessing.cpu_count() load = os.getloadavg() return [l/nproc * 100 for l in load]
Example #16
Source File: node.py From psdash with Creative Commons Zero v1.0 Universal | 5 votes |
def get_sysinfo(self): uptime = int(time.time() - psutil.boot_time()) sysinfo = { 'uptime': uptime, 'hostname': socket.gethostname(), 'os': platform.platform(), 'load_avg': os.getloadavg(), 'num_cpus': psutil.cpu_count() } return sysinfo
Example #17
Source File: metrics.py From temboard-agent with PostgreSQL License | 5 votes |
def get_load_average(self,): return os.getloadavg()[0]
Example #18
Source File: systemHelper.py From pep.py with GNU Affero General Public License v3.0 | 5 votes |
def getSystemInfo(): """ Get a dictionary with some system/server info :return: ["unix", "connectedUsers", "webServer", "cpuUsage", "totalMemory", "usedMemory", "loadAverage"] """ data = {"unix": runningUnderUnix(), "connectedUsers": len(glob.tokens.tokens), "matches": len(glob.matches.matches)} # General stats delta = time.time()-glob.startTime days = math.floor(delta/86400) delta -= days*86400 hours = math.floor(delta/3600) delta -= hours*3600 minutes = math.floor(delta/60) delta -= minutes*60 seconds = math.floor(delta) data["uptime"] = "{}d {}h {}m {}s".format(days, hours, minutes, seconds) data["cpuUsage"] = psutil.cpu_percent() memory = psutil.virtual_memory() data["totalMemory"] = "{0:.2f}".format(memory.total/1074000000) data["usedMemory"] = "{0:.2f}".format(memory.active/1074000000) # Unix only stats if data["unix"]: data["loadAverage"] = os.getloadavg() else: data["loadAverage"] = (0,0,0) return data
Example #19
Source File: index.py From listenbrainz-server with GNU General Public License v2.0 | 5 votes |
def current_status(): load = "%.2f %.2f %.2f" % os.getloadavg() try: with rabbitmq_connection._rabbitmq.get() as connection: queue = connection.channel.queue_declare(current_app.config['INCOMING_QUEUE'], passive=True, durable=True) incoming_len_msg = format(int(queue.method.message_count), ',d') queue = connection.channel.queue_declare(current_app.config['UNIQUE_QUEUE'], passive=True, durable=True) unique_len_msg = format(int(queue.method.message_count), ',d') except (pika.exceptions.ConnectionClosed, pika.exceptions.ChannelClosed): current_app.logger.error('Unable to get the length of queues', exc_info=True) incoming_len_msg = 'Unknown' unique_len_msg = 'Unknown' listen_count = _influx.get_total_listen_count() try: user_count = format(int(_get_user_count()), ',d') except DatabaseException as e: user_count = 'Unknown' return render_template( "index/current-status.html", load=load, listen_count=format(int(listen_count), ",d"), incoming_len=incoming_len_msg, unique_len=unique_len_msg, user_count=user_count, )
Example #20
Source File: panel.py From coursys with GNU General Public License v3.0 | 5 votes |
def ps_info(): import psutil, time CMD_DISP_MAX = 80 data = [] data.append(('System Load', os.getloadavg())) cpu_total = 0 psdata = ['<table id="procs"><thead><tr><th>PID</th><th>Owner</th><th>CPU %</th><th>VM Use (MB)</th><th>Status</th><th>Command</th></tr></thead><tbody>'] for proc in psutil.process_iter(): # start the clock on CPU usage percents try: proc.cpu_percent() except psutil.NoSuchProcess: pass time.sleep(2) for proc in psutil.process_iter(): try: perc = proc.cpu_percent() if perc > 0: cpu_total += perc mem = proc.memory_info().vms / 1024.0 / 1024.0 cmd = ' '.join(proc.cmdline()) if len(cmd) > CMD_DISP_MAX: cmd = '<span title="%s">%s</span>' % (escape(cmd), escape(cmd[:(CMD_DISP_MAX-5)]) + '…') else: cmd = escape(cmd) psdata.append('<tr><td>%s</td><td>%s</td><td>%s</td><td>%.1f</td><td>%s</td><td>%s</td></tr>' \ % (proc.pid, proc.username(), perc, mem, escape(str(proc.status())), cmd)) except psutil.NoSuchProcess: pass psdata.append('</tbody></table>') data.append(('CPU Percent', cpu_total)) data.append(('Running Processes', mark_safe(''.join(psdata)))) return data
Example #21
Source File: load_container_crawler.py From agentless-system-crawler with Apache License 2.0 | 5 votes |
def crawl_load(self): load = os.getloadavg() feature_key = 'load' feature_attributes = LoadFeature(load[0], load[1], load[1]) yield (feature_key, feature_attributes, 'load')
Example #22
Source File: load_host_crawler.py From agentless-system-crawler with Apache License 2.0 | 5 votes |
def crawl_load(self): load = os.getloadavg() feature_key = 'load' feature_attributes = LoadFeature(load[0], load[1], load[1]) yield (feature_key, feature_attributes, 'load')
Example #23
Source File: sysinfo.py From judge-server with GNU Affero General Public License v3.0 | 5 votes |
def load_fair(): try: load = os.getloadavg()[0] / _cpu_count except OSError: # as of May 2016, Windows' Linux subsystem throws OSError on getloadavg load = -1 return 'load', load
Example #24
Source File: script.py From heartbeats with MIT License | 5 votes |
def get_loadavg(): loadavgs = os.getloadavg() return { 'avg1': float(loadavgs[0]), 'avg5': float(loadavgs[1]), 'avg15': float(loadavgs[2]), }
Example #25
Source File: script_ex.py From heartbeats with MIT License | 5 votes |
def get_loadavg(): loadavgs = os.getloadavg() return { 'avg1': float(loadavgs[0]), 'avg5': float(loadavgs[1]), 'avg15': float(loadavgs[2]), }
Example #26
Source File: run_fuzzer.py From prjxray with ISC License | 5 votes |
def get_load(): """Return current load average. Values is average perecntage of CPU used over 1 minute, 5 minutes, 15 minutes. """ a1, a5, a15 = os.getloadavg() cpus = os.cpu_count() return a1 / cpus * 100.0, a5 / cpus * 100.0, a15 / cpus * 100.0
Example #27
Source File: run_fuzzer.py From prjxray with ISC License | 5 votes |
def get_load(): """Return current load average. Values is average perecntage of CPU used over 1 minute, 5 minutes, 15 minutes. """ a1, a5, a15 = os.getloadavg() cpus = os.cpu_count() return a1 / cpus * 100.0, a5 / cpus * 100.0, a15 / cpus * 100.0
Example #28
Source File: job_server.py From catkin_tools with Apache License 2.0 | 5 votes |
def _check_load(cls): if cls._max_load is not None: try: load = os.getloadavg() if load[1] < cls._max_load: cls._load_ok = True else: cls._load_ok = False except NotImplementedError: cls._load_ok = True return cls._load_ok
Example #29
Source File: services.py From CTF_AWD_Platform with MIT License | 5 votes |
def get_load(): """ Get load average """ try: data = os.getloadavg()[0] except Exception as err: data = str(err) return data
Example #30
Source File: recipe-577933.py From code with MIT License | 5 votes |
def display_loadavg(scr): lavg = os.getloadavg() write(scr, 1, 0, 'System', curses.color_pair(9)) write(scr, 1, 7, 'Load:', curses.color_pair(9)) write(scr, 1, 13, '%.02f' % lavg[0], curses.color_pair(9)) write(scr, 1, 20, '%.02f' % lavg[1], curses.color_pair(9)) write(scr, 1, 27, '%.02f' % lavg[2], curses.color_pair(9))