6,534
edits
Changes
use headings in →Scripting: to better organize contents; some minor spelling fixes
Here are some scripting ideas
<pre>
host2:~/bin# cat vz-all-running
</pre>
<pre>
host2:~/bin# cat vz-all-running-ip
</pre>
<pre>
host2:~/bin# cat vz-iptables-create-rules
</pre>
Please use crontab to run this script once per hour or day to collect your traffic statistics.
<pre>
# reset the counter
iptables -Z
# update the ip table iptables rules if there is a any change in vz'sVEs
./vz-iptables-create-rules
# copy the trafficlog file to a webserver where users can take see their traffic
# please mind to use
# ssh-keygen -t rsa
# to generate ssh keys
# and append the new public key from your hardware node (~/.ssh/id_rsa.pub)
# to ~/.ssh/authorized_keys2 on the HOST-TO-SHOW-THE-TRAFFIC-TO-THE-USERS
# in order for the below scp command to not ask for root password
scp $trafficlog USER@HOST-TO-SHOW-THE-TRAFFIC-TO-THE-USERS:/var/www/OPENVZ-CONTROL-WEB-SITE/tmp/$HOSTNAME-traffic
</pre>
<pre>
HOST-TO-SHOW-THE-TRAFFIC-TO-THE-USERS:/var/www/OPENVZ-CONTROL-WEB-SITE# cat traffic-read.php
</pre>
=== A SQL querry query to get the traffic for the last 30 days===
<pre>
SELECT sum(bytes)
</pre>
=== Notes === As you see this way can be time-consuming in case of a big number of VEs.
So if anybody has scripts that automate all the process — you are welcome!
[[Category: HOWTO]]
[[Category: Networking]]