Editing Traffic accounting through proc
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 22: | Line 22: | ||
# Author: "Brian Harrington, Alticon Inc" <bharrington@alticon.net> | # Author: "Brian Harrington, Alticon Inc" <bharrington@alticon.net> | ||
# Website: htty://www.alticon.net | # Website: htty://www.alticon.net | ||
− | |||
# Time to do the data collection. | # Time to do the data collection. | ||
− | for veid in | + | for veid in `/usr/sbin/vzlist -o veid -H | sed 's/ //g'`; do |
− | |||
− | |||
− | |||
− | |||
− | + | RRDFILE="/var/lib/rrd/$veid.rrd" | |
− | + | ||
− | + | if ! test -e $RRDFILE; then | |
− | + | echo $RRDFILE does not exist, creating. | |
− | + | # Place your preferred RRD Creation command here | |
− | + | fi | |
− | + | ||
− | + | # Parse out the inbound/outbound traffic and assign them to the corresponding variables | |
− | + | eval `/usr/sbin/vzctl exec $veid "grep venet0 /proc/net/dev" | \ | |
− | + | awk -F: '{print $2}' | awk '{printf"CTIN=%-15d\nCTOUT=%-15d\n", $1, $9}'` | |
− | + | ||
− | + | # Send the data to the corresponding RRD time with (N)now as the update time | |
− | + | /usr/bin/rrdtool update $RRDFILE N:$CTIN:$CTOUT | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
done | done | ||
</source> | </source> | ||
== Setup == | == Setup == | ||
− | Add this to cron to run | + | Add this to cron to run every 5 minutes: |
− | # cat | + | # cat "*/5 * * * * root /path/to/script/vz_direct_traffic_log " > \ |
− | + | /etc/crontab && /etc/init.d/crontab restart | |
− | |||
− | |||
To check the output of this later run: | To check the output of this later run: | ||
Line 98: | Line 55: | ||
* [[Traffic accounting with iptables]] | * [[Traffic accounting with iptables]] | ||
− | |||
[[Category: Monitoring]] | [[Category: Monitoring]] | ||
[[Category: Networking]] | [[Category: Networking]] |