c_monrrds.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #!/bin/sh
  2. # $Id: c_monrrds.sh,v 1.9 2002/08/29 19:38:56 dijkstra Exp $
  3. #
  4. # Copyright (c) 2001-2002 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. # mon 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. # --- user configuration starts here
  36. INTERVAL=`grep MON_INTERVAL ../mon/mon.h 2>/dev/null | cut -f3 -d\ `
  37. INTERVAL=${INTERVAL:-5}
  38. # RRA setup:
  39. # - 2 days of 5 second samples = 34560 x 5 second samples
  40. # - 14 days of 30 minutes samples = 672 x 360 x 5 second samples
  41. # - 50 days of 2 hour samples = 600 x 1440 x 5 second samples
  42. # - 600 days of 1 day samples = 600 x 17280 x 5 second samples
  43. RRA_SETUP=" RRA:AVERAGE:0.5:1:34560
  44. RRA:AVERAGE:0.5:360:672
  45. RRA:AVERAGE:0.5:1440:600
  46. RRA:AVERAGE:0.5:17280:600
  47. RRA:MAX:0.5:1:34560
  48. RRA:MAX:0.5:360:672
  49. RRA:MAX:0.5:1440:600
  50. RRA:MAX:0.5:17280:600
  51. RRA:MIN:0.5:1:34560
  52. RRA:MIN:0.5:360:672
  53. RRA:MIN:0.5:1440:600
  54. RRA:MIN:0.5:17280:600"
  55. # --- user configuration ends here
  56. # All interfaces and disks
  57. INTERFACES="an|awi|be|bge|bm|bridge|cnw|dc|de|ec|ef|eg|el|enc|ep|ex|faith|fea|fpa|fxp|gem|gif|gm|gre|hme|ie|kue|lc|le|lge|lmc|lo|ne|ne|nge|ray|rl|ppp|qe|qec|sf|sis|sk|skc|sl|sm|siop|sppp|ste|stge|strip|ti|tl|tr|tun|tx|txp|vlan|vme|vr|wb|we|wi|wx|xe|xl"
  58. DISKS="sd|cd|ch|rd|raid|ss|uk|vnc|wd"
  59. # addsuffix adds a suffix to each entry of a list (item|item|...)
  60. addsuffix() {
  61. list=$1'|'
  62. suffix=$2
  63. while [ `echo $list | grep '|'` ]; do
  64. newlist=$newlist'|'`echo $list | cut -f1 -d\|`$suffix
  65. list=`echo $list | cut -f2- -d\|`
  66. done
  67. echo $newlist | cut -b2-
  68. }
  69. this=$0
  70. if [ X"$1$2$3$4$5$6$7$8$9" == "X" ]; then
  71. sh $this help
  72. exit 1;
  73. fi
  74. DISKS=`addsuffix $DISKS [0-9]`
  75. INTERFACES=`addsuffix $INTERFACES [0-9]`
  76. for i
  77. do
  78. # add if_*.rrd if it is an interface
  79. if [ `echo $i | egrep -e "^($INTERFACES)$"` ]; then i=if_$i.rrd; fi
  80. # add io_*.rrd if it is a disk
  81. if [ `echo $i | egrep -e "^($DISKS)$"` ]; then i=io_$i.rrd; fi
  82. # add .rrd if it is a cpu or mem
  83. if [ `echo $i | egrep -e "^(cpu[0-9]|mem|pf)$"` ]; then i=$i.rrd; fi
  84. if [ -f $i ]; then
  85. echo "$i exists - ignoring"
  86. i="done"
  87. fi
  88. case $i in
  89. all)
  90. echo "Creating rrd files for {cpu0|mem|disks|interfaces|pf}"
  91. sh $this cpu0 mem
  92. sh $this interfaces
  93. sh $this disks
  94. sh $this pf
  95. ;;
  96. if|interfaces)
  97. # obtain all network cards
  98. sh $this `ifconfig -a| egrep -e "^($INTERFACES):" | cut -f1 -d\: | sort -u`
  99. ;;
  100. io|disks)
  101. # obtain all disks
  102. sh $this `df | grep dev | sed 's/^\/dev\/\(.*\)[a-z] .*$/\1/' | sort -u`
  103. ;;
  104. cpu[0-9].rrd)
  105. # Build cpu file
  106. rrdtool create $i --step=$INTERVAL \
  107. DS:user:GAUGE:5:0:100 \
  108. DS:nice:GAUGE:5:0:100 \
  109. DS:system:GAUGE:5:0:100 \
  110. DS:interrupt:GAUGE:5:0:100 \
  111. DS:idle:GAUGE:5:0:100 \
  112. $RRA_SETUP
  113. echo "$i created"
  114. ;;
  115. mem.rrd)
  116. # Build memory file
  117. rrdtool create $i --step=$INTERVAL \
  118. DS:real_active:GAUGE:5:0:U \
  119. DS:real_total:GAUGE:5:0:U \
  120. DS:free:GAUGE:5:0:U \
  121. DS:swap_used:GAUGE:5:0:U \
  122. DS:swap_total:GAUGE:5:0:U \
  123. $RRA_SETUP
  124. echo "$i created"
  125. ;;
  126. if_*.rrd)
  127. # Build interface files
  128. rrdtool create $i --step=$INTERVAL \
  129. DS:ipackets:COUNTER:5:U:U DS:opackets:COUNTER:5:U:U \
  130. DS:ibytes:COUNTER:5:U:U DS:obytes:COUNTER:5:U:U \
  131. DS:imcasts:COUNTER:5:U:U DS:omcasts:COUNTER:5:U:U \
  132. DS:ierrors:COUNTER:5:U:U DS:oerrors:COUNTER:5:U:U \
  133. DS:collisions:COUNTER:5:U:U DS:drops:COUNTER:5:U:U \
  134. $RRA_SETUP
  135. echo "$i created"
  136. ;;
  137. pf.rrd)
  138. # Build pf file
  139. rrdtool create $i --step=$INTERVAL \
  140. DS:bytes_v4_in:DERIVE:5:0:U DS:bytes_v4_out:DERIVE:5:0:U \
  141. DS:bytes_v6_in:DERIVE:5:0:U DS:bytes_v6_out:DERIVE:5:0:U \
  142. DS:packets_v4_in_pass:DERIVE:5:0:U DS:packets_v4_in_drop:DERIVE:5:0:U \
  143. DS:packets_v4_out_pass:DERIVE:5:0:U DS:packets_v4_out_drop:DERIVE:5:0:U \
  144. DS:packets_v6_in_pass:DERIVE:5:0:U DS:packets_v6_in_drop:DERIVE:5:0:U \
  145. DS:packets_v6_out_pass:DERIVE:5:0:U DS:packets_v6_out_drop:DERIVE:5:0:U \
  146. DS:states_entries:ABSOLUTE:5:0:U \
  147. DS:states_searches:DERIVE:5:0:U \
  148. DS:states_inserts:DERIVE:5:0:U \
  149. DS:states_removals:DERIVE:5:0:U \
  150. DS:counters_match:DERIVE:5:0:U \
  151. DS:counters_badoffset:DERIVE:5:0:U \
  152. DS:counters_fragment:DERIVE:5:0:U \
  153. DS:counters_short:DERIVE:5:0:U \
  154. DS:counters_normalize:DERIVE:5:0:U \
  155. DS:counters_memory:DERIVE:5:0:U \
  156. $RRA_SETUP
  157. echo "$i created"
  158. ;;
  159. io_*.rrd)
  160. # Build disk files
  161. rrdtool create $i --step=$INTERVAL \
  162. DS:transfers:COUNTER:5:U:U \
  163. DS:seeks:COUNTER:5:U:U \
  164. DS:bytes:COUNTER:5:U:U \
  165. $RRA_SETUP
  166. echo "$i created"
  167. ;;
  168. "done")
  169. # ignore
  170. ;;
  171. *)
  172. # Default match
  173. cat <<EOF
  174. Usage: $0 all
  175. $0 cpu0|mem|<if>|<io>
  176. Where:
  177. if= `echo $INTERFACES|
  178. awk 'BEGIN {FS="|"}
  179. {for (i=1; i<=NF; i++) {
  180. printf("%s|",$i);
  181. if ((i%6)==0) {
  182. printf("%s","\n ")
  183. }
  184. }
  185. print " ";}'`
  186. io= `echo $DISKS|
  187. awk 'BEGIN {FS="|"}
  188. {for (i=1; i<=NF; i++) {
  189. printf("%s|",$i);
  190. if ((i%6)==0) {
  191. printf("%s","\n ")
  192. }
  193. }
  194. print " ";}'`
  195. EOF
  196. ;;
  197. esac
  198. done