OpenVZ Monitoring · 6 min read · Oct 18, 2025

Comment surveiller les limites OpenVZ avec vzwatchd sur Debian et Ubuntu

Vzwatchd est un démon de surveillance OpenVZ qui informe l’administrateur du serveur par e-mail lorsqu’une limite du conteneur est atteinte. OpenVZ est une technologie de virtualisation du noyau Linux souvent utilisée par les services d’hébergement Web, c’est le noyau gratuit de l’application de virtualisation commerciale virtuozzo. OpenVZ est une virtualisation légère qui a moins de surcharge que KVM ou XEN, c’est plus comme une prison Linux LXC mais avec des options de limite avancées pour définir combien de ressources une machine virtuelle peut utiliser et il prend en charge le quota de système de fichiers.

Ce tutoriel explique l’installation et la configuration du démon vzwatchd sur Debian et Ubuntu.

1 Mon serveur virtuel utilise-t-il OpenVZ

Avez-vous loué un serveur virtuel auprès d’une société d’hébergement sans savoir quelle technologie de virtualisation elle utilise ? Exécutez la commande suivante pour tester s’il utilise OpenVZ :

cat /proc/user_beancounters

Si la sortie est similaire à celle ci-dessous, alors votre serveur utilise OpenVZ ou une technologie compatible et vous pouvez utiliser vzwatchd pour surveiller le 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

La sortie montre les limites de la machine virtuelle, chaque ligne décrit une limite et la colonne surveillée par vzwatchd est la dernière colonne qui compte combien de fois une limite a été atteinte.

2 Installer vzwatchd

Vzwatchd est écrit en Perl, il est téléchargé et installé à partir de l’archive CPAN de Perl avec la commande CPAN.

Installation des prérequis

Je vais effectuer les étapes suivantes en tant qu’utilisateur root, exécutez sudo -s sur Ubuntu pour devenir root :

sudo -s

Tout d’abord, j’installerai l’outil make et l’éditeur nano, make est utilisé par CPAN pour construire vzwatchd et j’utiliserai nano plus tard pour éditer le fichier de configuration :

apt-get install make nano

Ensuite, j’installerai vzwatchd à partir de CPAN avec cette commande :

cpan -i App::OpenVZ::BCWatch

Si c’est la première fois que vous utilisez CPAN sur un serveur, le script vous posera quelques questions sur la configuration de base de CPAN :

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]

Répondez aux deux questions par “yes”.

L’installateur va maintenant télécharger, compiler et installer de nombreux modules Perl :

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,  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,  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

Il est important que vous voyiez la ligne

./Build install -- OK

à la fin de la sortie de compilation. Si vous obtenez une erreur à la place, alors relancez la commande. J’ai dû exécuter la commande deux fois pour compiler tous les modules avec succès.

Pour vérifier si l’installation a réussi, exécutez la commande :

vzwatchd check

Cela vérifiera l’installation et créera un fichier de configuration exemple.

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 Configurer et activer vzwatchd

Maintenant, je vais éditer le fichier vzwatchd.conf et définir l’adresse e-mail pour les messages de notification.

nano /etc/vzwatchd.conf

Le fichier de configuration doit ressembler à ceci après que vous l’ayez modifié, juste avec votre propre adresse e-mail bien sûr.

mail[from] = [email protected]  
mail[to] = [email protected]  
mail[subject] = vzwatchd sur server.example.com : AVIS  
sleep = 60  
verbose = 0  
monitor_fields = failcnt  
_active = 1

Les modifications sont :

  • La ligne “mail[from]” contient l’adresse de l’expéditeur des e-mails de notification.
  • La ligne “mail[to]” contient l’adresse e-mail qui doit recevoir les notifications.
  • La valeur de la ligne “_active” doit être changée en 1 pour activer vzwatchd.
  • Lorsque vous exécutez plusieurs serveurs OpenVZ, il peut être utile de changer “mail[subject]” pour contenir le nom du serveur.

Configurez vzwatchd pour qu’il démarre automatiquement lorsque le serveur démarre :

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   
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

Et démarrez le démon de surveillance vzwatchd :

vzwatchd start
root@server:~# vzwatchd start  
Starting /usr/local/bin/vzwatchd server

Maintenant, vous serez notifié par e-mail lorsque votre serveur virtuel OpenVZ atteindra l’une des limites du conteneur OpenVZ.

Liens

  • OpenVZ
  • Vzwatchd
Share: X/Twitter LinkedIn

Recevez de nouveaux articles dans votre boîte de réception.

Aucun spam. Désabonnez-vous à tout moment.