Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upate docs, small fixes and improvements #9

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions README-DEBUGGING.md
Original file line number Diff line number Diff line change
@@ -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"
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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)

Expand Down
3 changes: 0 additions & 3 deletions Template_Linux_Collectd_libvirt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@
<application>
<name>Libvirt - disk octets stats</name>
</application>
<application>
<name>Libvirt - Disk operations stats</name>
</application>
</applications>
<valuemap/>
</item_prototype>
Expand Down
90 changes: 74 additions & 16 deletions scripts/collect-libvirt-handler.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -173,15 +206,25 @@ 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'};

if( $val eq "ALL"){
$string .= "-" . $ident->{'plugin'};
}

if (defined $ident->{'plugin_instance'}) {
if (defined $ident->{'plugin_instance'} and $ident->{'plugin'} ne "virt") {
$string .= "-" . $ident->{'plugin_instance'};
}

Expand All @@ -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'};
}
Expand All @@ -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 {
Expand All @@ -235,10 +296,6 @@ sub listval {
return;
}

# foreach my $ident (@res) {
# print putidB($ident);
# }

my $firstline = 1;

print "{\n\t\"data\":[\n\n";
Expand Down Expand Up @@ -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";
}
Expand All @@ -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 ..." . $/;
Expand All @@ -348,7 +405,7 @@ sub getval {
}

}
elsif($line[0] =~ /^.*\/libvirt\/if_packets/){
elsif($line[0] =~ /^.*\/.*virt.*\/if_packets/){

#debug
#print "DEBUG: if_packets options ..." . $/;
Expand All @@ -364,7 +421,7 @@ sub getval {
}

}
elsif($line[0] =~ /^.*\/libvirt\/if_octets/){
elsif($line[0] =~ /^.*\/.*virt.*\/if_octets/){

#debug
#print "DEBUG: if_octets options ..." . $/;
Expand All @@ -387,3 +444,4 @@ sub getval {
return 1;
}