system resource monitor

本文介绍了一个使用Perl编写的系统监控脚本,该脚本能够监控CPU、内存、I/O状态等,并将数据记录到文件中。同时提供了分析脚本及绘图脚本,用于展示监控数据的趋势。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

monitor.pl

#!/usr/bin/perl ###monintor start#### if($ARGV[0] eq "start"){     print "monitor start!/nwe are monitoring cpu,memory,iostat,prstat!/n";     $flag=1;     while($flag==1){     $fname = `date +%F`;     $fname=~ s//-//g;     chomp($fname);     $cpufile=cpu."$fname";     `touch $cpufile`;     $time = `date "+%Y%m%d %H:%M:%S"`;     open(FILE,">>$cpufile");     $cpu=`sar 2 1|tail -1`;     printf FILE ("%s%s/n",$cpu);     $iostatfile=iostat."$fname";         `touch $iostatfile`;         open(FILE,">>$iostatfile");     print FILE ("$time");     $io=`iostat -xnzD 2 2 |tail -1 `;     printf FILE ("%s/n",$io);     $topfile=top."$fname";         `touch $iostatfile`;         open(FILE,">>$topfile");     print FILE ("$time");     $w=`w|awk '{print $10}' | head -1`;     $vmstat=`vmstat  2 2| tail -1 `;     printf FILE ("%s%s/n",$w,$vmstat);     $prstatfile=prstat."$fname";

    `touch $prstatfile`;         open(FILE,">>$prstatfile");         print FILE ("$time");     $prstat=`prstat -a 1 1`;     printf FILE ("%s%s/n",$prstat);     sleep 5;     } } #####monitor stop############ elsif($ARGV[0] eq "stop"){     `ps -ef |grep "perl monitor.pl start" > plist`;     open(KEY,"plist");     while(<KEY>){         ($aa,$pid) = split(" ",$_);     #   print $pid;         kill (9,$pid);     }

} #################### else{     print "if you want to start monitor script, please input start!/n";     print "if you want to stop monitor script, please input stop!/n"; }

 

memory.sh

#!/usr/bin/env bash sed -f parse_top.sed top20080524 |awk '{printf("%s/t%f/t%s/n", $2, $19/83886.08, $19)}' > memory.log

 

mem.plt

set xlabel 'x-time' set ylabel 'y-%' set mxtics 1 set title "free memory ratio analysis (total: 8192M)" set key top left set key box set term post eps color solid enh set output 'mem.eps' set xdata time #set timefmt "%H:%M:%S" set timefmt "%Y%m%d-%H:%M:%S" #set format x "%H:%M" set format x "%H:%M" plot  'memory_monitor.log' using 1:2 title "mem" with lines linecolor rgb "red"

 

cpu.plt

set xlabel 'x-time' set ylabel 'y-%' set mxtics 1 set title "cpu data analysis" set key top left set key box set term post eps color solid enh set output 'cpu.eps' set xdata time set timefmt "%H:%M:%S" set format x "%H:%M" plot  'cpu' using 1:2 title "usr" with lines linecolor rgb "yellow", 'cpu' using 1:3 title "sys" wit h line linecolor rgb "red" , 'cpu' using 1:4 title "wio" with line linecolor rgb "blue", 'cpu' using  1:5 title "idle" with line linecolor rgb "green"

 

cpu.pl

#!/usr/bin/perl

################define parameters################### open(FILE,$ARGV[0]); open(RES,">cpu");

##############main ############################################ @cpu = grep{!/^/n/}  <FILE>; foreach $cpu(@cpu) {     $cpu =~ tr/ //t/s;     ($date,$us,$sy,$wio,$id) = split(//t/,$cpu);     push(@us,$us);     push(@sy,$sy);     push(@wio,$wio);     push(@id,$id);     print RES $cpu; }

print "us/tmax:".get_max(@us)."/n"; print "us/tmin:".get_min(@us)."/n"; print "us/taverage:".get_average(@us)."/n";

print "sy/tmax:".get_max(@sy)."/n"; print "sy/tmin:".get_min(@sy)."/n"; print "sy/taverage:".get_average(@sy)."/n";

print "wio/tmax:".get_max(@wio)."/n";

print "wio/tmin:".get_min(@wio)."/n"; print "wio/taverage:".get_average(@wio)."/n";

print "id/tmax:".get_max(@id); print "id/tmin:".get_min(@id); print "id/taverage:".get_average(@id); print "/n########################/n"; print "Do you want to paint image? if yes, please input /"y/", else input /"n/""; $flag = <STDIN>; chomp($flag); if ($flag eq "y"){     `gnuplot cpu.plt`; }

#######get max ################ sub get_max {     my $max ;     $max = shift(@_) ;     foreach $_(@_)     {         if ($max<$_)         {             $max=$_;         }     }     return $max ; }

#############get min################### sub get_min {     my $min ;     $min = shift(@_);     foreach $_(@_)     {         if ($min>$_)         {             $min = $_;         }     }     return $min; }

###############get average######################## sub get_average {     my $total; #   my $average = shift(@_);     foreach $_ (@_)     {         $total = $total + $_ ;     }     $average = $total/($#_+1) ;     return $average;

}

 

gen_graph.sh

#!/usr/bin/env bash

top_file_name="top20080618" total_mem_size="8388608" /export/home/deric/shell/get_mem.awk  $top_file_name | awk '{printf("%s-%s %s %s/n", $1, $2, $7/83886.08, $7)}' > memory_monitor.log gnuplot mem.plt gnuplot cpu.plt

 

get_mem.awk

#!/usr/bin/awk -f

BEGIN {     FS="/n"     RS="" } {     printf("%s %s/n", $1,$3) }

### SOLIDWORKS Resource Monitor 弹窗及系统内存低的解决方案 对于频繁出现的 SOLIDWORKS Resource Monitor 弹窗问题,存在多种处理办法。一种临时性的措施是在当前会话期间停止弹窗提醒,具体操作为打开任务管理器定位到 SOLIDWORKS 应用程序下的 SOLIDWORKS Resource Monitor 并终止其进程[^1]。 然而,针对更深层次的问题——即系统报告可用内存过少的情况,则可能涉及到了软件本身存在的缺陷或是配置不当所致。有反馈指出 Solidworks 2024 版本相较于以往版本更加频发此类警告消息,即便实际物理内存充裕也不例外,这暗示着可能是由于该版本内部逻辑上的漏洞所引起[^2]。 为了从根本上解决问题,除了考虑升级硬件增加实体RAM外,还可以尝试调整操作系统层面的一些设置: - **增大页面文件大小**:适当提高虚拟内存上限有助于缓解因物理内存不足引发的应用崩溃风险; - **修改注册表键值**:编辑特定路径下的 Windows 注册表条目也可能有效减少错误发生频率。需要注意的是,在更改之前一定要做好备份以防万一出现问题时能迅速恢复原状。涉及到的关键位置有两个分支分别是 `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows` 和 `HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\Windows`。 另外值得注意的一点是,虽然上述建议可以在一定程度上改善状况,但如果目标是为了彻底消除这类干扰信息而不影响正常功能的话,或许还需要等待官方发布补丁或者后续改进版本来修正潜在 bug。 ```powershell # 修改页面文件大小示例脚本 (PowerShell) $computerName = "localhost" $pageFilePath = "C:\pagefile.sys" Set-WmiInstance -Class Win32_ComputerSystem -ComputerName $computerName -Arguments @{AutomaticManagedPagefile="False"} Set-CimInstance -Query ("SELECT * FROM Win32_PageFileSetting WHERE Name='" + $pageFilePath + "'") -Property @{InitialSize=8192; MaximumSize=16384} ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值