Merge pull request #1735 from sumpfralle/olsr-jsoninfo-parser-handle-empty-result
[oweals/luci.git] / applications / luci-app-statistics / luasrc / statistics / rrdtool / definitions / cpu.lua
1 -- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 module("luci.statistics.rrdtool.definitions.cpu",package.seeall)
5
6 local uci = require("luci.model.uci").cursor()
7 local reportbystate = uci:get("luci_statistics", "collectd_cpu", "ReportByState") or "0"
8
9 function item()
10         return luci.i18n.translate("Processor")
11 end
12
13 function rrdargs( graph, plugin, plugin_instance, dtype )
14         local p = {}
15
16         local title = "%H: Processor usage"
17         if #plugin_instance > 0 then
18                 title = "%H: Processor usage on core #%pi"
19         end
20
21         if reportbystate == "1" then
22                 local cpu = {
23                         title = title,
24                         y_min = "0",
25                         alt_autoscale_max = true,
26                         vlabel = "Jiffies",
27                         number_format = "%5.1lf",
28                         data = {
29                                 instances = {
30                                         cpu = {
31                                                 "idle",
32                                                 "interrupt",
33                                                 "nice",
34                                                 "softirq",
35                                                 "steal",
36                                                 "system",
37                                                 "user",
38                                                 "wait"
39                                         }
40                                 },
41                                 options = {
42                                         cpu_idle = {
43                                                 color = "ffffff",
44                                                 title = "Idle"
45                                         },
46                                         cpu_interrupt = {
47                                                 color = "a000a0",
48                                                 title = "Interrupt"
49                                         },
50                                         cpu_nice = {
51                                                 color = "00e000",
52                                                 title = "Nice"
53                                         },
54                                         cpu_softirq = {
55                                                 color = "ff00ff",
56                                                 title = "Softirq"
57                                         },
58                                         cpu_steal = {
59                                                 color = "000000",
60                                                 title = "Steal"
61                                         },
62                                         cpu_system = {
63                                                 color = "ff0000",
64                                                 title = "System"
65                                         },
66                                         cpu_user = {
67                                                 color = "0000ff",
68                                                 title = "User"
69                                         },
70                                         cpu_wait = {
71                                                 color = "ffb000",
72                                                 title = "Wait"
73                                         }
74                                 }
75                         }
76                 }
77
78                 local percent = {
79                         title = title,
80                         y_min = "0",
81                         alt_autoscale_max = true,
82                         vlabel = "Percent",
83                         number_format = "%5.1lf%%",
84                         data = {
85                                 instances = {
86                                         percent = {
87                                                 "idle",
88                                                 "interrupt",
89                                                 "nice",
90                                                 "softirq",
91                                                 "steal",
92                                                 "system",
93                                                 "user",
94                                                 "wait"
95                                         }
96                                 },
97                                 options = {
98                                         percent_idle = {
99                                                 color = "ffffff",
100                                                 title = "Idle"
101                                         },
102                                         percent_interrupt = {
103                                                 color = "a000a0",
104                                                 title = "Interrupt"
105                                         },
106                                         percent_nice = {
107                                                 color = "00e000",
108                                                 title = "Nice"
109                                         },
110                                         percent_softirq = {
111                                                 color = "ff00ff",
112                                                 title = "Softirq"
113                                         },
114                                         percent_steal = {
115                                                 color = "000000",
116                                                 title = "Steal"
117                                         },
118                                         percent_system = {
119                                                 color = "ff0000",
120                                                 title = "System"
121                                         },
122                                         percent_user = {
123                                                 color = "0000ff",
124                                                 title = "User"
125                                         },
126                                         percent_wait = {
127                                                 color = "ffb000",
128                                                 title = "Wait"
129                                         }
130                                 }
131                         }
132                 }
133
134                 local types = graph.tree:data_types( plugin, plugin_instance )
135
136                 for _, t in ipairs(types) do
137                         if t == "cpu" then
138                                 p[#p+1] = cpu
139                         end
140
141                         if t == "percent" then
142                                 p[#p+1] = percent
143                         end
144                 end
145         else
146                 p = {
147                         title = title,
148                         y_min = "0",
149                         alt_autoscale_max = true,
150                         vlabel = "Percent",
151                         number_format = "%5.1lf%%",
152                         data = {
153                                 instances = {
154                                         percent = {
155                                                 "active",
156                                         }
157                                 },
158                                 options = {
159                                         percent_active = {
160                                                 color = "00e000",
161                                                 title = "Active"
162                                         }
163                                 }
164                         }
165                 }
166         end
167
168         return p
169 end