Freitag, 22. November 2013

Nagios: Überwachung eines ESX Clusters und Visualisierung

Wer einen ESX-Cluster im Hause hat, möchte sicherlich auch informiert werden, wenn dort etwas schief geht.

Dazu setze ich das Plugin check_esx3.pl von OP5 ein, dieses liefert, via Webschnittstelle, den Status für ein Datacenter, einzelne ESXi-Hosts oder virtuelle Maschinen.

Als Abhängigkeiten hat es folgende Perl Klassen: Nagios::Plugins, File::Basename und VMware::VIRuntime (muss separat über das Perl SDK von VMWare installiert werden: https://my.vmware.com/de/web/vmware/details?productId=285&downloadGroup=VSP510-SDKPERL-510 )

Überblick:

Usage: check_esx3.pl -D <data_center> | -H <host_name> [ -N <vm_name> ]

    -u <user> -p <pass> | -f <authfile>

    -l <command> [ -s <subcommand> ]

    [ -x <black_list> ] [ -o <additional_options> ]

    [ -t <timeout> ] [ -w <warn_range> ] [ -c <crit_range> ]

    [ -V ] [ -h ]



 -?, --usage

   Print usage information

 -h, --help

   Print detailed help screen

 -V, --version

   Print version information

 --extra-opts=[section][@file]

   Read options from an ini file. See http://nagiosplugins.org/extra-opts

   for usage and examples.

 -H, --host=<hostname>

   ESX or ESXi hostname.

 -C, --cluster=<clustername>

   ESX or ESXi clustername.

 -D, --datacenter=<DCname>

   Datacenter hostname.

 -N, --name=<vmname>

   Virtual machine name.

 -u, --username=<username>

   Username to connect with.

 -p, --password=<password>

   Password to use with the username.

 -f, --authfile=<path>

   Authentication file with login and password. File syntax :

   username=<login>

   password=<password>

 -w, --warning=THRESHOLD

   Warning threshold. See

   http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT

   for the threshold format.

 -c, --critical=THRESHOLD

   Critical threshold. See

   http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT

   for the threshold format.

 -l, --command=COMMAND

   Specify command type (CPU, MEM, NET, IO, VMFS, RUNTIME, ...)

 -s, --subcommand=SUBCOMMAND

   Specify subcommand

 -S, --sessionfile=SESSIONFILE

   Specify a filename to store sessions for faster authentication

 -x, --exclude=<black_list>

   Specify black list

 -o, --options=<additional_options>

   Specify additional command options

 -t, --timeout=INTEGER

   Seconds before plugin times out (default: 30)

 -v, --verbose

   Show details for command-line debugging (can repeat up to 3 times)

Supported commands(^ means blank or not specified parameter) :

    Common options for VM, Host and DC :

        * 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

            + 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

        * 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

        * io - shows disk io info

            + read - read latency in ms (totalReadLatency.average)

            + write - write latency in ms (totalWriteLatency.average)

            ^ all disk io info

        * runtime - shows runtime info

            + status - overall host status (gray/green/red/yellow)

            + issues - all issues for the host

            ^ all runtime info

    VM specific :

        * cpu - shows cpu info

            + wait - CPU wait time in ms

            + ready - CPU ready time in ms

        * mem - shows mem info

            + swapin - swapin mem usage in MB

            + swapout - swapout mem usage in MB

            + active - active mem usage in MB

        * io - shows disk I/O info

            + usage - overall disk usage in MB/s

        * runtime - shows runtime info

            + con - connection state

            + cpu - allocated CPU in MHz

            + mem - allocated mem in MB

            + state - virtual machine state (UP, DOWN, SUSPENDED)

            + consoleconnections - console connections to VM

            + guest - guest OS status, needs VMware Tools

            + tools - VMWare Tools status

    Host specific :

        * net - shows net info

            + nic - makes sure all active NICs are plugged in

        * io - shows disk io info

            + aborted - aborted commands count

            + resets - bus resets count

            + kernel - kernel latency in ms

            + device - device latency in ms

            + queue - queue latency in ms

        * vmfs - shows Datastore info

            + (name) - free space info for datastore with name (name)

            ^ all datastore info

        * runtime - shows runtime info

            + con - connection state

            + health - checks cpu/storage/memory/sensor status

            + maintenance - shows whether host is in maintenance mode

            + list(vm) - list of VMWare machines and their statuses

        * service - shows Host service info

            + (names) - check the state of one or several services specified by (names), syntax for (names):<service1>,<service2>,...,<serviceN>

            ^ show all services

        * storage - shows Host storage info

            + adapter - list bus adapters

            + lun - list SCSI logical units

            + path - list logical unit paths

    DC specific :

        * io - shows disk io info

            + aborted - aborted commands count

            + resets - bus resets count

            + kernel - kernel latency in ms

            + device - device latency in ms

            + queue - queue latency in ms

        * vmfs - shows Datastore info

            + (name) - free space info for datastore with name (name)

            ^ all datastore info

        * runtime - shows runtime info

            + list(vm) - list of VMWare machines and their statuses

            + listhost - list of VMWare esx host servers and their statuses

            + tools - VMWare Tools status

        * recommendations - shows recommendations for cluster

            + (name) - recommendations for cluster with name (name)

            ^ all clusters recommendations


Wie man sehen kann, lassen sich dort sehr viele Dinge überwachen, meiner Meinung nach sind Sachen wie die Auslastung (CPU, RAM, VMFS, IO, Netzwerk) und der Zustand von wichtigen VMs interessante Faktoren, die auf Probleme (Ausfälle, geringe Leistungskapazitäten, ...) hindeuten können.

Dazu hier eine typische commands.cfg:
 
define command {
        command_name    check_esxi_vm_list
        command_line    $USER1$/check_esx3.pl -D $ARG1$ -H $_HOSTESX_HOSTNAME$.DOMAIN.TLD -f $ARG2$ -l runtime -s list
}

define command {
        command_name    check_esxi_status
        command_line    $USER1$/check_esx3.pl -D $ARG1$ -H $_HOSTESX_HOSTNAME$.DOMAIN.TLD -f $ARG2$ -l runtime -s status
}

define command {
        command_name    check_esxi_io
        command_line    $USER1$/check_esx3.pl -D $ARG1$ -H $_HOSTESX_HOSTNAME$.DOMAIN.TLD -f $ARG2$ -l io
}

define command {
        command_name    check_esxi_vmfs
        command_line    $USER1$/check_esx3.pl -D $ARG1$ -H $_HOSTESX_HOSTNAME$.DOMAIN.TLD -f $ARG2$ -l vmfs -w 10%: -c 5%:
}

define command {
        command_name    check_esxi_cpu
        command_line    $USER1$/check_esx3.pl -D $ARG1$ -H $_HOSTESX_HOSTNAME$.DOMAIN.TLD -f $ARG2$ -l cpu -w 80 -c 90
}

define command {
        command_name    check_esxi_mem
        command_line    $USER1$/check_esx3.pl -D $ARG1$ -H $_HOSTESX_HOSTNAME$.DOMAIN.TLD -f $ARG2$ -l mem -w 80 -c 90
}

define command {
        command_name    check_esxi_net
        command_line    $USER1$/check_esx3.pl -D $ARG1$ -H $_HOSTESX_HOSTNAME$.DOMAIN.TLD -f $ARG2$ -l net
}

define command {
        command_name    check_esxi_vm_running
        command_line    $USER1$/check_esx3.pl -D $ARG1$ -H $_HOSTESX_HOSTNAME$.DOMAIN.TLD -f $ARG2$ -l runtime
}

define command {
        command_name    check_esxi_dc_running_hosts
        command_line    $USER1$/check_esx3.pl -D $ARG1$ -f $ARG2$ -l runtime -s listhost -c 8
}
define command {
        command_name    check_esxi_dc_vmfs
        command_line    $USER1$/check_esx3.pl -D $ARG1$ -f $ARG2$ -l vmfs -w 10%: -c 5%:
}

define command {
        command_name    check_esxi_dc
        command_line    $USER1$/check_esx3.pl -D $ARG1$ -f $ARG2$ -l runtime
}
define command {
        command_name    check_esxi_dc_net
        command_line    $USER1$/check_esx3.pl -D $ARG1$ -f $ARG2$ -l net
}

define command {
        command_name    check_esxi_dc_io
        command_line    $USER1$/check_esx3.pl -D $ARG1$ -f $ARG2$ -l io
}
define command {
        command_name    check_esxi_dc_cpu
        command_line    $USER1$/check_esx3.pl -D $ARG1$ -f $ARG2$ -l cpu
}

define command {
        command_name    check_esxi_dc_mem
        command_line    $USER1$/check_esx3.pl -D $ARG1$ -f $ARG2$ -l mem
}

In der commands.cfg verwende ich Custom Hostvariablen, da Hosts im Nagios normalerweise über die IP angelegt werden (keine DNS Abhängigkeit..) und die IPs dann natürlich nicht im Virtual Center matchen würden, diese Host Variablen kann man ganz einfach anlegen:
        _ESX_HOSTNAME                   esx2

Argument 1 muss die IP oder den Hostname des Virtual Centers enthalten, welcher die Abfragen für ein DataCenter bündeln kann.
Argument 2 wäre ein Authentifizierungsfile im Format, dabei ist Domain nur nötig, wenn man AD Authentifizierung nutzt:
username=foobar@domain.tld 

password=barfoo


Wenn die commands.cfg nun eingebunden ist, bietet es sich an eine Hostgruppe für die Veerbung der Service Checks einzurichten (Redundanzen vermeiden!) und dieser dann die ESXi Knoten zuweisen.


Nachdem nun die Service Checks eingerichtet wurden, kann die Überwachung beginnen.

Nun fehlt aber noch das i-Tüpfelchen: die Visualisierung der Auslastung über alle Hosts!

Dazu bediene ich mich dem großartigen PNP4Nagios (Achtung, bitte Version >= 0.6.x nutzen!), die Installation ist, durch die sehr gute Dokumentation, relativ einfach und schnell vollzogen.
Zum Start gibt es bereits ein Template, welches von OP5 im PNP4Nagios mitgeliefert wird.

Dieses unterstützt allerdings keine Multigraphen über mehrere Hosts, daher habe ich dafür eines selbst geschrieben, welches dann so aussieht:



Der grüne Balken ist ein Ticker und zeigt dort direkt Grün, Gelb, Rot an, wenn einer der Hosts ein Problem hat, also die Thresholds überschritten wurden.

Das Template bekommt ihr hier und muss in den templates.special Ordner (z.B: /usr/share/pnp4nagios/templates.special) abgelegt und geringfügig angepasst werden:

Hostnames unterstützen RegEx (z.B. 'esx' => esx1,esx2,...,esxN) oder arrays, falls die Namen kein gleiches Muster haben (array("host1","clusternode2","clusterhost1").
Die ServiceNames (in meinem Fall: ESXi_XXX) müssen genau passen, damit das Special Template funktionieren kann.

Bei Unsicherheiten kann man aber auch einfach die Zeilen "throw new Kohana_exception(print_r($data,TRUE));" auskommentieren und das Template über /pnp4nagios/special anschließend aufrufen, damit werden alle verfügbaren Daten ausgegeben.

$services = $this->tplGetServices("HOST_NAMES",  "SERVICE_NAME")
In Zeile: 12 (CPU), 37 (RAM), 60 (Network)


Wenn nun das Template in dem entsprechenden Ordner abgelegt ist, wird beim Aufruf des PNP4Nagios ein neuer "S" Button auf der rechten Seiten erscheinen, wenn man den auswählt, sollte das neue Template aufgelistet bzw. schon geöffnet sein.

Falls nicht, bitte die Pfade, Berechtigungen und Endung (.php!) überprüfen.


Et voila, die Überwachung der ESXi-Hosts / DataCenter ist eingerichtet und wird in Farbe und bunt angezeigt.