8000 feature: added new System Free/Used Memory graph · postgrespro/mamonsu@0f87624 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f87624

Browse files
committed
feature: added new System Free/Used Memory graph
- added new system metric 'Total Memory'; - added new simple graph showing amount of all system memory and a group of used, free and cached memory;
1 parent e04b387 commit 0f87624

File tree

1 file changed

+43
-53
lines changed

1 file changed

+43
-53
lines changed

mamonsu/plugins/system/linux/memory.py

Lines changed: 43 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class Memory(Plugin):
66
AgentPluginType = 'sys'
77
query_agent = "cat /proc/meminfo | awk '/^{0}\:/ "
8-
query_agent_apps = "MemTotal=$(cat /proc/meminfo | awk '/MemTotal\:/ { print $2 }'); " \
8+
query_agent_used = "MemTotal=$(cat /proc/meminfo | awk '/MemTotal\:/ { print $2 }'); " \
99
"SUM=$(cat /proc/meminfo | awk '/(MemFree|Buffers|(Swap)?Cached|Slab|PageTables)\:/ " \
1010
"{ SUM += $2 } END {print SUM}'); echo $((($MemTotal-$SUM)*1024))"
1111
query_agent_swap = "expr `grep -Ei 'Swap(Total|Free)' /proc/meminfo | awk '{print $2 * 1024}' | paste -s -d '-' " \
@@ -17,48 +17,22 @@ class Memory(Plugin):
1717
# 2. virtual memory
1818

1919
Items = [
20-
# zbx_key, meminfo_key, name, color
21-
('apps', None,
22-
'Apps: User-space applications', 'CC0000'),
23-
24-
('buffers', 'Buffers',
25-
'Buffers: Block device cache and dirty', '00CC00'),
26-
27-
('swap', None,
28-
'Swap: Swap space used', '0000CC'),
29-
30-
('cached', 'Cached',
31-
'Cached: Parked file data (file content) cache', 'CC00CC'),
32-
33-
('unused', 'MemFree',
34-
'Free: Wasted memory', '000000'),
35-
36-
('available', 'MemAvailable',
37-
'Free: Available', '008000'),
38-
39-
('slab', 'Slab',
40-
'Slab: Kernel used memory (inode cache)', 'CCCC00'),
41-
42-
('swap_cache', 'SwapCached',
43-
'SwapCached: Fetched unmod yet swap pages', '777777'),
44-
45-
('page_tables', 'PageTables',
46-
'PageTables: Map bt virtual and physical', '770000'),
47-
48-
('vmalloc_used', 'VmallocUsed',
49-
'VMallocUsed: vmaloc() allocated by kernel', '000077'),
50-
51-
('committed', 'Committed_AS',
52-
'Committed_AS: Total committed memory', '007700'),
53-
54-
('mapped', 'Mapped',
55-
'Mapped: All mmap()ed pages', 'DF0000'),
56-
57-
('active', 'Active',
58-
'Active: Memory recently used', '00DF00'),
59-
60-
('inactive', 'Inactive',
61-
'Inactive: Memory not currently used', '0000DF')
20+
# zbx_key, meminfo_key, name, color, drawtype
21+
('total', 'MemTotal', 'Memory Total', '5CA8FF', 4),
22+
('used', None, 'Used: User-space applications', 'CC0000', 1),
23+
('buffers', 'Buffers', 'Buffers: Block device cache and dirty', '00CC00', 1),
24+
('swap', None, 'Swap: Swap space used', '0000CC', 1),
25+
('cached', 'Cached', 'Cached: Parked file data (file content) cache', 'CC00CC', 1),
26+
('unused', 'MemFree', 'Free: Wasted memory', '000000', 1),
27+
('available', 'MemAvailable', 'Free: Available', '008000', 1),
28+
('slab', 'Slab', 'Slab: Kernel used memory (inode cache)', 'CCCC00', 1),
29+
('swap_cache', 'SwapCached', 'SwapCached: Fetched unmod yet swap pages', '777777', 1),
30+
('page_tables', 'PageTables', 'PageTables: Map bt virtual and physical', '770000', 1),
31+
('vmalloc_used', 'VmallocUsed', 'VMallocUsed: vmaloc() allocated by kernel', '000077', 1),
32+
('committed', 'Committed_AS', 'Committed_AS: Total committed memory', '007700', 1),
33+
('mapped', 'Mapped', 'Mapped: All mmap()ed pages', 'DF0000', 1),
34+
('active', 'Active', 'Active: Memory recently used', '00DF00', 1),
35+
('inactive', 'Inactive', 'Inactive: Memory not currently used', '0000DF', 1)
6236
]
6337

6438
def run(self, zbx):
@@ -76,7 +50,7 @@ def run(self, zbx):
7650
zbx_key, meminfo_key = item[0], item[1]
7751
if meminfo_key is not None:
7852
result[zbx_key] = meminfo.get(meminfo_key) or 0
79-
result['apps'] = meminfo['MemTotal'] - result['unused'] \
53+
result['used'] = meminfo['MemTotal'] - result['unused'] \
8054
- result['buffers'] - result['cached'] - result['slab'] \
8155
- result['page_tables'] - result['swap_cache']
8256
result['swap'] = (meminfo.get('SwapTotal') or 0) \
@@ -103,29 +77,45 @@ def items(self, template, dashboard=False):
10377
return []
10478

10579
def graphs(self, template, dashboard=False):
106-
items = []
80+
result = ""
81+
all_items = []
82+
free_used_items = []
10783
for item in self.Items:
108-
items.append({
84+
all_items.append({
10985
'key': self.right_type(self.key, item[0]),
11086
'color': item[3]
11187
})
112-
graph = {
113-
'name': 'Memory overview', 'height': 400,
114-
'type': 1, 'items': items}
88+
if item[0] in ['cached', 'available', 'used', 'total']:
89+
free_used_items.append({
90+
'key': self.right_type(self.key, item[0]),
91+
'color': item[3],
92+
'drawtype': item[4]
93+
})
94+
graphs = [{'name': 'Server Memory Detailed Overview',
95+
'height': 400,
96+
'type': 1,
97+
'items': all_items},
98+
{'name': 'Server Free/Used Memory Overview',
99+
'height': 400,
100+
'type': 0,
101+
'items': free_used_items}
102+
]
115103
if not dashboard:
116-
return template.graph(graph)
104+
for graph in graphs:
105+
result += template.graph(graph)
106+
return result
117107
else:
118-
return [{'dashboard': {'name': 'Memory overview',
108+
return [{'dashboard': {'name': 'Server Memory Detailed Overview',
119109
'page': ZbxTemplate.dashboard_page_overview['name'],
120110
'size': ZbxTemplate.dashboard_widget_size_medium,
121111
'position': 4}}]
122112

123113
def keys_and_queries(self, template_zabbix):
124114
result = []
125115
for item in self.Items:
126-
if item[1] is None and item[0] == 'apps':
116+
if item[1] is None and item[0] == 'used':
127117
result.append('{0},{1}'.format(self.key.format('.' + item[0]),
128-
self.query_agent_apps))
118+
self.query_agent_used))
129119
elif item[1] is None and item[0] == 'swap':
130120
result.append('{0},{1}'.format(self.key.format('.' + item[0]),
131121
self.query_agent_swap))

0 commit comments

Comments
 (0)
0