2d317d38fb2771ed9619248675a17777b678f1eb
[project/luci.git] / applications / luci-app-statistics / htdocs / luci-static / resources / view / statistics / plugins / df.js
1 'use strict';
2 'require fs';
3 'require form';
4
5 return L.Class.extend({
6 title: _('DF Plugin Configuration'),
7 description: _('The df plugin collects statistics about the disk space usage on different devices, mount points or filesystem types.'),
8
9 addFormOptions: function(s) {
10 var o;
11
12 o = s.option(form.Flag, 'enable', _('Enable this plugin'));
13 o.default = '0';
14
15 o = s.option(form.DynamicList, 'Devices', _('Monitor devices'));
16 o.optional = true;
17 o.depends('enable', '1');
18 o.load = function(section_id) {
19 return fs.lines('/proc/partitions').then(L.bind(function(lines) {
20 var parts = [];
21
22 for (var i = 0; i < lines.length; i++) {
23 var line = L.toArray(lines[i]);
24 if (!isNaN(line[0]))
25 parts.push('/dev/' + line[3]);
26 }
27
28 parts.sort();
29
30 for (var i = 0; i < parts.length; i++)
31 this.value(parts[i]);
32
33 return this.super('load', [section_id]);
34 }, this));
35 };
36
37 o = s.option(form.DynamicList, 'MountPoints', _('Monitor mount points'));
38 o.default = '/overlay';
39 o.optional = true;
40 o.depends('enable', '1');
41 o.load = function(section_id) {
42 return fs.lines('/proc/mounts').then(L.bind(function(lines) {
43 var mounts = {};
44
45 for (var i = 0; i < lines.length; i++) {
46 var line = L.toArray(lines[i]);
47 mounts[line[1]] = true;
48 }
49
50 mounts = Object.keys(mounts).sort();
51
52 for (var i = 0; i < mounts.length; i++)
53 this.value(mounts[i]);
54
55 return this.super('load', [section_id]);
56 }, this));
57 };
58
59 o = s.option(form.DynamicList, 'FSTypes', _('Monitor filesystem types'));
60 o.default = 'tmpfs';
61 o.optional = true;
62 o.depends('enable', '1');
63 o.load = function(section_id) {
64 return Promise.all([
65 fs.lines('/etc/filesystems'),
66 fs.lines('/proc/filesystems')
67 ]).then(L.bind(function(lines) {
68 var fslines = lines[0].concat(lines[1]),
69 fstypes = {};
70
71 for (var i = 0; i < fslines.length; i++) {
72 var line = L.toArray(fslines[i]);
73
74 if (line.length == 2 && line[0] == 'nodev')
75 continue;
76
77 fstypes[line.pop()] = true;
78 }
79
80 fstypes = Object.keys(fstypes).sort();
81
82 for (var i = 0; i < fstypes.length; i++)
83 this.value(fstypes[i]);
84
85 return this.super('load', [section_id]);
86 }, this));
87 };
88
89 o = s.option(form.Flag, 'IgnoreSelected', _('Monitor all except specified'));
90 o.default = '0';
91 o.depends('enable', '1');
92 },
93
94 configSummary: function(section) {
95 var devs = L.toArray(section.Devices),
96 mounts = L.toArray(section.MountPoints),
97 fstypes = L.toArray(section.FSTypes),
98 count = devs.length + mounts.length + fstypes.length,
99 invert = section.IgnoreSelected == '1';
100
101 if (count == 0)
102 return _('Monitoring all partitions');
103 else
104 return (invert ? _('Monitoring all except %s, %s, %s') : _('Monitoring %s, %s, %s')).format(
105 N_(devs.length, 'one device', '%d devices').format(devs.length),
106 N_(mounts.length, 'one mount', '%d mounts').format(mounts.length),
107 N_(fstypes.length, 'one filesystem type', '%d filesystem types').format(fstypes.length)
108 );
109 }
110 });