diff options
author | Rosy Song <rosysong@rosinson.com> | 2018-08-03 12:16:39 +0800 |
---|---|---|
committer | Rosy Song <rosysong@rosinson.com> | 2018-11-06 15:38:12 +0800 |
commit | 6b8235721a3bdf8b041e5370eef2e253e5874070 (patch) | |
tree | be86c8de7815838659ad5c50f6313b5fb13e3f7a /applications/luci-app-nft-qos/luasrc/controller/nft-qos.lua | |
parent | a6d96e0716dd63af9254cf8db850c921459454c6 (diff) |
luci-app-nft-qos: add new application
This application is for nft-qos package.
Signed-off-by: Rosy Song <rosysong@rosinson.com>
Diffstat (limited to 'applications/luci-app-nft-qos/luasrc/controller/nft-qos.lua')
-rw-r--r-- | applications/luci-app-nft-qos/luasrc/controller/nft-qos.lua | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/applications/luci-app-nft-qos/luasrc/controller/nft-qos.lua b/applications/luci-app-nft-qos/luasrc/controller/nft-qos.lua new file mode 100644 index 0000000000..42043505dc --- /dev/null +++ b/applications/luci-app-nft-qos/luasrc/controller/nft-qos.lua @@ -0,0 +1,51 @@ +-- Copyright 2018 Rosy Song <rosysong@rosinson.com> +-- Licensed to the public under the Apache License 2.0. + +module("luci.controller.nft-qos", package.seeall) + +function index() + if not nixio.fs.access("/etc/config/nft-qos") then + return + end + + entry({"admin", "status", "realtime", "rate"}, + template("nft-qos/rate"), _("Rate"), 5).leaf = true + entry({"admin", "status", "realtime", "rate_status"}, + call("action_rate")).leaf = true + entry({"admin", "services", "nft-qos"}, cbi("nft-qos/nft-qos"), + _("Qos over Nftables"), 60) +end + +function _action_rate(rv, n) + local c = io.popen("nft list chain inet nft-qos-monitor " .. n .. " 2>/dev/null") + if c then + for l in c:lines() do + local _, i, p, b = l:match('^%s+ip ([^%s]+) ([^%s]+) counter packets (%d+) bytes (%d+)') + if i and p and b then + -- handle expression + local r = { + rule = { + family = "inet", + table = "nft-qos-monitor", + chain = n, + handle = 0, + expr = { + { match = { right = i } }, + { counter = { packets = p, bytes = b } } + } + } + } + rv[#rv + 1] = r + end + end + c:close() + end +end + +function action_rate() + luci.http.prepare_content("application/json") + local data = { nftables = {} } + _action_rate(data.nftables, "upload") + _action_rate(data.nftables, "download") + luci.http.write_json(data) +end |