-
Notifications
You must be signed in to change notification settings - Fork 21
/
mongostat-demangler.sh
executable file
·71 lines (66 loc) · 1.46 KB
/
mongostat-demangler.sh
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
#!/bin/bash
cat "$@" \
| awk '
{
if (! /^insert/ && $3 !~ /\|/) {
$3 = $3 "|0";
} else {
$3 = $3;
}
print;
}
' \
| sed \
-e '/^connected to/d' \
-e '/can.t get data/d' \
-e '/reconnect/d' \
-e '/DBClient/d' \
-e 's/\*//g' \
-e 's/|/ /g' \
-e 's/:\([0-9.]\+%\)/ \1/' \
| awk '
BEGIN {
print "#time insert query update update_r delete getmore command command_r flushes mapped vsize res non-mapped faults locked_db lock% idx_miss_% qr qw ar aw netIn netOut conn set repl";
header = 0;
}
{
if (/^insert/) {
if (!header) {
$0 = gensub("^", "#time ", "", $0);
$0 = gensub("time *$", "", "", $0);
$0 = gensub("update", "update update_r", "", $0);
$0 = gensub("command", "command command_r", "", $0);
$0 = gensub("locked db", "locked_db lock%", "", $0);
$0 = gensub("idx miss %", "idx_miss_%", "", $0);
for (i = 1; i <= NF; i++) {
printf("%s(%d)%s", (i==1)?"#":"", i, (i==NF)?"\n":" ");
}
print;
#header = 1;
}
} else {
for (i = 1; i <= NF; i++) {
if ($i ~ /k$/) {
$i = 1000 * gensub("k$", "", "", $i);
}
if ($i ~ /m$/) {
$i = 1000000 * gensub("m$", "", "", $i);
}
if ($i ~ /g$/) {
$i = 1000000000 * gensub("g$", "", "", $i);
}
}
if ($3 >= 0) {
}
if ($1 >= 0) {
time = $NF;
for (i = NF; i > 1; i--) {
$i = $(i-1);
}
$1 = time;
print;
}
}
}
' \
| column -tn