xml地图|网站地图|网站标签 [设为首页] [加入收藏]

分享一段php获取linux服务器状态的代码,获取Li

来源:http://www.ccidsi.com 作者:呼叫中心培训课程 人气:129 发布时间:2019-08-14
摘要:  //检查测量试验时间   $fp = popen("date "%Y-%m-%d %H:%M"","r");   $rs = fread($fp,1024);   pclose($fp);   $detection_time = trim($rs); ?php  /*老是数据 begin*/  include("conn.php");  $obj_MyConnect = new MyConnect();  

  //检查测量试验时间
  $fp = popen("date "%Y-%m-%d %H:%M"","r");
  $rs = fread($fp,1024);
  pclose($fp);
  $detection_time = trim($rs);

<?php
 /*老是数据 begin*/
 include("conn.php");
 $obj_MyConnect = new MyConnect();
 $obj_MyConnect -> connect(DB_SERVER,DB_USER,DB_PWD,DB_NMAE); 
 /*三番几遍数据 end*/
 
 function get_used_status(){
  $fp = popen('top -b -n 2 | grep -E "^(Cpu|Mem|Tasks)"',"r");//获取某有的时候刻系统cpu和内部存款和储蓄器使用情形
  $rs = "";
  while(!feof($fp)){
   $rs .= fread($fp,1024);
  }
  pclose($fp);
  $sys_info = explode("n",$rs);

        if($temp<$overtime&&$temp>=0){

你可能感兴趣的稿子:

  • php获取服务器端mac和客户端mac的地方帮衬WIN/LINUX
  • php获取网卡的MAC地址帮助WIN/LINUX系统
  • PHP中赢得内网用户MAC地址(WINDOWS/linux)的贯彻代码
  • php $_SE昂科威VERAV4windows系统与linux系统下的分裂表明
  • linux系统上支撑php的 iconv()函数的措施
  • PHP实行linux系统命令的常用函数使用验证
  • Linux系统下php获得系统一分配区新闻的法子

收获服务器质量CPU、内部存款和储蓄器、硬盘等使用率  get_used_status.php

?>
</html>

  return  array('cpu_usage'=>$cpu_usage,'mem_usage'=>$mem_usage,'hd_avail'=>$hd_avail,'hd_usage'=>$hd_usage,'tast_running'=>$tast_running,'detection_time'=>$detection_time);
 }

  $tast_info = explode(",",$sys_info[3]);//进程 数组
  $cpu_info = explode(",",$sys_info[4]);  //CPU占有量  数组
  $mem_info = explode(",",$sys_info[5]); //内部存款和储蓄器占有量 数组

$pathtemp=explode("/",$HTTP_ENV_VARS["PATH_INFO"]);
$pathtemp[sizeof($pathtemp)-1]="";
$cgiroot="

  //内部存款和储蓄器据有量
  $mem_total = trim(trim($mem_info[0],'Mem: '),'k total');
  $mem_used = trim($mem_info[1],'k used');
  $mem_usage = round(100*intval($mem_used)/intval($mem_total),2);  //百分比  

数据库配置文件: conn.php

for($i=0;$i<sizeof($info);$i ){
    if(trim($info[$i])!="") fputs($fp,trim($info[$i].">"));
}
    fclose($fp);

轻巧易行的php获取linux服务器状态的代码,没多少说-直接上函数:

define("MONITORED_IP", "172.16.0.191");  //被监督的服务器IP地址  也便是本机地址
define("DB_SELX570VE奥德赛", "172.16.7.2");       //贮存数据的服务器IP地址
define("DB_USER", "root");
define("DB_PWD","111111");
define("DB_NMAE","performance");
 
class MyConnect{
 
 public function connect($db_server,$db_user,$db_pwd,$db_name){
 
  $conn = mysql_connect($db_server,$db_user,$db_pwd);
  if (!$conn){
   die('连接数据库退步: ' . mysql_error());
  }
  $flag = mysql_select_db($db_name,$conn);
  if(!$flag){
   echo "<p align='center'>数据库连接出错!</p>";exit();
  }else{
   mysql_query("SET NAMES UTF8");
  }
 }
 
}
?>

<?php
//传入num为要下载的文件号,col=要下载的分栏
//ip不超时下载次数加一

function get_used_status(){
  $fp = popen('top -b -n 2 | grep -E "^(Cpu|Mem|Tasks)"',"r");//获取某不时时系统cpu和内部存款和储蓄器使用境况
  $rs = "";
  while(!feof($fp)){
   $rs .= fread($fp,1024);
  }
  pclose($fp);
  $sys_info = explode("n",$rs);

  /*硬盘使用率 begin*/
  $fp = popen('df -lh | grep -E "^(/)"',"r");
  $rs = fread($fp,1024);
  pclose($fp);
  $rs = preg_replace("/s{2,}/",' ',$rs);  //把七个空格换来 “_”
  $hd = explode(" ",$rs);
  $hd_avail = trim($hd[3],'G'); //磁盘可用空间大小 单位G
  $hd_usage = trim($hd[4],'%'); //挂载点 百分比
  //print_r($hd);
  /*硬盘使用率 end*/  
  
  //检查实验时间
  $fp = popen("date "%Y-%m-%d %H:%M"","r");
  $rs = fread($fp,1024);
  pclose($fp);
  $detection_time = trim($rs);
  
  /*获取IP地址  begin*/
  /*
  $fp = popen('ifconfig eth0 | grep -E "(inet addr)"','r');
  $rs = fread($fp,1024);
  pclose($fp);
  $rs = preg_replace("/s{2,}/",' ',trim($rs));  //把三个空格换到“_”
  $rs = explode(" ",$rs);
  $ip = trim($rs[1],'addr:');
  */
  /*获取IP地址 end*/
  /*
  $file_name = "/tmp/data.txt"; // 相对路线: homedata.dat 
  $file_pointer = fopen($file_name, "a "); // "w"是一种情势,详见后边
  fwrite($file_pointer,$ip); // 先把公文剪切为0字节大小, 然后写入
  fclose($file_pointer); // 结束
  */
  
  return array('cpu_usage'=>$cpu_usage,'mem_usage'=>$mem_usage,'hd_avail'=>$hd_avail,'hd_usage'=>$hd_usage,'tast_running'=>$tast_running,'detection_time'=>$detection_time);
 }
 
 //echo date("Y-m-d H:i:s",time())."<br>";
 
 $status=get_used_status();
 
 $sql = "insert into performance(ip,cpu_usage,mem_usage,hd_avail,hd_usage,tast_running,detection_time) ";
 $sql .= " value('".MONITORED_IP."','".$status['cpu_usage']."','".$status['mem_usage']."','".$status['hd_avail']."','".$status['hd_usage']."','".$status['tast_running']."','".$status['detection_time']."')";
 $query = mysql_query($sql) or die("SQL 语句实行停业!");
 unset($status);
 
 //echo date("Y-m-d H:i:s",time())."<br>";
 
?>

//取出ip文件
$fp=@fopen($ipfile,"r") or die("对不起该投票不合规".$goback);
$ipinfo=fread($fp,filesize($ipfile));
fclose($fp);
unlink($ipfile);
$times=getdate();
$abstime=$times["yday"].sprintf("d",$times["hours"]);
//绝对时间  

  /*获取IP地址  begin*/
  /*
  $fp = popen('ifconfig eth0 | grep -E "(inet addr)"','r');
  $rs = fread($fp,1024);
  pclose($fp);
  $rs = preg_replace("/s{2,}/",' ',trim($rs));  //把两个空格换来“_”
  $rs = explode(" ",$rs);
  $ip = trim($rs[1],'addr:');
  */
  /*获取IP地址 end*/
  /*
  $file_name = "/tmp/data.txt"; // 相对路线: homedata.dat
  $file_pointer = fopen($file_name, "a "); // "w"是一种格局,详见前面
  fwrite($file_pointer,$ip); // 先把公文剪切为0字节大小, 然后写入
  fclose($file_pointer); // 结束
  */

  //正在运转的长河数
  $tast_running = trim(trim($tast_info[1],'running'));
  
  
  //CPU占有量
  $cpu_usage = trim(trim($cpu_info[0],'Cpu(s): '),'%us');  //百分比
  
  //内部存款和储蓄器占领量
  $mem_total = trim(trim($mem_info[0],'Mem: '),'k total'); 
  $mem_used = trim($mem_info[1],'k used');
  $mem_usage = round(100*intval($mem_used)/intval($mem_total),2);  //百分比   

    $items=explode("<",$info[$i]);
         if(!trim($items[0])) continue;
    if(trim($items[0])==$num){//要下载的类型
        if($firstdown)
        $items[6] ;
        $filepath=$uploadto.$items[2];
        $info[$i]=implode("<",$items);         
        break;
    }

  /*硬盘使用率 begin*/
  $fp = popen('df -lh | grep -E "^(/)"',"r");
  $rs = fread($fp,1024);
  pclose($fp);
  $rs = preg_replace("/s{2,}/",' ',$rs);  //把多少个空格换到 “_”
  $hd = explode(" ",$rs);
  $hd_avail = trim($hd[3],'G'); //磁盘可用空间大小 单位G
  $hd_usage = trim($hd[4],'%'); //挂载点 百分比
  //print_r($hd);
  /*硬盘使用率 end*/ 

<?php

    for($i=0;$i<sizeof($ip_times);$i ){

复制代码 代码如下:

图片 1

//ip剖断结束

  $tast_info = explode(",",$sys_info[3]);//进程 数组
  $cpu_info = explode(",",$sys_info[4]);  //CPU占有量  数组
  $mem_info = explode(",",$sys_info[5]); //内部存款和储蓄器占领量 数组

那是本系统的download.php,紧要担负下载和记数,在那之中文件格式均在疏解中表明.

  //正在运营的进程数
  $tast_running = trim(trim($tast_info[1],'running'));
  //CPU占有量
  $cpu_usage = trim(trim($cpu_info[0],'Cpu(s): '),'%us');  //百分比

echo "<head><meta http-equiv='refresh' content='3;URL=".$filepath."'>";
echo "<link rel='stylesheet' href='../css/eccct.css'></head>";
echo "<body class=tb >";
echo "<div >";
echo "<br><br><br>";
echo "<div class='values'>您的浏览器会在三秒钟后自动下载</div>";
echo "<br><br><br>";
echo "<div class='values'>恐怕点击<a href='".$filepath."'>此处</a>下载</div>";
echo "<br><br><br>";
echo "</div>";

本文由68399皇家赌场发布于呼叫中心培训课程,转载请注明出处:分享一段php获取linux服务器状态的代码,获取Li

关键词: 68399皇家赌场

上一篇:搭建项目,cli搭建项目

下一篇:没有了

最火资讯