<?php
$str = shell_exec('more /proc/stat');
$pattern = "/(cpu[0-9]? )[\s]+([0-9]+)[\s]+([0-9]+)[\s]+([0-9]+)[\s]+([0-9]+)[\s]+([0-9]+)[\s]+([0-9]+)[\s]+([0-9]+)/";
preg_match_all($pattern, $str, $out);
echo "共同拥有".count($out[1])."个CPU,每一个CPU利用率例如以下:\n";
for($n=0;$n<count($out[1]);$n++)
{
echo $out[1][$n]."=".(100*($out[1][$n]+$out[2][$n]+$out[3][$n])/($out[4][$n]+$out[5][$n]+$out[6][$n]+$out[7][$n]))."%\n";
}
$str = shell_exec('more /proc/meminfo');
$pattern = "/(.+):\s*([0-9]+)/";
preg_match_all($pattern, $str, $out);
echo "物理内存总量:".$out[2][0]."\n";
echo "已使用的内存:".$out[2][1]."\n";
echo "-----------------------------------------\n";
echo "内存使用率:".(100*($out[2][0]-$out[2][1])/$out[2][0])."%\n";
$str = shell_exec('more /proc/net/dev');
$pattern = "/(eth[0-9]+):\s*([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)/";
preg_match_all($pattern, $str, $out);
echo "共同拥有".count($out[1])."个网络接口,每一个网络接口利用率例如以下:\n";
for($n=0;$n<count($out[1]);$n++)
{
echo $out[1][$n].":收到 ".$out[3][$n]." 个数据包,发送 ".$out[11][$n]." 个数据包\n";
} function get_cpu_usg()
{
$str = shell_exec('more /proc/stat');
$pattern = "/(cpu[0-9]?)[\s]+([0-9]+)[\s]+([0-9]+)[\s]+([0-9]+)[\s]+([0-9]+)[\s]+([0-9]+)[\s]+([0-9]+)[\s]+([0-9]+)/";
preg_match_all($pattern, $str, $out);
$total=0;
for($n=0;$n<count($out[1]);$n++)
{
$usg=(100*($out[1][$n]+$out[2][$n]+$out[3][$n])/($out[4][$n]+$out[5][$n]+$out[6][$n]+$out[7][$n]));
$total+=$usg;
}
return $total;
} function get_mem_usg()
{
$str = shell_exec('more /proc/meminfo');
$pattern = "/(.+):\s*([0-9]+)/";
preg_match_all($pattern, $str, $out);
$memusg= (100*($out[2][0]-$out[2][1])/$out[2][0]) ;
return $memusg; }

输出形式例如以下

共同拥有11个CPU,每一个CPU利用率例如以下:
cpu=0.46448573378952%
cpu0=0.31392223749401%
cpu1=0.53497469529473%
cpu2=0.48665815912626%
cpu3=0.44933676279833%
cpu4=0.39351618273537%
cpu5=0.25942202031553%
cpu6=0.72395782907821%
cpu7=0.15144390649732%
cpu8=0.10644291691583%
cpu9=0.12204804936289%
物理内存总量:32776832
已使用的内存:240852
-----------------------------------------
内存使用率:99.265176085352%
共同拥有4个网络接口,每一个网络接口利用率例如以下:
eth0:收到 307077767 个数据包,发送 303024103 个数据包
eth1:收到 240252949 个数据包。发送 119448221 个数据包
eth2:收到 0 个数据包。发送 0 个数据包
eth3:收到 0 个数据包,发送 0 个数据包

php 获得linux 机器的性能的更多相关文章

  1. linux 查看服务器性能常用命令

    一.top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器   下面详细介绍它的使用方法.top是一个动态显示过程,即可以通过用户按键来 ...

  2. 【转载】Linux系统与性能监控

    原文地址:http://kerrigan.sinaapp.com/post-7.html Linux System and Performance Monitoring http://www.hous ...

  3. linux查看CPU性能及工作状态的指令

    http://www.aikaiyuan.com/9347.html http://blog.csdn.net/jk110333/article/details/8683478 http://www. ...

  4. (转)linux查看CPU性能及工作状态的指令mpstat,vmstat,iostat,sar,top

    衡量CPU性能的指标: 1,用户使用CPU的情况:CPU运行常规用户进程CPU运行niced processCPU运行实时进程 2,系统使用CPU情况:用于I/O管理:中断和驱动用于内存管理:页面交换 ...

  5. Linux系统与性能监控

    原文地址:http://kerrigan.sinaapp.com/post-7.html Linux System and Performance Monitoring http://www.hous ...

  6. Linux系统网络性能实例分析

    由于TCP/IP是使用最普遍的Internet协议,下面只集中讨论TCP/IP 栈和以太网(Ethernet).术语 LinuxTCP/IP栈和 Linux网络栈可互换使用,因为 TCP/IP栈是 L ...

  7. 性能测试 基于Python结合InfluxDB及Grafana图表实时采集Linux多主机性能数据

    基于Python结合InfluxDB及Grafana图表实时采集Linux多主机性能数据   by:授客 QQ:1033553122 实现功能 测试环境 环境搭建 使用前提 使用方法 运行程序 效果展 ...

  8. linux查看CPU性能及工作状态的指令mpstat,vmstat,iostat,sar,top

    转载:http://www.cnblogs.com/xianghang123/archive/2011/08/25/2153591.html 衡量CPU性能的指标: 1,用户使用CPU的情况:CPU运 ...

  9. 通过/proc/sys/net/ipv4/优化Linux下网络性能

    通过/proc/sys/net/ipv4/优化Linux下网络性能 /proc/sys/net/ipv4/优化1)      /proc/sys/net/ipv4/ip_forward该文件表示是否打 ...

随机推荐

  1. 基于jquery扩展漂亮的CheckBox

    大家都知道默认的html复选框控件样式可定义相当有限,无法满足大多用户的美观度.今天跟大家一起分享前一段时间自己编写的CheckBox控件.喜欢的朋友可以拿去使用,有什么好的建议希望你给我留言.废话不 ...

  2. neo4j中索引的使用

    neo4j可以对node和relationship中的属性建立索引,索引中的node(relationship)和属性对key-value为多对多的关系.一个node(relationship)可以在 ...

  3. [I/O]javaI/O工作机制

    摘要:IO问题可以说是当今web应用中面临的主要问题之一.因为在这个数据爆发的时代,海量的数据在网络到处流动,而在这个过程中都会涉及IO问题,可以说IO问题已经成为web应用的瓶颈之一.如何优化?以此 ...

  4. Shiro切入Spring的方式

    在springMVC中要使用shiro,一般都遵循下面的配置: applicationContext-shiro.xml <bean id="shiroFilter" cla ...

  5. Windows下Wireshark安装版本选择方式

    Windows下Wireshark安装版本选择方式   Wireshark版本分为1.X系列和2.X系列.1.X系列是早期版本,不提供中文版本.2.X系列是新版本,安装后,同时提供中文版和英文版.根据 ...

  6. Number lengths FZU - 1050

    N! (N factorial) can be quite irritating and difficult to compute for large values of N. So instead ...

  7. Selenium快速入门(上)

    浏览器驱动下载 Edge浏览器 Firefox浏览器 Safari浏览器 Chrome浏览器 PhantomJS浏览器 下载完成之后,添加到环境变量. 声明浏览器对象 selenium支持的浏览器版本 ...

  8. FFTW3学习笔记1:VS2015下配置FFTW3(快速傅里叶变换)库

    一.FFTW简介 FFTW ( the Faster Fourier Transform in the West) 是一个快速计算离散傅里叶变换的标准C语言程序集,其由MIT的M.Frigo 和S. ...

  9. [NC13B]贝伦卡斯泰露/[51Nod1400]序列分解

    [NC13B]贝伦卡斯泰露/[51Nod1400]序列分解 题目大意: 给定\(A_{1\sim n}(n\le40)\),问是否能将\(A\)分解成两个相同的子序列? 思路: 折半搜索.时间复杂度\ ...

  10. 两个矩阵相加 Exercise08_05

    import java.util.Scanner; /** * @author 冰樱梦 * 时间:2018年12月 * 题目:两个矩阵相加 * */ public class Exercise08_0 ...