| 
									
										
										
										
											2017-09-05 20:10:14 +04:30
										 |  |  | #!/bin/sh | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Copyright (c) 2017 Babak Farrokhi.  All rights reserved. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Redistribution and use in source and binary forms, with or without | 
					
						
							|  |  |  | # modification, are permitted provided that the following conditions | 
					
						
							|  |  |  | # are met: | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # 1. Redistributions of source code must retain the above copyright | 
					
						
							|  |  |  | #    notice, this list of conditions and the following disclaimer. | 
					
						
							|  |  |  | # 2. Redistributions in binary form must reproduce the above copyright | 
					
						
							|  |  |  | #    notice, this list of conditions and the following disclaimer in the | 
					
						
							|  |  |  | #    documentation and/or other materials provided with the distribution. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND | 
					
						
							|  |  |  | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
					
						
							|  |  |  | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 
					
						
							|  |  |  | # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 
					
						
							|  |  |  | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
					
						
							|  |  |  | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 
					
						
							|  |  |  | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 
					
						
							|  |  |  | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 
					
						
							|  |  |  | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 
					
						
							|  |  |  | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 
					
						
							|  |  |  | # SUCH DAMAGE. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #%# family=auto | 
					
						
							|  |  |  | #%# capabilities=autoconf | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [ "$1" = "autoconf" ]; then | 
					
						
							|  |  |  | 	echo yes | 
					
						
							| 
									
										
										
										
											2018-10-01 16:39:58 +01:00
										 |  |  | 	exit 0 | 
					
						
							| 
									
										
										
										
											2017-09-05 20:10:14 +04:30
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [ "$1" = "config" ]; then | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	echo 'graph_title CPU usage' | 
					
						
							|  |  |  | 	echo 'graph_order system interrupt user nice idle' | 
					
						
							|  |  |  | 	echo "graph_args --base 1000 -r --lower-limit 0 --upper-limit $PERCENT " | 
					
						
							|  |  |  | 	echo 'graph_vlabel %' | 
					
						
							|  |  |  | 	echo 'graph_scale no' | 
					
						
							|  |  |  | 	echo 'graph_info This graph shows how CPU time is spent.' | 
					
						
							|  |  |  | 	echo 'graph_category system' | 
					
						
							|  |  |  | 	echo 'graph_period second' | 
					
						
							|  |  |  | 	echo 'system.label system' | 
					
						
							|  |  |  | 	echo 'system.draw AREA' | 
					
						
							|  |  |  | 	echo 'system.max 100' | 
					
						
							|  |  |  | 	echo 'system.type DERIVE' | 
					
						
							|  |  |  | 	echo 'system.min 0' | 
					
						
							|  |  |  | 	echo 'system.info CPU time spent by the kernel in system activities' | 
					
						
							|  |  |  | 	echo 'interrupt.label interrupt' | 
					
						
							|  |  |  | 	echo 'interrupt.draw STACK' | 
					
						
							|  |  |  | 	echo 'interrupt.max 100' | 
					
						
							|  |  |  | 	echo 'interrupt.type DERIVE' | 
					
						
							|  |  |  | 	echo 'interrupt.min 0' | 
					
						
							|  |  |  | 	echo 'interrupt.info CPU time spent by the kernel processing interrupts' | 
					
						
							|  |  |  | 	echo 'user.label user' | 
					
						
							|  |  |  | 	echo 'user.draw STACK' | 
					
						
							|  |  |  | 	echo 'user.max 100' | 
					
						
							|  |  |  | 	echo 'user.type DERIVE' | 
					
						
							|  |  |  | 	echo 'user.info CPU time spent by normal programs and daemons' | 
					
						
							|  |  |  | 	echo 'user.min 0' | 
					
						
							|  |  |  | 	echo 'nice.label nice' | 
					
						
							|  |  |  | 	echo 'nice.draw STACK' | 
					
						
							|  |  |  | 	echo 'nice.max 100' | 
					
						
							|  |  |  | 	echo 'nice.type DERIVE' | 
					
						
							|  |  |  | 	echo 'nice.info CPU time spent by nice(1)d programs' | 
					
						
							|  |  |  | 	echo 'nice.min 0' | 
					
						
							|  |  |  | 	echo 'idle.label idle' | 
					
						
							|  |  |  | 	echo 'idle.draw STACK' | 
					
						
							|  |  |  | 	echo 'idle.max 100' | 
					
						
							|  |  |  | 	echo 'idle.type DERIVE' | 
					
						
							|  |  |  | 	echo 'idle.info Idle CPU time' | 
					
						
							|  |  |  | 	echo 'idle.min 0' | 
					
						
							|  |  |  | 	exit 0 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-16 14:42:49 +04:30
										 |  |  | #iostat -c2 -w0.1 -n0 | tail -1 | awk '{ print "user.value " $3 "\nnice.value " $4 "\nsystem.value " $5 "\ninterrupt.value " $6 "\nidle.value " $7 }' | 
					
						
							|  |  |  | # It expects to find our cpustat binary in /usr/local/bin | 
					
						
							|  |  |  | /usr/local/bin/cpustat | 
					
						
							| 
									
										
										
										
											2017-09-05 20:10:14 +04:30
										 |  |  | 
 |