[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 #!/usr/bin/perl 2 use POSIX; 3 4 #======================================================== 5 # CPU Usage script for mrtg 6 # 7 # File: cpuload.pl 8 # Author: Chretien Jean-Luc | jeanluc.chretien@tice.ac-caen.fr 9 # Version: 1.0 10 # 11 # Date: 09/08/02 12 # Purpose: This script reports CPU usage for user 13 # and system to mrtg, along with uptime 14 # and the machine's hostname. 15 # 16 # Usage: ./cpuload.pl 17 # 18 # 19 # Info: Designed on Debian Woody 20 # 21 # 22 # [Note to User] 23 # 24 # If anyone has comments or suggestions, email me at 25 # jean-luc.chretien@tice.ac-caen.fr and I'll try to 26 # get back to you :) 27 # 28 # Modified by Bruno Bzeznik 2002/12/18: 29 # I prefer to use output from uptime, the second entry gives 30 # the average load of last 5 minutes, and it's more representative 31 # as we run mrtg every 5 minutes. 32 # ------------------------------------------------------------- 33 # 34 # Sample cfg: 35 # 36 # Target[machine]: `./cpuload.pl` 37 # MaxBytes[machine]: 1000 38 # YTicsFactor[agios]: 0.1 39 # Options[machine]: gauge, nopercent 40 # Unscaled[machine]: dwym 41 # YLegend[machine]: % of CPU used 42 # ShortLegend[machine]: % 43 # LegendO[machine]: CPU System: 44 # LegendI[machine]: CPU User: 45 # Title[machine]: Machine name 46 # PageTop[machine]: <H1>CPU usage for Machine name 47 # </H1> 48 # <TABLE> 49 # <TR><TD>System:</TD><TD>Machine name</TD></TR> 50 # </TABLE> 51 # 52 53 # Run commands 54 $getuptime = `/usr/bin/uptime`; 55 56 # Commented by Bruno Bzeznik 2002-12-18: 57 # $getcpu = `/usr/bin/top -b -n 1 | grep "CPU"`; 58 # @line = split /^/m,$getcpu; 59 # @getload = split /\s+/,$line[0]; 60 # $getload[2]=~ s/\%//; 61 # $getload[4]=~ s/\%//; 62 # $cpuuser = floor($getload[2]+0.5); 63 # $cpusys = floor($getload[4]+0.5); 64 65 # Edited by Bruno Bzeznik 2002-12-18: 66 67 @line = split (/load average: /,$getuptime); 68 @getload = split (/\s+/,$line[1]); 69 $cpuuser = $getload[1]*100; 70 $cpusys = $cpuuser; 71 72 # Print cpu data for mrtg 73 ### DEBUG ### 74 #print "user:".$cpuuser."reel:".$getload[2]."\n"; 75 #print "system:".$cpusys."reel:".$getload[4]."\n"; 76 ### FIN DEBUG ### 77 print $cpuuser."\n"; 78 print $cpusys."\n"; 79 80 # Parse though getuptime and get data 81 $getuptime =~ /^\s+(\d{1,2}:\d{2}..)\s+up\s+(\d+)\s+(\w+),/; 82 83 # Print getuptime data for mrtg 84 print $2." ".$3."\n"; 85 86 # Print machine name for mrtg 87 #print $machine."\n"; 88 exit (0);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |