]>
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 # Calculate the percentage of the currently used
41 # space since this is helps the user very much to
43 "CDEF:percentage_used=100,used,*,used,free,+,/",
44 "VDEF:percentage_used_now=percentage_used,LAST",
45 "CDEF:percentage_left=100,percentage_used,-",
46 "VDEF:percentage_left_now=percentage_left,LAST",
48 # Area for the used space
49 "AREA:used%s:%s" % (util
.lighten(LIGHT_RED
, .66), _("Used")),
50 "GPRINT:percentage_used_now: (%6.2lf%%)",
51 "GPRINT:used_cur:%12s\:" % _("Current") + " %9.2lf%s",
52 "GPRINT:used_min:%12s\:" % _("Minimum") + " %9.2lf%s",
53 "GPRINT:used_max:%12s\:" % _("Maximum") + " %9.2lf%s\\n",
55 # Stacked area of unused space
56 "AREA:free%s:%s:STACK" % (util
.lighten(LIGHT_GREEN
, .66), _("Free")),
57 "GPRINT:percentage_left_now: (%6.2lf%%)",
58 "GPRINT:free_cur:%12s\:" % _("Current") + " %9.2lf%s",
59 "GPRINT:free_min:%12s\:" % _("Minimum") + " %9.2lf%s",
60 "GPRINT:free_max:%12s\:" % _("Maximum") + " %9.2lf%s\\n",
62 # Add contour lines for the areas
63 "LINE:used%s" % LIGHT_RED
,
64 "LINE:free%s::STACK" % LIGHT_GREEN
,
68 def graph_title(self
):
69 _
= self
.locale
.translate
70 return _("Disk Usage of %s") % self
.object.mountpoint
73 def graph_vertical_label(self
):
74 _
= self
.locale
.translate
78 class GraphTemplateInodeUsage(base
.GraphTemplate
):
84 _
= self
.locale
.translate
87 # Calculate the percentage of the currently used
88 # inodes since this is helps the user very much to
90 "CDEF:percentage_used=100,inodes_used,*,inodes_used,inodes_free,+,/",
91 "CDEF:percentage_left=100,percentage_used,-",
93 # Area for the used inodes
94 "AREA:inodes_used%s:%s" % (util
.lighten(LIGHT_RED
, .66), _("Used")),
95 "GPRINT:percentage_used_now: (%6.2lf%%)",
96 "GPRINT:inodes_used_cur:%12s\:" % _("Current") + " %9.2lf%s",
97 "GPRINT:inodes_used_min:%12s\:" % _("Minimum") + " %9.2lf%s",
98 "GPRINT:inodes_used_max:%12s\:" % _("Maximum") + " %9.2lf%s\\n",
100 # Stacked area of unused inodes
101 "AREA:inodes_free%s:%s:STACK" % (util
.lighten(LIGHT_GREEN
, .66), _("Free")),
102 "GPRINT:percentage_left_now: (%6.2lf%%)",
103 "GPRINT:inodes_free_cur:%12s\:" % _("Current") + " %9.2lf%s",
104 "GPRINT:inodes_free_min:%12s\:" % _("Minimum") + " %9.2lf%s",
105 "GPRINT:inodes_free_max:%12s\:" % _("Maximum") + " %9.2lf%s\\n",
107 # Add contour lines for the areas
108 "LINE:inodes_used%s" % LIGHT_RED
,
109 "LINE:inodes_free%s::STACK" % LIGHT_GREEN
,
115 "--base", "1000", # inodes
119 def graph_title(self
):
120 _
= self
.locale
.translate
121 return _("Inode Usage of %s") % self
.object.mountpoint
124 def graph_vertical_label(self
):
125 _
= self
.locale
.translate
129 class DiskUsageObject(base
.Object
):
133 "DS:inodes_used:GAUGE:0:U",
134 "DS:inodes_free:GAUGE:0:U",
138 return "<%s %s>" % (self
.__class
__.__name
__, self
.mountpoint
)
140 def init(self
, mountpoint
):
141 self
.mountpoint
= mountpoint
145 mountpoint
= self
.mountpoint
147 if mountpoint
.startswith("/"):
148 mountpoint
= mountpoint
[1:]
153 return mountpoint
.replace("/", "-")
156 stats
= os
.statvfs(self
.mountpoint
)
160 (stats
.f_blocks
* stats
.f_frsize
) - \
161 (stats
.f_bfree
* stats
.f_bsize
),
163 stats
.f_bfree
* stats
.f_bsize
,
165 stats
.f_files
- stats
.f_ffree
,
171 class DiskUsagePlugin(base
.Plugin
):
173 description
= "Disk Usage Plugin"
176 GraphTemplateDiskUsage
,
177 GraphTemplateInodeUsage
,
182 for dev
, mnt
, fs
, opts
in _collecty
.get_mountpoints():
183 yield DiskUsageObject(self
, mnt
)