-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"pollInterval" : 1000 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |