c_smrrds.sh 8.7 KB

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