php 获得linux 机器的性能
<?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 机器的性能的更多相关文章
- linux 查看服务器性能常用命令
一.top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器 下面详细介绍它的使用方法.top是一个动态显示过程,即可以通过用户按键来 ...
- 【转载】Linux系统与性能监控
原文地址:http://kerrigan.sinaapp.com/post-7.html Linux System and Performance Monitoring http://www.hous ...
- linux查看CPU性能及工作状态的指令
http://www.aikaiyuan.com/9347.html http://blog.csdn.net/jk110333/article/details/8683478 http://www. ...
- (转)linux查看CPU性能及工作状态的指令mpstat,vmstat,iostat,sar,top
衡量CPU性能的指标: 1,用户使用CPU的情况:CPU运行常规用户进程CPU运行niced processCPU运行实时进程 2,系统使用CPU情况:用于I/O管理:中断和驱动用于内存管理:页面交换 ...
- Linux系统与性能监控
原文地址:http://kerrigan.sinaapp.com/post-7.html Linux System and Performance Monitoring http://www.hous ...
- Linux系统网络性能实例分析
由于TCP/IP是使用最普遍的Internet协议,下面只集中讨论TCP/IP 栈和以太网(Ethernet).术语 LinuxTCP/IP栈和 Linux网络栈可互换使用,因为 TCP/IP栈是 L ...
- 性能测试 基于Python结合InfluxDB及Grafana图表实时采集Linux多主机性能数据
基于Python结合InfluxDB及Grafana图表实时采集Linux多主机性能数据 by:授客 QQ:1033553122 实现功能 测试环境 环境搭建 使用前提 使用方法 运行程序 效果展 ...
- linux查看CPU性能及工作状态的指令mpstat,vmstat,iostat,sar,top
转载:http://www.cnblogs.com/xianghang123/archive/2011/08/25/2153591.html 衡量CPU性能的指标: 1,用户使用CPU的情况:CPU运 ...
- 通过/proc/sys/net/ipv4/优化Linux下网络性能
通过/proc/sys/net/ipv4/优化Linux下网络性能 /proc/sys/net/ipv4/优化1) /proc/sys/net/ipv4/ip_forward该文件表示是否打 ...
随机推荐
- 洛谷P2408 不同字串个数 [后缀数组]
题目传送门 不同字串个数 题目背景 因为NOI被虐傻了,蒟蒻的YJQ准备来学习一下字符串,于是它碰到了这样一道题: 题目描述 给你一个长为N的字符串,求不同的子串的个数 我们定义两个子串不同,当且仅当 ...
- 深入浅出Spring(三) AOP详解
上次的博文深入浅出Spring(二) IoC详解中,我为大家简单介绍了一下Spring框架核心内容中的IoC,接下来我们继续讲解另一个核心AOP(Aspect Oriented Programming ...
- Vue 2.0学习(二)数据绑定
Vue实例对象 创建一个vue应用很简单,通过构造函数Vue就能创建一个Vue的根实例: var app = new Vue({ el: '#app', data: { message: 'Hello ...
- Hibernate 单项一对多的关联映射
在上一篇中我们简单介绍了多对一的关联映射,本文介绍hibernate中一对多的关联映射. 1.设计表结构 虽然关联关系由多对一变为一对多,但是我们表结构不会发生改变,只是指向变了. 2.创建stude ...
- android studio 可以汉化的 文件 地方
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 汉化包 百度云盘 下载地址:https://pan.baidu.com/s/1pLjwy ...
- [NOI2015]寿司晚宴 --- 状压DP
[NOI2015]寿司晚宴 题目描述 为了庆祝NOI的成功开幕,主办方为大家准备了一场寿司晚宴. 小G和小W作为参加NOI的选手,也被邀请参加了寿司晚宴. 在晚宴上,主办方为大家提供了n−1种不同的寿 ...
- java--由一道选择题研究数值越界
原题来自牛客网的java专项练习: 以下是代码. public class Test2 { public static void add(Byte b) { b=b++; } public stati ...
- bzoj 3172
收获:AC自动机定数组大小时,如果不确定,就定10^6(极限了) /************************************************************** Pro ...
- 2015 UESTC 搜索专题A题 王之迷宫 三维bfs
A - 王之迷宫 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Des ...
- ADC Power Supplies
http://www.planetanalog.com/author.asp?section_id=3041&doc_id=563055 Jonathan Harris, Product Ap ...