Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // error_reporting(E_ALL);
- $db_host = "xxxx";
- $db_user = "root";
- $db_pass = "xxxx";
- $db_name = "lvps";
- mysql_connect("$db_host", "$db_user", "$db_pass")or die("cannot connect");
- mysql_select_db("$db_name")or die("cannot select DB");
- $mmp=mysql_query("SELECT * FROM vps_vps_status");
- while ($rows = mysql_fetch_array($mmp)) {
- echo $rows['vps_id'];
- $dd=getvpsinfo($rows['vps_id'], "ram");
- $dd=getvpsinfo($rows['vps_id'], "hdd");
- $dd=getvpsinfo($rows['vps_id'], "cpu");
- }
- // neveikia, neaupdatina mysqle ko ?
- function getvpsinfo ($ifd, $kom) {
- global $serverIP;
- global $serverUSER;
- global $serverPASS;
- if ($kom == 'ram') {
- $connection=@ssh2_connect($serverIP, 22);
- ssh2_auth_password($connection,$serverUSER,$serverPASS);
- $stdout_stream = ssh2_exec($connection, "vzctl exec2 ".$ifd." free -m | awk {'print $3'}");
- sleep(1);
- $df = 0;
- $stderr_stream = ssh2_fetch_stream($stdout_stream, SSH2_STREAM_STDERR);
- while($line = fgets($stderr_stream)) { flush(); echo $line."<br>"; }
- while($line = fgets($stdout_stream)) { flush();
- //echo $line;
- if ($df == 1) {
- mysql_query("UPDATE vps_vps_status SET ram='$line' where vps_id='$ifd'");
- }
- $df=$df+1;
- }
- }
- if ($kom == 'hdd') {
- global $serverIP;
- $connection=@ssh2_connect($serverIP, 22);
- ssh2_auth_password($connection,$serverUSER,$serverPASS);
- $stdout_stream = ssh2_exec($connection, "vzctl exec2 ".$ifd." df -h |awk {'print $3'}");
- sleep(1);
- $df = 0;
- $stderr_stream = ssh2_fetch_stream($stdout_stream, SSH2_STREAM_STDERR);
- while($line = fgets($stderr_stream)) { flush(); echo $line."<br>"; }
- while($line = fgets($stdout_stream)) { flush();
- //echo $line;
- if ($df==1) {
- $mystring = $line;
- $findme = 'M';
- $pos = strpos($mystring, $findme);
- if ($pos !== false) {
- $hdd=(str_replace("M", "", $line) / 1024);
- } else {
- $hdd=(str_replace("G", "", $line));
- }
- mysql_query("UPDATE vps_vps_status SET disk='$hdd' where vps_id='$ifd'");
- $array = explode(" ", $line);
- $k1 = $array[0];
- $k2 = $array[1];
- $k3 = $array[2];
- $k4 = $array[3];
- $k5 = $array[4];
- for ($i=13; $i<15; $i++) {
- $k4=$k4."".$array[$i];
- }
- echo round($k4,1);
- }
- $df = $df + 1;
- }
- }
- if ($kom == 'cpu') {
- global $serverIP;
- $connection=@ssh2_connect($serverIP, 22);
- ssh2_auth_password($connection,$serverUSER,$serverPASS);
- $stdout_stream = ssh2_exec($connection, "vzctl exec2 ".$ifd." vmstat 1 5 |awk '{print $15}' > file");
- sleep(1);
- $df = 0;
- $stderr_stream = ssh2_fetch_stream($stdout_stream, SSH2_STREAM_STDERR);
- sleep(5);
- $stdout_stream = ssh2_exec($connection, 'cat file');
- sleep(1);
- $df = 0;
- $stderr_stream = ssh2_fetch_stream($stdout_stream, SSH2_STREAM_STDERR);
- while($line = fgets($stderr_stream)) { flush(); echo $line."<br>"; }
- while($line = fgets($stdout_stream)) { flush();
- //echo $line;
- if ($df==4) {
- $line=100-$line;
- echo $line;
- mysql_query("UPDATE vps_vps_status SET cpu='$line' where vps_id='$ifd'");
- }
- $df = $df + 1;
- }
- }
- if ($kom == 'uptime') {
- global $serverIP;
- $connection=@ssh2_connect($serverIP, 22);
- ssh2_auth_password($connection,$serverUSER,$serverPASS);
- $stdout_stream = ssh2_exec($connection, "vzctl exec2 ".$ifd." uptime");
- sleep(1);
- $df = 0;
- $stderr_stream = ssh2_fetch_stream($stdout_stream, SSH2_STREAM_STDERR);
- while($line = fgets($stderr_stream)) { flush(); echo $line."<br>"; }
- while($line = fgets($stdout_stream)) { flush();
- echo $line;
- if ($df == 1) {
- mysql_query("UPDATE vps_vps_status SET uptime='$line' where vps_id='$ifd'");
- }
- $df=$df+1;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement