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