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