c_smrrds.sh 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. #!/bin/sh
  2. # $Id: c_smrrds.sh,v 1.24 2003/12/21 13:23:15 dijkstra Exp $
  3. #
  4. # Copyright (c) 2001-2003 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. # get arguments
  34. select_interval=""
  35. for i
  36. do
  37. case $i in
  38. interval)
  39. select_interval="yes"
  40. ;;
  41. child)
  42. child=1
  43. ;;
  44. oneday)
  45. config=$i
  46. # today only RRA setup:
  47. # - 1 day of 5 second samples = 17280 x 5 second samples
  48. RRA_SETUP=" RRA:AVERAGE:0.5:1:17280
  49. RRA:MAX:0.5:1:17280
  50. RRA:MIN:0.5:1:17280"
  51. if [ X"$child" == "X" ]; then
  52. echo "RRDs will only contain a single day of data"
  53. fi
  54. ;;
  55. *)
  56. if [ -n "$select_interval" ]; then
  57. INTERVAL=$i
  58. select_interval=""
  59. else
  60. args="$args $i"
  61. fi
  62. ;;
  63. esac
  64. done
  65. if [ X"$RRA_SETUP" == "X" ]; then
  66. # default RRA setup:
  67. # - 2 days of 5 second samples = 34560 x 5 second samples
  68. # - 14 days of 30 minutes samples = 672 x 360 x 5 second samples
  69. # - 50 days of 2 hour samples = 600 x 1440 x 5 second samples
  70. # - 600 days of 1 day samples = 600 x 17280 x 5 second samples
  71. RRA_SETUP=" RRA:AVERAGE:0.5:1:34560
  72. RRA:AVERAGE:0.5:360:672
  73. RRA:AVERAGE:0.5:1440:600
  74. RRA:AVERAGE:0.5:17280:600
  75. RRA:MAX:0.5:1:34560
  76. RRA:MAX:0.5:360:672
  77. RRA:MAX:0.5:1440:600
  78. RRA:MAX:0.5:17280:600
  79. RRA:MIN:0.5:1:34560
  80. RRA:MIN:0.5:360:672
  81. RRA:MIN:0.5:1440:600
  82. RRA:MIN:0.5:17280:600"
  83. fi
  84. # All interfaces and disks
  85. 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"
  86. VIRTUALINTERFACES="bridge|enc|faith|gif|ppp|sppp|strip|tun|vlan";
  87. DISKS="sd|cd|ch|rd|raid|ss|uk|vnc|wd"
  88. # addsuffix adds a suffix to each entry of a list (item|item|...)
  89. addsuffix() {
  90. list=$1'|'
  91. suffix=$2
  92. while [ `echo $list | grep '|'` ]; do
  93. newlist=$newlist'|'`echo $list | cut -f1 -d\|`$suffix
  94. list=`echo $list | cut -f2- -d\|`
  95. done
  96. echo $newlist | cut -b2-
  97. }
  98. DISKS=`addsuffix $DISKS [0-9]`
  99. INTERFACES=`addsuffix $INTERFACES [0-9]`
  100. VIRTUALINTERFACES=`addsuffix $VIRTUALINTERFACES \\.\\*`
  101. this=$0
  102. if [ X"$1$2$3$4$5$6$7$8$9" == "X" ]; then
  103. cat <<EOF
  104. Create rrd files for symux.
  105. Usage: $0 [oneday] [interval <seconds>] all | cpu0 | mem |
  106. pf | mbuf | debug | proc_<process> |
  107. <if> | <io> | sensor[0-25]
  108. Where:
  109. oneday = modify rrds to only contain one day of information
  110. seconds = modify rrds for non standard monitoring interval
  111. process = the name of a process as specified in sy{mon,mux}.conf
  112. e.g. proc(httpd) -> proc_httpd
  113. if= `echo $INTERFACES|
  114. awk 'BEGIN {FS="|"}
  115. {for (i=1; i<=NF; i++) {
  116. printf("%s|",$i);
  117. if ((i%6)==0) {
  118. printf("%s","\n\t")
  119. }
  120. }
  121. print " ";}'`
  122. io= `echo $DISKS|
  123. awk 'BEGIN {FS="|"}
  124. {for (i=1; i<=NF; i++) {
  125. printf("%s|",$i);
  126. if ((i%6)==0) {
  127. printf("%s","\n\t")
  128. }
  129. }
  130. print " ";}'`
  131. EOF
  132. exit 1;
  133. fi
  134. for i in $args
  135. do
  136. # add if_*.rrd if it is an interface
  137. if [ `echo $i | egrep -e "^($INTERFACES)$"` ]; then i=if_$i.rrd; fi
  138. if [ `echo $i | egrep -e "^($VIRTUALINTERFACES)$"` ]; then i=if_$i.rrd; fi
  139. # add io_*.rrd if it is a disk
  140. if [ `echo $i | egrep -e "^($DISKS)$"` ]; then i=io_$i.rrd; fi
  141. # add .rrd if it is a cpu, etc.
  142. if [ `echo $i | egrep -e "^(cpu[0-9]$|mem$|pf$|mbuf$|debug$|proc_|sensor[0-9]$|sensor[0-9][0-9]$)"` ]; then i=$i.rrd; fi
  143. if [ -f $i ]; then
  144. echo "$i exists - ignoring"
  145. i="done"
  146. fi
  147. RRD_ARGS="--step=$INTERVAL --start=0"
  148. case $i in
  149. all)
  150. echo "Creating rrd files for {cpu0|mem|disks|interfaces|pf|mbuf}"
  151. sh $this interval $INTERVAL child $config cpu0 mem
  152. sh $this interval $INTERVAL child $config interfaces
  153. sh $this interval $INTERVAL child $config disks
  154. sh $this interval $INTERVAL child $config pf
  155. sh $this interval $INTERVAL child $config mbuf
  156. ;;
  157. if|interfaces)
  158. # obtain all network cards
  159. sh $this child $config `ifconfig -a| egrep -e "^($INTERFACES):" | cut -f1 -d\: | sort -u`
  160. ;;
  161. io|disks)
  162. # obtain all disks
  163. sh $this child $config `df | grep dev | sed 's/^\/dev\/\(.*\)[a-z] .*$/\1/' | sort -u`
  164. ;;
  165. cpu[0-9].rrd)
  166. # Build cpu file
  167. rrdtool create $i $RRD_ARGS \
  168. DS:user:GAUGE:$INTERVAL:0:100 \
  169. DS:nice:GAUGE:$INTERVAL:0:100 \
  170. DS:system:GAUGE:$INTERVAL:0:100 \
  171. DS:interrupt:GAUGE:$INTERVAL:0:100 \
  172. DS:idle:GAUGE:$INTERVAL:0:100 \
  173. $RRA_SETUP
  174. echo "$i created"
  175. ;;
  176. sensor*.rrd)
  177. # Build sensor file
  178. rrdtool create $i $RRD_ARGS \
  179. DS:value:GAUGE:$INTERVAL:-U:U \
  180. $RRA_SETUP
  181. echo "$i created"
  182. ;;
  183. mem.rrd)
  184. # Build memory file
  185. rrdtool create $i $RRD_ARGS \
  186. DS:real_active:GAUGE:$INTERVAL:0:U \
  187. DS:real_total:GAUGE:$INTERVAL:0:U \
  188. DS:free:GAUGE:$INTERVAL:0:U \
  189. DS:swap_used:GAUGE:$INTERVAL:0:U \
  190. DS:swap_total:GAUGE:$INTERVAL:0:U \
  191. $RRA_SETUP
  192. echo "$i created"
  193. ;;
  194. if_*.rrd)
  195. # Build interface files
  196. rrdtool create $i $RRD_ARGS \
  197. DS:ipackets:COUNTER:$INTERVAL:U:U DS:opackets:COUNTER:$INTERVAL:U:U \
  198. DS:ibytes:COUNTER:$INTERVAL:U:U DS:obytes:COUNTER:$INTERVAL:U:U \
  199. DS:imcasts:COUNTER:$INTERVAL:U:U DS:omcasts:COUNTER:$INTERVAL:U:U \
  200. DS:ierrors:COUNTER:$INTERVAL:U:U DS:oerrors:COUNTER:$INTERVAL:U:U \
  201. DS:collisions:COUNTER:$INTERVAL:U:U DS:drops:COUNTER:$INTERVAL:U:U \
  202. $RRA_SETUP
  203. echo "$i created"
  204. ;;
  205. debug.rrd)
  206. # Build debug file
  207. rrdtool create $i $RRD_ARGS \
  208. DS:debug0:GAUGE:$INTERVAL:U:U DS:debug1:GAUGE:$INTERVAL:U:U \
  209. DS:debug2:GAUGE:$INTERVAL:U:U DS:debug3:GAUGE:$INTERVAL:U:U \
  210. DS:debug4:GAUGE:$INTERVAL:U:U DS:debug5:GAUGE:$INTERVAL:U:U \
  211. DS:debug6:GAUGE:$INTERVAL:U:U DS:debug7:GAUGE:$INTERVAL:U:U \
  212. DS:debug8:GAUGE:$INTERVAL:U:U DS:debug9:GAUGE:$INTERVAL:U:U \
  213. DS:debug10:GAUGE:$INTERVAL:U:U DS:debug11:GAUGE:$INTERVAL:U:U \
  214. DS:debug12:GAUGE:$INTERVAL:U:U DS:debug13:GAUGE:$INTERVAL:U:U \
  215. DS:debug14:GAUGE:$INTERVAL:U:U DS:debug15:GAUGE:$INTERVAL:U:U \
  216. DS:debug16:GAUGE:$INTERVAL:U:U DS:debug17:GAUGE:$INTERVAL:U:U \
  217. DS:debug18:GAUGE:$INTERVAL:U:U DS:debug19:GAUGE:$INTERVAL:U:U \
  218. $RRA_SETUP
  219. echo "$i created"
  220. ;;
  221. proc_*.rrd)
  222. # Build proc file
  223. rrdtool create $i $RRD_ARGS \
  224. DS:number:GAUGE:$INTERVAL:0:U DS:uticks:GAUGE:$INTERVAL:0:U \
  225. DS:sticks:GAUGE:$INTERVAL:0:U DS:iticks:GAUGE:$INTERVAL:0:U \
  226. DS:cpusec:GAUGE:$INTERVAL:0:U DS:cpupct:GAUGE:$INTERVAL:0:100 \
  227. DS:procsz:GAUGE:$INTERVAL:0:U DS:rsssz:GAUGE:$INTERVAL:0:U \
  228. $RRA_SETUP
  229. echo "$i created"
  230. ;;
  231. pf.rrd)
  232. # Build pf file
  233. rrdtool create $i $RRD_ARGS \
  234. DS:bytes_v4_in:DERIVE:$INTERVAL:0:U DS:bytes_v4_out:DERIVE:$INTERVAL:0:U \
  235. DS:bytes_v6_in:DERIVE:$INTERVAL:0:U DS:bytes_v6_out:DERIVE:$INTERVAL:0:U \
  236. DS:packets_v4_in_pass:DERIVE:$INTERVAL:0:U DS:packets_v4_in_drop:DERIVE:$INTERVAL:0:U \
  237. DS:packets_v4_out_pass:DERIVE:$INTERVAL:0:U DS:packets_v4_out_drop:DERIVE:$INTERVAL:0:U \
  238. DS:packets_v6_in_pass:DERIVE:$INTERVAL:0:U DS:packets_v6_in_drop:DERIVE:$INTERVAL:0:U \
  239. DS:packets_v6_out_pass:DERIVE:$INTERVAL:0:U DS:packets_v6_out_drop:DERIVE:$INTERVAL:0:U \
  240. DS:states_entries:ABSOLUTE:$INTERVAL:0:U \
  241. DS:states_searches:DERIVE:$INTERVAL:0:U \
  242. DS:states_inserts:DERIVE:$INTERVAL:0:U \
  243. DS:states_removals:DERIVE:$INTERVAL:0:U \
  244. DS:counters_match:DERIVE:$INTERVAL:0:U \
  245. DS:counters_badoffset:DERIVE:$INTERVAL:0:U \
  246. DS:counters_fragment:DERIVE:$INTERVAL:0:U \
  247. DS:counters_short:DERIVE:$INTERVAL:0:U \
  248. DS:counters_normalize:DERIVE:$INTERVAL:0:U \
  249. DS:counters_memory:DERIVE:$INTERVAL:0:U \
  250. $RRA_SETUP
  251. echo "$i created"
  252. ;;
  253. mbuf.rrd)
  254. # Build mbuf file
  255. rrdtool create $i $RRD_ARGS \
  256. DS:totmbufs:GAUGE:$INTERVAL:0:U DS:mt_data:GAUGE:$INTERVAL:0:U \
  257. DS:mt_oobdata:GAUGE:$INTERVAL:0:U DS:mt_control:GAUGE:$INTERVAL:0:U \
  258. DS:mt_header:GAUGE:$INTERVAL:0:U DS:mt_ftable:GAUGE:$INTERVAL:0:U \
  259. DS:mt_soname:GAUGE:$INTERVAL:0:U DS:mt_soopts:GAUGE:$INTERVAL:0:U \
  260. DS:pgused:GAUGE:$INTERVAL:0:U DS:pgtotal:GAUGE:$INTERVAL:0:U \
  261. DS:totmem:GAUGE:$INTERVAL:0:U DS:totpct:GAUGE:$INTERVAL:0:100 \
  262. DS:m_drops:COUNTER:$INTERVAL:0:U DS:m_wait:COUNTER:$INTERVAL:0:U \
  263. DS:m_drain:COUNTER:$INTERVAL:0:U \
  264. $RRA_SETUP
  265. echo "$i created"
  266. ;;
  267. io_*.rrd)
  268. # Build disk files
  269. rrdtool create $i $RRD_ARGS \
  270. DS:transfers:COUNTER:$INTERVAL:U:U \
  271. DS:seeks:COUNTER:$INTERVAL:U:U \
  272. DS:bytes:COUNTER:$INTERVAL:U:U \
  273. $RRA_SETUP
  274. echo "$i created"
  275. ;;
  276. "done")
  277. # ignore
  278. ;;
  279. *)
  280. # Default match
  281. echo $i - unknown
  282. ;;
  283. esac
  284. done