diff --git a/README.md b/README.md index ab467f1..96720db 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,26 @@ -# Conntrack Graphdat Plugin +# Conntrack Plugin -DO NOT INSTALL! Conntrack plugin is going to be removed as it is not supported under new Boudnary Meter. The similar functionality is planned to be added instead in near term. +The Conntrack plugin checks kernel level metrics provided by the Netfilter Conntrack tools ### Prerequisites | OS | Linux | Windows | SmartOS | OS X | |:----------|:-----:|:-------:|:-------:|:----:| -| Supported | - | - | - | - | +| Supported | X | - | - | - | + +#### Boundary Meter Versions V4.0 Or Later + +- To install new meter go to Settings->Installation or [see instructons|https://help.boundary.com/hc/en-us/sections/200634331-Installation]. +- To upgrade the meter to the latest version - [see instructons|https://help.boundary.com/hc/en-us/articles/201573102-Upgrading-the-Boundary-Meter]. | Runtime | node.js | Python | Java | |:---------|:-------:|:------:|:----:| -| Required | + | | | +| Required | | | | -[How to install node.js?](https://help.boundary.com/hc/articles/202360701) +#### For Boundary Meter less than V4.0 + +NOT SUPPORTED! ### Plugin Setup @@ -22,11 +29,32 @@ DO NOT INSTALL! Conntrack plugin is going to be removed as it is not supported u For debian based OS's: `$ sudo apt-get install conntrack` For redhat based OS's, follow the installation instructions on [pkgs.org](http://pkgs.org/download/conntrack-tools) or this [gist](https://gist.github.com/codemoran/8309269) -#### Installation & Configuration +### Plugin Configuration Fields + +#### All Versions + +|Field Name |Field Title |Description | +|:-----------|:--------------|:------------------------------------------| +|pollInterval|Poll Interval |How often should the plugin poll conntrack | +|mode |Reporting Level|Use basic or advanced mode with conntrack | +|source |Source |Display name in the UI for this data | + +### Metrics Collected + +#### All Versions -* The `source` to prefix the display in the legend for the Conntrack data. It will default to the hostname of the server. -* The `mode` to prefix the display in the legend for the Conntrack data. It will default to the hostname of the server. +|Metric Name |Display Name |Description | +|:--------------------|:----------------------------|:----------------------------------------------------------------| +|CONNTRACK_ASSURED |Assured IP Connection Count |Number of [ASSURED] IP Connections | +|CONNTRACK_CONNECTIONS|IP Connections |Number of TCP and UDP connections | +|CONNTRACK_ESTABLISHED|TCP Established Count |Number of TCP sockets in ESTABLISHED state | +|CONNTRACK_FINWAIT |TCP Final Wait Count |Number of TCP sockets in FIN_WAIT state | +|CONNTRACK_LIMIT |IP Connection Limit |Ratio of current IP connections to total available IP connections| +|CONNTRACK_SYNSENT |TCP Synchronise Count |Number of TCP sockets in SYN_SENT state | +|CONNTRACK_TIMEWAIT |TCP Time Wait Count |Number of TCP sockets in TIME_WAIT state | +|CONNTRACK_UDP |UDP Connection Count |Number of current UDP connections | +|CONNTRACK_UNREPLIED |Unreplied IP Connection Count|Number of [UNREPLIED] IP Connections | -#### Tracks the following metrics for [Conntrack](http://conntrack-tools.netfilter.org/) +### Conntrack Information The conntrack-tools are a set of free software userspace tools for Linux that allow system administrators interact with the Connection Tracking System, which is the module that provides stateful packet inspection for iptables. The conntrack-tools are the userspace daemon conntrackd and the command line interface conntrack. diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..f43b0d5 --- /dev/null +++ b/init.lua @@ -0,0 +1,96 @@ +local boundary = require("boundary") +local timer = require("timer") +local fs = require("fs") +local spawn = require("childprocess").spawn + +local param = boundary.param or { + pollInterval = 5000, + mode = "basic" +} + +local analyse = function(tbl) + local states = {} + local total = 0 + local assured = 0 + local unreplied = 0 + for line in string.gmatch(tbl, "[^\n]+") do + local tokens = {} + -- return 1 if one of the tokens is s otherwise 0 + local findtoken = function(s) + for i, v in ipairs(tokens) do + if v == s then return 1 end + end + return 0 + end + -- tokenise + for t in string.gmatch(line, "[^ ]+") do table.insert(tokens, t) end + -- analyse + if tokens[1] == "tcp" or tokens[1] == "udp" then + total = total + 1 + if tokens[1] == "tcp" then + states[tokens[4]] = (states[tokens[4]] or 0) + 1 + elseif tokens[1] == "udp" then + states.UDP = (states.UDP or 0) + 1 + end + assured = assured + findtoken("[ASSURED]") + unreplied = unreplied + findtoken("[UNREPLIED]") + end + end + return { states = states, total = total, assured = assured, unreplied = unreplied } +end + +local maxConnections + +local show = function(stats) + print(string.format('CONNTRACK_CONNECTIONS %d %s', stats.total, param.source)) + print(string.format('CONNTRACK_LIMIT %f %s', stats.total / maxConnections, param.source)) + if param.mode == 'advanced' then + print(string.format('CONNTRACK_ESTABLISHED %d %s', stats.states.ESTABLISHED or 0, param.source)) + print(string.format('CONNTRACK_FINWAIT %d %s', stats.states.FIN_WAIT or 0, param.source)) + print(string.format('CONNTRACK_TIMEWAIT %d %s', stats.states.TIME_WAIT or 0, param.source)) + print(string.format('CONNTRACK_SYNSENT %d %s', stats.states.SYN_SENT or 0, param.source)) + print(string.format('CONNTRACK_UDP %d %s', stats.states.UDP or 0, param.source)) + print(string.format('CONNTRACK_ASSURED %d %s', stats.assured or 0, param.source)) + print(string.format('CONNTRACK_UNREPLIED %d %s', stats.unreplied or 0, param.source)) + end +end + +-- probably could use execFile here but not sure about error handling +-- in luvit version fc9be1fa48a9d5 +local exec = function(progname, args, callback) + local data = {} + local c = spawn(progname, args) + c.stdout:on("data", function(chunk) table.insert(data, chunk) end) + c.stdout:once("end", function() callback(table.concat(data)) end) + c:on("exit", function(code, signal) + if code == -1 then + error(string.format("Unable to run %s.", progname)) + elseif code > 0 then + error(string.format("%s error (errno %d)", progname, code)) + end + end) +end + +print("_bevent:Boundary conntrack plugin up : version 1.0|t:info|tags:lua,conntrack,plugin") + +exec("sysctl", {"-n", "net.netfilter.nf_conntrack_max"}, function(maxconn) + maxConnections = maxconn + local conntrack = function() + exec("conntrack", {"-L"}, function(connections) + show(analyse(connections)) + end) + end + local setupPoll = function() + timer.setInterval(param.pollInterval, conntrack) + conntrack() + end + if param.source then + setupPoll() + else + exec("hostname", {}, function(hostname) + param.source = string.sub(hostname, 1, -2) + setupPoll() + end) + end +end) + diff --git a/plugin.json b/plugin.json index de522ef..a4e24f1 100644 --- a/plugin.json +++ b/plugin.json @@ -1,9 +1,11 @@ { - "description" : "Displays important conntrack metrics", + "description" : "Plugin for conntrack kernel IP connection tracking", "icon" : "icon.png", "command" : "node index.js", "postExtract" : "npm install", "ignore" : "node_modules", + "command_lua": "boundary-meter index.lua", + "postExtract_lua" : "", "metrics" : [ "CONNTRACK_ASSURED", @@ -40,6 +42,14 @@ "default" : 5, "required" : true }, + { + "title" : "Poll Time (msec)", + "name" : "pollInterval", + "description" : "The Poll Interval to collect metrics. Default: 5 seconds", + "type" : "integer", + "default" : 5000, + "required" : true + }, { "title" : "Source", "name" : "source",