summaryrefslogtreecommitdiffstats
path: root/applications/luci-app-statistics/htdocs/luci-static/resources/view/statistics/plugins/irq.js
blob: ac4b6d7a46c42e37d9bfe28acdf44dcdb93382ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
'require baseclass';
'require fs';
'require form';

return baseclass.extend({
	title: _('IRQ Plugin Configuration'),
	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.'),

	addFormOptions(s) {
		let o;

		o = s.option(form.Flag, 'enable', _('Enable this plugin'));

		o = s.option(form.DynamicList, 'Irqs', _('Monitor interrupts'));
		o.optional = true;
		o.multiple = true;
		o.depends('enable', '1');
		o.load = function(section_id) {
			return fs.trimmed('/proc/interrupts').then(L.bind(function(str) {
				const lines = str.split(/\n/);
				const cpus = L.toArray(lines[0]);

				for (let line of lines) {
					const m = line.match(/^\s*([^\s:]+):/);

					if (!m)
						continue;

					line = line.replace(/^[^:]+:\s+/, '');

					for (let j = 0; j < cpus.length; j++)
						line = line.replace(/^\d+\s*/, '');

					var desc = line.split(/ {2,}/).join(', ');

					this.value(m[1], '%s (%s)'.format(m[1], desc || '-'));
				}

				return this.super('load', [section_id]);
			}, this));
		};

		o = s.option(form.Flag, 'IgnoreSelected', _('Monitor all except specified'));
		o.depends('enable', '1');
	},

	configSummary(section) {
		const irqs = L.toArray(section.Irqs);
		const invert = section.IgnoreSelected == '1';

		if (irqs.length == 0)
			return _('Monitoring all interrupts');
		else if (invert)
			return N_(irqs.length, 'Monitoring all but one interrupt', 'Monitoring all but %d interrupts').format(irqs.length);
		else
			return N_(irqs.length, 'Monitoring one interrupt', 'Monitoring %d interrupts').format(irqs.length);
	}
});