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