Nagios : Surveillance VMware ESXi et vSphere

Cet article décrit comment surveiller un hôte VMWare ESXi ou vSphere avec Nagios, en utilisant le plugin OP5 Check ESX écrit en PERL.

Ce plugin peut surveiller aussi bien un unique serveur ESXi/vSphere, du VirtualCenter/vCenter Server et des machines virtuelles individuelles. Ici nous allons voir comment surveiller un hôte ESXi 4.

Ce tutoriel a été fait sur une machine CentOS, il sera peut-etre nécessaire d’adpater certains chemins pour votre distribution.

Installation

Les pré-requis pour faire fonctionner ce plugin est d’installer le VMWare Perl SDK disponible sur le site de l’éditeur.
Téléchargez le fichier sur la machine, par exemple dans le répertoire root, décompressez-le et lancez l’installateur comme ceci :

# cd /root
# tar xvzf VMware-vSphere-Perl-SDK-4.1.0-254719.i386.tar.gz 
# cd vmware-vsphere-cli-distrib/
# ./vmware-install.pl

Suivre les instructions données par le script. Suivant votre configuration, certaines dépendances PERL devront etre installées pour que le SDK fonctionne correctement. Lorsque ceci est fait, nous pouvons obtenir le plugin ici, et le copier dans /usr/lib/nagios/plugins/. Le rendre exécutable :

# cd /usr/lib/nagios/plugins/
# chmod a+x check_esx



Configuration

Maintenant, la réelle configuration de Nagios peut commencer. Nous avons besoin d’un nom d’utilisateur et d’un mot de passe pour accèder à l’hôte ESXi, nous allons les définir dans des variables dans le fichier /etc/nagios/resource.cfg plus sécurisé, car ces informations restent cachées des CGIs :

$USER11$=username
$USER12$=password

Dans ce tutoriel, les ressources suivantes vont etre surveillées : CPU, memory usage, net usage, runtime status et IO/read/write. Mais beaucoup d’autres sont disponibles, voir les références ici. Ci-dessous les nouvelles commandes relatives à ESXi à ajouter dans /etc/nagios/objects/command.cfg (sont affichées ici uniquement les commandes pour ESXi, et non le code complet du fichier command.cfg, vous devez donc les ajouter en fin de fichier) :

# Surveiller une machine vmware esxi
# cpu
define command{
        command_name check_esx_cpu
        command_line $USER1$/check_esx -H $HOSTADDRESS$ \
			-u $USER11$ -p $USER12$ -l cpu -s usage -w $ARG1$ -c $ARG2$
        }

# memory usage
define command{
        command_name check_esx_mem
        command_line $USER1$/check_esx -H $HOSTADDRESS$ \
			-u $USER11$ -p $USER12$ -l mem -s usage -w $ARG1$ -c $ARG2$
        }

# net usage
define command{
        command_name check_esx_net
        command_line $USER1$/check_esx -H $HOSTADDRESS$ \
			-u $USER11$ -p $USER12$ -l net -s usage -w $ARG1$ -c $ARG2$
        }

# runtime status
define command{
        command_name check_esx_runtime
        command_line $USER1$/check_esx -H $HOSTADDRESS$ \
			-u $USER11$ -p $USER12$ -l runtime -s status
        }

# io read
define command{
        command_name check_esx_ioread
        command_line $USER1$/check_esx -H $HOSTADDRESS$ \
			-u $USER11$ -p $USER12$ -l io -s read -w $ARG1$ -c $ARG2$
        }

# io write
define command{
        command_name check_esx_iowrite
        command_line $USER1$/check_esx -H $HOSTADDRESS$ \
			-u $USER11$ -p $USER12$ -l io -s write -w $ARG1$ -c $ARG2$
        }

Et un exemple de configuration pour un hôte Nagios appellé esxi01 sous /etc/nagios/hosts/esxi01.cfg :

# Machine esx01
define host{
        use                     linux-server
        host_name               esxi01
        alias                   VMWare ESXi 01
        address                 192.168.1.100
        }

# Définit un service pour "pinger" la machine locale
define service{
        use                             generic-service
        host_name                       esxi01
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        }

# Surveillance VMWare
# cpu
define service{
        use                             generic-service
        host_name                       esxi01
        service_description             ESXi CPU Load
        check_command                   check_esx_cpu!80!90
        }

# memory usage
define service{
        use                             generic-service
        host_name                       esxi01
        service_description             ESXi Memory usage
        check_command                   check_esx_mem!80!90
        }

# net usage
define service{
        use                             generic-service
        host_name                       esxi01
        service_description             ESXi Network usage
        check_command                   check_esx_net!102400!204800
        }

# runtime status
define service{
        use                             generic-service
        host_name                       esxi01
        service_description             ESXi Runtime status
        check_command                   check_esx_runtime
        }

# io read
define service{
        use                             generic-service
        host_name                       esxi01
        service_description             ESXi IO read
        check_command                   check_esx_ioread!40!90
        }

# io write
define service{
        use                             generic-service
        host_name                       esxi01
        service_description             ESXi IO write
        check_command                   check_esx_iowrite!40!90
        }

Voilà, c’est terminé. Il suffit de re-démarrer Nagios et de patienter quelques instants (ou de faire un re-schedule) pour voir la surveillance des nouvelles ressources active.

Nagios


Note : cet article existait déjà en langue anglaise sur ce site, il s’agit juste de sa traduction dans la langue de Molière ^.^

8 thoughts on “Nagios : Surveillance VMware ESXi et vSphere”

  1. Excellent tuto disons plutot bonne traduction.
    J’apporte quelques petits détails pour certaines choses

    Pour ceux par hasard qui on un problème pour faire fonctionner le script. Si sur votre interface graphique de nagios il y a marqué « null » lors du check des services c’est qu’il vous manque plusieurs choses.

    Il faut installer CPAM.
    Ensuite lancer dans un terminal la commande :

    cpan
    Maintenant vous avez un nouveau terminal commençant par cpan >. Il faut maintenant taper :

    install Class::Accessor
    install Config::Tiny
    install Math::Calc::Units
    Params::Validate
    Nagios::Plugin

    Et voilà maintenant c’est ok.

    Pour choisir le plugin prendre celui là :
    check_esx.pl: Added support for Proxy Switches

    Ensuite sur la nouvelle page en petit sous du texte en haut il y marquer check_esx3.pl
    Il faut cliquer dessus.
    Puis en rouge toujours en haut sur check_esx3.pl faire clique droit puis enregistrer la cible du lien sous …

    Voilà, il faut mettre ce plugin que vous allez renommer en check_esx dans /usr/local/nagios/libexec enfin tout dépend de votre config.

  2. Bonsoir,
    Merci pour le tuto mais moi je bute sur un autre problème. Mes ESXi sont tous sur clé USB dans les serveurs. Je décompresse du coup le SDK dans l’espace dédié aux images ISO et aux vms pour ne pas « bouffer » de la place sur la clé mais pas de Perl dans le système pour exécuter l’installation. Ou alors je n’ai pas compris le truc ?
    C’est bien sur le système ESXi qu’il faut installer le SDK ou sur le serveur de monitoring ?
    Merci

    1. Finalement, je me le suis installé sur le serveur de monitoring … et çà marche après pas mal d’installation via CPAN de toutes les dépendances ! Mais au moins, rien à faire sur les ESXi ! Merci

      1. Oui l’installation est à faire sur le serveur de monitoring, on ne touche pas aux ESXi.
        Content que tout fonctionne pour toi.

  3. Autre chose, maintenant que tout roule pour moi grâce au check_esx. Comment remonter les infos des disques durs : etat du Raid, présence du hot spare, état des disques ? une idée ?

  4. Super tuto! Merci beaucoup!

    J’ai eu un léger blocage donc si ça peut aider : sur les check disk, un « -c 100000 » definit un max, pour definir un min, il faut « -c 100000: »

    source du script alternatif :
    http://exchange.nagios.org/directory/Plugins/Operating-Systems/*-Virtual-Environments/VMWare/check_vmware_api/details

    Pour tout avoir sur une page : liste des commandes compatibles ( meme si un -h permet de les avoir) :

    Usage: check_vmware_api.pl -D | -H [ -C ] [ -N ]
    -u -p | -f
    -l [ -s ] [ -T ] [ -i ]
    [ -x ] [ -o ]
    [ -t ] [ -w ] [ -c ]
    [ -V ] [ -h ]

    VM specific :
    * cpu – shows cpu info
    + usage – CPU usage in percentage
    + usagemhz – CPU usage in MHz
    + wait – CPU wait time in ms
    + ready – CPU ready time in ms
    ^ all cpu info(no thresholds)
    * mem – shows mem info
    + usage – mem usage in percentage
    + usagemb – mem usage in MB
    + swap – swap mem usage in MB
    + swapin – swapin mem usage in MB
    + swapout – swapout mem usage in MB
    + overhead – additional mem used by VM Server in MB
    + overall – overall mem used by VM Server in MB
    + active – active mem usage in MB
    + memctl – mem used by VM memory control driver(vmmemctl) that controls ballooning
    ^ all mem info(except overall and no thresholds)
    * net – shows net info
    + usage – overall network usage in KBps(Kilobytes per Second)
    + receive – receive in KBps(Kilobytes per Second)
    + send – send in KBps(Kilobytes per Second)
    ^ all net info(except usage and no thresholds)
    * io – shows disk I/O info
    + usage – overall disk usage in MB/s
    + read – read latency in ms (totalReadLatency.average)
    + write – write latency in ms (totalWriteLatency.average)
    ^ all disk io info(no thresholds)
    * runtime – shows runtime info
    + con – connection state
    + cpu – allocated CPU in MHz
    + mem – allocated mem in MB
    + state – virtual machine state (UP, DOWN, SUSPENDED)
    + status – overall object status (gray/green/red/yellow)
    + consoleconnections – console connections to VM
    + guest – guest OS status, needs VMware Tools
    + tools – VMWare Tools status
    + issues – all issues for the host
    ^ all runtime info(except con and no thresholds)
    Host specific :
    * cpu – shows cpu info
    + usage – CPU usage in percentage
    o quickstats – switch for query either PerfCounter values or Runtime info
    + usagemhz – CPU usage in MHz
    o quickstats – switch for query either PerfCounter values or Runtime info
    ^ all cpu info
    o quickstats – switch for query either PerfCounter values or Runtime info
    * mem – shows mem info
    + usage – mem usage in percentage
    o quickstats – switch for query either PerfCounter values or Runtime info
    + usagemb – mem usage in MB
    o quickstats – switch for query either PerfCounter values or Runtime info
    + swap – swap mem usage in MB
    o listvm – turn on/off output list of swapping VM’s
    + overhead – additional mem used by VM Server in MB
    + overall – overall mem used by VM Server in MB
    + memctl – mem used by VM memory control driver(vmmemctl) that controls ballooning
    o listvm – turn on/off output list of ballooning VM’s
    ^ all mem info(except overall and no thresholds)
    * net – shows net info
    + usage – overall network usage in KBps(Kilobytes per Second)
    + receive – receive in KBps(Kilobytes per Second)
    + send – send in KBps(Kilobytes per Second)
    + nic – makes sure all active NICs are plugged in
    ^ all net info(except usage and no thresholds)
    * io – shows disk io info
    + aborted – aborted commands count
    + resets – bus resets count
    + read – read latency in ms (totalReadLatency.average)
    + write – write latency in ms (totalWriteLatency.average)
    + kernel – kernel latency in ms
    + device – device latency in ms
    + queue – queue latency in ms
    ^ all disk io info
    * vmfs – shows Datastore info
    + (name) – free space info for datastore with name (name)
    o used – output used space instead of free
    o breif – list only alerting volumes
    o regexp – whether to treat name as regexp
    o blacklistregexp – whether to treat blacklist as regexp
    b – blacklist VMFS’s
    T (value) – timeshift to detemine if we need to refresh
    ^ all datastore info
    o used – output used space instead of free
    o breif – list only alerting volumes
    o blacklistregexp – whether to treat blacklist as regexp
    b – blacklist VMFS’s
    T (value) – timeshift to detemine if we need to refresh
    * runtime – shows runtime info
    + con – connection state
    + health – checks cpu/storage/memory/sensor status
    o listitems – list all available sensors(use for listing purpose only)
    o blackregexpflag – whether to treat blacklist as regexp
    b – blacklist status objects
    + storagehealth – storage status check
    o blackregexpflag – whether to treat blacklist as regexp
    b – blacklist status objects
    + temperature – temperature sensors
    o blackregexpflag – whether to treat blacklist as regexp
    b – blacklist status objects
    + sensor – threshold specified sensor
    + maintenance – shows whether host is in maintenance mode
    + list(vm) – list of VMWare machines and their statuses
    + status – overall object status (gray/green/red/yellow)
    + issues – all issues for the host
    b – blacklist issues
    ^ all runtime info(health, storagehealth, temperature and sensor are represented as one value and no thresholds)
    * service – shows Host service info
    + (names) – check the state of one or several services specified by (names), syntax for (names):,,…,
    ^ show all services
    * storage – shows Host storage info
    + adapter – list bus adapters
    b – blacklist adapters
    + lun – list SCSI logical units
    b – blacklist LUN’s
    + path – list logical unit paths
    b – blacklist paths
    ^ show all storage info
    * uptime – shows Host uptime
    o quickstats – switch for query either PerfCounter values or Runtime info
    * device – shows Host specific device info
    + cd/dvd – list vm’s with attached cd/dvd drives
    o listall – list all available devices(use for listing purpose only)
    DC specific :
    * cpu – shows cpu info
    + usage – CPU usage in percentage
    o quickstats – switch for query either PerfCounter values or Runtime info
    + usagemhz – CPU usage in MHz
    o quickstats – switch for query either PerfCounter values or Runtime info
    ^ all cpu info
    o quickstats – switch for query either PerfCounter values or Runtime info
    * mem – shows mem info
    + usage – mem usage in percentage
    o quickstats – switch for query either PerfCounter values or Runtime info
    + usagemb – mem usage in MB
    o quickstats – switch for query either PerfCounter values or Runtime info
    + swap – swap mem usage in MB
    + overhead – additional mem used by VM Server in MB
    + overall – overall mem used by VM Server in MB
    + memctl – mem used by VM memory control driver(vmmemctl) that controls ballooning
    ^ all mem info(except overall and no thresholds)
    * net – shows net info
    + usage – overall network usage in KBps(Kilobytes per Second)
    + receive – receive in KBps(Kilobytes per Second)
    + send – send in KBps(Kilobytes per Second)
    ^ all net info(except usage and no thresholds)
    * io – shows disk io info
    + aborted – aborted commands count
    + resets – bus resets count
    + read – read latency in ms (totalReadLatency.average)
    + write – write latency in ms (totalWriteLatency.average)
    + kernel – kernel latency in ms
    + device – device latency in ms
    + queue – queue latency in ms
    ^ all disk io info
    * vmfs – shows Datastore info
    + (name) – free space info for datastore with name (name)
    o used – output used space instead of free
    o breif – list only alerting volumes
    o regexp – whether to treat name as regexp
    o blacklistregexp – whether to treat blacklist as regexp
    b – blacklist VMFS’s
    T (value) – timeshift to detemine if we need to refresh
    ^ all datastore info
    o used – output used space instead of free
    o breif – list only alerting volumes
    o blacklistregexp – whether to treat blacklist as regexp
    b – blacklist VMFS’s
    T (value) – timeshift to detemine if we need to refresh
    * runtime – shows runtime info
    + list(vm) – list of VMWare machines and their statuses
    + listhost – list of VMWare esx host servers and their statuses
    + listcluster – list of VMWare clusters and their statuses
    + tools – VMWare Tools status
    b – blacklist VM’s
    + status – overall object status (gray/green/red/yellow)
    + issues – all issues for the host
    b – blacklist issues
    ^ all runtime info(except cluster and tools and no thresholds)
    * recommendations – shows recommendations for cluster
    + (name) – recommendations for cluster with name (name)
    ^ all clusters recommendations
    Cluster specific :
    * cpu – shows cpu info
    + usage – CPU usage in percentage
    + usagemhz – CPU usage in MHz
    ^ all cpu info
    * mem – shows mem info
    + usage – mem usage in percentage
    + usagemb – mem usage in MB
    + swap – swap mem usage in MB
    o listvm – turn on/off output list of swapping VM’s
    + memctl – mem used by VM memory control driver(vmmemctl) that controls ballooning
    o listvm – turn on/off output list of ballooning VM’s
    ^ all mem info(plus overhead and no thresholds)
    * cluster – shows cluster services info
    + effectivecpu – total available cpu resources of all hosts within cluster
    + effectivemem – total amount of machine memory of all hosts in the cluster
    + failover – VMWare HA number of failures that can be tolerated
    + cpufainess – fairness of distributed cpu resource allocation
    + memfainess – fairness of distributed mem resource allocation
    ^ only effectivecpu and effectivemem values for cluster services
    * runtime – shows runtime info
    + list(vm) – list of VMWare machines in cluster and their statuses
    + listhost – list of VMWare esx host servers in cluster and their statuses
    + status – overall cluster status (gray/green/red/yellow)
    + issues – all issues for the cluster
    b – blacklist issues
    ^ all cluster runtime info
    * vmfs – shows Datastore info
    + (name) – free space info for datastore with name (name)
    o used – output used space instead of free
    o breif – list only alerting volumes
    o regexp – whether to treat name as regexp
    o blacklistregexp – whether to treat blacklist as regexp
    b – blacklist VMFS’s
    T (value) – timeshift to detemine if we need to refresh
    ^ all datastore info
    o used – output used space instead of free
    o breif – list only alerting volumes
    o blacklistregexp – whether to treat blacklist as regexp
    b – blacklist VMFS’s
    T (value) – timeshift to detemine if we need to refresh

    Copyright (c) 2008 op5

  5. Bonjour,

    Merci pour ce bon tuto bien détaillé.
    J’utilise ce plugin depuis un petit moment mais j’ai quelques erreurs aléatoire. Plusieurs fois dans la journée j’ai un message d’erreur et le service passe en CRITICAL : SOAP request error – possibly a protocol issue: 500 Can’t read entity body: Resource temporarily unavailable. Ceci ce produit sur mes 4 esxi.
    Mes ESXi sont en version 4.1 update 2
    Quelqu’un aurait t’il une idée?

    Merci.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *