luci-app-statistics: add initial support for collectd-mod-openvpn
authorJo-Philipp Wich <jow@openwrt.org>
Mon, 5 Oct 2015 16:55:28 +0000 (18:55 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Mon, 5 Oct 2015 16:55:28 +0000 (18:55 +0200)
This changeset covers compression and traffic stats, not every combination has
been tested yet.

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
applications/luci-app-statistics/luasrc/controller/luci_statistics/luci_statistics.lua
applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/openvpn.lua [new file with mode: 0644]
applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/openvpn.lua [new file with mode: 0644]
applications/luci-app-statistics/root/usr/bin/stat-genconfig

index e9e716c..3f26aee 100644 (file)
@@ -42,6 +42,7 @@ function index()
                network         = _("Network"),
                nut                     = _("UPS"),
                olsrd           = _("OLSRd"),
                network         = _("Network"),
                nut                     = _("UPS"),
                olsrd           = _("OLSRd"),
+               openvpn         = _("OpenVPN"),
                ping            = _("Ping"),
                processes       = _("Processes"),
                rrdtool         = _("RRDTool"),
                ping            = _("Ping"),
                processes       = _("Processes"),
                rrdtool         = _("RRDTool"),
@@ -56,7 +57,7 @@ function index()
        local collectd_menu = {
                output  = { "csv", "network", "rrdtool", "unixsock" },
                general = { "cpu", "df", "disk", "email", "entropy", "exec", "irq", "load", "memory", "nut", "processes", "sensors", "uptime" },
        local collectd_menu = {
                output  = { "csv", "network", "rrdtool", "unixsock" },
                general = { "cpu", "df", "disk", "email", "entropy", "exec", "irq", "load", "memory", "nut", "processes", "sensors", "uptime" },
-               network = { "conntrack", "dns", "interface", "iptables", "netlink", "olsrd", "ping", "splash_leases", "tcpconns", "iwinfo" }
+               network = { "conntrack", "dns", "interface", "iptables", "netlink", "olsrd", "openvpn", "ping", "splash_leases", "tcpconns", "iwinfo" }
        }
 
        -- create toplevel menu nodes
        }
 
        -- create toplevel menu nodes
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/openvpn.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/openvpn.lua
new file mode 100644 (file)
index 0000000..193f044
--- /dev/null
@@ -0,0 +1,56 @@
+-- Copyright 2015 Jo-Philipp Wich <jow@openwrt.org>
+-- Licensed to the public under the Apache License 2.0.
+
+require "luci.sys"
+
+local m, s, o
+
+
+m = Map("luci_statistics",
+       translate("OpenVPN Plugin Configuration"),
+       translate("The OpenVPN plugin gathers information about the current vpn connection status."))
+
+s = m:section( NamedSection, "collectd_openvpn", "luci_statistics" )
+
+
+o = s:option( Flag, "enable", translate("Enable this plugin") )
+o.default = "0"
+
+
+o = s:option(Flag, "CollectIndividualUsers", translate("Generate a separate graph for each logged user"))
+o.default = "0"
+o.rmempty = true
+o:depends("enable", 1)
+
+
+o = s:option(Flag, "CollectUserCount", translate("Aggregate number of connected users"))
+o.default = "0"
+o.rmempty = true
+o:depends("enable", 1)
+
+
+o = s:option(Flag, "CollectCompression", translate("Gather compression statistics"))
+o.default = "0"
+o.rmempty = true
+o:depends("enable", 1)
+
+
+o = s:option(Flag, "ImprovedNamingSchema", translate("Use improved naming schema"))
+o.default = "0"
+o.rmempty = true
+o:depends("enable", 1)
+
+
+o = s:option(DynamicList, "StatusFile", translate("OpenVPN status files"))
+o.rmempty = true
+o:depends("enable", 1)
+
+local status_files = nixio.fs.glob("/var/run/openvpn.*.status")
+if status_files then
+       local status_file
+       for status_file in status_files do
+               o:value(status_file)
+       end
+end
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/openvpn.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/openvpn.lua
new file mode 100644 (file)
index 0000000..50efddb
--- /dev/null
@@ -0,0 +1,48 @@
+-- Copyright 2015 Jo-Philipp Wich <jow@openwrt.org>
+-- Licensed to the public under the Apache License 2.0.
+
+module("luci.statistics.rrdtool.definitions.openvpn", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance )
+       local inst = plugin_instance:gsub("^openvpn%.(.+)%.status$", "%1")
+
+       return {
+               {
+                       title = "%%H: OpenVPN \"%s\" - Traffic" % inst,
+                       vlabel = "Bytes/s",
+                       data = {
+                               instances = {
+                                       if_octets = { "traffic", "overhead" }
+                               },
+                               sources = {
+                                       if_octets = { "tx", "rx" }
+                               },
+                               options = {
+                                       if_octets_traffic_tx  = { title = "Bytes    (TX)", total = true, color = "00ff00" },
+                                       if_octets_overhead_tx = { title = "Overhead (TX)", total = true, color = "ff9900" },
+                                       if_octets_traffic_rx  = { title = "Bytes    (RX)", total = true, flip = true, color = "0000ff" },
+                                       if_octets_overhead_rx = { title = "Overhead (RX)", total = true, flip = true, color = "ff00ff" }
+                               }
+                       }
+               },
+
+               {
+                       title = "%%H: OpenVPN \"%s\" - Compression" % inst,
+                       vlabel = "Bytes/s",
+                       data = {
+                               instances = {
+                                       compression = { "data_out", "data_in" }
+                               },
+                               sources = {
+                                       compression = { "uncompressed", "compressed" }
+                               },
+                               options = {
+                                       compression_data_out_compressed   = { title = "Compressed   (TX)", total = true, color = "008800" },
+                                       compression_data_out_uncompressed = { title = "Uncompressed (TX)", total = true, color = "00ff00" },
+                                       compression_data_in_compressed    = { title = "Compressed   (RX)", total = true, flip = true, color = "000088" },
+                                       compression_data_in_uncompressed  = { title = "Uncompressed (RX)", total = true, flip = true, color = "0000ff" }
+                               }
+                       }
+               }
+       }
+end
index fed08cb..49d8a09 100755 (executable)
@@ -187,9 +187,9 @@ function _list_expand( c, l, nopad )
                        end
 
                        if n:find("(%w+)ses") then
                        end
 
                        if n:find("(%w+)ses") then
-                               k = n:gsub("(%w+)ses", "%1s")
+                               k = n:gsub("(%w+)ses$", "%1s")
                        else
                        else
-                               k = n:gsub("(%w+)s", "%1")
+                               k = n:gsub("(%w+)s$", "%1")
                        end
 
                        str = str .. _expand( c[n], k, nopad )
                        end
 
                        str = str .. _expand( c[n], k, nopad )
@@ -375,6 +375,12 @@ plugins = {
                { }
        },
 
                { }
        },
 
+       openvpn = {
+               { },
+               { "CollectIndividualUsers", "CollectUserCount", "CollectCompression", "ImprovedNamingSchema" },
+               { "StatusFile" }
+       },
+
        ping    = {
                { "TTL", "Interval" },
                { },
        ping    = {
                { "TTL", "Interval" },
                { },