亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
12下一頁(yè)
最近訪問(wèn)板塊 發(fā)新帖
查看: 5812 | 回復(fù): 15
打印 上一主題 下一主題

請(qǐng)教高手能不能給我解釋一下這個(gè)腳本 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2013-10-09 15:22 |只看該作者 |倒序?yàn)g覽
本帖最后由 Iinvincible 于 2013-10-09 15:26 編輯

root@root$ vmstat 2 3
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
2  0 213728  87600 1183808 849440    0    0    86    85    2    0  3  3 92  2  0
0  0 213728  88864 1183808 849460    0    0     0     0 1022  372  5  3 93  0  0
0  0 213728  88740 1183808 849472    0    0     0     2 1014  285  0  0 100  0  0



use strict;
use RRD::Simple;

my $cmd = "/usr/bin/vmstat 2 3";
my $rrdfile = "vmstat-cpu.rrd";
my $rrd = RRD::Simple->new( file => $rrdfile );

my @keys = ();
my %update = ();
open(PH,"-|",$cmd) or die qq{Unable to open file handle PH for command "$cmd": $!};
while (local $_ = <PH>) {
     next if /---/;
     s/^\s+|\s+$//g;
     if (/\d+/ && @keys) {
         @update{@keys} = split(/\s+/,$_);
     } else { @keys = split(/\s+/,$_); }
}

close(PH) or die qq{Unable to close file handle PH for command "$cmd": $!};

my @cpukeys = splice(@keys,-4,4);
my %labels = (wa => "IO wait", id => "Idle", sy => "System", us => "User");

$rrd->create(map { ($_ => "GAUGE") } @cpukeys) unless -f $rrdfile;
$rrd->update(map { ($_ => $update{$_}) } @cpukeys);

我知道這個(gè)腳本大概就是去vmstat cpu部分的數(shù)據(jù)然后畫圖,但是看不懂加粗的部分,尤其是紅色的部分。請(qǐng)高手幫我講解一下。謝謝啦!

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2013-10-09 16:55 |只看該作者
@update{@keys}   ??

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2013-10-09 17:26 |只看該作者
回復(fù) 2# w123456_cu


    是的,   
if (/\d+/ && @keys) {
         @update{@keys} = split(/\s+/,$_);
     } else { @keys = split(/\s+/,$_); }

論壇徽章:
6
丑牛
日期:2014-03-21 15:42:04子鼠
日期:2014-04-12 11:50:17處女座
日期:2014-09-01 09:25:1115-16賽季CBA聯(lián)賽之吉林
日期:2015-12-22 14:01:5215-16賽季CBA聯(lián)賽之廣東
日期:2016-03-08 18:49:422016科比退役紀(jì)念章
日期:2016-07-06 12:19:55
4 [報(bào)告]
發(fā)表于 2013-10-09 21:49 |只看該作者
本帖最后由 stanley_tam 于 2013-10-09 21:49 編輯
  1. @update{@keys}是hash切片,跟數(shù)組切片類似,如@array[0 .. $index]

  2. 建議你用Data::Dumper模塊把數(shù)據(jù)打印出來(lái),就一目了然了,如

  3. use strict;
  4. # use RRD::Simple;

  5. use Data::Dumper;


  6. my $cmd = "/usr/bin/vmstat 2 3";
  7. # my $rrdfile = "vmstat-cpu.rrd";
  8. # my $rrd = RRD::Simple->new( file => $rrdfile );

  9. my @keys = ();
  10. my %update = ();
  11. open(PH,"-|",$cmd) or die qq{Unable to open file handle PH for command "$cmd": $!};
  12. while (local $_ = <PH>) {
  13.      next if /---/;
  14.      s/^\s+|\s+$//g;
  15.      if (/\d+/ && @keys) {
  16.          @update{@keys} = split(/\s+/,$_);
  17.      } else { @keys = split(/\s+/,$_); }
  18. }
  19. close(PH) or die qq{Unable to close file handle PH for command "$cmd": $!};

  20. my @cpukeys = splice(@keys,-4,4);

  21. print Dumper \@keys;
  22. print Dumper \%update;
  23. print Dumper \@cpukeys;

  24. __END__

  25. my %labels = (wa => "IO wait", id => "Idle", sy => "System", us => "User");

  26. $rrd->create(map { ($_ => "GAUGE") } @cpukeys) unless -f $rrdfile;
  27. $rrd->update(map { ($_ => $update{$_}) } @cpukeys);
復(fù)制代碼
回復(fù) 1# Iinvincible


   

論壇徽章:
8
技術(shù)圖書徽章
日期:2013-09-30 08:51:28技術(shù)圖書徽章
日期:2013-12-11 09:26:39白羊座
日期:2013-12-27 15:27:13金牛座
日期:2014-01-06 09:13:05天蝎座
日期:2014-01-21 14:23:28酉雞
日期:2014-05-09 16:51:12卯兔
日期:2014-08-11 16:49:1515-16賽季CBA聯(lián)賽之八一
日期:2017-08-14 23:24:57
5 [報(bào)告]
發(fā)表于 2013-10-09 22:25 |只看該作者
這個(gè)就是哈希切片的用法回復(fù) 3# Iinvincible


   

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2013-10-10 10:09 |只看該作者
For example, consider the bowling scores set individually:
  1. $score{"fred"} = 205;
  2. $score{"barney"} = 195;
  3. $score{"dino"} = 30;
復(fù)制代碼
This seems rather redundant, and in fact can be shortened to:
  1. ($score{"fred"},$score{"barney"},$score{"dino"}) =
  2.     (205,195,30);
復(fù)制代碼
But even these seems redundant. Let's use a hash slice :
  1. @score{"fred","barney","dino"} = (205,195,30);
復(fù)制代碼
There. Much shorter. We can use a hash slice with variable interpolation as well:
  1. @players = qw(fred barney dino);
  2. print "scores are: @score{@players}\n";
復(fù)制代碼

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2013-10-10 16:23 |只看該作者
回復(fù) 6# w123456_cu

多謝!通過(guò)列子看起來(lái)容易些了。

但是這段腳本:
@players = qw(fred barney dino);
print "scores are: @score{@players}\n";

運(yùn)行后打印結(jié)果為:

score are:
沒打印出來(lái)啊


   

論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2013-10-10 16:30 |只看該作者
本帖最后由 Iinvincible 于 2013-10-10 16:32 編輯

回復(fù) 4# stanley_tam


    多謝啊!明白點(diǎn)了,又學(xué)了一招!

但我不明白 if (/\d+/ && @keys) 這是什么意思。d+代表匹配數(shù)字,@key是什么意思呢?

論壇徽章:
5
丑牛
日期:2014-01-21 08:26:26卯兔
日期:2014-03-11 06:37:43天秤座
日期:2014-03-25 08:52:52寅虎
日期:2014-04-19 11:39:48午馬
日期:2014-08-06 03:56:58
9 [報(bào)告]
發(fā)表于 2013-10-10 16:35 |只看該作者
強(qiáng)!4,6 樓 很贊啊

論壇徽章:
5
丑牛
日期:2014-01-21 08:26:26卯兔
日期:2014-03-11 06:37:43天秤座
日期:2014-03-25 08:52:52寅虎
日期:2014-04-19 11:39:48午馬
日期:2014-08-06 03:56:58
10 [報(bào)告]
發(fā)表于 2013-10-10 16:50 |只看該作者
請(qǐng)高手幫我講解一下。
  1. while (local $_ = <PH>) {
復(fù)制代碼
  1. while (<PH>) {
復(fù)制代碼
謝謝啦!@stanley_tam@w123456_cu
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP