perl实现监控linux
1、使用root用户telnet进入linux系统
2、修改DNS以下两种方法
A、通过setup命令配置dns
B、通过在/etc目录下创建resolv.conf文件
3、查看DNS是否配置成功
[root@BL360-25]# cat/etc/resolv.conf
nameserver 202.107.117.11
nameserver 202.107.117.12
1、使用root用户telnet进入linux系统
2、#提示符下,输入cpan
提示:Are you ready for manual configuration? [yes]
输入:no
进入cpan>状态
1、在cpan>提示下,输入o conf urllist push http://www.cpan.org/
2、在cpan>提示下,输入o conf urllist push ftp://ftp.cuhk.edu.hk/pub/packages/perl/CPAN/
3、执行过程中无任何输出后,在cpan>提示下,输入o conf commit,提示:commit: wrote /usr/lib/perl5/5.8.8/CPAN/Config.pm,表示成功
1、在cpan>提示下,输入o conf http_proxy http://proxy.neusoft.com:8080
2、在cpan>提示下,输入o conf proxy_user 用户名
3、在cpan>提示下,输入o conf proxy_pass 密码
4、执行过程中无任何输出后,在cpan>提示下,输入o conf commit,提示:commit: wrote /usr/lib/perl5/5.8.8/CPAN/Config.pm,表示成功
在cpan>提示下,输入install Sys::Statistics::Linux
Fetching with LWP:
http://www.cpan.org/authors/01mailrc.txt.gz
Going to read root/。。。。。。
UNIVERSAL::require
Shall I follow them and prepend them to the queue
of modules we are processing right now? [yes] yes
提示是否安装相关模块,请输入yes
All tests successful.
最后测试都通过表示安装成功
1、将linuxperfstat.tar包拷贝到linux系统,并解压出LinuxDiskStat.pm和linuxperfstat文件
2、设置可执行权限
chmod +x linuxperfstat
3、linuxperfstat -h - 打印帮助
具体使用方法请看readme.doc
more linuxperfstat
#!/usr/bin/perl -w
use strict;
use warnings;
use Sys::Statistics::Linux;
use Data::Dumper;
use LinuxDiskStat;
my $loop = 0; # current loop number
my $PAGESIZE = 20; # max lines per header
my $lines = $PAGESIZE; # counter for lines printed
#
# Process command line args
#
usage() if defined $ARGV[0] and $ARGV[0] =~ /^(-h|--help|0)$/;
# process [interval [count]],
my ($interval, $loop_max);
if (defined $ARGV[0]) {
$interval = $ARGV[0];
$loop_max = defined $ARGV[1] ? $ARGV[1] : 2**32;
usage() if $interval == 0;
}
else {
$interval = 1;
$loop_max = 1;
}
sub sim_show
{
my ($rh_siminfo) = @_;
my $str = "";
foreach (sort(keys(%$rh_siminfo)))
{
$str .= "$_: $rh_siminfo->{$_}\n";
}
return $str;
}
my $lxs = Sys::Statistics::Linux->new(
cpustats => {
init => 1,
},
diskstats => {
init => 1,
},
netstats => {
init => 1,
},
memstats => {
init => 1,
},
);
my $lxs_diskstat = LinuxDiskStat->new;
$lxs_diskstat->init;
my $NIC_SPEED = 100_000_000;
while (1) {
### Print header
if ($lines++ >= $PAGESIZE) {
$lines = 0;
printf "%-20s %28s\n", "", "------ Utilisation ------";
printf "%-20s %7s %6s %6s %6s\n", "Time", "%CPU",
"%Mem", "%Disk", "%Net";
}
my $stat = $lxs->get;
my $time = $lxs->gettime;
my $disk_stat = $lxs_diskstat->get;
#
# Calculate utilisation
#
my $ucpu = fetch_cpu($stat);
my $umem = fetch_mem($stat);
my $udisk = fetch_disk($disk_stat);
my $unet = fetch_net($stat);
printf "%-20s %7s %6s %6s %6s\n",$time, $ucpu, $umem, $udisk, $unet;
### Check for end
last if ++$loop == $loop_max;
### Interval
sleep $interval;
}
sub fetch_cpu
{
my ($rh_stat) = @_;
my $str_cpu = "";
if(defined($rh_stat->cpustats->{cpu}->{total}))
{
$str_cpu = $rh_stat->cpustats->{cpu}->{total};
$str_cpu = sprintf "%.2f", $str_cpu;
}
return $str_cpu;
}
sub fetch_mem
{
my ($rh_stat) = @_;
my $str_mem = "";
if(defined($rh_stat->memstats))
{
$str_mem = 100-$rh_stat->memstats->{memfree}/$rh_stat->memstats->{memtotal}*100;
$str_mem = sprintf "%.2f", $str_mem;
}
return $str_mem;
}
sub fetch_disk
{
my ($rh_stat) = @_;
my $str_disk = "";
if(defined($rh_stat->{hda}->{ticks}))
{
$str_disk = $rh_stat->{hda}->{ticks}/10;
$str_disk = sprintf "%.2f", $str_disk;
}
elsif(defined($rh_stat->{sda}->{ticks}))
{
$str_disk = $rh_stat->{sda}->{ticks}/10;
$str_disk = sprintf "%.2f", $str_disk;
}
elsif(defined($rh_stat->{xvdb1}->{ticks}))
{
$str_disk = $rh_stat->{xvdb1}->{ticks}/10;
$str_disk = sprintf "%.2f", $str_disk;
}
return $str_disk;
}
sub fetch_net
{
my ($rh_stat) = @_;
my $str_net = "";
if(defined($rh_stat->netstats->{eth0}->{ttbyt}))
{
$str_net = ($rh_stat->netstats->{eth0}->{ttbyt}*800)/$NIC_SPEED;
$str_net = sprintf "%.2f", $str_net;
}
return $str_net;
}
# usage - print usage and exit.
#
sub usage {
print STDERR <<END;
USAGE: linuxperfstat [-h] | [interval [count]]
eg, linuxperfstat # print summary since boot only
linuxperfstat 5 # print continually every 5 seconds
linuxperfstat 1 5 # print 5 times, every 1 second
END
exit 1;
}
perl实现监控linux的更多相关文章
- Zabbix监控Linux主机设置
说明: Zabbix监控服务端已经配置完成,现在要使用Zabbix对Linux主机进行监控. 具体操作: 以下操作在被监控的Linux主机进行,这里以CentOS 6.x系统为例. 一.配 ...
- 监控Linux系统性能的工具--nmon(一)
今天看到一资料上写着,nmon可以对linux系统进行性能监控,随手在自己的阿里云上敲了一下这个命令,提示'command not find' 一脸懵~,然后探索了一下如何安装这个工具以及如何更好的查 ...
- Loadrunner监控Linux系统资源
一.安装rsh和rpcbind 1.查看是否安装:rpm -qa |grep rsh 2.安装rsh:yum -y install rsh* 3.yum -y install nfs-utils r ...
- loadrunner监控linux服务器
参考http://www.cnblogs.com/yangxia-test/archive/2012/11/27/2790771.html http://www.cnblogs.com/candle8 ...
- 转载:JProfiler远程监控LINUX上的Tomcat过程细讲
来源于xuwanbest的博客 所谓"工欲善其事,必先利其器",好的工具确能起到事半工倍的作用.我用到的最多的就两个JConsole 和JProfiler .JConsole监 ...
- 20个命令行工具监控Linux系统性能
作为Linux/Unix 系统管理员需要掌握一些常用的工具用于检测系统性能.在这里,dodo为大家推荐非常20个有用的并且最常用的命令行系统监视工具: 1. top -Linux系统进程监控 top ...
- LoadRunner监控Linux
rstat协议允许网络上的用户获得同一网络上各机器的性能参数. 需要下载3个包: (1)rsh-0.17-14.i386.rpm (2)rsh-server-0.17-14.i386.r ...
- LR通过snmp监控linux下的mysql
LR通过snmp监控linux下的mysql 在linux底下安装配置snmp: 1.使用系统盘安装rpm包(这种方式最好) 2.在www.net-snmp.org处下载net-snmp安装(安装后有 ...
- pv命令监控Linux命令的执行进度
pv命令监控Linux命令的执行进度 http://www.techweb.com.cn/network/system/2015-12-14/2241124.shtml yum install -y ...
随机推荐
- ArcGIS Runtime SDK for Android 各版本下载地址
ArcGIS Runtime SDK for Android各版本下载地址:ArcGIS Runtime SDK交流群:249819194 SDK包中主要包含以下内容: 其中里面比较重要的有以下几项: ...
- html5 chrome 摄像头 &&bootstrap
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- Tomcat启动报Error listenerStart错误 | "beans" 必须匹配 DOCTYPE 根 "null" | java.lang.reflect.MalformedParameterizedTypeException
maven打包发布工程时,发布上去却报错FAIL - Deployed application at context path /ch but context failed to start 在服务器 ...
- PyYAML使用
install yum -y install PyYAML document http://www.showyounger.com/show/101586.html http://pyyaml.org ...
- 初学React:定义一个组件
接着聊React,今天说说如何创建一个组件类. <!DOCTYPE html> <html lang="en"> <head> <meta ...
- jmter安装配置
一 JMeter 简介 JMeter 它是Apache组织的开放源代码项目,它是现在比较流行的功能和性能测试的工具.JMeter requires a fully compliant JVM 7 or ...
- 检测浏览器中是否有Flash插件
由于IE和非IE浏览器检测方式不同,所以代码如下 function hasPlugin(name){ debugger; name = name.toLowerCase(); for(var i=0; ...
- 【转】Android tools:context
tools:context="com.example.guolin.scrollertest.MainActivity" 有时候可以看到有这个东西,但是从来没有用过,不知道有什么作 ...
- Spring注解@Value数值取值转换字符串失败
配置文件(yml)中,配置项如下: cebconfig: INST_CODE: 08801001 SFT_NOTIFY_CEB_CHANNEL: 123456 期望INST_CODE: 0880100 ...
- 接口是否可继承接口? 抽象类是否可实现(implements)接口? 抽象类是否可继承实体类(concrete class)?
接口是否可继承接口? 抽象类是否可实现(implements)接口? 抽象类是否可继承实体类(concrete class)? 答:接口可以继承接口.抽象类可以实现(implements)接口,抽象类 ...