Skip to content

Commit e857bb4

Browse files
authored
feat: [NET-1417] Add utility scripts (#31)
These Bash scripts extract information from the Crawler logs, e.g. - success/failure rates and version stats: `stats.sh` - version stats for a node: `node-version.sh` - version stats for a stream: `node-versions-for-stream.sh` - topology sizes: `topologies.sh`
1 parent f77fc05 commit e857bb4

File tree

8 files changed

+89
-0
lines changed

8 files changed

+89
-0
lines changed

tools/node-types.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
LOGFILE=~/.pm2/logs/stream-metrics-index-crawler-out.log
2+
echo 'Success:'
3+
grep 'Queried' $LOGFILE | grep -o 'type":[0-9]' | tr -d '"' | sort | uniq -c
4+
echo 'Failure:'
5+
grep 'Query failed' $LOGFILE | grep -o 'type":[0-9]' | tr -d '"' | sort | uniq -c

tools/node-version.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
NODE_ID=$1
2+
LOGFILE=~/.pm2/logs/stream-metrics-index-crawler-out.log
3+
grep -e 'Queried '$1 $LOGFILE | jq -sr 'map(.info.applicationVersion) | .[]' | sort | uniq

tools/node-versions-for-stream.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
STREAM_ID=$1
2+
RUN_ID=$2
3+
LOGFILE=~/.pm2/logs/stream-metrics-index-crawler-out.log
4+
grep $RUN_ID $LOGFILE | grep 'Queried' | grep $STREAM_ID | jq -s 'map(.info.applicationVersion) | group_by(.) | map({(.[0]): length}) | add'

tools/nodes.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
LOGFILE=~/.pm2/logs/stream-metrics-index-crawler-out.log
2+
grep 'Queried ' $LOGFILE | jq -sr 'map("success " + .runId + " " + .info.peerDescriptor.nodeId) | .[]'
3+
grep 'Query failed' $LOGFILE | jq -sr 'map("failure " + .runId + " " + .peerDescriptor.nodeId) | .[]'

tools/peer-descriptors.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
LOGFILE=~/.pm2/logs/stream-metrics-index-crawler-out.log
2+
(
3+
grep 'Queried '$1 $LOGFILE | jq -s 'map({peerDescriptor: .info.peerDescriptor, runId, time: (.time/1000|todate), success: true}) | .[]'
4+
grep 'Query failed '$1 $LOGFILE | jq -s 'map({peerDescriptor: .peerDescriptor, runId, time: (.time/1000|todate), success: false}) | .[]'
5+
) | jq -s

tools/stats.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
DEFAULT_LOGFILE=~/.pm2/logs/stream-metrics-index-crawler-out.log
4+
LOGFILE="${1:-$DEFAULT_LOGFILE}"
5+
6+
printStats() {
7+
local RUN_ID=$1
8+
echo "Run $RUN_ID"
9+
10+
local ITEMS=$(awk -v run_id="$RUN_ID" '$0 ~ run_id {print}' $LOGFILE)
11+
SUCCESS_ITEMS=$(jq -s 'map(select(.msg | contains("Queried ")))' <<< $ITEMS)
12+
FAILURE_ITEMS=$(jq -s 'map(select(.msg | contains("Query failed ")))' <<< $ITEMS)
13+
SUCCESS_DESCRIPTORS=$(jq 'map(.info.peerDescriptor)' <<< $SUCCESS_ITEMS)
14+
FAILURE_DESCRIPTORS=$(jq 'map(.peerDescriptor)' <<< $FAILURE_ITEMS)
15+
16+
printCategoryStats 'All' "$SUCCESS_DESCRIPTORS" "$FAILURE_DESCRIPTORS" '.'
17+
printCategoryStats 'NodeJS-all' "$SUCCESS_DESCRIPTORS" "$FAILURE_DESCRIPTORS" '.type == 0'
18+
printCategoryStats 'NodeJS-WebSocket' "$SUCCESS_DESCRIPTORS" "$FAILURE_DESCRIPTORS" '(.type == 0) and (.websocket)'
19+
printCategoryStats 'NodeJS-AutoCertified' "$SUCCESS_DESCRIPTORS" "$FAILURE_DESCRIPTORS" '(.type == 0) and ((.websocket.host // "") | contains("streamr-nodes.xyz"))'
20+
printCategoryStats 'NodeJS-non-WebSocket' "$SUCCESS_DESCRIPTORS" "$FAILURE_DESCRIPTORS" '(.type == 0) and (.websocket | not)'
21+
printCategoryStats 'Browser' "$SUCCESS_DESCRIPTORS" "$FAILURE_DESCRIPTORS" ".type == 1"
22+
23+
echo "Errors:"
24+
jq -r --monochrome-output 'map(.err.code) | group_by(.) | map({(.[0]): length}) | add' <<< $FAILURE_ITEMS
25+
26+
echo "Versions:"
27+
jq -r --monochrome-output 'map(.info.applicationVersion) | group_by(.) | map({(.[0]): length}) | add' <<< $SUCCESS_ITEMS
28+
29+
echo -e "\n\n"
30+
}
31+
32+
printCategoryStats() {
33+
local CATEGORY=$1
34+
local SUCCESS_DESCRIPTORS=$2
35+
local FAILURE_DESCRIPTORS=$3
36+
local FILTER=$4
37+
38+
local SUCCESS_COUNT=$(jq 'length' <<< $SUCCESS_DESCRIPTORS)
39+
local FAILURE_COUNT=$(jq 'length' <<< $FAILURE_DESCRIPTORS)
40+
local TOTAL_COUNT=$((SUCCESS_COUNT + FAILURE_COUNT))
41+
local FAILURE_PERCENTAGE=$((FAILURE_COUNT * 100 / TOTAL_COUNT))
42+
43+
echo "$CATEGORY:"
44+
local CATEGORY_SUCCESS_COUNT=$(jq "map(select($FILTER)) | length" <<< $SUCCESS_DESCRIPTORS)
45+
local CATEGORY_FAILURE_COUNT=$(jq "map(select($FILTER)) | length" <<< $FAILURE_DESCRIPTORS)
46+
local CATEGORY_TOTAL_COUNT=$((CATEGORY_SUCCESS_COUNT + CATEGORY_FAILURE_COUNT))
47+
if [ "$CATEGORY_TOTAL_COUNT" -eq 0 ]; then
48+
local CATEGORY_FAILURE_PERCENTAGE=0
49+
else
50+
local CATEGORY_FAILURE_PERCENTAGE=$((CATEGORY_FAILURE_COUNT * 100 / CATEGORY_TOTAL_COUNT))
51+
fi
52+
echo "- total=$CATEGORY_TOTAL_COUNT success=$CATEGORY_SUCCESS_COUNT failure=$CATEGORY_FAILURE_COUNT ($CATEGORY_FAILURE_PERCENTAGE%)"
53+
}
54+
55+
echo -e "\n\n"
56+
57+
grep 'Queried ' $LOGFILE | grep -o '"runId":"full-[0-9]*' | cut -c 10- | sort -u | while read -r RUN_ID; do
58+
printStats "$RUN_ID"
59+
done

tools/topologies.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
LOGFILE=~/.pm2/logs/stream-metrics-index-crawler-out.log
2+
grep 'Topology:' $LOGFILE | grep '"runId":"full' | jq -s '.[] | {msg, runId, time: (.time/1000) | todate}'

tools/versions.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
if [ $# -eq 0 ]; then
2+
echo "Error: No argument (runId) passed. Please provide an argument."
3+
exit 1
4+
fi
5+
6+
LOGFILE=~/.pm2/logs/stream-metrics-index-crawler-out.log
7+
8+
grep $1 $LOGFILE | grep 'Queried' | jq .info.applicationVersion | sort | uniq -c | awk '{print $2, $1}'

0 commit comments

Comments
 (0)