├── vzdiscover.sh ├── README.md └── template.xml /vzdiscover.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use strict; 4 | 5 | my $first = 1; 6 | 7 | print "{\n"; 8 | print "\t\"data\":[\n\n"; 9 | 10 | my $vzresult = `sudo /usr/sbin/vzlist -a -o veid,hostname,status,laverage -H`; 11 | 12 | my @lines = split /\n/, $vzresult; 13 | 14 | foreach my $l (@lines) { 15 | if ($l =~ /^(\s*?)(\d+) (.*?)(\s+)(\S+)/) 16 | { 17 | my $id = $2; 18 | my $hostname = $3; 19 | my $status = $5; 20 | print ",\n" if not $first; 21 | $first = 0; 22 | 23 | print "\t{\n"; 24 | print "\t\t\"{#VZID}\":\"$id\",\n"; 25 | print "\t\t\"{#VZHOST}\":\"$hostname\",\n"; 26 | print "\t\t\"{#VZSTATUS}\":\"$status\"\n"; 27 | print "\t}"; 28 | } 29 | } 30 | 31 | print "\n\t]\n"; 32 | print "}\n"; 33 | 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Zabbix - Proxmox/OpenVZ 2 | ============== 3 | 4 | Zabbix Template for monitoring cpu/memory of your Proxmox/OpenVZ Server 5 | This Template implements *low level discovery* to automatically discover all of your guest systems after you applied the template to a host 6 | 7 | 8 | ### Setup 9 | 10 | * Add the following to your **/etc/zabbix/zabbix_agentd.conf** file. 11 | 12 | ``` 13 | UserParameter=custom.pve.vzlist,/var/lib/zabbix/scripts/vzdiscover.sh 14 | UserParameter=custom.vz.cpu[*],sudo /usr/sbin/vzlist -a -o laverage -H $1 | awk -F/ '{print $$1}' 15 | UserParameter=custom.vz.cpu5[*],sudo /usr/sbin/vzlist -a -o laverage -H $1 | awk -F/ '{print $$2}' 16 | UserParameter=custom.vz.cpu10[*],sudo /usr/sbin/vzlist -a -o laverage -H $1 | awk -F/ '{print $$3}' 17 | 18 | UserParameter=custom.vz.usedmem[*],sudo /usr/sbin/vzlist -a -o physpages -H $1 | awk '{print $$1*4/1024}' 19 | ``` 20 | * Copy the file **vzdiscover.sh** to **/var/lib/zabbix/scripts/vzdiscover.sh** and make it executable 21 | * Because vzlist could only executed as root, you need to add this line to your visudo list 22 | 23 | ``` 24 | zabbix ALL=NOPASSWD:/var/lib/zabbix/scripts/vzdiscover.sh,/usr/sbin/vzlist 25 | ``` 26 | 27 | * Import the template.xml File into your Zabbix 28 | -------------------------------------------------------------------------------- /template.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0 4 | 2014-01-26T14:36:10Z 5 | 6 | 7 | Linux servers 8 | 9 | 10 | 11 | 322 | 323 | 324 | --------------------------------------------------------------------------------