-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
monitors: Add monitor for /proc/meminfo
- Loading branch information
1 parent
6bbab27
commit 0374c0c
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
def read_file(filename): | ||
"""Read the contents of :param:filename""" | ||
with open(filename, 'r') as f: | ||
return f.readall().split('\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from monitor.functions import register | ||
from monitor.helpers import read_file | ||
|
||
|
||
def monitor_memory(record): | ||
"Monitors system memory" | ||
meminfo = read_file('/proc/meminfo') | ||
print meminfo | ||
for line in meminfo: | ||
tokenized_line = line.split() | ||
if len(tokenized_line) > 1: | ||
key, value = tokenized_line[:2] | ||
key = key.strip(':') | ||
record(key, value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from mock import patch, MagicMock | ||
from nose.tools import eq_ | ||
|
||
from monitor.monitors.memory import monitor_memory | ||
import monitor.monitors.memory as mod | ||
|
||
|
||
@patch.object(mod, 'read_file') | ||
def test_memory(mock_read_file): | ||
mock_read_file.return_value = MEMINFO.split('\n') | ||
mock_record = MagicMock(name='record') | ||
monitor_memory(mock_record) | ||
|
||
mock_record.assert_any_call('MemFree', '69936') | ||
|
||
|
||
MEMINFO = """MemTotal: 255908 kB | ||
MemFree: 69936 kB | ||
Buffers: 15812 kB | ||
Cached: 115124 kB | ||
SwapCached: 0 kB | ||
Active: 92700 kB | ||
Inactive: 63792 kB | ||
HighTotal: 0 kB | ||
HighFree: 0 kB | ||
LowTotal: 255908 kB | ||
LowFree: 69936 kB | ||
SwapTotal: 524280 kB | ||
SwapFree: 524280 kB | ||
Dirty: 4 kB | ||
Writeback: 0 kB | ||
Mapped: 42236 kB | ||
Slab: 25912 kB | ||
Committed_AS: 118680 kB | ||
PageTables: 1236 kB | ||
VmallocTotal: 3874808 kB | ||
VmallocUsed: 1416 kB | ||
VmallocChunk: 3872908 kB | ||
HugePages_Total: 0 | ||
HugePages_Free: 0 | ||
Hugepagesize: 4096 kB""" |