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

Remove the need for a special template #18

Open
wants to merge 4 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
31 changes: 12 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ collected worng without calculating buffers and cache memory.<br> Zabbix have
[bug
report]([https://support.zabbix.com/browse/ZBX-12164](https://support.zabbix.com/browse/ZBX-12164)),
but it seems that no one don’t want to fix it soon.<br> So let’s fix it together
byself.
by ourselves.

First we need to create new user parameter for zabbix, I used `ct.memory.size`
name similarly built-in `vm.memory.size` parameter, but with my own single line
Expand Down Expand Up @@ -74,33 +74,26 @@ It will provide you support for next parameters:
ct.cpu.load[percpu,avg5]
ct.cpu.load[percpu,avg15]

Now add aliases to make the new/correct data available under the standard item names:

Alias=vm.memory.size:ct.memory.size
Alias=system.swap.size:ct.swap.size
Alias=system.cpu.load:ct.cpu.load
Alias=system.uptime:ct.uptime

Don’t forget to restart `zabbix-agent.service` after

Ok, now we can check is our parameter working from zabbix server:

$ zabbix_get -s <container_ip> -k ct.memory.size[available]
1709940736

Ok it’s working.

Now let’s configure zabbix for use them. In Zabbix Interface:

Go Configuration → Templtes
This new value should now also be available under the standard name:

* Make full copy “Template OS Linux” to “Template Linux Container”
* Open “Template Linux Container” → Items
* Replace all `vm.memory.size` items to `ct.memory.size`.
* Replace all `system.swap.size` items to `ct.swap.size`:<br> You also need to
remove commas in key filed here. Example:<br> replace `system.swap.size[,free]`
to `ct.swap.size[free]`
* Replace all `system.cpu.load[percpu,*]` items to `ct.cpu.load[percpu,*]`.

Or just download and import [my zabbix template](https://github.com/kvaps/zabbix-linux-container-template/blob/master/zbx_linux_container_template.xml).

Next, go to the Configuration → Hosts
$ zabbix_get -s <container_ip> -k vm.memory.size[available]
1709940736

* Unlink and clear “Template OS Linux” from your hosts
* Attach “Template Linux Container”
Ok it’s working.

Wait some time and check the graphics:

Expand Down
12 changes: 11 additions & 1 deletion zabbix_container.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
UserParameter=ct.memory.size[*],free -b | awk 'NR==2 {total=$ 2; used=($ 3+$ 5); pused=(($ 3+$ 5)*100/$ 2); free=$ 4; pfree=($ 4*100/$ 2); shared=$ 5; buffers=$ 6; cached=$ 6; available=$ 7; pavailable=($ 7*100/$ 2); if("$1" == "") {printf("%.0f", total )} else {printf("%.0f", $1 "" )} }'
UserParameter=ct.swap.size[*],free -b | awk 'NR==3 {total=$ 2; used=$ 3; free=$ 4; pfree=($ 4*100/$ 2); pused=($ 3*100/$ 2); if("$1" == "") {printf("%.0f", free )} else {printf("%.0f", $1 "" )} }'
Alias=vm.memory.size:ct.memory.size
Alias=vm.memory.size[*]:ct.memory.size[*]

UserParameter=ct.swap.size[*],free -b | awk 'NR==3 {total=$ 2; used=$ 3; free=$ 4; pfree=($ 4*100/$ 2); pused=($ 3*100/$ 2); if("$2" == "") {printf("%.0f", free )} else {printf("%.0f", $2 "" )} }'
Alias=system.swap.size:ct.swap.size
Alias=system.swap.size[*]:ct.swap.size[*]

UserParameter=ct.cpu.load[*],cut -d" " -f1-3 /proc/loadavg | awk -F'[, ]+' '{avg1=$(NF-2); avg5=$(NF-1); avg15=$(NF)}{print $2/'$(nproc)'}'
Alias=system.cpu.load:ct.cpu.load
Alias=system.cpu.load[*]:ct.cpu.load[*]

UserParameter=ct.uptime,cut -d"." -f1 /proc/uptime
Alias=system.uptime:ct.uptime
Loading