]>
git.ipfire.org Git - collecty.git/blob - src/collecty/plugins/df.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 ###############################################################################
22 from collecty
import _collecty
25 from ..constants
import *
31 class GraphTemplateDiskUsage(base
.GraphTemplate
):
37 _
= self
.locale
.translate
40 "DEF:used=%(file)s:used:AVERAGE",
41 "VDEF:used_cur=used,LAST",
42 "VDEF:used_min=used,MINIMUM",
43 "VDEF:used_max=used,MAXIMUM",
45 "DEF:free=%(file)s:free:AVERAGE",
46 "VDEF:free_cur=free,LAST",
47 "VDEF:free_min=free,MINIMUM",
48 "VDEF:free_max=free,MAXIMUM",
50 # Calculate the percentage of the currently used
51 # space since this is helps the user very much to
53 "CDEF:percentage_used=100,used,*,used,free,+,/",
54 "VDEF:percentage_used_now=percentage_used,LAST",
55 "CDEF:percentage_left=100,percentage_used,-",
56 "VDEF:percentage_left_now=percentage_left,LAST",
58 # Area for the used space
59 "AREA:used%s:%s" % (util
.lighten(LIGHT_RED
, .66), _("Used")),
60 "GPRINT:percentage_used_now: (%6.2lf%%)",
61 "GPRINT:used_cur:%12s\:" % _("Current") + " %9.2lf%s",
62 "GPRINT:used_min:%12s\:" % _("Minimum") + " %9.2lf%s",
63 "GPRINT:used_max:%12s\:" % _("Maximum") + " %9.2lf%s\\n",
65 # Stacked area of unused space
66 "AREA:free%s:%s:STACK" % (util
.lighten(LIGHT_GREEN
, .66), _("Free")),
67 "GPRINT:percentage_left_now: (%6.2lf%%)",
68 "GPRINT:free_cur:%12s\:" % _("Current") + " %9.2lf%s",
69 "GPRINT:free_min:%12s\:" % _("Minimum") + " %9.2lf%s",
70 "GPRINT:free_max:%12s\:" % _("Maximum") + " %9.2lf%s\\n",
72 # Add contour lines for the areas
73 "LINE:used%s" % LIGHT_RED
,
74 "LINE:free%s::STACK" % LIGHT_GREEN
,
78 def graph_title(self
):
79 _
= self
.locale
.translate
80 return _("Disk Usage of %s") % self
.object.mountpoint
83 def graph_vertical_label(self
):
84 _
= self
.locale
.translate
88 class GraphTemplateInodeUsage(base
.GraphTemplate
):
94 _
= self
.locale
.translate
97 "DEF:used=%(file)s:inodes_used:AVERAGE",
98 "VDEF:used_cur=used,LAST",
99 "VDEF:used_min=used,MINIMUM",
100 "VDEF:used_max=used,MAXIMUM",
102 "DEF:free=%(file)s:inodes_free:AVERAGE",
103 "VDEF:free_cur=free,LAST",
104 "VDEF:free_min=free,MINIMUM",
105 "VDEF:free_max=free,MAXIMUM",
107 # Calculate the percentage of the currently used
108 # inodes since this is helps the user very much to
110 "CDEF:percentage_used=100,used,*,used,free,+,/",
111 "VDEF:percentage_used_now=percentage_used,LAST",
112 "CDEF:percentage_left=100,percentage_used,-",
113 "VDEF:percentage_left_now=percentage_left,LAST",
115 # Area for the used inodes
116 "AREA:used%s:%s" % (util
.lighten(LIGHT_RED
, .66), _("Used")),
117 "GPRINT:percentage_used_now: (%6.2lf%%)",
118 "GPRINT:used_cur:%12s\:" % _("Current") + " %9.2lf%s",
119 "GPRINT:used_min:%12s\:" % _("Minimum") + " %9.2lf%s",
120 "GPRINT:used_max:%12s\:" % _("Maximum") + " %9.2lf%s\\n",
122 # Stacked area of unused inodes
123 "AREA:free%s:%s:STACK" % (util
.lighten(LIGHT_GREEN
, .66), _("Free")),
124 "GPRINT:percentage_left_now: (%6.2lf%%)",
125 "GPRINT:free_cur:%12s\:" % _("Current") + " %9.2lf%s",
126 "GPRINT:free_min:%12s\:" % _("Minimum") + " %9.2lf%s",
127 "GPRINT:free_max:%12s\:" % _("Maximum") + " %9.2lf%s\\n",
129 # Add contour lines for the areas
130 "LINE:used%s" % LIGHT_RED
,
131 "LINE:free%s::STACK" % LIGHT_GREEN
,
137 "--base", "1000", # inodes
141 def graph_title(self
):
142 _
= self
.locale
.translate
143 return _("Inode Usage of %s") % self
.object.mountpoint
146 def graph_vertical_label(self
):
147 _
= self
.locale
.translate
151 class DiskUsageObject(base
.Object
):
155 "DS:inodes_used:GAUGE:0:U",
156 "DS:inodes_free:GAUGE:0:U",
160 return "<%s %s>" % (self
.__class
__.__name
__, self
.mountpoint
)
162 def init(self
, mountpoint
):
163 self
.mountpoint
= mountpoint
167 mountpoint
= self
.mountpoint
169 if mountpoint
.startswith("/"):
170 mountpoint
= mountpoint
[1:]
175 return mountpoint
.replace("/", "-")
178 stats
= os
.statvfs(self
.mountpoint
)
182 (stats
.f_blocks
* stats
.f_frsize
) - \
183 (stats
.f_bfree
* stats
.f_bsize
),
185 stats
.f_bfree
* stats
.f_bsize
,
187 stats
.f_files
- stats
.f_ffree
,
193 class DiskUsagePlugin(base
.Plugin
):
195 description
= "Disk Usage Plugin"
198 GraphTemplateDiskUsage
,
199 GraphTemplateInodeUsage
,
204 for dev
, mnt
, fs
, opts
in _collecty
.get_mountpoints():
205 yield DiskUsageObject(self
, mnt
)