Hi,
this thread describes how one can easily monitor memory resources of OpenVZ hardware nodes and virtual private servers (Containers) via a Zabbix-Agent.
All information are taken from the "User Beancounters" table and by the output of the utility 'vzmemcheck'.
Items based on the User Bencounters table are valid for the hardware nodes and containers.
Items based on 'vzmemcheck' are only valid on hardware nodes.
Because the User Beancounters and the vzmemcheck files are only accessible/executable as user 'root' and the Zabbix-Agent (should) run as unprivileged user 'zabbix', one has to allow the user 'zabbix' access to them via a sudo rule.
Run the command 'visudo' and add the following lines at the end of the file:
Then add the following lines to the agent's configuration file (/etc/zabbix/zabbix_agentd.conf):
Beginning with XML file "zbx_OpenVZ-0.10.xml" the use of sudo decribed above can be extremly reduced. The drawback with the following alternative way of UBC monitoring is that there is no individual access to a single metric anymore. The template is extended by one additional Item 'Update copy of UBC table' (all other items are the same as in version 0.9) which copies the hole UBC table to a file which is accessible by user zabbix. This way all UBC Items can parse the table directly:
After restarting the Zabbix-Agent one can create items of type 'Zabbix Agent' and the desired key.
To get the current usage (held) of the resource 'numproc' use the following key definition:
To get the fail count of the resource 'numproc' use the following key definition:
To get the allocated memory (Alloc util) by all virtual servers on a hardware node in % use the key:
The attached XML file provides two templates for OpenVZ:
this thread describes how one can easily monitor memory resources of OpenVZ hardware nodes and virtual private servers (Containers) via a Zabbix-Agent.
All information are taken from the "User Beancounters" table and by the output of the utility 'vzmemcheck'.
Items based on the User Bencounters table are valid for the hardware nodes and containers.
Items based on 'vzmemcheck' are only valid on hardware nodes.
Code:
[root@zabbix /]# cat /proc/user_beancounters
Version: 2.5
uid resource held maxheld barrier limit failcnt
113: kmemsize 4620836 5669253 7573026 7756526 0
lockedpages 0 0 32 32 0
privvmpages 42262 83619 122713 127136 0
shmpages 10230 10230 24833 24833 0
dummy 0 0 0 0 0
numproc 52 63 80 80 0
physpages 15437 55627 0 2147483647 0
vmguarpages 0 0 92672 2147483647 0
oomguarpages 15566 55723 84090 2147483647 0
numtcpsock 30 47 106 106 0
numflock 3 5 100 100 0
numpty 1 1 16 16 0
numsiginfo 0 24 256 256 0
tcpsndbuf 51520 199360 692906 897706 0
tcprcvbuf 0 214400 476330 681130 0
othersockbuf 2240 18816 132096 336896 0
dgramrcvbuf 0 16768 132096 132096 0
numothersock 4 10 80 80 0
dcachesize 0 0 1048576 1048576 0
numfile 741 936 2048 2048 0
dummy 0 0 0 0 0
dummy 0 0 0 0 0
dummy 0 0 0 0 0
numiptent 14 14 128 128 0
[root@zabbix /]#
[root@ovzhn1 ~]# vzmemcheck
Output values in %
LowMem LowMem RAM MemSwap MemSwap Alloc Alloc Alloc
util commit util util commit util commit limit
7.95 20.64 60.74 20.33 75.11 57.80 86.55 141.26
[root@ovzhn1 ~]#
Run the command 'visudo' and add the following lines at the end of the file:
Code:
## Allow zabbix access to OpenVZ's resources Cmnd_Alias MON_OVZ_HN = /usr/sbin/vzmemcheck, /usr/sbin/vzmemcheck -A Cmnd_Alias MON_OVZ_UBC = /usr/bin/tac /proc/user_beancounters Defaults:zabbix !requiretty zabbix ALL = NOPASSWD: MON_OVZ_HN, MON_OVZ_UBC
Code:
### Parameter for monitoring OpenVZ resources
UserParameter=openvz.ubc[*],/usr/bin/sudo /usr/bin/tac /proc/user_beancounters | awk '/$1/{print $(NF-5+$2);exit}'
UserParameter=openvz.vzmemcheck.putil[*],/usr/bin/sudo /usr/sbin/vzmemcheck | awk '/[0-9]/{print $$$1}'
UserParameter=openvz.vzmemcheck.util[*],/usr/bin/sudo /usr/sbin/vzmemcheck -A | awk '/[0-9]/{print $$$1;exit}'
Code:
## Allow zabbix access to OpenVZ's resources (zbx_OpenVZ-0.10.xml only) Cmnd_Alias MON_OVZ_UBC = /usr/bin/install -o zabbix -g zabbix -m 440 /proc/user_beancounters /var/local/zabbix/log/user_beancounters Cmnd_Alias MON_OVZ_HN = /usr/sbin/vzmemcheck, /usr/sbin/vzmemcheck -A Defaults:zabbix !requiretty zabbix ALL = NOPASSWD: MON_OVZ_UBC, MON_OVZ_HN
Code:
### Parameter for monitoring OpenVZ resources (zbx_OpenVZ-0.10.xml only)
UserParameter=openvz.updateubc,/usr/bin/sudo /usr/bin/install -o zabbix -g zabbix -m 440 /proc/user_beancounters /var/local/zabbix/log/user_beancounters && echo Update succeeded || echo Update failed
UserParameter=openvz.ubc[*],/usr/bin/tac /var/local/zabbix/log/user_beancounters | awk '/$1/{print $(NF-5+$2); exit}'
UserParameter=openvz.vzmemcheck.putil[*],/usr/bin/sudo /usr/sbin/vzmemcheck | awk '/ *[0-9]/{print $$$1}'
UserParameter=openvz.vzmemcheck.util[*],/usr/bin/sudo /usr/sbin/vzmemcheck -A | awk '/ *[0-9]/{print $$$1;exit}'
To get the current usage (held) of the resource 'numproc' use the following key definition:
openvz.ubc[numproc,1]
To get the fail count of the resource 'numproc' use the following key definition:
openvz.ubc[numproc,5]
To get the allocated memory (Alloc util) by all virtual servers on a hardware node in % use the key:
openvz.vzmemcheck.putil[6]
The attached XML file provides two templates for OpenVZ:
- The first template 'OpenVZ' consists of the complete set of values from the UBC table and triggers for raised fail count as well as virtual network interface.
- The second template 'OpenVZ Node' consists of all values from vzmemcheck in % and MB as well as triggers for critical utilization.
Comment