当前位置: 首页>>代码示例>>PHP>>正文


PHP sys_getloadavg函数代码示例

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


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

示例1: content_header

    public static function content_header($icon, $title, $subtitle = '')
    {
        $serverload = implode(', ', sys_getloadavg());
        $pid = Service::ServiceData(SInfo::DATA_PID);
        if ($subtitle != '') {
            $title .= ' <span>&gt; ' . $subtitle . '</span>';
        }
        $buf = '<div class="row">
			<div class="col-xs-12 col-sm-7 col-md-7 col-lg-7">
				<h2 class="page-title txt-color-blueDark"><i class="fa-fw fa ' . $icon . '"></i> ' . $title . '</h2>
			</div>
			<div class="col-xs-12 col-sm-5 col-md-5 col-lg-5">
				<ul id="sparks" class="">
					<li class="sparks-info">
						<h5>LSWS PID <span id="lst-pid" class="txt-color-blue"> ' . $pid . ' </span></h5>&nbsp;
						<a class="btn btn-success" title="' . DMsg::UIStr('menu_restart') . '" href="javascript:lst_restart()"><i class="fa fa-lg fa-repeat"></i></a>
					</li>
					<li class="sparks-info">
						<h5> ' . DMsg::UIStr('note_loadavg') . ' <span id="lst-load" class="txt-color-purple"> ' . $serverload . ' </span></h5>&nbsp;
						<a class="btn btn-info" title="' . DMsg::UIStr('menu_rtstats') . '" href="#view/realtimestats.php"><i class="fa fa-lg fa-bar-chart-o"></i></a>
					</li>

				</ul>
			</div>
		</div>
				';
        return $buf;
    }
开发者ID:kopytov,项目名称:openlitespeed,代码行数:28,代码来源:UIBase.php

示例2: get

 /**
  * Returns a value from the cache.
  *
  * @param string $key
  *
  * @return mixed
  */
 public function get($key)
 {
     $filePath = $this->getFilePathFromKey($key);
     if (!file_exists($filePath)) {
         return false;
     }
     if (!is_readable($filePath)) {
         return false;
     }
     $cacheFileData = file_get_contents($filePath);
     if ($this->config['gzipCompression']) {
         $cacheFileData = gzuncompress($cacheFileData);
     }
     $cacheObj = json_decode($cacheFileData);
     $unixLoad = sys_getloadavg();
     if ($cacheObj->expiryTimestamp > time() || $unixLoad[0] >= $this->config['unixLoadUpperThreshold']) {
         // Cache item has not yet expired or system load is too high
         $content = $cacheObj->content;
         if ($unserializedContent = @unserialize($content)) {
             $content = $unserializedContent;
         }
         return $content;
     } else {
         // Cache item has expired
         return false;
     }
 }
开发者ID:rapidwebltd,项目名称:rw-file-cache,代码行数:34,代码来源:RWFileCache.php

示例3: frontendDashboard

 /**
  * @return Stage
  */
 public function frontendDashboard()
 {
     $Stage = new Stage('Dashboard', 'System');
     $Value = 100 / disk_total_space(__DIR__) * disk_free_space(__DIR__);
     Main::getDispatcher()->registerWidget('System', new Panel('Festplattenkapazität', array('<div class="progress" style="margin-bottom: 0;">
                       <div class="progress-bar progress-bar-success" style="width: ' . $Value . '%"></div>
                       <div class="progress-bar progress-bar-danger" style="width: ' . (100 - $Value) . '%"></div>
                     </div>', 'Gesamt: ' . number_format(disk_total_space(__DIR__), 0, ',', '.'), 'Frei: ' . number_format(disk_free_space(__DIR__), 0, ',', '.'))), 2, 2);
     $free = shell_exec('free');
     $free = (string) trim($free);
     $free_arr = explode("\n", $free);
     $mem = explode(" ", $free_arr[1]);
     $mem = array_filter($mem);
     $mem = array_merge($mem);
     $Value = $mem[2] / $mem[1] * 100;
     Main::getDispatcher()->registerWidget('System', new Panel('Speicherkapazität', array('<div class="progress" style="margin-bottom: 0;">
           <div class="progress-bar progress-bar-success" style="width: ' . $Value . '%"></div>
           <div class="progress-bar progress-bar-danger" style="width: ' . (100 - $Value) . '%"></div>
         </div>', 'Gesamt: ' . number_format($mem[1], 0, ',', '.'), 'Frei: ' . number_format($mem[2], 0, ',', '.'))), 2, 2);
     $load = sys_getloadavg();
     Main::getDispatcher()->registerWidget('System', new Panel('Rechenkapazität', array('<div class="progress" style="margin-bottom: 0;">
           <div class="progress-bar progress-bar-success" style="width: ' . 50 * (2 - $load[0]) . '%"></div>
           <div class="progress-bar progress-bar-danger" style="width: ' . 50 * $load[0] . '%"></div>
         </div>', 'Genutzt: ' . number_format($load[0], 5, ',', '.'), 'Frei: ' . number_format(2 - $load[0], 5, ',', '.'))), 2, 2);
     $Stage->setContent(Main::getDispatcher()->fetchDashboard('System'));
     return $Stage;
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:30,代码来源:System.php

示例4: get

 function get()
 {
     if (!get_config('system', 'hidden_version_siteinfo')) {
         $version = sprintf(t('Version %s'), \Zotlabs\Lib\System::get_project_version());
         if (@is_dir('.git') && function_exists('shell_exec')) {
             $commit = @shell_exec('git log -1 --format="%h"');
             $tag = \Zotlabs\Lib\System::get_std_version();
             // @shell_exec('git describe --tags --abbrev=0');
         }
         if (!isset($commit) || strlen($commit) > 16) {
             $commit = '';
         }
     } else {
         $version = $commit = '';
     }
     $plugins_list = implode(', ', visible_plugin_list());
     if ($plugins_list) {
         $plugins_text = t('Installed plugins/addons/apps:');
     } else {
         $plugins_text = t('No installed plugins/addons/apps');
     }
     $txt = get_config('system', 'admininfo');
     $admininfo = bbcode($txt);
     if (file_exists('doc/site_donate.html')) {
         $donate .= file_get_contents('doc/site_donate.html');
     }
     if (function_exists('sys_getloadavg')) {
         $loadavg = sys_getloadavg();
     }
     $o = replace_macros(get_markup_template('siteinfo.tpl'), array('$title' => t('$Projectname'), '$description' => t('This is a hub of $Projectname - a global cooperative network of decentralized privacy enhanced websites.'), '$version' => $version, '$tag_txt' => t('Tag: '), '$tag' => $tag, '$polled' => t('Last background fetch: '), '$lastpoll' => get_poller_runtime(), '$load_average' => t('Current load average: '), '$loadavg_all' => $loadavg[0] . ', ' . $loadavg[1] . ', ' . $loadavg[2], '$commit' => $commit, '$web_location' => t('Running at web location') . ' ' . z_root(), '$visit' => t('Please visit <a href="http://hubzilla.org">hubzilla.org</a> to learn more about $Projectname.'), '$bug_text' => t('Bug reports and issues: please visit'), '$bug_link_url' => 'https://github.com/redmatrix/hubzilla/issues', '$bug_link_text' => t('$projectname issues'), '$contact' => t('Suggestions, praise, etc. - please email "redmatrix" at librelist - dot com'), '$donate' => $donate, '$adminlabel' => t('Site Administrators'), '$admininfo' => $admininfo, '$plugins_text' => $plugins_text, '$plugins_list' => $plugins_list));
     call_hooks('about_hook', $o);
     return $o;
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:33,代码来源:Siteinfo.php

示例5: assureCpuNotBurning

 protected function assureCpuNotBurning($load = 8)
 {
     $cpu = sys_getloadavg();
     if ($cpu[0] > $load) {
         throw new DelayException();
     }
 }
开发者ID:supertowers,项目名称:queue-bundle,代码行数:7,代码来源:QueueJob.php

示例6: logData

 /**
  * logData
  *
  * Retrives data and logs it to file
  *
  * @param string $type type of logging default set to normal but it can be API too.
  * @return string $string if type is API returns data as string
  *
  */
 public function logData($type = false)
 {
     $class = __CLASS__;
     $settings = Logger::$_settings->{$class};
     $timestamp = time();
     $load = null;
     //use the php function if its there
     if (!function_exists('sys_getloadavg')) {
         $load = exec("cat /proc/loadavg | awk -F' ' '{print \$1\"|\"\$2\"|\"\$3}'");
     } else {
         $phpload = sys_getloadavg();
         $load = $phpload[0] . "|" . $phpload[1] . "|" . $phpload[2];
     }
     //if we want fancy formatting in logs we can always format them like this
     //$number = number_format((float)$number, 2, '.', '');
     $string = $timestamp . '|' . $load . "\n";
     //we can also add a switch to feed live data to server with no local logging
     //by just returning data
     $filename = sprintf($this->logfile, date('Y-m-d'));
     LoadUtility::safefilerewrite($filename, $string, "a", true);
     //If alerts are enabled, check for alerts
     //note: $phpload dont work on 4.0 needs fixing above
     if (Alert::$alertStatus) {
         $alertString = $this->checkAlerts($timestamp, $phpload, $settings);
     }
     //Based on API mode return data if need be
     if ($type == "api") {
         return $string;
     } else {
         return true;
     }
 }
开发者ID:javinc,项目名称:loadavg,代码行数:41,代码来源:log.Cpu.php

示例7: dump

 /**
  * Dump live informations from extender process (if in daemon mode and pcntl installed)
  *
  * @param   int     $timestamp_absolute
  * @param   itn     $parent_pid
  * @param   int     $completed_processes
  * @param   itn     $failed_processes
  */
 public static final function dump($timestamp_absolute, $parent_pid, $completed_processes, $failed_processes, $paused)
 {
     $statusfile = EXTENDER_CACHE_FOLDER . self::$statusfile;
     $data = array("RUNNING" => $paused ? 0 : 1, "STARTED" => $timestamp_absolute, "TIME" => microtime(true) - $timestamp_absolute, "PARENTPID" => $parent_pid, "COMPLETED" => $completed_processes, "FAILED" => $failed_processes, "CPUAVG" => sys_getloadavg(), "MEM" => memory_get_usage(true), "MEMPEAK" => memory_get_peak_usage(true), "USER" => get_current_user(), "NICENESS" => function_exists('pcntl_getpriority') ? pcntl_getpriority() : "UNDEFINED");
     $content = serialize($data);
     return file_put_contents($statusfile, $content);
 }
开发者ID:comodojo,项目名称:extender.framework,代码行数:15,代码来源:Status.php

示例8: loadAverage

 /**
  * Get load average in percents.
  * @return string
  */
 public static function loadAverage()
 {
     $load = 0;
     if (stristr(PHP_OS, 'win')) {
         // its not a better solution, but no other way to do this
         $cmd = "wmic cpu get loadpercentage /all";
         @exec($cmd, $output);
         // if output is exist
         if ($output) {
             // try to find line with numeric data
             foreach ($output as $line) {
                 if ($line && preg_match("/^[0-9]+\$/", $line)) {
                     $load = $line;
                     break;
                 }
             }
         }
     } else {
         $sys_load = sys_getloadavg();
         // get linux load average (1 = 100% of 1 CPU)
         $load = $sys_load[0] * 100;
         // to percentage
     }
     if ((int) $load <= 0) {
         return 'error';
     }
     return (int) $load . '%';
 }
开发者ID:phpffcms,项目名称:ffcms-core,代码行数:32,代码来源:Environment.php

示例9: getServerCpuUsage

 private function getServerCpuUsage()
 {
     $load = sys_getloadavg();
     $cores = shell_exec('nproc');
     $use = shell_exec('ps -A -o pcpu | tail -n+2 | paste -sd+ | bc');
     return $use / $cores;
 }
开发者ID:sing-group,项目名称:Markyt,代码行数:7,代码来源:JobsController.php

示例10: get_server_load

function get_server_load()
{
    if (stristr(PHP_OS, 'win') != false) {
        $fileModTime = filemtime("./load.cache");
        $cache = @file_get_contents("./load.cache");
        if (file_exists("./load.cache") && !empty($cache) && $fileModTime && time() - $fileModTime < 60) {
            $load = $cache;
        } else {
            $wmi = new COM("Winmgmts://");
            $server = $wmi->execquery("SELECT LoadPercentage FROM Win32_Processor");
            $cpu_num = 0;
            $load_total = 0;
            foreach ($server as $cpu) {
                $cpu_num++;
                $load_total += $cpu->loadpercentage;
            }
            $load = round($load_total / $cpu_num, 2);
            file_put_contents("./load.cache", $load);
        }
    } else {
        $sys_load = sys_getloadavg();
        $load = round($sys_load[0], 2);
    }
    return (int) $load;
}
开发者ID:kadivar,项目名称:sentora-whmcs,代码行数:25,代码来源:status.php

示例11: loadAverage

 private function loadAverage()
 {
     if (function_exists('sys_getloadavg')) {
         $load = sys_getloadavg();
         return $load[0];
     }
 }
开发者ID:jjechev,项目名称:phpTdConvert,代码行数:7,代码来源:Core.php

示例12: cpu

 public function cpu()
 {
     $loads = sys_getloadavg();
     $cores = trim($this->ssh->exec("grep -P '^processor' /proc/cpuinfo|wc -l"));
     $load = round($loads[0] / ($cores + 1) * 100, 2);
     return ['num' => $cores, 'load' => $load];
 }
开发者ID:DINKIN,项目名称:rokket,代码行数:7,代码来源:host.php

示例13: _load_protection

/**
 * 服务器负载保护函数,本方法目前不支持window系统
 *
 * 最大负载不要超过3*N核,例如有16核(含8核超线程)则 16*3=48
 *
 * @see http://php.net/manual/en/function.sys-getloadavg.php
 */
function _load_protection($max_load_avg = 24)
{
    global $dir_log, $dir_wwwroot;
    if (!function_exists('sys_getloadavg')) {
        return false;
    }
    $load = sys_getloadavg();
    if (!isset($load[0])) {
        return false;
    }
    if ($load[0] <= $max_load_avg) {
        // 未超过负载,则跳出
        return false;
    }
    $msg_tpl = "[%s] HOST:%s LOAD:%s ARGV/URI:%s\n";
    $time = @date(DATE_RFC2822);
    $host = php_uname('n');
    $load = sprintf('%.2f', $load[0]);
    if (php_sapi_name() == "cli" || empty($_SERVER['PHP_SELF'])) {
        $argv_or_uri = implode(',', $argv);
    } else {
        $argv_or_uri = $_SERVER['REQUEST_URI'];
    }
    $msg = sprintf($msg_tpl, $time, $host, $load, $argv_or_uri);
    if (@is_dir($dir_log)) {
        @file_put_contents($dir_log . "php-server-overload.log", $msg, FILE_APPEND);
    }
    # exit with 500 page
    header("HTTP/1.1 500 Internal Server Error");
    header("Expires: " . gmdate("D, d M Y H:i:s", time() - 99999) . " GMT");
    header("Cache-Control: private");
    header("Pragma: no-cache");
    exit(file_get_contents($dir_wwwroot . 'errors/server_overload.html'));
}
开发者ID:google2013,项目名称:myqeecms,代码行数:41,代码来源:index.php

示例14: verifyError

 public function verifyError()
 {
     $load = sys_getloadavg();
     $CPUProcessNumber = $this->getMaxCPUProcessNumbers();
     if ($load[$this->getTime()] > $CPUProcessNumber) {
         $this->getHandler()->addErrorHandle("Current CPU process number is {$load[$this->getTime()]}, when allowed is {$CPUProcessNumber}", '', $this->getStateType());
     }
 }
开发者ID:ASAPUK,项目名称:Monitoring,代码行数:8,代码来源:CPU.php

示例15: getCPUusage

 /**
  * CPU Last der letzten 1,5,15 Minuten auslesen
  */
 static function getCPUusage()
 {
     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
         return false;
     } else {
         return sys_getloadavg();
     }
 }
开发者ID:cherry-wb,项目名称:Qemu,代码行数:11,代码来源:Server.class.php


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