luci-app-statistics: CPU plugin: hide 'idle', tweak defaults
[project/luci.git] / applications / luci-app-statistics / htdocs / luci-static / resources / statistics / rrdtool / definitions / cpu.js
1 /* Licensed to the public under the Apache License 2.0. */
2
3 'use strict';
4 'require baseclass';
5 'require uci';
6
7 return baseclass.extend({
8 title: _('Processor'),
9
10 rrdargs: function(graph, host, plugin, plugin_instance, dtype) {
11 var p = [];
12
13 var title = "%H: Processor usage";
14
15 if (plugin_instance != '')
16 title = "%H: Processor usage on core #%pi";
17
18 var show_idle = uci.get("luci_statistics", "collectd_cpu", "ShowIdle") == "1" ? true : false;
19
20 if (uci.get("luci_statistics", "collectd_cpu", "ReportByState") == "1") {
21 var cpu = {
22 title: title,
23 y_min: "0",
24 alt_autoscale_max: true,
25 vlabel: "Jiffies",
26 number_format: "%5.1lf",
27 data: {
28 instances: {
29 cpu: [
30 ...(show_idle ? ["idle"] : []),
31 "interrupt",
32 "nice",
33 "softirq",
34 "steal",
35 "system",
36 "user",
37 "wait"
38 ]
39 },
40 options: {
41 cpu_idle: {
42 color: "ffffff",
43 title: "Idle"
44 },
45 cpu_interrupt: {
46 color: "a000a0",
47 title: "Interrupt"
48 },
49 cpu_nice: {
50 color: "00e000",
51 title: "Nice"
52 },
53 cpu_softirq: {
54 color: "ff00ff",
55 title: "Softirq"
56 },
57 cpu_steal: {
58 color: "000000",
59 title: "Steal"
60 },
61 cpu_system: {
62 color: "ff0000",
63 title: "System"
64 },
65 cpu_user: {
66 color: "0000ff",
67 title: "User"
68 },
69 cpu_wait: {
70 color: "ffb000",
71 title: "Wait"
72 }
73 }
74 }
75 };
76
77 var percent = {
78 title: title,
79 y_min: "0",
80 alt_autoscale_max: true,
81 vlabel: "Percent",
82 number_format: "%5.1lf%%",
83 data: {
84 instances: {
85 percent: [
86 ...(show_idle ? ["idle"] : []),
87 "interrupt",
88 "nice",
89 "softirq",
90 "steal",
91 "system",
92 "user",
93 "wait"
94 ]
95 },
96 options: {
97 percent_idle: {
98 color: "ffffff",
99 title: "Idle"
100 },
101 percent_interrupt: {
102 color: "a000a0",
103 title: "Interrupt"
104 },
105 percent_nice: {
106 color: "00e000",
107 title: "Nice"
108 },
109 percent_softirq: {
110 color: "ff00ff",
111 title: "Softirq"
112 },
113 percent_steal: {
114 color: "000000",
115 title: "Steal"
116 },
117 percent_system: {
118 color: "ff0000",
119 title: "System"
120 },
121 percent_user: {
122 color: "0000ff",
123 title: "User"
124 },
125 percent_wait: {
126 color: "ffb000",
127 title: "Wait"
128 }
129 }
130 }
131 };
132
133 var types = graph.dataTypes(host, plugin, plugin_instance);
134
135 for (var i = 0; i < types.length; i++)
136 if (types[i] == 'cpu')
137 p.push(cpu);
138 else if (types[i] == 'percent')
139 p.push(percent);
140 }
141 else {
142 p = {
143 title: title,
144 y_min: "0",
145 alt_autoscale_max: true,
146 vlabel: "Percent",
147 number_format: "%5.1lf%%",
148 data: {
149 instances: {
150 percent: [
151 "active",
152 ]
153 },
154 options: {
155 percent_active: {
156 color: "00e000",
157 title: "Active"
158 }
159 }
160 }
161 };
162 }
163
164 return p;
165 }
166 });