Reply
Username:
Title:
  Fett Unterstrichen Kursiv Strike Marquee Code Links Center Rechts Liste Code Zitat Code PHP Code Code Bild Link eMail Farbe
Nachricht:

Lachen LOL Biggrin Traurig Undecided
Zwink Rolleyes Tongune Kuss Lipsrsealed
Staunen Neutral Durcheinnander Cool Twisted
Evil Pfeil Idee Exclaim Frage

HTML is not allowed
Smilies are allowed
BBCode is allowed
Options
Matheaufgabe: Confirmation Code Ergebnis
 

Topics (Latest first) suche
Written by Lucky on 19.01.2010 to 02:35 Clock
Server Onlinezeit

sysonline.php

PHP Code:



<?php
function uptime() {
if (!
$times posix_times() ) {
return (
"unknown");
} else {
$now $times['ticks'];
$days intval($now / (60*60*24*100));
$remainder $now % (60*60*24*100);
$hours intval($remainder / (60*60*100));
$remainder $remainder % (60*60*100);
$minutes intval($remainder / (60*100));
if (
$days == 1) {$writeDays "Tag";} else {$writeDays "Tagen";}
if (
$hours == 1) {$writeHours "Stunde"; } else {$writeHours "Stunden";}
if (
$minutes == 1) {$writeMins "Minute";} else {$writeMins "Minuten";}
return (
"$days $writeDays$hours $writeHours$minutes $writeMins");
}
}
?>

<?php
print uptime();
?>
 
Written by Lucky on 19.01.2010 to 02:32 Clock
Arbeitsspeicher - Swap Auslastung auslesen.

ram.php

PHP Code:

<pre>
<?
php
// -b -> Speicher in Bytes
// -k -> Speicher in Kilobyte
// -m -> Speicher in Megabyte
// -g -> Speicher in Gigabytes
exec('free -t -m'$output);
list(
$null$ram_total$ram_used$ram_free$ram_shared$ram_buffers,
    
$ram_cached)
     = 
explode(' 'preg_replace('~[ ]+~'' '$output[1]));
list(
$null$swap_total$swap_used$swap_free)
    = 
explode(' 'preg_replace('~[ ]+~'' '$output[3]));
list(
$null$total_total$total_used$total_free)
     = 
explode(' 'preg_replace('~[ ]+~'' '$output[4]));
unset(
$null);
echo 
'Mem-Auslastung: ' $ram_used '/'$ram_total ' MB' PHP_EOL;

echo 
'Swap-Auslastung: ' $swap_used '/'$swap_total ' MB' .PHP_EOL;

echo 
'Gesamtlast: ' $total_used '/'$total_total .  ' MB' .PHP_EOL;
echo 
PHP_EOL;

?>
</pre>
 
Written by Lucky on 19.01.2010 to 02:27 Clock
Wusste nich wo ich es reinpacken sollte also ma hier.
Hab hier n paar Scripts die root - vServer User interessieren Sollten.
Mit diesen Scripts kannst du deine Server Auslastung auslesen und auf ner Webseite anzeigen lassen.

http://upload.matpo.de/bild/12142/sysinfoMGS7W.gif

CPU - Auslastung Auslesen.
Datei 1/2
class_CPULoad.php
PHP Code:

<?php
define
("TEMP_PATH","/tmp/");

class 
CPULoad {
    
    function 
check_load() {
        
$fd fopen("/proc/stat","r");
        if (
$fd) {
            
$statinfo explode("n",fgets($fd1024));
            
fclose($fd);
            foreach(
$statinfo as $line) {
                
$info explode(" ",$line);
                if(
$info[0]=="cpu") {
                    
array_shift($info);  
                    if(!
$info[0]) array_shift($info); 
                    
$this->user $info[0];
                    
$this->nice $info[1];
                    
$this->system $info[2];
                    
$this->idle $info[3];
                    return;
                }
            }
        }
    }
    
    function 
store_load() {
        
$this->last_user $this->user;
        
$this->last_nice $this->nice;
        
$this->last_system $this->system;
        
$this->last_idle $this->idle;
    }
    
    function 
save_load() {
        
$this->store_load();
        
$fp = @fopen(TEMP_PATH."cpuinfo.tmp","w");
        if (
$fp) {
            
fwrite($fp,time()."n");
            
fwrite($fp,$this->last_user." ".$this->last_nice." ".$this->last_system." ".$this->last_idle."n");
            
fwrite($fp,$this->load["user"]." ".$this->load["nice"]." ".$this->load["system"]." ".$this->load["idle"]." ".$this->load["cpu"]."n");
            
fclose($fp);
        }
    }
    
    function 
load_load() {
        
$fp = @fopen(TEMP_PATH."cpuinfo.tmp","r");
        if (
$fp) {
            
$lines explode("n",fread($fp,1024));
            
            
$this->lasttime $lines[0];
            list(
$this->last_user,$this->last_nice,$this->last_system,$this->last_idle) = explode(" ",$lines[1]);
            list(
$this->load["user"],$this->load["nice"],$this->load["system"],$this->load["idle"],$this->load["cpu"]) = explode(" ",$lines[2]);
            
fclose($fp);
        } else {
            
$this->lasttime time() - 60;
            
$this->last_user $this->last_nice $this->last_system $this->last_idle 0;
            
$this->user $this->nice $this->system $this->idle 0;
        }
    }
    
    function 
calculate_load() {
        
        
        
$d_user $this->user $this->last_user;
        
$d_nice $this->nice $this->last_nice;
        
$d_system $this->system $this->last_system;
        
$d_idle $this->idle $this->last_idle;
        
        

        
$total=$d_user+$d_nice+$d_system+$d_idle;
        if (
$total<1$total=1;
        
$scale 100.0/$total;
        
        
$cpu_load = ($d_user+$d_nice+$d_system)*$scale;
        
$this->load["user"] = $d_user*$scale;
        
$this->load["nice"] = $d_nice*$scale;
        
$this->load["system"] = $d_system*$scale;
        
$this->load["idle"] = $d_idle*$scale;
        
$this->load["cpu"] = ($d_user+$d_nice+$d_system)*$scale;
    }
    
    function 
print_current() {
        
printf("Current load tickers - User: %f  Nice: %f  System: %f  Idle: %f<br>",
            
$this->user,
            
$this->nice,
            
$this->system,
            
$this->idle
        
);
    }

    function 
print_load() {
        
printf("CPU Auslastung: %.1f%%<br>",
            
            
$this->load["cpu"]
        );
    }

    function 
sample_load($interval=1) {
        
$this->check_load();
        
$this->store_load();
        
sleep($interval);
        
$this->check_load();
        
$this->calculate_load();
    }
    
    function 
get_load($fastest_sample=4) {
        
$this->load_load();
        
$this->cached = (time()-$this->lasttime);
        if (
$this->cached>=$fastest_sample) {
            
$this->check_load(); 
            
$this->calculate_load();
            
$this->save_load();
        }
    }

}
?>

 


Teil 2 Datei showload.php
PHP Code:

<pre>
<?
php
require_once("class_CPULoad.php");

$cpuload = new CPULoad();
$cpuload->get_load();
$cpuload->print_load();


?>
</pre>
 

Das Script dann mit deine-domain.de/showload.php aufrufen

MatPo Facebookseite MatPo Twitterseite MatPo Googleplus Seite Add News Feeds zu Google