]>
git.ipfire.org Git - 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 ###############################################################################
26 from ..colours
import *
28 class GraphTemplateMemory(base
.GraphTemplate
):
36 _
= self
.locale
.translate
39 "AREA:used%s:%-15s" % (util
.lighten(MEMORY_USED
, AREA_OPACITY
), _("Used memory")),
40 "GPRINT:used_max:%12s\:" % _("Maximum") + " %6.2lf" ,
41 "GPRINT:used_min:%12s\:" % _("Minimum") + " %6.2lf",
42 "GPRINT:used_avg:%12s\:" % _("Average") + " %6.2lf\\n",
44 "STACK:buffered%s:%-15s" % (util
.lighten(MEMORY_BUFFERED
, AREA_OPACITY
), _("Buffered data")),
45 "GPRINT:buffered_max:%12s\:" % _("Maximum") + " %6.2lf" ,
46 "GPRINT:buffered_min:%12s\:" % _("Minimum") + " %6.2lf",
47 "GPRINT:buffered_avg:%12s\:" % _("Average") + " %6.2lf\\n",
49 "STACK:cached%s:%-15s" % (util
.lighten(MEMORY_CACHED
, AREA_OPACITY
), _("Cached data")),
50 "GPRINT:cached_max:%12s\:" % _("Maximum") + " %6.2lf" ,
51 "GPRINT:cached_min:%12s\:" % _("Minimum") + " %6.2lf",
52 "GPRINT:cached_avg:%12s\:" % _("Average") + " %6.2lf\\n",
54 # "STACK:free#7799ff:%-15s" % _("Free memory"),
55 # "GPRINT:free_max:%12s\:" % _("Maximum") + " %6.2lf" ,
56 # "GPRINT:free_min:%12s\:" % _("Minimum") + " %6.2lf",
57 # "GPRINT:free_avg:%12s\:" % _("Average") + " %6.2lf\\n",
59 "LINE3:swap%s:%-15s" % (MEMORY_SWAP
, _("Used Swap space")),
60 "GPRINT:swap_max:%12s\:" % _("Maximum") + " %6.2lf" ,
61 "GPRINT:swap_min:%12s\:" % _("Minimum") + " %6.2lf",
62 "GPRINT:swap_avg:%12s\:" % _("Average") + " %6.2lf\\n",
64 # Draw the outlines of the areas
65 "LINE1:used%s" % MEMORY_USED
,
66 "LINE1:buffered%s::STACK" % MEMORY_BUFFERED
,
67 "LINE1:cached%s::STACK" % MEMORY_CACHED
,
71 def graph_title(self
):
72 _
= self
.locale
.translate
73 return _("Memory Usage")
76 def graph_vertical_label(self
):
77 _
= self
.locale
.translate
81 class MemoryObject(base
.Object
):
83 "DS:used:GAUGE:0:100",
84 "DS:cached:GAUGE:0:100",
85 "DS:buffered:GAUGE:0:100",
86 "DS:free:GAUGE:0:100",
87 "DS:swap:GAUGE:0:100",
98 f
= open("/proc/meminfo")
99 for line
in f
.readlines():
100 if line
.startswith("MemTotal:"):
101 total
= float(line
.split()[1])
102 if line
.startswith("MemFree:"):
103 free
= float(line
.split()[1])
104 elif line
.startswith("Buffers:"):
105 buffered
= float(line
.split()[1])
106 elif line
.startswith("Cached:"):
107 cached
= float(line
.split()[1])
108 elif line
.startswith("SwapTotal:"):
109 swapt
= float(line
.split()[1])
110 elif line
.startswith("SwapFree:"):
111 swapf
= float(line
.split()[1])
114 "%s" % ((total
- (free
+ buffered
+ cached
)) * 100 / total
),
115 "%s" % (cached
* 100 / total
),
116 "%s" % (buffered
* 100 / total
),
117 "%s" % (free
* 100 / total
),
121 ret
.append("%s" % ((swapt
- swapf
) * 100 / swapt
))
131 class MemoryPlugin(base
.Plugin
):
133 description
= "Memory Usage Plugin"
135 templates
= [GraphTemplateMemory
]
139 yield MemoryObject(self
)