* luci/statistics: implement flip, overlay and total options for diagram models,...
[project/luci.git] / applications / luci-statistics / luasrc / statistics / rrdtool / definitions / netlink.lua
1 module("luci.statistics.rrdtool.definitions.netlink", package.seeall)
2
3 function rrdargs( graph, host, plugin, plugin_instance )
4
5         local diagram_list = { }
6
7         -- diagram names
8         local dtypes_names = {
9                 "Verkehr",
10                 "Pakete",
11                 "Multicast-Pakete",
12                 "Paketkollisionen",
13                 "Paketfehler",
14                 "RX-Fehler",
15                 "TX-Fehler"
16         }
17
18         -- diagram units
19         local dtypes_units = {
20                 "Bytes/s",
21                 "Pakete/s",
22                 "Pakete/s",
23                 "Kollisionen/s",
24                 "Fehler/s",                             -- (?)
25                 "Fehler/s",
26                 "Fehler/s"
27         }
28
29         -- data source overrides
30         local dtypes_sources = {
31                 if_errors  = { "tx", "rx" },            -- if_errors has tx and rx
32                 if_octets  = { "tx", "rx" },            -- if_octets has tx and rx
33                 if_packets = { "tx", "rx" },            -- if_packets has tx and rx
34                 if_dropped = { "tx", "rx" },            -- if_dopped has tx and rx
35         }
36
37         -- diagram data types
38         local dtypes_list  = {
39
40                 -- diagram 1: interface traffic statistics
41                 {
42                         if_octets     = { "" }          -- bytes/s
43                 },
44
45                 -- diagram 2: combined interface packet statistics
46                 { 
47                         if_dropped    = { "" },         -- packets/s
48                         if_packets    = { "" }          -- packets/s
49                 },
50
51                 -- diagram 3: multicast count
52                 {
53                         if_multicast  = { "" }          -- packets/s
54                 },
55
56                 -- diagram 4: interface collision statistics
57                 {
58                         if_collisions = { "" }          -- collisions/s
59                 },
60
61                 -- diagram 5: interface error statistics
62                 {
63                         if_errors     = { "" }          -- errors/s (?)
64                 },
65
66                 -- diagram 6: interface rx error statistics
67                 {
68                         if_rx_errors  = {               -- errors/s
69                                 "length", "missed", "over", "crc", "fifo", "frame"
70                         }
71                 },
72
73                 -- diagram 7: interface tx error statistics
74                 {
75                         if_tx_errors  = {               -- errors/s
76                                 "aborted", "carrier", "fifo", "heartbeat", "window"
77                         }
78                 }
79         }
80
81         -- diagram colors
82         local dtypes_colors = {
83
84                 -- diagram 1
85                 {
86                         if_octets__tx_  = "00ff00",
87                         if_octets__rx_  = "0000ff"
88                 },
89
90                 -- diagram 2
91                 {
92                         if_dropped__tx_ = "ff0000",
93                         if_dropped__rx_ = "ff5500",
94                         if_packets__tx_ = "00ff00",
95                         if_packets__rx_ = "0000ff"
96                 },
97
98                 -- diagram 3
99                 {
100                         if_multicast    = "0000ff"
101                 },
102
103                 -- diagram 4
104                 {
105                         if_collisions   = "ff0000"
106                 },
107
108                 -- diagram 5
109                 {
110                         if_errors__tx_  = "ff0000",
111                         if_errors__rx_  = "ff5500"
112                 },
113
114                 -- diagram 6
115                 {
116                         length          = "0000ff",
117                         missed          = "ff5500",
118                         over            = "ff0066",
119                         crc             = "ff0000",
120                         fifo            = "00ff00",
121                         frame           = "ffff00"
122                 },
123
124                 -- diagram 7
125                 {
126                         aborted         = "ff0000",
127                         carrier         = "ffff00",
128                         fifo            = "00ff00",
129                         heartbeat       = "0000ff",
130                         window          = "8800ff"
131                 }
132         }
133
134
135         for i, name in ipairs(dtypes_names) do
136
137                 local dtypes = dtypes_list[i]
138                 local opts   = { }
139
140                 opts.sources = { }
141                 opts.image   = graph:mkpngpath( host, plugin, plugin_instance, "netlink" .. i )
142                 opts.title   = host .. ": Netlink Statistiken - " .. name .. " auf " .. plugin_instance
143                 opts.rrd     = { "-v", dtypes_units[i] }
144                 opts.colors  = dtypes_colors[i]
145
146                 for dtype, dinstances in pairs(dtypes) do
147                         for i, inst in ipairs(dinstances) do
148
149                                 local name = inst
150                                 if name:len() == 0 then name = dtype end
151
152                                 -- check for data source override
153                                 if dtypes_sources[dtype] then
154
155                                         -- has override
156                                         for i, ds in ipairs(dtypes_sources[dtype]) do
157                                                 table.insert( opts.sources, {
158                                                         ds    = ds,     -- override
159                                                         name  = name .. " (" .. ds .. ")",
160                                                         rrd   = graph:mkrrdpath( host, plugin, plugin_instance, dtype, inst ),
161                                                         flip  = ( ds == "rx" ),
162                                                         total = ( ds == "rx" or ds == "tx" )
163                                                 } )
164                                         end
165                                 else
166                                         -- no override, assume single "value" data source
167                                         table.insert( opts.sources, {
168                                                 name  = name,
169                                                 rrd   = graph:mkrrdpath( host, plugin, plugin_instance, dtype, inst ),
170                                                 total = ( name == "if_multicast" )
171                                         } )
172                                 end
173                         end
174                 end
175
176                 table.insert( diagram_list, opts )
177         end
178
179         return diagram_list
180 end