How to monitor OpenVZ limits with vzwatchd on Debian and Ubuntu
Vzwatchd is an OpenVZ monitoring daemon that informs the server administrator by email when a limit of the container is reached. OpenVZ is a Linux Kernel virtualisation technology that is often used by Web Hosting services, it is the free core of the commercial virtuozzo virtualisation application. OpenVZ is a lightweight virtualisation which has less overhead then KVM or XEN, it is more like a Linux LXC jail but with advanced limit options to define how many ressources a virtual machine may use and it has support for filesystem quota.
This tutorial explains the installation and configuration of the vzwatchd daemon on Debian and Ubuntu.
1 Does my virtual server use OpenVZ
Have you rented a virtual server from a hosting company without knowing which virtualisation technology it uses? Run the following command to test if it uses OpenVZ:
cat /proc/user_beancounters
If the output is similar to the one below, then your server uses OpenVZ or a compatible technology and you can use vzwatchd to monitor the vserver.
root@www:/# cat /proc/user_beancounters
Version: 2.5
uid resource held maxheld barrier limit failcnt
101: kmemsize 190939926 274194432 9223372036854775807 9223372036854775807 0
lockedpages 0 3211 1048576 1048576 0
privvmpages 749006 781311 9223372036854775807 9223372036854775807 0
shmpages 22506 30698 9223372036854775807 9223372036854775807 0
dummy 0 0 9223372036854775807 9223372036854775807 0
numproc 237 312 9223372036854775807 9223372036854775807 0
physpages 486543 804959 0 1048576 0
vmguarpages 0 0 3145728 9223372036854775807 0
oomguarpages 233498 242378 1048576 9223372036854775807 0
numtcpsock 111 298 9223372036854775807 9223372036854775807 0
numflock 253 294 9223372036854775807 9223372036854775807 0
numpty 1 12 9223372036854775807 9223372036854775807 0
numsiginfo 0 33 9223372036854775807 9223372036854775807 0
tcpsndbuf 7083944 11209000 9223372036854775807 9223372036854775807 0
tcprcvbuf 3300832 10792248 9223372036854775807 9223372036854775807 0
othersockbuf 261256 1008400 9223372036854775807 9223372036854775807 0
dgramrcvbuf 0 5152 9223372036854775807 9223372036854775807 0
numothersock 166 526 1024 1024 0
dcachesize 168291899 247843839 9223372036854775807 9223372036854775807 0
numfile 3098 5205 9223372036854775807 9223372036854775807 0
dummy 0 0 9223372036854775807 9223372036854775807 0
dummy 0 0 9223372036854775807 9223372036854775807 0
dummy 0 0 9223372036854775807 9223372036854775807 0
numiptent 28 35 9223372036854775807 9223372036854775807 0
The output shows the limits of the virtual machine, each line describes one limit and the column that is watched by vzwatchd is the last column that counts how often a limit has been reached.
2 Install vzwatchd
Vzwatchd is written in Perl, it is downloaded and installed from Perl CPAN archive with the CPAN command.
Installing the prerequisites
I will do the following steps as root user, run sudo -s on Ubuntu to become root:
sudo -s
First I will install the make tool and the nano editor, make is used by CPAN to build vzwatchd and I will use nano later to edit the config file:
apt-get install make nano
Next I will install vzwatchd from CPAN with this command:
cpan -i App::OpenVZ::BCWatch
If this is the first time that you use CPAN on a server, the script will ask you a few questions about the basic CPAN configuration:
Would you like to configure as much as possible automatically? [yes]
Would you like me to automatically choose some CPAN mirror sites for you? (This means connecting to the Internet) [yes]
Answer both questions with "yes".
The installer will now download, compile and install a lot of Perl modules:
root@rz3:~# cpan -i App::OpenVZ::BCWatch
CPAN.pm requires configuration, but most of it can be done automatically.
If you answer 'no' below, you will enter an interactive dialog for each
configuration option instead.
Would you like to configure as much as possible automatically? [yes] yes
Autoconfigured everything but 'urllist'.
Now you need to choose your CPAN mirror sites. You can let me
pick mirrors for you, you can select them from a list or you
can enter them by hand.
Would you like me to automatically choose some CPAN mirror
sites for you? (This means connecting to the Internet) [yes] yes
Trying to fetch a mirror list from the Internet
Fetching with LWP:
http://www.perl.org/CPAN/MIRRORED.BY
Looking for CPAN mirrors near you (please be patient)
.............................. done!
New urllist
http://www.planet-elektronik.de/CPAN/
http://cpan.noris.de/
http://cpan.lnx.sk/
Autoconfiguration complete.
commit: wrote '/root/.cpan/CPAN/MyConfig.pm'
You can re-run configuration any time with 'o conf init' in the CPAN shell
Fetching with LWP:
http://www.planet-elektronik.de/CPAN/authors/01mailrc.txt.gz
Going to read '/root/.cpan/sources/authors/01mailrc.txt.gz'
............................................................................DONE
Fetching with LWP:
http://www.planet-elektronik.de/CPAN/modules/02packages.details.txt.gz
Going to read '/root/.cpan/sources/modules/02packages.details.txt.gz'
Database was generated on Mon, 13 Apr 2015 23:29:02 GMT
..............
New CPAN.pm version (v2.10) available.
[Currently running version is v1.960001]
You might want to try
install CPAN
reload cpan
to both upgrade CPAN.pm and run the new version without leaving
the current session.
[... snip ...]
CPAN.pm: Going to build G/GW/GWOLF/Config-File-1.50.tar.gz
Building Config-File
GWOLF/Config-File-1.50.tar.gz
./Build -- OK
Running Build test
t/pod.t ........... Subroutine main::all_pod_files_ok redefined at /usr/local/share/perl/5.14.2/Test/Pod.pm line 90.
t/pod.t ........... ok
t/pod_coverage.t .. ok
t/test.t .......... 1/11 Invalid characters in key to'be^ignored at line 10 - Ignoring at /root/.cpan/build/Config-File-1.50-NjLxod/blib/lib/Config/File.pm line 41, <GEN0> line 10.
Line format invalid at line 11: 'malformed line that should be also dropped (no equal sign)' at /root/.cpan/build/Config-File-1.50-NjLxod/blib/lib/Config/File.pm line 35, <GEN0> line 11.
t/test.t .......... ok
All tests successful.
Files=3, Tests=13, 0 wallclock secs ( 0.03 usr 0.00 sys + 0.13 cusr 0.02 csys = 0.18 CPU)
Result: PASS
GWOLF/Config-File-1.50.tar.gz
./Build test -- OK
Running Build install
Building Config-File
Installing /usr/local/share/perl/5.14.2/Config/File.pm
Installing /usr/local/man/man3/Config::File.3pm
GWOLF/Config-File-1.50.tar.gz
./Build install -- OK
Running Build for S/SC/SCHUBIGER/App-OpenVZ-BCWatch-0.04.tar.gz
Has already been unwrapped into directory /root/.cpan/build/App-OpenVZ-BCWatch-0.04-4Al97O
CPAN.pm: Going to build S/SC/SCHUBIGER/App-OpenVZ-BCWatch-0.04.tar.gz
Building App-OpenVZ-BCWatch
SCHUBIGER/App-OpenVZ-BCWatch-0.04.tar.gz
./Build -- OK
Running Build test
t/00-load.t ....... ok
t/basic.t ......... ok
t/pod-coverage.t .. ok
t/pod.t ........... ok
All tests successful.
Files=4, Tests=6, 0 wallclock secs ( 0.04 usr 0.01 sys + 0.27 cusr 0.04 csys = 0.36 CPU)
Result: PASS
SCHUBIGER/App-OpenVZ-BCWatch-0.04.tar.gz
./Build test -- OK
Running Build install
Building App-OpenVZ-BCWatch
Installing /usr/local/man/man1/vzwatchd.1p
Installing /usr/local/share/perl/5.14.2/App/OpenVZ/BCWatch.pm
Installing /usr/local/man/man3/App::OpenVZ::BCWatch.3pm
Installing /usr/local/bin/vzwatchd
SCHUBIGER/App-OpenVZ-BCWatch-0.04.tar.gz
./Build install -- OK
It is important that you see the line
./Build install -- OK
at the end of of the compile output. If you get an error instead, then rerun the command. I had to run the command twice to compile all modules successfully.
To check if the installation was successfull, run the command:
vzwatchd check
This will check the installation and create an example config file.
root@server:~# vzwatchd check
/etc/vzwatchd.conf does not exist, creating one with defaults.
Edit /etc/vzwatchd.conf to suit your needs and then start /usr/local/bin/vzwatchd again.
3 Configure and activate vzwatchd
Now I will edit the vzwatchd.conf file and set the email address for the notification messages.
nano /etc/vzwatchd.conf
The config file shall look like this after you edited it, just with your own email address off course.
mail[from] = [email protected]
mail[to] = [email protected]
mail[subject] = vzwatchd on server.example.com: NOTICE
sleep = 60
verbose = 0
monitor_fields = failcnt
_active = 1
The changes are:
- The line "mail[from]" contains the from address of the notification emails.
- The line "mail[to]" contains the email address that shall receive the notifications.
- The value in the line "_active" has to be changed to 1 to activate vzwatchd.
- When you run multiple OpenVZ servers then it might be handy to change "mail[subject]" to contain the server name.
Configure vzwatchd to start automatically when the server is booting:
vzwatchd install
root@server:~# vzwatchd install
+ /usr/sbin/update-rc.d vzwatchd defaults
update-rc.d: warning: /etc/init.d/vzwatchd missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
Adding system startup for /etc/init.d/vzwatchd ...
/etc/rc0.d/K20vzwatchd -> ../init.d/vzwatchd
/etc/rc1.d/K20vzwatchd -> ../init.d/vzwatchd
/etc/rc6.d/K20vzwatchd -> ../init.d/vzwatchd
/etc/rc2.d/S20vzwatchd -> ../init.d/vzwatchd
/etc/rc3.d/S20vzwatchd -> ../init.d/vzwatchd
/etc/rc4.d/S20vzwatchd -> ../init.d/vzwatchd
/etc/rc5.d/S20vzwatchd -> ../init.d/vzwatchd
And start the vzwatchd monitor daemon:
vzwatchd start
root@server:~# vzwatchd start
Starting /usr/local/bin/vzwatchd server
Now you will get notified by email when your OpenVZ virtual server reaches one of the limits of the OpenVZ container.