Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
Boundary Memcached Plugin
-------------------------
# Boundary Memcached Plugin

Collects metrics from a memcached instance. See video [walkthrough](https://help.boundary.com/hc/articles/201816101).

### Prerequisites
## Prerequisites

### Supported OS

| OS | Linux | Windows | SmartOS | OS X |
|:----------|:-----:|:-------:|:-------:|:----:|
| Supported | v | v | v | v |

#### 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].

#### For Boundary Meter less than V4.0

| Runtime | node.js | Python | Java |
|:---------|:-------:|:------:|:----:|
| Required | + | | |

- [How to install node.js?](https://help.boundary.com/hc/articles/202360701)

### Plugin Setup

None

#### Plugin Configuration Fields
### Plugin Configuration Fields

#### For All Versions

|Field Name|Description |
|:---------|:----------------------------------------------------------|
Expand All @@ -27,6 +38,9 @@ None
|Host |The MEMCACHED hostname. |

### Metrics Collected

#### For All Versions

|Metric Name |Description |
|:--------------------|:---------------------------------|
|Memcached Allocated |Percent of available memory used |
Expand Down
105 changes: 105 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
local timer = require('timer')
local boundary = require('boundary')
local io = require('io')
local net = require('net')


local __pgk = "BOUNDARY MEMCACHED"
local client
local _previous = {}
local host = "127.0.0.1"
local port = 11211
local pollInterval = 1000


if (boundary.param ~= nil) then
pollInterval = boundary.param.pollInterval or pollInterval
host = boundary.param.host or host
port = boundary.param.port or port
source = (type(boundary.param.source) == 'string' and boundary.param.source:gsub('%s+', '') ~= '' and boundary.param.source) or
io.popen("uname -n"):read('*line')
end


function berror(err)
if err then print(string.format("%s ERROR: %s", __pgk, tostring(err))) return err end
end



function diff(a, b)
if a == nil or b == nil then return 0 end
return math.max(a - b, 0)
end


-- accumulate a value and return the difference from the previous value
function accumulate(key, newValue)
local oldValue = _previous[key] or newValue
local difference = diff(newValue, oldValue)
_previous[key] = newValue
return difference
end

-- init client
function init()
if client == nil then
client = net.createConnection(port, host, function (err)
if berror(err) then end
end)
end
client:on("error", function(err)
berror(err)
end)
client:on("data", function(data)

local d = {}
for _, v in pairs(split(data, "\r\n")) do
local s = v:gsub("STAT ", "")
local t = {}
for w in s:gmatch("%S+") do
table.insert(t, w)
end
d[t[1]] = tonumber(t[2])
end

print(string.format('MEMCACHED_ALLOCATED %d %s', d.bytes / d.limit_maxbytes, source))
print(string.format('MEMCACHED_CONNECTIONS %d %s', d.curr_connections, source))
print(string.format('MEMCACHED_HITS %d %s', accumulate('get_hits', d.get_hits), source))
print(string.format('MEMCACHED_MISSES %d %s', accumulate('get_misses', d.get_misses), source))
print(string.format('MEMCACHED_ITEMS %d %s', d.curr_items, source))
print(string.format('MEMCACHED_REQUESTS %d %s', accumulate('cmd_get', d.cmd_get) + accumulate('cmd_set', d.cmd_set), source))
print(string.format('MEMCACHED_NETWORK_IN %d %s', accumulate('bytes_read', d.bytes_read), source))
print(string.format('MEMCACHED_NETWORK_OUT %d %s', accumulate('bytes_written', d.bytes_written), source))
end)

end


-- get the natural difference between a and b
function diff(a, b)
if not a or not b then return 0 end
return math.max(a - b, 0)
end

function split(str, delim)
local res = {}
local pattern = string.format("([^%s]+)%s()", delim, delim)
while (true) do
line, pos = str:match(pattern, pos)
if line == nil then break end
table.insert(res, line)
end
return res
end

print("_bevent:MEMCACHED plugin up : version 1.0|t:info|tags:memcached, lua, plugin")
init()

timer.setInterval(pollInterval, function ()
client:write("stats " .. "\r\n")
end)




Loading