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

Adding support for MemAvailable #1993

Merged
merged 4 commits into from
Oct 26, 2015
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 3 additions & 2 deletions checks/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def run(self, checksd=None, start_event=True):
memory = sys_checks['memory'].check(self.agentConfig)

if memory:
payload.update({
memstats = {
'memPhysUsed': memory.get('physUsed'),
'memPhysPctUsable': memory.get('physPctUsable'),
'memPhysFree': memory.get('physFree'),
Expand All @@ -318,7 +318,8 @@ def run(self, checksd=None, start_event=True):
'memCached': memory.get('physCached'),
'memBuffers': memory.get('physBuffers'),
'memShared': memory.get('physShared')
})
}
payload.update(memstats)

ioStats = sys_checks['io'].check(self.agentConfig)
if ioStats:
Expand Down
12 changes: 10 additions & 2 deletions checks/system/unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,13 @@ def check(self, agentConfig):
self.logger.exception('Cannot get memory metrics from /proc/meminfo')
return False

# NOTE: not all of the stats below are present on all systems as
# not all kernel versions report all of them.
#
# $ cat /proc/meminfo
# MemTotal: 7995360 kB
# MemFree: 1045120 kB
# MemAvailable: 1253920 kB
# Buffers: 226284 kB
# Cached: 775516 kB
# SwapCached: 248868 kB
Expand Down Expand Up @@ -361,13 +365,17 @@ def check(self, agentConfig):
try:
memData['physTotal'] = int(meminfo.get('MemTotal', 0)) / 1024
memData['physFree'] = int(meminfo.get('MemFree', 0)) / 1024
if 'MemAvailable' in meminfo:
memData['physUsable'] = int(meminfo.get('MemAvailable', 0)) / 1024
else:
# Usable is relative since cached and buffers are actually used to speed things up.
memData['physUsable'] = memData['physFree'] + memData['physBuffers'] + memData['physCached']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't look like physBuffers and physCached are populated until L374-375 . Maybe move this block of code below that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting that! Careless.


memData['physBuffers'] = int(meminfo.get('Buffers', 0)) / 1024
memData['physCached'] = int(meminfo.get('Cached', 0)) / 1024
memData['physShared'] = int(meminfo.get('Shmem', 0)) / 1024

memData['physUsed'] = memData['physTotal'] - memData['physFree']
# Usable is relative since cached and buffers are actually used to speed things up.
memData['physUsable'] = memData['physFree'] + memData['physBuffers'] + memData['physCached']

if memData['physTotal'] > 0:
memData['physPctUsable'] = float(memData['physUsable']) / float(memData['physTotal'])
Expand Down