Example #1
0
function update_controls()
{
    $sysinfo = system_get_sysinfo();
    $cpus = system_get_cpus();
    $sysinfo['cpus'] = $cpus;
    if ($cpus > 1) {
        $sysinfo['cpuusage2'] = system_get_smp_cpu_usage();
        $sysinfo['cpuusage'] = floor(array_sum($sysinfo['cpuusage2']) / $cpus);
    } else {
        $sysinfo['cpuusage2'] = array($sysinfo['cpuusage']);
    }
    return json_encode($sysinfo);
}
Example #2
0
	(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
	SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

	The views and conclusions contained in the software and documentation are those
	of the authors and should not be interpreted as representing official policies,
	either expressed or implied, of the NAS4Free Project.
*/
require "auth.inc";
require "guiconfig.inc";
session_start();
// Make sure no other output than the requested data is echoed.
if (0 == strcmp("cpu=", getenv("QUERY_STRING"))) {
    /* leave it as is to avoid side effects (only an additional "=")*/
    $cpuload = @system_get_cpu_usage();
    echo $cpuload;
} else {
    $param = $_GET;
    if (isset($param['if'])) {
        $ifinfo = @get_interface_info($param['if']);
        $time = gettimeofday();
        $timing = (double) $time["sec"] + (double) $time["usec"] / 1000000.0;
        echo "{$timing}|" . $ifinfo['inbytes'] . "|" . $ifinfo['outbytes'] . "\n";
    } else {
        if (isset($param['cpu'])) {
            if ($param['cpu'] == 0) {
                $_SESSION['cpu'] = @system_get_smp_cpu_usage();
            }
            echo $_SESSION['cpu'][$param['cpu']];
        }
    }
}