-
Notifications
You must be signed in to change notification settings - Fork 15
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
11 changed files
with
537 additions
and
19 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
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
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,16 @@ | ||
local M = {} | ||
|
||
|
||
function M.counter(name, help, labels) | ||
|
||
end | ||
|
||
function M.gauge(name, help, labels) | ||
|
||
end | ||
|
||
function M.summary(name, help, labels) | ||
|
||
end | ||
|
||
function |
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,39 @@ | ||
local M = {} | ||
local pairs = table.pairs | ||
local remove = table.remove | ||
local setmetatable = setmetatable | ||
|
||
local mt = {__index = M} | ||
|
||
|
||
function M:new() | ||
return setmetatable({metrics = {}}, mt) | ||
end | ||
|
||
function M:register(obj) | ||
for i = 1, #self do | ||
if self[i] == obj then | ||
return | ||
end | ||
end | ||
self[#self + 1] = obj | ||
end | ||
|
||
function M:unregister(obj) | ||
for i = 1, #self do | ||
if self[i] == obj then | ||
remove(self, i) | ||
return | ||
end | ||
end | ||
end | ||
|
||
function M:collect() | ||
local len = 0 | ||
local metrics = self.metrics | ||
for i = 1, #list do | ||
len = list[i]:collect(metrics, len) | ||
|
||
|
||
return M | ||
|
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,33 @@ | ||
local labels = require "sys.metrics.labels" | ||
local helper = require "sys.metrics.helper" | ||
|
||
local mt | ||
local label_mt | ||
|
||
mt = { | ||
__index = nil, | ||
new = nil, | ||
collect = helper.collect, | ||
add = helper.add, | ||
inc = helper.inc, | ||
} | ||
|
||
label_mt = { | ||
__index = nil, | ||
new = nil, | ||
collect = helper.collect, | ||
labels = labels({__index = { | ||
add = helper.add, | ||
inc = helper.inc, | ||
}}) | ||
} | ||
|
||
local new = helper.new("counter", {__index = mt}, {__index = label_mt}) | ||
|
||
mt.new = new | ||
label_mt.new = new | ||
|
||
mt.__index = mt | ||
label_mt.__index = label_mt | ||
|
||
return new |
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,39 @@ | ||
local labels = require "sys.metrics.labels" | ||
local helper = require "sys.metrics.helper" | ||
|
||
local mt | ||
local label_mt | ||
|
||
mt = { | ||
__index = nil, | ||
new = nil, | ||
collect = helper.collect, | ||
add = helper.add, | ||
inc = helper.inc, | ||
sub = helper.sub, | ||
dec = helper.dec, | ||
set = helper.set, | ||
} | ||
|
||
label_mt = { | ||
__index = nil, | ||
new = nil, | ||
collect = helper.collect, | ||
labels = labels({__index = { | ||
add = helper.add, | ||
inc = helper.inc, | ||
sub = helper.sub, | ||
dec = helper.dec, | ||
set = helper.set, | ||
}}) | ||
} | ||
|
||
local new = helper.new("gauge", {__index = mt}, {__index = label_mt}) | ||
|
||
mt.new = new | ||
label_mt.new = new | ||
|
||
mt.__index = mt | ||
label_mt.__index = label_mt | ||
|
||
return new |
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,58 @@ | ||
local M = {} | ||
|
||
local assert = assert | ||
local setmetatable = setmetatable | ||
|
||
function M:set(v) | ||
self[1] = v | ||
end | ||
|
||
function M:add(v) | ||
assert(v >= 0) | ||
self[1] = self[1] + v | ||
end | ||
|
||
function M:inc() | ||
self[1] = self[1] + 1 | ||
end | ||
|
||
function M:sub(v) | ||
self[1] = self[1] - v | ||
end | ||
|
||
function M:dec() | ||
self[1] = self[1] - 1 | ||
end | ||
|
||
function M.new(kind, mt, label_mt) | ||
assert(kind, "kind") | ||
assert(mt, "mt") | ||
assert(label_mt, "label_mt") | ||
return function(name, help, labels) | ||
local obj | ||
if labels then | ||
obj = setmetatable({ | ||
name = name, | ||
help = help, | ||
kind = kind, | ||
labelnames = labels, | ||
}, label_mt) | ||
else | ||
obj = setmetatable({ | ||
name = name, | ||
help = help, | ||
kind = kind, | ||
[1] = 0, --the count value | ||
}, mt) | ||
end | ||
return obj | ||
end | ||
end | ||
|
||
function M.collect(self, buf, len) | ||
len = len + 1 | ||
buf[len] = self | ||
return len | ||
end | ||
|
||
return M |
Oops, something went wrong.