6,534
edits
Changes
categorized; removed unneeded 'code' tags, use -H in vzlist; get rid of first-level headings
|}
==Introduction==Traffic accounting in OpenVZ can be done through data collection against <code>/proc/net/dev </code> in the individual VEs on a HN.
==Prerequisites== * OpenVZ * RRDTool * Gnu GNU AWK
==Script==
First create a directory to store your RRD files:
# mkdir /var/lib/rrd/
#!/bin/sh
# Script Name: vz_direct_traffic_log
# Time to do the data collection.
for veid in `/usr/sbin/vzlist -o veid | grep -v VEID H | sed 's/ //g'`; do
RRDFILE="/var/lib/rrd/$veid.rrd"
awk -F: '{print $2}' | awk '{printf"VEIN=%-15d\nVEOUT=%-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:$VEIN:$VEOUT
done
==Setup==
Add this to cron to run every 5 minutes:
To check the output of this later run:
# rrdtool fetch /var/lib/rrd/<veid>.rrd AVERAGE -s -3600