Skip to content

Commit

Permalink
Added LUA version of plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
BigHNF committed Feb 24, 2015
1 parent 1be8ffe commit ce648ee
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
36 changes: 36 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions param.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"pollInterval" : 1000
}
26 changes: 22 additions & 4 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}

0 comments on commit ce648ee

Please sign in to comment.