This repository was archived by the owner on Jun 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocket_connections.lua
84 lines (73 loc) · 2.45 KB
/
socket_connections.lua
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
-- Chisel description
description = "Count open connections to a given socket. Find maximum number as well as the minimum where a connection error occured."
short_description = "socket connections"
category = "misc"
-- Chisel argument list
args = {
{
name = "socket_path",
description = "socket to monitor",
argtype = "string",
},
}
function on_set_arg(name, val)
socket_path = val
return true
end
-- Initialization callback
function on_init()
-- Request the fileds that we need
fnum = chisel.request_field("evt.num")
ftype = chisel.request_field("evt.type")
ftime = chisel.request_field("evt.time.s")
fpid = chisel.request_field("proc.pid")
fname = chisel.request_field("proc.name")
frawres = chisel.request_field("evt.rawres")
-- set the filter
chisel.set_filter("((evt.type = accept or evt.type = connect) and evt.dir = < and fd.name contains " .. socket_path ..") or (evt.type = close and evt.dir = > and fd.name contains " .. socket_path .. ")")
highest_seen = 0
lowest_seen = 0
count = 0
failures = 0
failures_at = nil
chisel.set_interval_s(1)
return true
end
function on_interval()
print(evt.field(fnum) .. " " .. evt.field(ftime) .. " Estimating connection count at: " .. count - lowest_seen)
return true
end
-- Event parsing callback
function on_event()
if evt.field(ftype) ~= "close" then
if evt.field(frawres) >= 0 then
count = count + 1
if count > highest_seen then
highest_seen = count
end
-- print(evt.field(fnum) .. " " .. evt.field(ftime) .. " " .. evt.field(fname) .. "(" .. evt.field(fpid) .. ")" .. " opened")
else
failures = failures + 1
if failures_at == nil or failures_at > count then
failures_at = count
end
-- print(evt.field(fnum) .. " " .. evt.field(ftime) .. " " .. evt.field(fname) .. "(" .. evt.field(fpid) .. ")" .. " failed to open")
end
else
count = count - 1
if count < lowest_seen then
lowest_seen = count
end
-- print(evt.field(fnum) .. " " .. evt.field(ftime) .. " " .. evt.field(fname) .. "(" .. evt.field(fpid) .. ")" .. " closed")
end
end
-- End of capture callback
function on_capture_end()
maximum = highest_seen - lowest_seen
print("Highest connection count seen: " .. maximum .. " (" .. lowest_seen .. " .. " .. highest_seen .. ")")
if failures > 0 then
print("Seen " .. failures .. " failures, lowest at " .. (failures_at - lowest_seen))
else
print("No failures seen")
end
end