- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
COLORFUL /PROC REPORTING in Font
CHAPTER 35 COLORFUL /PROC REPORTING ECC200 Generator In None Using Barcode generation for Font Control to generate, create ECC200 image in Font applications. www.OnBarcode.comDrawing GS1 - 13 In None Using Barcode generator for Font Control to generate, create EAN13 image in Font applications. www.OnBarcode.comecho -e "OS Type: $white$ostype$normal Kernel:\ $white$osrelease$normal" echo -e " Kernel Compile $white$rev$normal on\ $white$da_date$normal" echo -e "Uptime: $magenta$uptime$normal days" Create PDF-417 2d Barcode In None Using Barcode encoder for Font Control to generate, create PDF-417 2d barcode image in Font applications. www.OnBarcode.comPrint GS1 - 12 In None Using Barcode drawer for Font Control to generate, create UPC Symbol image in Font applications. www.OnBarcode.comThese lines gather system memory and swap information and calculate the proportion of these system resources currently used by the running processes. One interesting bit is the use of the set command; it uses the result of greping through /proc/meminfo to assign values to positional parameters. This is a convenient way of assigning each item in a spaceseparated sequence of items to its own variable. Generate Code-39 In None Using Barcode encoder for Font Control to generate, create Code 39 Extended image in Font applications. www.OnBarcode.comGenerate Data Matrix In None Using Barcode generator for Font Control to generate, create ECC200 image in Font applications. www.OnBarcode.comset `grep MemTotal /proc/meminfo` tot_mem=$2 ; tot_mem_unit=$3 set `grep MemFree /proc/meminfo` free_mem=$2 ; fre_mem_unit=$3 perc_mem_used=$((100-(100*free_mem/tot_mem))) set `grep SwapTotal /proc/meminfo` tot_swap=$2 ; tot_swap_unit=$3 set `grep SwapFree /proc/meminfo` free_swap=$2 ; fre_swap_unit=$3 perc_swap_used=$((100-(100*free_swap/tot_swap))) Make Barcode In None Using Barcode maker for Font Control to generate, create Barcode image in Font applications. www.OnBarcode.comEncoding USPS Confirm Service Barcode In None Using Barcode generator for Font Control to generate, create USPS Confirm Service Barcode image in Font applications. www.OnBarcode.comOnce the script has calculated percentages, the color of the output is set depending on the usage value that is being reported. Messages reporting usage levels of less than 80 percent appear in green, values between 80 and 90 percent appear in yellow, and 90 percent utilization or greater values appear in red. I have chosen the percentages somewhat arbitrarily. One improvement to the script would be to replace the percentage values with variables that are initialized using either a command-line switch or a configuration file. Generate DataMatrix In .NET Framework Using Barcode creator for Visual Studio .NET Control to generate, create Data Matrix image in .NET applications. www.OnBarcode.comData Matrix 2d Barcode Printer In .NET Framework Using Barcode printer for Reporting Service Control to generate, create ECC200 image in Reporting Service applications. www.OnBarcode.comif [ $perc_mem_used -lt 80 ] then mem_color=$green elif [ $perc_mem_used -ge 80 -a $perc_mem_used -lt 90 ] then mem_color=$yellow else mem_color=$red fi if [ $perc_swap_used -lt 80 ] then swap_color=$green elif [ $perc_swap_used -ge 80 -a $perc_swap_used -lt 90 ] then swap_color=$yellow Barcode Generator In .NET Framework Using Barcode maker for ASP.NET Control to generate, create Barcode image in ASP.NET applications. www.OnBarcode.comQR Reader In Java Using Barcode reader for Java Control to read, scan read, scan image in Java applications. www.OnBarcode.comCHAPTER 35 COLORFUL /PROC REPORTING
Denso QR Bar Code Printer In Visual C#.NET Using Barcode creator for .NET Control to generate, create QR Code 2d barcode image in .NET applications. www.OnBarcode.comRead QR-Code In Visual Studio .NET Using Barcode decoder for .NET Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.comelse swap_color=$red fi echo -e "Memory: $white$tot_mem$normal $tot_mem_unit Free: $white$free_mem$normal \ $fre_mem_unit %Used: $mem_color$perc_mem_used$normal" echo -e "Swap: $white$tot_swap$normal $tot_swap_unit Free: $white$free_swap$normal \ $fre_swap_unit %Used: $swap_color$perc_swap_used$normal" echo Decoding UPC-A Supplement 2 In .NET Using Barcode scanner for .NET Control to read, scan read, scan image in .NET applications. www.OnBarcode.comGenerate USS Code 39 In Java Using Barcode drawer for Java Control to generate, create Code39 image in Java applications. www.OnBarcode.comIn addition to memory and swap utilization, the script determines the system-load averages, again using the set command to assign values to the positional variables. The /proc/loadavg file contains a single line of space-separated fields, where the first three fields are the 1-minute, 5-minute, and 15-minute load averages of the running system. Recognizing Code 128 In C#.NET Using Barcode decoder for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.comMake QR Code In None Using Barcode generation for Software Control to generate, create QR Code 2d barcode image in Software applications. www.OnBarcode.comset `cat /proc/loadavg` one_min=$1 five_min=$2 fifteen_min=$3 echo -n "Load Average:" for ave in $one_min $five_min $fifteen_min do int_ave=`echo $ave | cut -d. -f1` if [ $int_ave -lt 1 ] then echo -en " $green$ave$normal" elif [ $int_ave -ge 1 -a $int_ave -lt 5 ] then echo -en " $yellow$ave$normal" else echo -en " $red$ave$normal" fi done echo Printing Data Matrix ECC200 In Visual Basic .NET Using Barcode generator for Visual Studio .NET Control to generate, create Data Matrix image in Visual Studio .NET applications. www.OnBarcode.comGS1 - 12 Scanner In None Using Barcode recognizer for Software Control to read, scan read, scan image in Software applications. www.OnBarcode.comWhen the file s output is applied to the set command, the first three fields become the values of the positional parameter variables $1, $2, and $3. Once these values have been obtained, the script adjusts the color of the text. A load average below 1 will be reported in green, between 1 and 5 in yellow, and any value 5 or greater in red. Keep in mind that the colors for the load averages are assumed to be for single-CPU systems. The final operation counts the running processes and determines their states. Once the total number of processes is calculated, the script displays the process count. It also gives a breakdown of processes by status type, telling the user how many processes are running, sleeping, stopped, or zombified. CHAPTER 35 COLORFUL /PROC REPORTING
running=0; sleeping=0 stopped=0; zombie=0 for pid in /proc/[1-9]* do procs=$((procs+1)) stat=`awk '{print $3}' $pid/stat` case $stat in R) running=$((running+1));; S) sleeping=$((sleeping+1));; T) stopped=$((stopped+1));; Z) zombie=$((zombie+1));; esac done echo -n "Process Count: " echo -e "$white$procs$normal total $white$running$normal running\ $white$sleeping$normal sleeping $white$stopped$normal stopped\ $white$zombie$normal zombie" echo The following is a sample report that the script generates while running. I have used boldface wherever the report is supposed to appear in a special color. It is more informative with colorized output, although even without color it is useful for capturing a snapshot of the system state and displaying everything on one screen. System Report for casper on Thu Aug 4 21:33:19 PDT 2005 Hostname: casper NIS Domain: (none) Processor: Intel(R) Pentium(R) 4 CPU 1.80GHz Running at 3555.32 bogomips with 256 KB cache OS Type: Linux Kernel: 2.6.10-gentoo-r7 Kernel Compile #2 on Thu Feb 24 14:38:44 PST 2005 Uptime: 163.70 days Memory: 514836 kB Free: 183744 kB %Used: 65 Swap: 506036 kB Free: 491324 kB %Used: 3 Load Average: 0.04 0.11 0.05 Process Count: 140 total 1 running 139 sleeping 0 stopped 0 zombie It is possible to retrieve most of the information in the files located in the /proc directory tree using other methods. Programs such as hostname, netstat, top, ps, uptime, and others get their data from /proc. In some cases those programs are easier to use because they condense information and present it in a more readable form. In other cases getting the data directly from the files residing in /proc is easier or faster. This is the situation with our script: there is no data to format and there is no unneeded functionality that may impact performance. The part of the script that gets the load average provides a good illustration of this; the data in /proc/loadavg is easier to process than data from other sources. Load-average
|
|