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
27 changes: 9 additions & 18 deletions index.lua
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
-- [boundary.com] Redis Lua Plugin
-- [author] Ivano Picco <ivano.picco@pianobit.com>

-- Requires.
-- Common requires.
local utils = require('utils')
local uv_native = require ('uv_native')
local string = require('string')
local split = require('split')
local redis = require('luvit-redis')
local timer = require('timer')
local ffi = require ('ffi')
local fs = require('fs')
local json = require('json')
local os = require ('os')
local tools = require ('tools')

local success, boundary = pcall(require,'boundary')
if (not success) then
boundary = nil
end

-- portable gethostname syscall
ffi.cdef [[
int gethostname (char *, int);
]]
function gethostname()
local buf = ffi.new("uint8_t[?]", 256)
ffi.C.gethostname(buf,256);
return ffi.string(buf)
end
-- Business requires.
local redis = require('luvit-redis')

-- Default parameters.
local pollInterval = 10000
Expand All @@ -41,7 +32,7 @@ _parameters.pollInterval =

_parameters.source =
(type(_parameters.source) == 'string' and _parameters.source:gsub('%s+', '') ~= '' and _parameters.source ~= nil and _parameters.source) or
gethostname()
os.hostname()

_parameters.host =
(type(_parameters.host) == 'string' and _parameters.host:gsub('%s+', '') ~= '' and _parameters.host) or
Expand Down Expand Up @@ -76,7 +67,7 @@ end

-- Parse line (i.e. line: "connected_clients : <value>").
function parseEachLine(line)
local t = split(line,':')
local t = tools.split(line,':')
if (#t == 2) then
currentValues[t[1]]=t[2];
end
Expand All @@ -91,7 +82,7 @@ function outputs()
utils.print('REDIS_KEY_EVICTIONS', diffvalues('evicted_keys'), _parameters.source)
utils.print('REDIS_COMMANDS_PROCESSED', diffvalues('total_commands_processed'), _parameters.source)
utils.print('REDIS_CONNECTIONS_RECEIVED', diffvalues('total_connections_received'), _parameters.source)
utils.print('REDIS_USED_MEMORY', currentValues.used_memory_rss / uv_native.getTotalMemory(), _parameters.source)
utils.print('REDIS_USED_MEMORY', currentValues.used_memory_rss / os.totalmem(), _parameters.source)
end

-- Get current values.
Expand Down
7 changes: 0 additions & 7 deletions modules/split/package.lua

This file was deleted.

15 changes: 0 additions & 15 deletions modules/split/src/init.lua

This file was deleted.

65 changes: 65 additions & 0 deletions modules/tools.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
--
-- Module.
--
local tools = {}


-- Requires.
local string = require('string')

--
-- Limit a given number x between two boundaries.
-- Either min or max can be nil, to fence on one side only.
--
tools.fence = function(x, min, max)
return (min and x < min and min) or (max and x > max and max) or x
end

--
-- Encode data in Base64 format.
--
tools.base64 = function(data)
local _lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
return ((data:gsub('.', function(x)
local r, b = '', x:byte()
for i = 8, 1, -1 do
r = r .. (b % 2 ^ i - b % 2 ^ (i - 1) > 0 and '1' or '0')
end
return r
end) .. '0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
if #x < 6 then
return ''
end
local c = 0
for i = 1, 6 do
c = c + (x:sub(i, i) == '1' and 2 ^ (6 - i) or 0)
end
return _lookup:sub(c + 1, c + 1)
end) .. ({
'',
'==',
'='
})[#data % 3 + 1])
end


--
-- Split a string into a table
--

tools.split = function (inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={} ; local i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end

--
-- Export.
--
return tools