/usr/share/sysdig/chisels/table_generator.lua is in sysdig 0.8.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | --[[
Copyright (C) 2013-2014 Draios inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
--]]
-- Chisel description
description = "Given two filter fields, a key and a value, this chisel creates and renders a table to the screen."
short_description = "Filter on a key and value"
category = "Filter"
hidden = true
-- Chisel argument list
args =
{
{
name = "keys",
description = "comma-separated list of filter fields to use for grouping",
argtype = "string"
},
{
name = "keydescs",
description = "comma separated list of human readable descriptions for the key",
argtype = "string"
},
{
name = "value",
description = "the value to count for every key",
argtype = "string"
},
{
name = "valuedesc",
description = "human readable description for the value",
argtype = "string"
},
{
name = "filter",
description = "the filter to apply",
argtype = "string"
},
{
name = "top_number",
description = "maximum number of elements to display",
argtype = "string"
},
{
name = "value_units",
description = "how to render the values in the result. Can be 'bytes', 'time', 'timepct', or 'none'.",
argtype = "string"
},
}
require "common"
terminal = require "ansiterminal"
grtable = {}
filter = ""
islive = false
fkeys = {}
vizinfo =
{
key_fld = {},
key_desc = {},
value_fld = "",
value_desc = "",
value_units = "none",
top_number = 0,
output_format = "normal"
}
-- Argument notification callback
function on_set_arg(name, val)
if name == "keys" then
vizinfo.key_fld = split(val, ",")
return true
elseif name == "keydescs" then
vizinfo.key_desc = split(val, ",")
return true
elseif name == "value" then
vizinfo.value_fld = val
return true
elseif name == "valuedesc" then
vizinfo.value_desc = val
return true
elseif name == "filter" then
filter = val
return true
elseif name == "top_number" then
vizinfo.top_number = tonumber(val)
return true
elseif name == "value_units" then
vizinfo.value_units = val
return true
end
return false
end
-- Initialization callback
function on_init()
if #vizinfo.key_fld ~= #vizinfo.key_desc then
print("error: number of entries in keys different from number entries in keydescs")
return false
end
-- Request the fields we need
for i, name in ipairs(vizinfo.key_fld) do
fkeys[i] = chisel.request_field(name)
end
fvalue = chisel.request_field(vizinfo.value_fld)
-- set the filter
if filter ~= "" then
chisel.set_filter(filter)
end
return true
end
-- Final chisel initialization
function on_capture_start()
islive = sysdig.is_live()
vizinfo.output_format = sysdig.get_output_format()
if islive then
chisel.set_interval_s(1)
if vizinfo.output_format ~= "json" then
terminal.clearscreen()
terminal.hidecursor()
end
end
return true
end
-- Event parsing callback
function on_event()
local key = nil
local kv = nil
for i, fld in ipairs(fkeys) do
kv = evt.field(fld)
if kv == nil then
return
end
if key == nil then
key = kv
else
key = key .. "\001\001" .. evt.field(fld)
end
end
value = evt.field(fvalue)
if value ~= nil and value > 0 then
entryval = grtable[key]
if entryval == nil then
grtable[key] = value
else
grtable[key] = grtable[key] + value
end
end
return true
end
-- Periodic timeout callback
function on_interval(ts_s, ts_ns, delta)
if vizinfo.output_format ~= "json" then
terminal.clearscreen()
terminal.moveto(0, 0)
end
print_sorted_table(grtable, ts_s, 0, delta, vizinfo)
-- Clear the table
grtable = {}
return true
end
-- Called by the engine at the end of the capture (Ctrl-C)
function on_capture_end(ts_s, ts_ns, delta)
if islive and vizinfo.output_format ~= "json" then
terminal.clearscreen()
terminal.moveto(0 ,0)
terminal.showcursor()
return true
end
print_sorted_table(grtable, ts_s, 0, delta, vizinfo)
return true
end
|