]>
Commit | Line | Data |
---|---|---|
9823dfef MT |
1 | #!/usr/bin/python3 |
2 | ############################################################################### | |
3 | # # | |
4 | # collecty - A system statistics collection daemon for IPFire # | |
5 | # Copyright (C) 2012 IPFire development team # | |
6 | # # | |
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. # | |
11 | # # | |
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. # | |
16 | # # | |
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/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
9823dfef MT |
22 | import os |
23 | ||
a031204a | 24 | from .. import _collecty |
9823dfef MT |
25 | from . import base |
26 | ||
a031204a MT |
27 | from ..constants import * |
28 | from ..colours import * | |
9823dfef MT |
29 | |
30 | class GraphTemplateDiskUsage(base.GraphTemplate): | |
31 | name = "disk-usage" | |
32 | lower_limit = 0 | |
33 | ||
34 | @property | |
35 | def rrd_graph(self): | |
36 | _ = self.locale.translate | |
37 | ||
38 | return [ | |
97cb4bea MT |
39 | "COMMENT:%s" % EMPTY_LABEL, |
40 | "COMMENT:%s" % (COLUMN % _("Current")), | |
41 | "COMMENT:%s" % (COLUMN % _("Average")), | |
42 | "COMMENT:%s" % (COLUMN % _("Minimum")), | |
43 | "COMMENT:%s\\j" % (COLUMN % _("Maximum")), | |
9823dfef MT |
44 | |
45 | # Area for the used space | |
97cb4bea MT |
46 | "AREA:used%s:%s" % ( |
47 | transparency(LIGHT_RED, AREA_OPACITY), | |
48 | LABEL % _("Used"), | |
49 | ), | |
50 | "GPRINT:used_cur:%s" % LARGE_FLOAT, | |
51 | "GPRINT:used_avg:%s" % LARGE_FLOAT, | |
52 | "GPRINT:used_min:%s" % LARGE_FLOAT, | |
53 | "GPRINT:used_max:%s\\j" % LARGE_FLOAT, | |
9823dfef MT |
54 | |
55 | # Stacked area of unused space | |
97cb4bea MT |
56 | "AREA:free%s:%s:STACK" % ( |
57 | transparency(LIGHT_GREEN, AREA_OPACITY), | |
58 | LABEL % _("Free"), | |
59 | ), | |
60 | "GPRINT:free_cur:%s" % LARGE_FLOAT, | |
61 | "GPRINT:free_avg:%s" % LARGE_FLOAT, | |
62 | "GPRINT:free_min:%s" % LARGE_FLOAT, | |
63 | "GPRINT:free_max:%s\\j" % LARGE_FLOAT, | |
9823dfef MT |
64 | |
65 | # Add contour lines for the areas | |
66 | "LINE:used%s" % LIGHT_RED, | |
67 | "LINE:free%s::STACK" % LIGHT_GREEN, | |
68 | ] | |
69 | ||
70 | @property | |
71 | def graph_title(self): | |
72 | _ = self.locale.translate | |
73 | return _("Disk Usage of %s") % self.object.mountpoint | |
74 | ||
75 | @property | |
76 | def graph_vertical_label(self): | |
77 | _ = self.locale.translate | |
78 | return _("Bytes") | |
79 | ||
80 | ||
81 | class GraphTemplateInodeUsage(base.GraphTemplate): | |
82 | name = "inode-usage" | |
83 | lower_limit = 0 | |
84 | ||
85 | @property | |
86 | def rrd_graph(self): | |
87 | _ = self.locale.translate | |
88 | ||
89 | rrd_graph = [ | |
97cb4bea MT |
90 | "COMMENT:%s" % EMPTY_LABEL, |
91 | "COMMENT:%s" % (COLUMN % _("Current")), | |
92 | "COMMENT:%s" % (COLUMN % _("Average")), | |
93 | "COMMENT:%s" % (COLUMN % _("Minimum")), | |
94 | "COMMENT:%s\\j" % (COLUMN % _("Maximum")), | |
9823dfef MT |
95 | |
96 | # Area for the used inodes | |
97cb4bea MT |
97 | "AREA:inodes_used%s:%s" % ( |
98 | transparency(LIGHT_RED, AREA_OPACITY), | |
99 | LABEL % _("Used"), | |
100 | ), | |
101 | "GPRINT:inodes_used_cur:%s" % LARGE_FLOAT, | |
102 | "GPRINT:inodes_used_avg:%s" % LARGE_FLOAT, | |
103 | "GPRINT:inodes_used_min:%s" % LARGE_FLOAT, | |
104 | "GPRINT:inodes_used_max:%s\\j" % LARGE_FLOAT, | |
9823dfef MT |
105 | |
106 | # Stacked area of unused inodes | |
97cb4bea MT |
107 | "AREA:inodes_free%s:%s:STACK" % ( |
108 | transparency(LIGHT_GREEN, AREA_OPACITY), | |
109 | LABEL % _("Free"), | |
110 | ), | |
111 | "GPRINT:inodes_free_cur:%s" % LARGE_FLOAT, | |
112 | "GPRINT:inodes_free_avg:%s" % LARGE_FLOAT, | |
113 | "GPRINT:inodes_free_min:%s" % LARGE_FLOAT, | |
114 | "GPRINT:inodes_free_max:%s\\j" % LARGE_FLOAT, | |
9823dfef MT |
115 | |
116 | # Add contour lines for the areas | |
cd8bba0b MT |
117 | "LINE:inodes_used%s" % LIGHT_RED, |
118 | "LINE:inodes_free%s::STACK" % LIGHT_GREEN, | |
9823dfef MT |
119 | ] |
120 | ||
121 | return rrd_graph | |
122 | ||
123 | rrd_graph_args = [ | |
124 | "--base", "1000", # inodes | |
125 | ] | |
126 | ||
127 | @property | |
128 | def graph_title(self): | |
129 | _ = self.locale.translate | |
130 | return _("Inode Usage of %s") % self.object.mountpoint | |
131 | ||
132 | @property | |
133 | def graph_vertical_label(self): | |
134 | _ = self.locale.translate | |
135 | return _("Inodes") | |
136 | ||
137 | ||
138 | class DiskUsageObject(base.Object): | |
139 | rrd_schema = [ | |
140 | "DS:used:GAUGE:0:U", | |
141 | "DS:free:GAUGE:0:U", | |
142 | "DS:inodes_used:GAUGE:0:U", | |
143 | "DS:inodes_free:GAUGE:0:U", | |
144 | ] | |
145 | ||
146 | def __repr__(self): | |
147 | return "<%s %s>" % (self.__class__.__name__, self.mountpoint) | |
148 | ||
149 | def init(self, mountpoint): | |
150 | self.mountpoint = mountpoint | |
151 | ||
152 | @property | |
153 | def id(self): | |
154 | mountpoint = self.mountpoint | |
155 | ||
156 | if mountpoint.startswith("/"): | |
157 | mountpoint = mountpoint[1:] | |
158 | ||
159 | if not mountpoint: | |
160 | return "root" | |
161 | ||
162 | return mountpoint.replace("/", "-") | |
163 | ||
164 | def collect(self): | |
165 | stats = os.statvfs(self.mountpoint) | |
166 | ||
167 | return ( | |
168 | # used | |
169 | (stats.f_blocks * stats.f_frsize) - \ | |
170 | (stats.f_bfree * stats.f_bsize), | |
171 | # free | |
172 | stats.f_bfree * stats.f_bsize, | |
173 | # inodes used | |
174 | stats.f_files - stats.f_ffree, | |
175 | # inodes free | |
176 | stats.f_ffree, | |
177 | ) | |
178 | ||
179 | ||
180 | class DiskUsagePlugin(base.Plugin): | |
181 | name = "df" | |
182 | description = "Disk Usage Plugin" | |
183 | ||
184 | templates = [ | |
185 | GraphTemplateDiskUsage, | |
186 | GraphTemplateInodeUsage, | |
187 | ] | |
188 | ||
189 | @property | |
190 | def objects(self): | |
191 | for dev, mnt, fs, opts in _collecty.get_mountpoints(): | |
192 | yield DiskUsageObject(self, mnt) |