treewide: import utility classes explicitly
[project/luci.git] / applications / luci-app-statistics / htdocs / luci-static / resources / view / statistics / plugins / irq.js
1 'use strict';
2 'require baseclass';
3 'require fs';
4 'require form';
5
6 return baseclass.extend({
7 title: _('IRQ Plugin Configuration'),
8 description: _('The irq plugin will monitor the rate of issues per second for each selected interrupt. If no interrupt is selected then all interrupts are monitored.'),
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, 'Irqs', _('Monitor interrupts'));
16 o.optional = true;
17 o.multiple = true;
18 o.depends('enable', '1');
19 o.load = function(section_id) {
20 return fs.trimmed('/proc/interrupts').then(L.bind(function(str) {
21 var lines = str.split(/\n/),
22 cpus = L.toArray(lines[0]);
23
24 for (var i = 1; i < lines.length; i++) {
25 var line = lines[i],
26 m = lines[i].match(/^\s*([^\s:]+):/);
27
28 if (!m)
29 continue;
30
31 line = line.replace(/^[^:]+:\s+/, '');
32
33 for (var j = 0; j < cpus.length; j++)
34 line = line.replace(/^\d+\s*/, '');
35
36 var desc = line.split(/ {2,}/).join(', ');
37
38 this.value(m[1], '%s (%s)'.format(m[1], desc || '-'));
39 }
40
41 return this.super('load', [section_id]);
42 }, this));
43 };
44
45 o = s.option(form.Flag, 'IgnoreSelected', _('Monitor all except specified'));
46 o.depends('enable', '1');
47 },
48
49 configSummary: function(section) {
50 var irqs = L.toArray(section.Irqs),
51 invert = section.IgnoreSelected == '1';
52
53 if (irqs.length == 0)
54 return _('Monitoring all interrupts');
55 else if (invert)
56 return N_(irqs.length, 'Monitoring all but one interrupt', 'Monitoring all but %d interrupts').format(irqs.length);
57 else
58 return N_(irqs.length, 'Monitoring one interrupt', 'Monitoring %d interrupts').format(irqs.length);
59 }
60 });