5
5
class Memory (Plugin ):
6
6
AgentPluginType = 'sys'
7
7
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 }'); " \
9
9
"SUM=$(cat /proc/meminfo | awk '/(MemFree|Buffers|(Swap)?Cached|Slab|PageTables)\:/ " \
10
10
"{ SUM += $2 } END {print SUM}'); echo $((($MemTotal-$SUM)*1024))"
11
11
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):
17
17
# 2. virtual memory
18
18
19
19
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 )
62
36
]
63
37
64
38
def run (self , zbx ):
@@ -76,7 +50,7 @@ def run(self, zbx):
76
50
zbx_key , meminfo_key = item [0 ], item [1 ]
77
51
if meminfo_key is not None :
78
52
result [zbx_key ] = meminfo .get (meminfo_key ) or 0
79
- result ['apps ' ] = meminfo ['MemTotal' ] - result ['unused' ] \
53
+ result ['used ' ] = meminfo ['MemTotal' ] - result ['unused' ] \
80
54
- result ['buffers' ] - result ['cached' ] - result ['slab' ] \
81
55
- result ['page_tables' ] - result ['swap_cache' ]
82
56
result ['swap' ] = (meminfo .get ('SwapTotal' ) or 0 ) \
@@ -103,29 +77,45 @@ def items(self, template, dashboard=False):
103
77
return []
104
78
105
79
def graphs (self , template , dashboard = False ):
106
- items = []
80
+ result = ""
81
+ all_items = []
82
+ free_used_items = []
107
83
for item in self .Items :
108
- items .append ({
84
+ all_items .append ({
109
85
'key' : self .right_type (self .key , item [0 ]),
110
86
'color' : item [3 ]
111
87
})
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
+ ]
115
103
if not dashboard :
116
- return template .graph (graph )
104
+ for graph in graphs :
105
+ result += template .graph (graph )
106
+ return result
117
107
else :
118
- return [{'dashboard' : {'name' : 'Memory overview ' ,
108
+ return [{'dashboard' : {'name' : 'Server Memory Detailed Overview ' ,
119
109
'page' : ZbxTemplate .dashboard_page_overview ['name' ],
120
110
'size' : ZbxTemplate .dashboard_widget_size_medium ,
121
111
'position' : 4 }}]
122
112
123
113
def keys_and_queries (self , template_zabbix ):
124
114
result = []
125
115
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 ' :
127
117
result .append ('{0},{1}' .format (self .key .format ('.' + item [0 ]),
128
- self .query_agent_apps ))
118
+ self .query_agent_used ))
129
119
elif item [1 ] is None and item [0 ] == 'swap' :
130
120
result .append ('{0},{1}' .format (self .key .format ('.' + item [0 ]),
131
121
self .query_agent_swap ))
0 commit comments