luci2: move most RPC proxy function declarations into the views using them to reduce...
[project/luci2/ui.git] / luci2 / htdocs / luci2 / view / status.processes.js
1 L.ui.view.extend({
2 title: L.tr('Processes'),
3 description: L.tr('This list gives an overview over currently running system processes and their status.'),
4
5 getProcessList: L.rpc.declare({
6 object: 'luci2.system',
7 method: 'process_list',
8 expect: { processes: [ ] },
9 filter: function(data) {
10 data.sort(function(a, b) { return a.pid - b.pid });
11 return data;
12 }
13 }),
14
15 sendSignal: L.rpc.declare({
16 object: 'luci2.system',
17 method: 'process_signal',
18 params: [ 'pid', 'signal' ],
19 filter: function(data) {
20 return (data == 0);
21 }
22 }),
23
24 execute: function() {
25 var self = this;
26 var allow_signals = this.options.acls.status;
27 return self.getProcessList().then(function(list) {
28 var procTable = new L.ui.table({
29 columns: [ {
30 caption: L.tr('PID'),
31 key: 'pid'
32 }, {
33 caption: L.tr('Owner'),
34 key: 'user'
35 }, {
36 caption: L.tr('Command'),
37 key: 'command'
38 }, {
39 caption: L.tr('CPU usage (%)'),
40 key: 'cpu_percent',
41 format: '%d%%'
42 }, {
43 caption: L.tr('Memory usage (%)'),
44 key: 'vsize_percent',
45 format: '%d%%'
46 }, {
47 key: 'pid',
48 format: function(v, n) {
49 return $('<div />')
50 .addClass('btn-group')
51 .append($('<button />')
52 .addClass('btn btn-primary btn-sm dropdown-toggle')
53 .attr('data-toggle', 'dropdown')
54 .text(L.tr('Signal…')))
55 .append($('<ul />')
56 .addClass('dropdown-menu pull-right')
57 .append($('<li />')
58 .append($('<a />')
59 .attr('href', '#')
60 .html('%s (<code>%s</code>)'.format(L.trc('UNIX signal', 'Reload'), 'HUP'))
61 .click(function(ev) { self.sendSignal(v, 1).then(status); ev.preventDefault(); })))
62 .append($('<li />')
63 .append($('<a />')
64 .attr('href', '#')
65 .html('%s (<code>%s</code>)'.format(L.trc('UNIX signal', 'Terminate'), 'TERM'))
66 .click(function(ev) { self.sendSignal(v, 15).then(status); ev.preventDefault(); })))
67 .append($('<li />')
68 .append($('<a />')
69 .attr('href', '#')
70 .html('%s (<code>%s</code>)'.format(L.trc('UNIX signal', 'Kill immediately'), 'KILL'))
71 .click(function(ev) { self.sendSignal(v, 9).then(status); ev.preventDefault(); }))))
72 }
73 } ]
74 });
75
76 procTable.rows(list);
77 procTable.insertInto('#process_table');
78 });
79 }
80 });