/usr/share/sysdig/chisels/fileslower.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 | --[[
fileslower.lua - trace file I/O slower than a given threshold.
USAGE: sysdig -c fileslower min_ms
eg,
sysdig -c fileslower 10 # show file I/O slower than 10 ms
sysdig -c fileslower 0 # show all file I/O
sysdig -c fileslower "1 disable_colors" # show file I/O slower than 1 ms. w/ no colors
sysdig -pc -c fileslower 0 # show all file I/O and container output
By default this skips file I/O to /dev. Modify the skip_dev variable in this
chisel to change this behavior.
Note: The file I/O traced is those matched by the sysdig filter:
"evt.is_io=true and fd.type=file".
Copyright (C) 2014 Brendan Gregg.
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 = "Trace file I/O slower than a threshold, or all file I/O. This chisel is compatable with containers using the sysdig -pc or -pcontainer argument, otherwise no container information will be shown. (Blue represents a process running within a container, and Green represents a host process)";
short_description = "Trace slow file I/O";
category = "Performance";
skip_dev = true -- skip /dev/... files
-- Chisel argument list
args =
{
{
name = "min_ms",
description = "Minimum millisecond threshold for showing file I/O",
argtype = "int",
optional = false
},
{
name = "disable_color",
description = "Set to 'disable_colors' if you want to disable color output",
argtype = "string",
optional = true
},
}
require "common"
terminal = require "ansiterminal"
terminal.enable_color(true)
-- Argument notification callback
function on_set_arg(name, val)
if name == "disable_color" and val == "disable_color" then
terminal.enable_color(false)
elseif name == "min_ms" then
min_ms = parse_numeric_input(val, name)
end
return true
end
-- Initialization callback
function on_init()
-- set the following fields on_event()
etype = chisel.request_field("evt.type")
dir = chisel.request_field("evt.dir")
datetime = chisel.request_field("evt.datetime")
fname = chisel.request_field("fd.name")
pname = chisel.request_field("proc.name")
latency = chisel.request_field("evt.latency")
fcontainername = chisel.request_field("container.name")
fcontainerid = chisel.request_field("container.id")
-- The -pc or -pcontainer options was supplied on the cmd line
print_container = sysdig.is_print_container_data()
-- filter for file I/O
chisel.set_filter("evt.is_io=true and fd.type=file")
-- The -pc or -pcontainer options was supplied on the cmd line
if print_container then
print(string.format("%-23.23s %-20.20s %-20.20s %-12.12s %-8s %-12s %s",
"evt.datetime",
"container.id",
"container.name",
"proc.name",
"evt.type",
"LATENCY(ms)",
"fd.name"))
print(string.format("%-23.23s %-20.20s %-20.20s %-12.12s %-8s %-12s %s",
"-----------------------",
"------------------------------",
"------------------------------",
"------------",
"--------",
"------------",
"-----------------------------------------"))
else
print(string.format("%-23.23s %-12.12s %-8s %-12s %s",
"evt.datetime",
"proc.name",
"evt.type",
"LATENCY(ms)",
"fd.name"))
print(string.format("%-23.23s %-12.12s %-8s %-12s %s",
"-----------------------",
"------------",
"--------",
"------------",
"-----------------------------------------"))
end
return true
end
-- Event callback
function on_event()
local color = terminal.green
lat = evt.field(latency) / 1000000
fn = evt.field(fname)
if evt.field(dir) == "<" and lat > min_ms then
-- filter /dev files if needed
if skip_dev == false or string.sub(fn, 0, 5) ~= "/dev/" then
-- If this is a container modify the output color
if evt.field(fcontainername) ~= "host" then
color = terminal.blue
end
-- The -pc or -pcontainer options was supplied on the cmd line
if print_container then
print(color .. string.format("%-23.23s %-20.20s %-20.20s %-12.12s %-8s %12d %s",
evt.field(datetime),
evt.field(fcontainerid),
evt.field(fcontainername),
evt.field(pname),
evt.field(etype),
lat,
fn ))
else
print(color .. string.format("%-23.23s %-12.12s %-8s %12d %s",
evt.field(datetime),
evt.field(pname),
evt.field(etype),
lat,
fn ))
end
end
end
return true
end
|