24. 07. 2005. | #1 |
Web designer
Professional
|
Server status
Ovo moze slobodno da ide u i linux sekciju
Konkretno zanima me kako bi isao output za status servera, pokrenutih servisa i njihov uptime (znaci koliko dugo je vec aktivan taj daemon, tipa apache) Kôd:
<?php function checkd($daemon,$name) { $ps ="ps ax | grep $daemon | wc -l"; $origps = exec($ps); $minone = $origps-2; if ($minone<1) { $dataps = "only <b><font color=red>$minone</font> daemon</b> for <b>$daemon</b>, <br><b><font color=red>$name TOTALY DOWN</font></b><br>"; } if ($minone==1) { $dataps = "<b><font color=blue>up</font></b> only with <b><font color=red>$minone</font> $daemon daemon</b><br>"; } if ($minone>1) { $dataps = "<b><font color=blue>up</font></b> with <b><font color=red>$minone</font> $daemon daemons</b><br>"; } return $dataps; } echo checkd("mysqld","mysql daemon"); echo checkd("httpd","httpd daemon"); ?> |
25. 07. 2005. | #2 |
Nikola Denić
Sir Write-a-Lot
|
uhm .. znam da beše neko čudo koje je to radilo i to je open sorce .. ček da se javi bluesman on je radio sa tim
__________________
Do not ask yourself what the world needs. Ask yourself what makes you come alive, and then go do that. Because what the world needs is people who have come alive |
25. 07. 2005. | #3 |
Goran Pilipović
Sir Write-a-Lot
|
Ja sam se samo igrao sa server load, pokušavao sam da iz PHP saznam koji je load servera. Hteo sam dobijene podatke da koristim za neki simple "load balancing". Nisam došao do pouzdanog rešenja, možda zato što mi fali malo advanced linux znanja.
A ovo je malo tricky, ako je apache, myslq ... down, velika je šansa i da je ceo server down a onda je nelogično izvršavati script na serveru koji je verovatno down. Ja sam imao drugu ideju, da na drugom serveru slušam neki treći server... ali nisam išao dalje od ideje.
__________________
Goran Pilipović a.k.a. Ugly Fingers Bradley f.k.a. bluesman I don't always know what I'm talking about but I know I'm right! |
25. 07. 2005. | #4 |
Web designer
Professional
|
Server load, etc.
Kôd:
<?php // VHost Address... $vHost = @getenv(SERVER_NAME); if (!$vHost) { $vHost = "(N/A)"; } // Host Server Name... $fp = @fopen("/proc/sys/kernel/hostname","r"); if ($fp) { $serverName = trim(fgets($fp, 4096)); $serverName = gethostbyname($serverName); $serverName = gethostbyaddr($serverName); fclose($fp); } else { $serverName = "(N/A)"; } // Server or Dedicated IP... $IPAddress = getenv("SERVER_ADDR"); // Operating system... $fp = @fopen("/proc/version", "r"); if ($fp) { $temp = fgets($fp); fclose($fp); if (preg_match("/version (.*?) /", $temp, $OSArray)) { $kernel = $OSArray[1]; preg_match("/[0-9]{5,} (\((.* *)\)\))/", $temp, $OSArray); $flavour = $OSArray[2]; $operatingSystem = $flavour." (".PHP_OS." ".$kernel.")"; if (preg_match("/SMP/", $buf)) { $operatingSystem .= " (SMP)"; } } else { $result = "(N/A)"; } } else { $result = "(N/A)"; } // Users and load information... $rawUptime = trim(exec("uptime")); if ($rawUptime) { if (preg_match("/, *(\d) (users?), .*: (.*), (.*), (.*)/", $rawUptime, $uptime)) { $users[0] = $uptime[1]; $users[1] = $uptime[2]; $loadNow = $uptime[3]; $load15 = $uptime[4]; $load30 = $uptime[5]; } } else { $users[0] = "Unavailable"; $users[1] = "--"; $loadNow = "Unavailable"; $load15 = "--"; $load30 = "--"; } // CPUs Stuff... $fp = @fopen("/proc/cpuinfo", "r"); if ($fp) { while ($temp = fgets($fp, 4096)) { $temp = trim($temp); $thing = preg_split("/\s+:\s+/", $temp, 2); switch ($thing[0]) { case "model name": $CPUModel = $thing[1]; break; case "cpu MHz": $CUPSize = sprintf("%.2f", $thing[1]); break; case "cycle frequency [Hz]": $CUPSize = sprintf("%.2f", $thing[1] / 1000000); break; case "bogomips": $BOGO += $thing[1]; break; case "processor": $CPUs += 1; break; } } fclose($fp); } else { $CPUModel = "(Not Available)"; $CUPSize = "--"; $BOGO = "--"; $CPUs = "--"; } ?> <HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <TITLE><?=$_GET[server]?> Statistics</TITLE> </HEAD> <BODY> <P><B>Server Statistics (<?=$_GET[server]?>):</B><FONT color="#808080"><BR> <?=$vHost?> </FONT>on <FONT color="#808080"><?=$serverName?> </FONT>(<FONT color="#808080"><?=$IPAddress?></FONT>)<BR> Running <FONT color="#808080"><?=$operatingSystem?></FONT>; <FONT color="#808080"><?=$users[0]?> </FONT>current active <?=$users[1]?>.<BR> With <FONT color="#808080"><?=$CUPs?></FONT> CPU: <FONT color="#808080"><?=$CPUModel?></FONT> <SMALL>(actual measured speed: <FONT color="#808080"><?=$CUPSize?>KHz - <?=$BOGO?> bogomips</FONT>)</SMALL>.<BR> Current load: <FONT color="#808080"><?=$loadNow?></FONT>; 15 minute load average: <FONT color="#808080"><?=$load15?></FONT>; 30 minute load average: <FONT color="#808080"><?=$load30?></FONT>.</P> </BODY> </HTML> E sad posto ja ne znam programiranje, znam sta i kako radi, ali nazalost ne znam sam da napisem svoj code, trebao bi mi status kao onaj na jabber.elitsecurity.org, znaci koliko dana, sati, minuta je neki daemon podignut. Ehh da imam vase php znanje |
25. 07. 2005. | #5 |
Goran Pilipović
Sir Write-a-Lot
|
Na žalost, na prvi pogled ovaj tvoj kod radi samo na specijalnim i prilično "bušnim" serverima. Tako da bi ti na "bezbednijim" ili "paranoičnijim" serverima, recimo
PHP kôd:
Zato kažem da nisam našao zadovoljavajuće rešenje.
__________________
Goran Pilipović a.k.a. Ugly Fingers Bradley f.k.a. bluesman I don't always know what I'm talking about but I know I'm right! |
25. 07. 2005. | #6 |
Web designer
Professional
|
Kôd:
twix@twixbox:/var/www # ps -eo etime,cmd | grep "apache2" 01:15:57 /usr/sbin/apache2 -k start -DSSL 01:15:56 /usr/sbin/apache2 -k start -DSSL 01:15:56 /usr/sbin/apache2 -k start -DSSL 01:15:56 /usr/sbin/apache2 -k start -DSSL 01:15:56 /usr/sbin/apache2 -k start -DSSL 01:15:56 /usr/sbin/apache2 -k start -DSSL 01:13:02 /usr/sbin/apache2 -k start -DSSL 01:06:22 /usr/sbin/apache2 -k start -DSSL 00:00 grep apache2 twix@twixbox:/var/www # Apache je pokrenut 1 sat i 15 minuta . E sad, ne znam kako ce to da bude ako je pokrenut recimo 20 dana, kako da ispise: Apache je pokrenut 20 dana, 1 sat i 15 minuta . Sto se tice cat /proc/sys/kernel/hostname moguce da na nekim serverima ne mozes to da pogledas, ali do sada nisam naisao na sistem gde je to zabranjeno, ako nista, barem: twix@twixbox:/var/www # uname -a Linux twixbox 2.6.10-5-386 #1 Tue Apr 5 12:12:40 UTC 2005 i686 GNU/Linux twix@twixbox:/var/www # Hvala, |
25. 07. 2005. | #7 |
Igor Marinović
Expert
|
Ne mogu baš da nađem opravdanje i razumevanje za prikaz informacije o uptimeu procesa. Obično je to irelevantno za korisnika, interesantno je eventualno za administratore koji ionako to mogu videti na drugi način. Jeste dugačak uptime ponos, ali ne govori mnogo.
Doduše, ima i primera kada je prikazana sistemska informacija korisna: primer je (inače odličan) sajt http://www.sxc.hu/ ... Tamo prikazuju koliko je opterećenje servera, pa se korisnik moli da se obuzda ukoliko vidi da je dogorelo do nokata A za load balancing servera svakako treba jača artiljerija od običnog php-a. |
25. 07. 2005. | #8 |
Igor Marinović
Expert
|
Ali ajde da budem konstruktivan: ovo ce ti resiti posao:
Kôd:
<? $process = 'apache'; $uptime = exec("ps -eo etime,cmd T| grep $process |head -1 |cut -f 1 -d '/'"); if (preg_match("/(\d*)-?(\d\d):(\d\d):(\d\d) *$/",$uptime, $m)) { $dan = $m[1]?"$m[1] dana":''; $sat = $m[2]?"$m[2] sati":''; } else { preg_match("/(\d*)-?(\d*):?(\d\d):(\d\d) *$/",$uptime, $m); } print "$process je pokrenut: $dan $sat $m[3] minuta $m[4] sekundi"; ?> |
25. 07. 2005. | #9 | |
Web designer
Professional
|
Zigor hvala puno, ovo mi je trebalo!
Citat:
Hvala jos jednom, pozdrav.. |
|
26. 07. 2005. | #10 |
Nikola Denić
Sir Write-a-Lot
|
pa ne moras da tako gledas da li je aktivan jabber server ... direktno komuniciraj sa jabberd-om
__________________
Do not ask yourself what the world needs. Ask yourself what makes you come alive, and then go do that. Because what the world needs is people who have come alive |
|
|
Slične teme | ||||
Tema | Početna poruka teme | Forum | Odgovori | Poslednja poruka |
Status servisa na serveru, provera? | pcigre | Web Hosting, web serveri i operativni sistemi | 9 | 22. 01. 2009. 21:11 |
Domen ističe za godinu dana a ima status PENDING DELETE RESTORABLE ?! | Nenad Vasić | Domain Name Service (DNS) | 7 | 30. 06. 2008. 03:22 |
Limundo status nagradne igre | Milos Micic | e-Business | 42 | 13. 06. 2007. 15:44 |
Server vs. UTF-8 | Milos Vukotic | Web Hosting, web serveri i operativni sistemi | 18 | 02. 02. 2006. 00:22 |