From: Moses M. <mo...@mo...> - 2007-09-20 18:45:07
|
Nicolai Langfeldt wrote: > It would also appear that "vmstat 1 1" should do the job - at least on > Linux. The vmstat plugin is generic and seems to work on all (or most) > unixes. I think the plugin author used 'vmstat 1 2' because the numbers might be a little off if vmstat on an old or shifty Unix machine was called in the middle between two seconds. In my opinion being off by one isn't that big of a deal. Oh, unless it'd the difference between 1 and 0 for procs 'b' (sleep.value). Reading vmstat's man page, it says the number for procs 'r' "doesn't take into account vmstat itself," whereas using /usr/bin/sed on /proc/stat would include sed in procs_running. This would prevent it from every going to '0'... but I doubt that's a bad thing. > Would you adapt a vmstat plugin for linux based on /proc/stat > and then e-mail me please? Here's a simple patch. Let me know if I made a mistake. [moomo@hubble plugins]$ diff -u vmstat-1.4 vmstat --- vmstat-1.4 2007-09-20 14:26:16.000000000 -0400 +++ vmstat 2007-09-20 14:25:03.000000000 -0400 @@ -1,7 +1,7 @@ #!/bin/sh # # Plugin to monitor the number of procs in io-sleep and other wait -# states. Uses `vmstat`. +# states. Uses `vmstat` or /proc/stat # # Parameters: # @@ -9,6 +9,9 @@ # autoconf (optional - used by munin-config) # # $Log$ +# Revision 1.5 2007/09/20 14:19:14 moomo +# Uses faster method if on a linux machine. +# # Revision 1.4 2004/05/20 13:57:12 jimmyo # Set categories to some of the plugins. # @@ -39,7 +42,7 @@ if [ "$1" = "autoconf" ]; then - if ( vmstat 1 1 >/dev/null 2>&1 ); then + if ( grep procs_ /proc/stat >/dev/null 2>&1 ) || ( vmstat 1 1 >/dev/null 2>&1 ); then echo yes exit 0 else @@ -65,7 +67,11 @@ echo 'sleep.label I/O sleep' echo 'sleep.type GAUGE' echo 'sleep.max 500000' exit 0 fi -vmstat 1 2 | awk '{wait = $1; sleep = $2} END { print "wait.value " wait "\nsleep.value " sleep }' +if [ -e /proc/stat ]; then + sed '/procs_/!d; s/procs_running/wait.value/; s/procs_blocked/sleep.value/' < /proc/stat +else + vmstat 1 2 | awk '{wait = $1; sleep = $2} END { print "wait.value " wait "\nsleep.value " sleep }' +fi [moomo@hubble plugins]$ _ |