PHP Classes

File: serverdata.php

Recommend this page to a friend!
  Classes of Gianluca Zanferrari   PHP Graph Real Time   serverdata.php   Download  
File: serverdata.php
Role: Auxiliary script
Content type: text/plain
Description: ajax handler
Class: PHP Graph Real Time
Display graphs of machine usage in real time
Author: By
Last change:
Date: 9 years ago
Size: 905 bytes
 

Contents

Class file image Download
<?php
function get_memory_usage(){

   
$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);
   
$memory_usage = $mem[2]/$mem[1]*100;

    return(
round($memory_usage,2));
}

function
get_number_threads(){
   
$threads = shell_exec('ps -eo nlwp | tail -n +2 | awk \'{ num_threads += $1 } END { print num_threads }\'');
    return(
$threads);
}

function
get_number_users(){
   
$users = shell_exec('users | wc -w');
    return(
$users);
}

function
get_used_space(){
   
$ds = shell_exec('df -h /');
   
$arr_ds = explode("\n",$ds);
   
$line = $arr_ds[1];
   
$arr_data = explode(' ',$line);
    return(
round(intval($arr_data[4]),2));
}

if(isset(
$_GET['monitor']) && function_exists ($_GET['monitor'])){
    echo(
call_user_func($_GET['monitor']));
}