Skip to content

Commit

Permalink
Add optional template-specific stats counters
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandergall committed Mar 15, 2018
1 parent d72d42d commit 46263a7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/apps/ipfix/ipfix.lua
Expand Up @@ -177,6 +177,7 @@ function FlowSet:new (template, args)
o.match = template.match
o.incoming_link_name, o.incoming = new_internal_link('IPFIX incoming')

-- Generic per-template counters
o.shm = shm.create_frame("templates/"..template.id,
{ packets_in = { counter },
flow_export_packets = { counter },
Expand All @@ -186,6 +187,15 @@ function FlowSet:new (template, args)
table_occupancy = { counter, o.table.occupancy },
table_max_displacement = { counter, o.table.max_displacement },
table_scan_time = { counter, 0 } })
-- Template-specific counters
if template.counters then
local conf = {}
for name, _ in pairs(template.counters) do
conf[name] = { counter, 0 }
end
o.shm_template =
shm.create_frame("templates/"..template.id.."/stats", conf)
end
return setmetatable(o, { __index = self })
end

Expand Down Expand Up @@ -318,6 +328,11 @@ function FlowSet:sync_stats()
counter.set(self.shm.table_occupancy, self.table.occupancy)
counter.set(self.shm.table_max_displacement, self.table.max_displacement)
counter.set(self.shm.table_scan_time, self.table_scan_time)
if self.shm_template then
for _, name in ipairs(self.template.counters_names) do
counter.set(self.shm_template[name], self.template.counters[name])
end
end
end

IPFIX = {}
Expand Down
10 changes: 9 additions & 1 deletion src/apps/ipfix/template.lua
Expand Up @@ -188,6 +188,12 @@ local function make_template_info(spec)
-- included in export records.
assert(ffi.sizeof(record_t) - ffi.sizeof(spec.state_t or 'char [0]') == data_len)

local counters_names = {}
if spec.counters then
for name, _ in pairs(spec.counters) do
table.insert(counters_names, name)
end
end
return { id = spec.id,
field_count = #spec.keys + #spec.values,
buffer = buffer,
Expand All @@ -199,7 +205,9 @@ local function make_template_info(spec)
record_ptr_t = ptr_to(record_t),
swap_fn = gen_swap_fn(),
match = pf.compile_filter(spec.filter),
logger = lib.logger_new({ module = "IPFIX template #"..spec.id })
logger = lib.logger_new({ module = "IPFIX template #"..spec.id }),
counters = spec.counters,
counters_names = counters_names
}
end

Expand Down
8 changes: 8 additions & 0 deletions src/program/ipfix/stats/stats.lua
Expand Up @@ -124,6 +124,14 @@ function run (args)
format(" Max displacement %d", max_disp)
format(" Last scan time %d", read(template.table_scan_time))
shm.delete_frame(template)
if shm.exists(base_path.."/templates/"..id.."/stats") then
format("Template-specific stats")
local stats = shm.open_frame(base_path.."/templates/"..id.."/stats")
for name, _ in pairs(stats.specs) do
format(" %-25s %s", name, read(stats[name], true))
end
shm.delete_frame(stats)
end
end
end
end

0 comments on commit 46263a7

Please sign in to comment.