]>
git.ipfire.org Git - oddments/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 ###############################################################################
24 from .. import _collecty
27 from ..constants
import *
28 from ..colours
import *
30 class GraphTemplateDiskUsage(base
.GraphTemplate
):
36 _
= self
.locale
.translate
39 # Calculate the percentage of the currently used
40 # space since this is helps the user very much to
42 "CDEF:percentage_used=100,used,*,used,free,+,/",
43 "VDEF:percentage_used_now=percentage_used,LAST",
44 "CDEF:percentage_left=100,percentage_used,-",
45 "VDEF:percentage_left_now=percentage_left,LAST",
47 # Area for the used space
48 "AREA:used%s:%s" % (transparency(LIGHT_RED
, AREA_OPACITY
), _("Used")),
49 "GPRINT:percentage_used_now: (%6.2lf%%)",
50 "GPRINT:used_cur:%12s\:" % _("Current") + " %9.2lf%s",
51 "GPRINT:used_min:%12s\:" % _("Minimum") + " %9.2lf%s",
52 "GPRINT:used_max:%12s\:" % _("Maximum") + " %9.2lf%s",
54 # Stacked area of unused space
55 "AREA:free%s:%s:STACK" % (transparency(LIGHT_GREEN
, AREA_OPACITY
), _("Free")),
56 "GPRINT:percentage_left_now: (%6.2lf%%)",
57 "GPRINT:free_cur:%12s\:" % _("Current") + " %9.2lf%s",
58 "GPRINT:free_min:%12s\:" % _("Minimum") + " %9.2lf%s",
59 "GPRINT:free_max:%12s\:" % _("Maximum") + " %9.2lf%s",
61 # Add contour lines for the areas
62 "LINE:used%s" % LIGHT_RED
,
63 "LINE:free%s::STACK" % LIGHT_GREEN
,
67 def graph_title(self
):
68 _
= self
.locale
.translate
69 return _("Disk Usage of %s") % self
.object.mountpoint
72 def graph_vertical_label(self
):
73 _
= self
.locale
.translate
77 class GraphTemplateInodeUsage(base
.GraphTemplate
):
83 _
= self
.locale
.translate
86 # Calculate the percentage of the currently used
87 # inodes since this is helps the user very much to
89 "CDEF:percentage_used=100,inodes_used,*,inodes_used,inodes_free,+,/",
90 "CDEF:percentage_left=100,percentage_used,-",
92 # Area for the used inodes
93 "AREA:inodes_used%s:%s" % (lighten(LIGHT_RED
, .66), _("Used")),
94 "GPRINT:percentage_used_now: (%6.2lf%%)",
95 "GPRINT:inodes_used_cur:%12s\:" % _("Current") + " %9.2lf%s",
96 "GPRINT:inodes_used_min:%12s\:" % _("Minimum") + " %9.2lf%s",
97 "GPRINT:inodes_used_max:%12s\:" % _("Maximum") + " %9.2lf%s",
99 # Stacked area of unused inodes
100 "AREA:inodes_free%s:%s:STACK" % (lighten(LIGHT_GREEN
, .66), _("Free")),
101 "GPRINT:percentage_left_now: (%6.2lf%%)",
102 "GPRINT:inodes_free_cur:%12s\:" % _("Current") + " %9.2lf%s",
103 "GPRINT:inodes_free_min:%12s\:" % _("Minimum") + " %9.2lf%s",
104 "GPRINT:inodes_free_max:%12s\:" % _("Maximum") + " %9.2lf%s",
106 # Add contour lines for the areas
107 "LINE:inodes_used%s" % LIGHT_RED
,
108 "LINE:inodes_free%s::STACK" % LIGHT_GREEN
,
114 "--base", "1000", # inodes
118 def graph_title(self
):
119 _
= self
.locale
.translate
120 return _("Inode Usage of %s") % self
.object.mountpoint
123 def graph_vertical_label(self
):
124 _
= self
.locale
.translate
128 class DiskUsageObject(base
.Object
):
132 "DS:inodes_used:GAUGE:0:U",
133 "DS:inodes_free:GAUGE:0:U",
137 return "<%s %s>" % (self
.__class
__.__name
__, self
.mountpoint
)
139 def init(self
, mountpoint
):
140 self
.mountpoint
= mountpoint
144 mountpoint
= self
.mountpoint
146 if mountpoint
.startswith("/"):
147 mountpoint
= mountpoint
[1:]
152 return mountpoint
.replace("/", "-")
155 stats
= os
.statvfs(self
.mountpoint
)
159 (stats
.f_blocks
* stats
.f_frsize
) - \
160 (stats
.f_bfree
* stats
.f_bsize
),
162 stats
.f_bfree
* stats
.f_bsize
,
164 stats
.f_files
- stats
.f_ffree
,
170 class DiskUsagePlugin(base
.Plugin
):
172 description
= "Disk Usage Plugin"
175 GraphTemplateDiskUsage
,
176 GraphTemplateInodeUsage
,
181 for dev
, mnt
, fs
, opts
in _collecty
.get_mountpoints():
182 yield DiskUsageObject(self
, mnt
)