]> git.somenet.org - somenet/munin.git/blob - threads
Updated ircd scripts to fix some channel naming fails.
[somenet/munin.git] / threads
1 #!/bin/sh
2 # -*- sh -*-
3
4 : << =cut
5
6 =head1 NAME
7
8 threads - copy of threads, with another ps option. commented out all but linux.
9
10 =cut
11
12 # Search for program in $PATH unless predefined.
13 [ $awk ]     || awk="awk"
14 [ $ps ]      || ps="ps"
15
16 # Find operating system
17 [ $OPERSYS ] || OPERSYS=`uname` || exit 1
18
19 if [ "$1" = "autoconf" ]; then
20         echo yes
21         exit 0
22 fi
23
24 . $MUNIN_LIBDIR/plugins/plugin.sh
25
26 # Define colours
27 RUNNABLE='22ff22'         # Green
28 SLEEPING='0022ff'         # Blue
29 STOPPED='cc0000'          # Darker red
30 ZOMBIE='990000'           # Darkest red
31 UNINTERRUPTIBLE='ffa500'  # Orange
32 IDLE='4169e1'             # Royal blue
33 PAGING='00aaaa'           # Darker turquoise
34 INTERRUPT='ff00ff'        # Fuchsia
35 LOCK='ff3333'             # Lighter red
36 RUNNING='00ff7f'          # Spring green
37 DEAD='ff0000'             # Red
38 SUSPENDED='ff1493'        # Deep pink
39 TOTAL='c0c0c0'            # Silver
40
41 # Taken from ps(1)
42 # R - Linux, SunOS, FreeBSD, OpenBSD, NetBSD, OSX      (runable)
43 # S - Linux, SunOS, FreeBSD*, OpenBSD*, NetBSD*, OSX*  (sleeping)
44 # T - Linux, SunOS, FreeBSD, OpenBSD, NetBSD, OSX      (stopped)
45 # Z - Linux, SunOS, FreeBSD, OpenBSD, NetBSD, OSX      (zombie)
46 # D - Linux, FreeBSD, OpenBSD, NetBSD                  (uninterruptible)
47 # I - FreeBSD, OpenBSD, NetBSD, OSX                    (idle)
48 # W - Linux*, FreeBSD*                                 (paging/interrupt)
49 # L - FreeBSD                                          (lock)
50 # O - SunOS                                            (running)
51 # X - Linux                                            (dead)
52 # U - OSX, NetBSD*                                     (uninterruptible/suspended)
53 # *) Differ meaning
54
55 if [ "$1" = "config" ]; then
56     echo "graph_title Threads"
57     echo "graph_info This graph shows the number of threads"
58     echo "graph_category system"
59     echo "graph_args --base 1000 -l 0"
60     echo "graph_vlabel Number of threads"
61
62     # OS specific flags
63 #    if [ "$OPERSYS" = "Linux" ]; then
64         echo "graph_order sleeping stopped zombie dead paging uninterruptible runnable threads"
65         echo "dead.label dead"
66         echo "dead.draw STACK"
67         echo "dead.colour $DEAD"
68         echo "dead.info The number of dead threads."
69         print_warning dead
70         print_critical dead
71         echo "paging.label paging"
72         echo "paging.draw STACK"
73         echo "paging.colour $PAGING"
74         echo "paging.info The number of paging threads (<2.6 kernels only)."
75         print_warning paging
76         print_critical paging
77
78 #    elif [ "$OPERSYS" = "SunOS" ]; then
79 #       echo "graph_order sleeping stopped zombie runnable running total"
80 #       echo "running.label running"
81 #       echo "running.draw STACK"
82 #       echo "running.colour $RUNNING"
83 #       echo "running.info The number of threads that are running on a processor."
84 #       print_warning running
85 #       print_critical running
86 #       # Be backwards compatible.
87 #       echo "total.label total"
88 #       echo "total.draw LINE1"
89 #        echo "total.colour $TOTAL"
90 #       echo "total.info The total number of threads."
91 #       print_warning total
92 #       print_critical total
93 #
94 #    elif [ "$OPERSYS" = "FreeBSD" ]; then
95 #       echo "graph_order sleeping idle stopped zombie lock uninterruptible interrupt runnable threads"
96 #       echo "lock.label lock"
97 #       echo "lock.draw STACK"
98 #       echo "lock.colour $LOCK"
99 #       echo "lock.info The number of threads that are waiting to acquire a lock."
100 #       print_warning lock
101 #       print_critical lock
102 #       echo "interrupt.label interrupt"
103 #       echo "interrupt.draw STACK"
104 #       echo "interrupt.colour $INTERRUPT"
105 #       echo "interrupt.info The number of idle interrupt threads."
106 #       print_warning interrupt
107 #       print_critical interrupt
108 #      
109 #    elif [ "$OPERSYS" = "OpenBSD" ]; then
110 #       echo "graph_order sleeping idle stopped zombie uninterruptible runnable threads"
111 #
112 #    elif [ "$OPERSYS" = "NetBSD" ]; then
113 #       echo "graph_order sleeping idle stopped zombie uninterruptible suspended runnable threads"
114 #       echo "suspended.label suspended"
115 #       echo "suspended.draw STACK"
116 #       echo "suspended.colour $SUSPENDED"
117 #       echo "suspended.info The number of threads that are suspended."
118 #       print_warning suspended
119 #       print_critical suspended
120 #
121 #    elif [ "$OPERSYS" = "Darwin" ]; then
122 #       echo "graph_order sleeping idle stopped zombie uninterruptible running threads"
123 #       echo "uninterruptible.label uninterruptible"
124 #       echo "uninterruptible.draw STACK"
125 #       echo "uninterruptible.colour $UNINTERRUPTIBLE"
126 #       echo "uninterruptible.info The number of uninterruptible threads (usually IO)."
127 #       print_warning uninterruptible
128 #       print_critical uninterruptible
129 #    fi
130 #
131 #    # Common flags for some OS
132 #    if [ "$OPERSYS" = "FreeBSD" ] || [ "$OPERSYS" = "OpenBSD" ] || 
133 #       [ "$OPERSYS" = "NetBSD" ] || [ "$OPERSYS" = "Darwin" ]; then
134 #       echo "idle.label idle"
135 #       echo "idle.draw STACK"
136 #       echo "idle.colour $IDLE"
137 #       echo "idle.info The number of threads that are idle (sleeping for longer than about 20 seconds)."
138 #       print_warning idle
139 #       print_critical idle
140 #       echo "sleeping.label sleeping"
141 #       echo "sleeping.draw AREA"
142 #       echo "sleeping.colour $SLEEPING"
143 #       echo "sleeping.info The number of threads that are sleeping for less than about 20 seconds."
144 #       print_warning sleeping
145 #       print_critical sleeping
146 #    else
147         echo "sleeping.label sleeping"
148         echo "sleeping.draw AREA"
149         echo "sleeping.colour $SLEEPING"
150         echo "sleeping.info The number of sleeping threads."
151         print_warning sleeping
152         print_critical sleeping
153 #    fi
154    
155     if [ "$OPERSYS" = "Linux" ] || [ "$OPERSYS" = "FreeBSD" ] || 
156         [ "$OPERSYS" = "OpenBSD" ] || [ "$OPERSYS" = "NetBSD" ]; then
157         echo "uninterruptible.label uninterruptible"
158         echo "uninterruptible.draw STACK"
159         echo "uninterruptible.colour $UNINTERRUPTIBLE"
160         echo "uninterruptible.info The number of uninterruptible threads (usually IO)." 
161         print_warning uninterruptible
162         print_critical uninterruptible
163     fi
164
165     # Common flags
166     echo "zombie.label zombie"
167     echo "zombie.draw STACK"
168     echo "zombie.colour $ZOMBIE"
169     echo "zombie.info The number of defunct ("zombie") threads (thread terminated and parent not waiting)."
170     print_warning zombie
171     print_critical zombie
172
173     echo "stopped.label stopped"
174     echo "stopped.draw STACK"
175     echo "stopped.colour $STOPPED"
176     echo "stopped.info The number of stopped or traced threads."
177     print_warning stopped
178     print_critical stopped
179
180     echo "runnable.label runnable"
181     echo "runnable.draw STACK"
182     echo "runnable.colour $RUNNABLE"
183     echo "runnable.info The number of runnable threads (on the run queue)."
184     print_warning runnable
185     print_critical runnable
186
187     if [ "$OPERSYS" != "SunOS" ]; then
188         # Not using 'graph_total' due to backwards compability. SunOS uses 'total'.
189         #echo 'graph_total total'
190         echo "threads.label total"
191         echo "threads.draw LINE1"
192         echo "threads.colour $TOTAL"
193         echo "threads.info The total number of threads."
194         print_warning threads
195         print_critical threads
196     fi
197
198     exit 0
199 fi
200
201 #if [ "$OPERSYS" = "Linux" ]; then
202     $ps --no-header -eTo s | $awk '
203 { threads++; stat[$1]++ }
204 END {
205 print "threads.value "        0+threads;
206 print "uninterruptible.value "  0+stat["D"];
207 print "runnable.value "         0+stat["R"];
208 print "sleeping.value "         0+stat["S"];
209 print "stopped.value "          0+stat["T"];
210 print "paging.value "           0+stat["W"];
211 print "dead.value "             0+stat["X"];
212 print "zombie.value "           0+stat["Z"];
213 }'
214
215 #elif [ "$OPERSYS" = "SunOS" ]; then
216 #    $ps -e -o s | $awk '
217 #{ total++; stat[$1]++ }
218 #END {
219 #print "total.value "    0+total;
220 #print "running.value "  0+stat["O"];
221 #print "sleeping.value " 0+stat["S"];
222 #print "runnable.value " 0+stat["R"];
223 #print "stopped.value "  0+stat["T"];
224 #print "zombie.value "   0+stat["Z"];
225 #}'
226 #elif [ "$OPERSYS" = "FreeBSD" ]; then
227 #    $ps -axo state= | sed -e 's/^\(.\).*/\1/' | $awk '
228 #{ threads++; stat[$1]++ }
229 #END {
230 #print "threads.value "        0+threads;
231 #print "uninterruptible.value "  0+stat["D"];
232 #print "idle.value "             0+stat["I"];
233 #print "lock.value "             0+stat["G"];
234 #print "runnable.value "         0+stat["R"];
235 #print "sleeping.value "         0+stat["S"];
236 #print "stopped.value "          0+stat["T"];
237 #print "interrupt.value "        0+stat["W"];
238 #print "zombie.value "           0+stat["Z"];
239 #}'
240 #elif [ "$OPERSYS" = "OpenBSD" ]; then
241 #    # First line is header. Remove it.
242 #    $ps -axo state= | sed '1d' | sed -e 's/^\(.\).*/\1/' | $awk '
243 #{ threads++; stat[$1]++ }
244 #END {
245 #print "threads.value "        0+threads;
246 #print "uninterruptible.value "  0+stat["D"];
247 #print "idle.value "             0+stat["I"];
248 #print "runnable.value "         0+stat["R"];
249 #print "sleeping.value "         0+stat["S"];
250 #print "stopped.value "          0+stat["T"];
251 #print "zombie.value "           0+stat["Z"];
252 #}'
253 #elif [ "$OPERSYS" = "NetBSD" ]; then
254 #    # First line is header. Remove it.
255 #    $ps -axo state= | sed '1d' | sed -e 's/^\(.\).*/\1/' | $awk '
256 #{ threads++; stat[$1]++ }
257 #END {
258 #print "threads.value "        0+threads;
259 #print "uninterruptible.value "  0+stat["D"];
260 #print "idle.value "             0+stat["I"];
261 #print "suspended.value "        0+stat["U"];
262 #print "runnable.value "         0+stat["R"];
263 #print "sleeping.value "         0+stat["S"];
264 #print "stopped.value "          0+stat["T"];
265 #print "zombie.value "           0+stat["Z"];
266 #}'
267 #
268 #elif [ "$OPERSYS" = "Darwin" ]; then
269 #    # First line is header. Remove it.
270 #    $ps -axo state= | sed '1d' | sed -e 's/^\(.\).*/\1/' | $awk '
271 #{ threads++; stat[$1]++ }
272 #END {
273 #print "threads.value "        0+threads;
274 #print "uninterruptible.value "  0+stat["U"];
275 #print "idle.value "             0+stat["I"];
276 #print "runnable.value "         0+stat["R"];
277 #print "sleeping.value "         0+stat["S"];
278 #print "stopped.value "          0+stat["T"];
279 #print "zombie.value "           0+stat["Z"];
280 #}'
281 #fi
282