From ce648ee80f9168800961f8242fa6194653f6e002 Mon Sep 17 00:00:00 2001 From: TheBigHNF Date: Tue, 24 Feb 2015 13:50:18 -0600 Subject: [PATCH] Added LUA version of plugin --- init.lua | 36 ++++++++++++++++++++++++++++++++++++ param.json | 3 +++ plugin.json | 26 ++++++++++++++++++++++---- 3 files changed, 61 insertions(+), 4 deletions(-) create mode 100755 init.lua create mode 100755 param.json diff --git a/init.lua b/init.lua new file mode 100755 index 0000000..9d9ca65 --- /dev/null +++ b/init.lua @@ -0,0 +1,36 @@ +local os = require 'os' +local boundary = require 'boundary' +local timer = require 'timer' + +local param = boundary.param + +local source = param.source or os.hostname() +local interval = param.pollInterval or 1000; + +local last_cpus = nil + +timer.setInterval(interval, function() + local cpus = os.cpus() + + for _, cpu in ipairs(cpus) do + cpu.total = 0 + + for name, value in pairs(cpu.times) do + cpu.total = cpu.total + value + end + end + + if last_cpus then + for idx, cpu in ipairs(cpus) do + local last_cpu = last_cpus[idx] + + local user = (cpu.times.user - last_cpu.times.user) / (cpu.total - last_cpu.total) + + if user == user then + print(string.format("CPU_CORE %f %s-C%d", user, source, idx)) + end + end + end + + last_cpus = cpus +end) diff --git a/param.json b/param.json new file mode 100755 index 0000000..2469a08 --- /dev/null +++ b/param.json @@ -0,0 +1,3 @@ +{ + "pollInterval" : 1000 +} diff --git a/plugin.json b/plugin.json index 9fdb780..540193a 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,25 @@ { "description" : "Provides per core CPU utilization", - "command" : "node index.js $(pollInterval)", - "metrics" : ["CPU_CORE"], - "postExtract" : "npm install", - "ignore" : "node_modules" + "command" : "node index.js $(pollInterval)", + "command_lua" : "boundary-meter init.lua", + "postExtract" : "npm install", + "postExtract_lua" : "", + "ignore" : "node_modules", + "metrics" : ["CPU_CORE"], + "paramSchema": [ + { + "title": "Poll Interval", + "name": "pollInterval", + "description": "How often (in milliseconds) to poll the system for metrics (default: 1000).", + "type" : "integer", + "default" : 1000, + "required" : false + }, + { + "title" : "Source", + "name" : "source", + "description" : "The Source to display in the legend for the CPU Core data. It will default to the hostname of the server", + "type" : "string" + } + ] }