f0c194dac5a98e738c89851498b24a7a519b7ee2
[project/luci.git] / applications / luci-livestats / luasrc / view / livestats / traffic.htm
1 <%+header%>
2
3 <!--[if IE]><script type="text/javascript" src="<%=resource%>/livestats/ExCanvas.js"></script><![endif]-->
4 <script type="text/javascript" src="<%=resource%>/livestats/MochiKit.js"></script>
5 <script type="text/javascript" src="<%=resource%>/livestats/JsonRpc.js"></script>
6 <script type="text/javascript" src="<%=resource%>/livestats/PlotKit.js"></script>
7 <script type="text/javascript" src="<%=resource%>/livestats/GraphRPC.js"></script>
8 <script type="text/javascript" src="<%=resource%>/livestats/Legend.js"></script>
9
10 <%
11         local interfaces = { }
12         local ifnames = {}
13         local uci = luci.model.uci.cursor_state()
14
15         uci:foreach("network", "interface",
16                 function(s)
17                         if s.ifname ~= "lo" then
18                                 table.insert( interfaces,
19                                         "'" .. ( s.ifname or s['.name'] ) .. "'"
20                                 )
21                                 ifnames[s.ifname or s['.name']] = s['.name']
22                         end
23                 end
24         )
25 -%>
26
27 <script type="text/javascript">
28         function initGraphs() {
29                 var rpc = new GraphRPC(
30                         document.getElementById('live_graphs'),
31                         '<%=luci.dispatcher.build_url('rpc', 'sys')%>', 'net.deviceinfo',
32                         2000,
33
34                         // Data sources
35                         [ "0", "<%:livestats_incoming%> (kiB/s)", "8", "<%:livestats_outgoing%> (kiB/s)" ],
36
37                         // Graph layout options
38                         { 
39                         shouldFill: false, 
40                         drawBackground: false, 
41                         strokeColor: null,
42                         title: '<%:livestats_traffic%> %s',
43                         strokeWidth: 2.5, height: 140,
44                         padding: { left: 70, right: 10, top: 10, bottom: 20 },
45                         instances: [ <%=table.concat(interfaces, ", ") %> ],
46                         instanceNames: {
47                                 <%- for iface, network in pairs(ifnames) do %>
48                                         <%-="%q:%q," % {iface, network}-%>
49                                 <% end %>
50                                 "0": ""
51                         }},
52
53                         // transform function
54                         function (cur, last) {
55                                 return (cur - last) / 2048;
56                         },
57                         'live_graphs'
58                 );
59         }
60
61         MochiKit.DOM.addLoadEvent(initGraphs);
62 </script>
63
64 <div id="live_graphs"></div>
65
66 <%+footer%>