[ZBXNEXT-1024] Add/delete some modes for vm.memory.size key under FreeBSD (or all BSD) and other OS Created: 2011 May 04  Updated: 2013 Apr 30  Resolved: 2011 Nov 23

Status: Closed
Project: ZABBIX FEATURE REQUESTS
Component/s: Agent (G)
Affects Version/s: None
Fix Version/s: 1.9.9 (beta)

Type: Change Request Priority: Trivial
Reporter: Pavel Timofeev Assignee: dimir
Resolution: Fixed Votes: 2
Labels: freebsd, memory
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

FreeBSD


Attachments: PNG File memusage_with_patch.png     PNG File memusage_with_patch_desc.png     Text File patch-src_freebsd_mem.c    
Issue Links:
Duplicate
duplicates ZBXNEXT-144 Please implement support of item key ... Closed
is duplicated by ZBX-4419 Missing memory items FreeBSD 8.2 Closed

 Description   

Now in Zabbix we have many parameters for monitoring memory under FreeBSD: vm.memory.size[<mode>]
<mode> can be:

total
free
used
shared
cached

5 parameters! ('pfree' and 'pused' doesn't work in my servers, and doesn't work correct anyway) Ok, not bad.
But I don't know what does 'shared' and 'used' parameters mean.

If you use FreeBSD go to `top`. At head you can see memory parts:
Active, Inact, Wired, Cache, Buf and Free. You can't see 'shared' and 'used' parameters. And you don't know how to get correct or real free memory!

In order to know REAL FREE MEMory you need:
1. Get from sysctl folowing vars:

"vm.stats.vm.v_inactive_count" * "vm.stats.vm.v_page_size" (lets call it INACT)
"vm.stats.vm.v_cache_count" * "vm.stats.vm.v_page_size" (CACHE)
"vm.stats.vm.v_free_count" * "vm.stats.vm.v_page_size" (FREE)

2. Calculate REAL FREE MEMory:
free_mem = INACT + CACHE + FREE

3. If you want to get REAL USED MEMory:
total_mem = "vm.stats.vm.v_page_count" * "vm.stats.vm.v_page_size" (it defines correct in zabbix)
used_mem = total_mem - free_mem

Conclusion 4 developers:
Please make correct calculation of FreeBSD memory!
You need add INACT (sysclt vm.stats.vm.v_inactive_count) mode to vm.memory.size.
Then make 'pfree' and 'pused' mode calculation as I described below (real free and real used memory).
I think you need to delete 'shared' and 'used' modes for fbsd, because it is not necessary under FreeBSD.

Thanks!

P.S. maybe it right for all BSD systems.

____________

? ????? ?????? Zabbix ????? ?????????? ?? ???- ???????? ??? FreeBSD (? ????? ? ??? ???? BSD) ???????? vm.memory.size:
shared ? used (? ???? ?? ???? ??? ??? ?? ???????? ?????)
? ?? ?? ????? ??????????? ?????????? ???????? inactive ?????? (?? ? active).
? ???? ?? ? ???? ????? ?? ?????????? ?????? pused ? pfree, ?? ? ??? ???? ???????????.

????? ?????? ??????? ????????? ??? ?????????? ????????? ??????, ?.?. ?? ???? ??? ?????? ??????? ?????????????? swap, ????? ?????????? ???????? ????????? ????.
???????!



 Comments   
Comment by Pavel Timofeev [ 2011 May 04 ]

Готов к диалогу
Ready for dialog

Comment by Pavel Timofeev [ 2011 May 05 ]

Алексей, а можно ли дать мне возможность отредактировать тикет? или закрыт его и создать новый? писал в не очень адекватном состоянии и хотел бы переделать его.
Can I edit this ticket? Or creating new ticket will be best solution?

Comment by richlv [ 2011 May 05 ]

just add an updated summary as a new comment here, somebody surely will handle it from there

Comment by Pavel Timofeev [ 2011 May 05 ]

Thank you for fast reply!

Maybe I will repeat myself.

I just want to say: Please, add some new modes for vm.memory.size key and delete useless modes!

It need for FreeBSD and maybe other BSD systems. If you want I'll check it!
Memory organization in FreeBSD is different than in Linux.
Existing modes like 'used', 'shared', 'pfree' and 'pused' don't need under FreeBSD(allBSD?). It useless.

Also we already have 'total', 'free' and 'cached' modes. It usefull under FreeBSD.
As I see in src (src/libs/zbxsysinfo/freebsd/memory.c) 'total' memory calculate as "vm.stats.vm.v_page_count" * "vm.stats.vm.v_page_size".
'free' memory = "vm.stats.vm.v_free_count" * "vm.stats.vm.v_page_size".
'cached' memory = "vm.stats.vm.v_cache_count" * "vm.stats.vm.v_page_size"
This is good and right!

But we also need 'active', 'inactive' and 'wired' modes for vm.memory.size key under FreeBSD(BSD)!
We may calculate 'active' mem as "vm.stats.vm.v_active_count" * "vm.stats.vm.v_page_size"
'inactive' = "vm.stats.vm.v_inactive_count" * "vm.stats.vm.v_page_size"
'wired' = "vm.stats.vm.v_wire_count" * "vm.stats.vm.v_page_size" (sysctl var contains 'wire', not 'wired')

If you add up all this memory you get 'total' memory.
I.e. 'total' = 'active' + 'wired' + 'cache' + 'inactive' + 'free'

In FreeBSD 'free' memory doesn't mean REAL free memory available for programs.
Actually used memory in FreeBSD is 'active' + 'wired'. And real free mem is 'cache' + 'inactive' + 'free'.
Under load 'active' and 'wired' types of memory are growing and other types are decreasing.
When 'cache', 'inactive' and 'free' will be tiny system will be active use swap.

I can provied graphics if you want.
And if you don't have enough time I can try to provide patches for src/libs/zbxsysinfo/freebsd/memory.c, but I have small experience in C programming.

Comment by Oleksii Zagorskyi [ 2011 May 05 ]

forum thread http://www.zabbix.com/forum/showthread.php?t=21826
I think it's created by reporter Pavel Timofeev

Comment by Pavel Timofeev [ 2011 May 05 ]

Yes, it's me.

Comment by Pavel Timofeev [ 2011 May 05 ]

patch that add 3 new modes for vm.memory.size in Zabbix agent under FreeBSD
http://narod.ru/disk/11988360001/zbx_bsd_mem.patch.html
or
http://pastebin.com/e98rru5v

It works good. Just checked!

Comment by Pavel Timofeev [ 2011 May 05 ]

than remove shared and used modes
http://narod.ru/disk/11991925001/zbx_bsd_mem.patch2.html
or
http://pastebin.com/YM3iqdh1

Comment by Pavel Timofeev [ 2011 May 05 ]

than 3rd patch for correct calculation of pfree and pused
http://narod.ru/disk/12077306001/zbx_bsd_mem.patch3.html
or
http://pastebin.com/Ec3D6bja
links was changed: forgot one small '()'

Comment by Oleksii Zagorskyi [ 2011 May 05 ]

Pavel, it better to attach here all your patches
See to "More Actions -> Attach File"

Comment by Pavel Timofeev [ 2011 May 05 ]

Cumulative patch
All patches for Zabbix 1.8.5.
Works on FreeBSD 8.2 RELEASE i386 and amd64.

Comment by Pavel Timofeev [ 2011 May 06 ]

Small change in patch. Forgot one ()

You can test it. Just copy this file to /usr/ports/net-mgmt/zabbix-server/files/ directory and reinstall zabbix_agent

Comment by Pavel Timofeev [ 2011 May 07 ]

This ticket valid only for FreeBSD. Other BSD - other memory.

Comment by Pavel Timofeev [ 2011 May 10 ]

By analogy with 'pfree' and 'pused' and I'll add calculations for 'available' and 'used' memory types.
And I think 'pfree' memory type need to rename to 'pavailable'.

Comment by Pavel Timofeev [ 2011 May 10 ]

Latest patch. Tested under FreeBSD 8.2 RELEASE and Zabbix-1.8.5 from ports tree.
Works fine. Please, test it if you have a time.
For pfree and pused memory types in item menu you need choose - Type of information: Numeric (float), Units: %
other types - Type of information: Numeric (insigned), Units: B.

Comment by Pavel Timofeev [ 2011 May 10 ]

TOTAL RESULT:
Please exam attached patch.
It adds some freebsd specific types of memory for vm.memory.size and makes correct calculation for pused, pfree, etc.

And I think 'pfree' memory type need to rename to 'pavailable'.

Waiting for you marks!

Comment by Pavel Timofeev [ 2011 Aug 10 ]

I'm showing a few screenshots of server that works with my patch.
Can you see that I maybe right?

Comment by Pavel Timofeev [ 2011 Aug 10 ]

Please, talk with me =)

Comment by Pavel Timofeev [ 2011 Aug 18 ]

Please, read http://www.absolutebsd.com/AbsoluteBSD18.pdf

Comment by Pavel Timofeev [ 2011 Aug 31 ]

small correction: don't delete "shared" memory type (like in my patch).
and may be add buffer mem type will be useful.

Comment by Pavel Timofeev [ 2011 Aug 31 ]

When you'll solve this PR I would like to discuss about other OS and their memory types.

Comment by richlv [ 2011 Sep 09 ]

it might be worth attaching latest patch to this issue

Comment by Pavel Timofeev [ 2011 Nov 10 ]

I want to discuss about some thing like common type of memory. It is general problem.
Can I post here my reflections?

Comment by Pavel Timofeev [ 2011 Nov 10 ]

All existing monitoring things (like snmp and monitoring systems) are imbrued with linuxism.

For monitoring purposes:
Linux has some memory types: Used, Free, Shared, Buffers, Cached. And in most cases all monitoring systems oriented to these.

But other UNIX's have similar and different types:
FreeBSD/DragonflyBSD: Active, Inactive, Wired, Cache, Buffer (for UFS only), Free, Shared.
OpenBSD: Real active, Real total, Free, Shared, Buf, Cached.
NetBSD (similar to freebsd): Active, Inactive, Wired, Exec, File, Free, Buff, Shared.
OpenSolaris/OpenIndiana may has own types.

We need to think about it: this types are responsible for different things.
For example, for NetBSD http://www.selonen.org/arto/netbsd/
or for FreeBSD http://www.absolutebsd.com/AbsoluteBSD18.pdf

May be we need to introduce COMMON types like Available and Filled (for example) and specific types for each unix.

Comment by Aleksandrs Saveljevs [ 2011 Nov 23 ]

Pavel, thanks for the inspiration! Below is a list of user-visible changes that were done under this issue.

  • Changed formatting for "system.localtime[local]". It used to return data in the format "2000-1-2,3:4:5.67,+2:0", now it returns data in the format "2000-01-02,03:04:05.067,+02:00" (note the leading zeros).
  • Documented which items are indeed available on Mac OS X. Added support for "net.if.collisions", "net.if.in", "net.if.out", "net.if.total", "system.boottime", "system.cpu.num[online]", "vfs.fs.discovery" for Mac OS X.
  • Added "net.tcp.listen" on Mac OS X. Added "net.udp.listen" on Mac OS X, FreeBSD, and Solaris.
  • Item "vm.memory.size[shared]" always returned 0 on Linux 2.6, removed it. Left it only for Linux 2.4. Dropped support for Linux 2.3 in memory-related modules.
  • Removed items "vm.memory.size[pfree]" on all platforms that supported it for reasons described below.

Now, the main part. As Pavel mentioned, different operating systems use different memory types and different terms to describe them. We have decided that item "vm.memory.size" will support all these specific terms for each platform: for instance, "vm.memory.size[wired]" on FreeBSD and "vm.memory.size[exec]" on NetBSD.

However, sometimes these specific memory types are not needed. What is really needed is a user-level estimate of how much memory is used and how much memory is available. Items "vm.memory.size[used]", "vm.memory.size[pused]" and "vm.memory.size[available]", "vm.memory.size[pavailable]" are intended to provide these estimates. Note that "vm.memory.size[used]" plus "vm.memory.size[available]" do not necessarily equal total. For instance, on FreeBSD active, inactive, wired, cached memories are considered used, because they store some useful information. At the same time inactive, cached, free memories (note that "free" here is a specific memory term, thus "pfree" is not very useful) are considered available, because these kinds of memories can be given instantly to processes that request more memory. So, for example, inactive memory is both used and available simultaneously. Because of this, item "vm.memory.size[used]" is designed for informational purposes only, while item "vm.memory.size[available]" is designed for triggers. These user-level estimate items are available for all platforms.

The full list of supported arguments to "vm.memory.size" is available in the documentation.

What still remains to be done is to figure out the purpose of "vm.memory.size[buffers]", "vm.memory.size[cached]", "vm.memory.size[shared]" on NetBSD and "vm.memory.size[cached]", "vm.memory.size[shared]" on OpenBSD. Another thing is that on OpenBSD the sum of "vm.memory.size[used]" and "vm.memory.size[available]" is less than "vm.memory.size[total]", which is also something that needs to be improved.

Comment by Aleksandrs Saveljevs [ 2011 Nov 23 ]

Available in development branch svn://svn.zabbix.com/branches/dev/ZBXNEXT-1024 .

Comment by Pavel Timofeev [ 2011 Nov 23 ]

Good explanation and solution =) Thank you very much!

Comment by Aleksandrs Saveljevs [ 2011 Nov 29 ]

One of the things I seem to have not done is add division by zero checks in vm.memory.size[pfree] and vm.memory.size[pavailable] for all platforms. I am not sure they are needed, though.

Comment by dimir [ 2011 Dec 01 ]

I guess you meant pused and pavailable. The checks are partly there so I think it makes sense to add the missing ones.

Comment by dimir [ 2011 Dec 05 ]

So, as I mentioned above currently vm.memory.size checks support "pused" instead of "pfree". Let's try to use "pused" on netbsd 5.0:

for i in total used pused; do echo -n "$i : "; bin/zabbix_get -s netbsd50 -k vm.memory.size[$i]; done
total : 251596800
used : 310284288
pused : 123.326007

"used" is greater than "total" so we end up with used 123 %. This is because "used" includes file pages, which are not included in "total". Let's check the description of vm.memory.size[used] in 2.0 manual:

"Note that the sum of vm.memory.size[used] and vm.memory.size[available] does not necessarily equal total. For instance, on FreeBSD active, inactive, wired, cached memories are considered used, because they store some useful information. At the same time inactive, cached, free memories are considered available, because these kinds of memories can be given instantly to processes that request more memory. So inactive memory is both used and available simultaneously. Because of this, item vm.memory.size[used] is designed for informational purposes only, while item vm.memory.size[available] is designed to be used in triggers."

This sounds logical but do we really want to support vm.memory.size[pused]? If "used" is informative, that's OK but I don't see much sense in relating this value to "total".

Opinions?

Comment by dimir [ 2011 Dec 06 ]

(1) "Inactive" in *BSD systems should not be included in "used" calculation. The inactive memory has valid content, but is marked as not used.

<dimir> Now this looks much better:

$ for i in total used pused available pavailable; do echo -n "$i : "; bin/zabbix_get -s netbsd50 -k vm.memory.size[$i]; done
total : 251596800
used : 80326656
pused : 31.926740
available : 176644096
pavailable : 70.209198

RESOLVED in r23816

<dimir> CLOSED, moved to (2)

Comment by dimir [ 2012 Jan 03 ]

(2) Tested successfully. Now someone will have to check my changes from r23601 (including) up to the latest.

<Sasha> CLOSED

Comment by dimir [ 2012 Jan 03 ]

(3) Please review next changes to docs before I publish them:

  • describe vm.memory.size parameters, I propose like this:
    total - Total real memory available.
    free - Memory that is readily available to any entity requesting memory.
    active - Memory currently in use or very recently used, and so it is in RAM.
    inactive - Memory that is marked as not used.
    wired - Memory that is marked to always stay in RAM. It is never moved to disk.
    pinned - Same as wired.
    anon - Memory not associated with a file (can not be re-read from it).
    exec - Executable code, typically from a (program) file.
    file - Cache for contents of recently accessed files.
    buffers - Cache for things like file system metadata.
    cached - Cache for various things.
    shared - Memory that may be simultaneously accessed by multiple processes.
    used - Active + wired memory.
    pused - Active + wired memory in relation to total.
    available - Inactive + free memory.
    pavailable - Inactive + free memory in relation to total.
  • on aix available and free is the same thing
  • on solaris available and free is the same thing
  • add 'active' support for hpux
  • linux/shared works only on kernel 2.4

<richlv> 'real' - how about 'physical' ?
and, of course, proper capitalisation for os names

<dimir> I agree to all above.

<Sasha> added support of vm.memory.size[active] on HPUX
http://www.zabbix.com/documentation/2.0/manual/appendix/items/supported_by_platform

Comment by Pavel Timofeev [ 2012 Jan 04 ]

> available - Inactive + free memory
> pavailable - Inactive + free memory in relation to total

why don't you add cached memory to available calculation?

Comment by dimir [ 2012 Jan 04 ]

Great point, Pavel. It's actually there, I must fix the description. Also I spotted a couple of platforms where this isn't included in available.

Comment by dimir [ 2012 Jan 19 ]

New page added: http://www.zabbix.com/documentation/2.0/manual/appendix/items/vm.memory.size_params

Comment by dimir [ 2012 Jan 19 ]

Fixed in pre-1.9.9 r24902.

Generated at Wed Apr 17 02:33:17 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.