diff --git a/README-DEBUGGING.md b/README-DEBUGGING.md new file mode 100644 index 0000000..05135f6 --- /dev/null +++ b/README-DEBUGGING.md @@ -0,0 +1,121 @@ +# Zabbix Template Linux Collectd_libvirt - DEEP DIVE AND DEBUG MANUAL + +## How it works + +* zabbix-agent calls collect-libvirt-handler.pl script + +* collect-libvirt-handler.pl calls collectd service over unixsocket + +* * after transforms zabbix-item's names (keys) to libvirt's names (unixsocket format) + +* * after reads values and return data back to zabbix-agent + +If you have in zabbix name with key: collectd-libvirt.cpu["instance-00000841-virt_cpu_total"], +zabbix runs external command: sudo /etc/zabbix/scripts/collectd-libvirt/collect-libvirt-handler.pl /var/run/collectd-unixsock GETVAL instance-00000841-virt_cpu_total +and and should return number :) + +## Example workflow + +* You should be see in zabbix server this items + +``` + collectd-libvirt.disk-ops-read[serve.lordcritical-disk-vda] + collectd-libvirt.disk-ops-write[serve.lordcritical-disk-vda] + collectd-libvirt.disk-oct-read[serve.lordcritical-disk-vda] + collectd-libvirt.disk-oct-write[serve.lordcritical-disk-vda] + collectd-libvirt.cpu[serve.lordcritical-virt_cpu_total] +(and network items...) +``` + +* after this $command variable should be (...handler.pl): + +``` +GETVAL serve.lordcritical/libvirt/disk_ops-vda OPS-READ +GETVAL serve.lordcritical/libvirt/disk_ops-vda OPS-WRITE +GETVAL serve.lordcritical/libvirt/disk_octets-vda OCT-READ +GETVAL serve.lordcritical/libvirt/disk_octets-vda OCT-WRITE +GETVAL serve.lordcritical/libvirt/virt_cpu_total +``` + +* and into collectd unixsocket arrive queries + +``` +GETVAL serve.lordcritical/libvirt/disk_ops-vda +GETVAL serve.lordcritical/libvirt/disk_octets-vda +GETVAL serve.lordcritical/libvirt/virt_cpu_total +``` + +## Example of Discovery results + +https://github.com/czhujer/Zabbix-Template-Linux-Collectd_libvirt/blob/master/docs-examples/example-discovery-result.md + + +## DEBUG + +* install template https://github.com/czhujer/Zabbix-Template-Linux-Collectd_libvirt + +* check if script collect-libvirt-handler.pl works + +* uncomment line 45 + + (print "DEBUG: command: " . $command . " val: " . $val . " \n";) + +* check results .. + + +~~~ +with zabbix key: collectd-libvirt.cpu["instance-00000841-virt_cpu_total"] +debug output shlould by: +DEBUG: command: GETVAL instance-00000841/libvirt/virt_cpu_total val: instance-00000841/libvirt/virt_cpu_total +2000000 +~~~ + +* if dont have, download exmaple script for collectd unixsocket communication.. + +``` + [root@localhost]# wget https://raw.githubusercontent.com/collectd/collectd/master/contrib/cussh.pl +``` + +* run example script + +``` + [root@localhost]# ./cussh.pl or ./cussh.pl /var/run/collectd-unixsock +``` + +* send command from $command value into cussh shel.. + +``` +cussh> GETVAL instance-00000841/libvirt/virt_cpu_total + ns: 2000000 +``` + +* check if this number is same as returns collect-libvirt-handler.pl + + +### DEBUG items name + +simillar like a DEBUG + +* run commnad "LISTVAL" in cussh shel.. + +``` +cussh> LISTVAL + +1413985396 instance-00000935/libvirt/disk_octets-vda +1413985396 instance-00000935/libvirt/disk_ops-vda +1413985396 instance-00000935/libvirt/if_dropped-tap869d29b8-08 +1413985396 instance-00000935/libvirt/if_errors-tap869d29b8-08 +1413985396 instance-00000935/libvirt/if_octets-tap869d29b8-08 +1413985396 instance-00000935/libvirt/if_packets-tap869d29b8-08 +1413985396 instance-00000935/libvirt/virt_cpu_total +1413985396 instance-00000935/libvirt/virt_vcpu-0 +1413985396 instance-00000935/libvirt/virt_vcpu-1 +``` + +* modify script collect-libvirt-handler.pl like that, so print to the same things as you see in LISTVAL part... + +LINES 21 - 24 is for "cpu_total" + +LINES 25 - 33 is for "disk stats" + +LINES 34 - 41 is for "networks stats" diff --git a/README.md b/README.md index f3a32b8..22e419b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,15 @@ A Zabbix templates for libvirt stats -Tested on: +Version 1.4.0 and higher are tested on: + +> CentOS 6.x x86_64, Collectd 4.10 +> Zabbix 2.2, Zabbix 2.4 + +> CentOS 7.x x86_64, Collectd 5.5 +> Zabbix 2.2, Zabbix 2.4 + +versions 1.2 and lower were tested on: > Ubuntu 12.04 x86_64 with KVM (kernel 3.5.0-44), collectd 4.10 > Zabbix 2.0.x @@ -20,7 +28,7 @@ Tested on: * install a configure zabbix-agent -* copy file "zabbix-collectd.conf" into your zabbix include folder +* copy file "zabbix-collectd.conf" into zabbix agent config folder (e.g. /etc/zabbix/zabbix_agentd.d) * install collectd package(s) and perl modules @@ -37,7 +45,9 @@ Tested on: yum install epel-release ``` -* copy collectd config file (collectd.conf) into zabbix agent config folder (e.g. /etc/zabbix/zabbix_agentd.d) +* copy/rewrite collectd config file (collectd.conf) in /etc + +* * or enable libvirt & unixsock plugins in collectd service * copy script "collect-libvirt-handler.pl" into /etc/zabbix/scripts/collectd-libvirt folder (with 755 perms) diff --git a/Template_Linux_Collectd_libvirt.xml b/Template_Linux_Collectd_libvirt.xml index 46fc476..f054338 100644 --- a/Template_Linux_Collectd_libvirt.xml +++ b/Template_Linux_Collectd_libvirt.xml @@ -94,9 +94,6 @@ Libvirt - disk octets stats - - Libvirt - Disk operations stats - diff --git a/scripts/collect-libvirt-handler.pl b/scripts/collect-libvirt-handler.pl index 6b99f5e..2306919 100755 --- a/scripts/collect-libvirt-handler.pl +++ b/scripts/collect-libvirt-handler.pl @@ -9,34 +9,67 @@ my $path = $ARGV[0] || "/var/run/collectd-unixsock"; my $command = $ARGV[1] || "LISTVAL"; my @vals; - our $val = $ARGV[2]; + our $val = $ARGV[2] || "undef"; our $val_type = $ARGV[3] || "undef"; + our $collectd_version; - if( $command eq "LISTVAL" and $val eq ""){ + $collectd_version = `collectd -h |grep \'http://\' | sed \'s/\^.*[^0-9]\\([0-9]*\\.[0-9]*\\.[0-9]*\\).*\$/\\1/\' | tr -d '\n'`; + +# print "INFO: collectd version: " . $collectd_version . "\n"; + + if( $command eq "LISTVAL" and $val eq "undef"){ $val = "ALL" } if( $command eq "GETVAL"){ - + if( $val =~ /^.*-virt_cpu_total/ ){ @vals = split(/-virt/, $val); - $val = $vals[0] . "/libvirt/" . "virt" . $vals[1] + + if( $collectd_version =~ /5.5/ ){ + $val = $vals[0] . "/virt-" . $vals[0] . "/virt" . $vals[1] + } + else{ + $val = $vals[0] . "/libvirt/" . "virt" . $vals[1] + } } elsif($val =~ /^.*-disk-/ and $val_type =~ /^OPS/){ @vals = split(/-disk/, $val); - $val = $vals[0] . "/libvirt/disk_ops" .$vals[1] + + if( $collectd_version =~ /5.5/ ){ + $val = $vals[0] . "/virt-" . $vals[0] . "/disk_ops" .$vals[1] + } + else { + $val = $vals[0] . "/libvirt/disk_ops" .$vals[1] + } } elsif($val =~ /^.*-disk-/ and $val_type =~ /^OCT/){ @vals = split(/-disk/, $val); + + if( $collectd_version =~ /5.5/ ){ + $val = $vals[0] . "/virt-" . $vals[0] . "/disk_octets" .$vals[1] + } + else { $val = $vals[0] . "/libvirt/disk_octets" .$vals[1] + } } elsif($val =~ /^.*-if-/ and $val_type =~ /^NET-PACKETS/){ @vals = split(/-if/, $val); + if( $collectd_version =~ /5.5/ ){ + $val = $vals[0] . "/virt-" . $vals[0] . "/if_packets" . $vals[1] + } + else { $val = $vals[0] . "/libvirt/if_packets" . $vals[1] + } } elsif($val =~ /^.*-if-/ and $val_type =~ /^NET-OCTETS/){ @vals = split(/-if/, $val); + if( $collectd_version =~ /5.5/ ){ + $val = $vals[0] . "/virt-" . $vals[0] . "/if_octets" .$vals[1] + } + else{ $val = $vals[0] . "/libvirt/if_octets" .$vals[1] + } } $command .= " " . $val; @@ -173,7 +206,17 @@ sub putidjson { my $ident = shift || return; my $string; my $stringjson; +# my $stringjson5; our $val; +# our $collectd_version; + + #debug dumping + sub print_hash { + my $href = shift; + print "$_\t=> $href->{$_}\n" for keys %{$href}; + } + #print_hash($ident); + #end of debug dumping $string = $ident->{'host'}; @@ -181,7 +224,7 @@ sub putidjson { $string .= "-" . $ident->{'plugin'}; } - if (defined $ident->{'plugin_instance'}) { + if (defined $ident->{'plugin_instance'} and $ident->{'plugin'} ne "virt") { $string .= "-" . $ident->{'plugin_instance'}; } @@ -193,6 +236,14 @@ sub putidjson { $ident->{'type'} =~ s/_packets//; $string .= "-" . $ident->{'type'}; } + elsif ($ident->{'plugin'} eq "virt" and $ident->{'type'} =~ /^disk/ and $val eq "LIBVIRT-DISK"){ + $ident->{'type'} =~ s/_ops//; + $string .= "-" . $ident->{'type'}; + } + elsif ($ident->{'plugin'} eq "virt" and $ident->{'type'} =~ /^if/ and $val eq "LIBVIRT-NET") { + $ident->{'type'} =~ s/_packets//; + $string .= "-" . $ident->{'type'}; + } else{ $string .= "-" . $ident->{'type'}; } @@ -215,6 +266,16 @@ sub putidjson { elsif( $ident->{'plugin'} eq "libvirt" and $ident->{'type'} =~ /^if$/ and $val eq "LIBVIRT-NET"){ return $stringjson; } + elsif( $ident->{'plugin'} eq "virt" and $ident->{'type'} eq "virt_cpu_total" and $val eq "LIBVIRT-CPU"){ + return $stringjson; + } + elsif( $ident->{'plugin'} eq "virt" and $ident->{'type'} =~ /^disk$/ and $val eq "LIBVIRT-DISK"){ + return $stringjson; + } + elsif( $ident->{'plugin'} eq "virt" and $ident->{'type'} =~ /^if$/ and $val eq "LIBVIRT-NET"){ + return $stringjson; + } + # unknown plugin / known plugin not found } sub listval { @@ -235,10 +296,6 @@ sub listval { return; } -# foreach my $ident (@res) { -# print putidB($ident); -# } - my $firstline = 1; print "{\n\t\"data\":[\n\n"; @@ -317,11 +374,11 @@ sub getval { #debug #print $line[0] . "\n"; - if( $line[0] =~ /^.*\/libvirt\/virt_cpu_total/ ){ + if( $line[0] =~ /^.*\/.*virt.*\/virt_cpu_total/ ){ print "$vals->{$key}\n"; } - elsif($line[0] =~ /^.*\/libvirt\/disk_ops/){ - + elsif( $line[0] =~ /^.*\/.*virt.*\/disk_ops/ ){ + if($val_type eq "OPS-READ" and $key eq "read"){ print "$vals->{$key}\n"; } @@ -332,7 +389,7 @@ sub getval { print "\t$key: $vals->{$key}\n"; } } - elsif($line[0] =~ /^.*\/libvirt\/disk_octets/){ + elsif($line[0] =~ /^.*\/.*virt.*\/disk_octets/){ #debug #print "DEBUG: disk_octets options ..." . $/; @@ -348,7 +405,7 @@ sub getval { } } - elsif($line[0] =~ /^.*\/libvirt\/if_packets/){ + elsif($line[0] =~ /^.*\/.*virt.*\/if_packets/){ #debug #print "DEBUG: if_packets options ..." . $/; @@ -364,7 +421,7 @@ sub getval { } } - elsif($line[0] =~ /^.*\/libvirt\/if_octets/){ + elsif($line[0] =~ /^.*\/.*virt.*\/if_octets/){ #debug #print "DEBUG: if_octets options ..." . $/; @@ -387,3 +444,4 @@ sub getval { return 1; } +