c_smrrds.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. #!/bin/sh
  2. # $Id: c_smrrds.sh,v 1.30 2005/03/20 16:17:22 dijkstra Exp $
  3. #
  4. # Copyright (c) 2001-2005 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. OS=`uname -s`
  34. # addsuffix adds a suffix to each entry of a list (item|item|...)
  35. addsuffix() {
  36. list=$1'|'
  37. suffix=$2
  38. while [ `echo $list | grep '|'` ]; do
  39. newlist=$newlist'|'`echo $list | cut -f1 -d\|`$suffix
  40. list=`echo $list | cut -f2- -d\|`
  41. done
  42. echo $newlist | cut -b2-
  43. }
  44. create_rrd() {
  45. file=$1
  46. shift
  47. rrdtool create $file $RRD_ARGS $* $RRA_SETUP
  48. if [ "$?" = "0" -a -f $file ]; then
  49. echo "$file created"
  50. else
  51. echo "could not create $file"
  52. fi
  53. }
  54. # get arguments
  55. select_interval=""
  56. for i
  57. do
  58. case $i in
  59. interval)
  60. select_interval="yes"
  61. ;;
  62. child)
  63. child=1
  64. ;;
  65. oneday)
  66. config=$i
  67. # today only RRA setup:
  68. # - 1 day of 5 second samples = 17280 x 5 second samples
  69. RRA_SETUP=" RRA:AVERAGE:0.5:1:17280
  70. RRA:MAX:0.5:1:17280
  71. RRA:MIN:0.5:1:17280"
  72. if [ X"$child" = "X" ]; then
  73. echo "RRDs will only contain a single day of data"
  74. fi
  75. ;;
  76. *)
  77. if [ -n "$select_interval" ]; then
  78. INTERVAL=$i
  79. select_interval=""
  80. else
  81. args="$args $i"
  82. fi
  83. ;;
  84. esac
  85. done
  86. if [ X"$RRA_SETUP" = "X" ]; then
  87. # default RRA setup:
  88. # - 2 days of 5 second samples = 34560 x 5 second samples
  89. # - 14 days of 30 minutes samples = 672 x 360 x 5 second samples
  90. # - 50 days of 2 hour samples = 600 x 1440 x 5 second samples
  91. # - 600 days of 1 day samples = 600 x 17280 x 5 second samples
  92. RRA_SETUP=" RRA:AVERAGE:0.5:1:34560
  93. RRA:AVERAGE:0.5:360:672
  94. RRA:AVERAGE:0.5:1440:600
  95. RRA:AVERAGE:0.5:17280:600
  96. RRA:MAX:0.5:1:34560
  97. RRA:MAX:0.5:360:672
  98. RRA:MAX:0.5:1440:600
  99. RRA:MAX:0.5:17280:600
  100. RRA:MIN:0.5:1:34560
  101. RRA:MIN:0.5:360:672
  102. RRA:MIN:0.5:1440:600
  103. RRA:MIN:0.5:17280:600"
  104. fi
  105. # All interfaces and disks
  106. case ${OS} in
  107. FreeBSD)
  108. DISKS="ad|acd|afd|ast|sa|da|ar|cd|ch|md"
  109. INTERFACES="an|ar|ath|aue|awi|axe|bfe|bge|cm|cnw|cs|cue|dc|de|ed|el|em|ep|ex|fe|fwe|fxp|gem|gx|hme|ie|kue|lge|lnc|my|nge|pcn|ray|re|rl|rue|sf|sis|sk|sn|snc|ste|ti|tl|tx|txp|vge|vr|vx|wb|wi|xe|xl";
  110. VIRTUALINTERFACES="bridge|carp|enc|faith|gif|ppp|sl|sppp|strip|tun|vlan";
  111. diskcmd="mount | sed -n '/^\/dev/ s,/dev/\([a-z]*[0-9]\).*,\1,p' | sort -u"
  112. interfacecmd="ifconfig -l | sed 's/lo0//'"
  113. ;;
  114. Linux)
  115. DISKS="hda|hdb|hdc|hdd|sda|sdb|sdc|sdd"
  116. INTERFACES="eth"
  117. VIRTUALINTERFACES="sit"
  118. diskcmd="mount | sed -n '/^\/dev/ s,/dev/\([a-z]*[0-9]\).*,\1,p' | sort -u"
  119. interfacecmd="ifconfig -a| egrep -e \"^(\$INTERFACES) \" | cut -f1 -d\ | sort -u"
  120. ;;
  121. OpenBSD)
  122. DISKS="sd|cd|ch|rd|raid|ss|uk|vnc|wd"
  123. 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"
  124. VIRTUALINTERFACES="bridge|carp|enc|faith|gif|ppp|sppp|strip|tun|vlan";
  125. diskcmd="mount | sed -n '/^\/dev/ s,/dev/\([a-z]*[0-9]\).*,\1,p' | sort -u"
  126. interfacecmd="ifconfig -a| egrep -e \"^(\$INTERFACES):\" | cut -f1 -d\: | sort -u"
  127. ;;
  128. NetBSD)
  129. DISKS="sd|cd|ch|rd|raid|ss|uk|vnc|wd"
  130. INTERFACES="ai|an|ate|ath|atw|awi|bce|bge|bicc|cnw|com|cs|depca|ec|ef|eg|el|elmc|en|ep|epic|esh|ex|fea|fmv|fpa|fxp|gsip|hme|ipw|iwi|ix|iy|lc|le|lmc|mbe|mhzc|mtd|ne|nele|ntwoc|pcn|ray|re|rtk|sf|sip|sk|skc|sm|ste|stge|ti|tl|tlp|tr|vge|vr|we|wi|wm|xi|xirc"
  131. VIRTUALINTERFACES="bridge|carp|enc|faith|gif|ppp|sppp|sl|strip|tun|vlan";
  132. diskcmd="mount | sed -n '/^\/dev/ s,/dev/\([a-z]*[0-9]\).*,\1,p' | sort -u"
  133. interfacecmd="ifconfig -l | sed 's/lo0//'"
  134. ;;
  135. esac
  136. DISKS=`addsuffix $DISKS [0-9]`
  137. INTERFACES=`addsuffix $INTERFACES [0-9]`
  138. VIRTUALINTERFACES=`addsuffix $VIRTUALINTERFACES \\.\\*`
  139. this=$0
  140. if [ X"$1$2$3$4$5$6$7$8$9" = "X" ]; then
  141. cat <<EOF
  142. Create rrd files for symux.
  143. Usage: `basename $0` [oneday] [interval <seconds>] all | cpu0 | mem |
  144. pf | pfq_<queue> | mbuf | debug | proc_<process> |
  145. <if> | <io> | sensor[0-25]
  146. Where:
  147. oneday = modify rrds to only contain one day of information
  148. seconds = modify rrds for non standard monitoring interval
  149. process = the name of a process as specified in sy{mon,mux}.conf
  150. e.g. proc(httpd) -> proc_httpd
  151. queue = the name of a queue as specified in sy{mon,mux}.conf
  152. e.g. pfq(root) -> pfq_root
  153. if= `echo $INTERFACES|
  154. awk 'BEGIN {FS="|"}
  155. {for (i=1; i<=NF; i++) {
  156. printf("%s|",$i);
  157. if ((i%6)==0) {
  158. printf("%s","\n\t")
  159. }
  160. }
  161. print " ";}'`
  162. io= `echo $DISKS|
  163. awk 'BEGIN {FS="|"}
  164. {for (i=1; i<=NF; i++) {
  165. printf("%s|",$i);
  166. if ((i%6)==0) {
  167. printf("%s","\n\t")
  168. }
  169. }
  170. print " ";}'`
  171. OpenBSD pre-3.5 disk statistics are available via the io1_<disk> argument.
  172. EOF
  173. exit 1;
  174. fi
  175. for i in $args
  176. do
  177. # add if_*.rrd if it is an interface
  178. if [ `echo $i | egrep -e "^($INTERFACES)$"` ]; then i=if_$i.rrd; fi
  179. if [ `echo $i | egrep -e "^($VIRTUALINTERFACES)$"` ]; then i=if_$i.rrd; fi
  180. # add io_*.rrd if it is a disk
  181. if [ `echo $i | egrep -e "^($DISKS)$"` ]; then i=io_$i.rrd; fi
  182. # add .rrd if it is a cpu, etc.
  183. if [ `echo $i | egrep -e "^(cpu[0-9]$|mem$|pf$|pfq_|mbuf$|debug$|proc_|sensor[0-9]$|sensor[0-9][0-9]$|io1_)"` ]; then i=$i.rrd; fi
  184. if [ -f $i ]; then
  185. echo "$i exists - ignoring"
  186. i="done"
  187. fi
  188. RRD_ARGS="--step=$INTERVAL --start=0"
  189. case $i in
  190. all)
  191. echo "Creating rrd files for {cpu0|mem|disks|interfaces|pf|mbuf}"
  192. sh $this interval $INTERVAL child $config cpu0 mem
  193. sh $this interval $INTERVAL child $config interfaces
  194. sh $this interval $INTERVAL child $config disks
  195. sh $this interval $INTERVAL child $config pf
  196. sh $this interval $INTERVAL child $config mbuf
  197. ;;
  198. if|interfaces)
  199. # obtain all network cards
  200. sh $this child $config `eval $interfacecmd`
  201. ;;
  202. io|disks)
  203. # obtain all disks
  204. sh $this child $config `eval $diskcmd`
  205. ;;
  206. cpu[0-9].rrd)
  207. # Build cpu file
  208. create_rrd $i \
  209. DS:user:GAUGE:$INTERVAL:0:100 \
  210. DS:nice:GAUGE:$INTERVAL:0:100 \
  211. DS:system:GAUGE:$INTERVAL:0:100 \
  212. DS:interrupt:GAUGE:$INTERVAL:0:100 \
  213. DS:idle:GAUGE:$INTERVAL:0:100
  214. ;;
  215. sensor*.rrd)
  216. # Build sensor file
  217. create_rrd $i \
  218. DS:value:GAUGE:$INTERVAL:-U:U
  219. ;;
  220. mem.rrd)
  221. # Build memory file
  222. create_rrd $i \
  223. DS:real_active:GAUGE:$INTERVAL:0:U \
  224. DS:real_total:GAUGE:$INTERVAL:0:U \
  225. DS:free:GAUGE:$INTERVAL:0:U \
  226. DS:swap_used:GAUGE:$INTERVAL:0:U \
  227. DS:swap_total:GAUGE:$INTERVAL:0:U
  228. ;;
  229. if_*.rrd)
  230. # Build interface files
  231. create_rrd $i \
  232. DS:ipackets:COUNTER:$INTERVAL:U:U DS:opackets:COUNTER:$INTERVAL:U:U \
  233. DS:ibytes:COUNTER:$INTERVAL:U:U DS:obytes:COUNTER:$INTERVAL:U:U \
  234. DS:imcasts:COUNTER:$INTERVAL:U:U DS:omcasts:COUNTER:$INTERVAL:U:U \
  235. DS:ierrors:COUNTER:$INTERVAL:U:U DS:oerrors:COUNTER:$INTERVAL:U:U \
  236. DS:collisions:COUNTER:$INTERVAL:U:U DS:drops:COUNTER:$INTERVAL:U:U
  237. ;;
  238. debug.rrd)
  239. # Build debug file
  240. create_rrd $i \
  241. DS:debug0:GAUGE:$INTERVAL:U:U DS:debug1:GAUGE:$INTERVAL:U:U \
  242. DS:debug2:GAUGE:$INTERVAL:U:U DS:debug3:GAUGE:$INTERVAL:U:U \
  243. DS:debug4:GAUGE:$INTERVAL:U:U DS:debug5:GAUGE:$INTERVAL:U:U \
  244. DS:debug6:GAUGE:$INTERVAL:U:U DS:debug7:GAUGE:$INTERVAL:U:U \
  245. DS:debug8:GAUGE:$INTERVAL:U:U DS:debug9:GAUGE:$INTERVAL:U:U \
  246. DS:debug10:GAUGE:$INTERVAL:U:U DS:debug11:GAUGE:$INTERVAL:U:U \
  247. DS:debug12:GAUGE:$INTERVAL:U:U DS:debug13:GAUGE:$INTERVAL:U:U \
  248. DS:debug14:GAUGE:$INTERVAL:U:U DS:debug15:GAUGE:$INTERVAL:U:U \
  249. DS:debug16:GAUGE:$INTERVAL:U:U DS:debug17:GAUGE:$INTERVAL:U:U \
  250. DS:debug18:GAUGE:$INTERVAL:U:U DS:debug19:GAUGE:$INTERVAL:U:U
  251. ;;
  252. proc_*.rrd)
  253. # Build proc file
  254. create_rrd $i \
  255. DS:number:GAUGE:$INTERVAL:0:U DS:uticks:COUNTER:$INTERVAL:0:U \
  256. DS:sticks:COUNTER:$INTERVAL:0:U DS:iticks:COUNTER:$INTERVAL:0:U \
  257. DS:cpusec:GAUGE:$INTERVAL:0:U DS:cpupct:GAUGE:$INTERVAL:0:100 \
  258. DS:procsz:GAUGE:$INTERVAL:0:U DS:rsssz:GAUGE:$INTERVAL:0:U
  259. ;;
  260. pf.rrd)
  261. # Build pf file
  262. create_rrd $i \
  263. DS:bytes_v4_in:DERIVE:$INTERVAL:0:U DS:bytes_v4_out:DERIVE:$INTERVAL:0:U \
  264. DS:bytes_v6_in:DERIVE:$INTERVAL:0:U DS:bytes_v6_out:DERIVE:$INTERVAL:0:U \
  265. DS:packets_v4_in_pass:DERIVE:$INTERVAL:0:U DS:packets_v4_in_drop:DERIVE:$INTERVAL:0:U \
  266. DS:packets_v4_out_pass:DERIVE:$INTERVAL:0:U DS:packets_v4_out_drop:DERIVE:$INTERVAL:0:U \
  267. DS:packets_v6_in_pass:DERIVE:$INTERVAL:0:U DS:packets_v6_in_drop:DERIVE:$INTERVAL:0:U \
  268. DS:packets_v6_out_pass:DERIVE:$INTERVAL:0:U DS:packets_v6_out_drop:DERIVE:$INTERVAL:0:U \
  269. DS:states_entries:GAUGE:$INTERVAL:0:U \
  270. DS:states_searches:DERIVE:$INTERVAL:0:U \
  271. DS:states_inserts:DERIVE:$INTERVAL:0:U \
  272. DS:states_removals:DERIVE:$INTERVAL:0:U \
  273. DS:counters_match:DERIVE:$INTERVAL:0:U \
  274. DS:counters_badoffset:DERIVE:$INTERVAL:0:U \
  275. DS:counters_fragment:DERIVE:$INTERVAL:0:U \
  276. DS:counters_short:DERIVE:$INTERVAL:0:U \
  277. DS:counters_normalize:DERIVE:$INTERVAL:0:U \
  278. DS:counters_memory:DERIVE:$INTERVAL:0:U
  279. ;;
  280. pfq_*.rrd)
  281. # Build pfq file
  282. create_rrd $i \
  283. DS:sent_bytes:COUNTER:$INTERVAL:0:U \
  284. DS:sent_packets:COUNTER:$INTERVAL:0:U \
  285. DS:drop_bytes:COUNTER:$INTERVAL:0:U \
  286. DS:drop_packets:COUNTER:$INTERVAL:0:U
  287. ;;
  288. mbuf.rrd)
  289. # Build mbuf file
  290. create_rrd $i \
  291. DS:totmbufs:GAUGE:$INTERVAL:0:U DS:mt_data:GAUGE:$INTERVAL:0:U \
  292. DS:mt_oobdata:GAUGE:$INTERVAL:0:U DS:mt_control:GAUGE:$INTERVAL:0:U \
  293. DS:mt_header:GAUGE:$INTERVAL:0:U DS:mt_ftable:GAUGE:$INTERVAL:0:U \
  294. DS:mt_soname:GAUGE:$INTERVAL:0:U DS:mt_soopts:GAUGE:$INTERVAL:0:U \
  295. DS:pgused:GAUGE:$INTERVAL:0:U DS:pgtotal:GAUGE:$INTERVAL:0:U \
  296. DS:totmem:GAUGE:$INTERVAL:0:U DS:totpct:GAUGE:$INTERVAL:0:100 \
  297. DS:m_drops:COUNTER:$INTERVAL:0:U DS:m_wait:COUNTER:$INTERVAL:0:U \
  298. DS:m_drain:COUNTER:$INTERVAL:0:U
  299. ;;
  300. io_*.rrd)
  301. # Build disk files
  302. create_rrd $i \
  303. DS:rxfer:COUNTER:$INTERVAL:U:U \
  304. DS:wxfer:COUNTER:$INTERVAL:U:U \
  305. DS:seeks:COUNTER:$INTERVAL:U:U \
  306. DS:rbytes:COUNTER:$INTERVAL:U:U \
  307. DS:wbytes:COUNTER:$INTERVAL:U:U
  308. ;;
  309. io1_*.rrd)
  310. # Build disk files
  311. create_rrd $i \
  312. DS:transfers:COUNTER:$INTERVAL:U:U \
  313. DS:seeks:COUNTER:$INTERVAL:U:U \
  314. DS:bytes:COUNTER:$INTERVAL:U:U
  315. ;;
  316. "done")
  317. # ignore
  318. ;;
  319. *)
  320. # Default match
  321. echo $i - unknown
  322. ;;
  323. esac
  324. done