applications/luci-statistics: move all models to the per-plugin level, provide titles...
[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, is_index )
19
20 local g = { }
21
22 if plugin_instance == "routes" then
23
24 g[#g+1] = {
25 -- diagram data description
26 title = "%H: Total amount of OLSR routes", vlabel = "n",
27 number_format = "%5.0lf", data = {
28 types = { "routes" },
29 options = {
30 routes = {
31 color = "ff0000",
32 title = "Total number of routes"
33 }
34 }
35 }
36 }
37
38 if not is_index then
39 g[#g+1] = {
40 title = "%H: Average route ETX", vlabel = "ETX",
41 number_format = "%5.1lf",data = {
42 instances = { "average" }, -- falls es irgendwann mal welche pro ip gibt, wie bei links, dann werden die hier excludiert
43 types = { "route_etx" },
44 options = {
45 route_etx = {
46 title = "Average route ETX"
47 }
48 }
49 }
50 }
51
52 g[#g+1] = {
53 title = "%H: Average route metric", vlabel = "metric",
54 number_format = "%5.1lf", data = {
55 instances = { "average" }, -- falls es irgendwann mal welche pro ip gibt, wie bei links, dann werden die hier excludiert
56 types = { "route_metric" },
57 options = {
58 route_metric = {
59 title = "Average route metric"
60 }
61 }
62 }
63 }
64 end
65
66 elseif plugin_instance == "links" then
67
68 g[#g+1] = {
69 -- diagram data description
70 title = "%H: Total amount of OLSR neighbours", vlabel = "n",
71 number_format = "%5.0lf", data = {
72 instances = { "" },
73 types = { "links" },
74 options = {
75 links = {
76 color = "00ff00",
77 title = "Number of neighbours"
78 }
79 }
80 }
81 }
82
83 if not is_index then
84 local instances = tree:data_instances(plugin, plugin_instance, "signal_quality")
85 table.sort(instances)
86
87 -- define one diagram per host, containing the rx and lq values
88 local i
89 for i = 1, #instances, 2 do
90 local dsn1 = "signal_quality_%s_value" % instances[i]:gsub("[^%w]+", "_")
91 local dsn2 = "signal_quality_%s_value" % instances[i+1]:gsub("[^%w]+", "_")
92 local host = instances[i]:match("^[^%-]+%-([^%-]+)%-.+")
93
94 g[#g+1] = {
95 title = "%H: Signal Quality" .. " (" .. (host or "avg") ..")", vlabel = "ETX",
96 number_format = "%5.2lf", data = {
97 types = { "signal_quality" },
98
99 instances = {
100 signal_quality = { instances[i], instances[i+1] },
101 },
102
103 options = {
104 [dsn1] = {
105 color = "00ff00",
106 title = "LQ (%s)" % (host or "avg"),
107 },
108 [dsn2] = {
109 color = "0000ff",
110 title = "NLQ (%s)" % (host or "avg"),
111 flip = true
112 }
113 }
114 }
115 }
116 end
117 end
118
119 elseif plugin_instance == "topology" then
120
121 g[#g+1] = {
122 title= "%H: Total amount of OLSR links", vlabel = "n",
123 number_format = "%5.0lf", data = {
124 instances = { "" },
125 types = { "links" },
126 options = {
127 links = { -- or: links__value is aber egal weils eh nur eines davon gibt
128 color = "0000ff",
129 title = "Total number of links"
130 }
131 }
132 }
133 }
134
135 if not is_index then
136 g[#g+1] = {
137 title= "%H: Average signal quality", vlabel = "n",
138 number_format = "%5.2lf", data = {
139 instances = { "average" }, -- exclude possible per-ip stuff
140 types = { "signal_quality" },
141 options = {
142 signal_quality = {
143 color = "0000ff",
144 title = "Average signal quality"
145 }
146 }
147 }
148 }
149 end
150 end
151
152 return g
153 end