summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/cpu.lua
blob: 3f8910722a1914bfdb8f2da3f7c0fe75eeb2a276 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
-- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
-- Licensed to the public under the Apache License 2.0.

module("luci.statistics.rrdtool.definitions.cpu",package.seeall)

local uci = require("luci.model.uci").cursor()
local reportbystate = uci:get("luci_statistics", "collectd_cpu", "ReportByState") or "0"

function item()
	return luci.i18n.translate("Processor")
end

function rrdargs( graph, plugin, plugin_instance, dtype )
	local p = {}

	local title = "%H: Processor usage"
	if #plugin_instance > 0 then
		title = "%H: Processor usage on core #%pi"
	end

	if reportbystate == "1" then
		local cpu = {
			title = title,
			y_min = "0",
			alt_autoscale_max = true,
			vlabel = "Jiffies",
			number_format = "%5.1lf",
			data = {
				instances = {
					cpu = {
						"idle",
						"interrupt",
						"nice",
						"softirq",
						"steal",
						"system",
						"user",
						"wait"
					}
				},
				options = {
					cpu_idle = {
						color = "ffffff",
						title = "Idle"
					},
					cpu_interrupt = {
						color = "a000a0",
						title = "Interrupt"
					},
					cpu_nice = {
						color = "00e000",
						title = "Nice"
					},
					cpu_softirq = {
						color = "ff00ff",
						title = "Softirq"
					},
					cpu_steal = {
						color = "000000",
						title = "Steal"
					},
					cpu_system = {
						color = "ff0000",
						title = "System"
					},
					cpu_user = {
						color = "0000ff",
						title = "User"
					},
					cpu_wait = {
						color = "ffb000",
						title = "Wait"
					}
				}
			}
		}

		local percent = {
			title = title,
			y_min = "0",
			alt_autoscale_max = true,
			vlabel = "Percent",
			number_format = "%5.1lf%%",
			data = {
				instances = {
					percent = {
						"idle",
						"interrupt",
						"nice",
						"softirq",
						"steal",
						"system",
						"user",
						"wait"
					}
				},
				options = {
					percent_idle = {
						color = "ffffff",
						title = "Idle"
					},
					percent_interrupt = {
						color = "a000a0",
						title = "Interrupt"
					},
					percent_nice = {
						color = "00e000",
						title = "Nice"
					},
					percent_softirq = {
						color = "ff00ff",
						title = "Softirq"
					},
					percent_steal = {
						color = "000000",
						title = "Steal"
					},
					percent_system = {
						color = "ff0000",
						title = "System"
					},
					percent_user = {
						color = "0000ff",
						title = "User"
					},
					percent_wait = {
						color = "ffb000",
						title = "Wait"
					}
				}
			}
		}

		local types = graph.tree:data_types( plugin, plugin_instance )

		for _, t in ipairs(types) do
			if t == "cpu" then
				p[#p+1] = cpu
			end

			if t == "percent" then
				p[#p+1] = percent
			end
		end
	else
		p = {
			title = title,
			y_min = "0",
			alt_autoscale_max = true,
			vlabel = "Percent",
			number_format = "%5.1lf%%",
			data = {
				instances = {
					percent = {
						"active",
					}
				},
				options = {
					percent_active = {
						color = "00e000",
						title = "Active"
					}
				}
			}
		}
	end

	return p
end