treewide: import utility classes explicitly
[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 if (uci.get("luci_statistics", "collectd_cpu", "ReportByState") == "1") {
19 var cpu = {
20 title: title,
21 y_min: "0",
22 alt_autoscale_max: true,
23 vlabel: "Jiffies",
24 number_format: "%5.1lf",
25 data: {
26 instances: {
27 cpu: [
28 "idle",
29 "interrupt",
30 "nice",
31 "softirq",
32 "steal",
33 "system",
34 "user",
35 "wait"
36 ]
37 },
38 options: {
39 cpu_idle: {
40 color: "ffffff",
41 title: "Idle"
42 },
43 cpu_interrupt: {
44 color: "a000a0",
45 title: "Interrupt"
46 },
47 cpu_nice: {
48 color: "00e000",
49 title: "Nice"
50 },
51 cpu_softirq: {
52 color: "ff00ff",
53 title: "Softirq"
54 },
55 cpu_steal: {
56 color: "000000",
57 title: "Steal"
58 },
59 cpu_system: {
60 color: "ff0000",
61 title: "System"
62 },
63 cpu_user: {
64 color: "0000ff",
65 title: "User"
66 },
67 cpu_wait: {
68 color: "ffb000",
69 title: "Wait"
70 }
71 }
72 }
73 };
74
75 var percent = {
76 title: title,
77 y_min: "0",
78 alt_autoscale_max: true,
79 vlabel: "Percent",
80 number_format: "%5.1lf%%",
81 data: {
82 instances: {
83 percent: [
84 "idle",
85 "interrupt",
86 "nice",
87 "softirq",
88 "steal",
89 "system",
90 "user",
91 "wait"
92 ]
93 },
94 options: {
95 percent_idle: {
96 color: "ffffff",
97 title: "Idle"
98 },
99 percent_interrupt: {
100 color: "a000a0",
101 title: "Interrupt"
102 },
103 percent_nice: {
104 color: "00e000",
105 title: "Nice"
106 },
107 percent_softirq: {
108 color: "ff00ff",
109 title: "Softirq"
110 },
111 percent_steal: {
112 color: "000000",
113 title: "Steal"
114 },
115 percent_system: {
116 color: "ff0000",
117 title: "System"
118 },
119 percent_user: {
120 color: "0000ff",
121 title: "User"
122 },
123 percent_wait: {
124 color: "ffb000",
125 title: "Wait"
126 }
127 }
128 }
129 };
130
131 var types = graph.dataTypes(host, plugin, plugin_instance);
132
133 for (var i = 0; i < types.length; i++)
134 if (types[i] == 'cpu')
135 p.push(cpu);
136 else if (types[i] == 'percent')
137 p.push(percent);
138 }
139 else {
140 p = {
141 title: title,
142 y_min: "0",
143 alt_autoscale_max: true,
144 vlabel: "Percent",
145 number_format: "%5.1lf%%",
146 data: {
147 instances: {
148 percent: [
149 "active",
150 ]
151 },
152 options: {
153 percent_active: {
154 color: "00e000",
155 title: "Active"
156 }
157 }
158 }
159 };
160 }
161
162 return p;
163 }
164 });