]>
git.ipfire.org Git - oddments/collecty.git/blob - src/collecty/plugins/memory.py
2 ###############################################################################
4 # collecty - A system statistics collection daemon for IPFire #
5 # Copyright (C) 2012 IPFire development team #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
24 from ..colours
import *
25 from ..constants
import *
27 class GraphTemplateMemory(base
.GraphTemplate
):
35 _
= self
.locale
.translate
39 "COMMENT:%s" % EMPTY_LABEL
,
40 "COMMENT:%s" % (COLUMN
% _("Current")),
41 "COMMENT:%s" % (COLUMN
% _("Average")),
42 "COMMENT:%s" % (COLUMN
% _("Minimum")),
43 "COMMENT:%s\\j" % (COLUMN
% _("Maximum")),
46 transparency(MEMORY_USED
, AREA_OPACITY
),
47 LABEL
% _("Used Memory"),
49 "GPRINT:used_cur:%s" % PERCENTAGE
,
50 "GPRINT:used_avg:%s" % PERCENTAGE
,
51 "GPRINT:used_min:%s" % PERCENTAGE
,
52 "GPRINT:used_max:%s\\j" % PERCENTAGE
,
54 "STACK:buffered%s:%s" % (
55 transparency(MEMORY_BUFFERED
, AREA_OPACITY
),
56 LABEL
% _("Buffered Data"),
58 "GPRINT:buffered_cur:%s" % PERCENTAGE
,
59 "GPRINT:buffered_avg:%s" % PERCENTAGE
,
60 "GPRINT:buffered_min:%s" % PERCENTAGE
,
61 "GPRINT:buffered_max:%s\\j" % PERCENTAGE
,
63 "STACK:cached%s:%s" % (
64 lighten(MEMORY_CACHED
, AREA_OPACITY
),
65 LABEL
% _("Cached data")),
66 "GPRINT:cached_cur:%s" % PERCENTAGE
,
67 "GPRINT:cached_avg:%s" % PERCENTAGE
,
68 "GPRINT:cached_min:%s" % PERCENTAGE
,
69 "GPRINT:cached_max:%s\\j" % PERCENTAGE
,
71 # "STACK:free#7799ff:%-15s" % _("Free memory"),
72 # "GPRINT:free_max:%12s\:" % _("Maximum") + " %6.2lf" ,
73 # "GPRINT:free_min:%12s\:" % _("Minimum") + " %6.2lf",
74 # "GPRINT:free_avg:%12s\:" % _("Average") + " %6.2lf",
76 "LINE3:swap%s:%-15s" % (MEMORY_SWAP
, LABEL
% _("Used Swap Space")),
77 "GPRINT:swap_cur:%s" % PERCENTAGE
,
78 "GPRINT:swap_avg:%s" % PERCENTAGE
,
79 "GPRINT:swap_min:%s" % PERCENTAGE
,
80 "GPRINT:swap_max:%s\\j" % PERCENTAGE
,
82 # Draw the outlines of the areas
83 "LINE1:used%s" % MEMORY_USED
,
84 "LINE1:buffered%s::STACK" % MEMORY_BUFFERED
,
85 "LINE1:cached%s::STACK" % MEMORY_CACHED
,
89 def graph_title(self
):
90 _
= self
.locale
.translate
92 return _("Memory Usage")
95 def graph_vertical_label(self
):
96 _
= self
.locale
.translate
101 class MemoryObject(base
.Object
):
103 "DS:used:GAUGE:0:100",
104 "DS:cached:GAUGE:0:100",
105 "DS:buffered:GAUGE:0:100",
106 "DS:free:GAUGE:0:100",
107 "DS:swap:GAUGE:0:100",
115 with
open("/proc/meminfo") as f
:
117 if line
.startswith("MemTotal:"):
118 total
= float(line
.split()[1])
119 if line
.startswith("MemFree:"):
120 free
= float(line
.split()[1])
121 elif line
.startswith("Buffers:"):
122 buffered
= float(line
.split()[1])
123 elif line
.startswith("Cached:"):
124 cached
= float(line
.split()[1])
125 elif line
.startswith("SwapTotal:"):
126 swapt
= float(line
.split()[1])
127 elif line
.startswith("SwapFree:"):
128 swapf
= float(line
.split()[1])
131 "%s" % ((total
- (free
+ buffered
+ cached
)) * 100 / total
),
132 "%s" % (cached
* 100 / total
),
133 "%s" % (buffered
* 100 / total
),
134 "%s" % (free
* 100 / total
),
138 ret
.append("%s" % ((swapt
- swapf
) * 100 / swapt
))
145 class MemoryPlugin(base
.Plugin
):
147 description
= "Memory Usage Plugin"
149 templates
= [GraphTemplateMemory
]
153 yield MemoryObject(self
)