luci-app-statistics: treat APC UPS "host" setting as single value option
[project/luci.git] / applications / luci-app-statistics / htdocs / luci-static / resources / view / statistics / plugins / df.js
1 'use strict';
2 'require baseclass';
3 'require fs';
4 'require form';
5
6 return baseclass.extend({
7 title: _('DF Plugin Configuration'),
8 description: _('The df plugin collects statistics about the disk space usage on different devices, mount points or filesystem types.'),
9
10 addFormOptions: function(s) {
11 var o;
12
13 o = s.option(form.Flag, 'enable', _('Enable this plugin'));
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.depends('enable', '1');
91
92 o = s.option(form.Flag, 'ValuesPercentage', _('Free space, reserved space and used space is reported as relative values'));
93 o.depends('enable', '1');
94 },
95
96 configSummary: function(section) {
97 var devs = L.toArray(section.Devices),
98 mounts = L.toArray(section.MountPoints),
99 fstypes = L.toArray(section.FSTypes),
100 count = devs.length + mounts.length + fstypes.length,
101 invert = section.IgnoreSelected == '1';
102
103 if (count == 0)
104 return _('Monitoring all partitions');
105 else
106 return (invert ? _('Monitoring all except %s, %s, %s') : _('Monitoring %s, %s, %s')).format(
107 N_(devs.length, 'one device', '%d devices').format(devs.length),
108 N_(mounts.length, 'one mount', '%d mounts').format(mounts.length),
109 N_(fstypes.length, 'one filesystem type', '%d filesystem types').format(fstypes.length)
110 );
111 }
112 });