]>
git.ipfire.org Git - collecty.git/blob - 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 class PluginMemory(base
.Plugin
):
27 _name
= "Memory Usage Plugin"
30 _rrd
= ["DS:used:GAUGE:120:0:100",
31 "DS:cached:GAUGE:120:0:100",
32 "DS:buffered:GAUGE:120:0:100",
33 "DS:free:GAUGE:120:0:100",
34 "DS:swap:GAUGE:120:0:100",
35 "RRA:AVERAGE:0.5:1:2160",
36 "RRA:AVERAGE:0.5:5:2016",
37 "RRA:AVERAGE:0.5:15:2880",
38 "RRA:AVERAGE:0.5:60:8760" ]
40 _graph
= [ "DEF:used=%(file)s:used:AVERAGE",
41 "DEF:cached=%(file)s:cached:AVERAGE",
42 "DEF:buffered=%(file)s:buffered:AVERAGE",
43 "DEF:free=%(file)s:free:AVERAGE",
44 "DEF:swap=%(file)s:swap:AVERAGE",
45 "AREA:used#0000ee:%-15s" % _("Used memory"),
46 "VDEF:usedmin=used,MINIMUM",
47 "VDEF:usedmax=used,MAXIMUM",
48 "VDEF:usedavg=used,AVERAGE",
49 "GPRINT:usedmax:%12s\:" % _("Maximum") + " %6.2lf" ,
50 "GPRINT:usedmin:%12s\:" % _("Minimum") + " %6.2lf",
51 "GPRINT:usedavg:%12s\:" % _("Average") + " %6.2lf\\n",
52 "STACK:cached#0099ee:%-15s" % _("Cached data"),
53 "VDEF:cachedmin=cached,MINIMUM",
54 "VDEF:cachedmax=cached,MAXIMUM",
55 "VDEF:cachedavg=cached,AVERAGE",
56 "GPRINT:cachedmax:%12s\:" % _("Maximum") + " %6.2lf" ,
57 "GPRINT:cachedmin:%12s\:" % _("Minimum") + " %6.2lf",
58 "GPRINT:cachedavg:%12s\:" % _("Average") + " %6.2lf\\n",
59 "STACK:buffered#4499ff:%-15s" % _("Buffered data"),
60 "VDEF:bufferedmin=buffered,MINIMUM",
61 "VDEF:bufferedmax=buffered,MAXIMUM",
62 "VDEF:bufferedavg=buffered,AVERAGE",
63 "GPRINT:bufferedmax:%12s\:" % _("Maximum") + " %6.2lf" ,
64 "GPRINT:bufferedmin:%12s\:" % _("Minimum") + " %6.2lf",
65 "GPRINT:bufferedavg:%12s\:" % _("Average") + " %6.2lf\\n",
66 "STACK:free#7799ff:%-15s" % _("Free memory"),
67 "VDEF:freemin=free,MINIMUM",
68 "VDEF:freemax=free,MAXIMUM",
69 "VDEF:freeavg=free,AVERAGE",
70 "GPRINT:freemax:%12s\:" % _("Maximum") + " %6.2lf" ,
71 "GPRINT:freemin:%12s\:" % _("Minimum") + " %6.2lf",
72 "GPRINT:freeavg:%12s\:" % _("Average") + " %6.2lf\\n",
73 "LINE3:swap#ff0000:%-15s" % _("Used Swap space"),
74 "VDEF:swapmin=swap,MINIMUM",
75 "VDEF:swapmax=swap,MAXIMUM",
76 "VDEF:swapavg=swap,AVERAGE",
77 "GPRINT:swapmax:%12s\:" % _("Maximum") + " %6.2lf" ,
78 "GPRINT:swapmin:%12s\:" % _("Minimum") + " %6.2lf",
79 "GPRINT:swapavg:%12s\:" % _("Average") + " %6.2lf\\n", ]
81 def __init__(self
, collecty
, **kwargs
):
82 Plugin
.__init
__(self
, collecty
, **kwargs
)
85 ret
= "%s" % self
.time()
86 f
= open("/proc/meminfo")
87 for line
in f
.readlines():
88 if line
.startswith("MemTotal:"):
89 total
= float(line
.split()[1])
90 if line
.startswith("MemFree:"):
91 free
= float(line
.split()[1])
92 elif line
.startswith("Buffers:"):
93 buffered
= float(line
.split()[1])
94 elif line
.startswith("Cached:"):
95 cached
= float(line
.split()[1])
96 elif line
.startswith("SwapTotal:"):
97 swapt
= float(line
.split()[1])
98 elif line
.startswith("SwapFree:"):
99 swapf
= float(line
.split()[1])
103 ret
+= ":%s" % ((total
- (free
+ buffered
+ cached
)) * 100 / total
)
104 ret
+= ":%s" % (cached
* 100 / total
)
105 ret
+= ":%s" % (buffered
* 100 / total
)
106 ret
+= ":%s" % (free
* 100 / total
)
107 ret
+= ":%s" % ((swapt
- swapf
) * 100 / swapt
)