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
48 changes: 32 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,50 @@ Collects metrics from an instance of a Redis database.
|:----------|:-----:|:-------:|:-------:|:----:|
| Supported | v | v | v | v |

#### For Boundary Meter V4.0
(to update/download - curl -fsS -d '{"token":"api.<Your API Key Here>"}' -H 'Content-Type: application/json' https://meter.boundary.com/setup_meter > setup_meter.sh && chmod +x setup_meter.sh && ./setup_meter.sh)

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

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

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

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

### Plugin Setup

#### For All Versions

None

#### Plugin Configuration Fields

|Field Name|Description |
|:-------|:------------------------------------------------------|
|Source |The source to display in the legend for the REDIS data.|
|Port |The redis port. |
|Host |The redis hostname. |
|Password|Password to the redis server. |
#### For All Versions

|Field Name |Description |
|:-----------|:------------------------------------------------------|
|Source |The source to display in the legend for the REDIS data.|
|Port |The redis port. |
|Host |The redis hostname. |
|Password |Password to the redis server. |
|PollInterval|Interval to query the redis server. |

### Metrics Collected

#### For All Versions

|Metric Name |Description|
|:-------------------------|:|
|Redis Connected Clients ||
|Redis Key Hits ||
|Redis Key Misses ||
|Redis Keys Expired ||
|Redis Key Evictions ||
|Redis Connections Received||
|Redis Commands Processed ||
|Redis Used Memory ||
|:-------------------------|:----------|
|Redis Connected Clients | |
|Redis Key Hits | |
|Redis Key Misses | |
|Redis Keys Expired | |
|Redis Key Evictions | |
|Redis Connections Received| |
|Redis Commands Processed | |
|Redis Used Memory | |
113 changes: 113 additions & 0 deletions index.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
-- [boundary.com] Redis Lua Plugin
-- [author] Ivano Picco <ivano.picco@pianobit.com>

-- 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 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

-- Default parameters.
local pollInterval = 10000
local port = 6379
local host = "localhost"
local source = nil

-- Configuration.
local _parameters = (boundary and boundary.param and boundary.param) or json.parse(fs.readFileSync('param.json')) or {}

_parameters.pollInterval =
(_parameters.pollInterval and tonumber(_parameters.pollInterval)>0 and tonumber(_parameters.pollInterval)) or
pollInterval;

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

_parameters.host =
(type(_parameters.host) == 'string' and _parameters.host:gsub('%s+', '') ~= '' and _parameters.host) or
host

_parameters.port =
(_parameters.port and tonumber(_parameters.port) and _parameters.port>0) and _parameters.port or
port

-- Client initialization
local client = redis:new(_parameters.host,_parameters.port)

client:on("error", function (err)
utils.debug("Error (error callback): ", err)
end)

if (_parameters.password) then
client:auth(_parameters.password)
end

-- Back-trail.
local previousValues={}
local currentValues={}

-- Get difference between current and previous value.
function diffvalues(name)
local cur = currentValues[name]
local last = previousValues[name] or cur
previousValues[name] = cur
return (tonumber(cur) - tonumber(last))
end

-- Parse line (i.e. line: "connected_clients : <value>").
function parseEachLine(line)
local t = split(line,':')
if (#t == 2) then
currentValues[t[1]]=t[2];
end
end

-- print results
function outputs()
utils.print('REDIS_CONNECTED_CLIENTS', currentValues.connected_clients, _parameters.source)
utils.print('REDIS_KEY_HITS', diffvalues('keyspace_hits'), _parameters.source)
utils.print('REDIS_KEY_MISSES', diffvalues('keyspace_misses'), _parameters.source)
utils.print('REDIS_KEYS_EXPIRED', diffvalues('expired_keys'), _parameters.source)
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)
end

-- Get current values.
function poll()
client:info( function(err,result)
if (err) then
utils.debug(err)
return
end
-- call func with each word in a string
result:gsub("[^\r\n]+", parseEachLine)

outputs()
end)
end

-- Ready, go.
poll()
timer.setInterval(_parameters.pollInterval,poll)
1 change: 1 addition & 0 deletions modules/luvit-redis/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
3 changes: 3 additions & 0 deletions modules/luvit-redis/.gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "deps/hiredis"]
path = deps/hiredis
url = git://github.com/redis/hiredis.git
32 changes: 32 additions & 0 deletions modules/luvit-redis/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
LUVIT = luvit
CFLAGS = $(shell $(LUVIT) --cflags | sed s/-Werror//)
LIBS = $(shell $(LUVIT) --libs)
HIREDISDIR = deps/hiredis

# uncomment to use freelist for references (saves malloc/free calls)
#CFLAGS += -DUSE_REF_FREELIST=1

all: build/redis.luvit

${HIREDISDIR}/Makefile:
git submodule update --init ${HIREDISDIR}

${HIREDISDIR}/libhiredis.a: ${HIREDISDIR}/Makefile
$(MAKE) -C ${HIREDISDIR} libhiredis.a

build/%.luvit: src/%.c ${HIREDISDIR}/libhiredis.a
mkdir -p build
$(CC) ${CFLAGS} -I${HIREDISDIR} -Isrc -o $@ $^ ${LIBS} ${HIREDISDIR}/libhiredis.a

clean:
${MAKE} -C ${HIREDISDIR} clean
rm -fr build

profile:
valgrind --tool=callgrind --dump-instr=yes --simulate-cache=yes --collect-jumps=yes luvit benchmark.lua

profile-mem:
valgrind --leak-check=full --show-reachable=yes -v luvit benchmark.lua


.PHONY: all clean deps profile profile-mem
Loading