]>
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 *
26 class GraphTemplateMemory(base
.GraphTemplate
):
34 _
= self
.locale
.translate
37 "AREA:used%s:%-15s" % (lighten(MEMORY_USED
, AREA_OPACITY
), _("Used memory")),
38 "GPRINT:used_max:%12s\:" % _("Maximum") + " %6.2lf" ,
39 "GPRINT:used_min:%12s\:" % _("Minimum") + " %6.2lf",
40 "GPRINT:used_avg:%12s\:" % _("Average") + " %6.2lf\\n",
42 "STACK:buffered%s:%-15s" % (lighten(MEMORY_BUFFERED
, AREA_OPACITY
), _("Buffered data")),
43 "GPRINT:buffered_max:%12s\:" % _("Maximum") + " %6.2lf" ,
44 "GPRINT:buffered_min:%12s\:" % _("Minimum") + " %6.2lf",
45 "GPRINT:buffered_avg:%12s\:" % _("Average") + " %6.2lf\\n",
47 "STACK:cached%s:%-15s" % (lighten(MEMORY_CACHED
, AREA_OPACITY
), _("Cached data")),
48 "GPRINT:cached_max:%12s\:" % _("Maximum") + " %6.2lf" ,
49 "GPRINT:cached_min:%12s\:" % _("Minimum") + " %6.2lf",
50 "GPRINT:cached_avg:%12s\:" % _("Average") + " %6.2lf\\n",
52 # "STACK:free#7799ff:%-15s" % _("Free memory"),
53 # "GPRINT:free_max:%12s\:" % _("Maximum") + " %6.2lf" ,
54 # "GPRINT:free_min:%12s\:" % _("Minimum") + " %6.2lf",
55 # "GPRINT:free_avg:%12s\:" % _("Average") + " %6.2lf\\n",
57 "LINE3:swap%s:%-15s" % (MEMORY_SWAP
, _("Used Swap space")),
58 "GPRINT:swap_max:%12s\:" % _("Maximum") + " %6.2lf" ,
59 "GPRINT:swap_min:%12s\:" % _("Minimum") + " %6.2lf",
60 "GPRINT:swap_avg:%12s\:" % _("Average") + " %6.2lf\\n",
62 # Draw the outlines of the areas
63 "LINE1:used%s" % MEMORY_USED
,
64 "LINE1:buffered%s::STACK" % MEMORY_BUFFERED
,
65 "LINE1:cached%s::STACK" % MEMORY_CACHED
,
69 def graph_title(self
):
70 _
= self
.locale
.translate
71 return _("Memory Usage")
74 def graph_vertical_label(self
):
75 _
= self
.locale
.translate
79 class MemoryObject(base
.Object
):
81 "DS:used:GAUGE:0:100",
82 "DS:cached:GAUGE:0:100",
83 "DS:buffered:GAUGE:0:100",
84 "DS:free:GAUGE:0:100",
85 "DS:swap:GAUGE:0:100",
93 with
open("/proc/meminfo") as f
:
95 if line
.startswith("MemTotal:"):
96 total
= float(line
.split()[1])
97 if line
.startswith("MemFree:"):
98 free
= float(line
.split()[1])
99 elif line
.startswith("Buffers:"):
100 buffered
= float(line
.split()[1])
101 elif line
.startswith("Cached:"):
102 cached
= float(line
.split()[1])
103 elif line
.startswith("SwapTotal:"):
104 swapt
= float(line
.split()[1])
105 elif line
.startswith("SwapFree:"):
106 swapf
= float(line
.split()[1])
109 "%s" % ((total
- (free
+ buffered
+ cached
)) * 100 / total
),
110 "%s" % (cached
* 100 / total
),
111 "%s" % (buffered
* 100 / total
),
112 "%s" % (free
* 100 / total
),
116 ret
.append("%s" % ((swapt
- swapf
) * 100 / swapt
))
123 class MemoryPlugin(base
.Plugin
):
125 description
= "Memory Usage Plugin"
127 templates
= [GraphTemplateMemory
]
131 yield MemoryObject(self
)