c_smrrds.sh 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. #!/bin/sh
  2. # $Id: c_smrrds.sh,v 1.26 2004/02/26 22:48:08 dijkstra Exp $
  3. #
  4. # Copyright (c) 2001-2004 Willem Dijkstra
  5. # All rights reserved.
  6. #
  7. # Redistribution and use in source and binary forms, with or without
  8. # modification, are permitted provided that the following conditions
  9. # are met:
  10. #
  11. # - Redistributions of source code must retain the above copyright
  12. # notice, this list of conditions and the following disclaimer.
  13. # - Redistributions in binary form must reproduce the above
  14. # copyright notice, this list of conditions and the following
  15. # disclaimer in the documentation and/or other materials provided
  16. # with the distribution.
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  21. # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  22. # COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  23. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  24. # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  26. # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  28. # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. # POSSIBILITY OF SUCH DAMAGE.
  30. # --- user configuration starts here
  31. INTERVAL=${INTERVAL:-5}
  32. # --- user configuration ends here
  33. # addsuffix adds a suffix to each entry of a list (item|item|...)
  34. addsuffix() {
  35. list=$1'|'
  36. suffix=$2
  37. while [ `echo $list | grep '|'` ]; do
  38. newlist=$newlist'|'`echo $list | cut -f1 -d\|`$suffix
  39. list=`echo $list | cut -f2- -d\|`
  40. done
  41. echo $newlist | cut -b2-
  42. }
  43. create_rrd() {
  44. file=$1
  45. shift
  46. rrdtool create $file $RRD_ARGS $* $RRA_SETUP
  47. if [ "$?" = "0" -a -f $file ]; then
  48. echo "$file created"
  49. else
  50. echo "could not create $file"
  51. fi
  52. }
  53. # get arguments
  54. select_interval=""
  55. for i
  56. do
  57. case $i in
  58. interval)
  59. select_interval="yes"
  60. ;;
  61. child)
  62. child=1
  63. ;;
  64. oneday)
  65. config=$i
  66. # today only RRA setup:
  67. # - 1 day of 5 second samples = 17280 x 5 second samples
  68. RRA_SETUP=" RRA:AVERAGE:0.5:1:17280
  69. RRA:MAX:0.5:1:17280
  70. RRA:MIN:0.5:1:17280"
  71. if [ X"$child" == "X" ]; then
  72. echo "RRDs will only contain a single day of data"
  73. fi
  74. ;;
  75. *)
  76. if [ -n "$select_interval" ]; then
  77. INTERVAL=$i
  78. select_interval=""
  79. else
  80. args="$args $i"
  81. fi
  82. ;;
  83. esac
  84. done
  85. if [ X"$RRA_SETUP" == "X" ]; then
  86. # default RRA setup:
  87. # - 2 days of 5 second samples = 34560 x 5 second samples
  88. # - 14 days of 30 minutes samples = 672 x 360 x 5 second samples
  89. # - 50 days of 2 hour samples = 600 x 1440 x 5 second samples
  90. # - 600 days of 1 day samples = 600 x 17280 x 5 second samples
  91. RRA_SETUP=" RRA:AVERAGE:0.5:1:34560
  92. RRA:AVERAGE:0.5:360:672
  93. RRA:AVERAGE:0.5:1440:600
  94. RRA:AVERAGE:0.5:17280:600
  95. RRA:MAX:0.5:1:34560
  96. RRA:MAX:0.5:360:672
  97. RRA:MAX:0.5:1440:600
  98. RRA:MAX:0.5:17280:600
  99. RRA:MIN:0.5:1:34560
  100. RRA:MIN:0.5:360:672
  101. RRA:MIN:0.5:1440:600
  102. RRA:MIN:0.5:17280:600"
  103. fi
  104. # All interfaces and disks
  105. INTERFACES="an|awi|be|bge|bm|cnw|dc|de|ec|ef|eg|el|em|ep|ex|fea|fpa|fxp|gem|gm|gre|hme|ie|kue|lc|le|lge|lmc|lo|ne|nge|ray|rl|qe|sf|sis|sk|sl|sm|ste|stge|ti|tl|tr|tx|txp|vme|vr|wb|we|wi|wx|xe|xl"
  106. VIRTUALINTERFACES="bridge|carp|enc|faith|gif|ppp|sppp|strip|tun|vlan";
  107. DISKS="sd|cd|ch|rd|raid|ss|uk|vnc|wd"
  108. DISKS=`addsuffix $DISKS [0-9]`
  109. INTERFACES=`addsuffix $INTERFACES [0-9]`
  110. VIRTUALINTERFACES=`addsuffix $VIRTUALINTERFACES \\.\\*`
  111. this=$0
  112. if [ X"$1$2$3$4$5$6$7$8$9" == "X" ]; then
  113. cat <<EOF
  114. Create rrd files for symux.
  115. Usage: $0 [oneday] [interval <seconds>] all | cpu0 | mem |
  116. pf | mbuf | debug | proc_<process> |
  117. <if> | <io> | sensor[0-25]
  118. Where:
  119. oneday = modify rrds to only contain one day of information
  120. seconds = modify rrds for non standard monitoring interval
  121. process = the name of a process as specified in sy{mon,mux}.conf
  122. e.g. proc(httpd) -> proc_httpd
  123. if= `echo $INTERFACES|
  124. awk 'BEGIN {FS="|"}
  125. {for (i=1; i<=NF; i++) {
  126. printf("%s|",$i);
  127. if ((i%6)==0) {
  128. printf("%s","\n\t")
  129. }
  130. }
  131. print " ";}'`
  132. io= `echo $DISKS|
  133. awk 'BEGIN {FS="|"}
  134. {for (i=1; i<=NF; i++) {
  135. printf("%s|",$i);
  136. if ((i%6)==0) {
  137. printf("%s","\n\t")
  138. }
  139. }
  140. print " ";}'`
  141. Pre 3.5 disk statistics are available via the io1_<disk> argument.
  142. EOF
  143. exit 1;
  144. fi
  145. for i in $args
  146. do
  147. # add if_*.rrd if it is an interface
  148. if [ `echo $i | egrep -e "^($INTERFACES)$"` ]; then i=if_$i.rrd; fi
  149. if [ `echo $i | egrep -e "^($VIRTUALINTERFACES)$"` ]; then i=if_$i.rrd; fi
  150. # add io_*.rrd if it is a disk
  151. if [ `echo $i | egrep -e "^($DISKS)$"` ]; then i=io_$i.rrd; fi
  152. # add .rrd if it is a cpu, etc.
  153. if [ `echo $i | egrep -e "^(cpu[0-9]$|mem$|pf$|mbuf$|debug$|proc_|sensor[0-9]$|sensor[0-9][0-9]$|io1_)"` ]; then i=$i.rrd; fi
  154. if [ -f $i ]; then
  155. echo "$i exists - ignoring"
  156. i="done"
  157. fi
  158. RRD_ARGS="--step=$INTERVAL --start=0"
  159. case $i in
  160. all)
  161. echo "Creating rrd files for {cpu0|mem|disks|interfaces|pf|mbuf}"
  162. sh $this interval $INTERVAL child $config cpu0 mem
  163. sh $this interval $INTERVAL child $config interfaces
  164. sh $this interval $INTERVAL child $config disks
  165. sh $this interval $INTERVAL child $config pf
  166. sh $this interval $INTERVAL child $config mbuf
  167. ;;
  168. if|interfaces)
  169. # obtain all network cards
  170. sh $this child $config `ifconfig -a| egrep -e "^($INTERFACES):" | cut -f1 -d\: | sort -u`
  171. ;;
  172. io|disks)
  173. # obtain all disks
  174. sh $this child $config `df | grep dev | sed 's/^\/dev\/\(.*\)[a-z] .*$/\1/' | sort -u`
  175. ;;
  176. cpu[0-9].rrd)
  177. # Build cpu file
  178. create_rrd $i \
  179. DS:user:GAUGE:$INTERVAL:0:100 \
  180. DS:nice:GAUGE:$INTERVAL:0:100 \
  181. DS:system:GAUGE:$INTERVAL:0:100 \
  182. DS:interrupt:GAUGE:$INTERVAL:0:100 \
  183. DS:idle:GAUGE:$INTERVAL:0:100
  184. ;;
  185. sensor*.rrd)
  186. # Build sensor file
  187. create_rrd $i \
  188. DS:value:GAUGE:$INTERVAL:-U:U
  189. ;;
  190. mem.rrd)
  191. # Build memory file
  192. create_rrd $i \
  193. DS:real_active:GAUGE:$INTERVAL:0:U \
  194. DS:real_total:GAUGE:$INTERVAL:0:U \
  195. DS:free:GAUGE:$INTERVAL:0:U \
  196. DS:swap_used:GAUGE:$INTERVAL:0:U \
  197. DS:swap_total:GAUGE:$INTERVAL:0:U
  198. ;;
  199. if_*.rrd)
  200. # Build interface files
  201. create_rrd $i \
  202. DS:ipackets:COUNTER:$INTERVAL:U:U DS:opackets:COUNTER:$INTERVAL:U:U \
  203. DS:ibytes:COUNTER:$INTERVAL:U:U DS:obytes:COUNTER:$INTERVAL:U:U \
  204. DS:imcasts:COUNTER:$INTERVAL:U:U DS:omcasts:COUNTER:$INTERVAL:U:U \
  205. DS:ierrors:COUNTER:$INTERVAL:U:U DS:oerrors:COUNTER:$INTERVAL:U:U \
  206. DS:collisions:COUNTER:$INTERVAL:U:U DS:drops:COUNTER:$INTERVAL:U:U
  207. ;;
  208. debug.rrd)
  209. # Build debug file
  210. create_rrd $i \
  211. DS:debug0:GAUGE:$INTERVAL:U:U DS:debug1:GAUGE:$INTERVAL:U:U \
  212. DS:debug2:GAUGE:$INTERVAL:U:U DS:debug3:GAUGE:$INTERVAL:U:U \
  213. DS:debug4:GAUGE:$INTERVAL:U:U DS:debug5:GAUGE:$INTERVAL:U:U \
  214. DS:debug6:GAUGE:$INTERVAL:U:U DS:debug7:GAUGE:$INTERVAL:U:U \
  215. DS:debug8:GAUGE:$INTERVAL:U:U DS:debug9:GAUGE:$INTERVAL:U:U \
  216. DS:debug10:GAUGE:$INTERVAL:U:U DS:debug11:GAUGE:$INTERVAL:U:U \
  217. DS:debug12:GAUGE:$INTERVAL:U:U DS:debug13:GAUGE:$INTERVAL:U:U \
  218. DS:debug14:GAUGE:$INTERVAL:U:U DS:debug15:GAUGE:$INTERVAL:U:U \
  219. DS:debug16:GAUGE:$INTERVAL:U:U DS:debug17:GAUGE:$INTERVAL:U:U \
  220. DS:debug18:GAUGE:$INTERVAL:U:U DS:debug19:GAUGE:$INTERVAL:U:U
  221. ;;
  222. proc_*.rrd)
  223. # Build proc file
  224. create_rrd $i \
  225. DS:number:GAUGE:$INTERVAL:0:U DS:uticks:COUNTER:$INTERVAL:0:U \
  226. DS:sticks:COUNTER:$INTERVAL:0:U DS:iticks:COUNTER:$INTERVAL:0:U \
  227. DS:cpusec:GAUGE:$INTERVAL:0:U DS:cpupct:GAUGE:$INTERVAL:0:100 \
  228. DS:procsz:GAUGE:$INTERVAL:0:U DS:rsssz:GAUGE:$INTERVAL:0:U
  229. ;;
  230. pf.rrd)
  231. # Build pf file
  232. create_rrd $i \
  233. DS:bytes_v4_in:DERIVE:$INTERVAL:0:U DS:bytes_v4_out:DERIVE:$INTERVAL:0:U \
  234. DS:bytes_v6_in:DERIVE:$INTERVAL:0:U DS:bytes_v6_out:DERIVE:$INTERVAL:0:U \
  235. DS:packets_v4_in_pass:DERIVE:$INTERVAL:0:U DS:packets_v4_in_drop:DERIVE:$INTERVAL:0:U \
  236. DS:packets_v4_out_pass:DERIVE:$INTERVAL:0:U DS:packets_v4_out_drop:DERIVE:$INTERVAL:0:U \
  237. DS:packets_v6_in_pass:DERIVE:$INTERVAL:0:U DS:packets_v6_in_drop:DERIVE:$INTERVAL:0:U \
  238. DS:packets_v6_out_pass:DERIVE:$INTERVAL:0:U DS:packets_v6_out_drop:DERIVE:$INTERVAL:0:U \
  239. DS:states_entries:ABSOLUTE:$INTERVAL:0:U \
  240. DS:states_searches:DERIVE:$INTERVAL:0:U \
  241. DS:states_inserts:DERIVE:$INTERVAL:0:U \
  242. DS:states_removals:DERIVE:$INTERVAL:0:U \
  243. DS:counters_match:DERIVE:$INTERVAL:0:U \
  244. DS:counters_badoffset:DERIVE:$INTERVAL:0:U \
  245. DS:counters_fragment:DERIVE:$INTERVAL:0:U \
  246. DS:counters_short:DERIVE:$INTERVAL:0:U \
  247. DS:counters_normalize:DERIVE:$INTERVAL:0:U \
  248. DS:counters_memory:DERIVE:$INTERVAL:0:U
  249. ;;
  250. mbuf.rrd)
  251. # Build mbuf file
  252. create_rrd $i \
  253. DS:totmbufs:GAUGE:$INTERVAL:0:U DS:mt_data:GAUGE:$INTERVAL:0:U \
  254. DS:mt_oobdata:GAUGE:$INTERVAL:0:U DS:mt_control:GAUGE:$INTERVAL:0:U \
  255. DS:mt_header:GAUGE:$INTERVAL:0:U DS:mt_ftable:GAUGE:$INTERVAL:0:U \
  256. DS:mt_soname:GAUGE:$INTERVAL:0:U DS:mt_soopts:GAUGE:$INTERVAL:0:U \
  257. DS:pgused:GAUGE:$INTERVAL:0:U DS:pgtotal:GAUGE:$INTERVAL:0:U \
  258. DS:totmem:GAUGE:$INTERVAL:0:U DS:totpct:GAUGE:$INTERVAL:0:100 \
  259. DS:m_drops:COUNTER:$INTERVAL:0:U DS:m_wait:COUNTER:$INTERVAL:0:U \
  260. DS:m_drain:COUNTER:$INTERVAL:0:U
  261. ;;
  262. io_*.rrd)
  263. # Build disk files
  264. create_rrd $i \
  265. DS:rxfer:COUNTER:$INTERVAL:U:U \
  266. DS:wxfer:COUNTER:$INTERVAL:U:U \
  267. DS:seeks:COUNTER:$INTERVAL:U:U \
  268. DS:rbytes:COUNTER:$INTERVAL:U:U \
  269. DS:wbytes:COUNTER:$INTERVAL:U:U
  270. ;;
  271. io1_*.rrd)
  272. # Build disk files
  273. create_rrd $i \
  274. DS:transfers:COUNTER:$INTERVAL:U:U \
  275. DS:seeks:COUNTER:$INTERVAL:U:U \
  276. DS:bytes:COUNTER:$INTERVAL:U:U
  277. ;;
  278. "done")
  279. # ignore
  280. ;;
  281. *)
  282. # Default match
  283. echo $i - unknown
  284. ;;
  285. esac
  286. done