]>
git.ipfire.org Git - collecty.git/blob - src/collecty/plugins/memory.py
6569a80b18c0a7a34f1a5ac87b3a3103b727121c
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 class GraphTemplateMemory(base
.GraphTemplate
):
34 _
= self
.locale
.translate
37 "AREA:used#90EE90:%-15s" % _("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#4169E1:%-15s" % _("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#FFD700:%-15s" % _("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#ff0000:%-15s" % _("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",
64 def graph_title(self
):
65 _
= self
.locale
.translate
66 return _("Memory Usage")
69 def graph_vertical_label(self
):
70 _
= self
.locale
.translate
74 class MemoryObject(base
.Object
):
76 "DS:used:GAUGE:0:100",
77 "DS:cached:GAUGE:0:100",
78 "DS:buffered:GAUGE:0:100",
79 "DS:free:GAUGE:0:100",
80 "DS:swap:GAUGE:0:100",
91 f
= open("/proc/meminfo")
92 for line
in f
.readlines():
93 if line
.startswith("MemTotal:"):
94 total
= float(line
.split()[1])
95 if line
.startswith("MemFree:"):
96 free
= float(line
.split()[1])
97 elif line
.startswith("Buffers:"):
98 buffered
= float(line
.split()[1])
99 elif line
.startswith("Cached:"):
100 cached
= float(line
.split()[1])
101 elif line
.startswith("SwapTotal:"):
102 swapt
= float(line
.split()[1])
103 elif line
.startswith("SwapFree:"):
104 swapf
= float(line
.split()[1])
107 "%s" % ((total
- (free
+ buffered
+ cached
)) * 100 / total
),
108 "%s" % (cached
* 100 / total
),
109 "%s" % (buffered
* 100 / total
),
110 "%s" % (free
* 100 / total
),
114 ret
.append("%s" % ((swapt
- swapf
) * 100 / swapt
))
124 class MemoryPlugin(base
.Plugin
):
126 description
= "Memory Usage Plugin"
128 templates
= [GraphTemplateMemory
]
132 yield MemoryObject(self
)