-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjson-io-config
109 lines (99 loc) · 2.93 KB
/
json-io-config
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
# -*- tab-width: 4 -*- ;; Emacs
# vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM
############################################################ IDENT(1)
#
# $Title: dwatch(8) JSON module for dtrace_io(4) $
# $Copyright: 2014-2022 Devin Teske. All rights reserved. $
# $FrauBSD: dwatch-json/json-io-config 2022-08-22 15:36:11 -0700 freebsdfrau $
# $Version: 1.0 $
#
############################################################ DESCRIPTION
#
# Produce JSON custom log format for disk I/O
#
############################################################ GLOBALS
eval "$( echo "$EVENT_TEST" | awk -v argv="$ARGV" '
function set(var, value)
{
gsub(/'\''/,"&\\\\&&", value)
printf "%s='\''%s'\''\n", var, value
}
$0 { buf = buf $0 }
END {
#
# EVENT_TEST for -k "ssh"
# execname == "ssh"
#
head = buf
tail = ""
while (match(head, /execname == "[^"]*"/)) {
tail = substr(head, 1, RSTART - 1)
repl = substr(head, RSTART, RLENGTH)
head = substr(head, RSTART + RLENGTH)
if (sub(/ \|\|[[:space:]]*\(/, "", head))
sub(/\)$/, "", head)
sub(/^execname == "/, "", repl)
sub(/"$/, "", repl)
argv = argv " -k \"" repl "\""
}
buf = tail head
#
# EVENT_TEST for -k "ssh*"
# strstr(execname, "ssh") == execname
#
head = buf
tail = ""
while (match(head, "strstr\\(execname, \"[^\"]*\"\\) == " \
"execname")) \
{
tail = substr(head, 1, RSTART - 1)
repl = substr(head, RSTART, RLENGTH)
head = substr(head, RSTART + RLENGTH)
if (sub(/ \|\|[[:space:]]*\(/, "", head))
sub(/\)$/, "", head)
sub(/^strstr\(execname, "/, "", repl)
sub(/"\) == execname$/, "", repl)
argv = argv " -k \"" repl "*\""
}
buf = tail head
#
# EVENT_TEST for -k "*ssh"
# strstr(execname, "ssh") == (execname + strlen(execname) - 3)
#
head = buf
tail = ""
while (match(head, "strstr\\(execname, \"[^\"]*\"\\) == " \
"\\(execname \\+ strlen\\(execname\\) - " \
"[[:digit:]]+\\)")) \
{
tail = substr(head, 1, RSTART - 1)
repl = substr(head, RSTART, RLENGTH)
head = substr(head, RSTART + RLENGTH)
if (sub(/ \|\|[[:space:]]*\(/, "", head))
sub(/\)$/, "", head)
sub(/^strstr\(execname, "/, "", repl)
sub("\"\\) == \\(execname \\+ strlen\\(execname\\)" \
" - [[:digit:]]+\\)", "", repl)
argv = argv " -k \"*" repl "\""
}
buf = tail head
set("EVENT_TEST", buf)
set("ARGV", argv)
}
' )"
############################################################ PROBE
_RAW_PROFILE=$PROFILE-raw
load_profile $_RAW_PROFILE
############################################################ MAIN
if [ "$DEBUG$EXIT_AFTER_COMPILE" ]; then
eval dwatch $ARGV -qX $_RAW_PROFILE
exit
fi
info "Watching '$PROBE' ..."
eval dwatch $ARGV -qX $_RAW_PROFILE $PROBE_ARG | awk '
sub(/^.*: /, "")||1 { print; fflush() }
' # END-QUOTE
exit $SUCCESS
################################################################################
# END
################################################################################