miaopanel
1#!/usr/bin/env bash
2# Diagnose live metric collection while traffic flows.
3set -uo pipefail
4ENTRY="${1:?usage: debug-waf.sh <entry>}"
5BASE="http://127.0.0.1:8888/$ENTRY"
6PASS=$(awk -F': ' '/^password:/{print $2}' /www/server/panel/data/initial_password.txt)
7
8curl -s -c /tmp/ck.txt -H 'Content-Type: application/json' -H 'Origin: http://127.0.0.1:8888' \
9 -d "{\"username\":\"admin\",\"password\":\"$PASS\"}" "$BASE/api/v1/auth/login" >/dev/null
10
11(
12 for i in $(seq 1 40); do
13 curl -s -o /dev/null -H 'Host: demo.test' "http://127.0.0.1/dbg-$i"
14 sleep 0.15
15 done
16) &
17LOAD=$!
18
19for n in 1 2 3 4; do
20 sleep 3
21 echo "--- t+$((n*3))s ---"
22 curl -s -b /tmp/ck.txt "$BASE/api/v1/waf/debug"
23 echo
24 curl -s -b /tmp/ck.txt "$BASE/api/v1/waf/overview" | python3 -c "
25import json,sys
26d=json.load(sys.stdin)['data']
27print(' qps=%.2f traffic=%.0f rt=%.2f req=%d blk=%d' % (d['qps'], d['traffic'], d['rt'], d['requests'], d['blocked']))"
28done
29wait $LOAD 2>/dev/null || true
30sleep 2
31echo "--- after traffic ---"
32curl -s -b /tmp/ck.txt "$BASE/api/v1/waf/debug"; echo
33tail -2 /www/wwwlogs/demo/access.log