This repository has been archived by the owner on Jun 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
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
67 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- | ||
-- | ||
-- 该脚本实现将 kafka 中的数据落地到文件中,并且统计落地消息数 | ||
-- | ||
-- | ||
local obj = aidp.message.get() | ||
local filename = os.date('%Y-%m-%d-%H') .. '.log' | ||
local files = {}; | ||
local storage = aidp.storage() | ||
for k,v in pairs(obj) do | ||
if #v == 3 then | ||
if files[v[2]] == nil then | ||
files[v[2]] = io.open(v[2]..filename, 'a+'); | ||
files[v[2]]:setvbuf('full') | ||
end | ||
files[v[2]]:write(v[3]..'\n') | ||
storage:incr(v[2] .. ':message_size', 1) | ||
end | ||
end | ||
for k,v in pairs(files) do | ||
v:flush() | ||
v:close() | ||
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,42 @@ | ||
|
||
--- | ||
-- @function: 打印table的内容,递归 | ||
-- @param: tbl 要打印的table | ||
-- @param: level 递归的层数,默认不用传值进来 | ||
-- @param: filteDefault 是否过滤打印构造函数,默认为是 | ||
-- @return: return | ||
function PrintTable( tbl , level, filteDefault) | ||
local msg = "" | ||
filteDefault = filteDefault or true --默认过滤关键字(DeleteMe, _class_type) | ||
level = level or 1 | ||
local indent_str = "" | ||
for i = 1, level do | ||
indent_str = indent_str.." " | ||
end | ||
|
||
print(indent_str .. "{") | ||
for k,v in pairs(tbl) do | ||
if filteDefault then | ||
if k ~= "_class_type" and k ~= "DeleteMe" then | ||
local item_str = string.format("%s%s = %s", indent_str .. " ",tostring(k), tostring(v)) | ||
print(item_str) | ||
if type(v) == "table" then | ||
PrintTable(v, level + 1) | ||
end | ||
end | ||
else | ||
local item_str = string.format("%s%s = %s", indent_str .. " ",tostring(k), tostring(v)) | ||
print(item_str) | ||
if type(v) == "table" then | ||
PrintTable(v, level + 1) | ||
end | ||
end | ||
end | ||
print(indent_str .. "}") | ||
end | ||
|
||
local request = aidp.http.request(); | ||
local topic_name = request:get_query('t') | ||
local response = aidp.http.response(); | ||
local storage = aidp.storage() | ||
response:set_content(topic_name .. ':message_size ' .. storage:get(topic_name .. ':message_size')); |