Révision 2f76334c
Initial version
| plugins/other/ipfwcnt_ | ||
|---|---|---|
| 1 |
#!/bin/sh |
|
| 2 |
# |
|
| 3 |
# Copyright (C) 2009 Alexey Illarionov <littlesavage@rambler.ru> |
|
| 4 |
# |
|
| 5 |
# Wildcard plugin to monitor ipfw rules counters |
|
| 6 |
# Usage: |
|
| 7 |
# |
|
| 8 |
# Method 1: |
|
| 9 |
# |
|
| 10 |
# Link ipfwcnt_<rule number> to this file. E.g. |
|
| 11 |
# |
|
| 12 |
# ln -s ipfwcnt_ ipfwcnt_100 |
|
| 13 |
# |
|
| 14 |
# ... will monitror ipfw rule 100 |
|
| 15 |
# |
|
| 16 |
# Method 2: |
|
| 17 |
# |
|
| 18 |
# 1. Add count rules to ipfw E.g. |
|
| 19 |
# |
|
| 20 |
# ipfw add 100 count ip from any to table(1,0) in via rl0 |
|
| 21 |
# ipfw add 200 count ip from any to table(1,1) in via rl0 |
|
| 22 |
# ipfw add 300 count ip from any to table(1,2) in via rl0 |
|
| 23 |
# ipfw add 400 count ip from any to not table(1) in via rl0 |
|
| 24 |
# |
|
| 25 |
# 2. Link ipfwcnt_<name> to this file. E.g. |
|
| 26 |
# ln -s ipfwcnt_ ipfwcnt_rl0-in |
|
| 27 |
# |
|
| 28 |
# 3. Add rules configuration to plugins.conf: |
|
| 29 |
# [ipfwcnt_rl0-in] |
|
| 30 |
# user root |
|
| 31 |
# env rules group0 group1 group2 nogroup |
|
| 32 |
# env rule_group0 100 |
|
| 33 |
# env rule_group0_label group0 |
|
| 34 |
# env rule_group0_info Incoming traffic of group 0 |
|
| 35 |
# env rule_group1 200 |
|
| 36 |
# env rule_group1_label group1 |
|
| 37 |
# env rule_group1_info Incoming traffic of group 1 |
|
| 38 |
# env rule_group2 300 |
|
| 39 |
# env rule_group2_label group2 |
|
| 40 |
# env rule_group2_info Incoming traffic of group 2 |
|
| 41 |
# env rule_nogroup 400 |
|
| 42 |
# env rule_nogroup_label nogroup |
|
| 43 |
# env rule_nogroup_info Incoming traffic of no group |
|
| 44 |
# |
|
| 45 |
# ... will monitor ipfw rules 100,200,300,400 |
|
| 46 |
# |
|
| 47 |
# This plugin needs to be run as root. |
|
| 48 |
# |
|
| 49 |
# Magic markers (optional - used by munin-config and some installation |
|
| 50 |
# scripts): |
|
| 51 |
# |
|
| 52 |
#%# family=manual |
|
| 53 |
|
|
| 54 |
NAME=`basename $0 | sed 's/^ipfwcnt_//g'` |
|
| 55 |
|
|
| 56 |
if [ -z "$rules" ]; then |
|
| 57 |
if [ -z "$NAME" ]; then exit 1; fi |
|
| 58 |
rules="r$NAME" |
|
| 59 |
eval "rule_r$NAME=$NAME" |
|
| 60 |
fi |
|
| 61 |
|
|
| 62 |
if [ "$1" = "config" ]; then |
|
| 63 |
echo "graph_title Ipfw rules counters $NAME" |
|
| 64 |
echo 'graph_args --base 1000 -l 0' |
|
| 65 |
echo 'graph_vlabel bits / ${graph_period}'
|
|
| 66 |
echo 'graph_category network' |
|
| 67 |
draw="AREA" |
|
| 68 |
for rule in $rules; do |
|
| 69 |
eval "label0=\$rule_${rule}_label"
|
|
| 70 |
eval "info0=\$rule_${rule}_info"
|
|
| 71 |
label=${label0:-$rule}
|
|
| 72 |
info=${info0:-$rule}
|
|
| 73 |
|
|
| 74 |
echo "$rule.label $label" |
|
| 75 |
echo "$rule.draw $draw" |
|
| 76 |
echo "$rule.type DERIVE" |
|
| 77 |
echo "$rule.min 0" |
|
| 78 |
echo "$rule.cdef $rule,8,*" |
|
| 79 |
echo "$rule.info $info" |
|
| 80 |
|
|
| 81 |
draw="STACK" |
|
| 82 |
done |
|
| 83 |
|
|
| 84 |
echo "graph_info Ipfw rules counters $NAME" |
|
| 85 |
exit 0 |
|
| 86 |
fi |
|
| 87 |
|
|
| 88 |
for rule in $rules; do |
|
| 89 |
eval "num=\$rule_$rule" |
|
| 90 |
if [ -z $(echo "$num" | sed 's/[0-9]//g') ]; then |
|
| 91 |
val0=$(/sbin/ipfw show $num 2>/dev/null | awk '{res+=$3;} END{print res;}')
|
|
| 92 |
fi |
|
| 93 |
val=${val0:-"U"}
|
|
| 94 |
echo "$rule.value $val" |
|
| 95 |
done |
|
| 96 |
|
|
Formats disponibles : Unified diff