用机器生成的音乐监控Linux 计算机
http://tech.ddvip.com 2007年02月28日 社区交流
本文详细介绍用机器生成的音乐监控Linux 计算机
在脚本的开头,我们选择vmstat 1作为要被执行的命令并且每秒读取一次。为各次读取之间记录的信息包总数设置一个变量并记录从 vmstat 程序中读取到的行数,接下来定义标题。每秒都会从 vmstat 程序中读取字段标题bi(磁盘块入)、bo(磁盘块出)和us(用户 CPU 使用量)。字段散列允许稍后在程序中按名称引用这些数据字段。请注意$|=1行。如果删除此行,您将会遇到一些难以诊断的行为;还需要为缓冲而头疼!
清单 3. 主程序开始# open the vmstat program to read from
open( INPIPE, "$vmStatCmd |" ) || die "can't read from vmstat";
# wait while the fluidsynth program opens
sleep(3);
while(my $statLine = <INPIPE> ){
# ignore the header display, and the fieldname display lines
if( $statLine !~ /----/ && $statLine !~ /swpd/ ){
# the first line of vmstat data is a recent average, ignore
if( $lineCount > 2 ){
代码的下一部分将通过 vmstat 命令创建一个管道,程序将在其中每秒读取一次数据。等待几秒待 FluidSynth 程序激活后,即可开始处理 vmstat 输出。输出的前三行将被忽略,因为它们分别包含分隔符、标题信息和最新的平均值。
清单 4. 主程序通知处理 # reset wavetable synthesis
if( $totalTime % 10 == 0 ){ print "reset
" }
$totalTime ++;
my $note = "";
my @currLine = split " ", $statLine;
# user cpu usage
$note = $currLine[ $fields{us} ];
sendNote( $note, 14, 12, 96 );
# conglomerate disk i/o fields to one stat
$note = $currLine[ $fields{bi} ] + $currLine[ $fields{bo} ];
if( $note > 1000 ){ $note = 1000; }
$note = $note/10;
sendNote( $note, 8, 12, 96 );
# network throughput on eth0
$note = getNetworkStats();
sendNote( $note, 5, 12, 84 );
}#if not first 3 lines to ignore
}#if not a header line
$lineCount++;
}#while reading the pipe
close(INPIPE);
作者:Nathan Harrington 责编:豆豆技术应用
- Linux/Unix 新闻
- Linux/Unix 入门
- Linux/Unix 命令
- Linux/Unix 安装
- Linux 嵌入式系统
- Linux/Unix 编程
- Linux/Unix 管理
- Linux/Unix 桌面
- Linux/Unix 内核
- Linux/Unix 软件
- SCO Unix
- NetBSD
- OpenBSD
- Redhat/Fedora Linux
- 手机
- Linux/Unix find 搜索命令
- Linux/Unix vi 命令
- Linux/Unix kde 桌面环境
- Linux/Unix GNOME 桌面环境
- Linux/Unix Make 命令
- Linux/Unix crontab 命令
- Linux/Unix ext3 文件系统
- Linux/Unix 文件系统详解
- Linux/Unix ADSL 拨号设置
- Linux/Unix GRUB 配置及应用
- Linux/Unix nfs配置
- Linux/Unix 硬件信息查看及管理
- Linux/Unix 优化
- Linux/Unix 交换分区Swap管理及应用
- Linux/Unix 用户管理
- Linux/Unix Ramdisk
- Linux/Unix 密码恢复管理
- Linux/Unix 文件删除恢复
- Linux/Unix fdisk分区
- Linux/Unix lvs负载均衡管理
- Linux/Unix root用户
- Linux/Unix 集群
- Linux/Unix 日志
- 更多Linux/Unix专题……