applications/luci-statistics: rework handling of index and detail graphs
[project/luci.git] / applications / luci-statistics / luasrc / statistics / rrdtool / definitions / olsrd.lua
1 --[[
2
3 Luci statistics - olsrd plugin diagram definition
4
5 Copyright 2011 Manuel Munz <freifunk at somakoma dot de>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11         http://www.apache.org/licenses/LICENSE-2.0
12 ]]--
13
14 module("luci.statistics.rrdtool.definitions.olsrd", package.seeall)
15
16 local tree = luci.statistics.datatree.Instance()
17
18 function rrdargs( graph, plugin, plugin_instance, dtype )
19         local g = { }
20
21         if plugin_instance == "routes" then
22
23                 g[#g+1] = {
24                         -- diagram data description
25                         title = "%H: Total amount of OLSR routes", vlabel = "n",
26                         number_format = "%5.0lf", data = {
27                                 types = { "routes" },
28                                 options = {
29                                         routes = {
30                                                 color = "ff0000",
31                                                 title = "Total number of routes"
32                                         }
33                                 }
34                         }
35                 }
36
37                 g[#g+1] = {
38                         title = "%H: Average route ETX", vlabel = "ETX", detail = true,
39                         number_format = "%5.1lf",data = {
40                                 instances = { "average" }, -- falls es irgendwann mal welche pro ip gibt, wie bei links, dann werden die hier excludiert
41                                 types = { "route_etx" },
42                                 options = {
43                                         route_etx = {
44                                                 title = "Average route ETX"
45                                         }
46                                 }
47                         }
48                 }
49
50                 g[#g+1] = {
51                         title = "%H: Average route metric", vlabel = "metric", detail = true,
52                         number_format = "%5.1lf", data = {
53                                 instances = { "average" }, -- falls es irgendwann mal welche pro ip gibt, wie bei links, dann werden die hier excludiert
54                                 types = { "route_metric" },
55                                 options = {
56                                         route_metric = {
57                                                 title = "Average route metric"
58                                         }
59                                 }
60                         }
61                 }
62
63         elseif plugin_instance == "links" then
64
65                 g[#g+1] = {
66                         -- diagram data description
67                         title = "%H: Total amount of OLSR neighbours", vlabel = "n",
68                         number_format = "%5.0lf", data = {
69                                 instances = { "" },
70                                 types = { "links" },
71                                 options = {
72                                         links = {
73                                                 color = "00ff00",
74                                                 title = "Number of neighbours"
75                                         }
76                                 }
77                         }
78                 }
79
80                 local instances = tree:data_instances(plugin, plugin_instance, "signal_quality")
81                 table.sort(instances)
82
83                 -- define one diagram per host, containing the rx and lq values
84                 local i
85                 for i = 1, #instances, 2 do
86                         local dsn1 = "signal_quality_%s_value" % instances[i]:gsub("[^%w]+", "_")
87                         local dsn2 = "signal_quality_%s_value" % instances[i+1]:gsub("[^%w]+", "_")
88                         local host = instances[i]:match("^[^%-]+%-([^%-]+)%-.+")
89
90                         g[#g+1] = {
91                                 title = "%H: Signal Quality" .. " (" .. (host or "avg") ..")", vlabel = "ETX",
92                                 number_format = "%5.2lf", detail = true,
93                                 data = {
94                                         types = { "signal_quality" },
95         
96                                         instances = {
97                                                 signal_quality = { instances[i], instances[i+1] },
98                                         },
99
100                                         options = {
101                                                 [dsn1] = {
102                                                         color = "00ff00",
103                                                         title = "LQ (%s)" % (host or "avg"),
104                                                 },
105                                                 [dsn2] = {
106                                                         color = "0000ff",
107                                                         title = "NLQ (%s)" % (host or "avg"),
108                                                         flip  = true
109                                                 }
110                                         }
111                                 }
112                         }
113                 end
114
115         elseif plugin_instance == "topology" then
116
117                 g[#g+1] = {
118                         title= "%H: Total amount of OLSR links", vlabel = "n",
119                         number_format = "%5.0lf", data = {
120                                 instances = { "" },
121                                 types = { "links" },
122                                 options = {
123                                         links = {
124                                                 color = "0000ff",
125                                                 title = "Total number of links"
126                                         }
127                                 }
128                         }
129                 }
130
131                 g[#g+1] = {
132                         title= "%H: Average signal quality", vlabel = "n",
133                         number_format = "%5.2lf", detail = true,
134                         data = {
135                                 instances = { "average" }, -- exclude possible per-ip stuff
136                                 types = { "signal_quality" },
137                                 options = {
138                                         signal_quality = {
139                                                 color = "0000ff",
140                                                 title = "Average signal quality"
141                                         }
142                                 }
143                         }
144                 }
145         end
146
147         return g
148 end