Date: Sun, 08 Aug 2010 19:56:54 +0100 From: Matthew Seaman <m.seaman@infracaninophile.co.uk> To: freebsd-questions@freebsd.org Subject: Re: Connection Bandwidth Metering? Message-ID: <4C5EFDF6.9080305@infracaninophile.co.uk> In-Reply-To: <4C5EF1A2.6000407@telting.org> References: <4C5EF1A2.6000407@telting.org>
next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig4A431AD167879313C08E6B04 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 08/08/2010 19:04:18, Chris Telting wrote: > I have my own Virtual Private Server (VPS) and was wondering what is th= e > most straightforward to meter my own connection? It depends on exactly what type of VPS you have. If it's a Xen domU host, or running under VMWare or VirtualBox, then it should be fairly simple to access the byte counters kept by the network interfaces -- SNMP is the obvious way to do it -- or you can use firewall rules to match various different types of traffic and keep counters that way. Then you'll need to run a cron job that grabs this data and saves it away at regular intervals -- every 5 minutes is fairly typical. You can then calculate the average bandwidth usage for a 5 minute sampling period by working out the difference between two adjacent samples (ie. no of bytes sent/received during that 5 minutes) and then multiply by 8 / (5 * 60) to get the result in bits/s You'll have to work out how to deal with missing samples, with the counters rolling over and with counters being set to zero at reboot, puls storing a reasonable number of samples for doing your calculations in an efficient way; all of which suggests that simply using one of the available graphing programs would probably save you a deal of effort. If your VPS is more like a FreeBSD jail, then you may need the cooperation of whoever controls the host system to produce appropriate stats. > I would like to email notices to myself of excessive bandwidth usage as= > well as take steps that limit a DOS attack or Slashdot effect on the > webserver. I would also like the metering to be persistent as possible= > across reboots. Not really looking for full logging or to do graphs > yet, just want the current metered bandwidth. What counts as 'excessive'? Bandwidth usage tends by it's nature to be pretty bursty. A common billing method is to calculate the 95% percentile rate over a month -- ie. order the per-5minute bandwidth samples from largest to smallest, discard the top 5% and then charge you for the next highest value. Use 1Mb/s for 4.999% of the time, and 20kb/s the rest, and you'll only be charged for 20kb/s. Use 1Mb/s for 5.001% of the time, and you'll be charged for 1Mb/s for the whole month. Very tricky to put together an alerting system that behaves intelligently under such conditions, and that doesn't send you hundreds of false alarms However, you can use QoS bandwidth shaping to prevent your ever using up too much bandwidth. See dummynet(4) {use with ipfw} or altq(4) {use with pf}. These work to some extent by delaying traffic so that instantaneous bandwidth usage stays within some preset bounds. You can also arrange to reserve bandwidth for other services than your webserver, which helps with the Slashdot effect. Cheers, Matthew --=20 Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard Flat 3 PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate JID: matthew@infracaninophile.co.uk Kent, CT11 9PW --------------enig4A431AD167879313C08E6B04 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.14 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkxe/f4ACgkQ8Mjk52CukIweCgCfRSNFxl9zyEjHdvwtVXxGrKp/ M2wAniPvndAmQEpn3ICnxKFYTaqf6Ri2 =DAKP -----END PGP SIGNATURE----- --------------enig4A431AD167879313C08E6B04--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4C5EFDF6.9080305>