标签:aws 监控脚本
在centos上使用aws硬盘和内存监控脚本,会发现脚本出错,无法正常工作,这是因为aws的官方文档中提到脚本没有在centos上做过测试,并不能保证脚本能使用 如何解决呢,需要安装以下软件:
yum install -y perl-CPAN exportPERL_MM_USE_DEFAULT=1 # setup defaultconfig perl -MCPAN -e shell #进入MCPAN Shell,自动生成默认配置,并退出 # 类似于yum,下载安装各种包,需要花点时间 perl -MCPAN -e‘CPAN::Shell->rematein("notest", "install","Bundle::CPAN")‘ perl -MCPAN -e‘CPAN::Shell->rematein("notest", "install","CPAN")‘ perl -MCPAN -e‘CPAN::Shell->rematein("notest", "install","Bundle::LWP")‘ perl -MCPAN -e ‘CPAN::Shell->rematein("notest","install", "LWP")‘ perl -MCPAN -e‘CPAN::Shell->rematein("notest", "install","LWP::Protocol::https")‘ perl -MCPAN -e‘CPAN::Shell->rematein("notest", "install","Crypt::SSLeay")‘ perl -MCPAN -e‘CPAN::Shell->rematein("notest", "install","Switch")‘
安装完成后,可能仍然会出现问题:
Can‘t locate object method "new" via package "LWP::Protocol::https::Socket"
需要再次安装:
cpan> install Net::HTTPS install Net::SSL install IO::Socket::SSL
但是仍然报错:
[root@serveraws-scripts-mon1]# perl mon-put-instance-data.pl --mem-util ERROR: Failed tocall CloudWatch: HTTP 500. Message: Can‘t connect to monitoring.us-east-1.amazonaws.com:443 (Crypt-SSLeay can‘t verify hostnames) Net::SSL fromCrypt-SSLeay can‘t verify hostnames; either install IO::Socket::SSL or turn offverification by setting the PERL_LWP_SSL_VERIFY_HOSTNAME environment variableto 0 at /usr/local/share/perl5/LWP/Protocol/http.pm line 46.
提示IO::Socket::SSL没安装,但确实是安装了;不过,根据错误提示可以设置环境变量
[root@pa01aws-scripts-mon]# export PERL_LWP_SSL_VERIFY_HOSTNAME=0 [root@pa01aws-scripts-mon]# perl mon-put-instance-data.pl --mem-util Successfullyreported metrics to CloudWatch. Reference Id:cab2a044-1515-11e7-9631-9fb8068ec2cc
再次执行就成功了;但是,监控脚本一般是放在crontab中执行的,因此crontab还需要加入环境变量
*/5 * * * * export PERL_LWP_SSL_VERIFY_HOSTNAME=0 && perl /opt/alarm/aws-scripts-mon/mon-put-instance-data.pl --mem-util--mem-avail --mem-used --swap-used --swap-util
标签:aws 监控脚本
原文地址:http://3379770.blog.51cto.com/3369770/1912099