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的更多相关文章

  1. Zabbix监控Linux主机设置

          说明: Zabbix监控服务端已经配置完成,现在要使用Zabbix对Linux主机进行监控. 具体操作: 以下操作在被监控的Linux主机进行,这里以CentOS 6.x系统为例. 一.配 ...

  2. 监控Linux系统性能的工具--nmon(一)

    今天看到一资料上写着,nmon可以对linux系统进行性能监控,随手在自己的阿里云上敲了一下这个命令,提示'command not find' 一脸懵~,然后探索了一下如何安装这个工具以及如何更好的查 ...

  3. Loadrunner监控Linux系统资源

    一.安装rsh和rpcbind 1.查看是否安装:rpm -qa |grep rsh 2.安装rsh:yum -y install rsh* 3.yum  -y install nfs-utils r ...

  4. loadrunner监控linux服务器

    参考http://www.cnblogs.com/yangxia-test/archive/2012/11/27/2790771.html http://www.cnblogs.com/candle8 ...

  5. 转载:JProfiler远程监控LINUX上的Tomcat过程细讲

    来源于xuwanbest的博客   所谓"工欲善其事,必先利其器",好的工具确能起到事半工倍的作用.我用到的最多的就两个JConsole 和JProfiler .JConsole监 ...

  6. 20个命令行工具监控Linux系统性能

    作为Linux/Unix 系统管理员需要掌握一些常用的工具用于检测系统性能.在这里,dodo为大家推荐非常20个有用的并且最常用的命令行系统监视工具: 1. top -Linux系统进程监控 top ...

  7. LoadRunner监控Linux

    rstat协议允许网络上的用户获得同一网络上各机器的性能参数. 需要下载3个包:    (1)rsh-0.17-14.i386.rpm     (2)rsh-server-0.17-14.i386.r ...

  8. LR通过snmp监控linux下的mysql

    LR通过snmp监控linux下的mysql 在linux底下安装配置snmp: 1.使用系统盘安装rpm包(这种方式最好) 2.在www.net-snmp.org处下载net-snmp安装(安装后有 ...

  9. pv命令监控Linux命令的执行进度

    pv命令监控Linux命令的执行进度 http://www.techweb.com.cn/network/system/2015-12-14/2241124.shtml yum install -y ...

随机推荐

  1. css3 走马灯效果

    纯css3实现了一个正六边形的走马灯效果,记录一下css3动画的学习情况,效果如下: 主要用到的css3技术有:keyframes.perspective.perspective-origin.tra ...

  2. python 生成随机图片验证码

    1.安装pillow模块 pip install pillow (1)创建图片 from PIL import Image #定义使用Image类实例化一个长为400px,宽为400px,基于RGB的 ...

  3. php 调用微信虚拟支付

    摘要:小游戏对接微信虚拟支付,需要自己的后台调用微信的虚拟支付接口,微信的文档实在烂,总结走过的坑. 1.报错{errcode:90007,errmsg:invalid openid} 无效的open ...

  4. eclipse 上使用tomcat 启动项目,项目目录下无.class 文件

    摘要:在使用eclipse 启动taomcat时,项目报错,但将项目打成war包单独部署到tomcat时,则项目正常,通过对比两次部署文件发现,从eclipse直接启动tomcat时,部署到tomca ...

  5. .net core 操作域控 活动目录 ladp -- Support for System.DirectoryServices for Windows

    原文链接:https://github.com/dotnet/corefx/issues/2089 1. @ianhays to kick start the project in CoreFX re ...

  6. C语言总结的知识点

    什么是有效数字? ------------------------- 数据类型 运算符: 函数: 程序结构: 存储结构 内存管理 关键字: ------------------------- C语言: ...

  7. 【HHHOJ】ZJOI2019模拟赛(十四)03.12 解题报告

    点此进入比赛 得分: \(50+5+24=79\) 排名: \(Rank\ 2\) \(Rating\):\(+79\) \(T1\):[HHHOJ197]古明地(点此看题面) 基本上全部时间都用来想 ...

  8. 问题 B: C++习题 对象数组输入与输出

    题目描述 建立一个对象数组,内放n(n<10)个学生的数据(学号.成绩),用指针指向数组首元素,输出第奇数(1,3,5,7)个学生的数据. 输入 n和n个学生的学号.成绩 输出 奇数学生的数据 ...

  9. xml中${}的使用含义(美元符号大括号,以Spring、ibatis、mybatis为例)

    项目中,经常会在xml中看到这样的写法: <properties resource="properties/database.properties"/> <dat ...

  10. C# continue语句

    一.C# continue语句 continue语句在循环体中结束本次循环,而重新开始下一次循环. 语法格式如下: continue;二.示例   using System;using System. ...