forked from paritytech/jamtart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus.sh
More file actions
executable file
Β·311 lines (274 loc) Β· 8.9 KB
/
status.sh
File metadata and controls
executable file
Β·311 lines (274 loc) Β· 8.9 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/bin/bash
# TART Telemetry System Status Script
# Shows comprehensive status of the telemetry system
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Default values
API_PORT=8080
TELEMETRY_PORT=9000
SHOW_EVENTS=10
WATCH_MODE=false
JSON_OUTPUT=false
# Parse command line arguments
print_usage() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -a, --api-port API port (default: 8080)"
echo " -t, --telemetry-port Telemetry port (default: 9000)"
echo " -e, --events COUNT Number of recent events to show (default: 10)"
echo " -w, --watch Watch mode - refresh every 5 seconds"
echo " -j, --json Output raw JSON"
echo " -h, --help Show this help message"
}
while [[ $# -gt 0 ]]; do
case $1 in
-a|--api-port)
API_PORT="$2"
shift 2
;;
-t|--telemetry-port)
TELEMETRY_PORT="$2"
shift 2
;;
-e|--events)
SHOW_EVENTS="$2"
shift 2
;;
-w|--watch)
WATCH_MODE=true
shift
;;
-j|--json)
JSON_OUTPUT=true
shift
;;
-h|--help)
print_usage
exit 0
;;
*)
echo "Unknown option: $1"
print_usage
exit 1
;;
esac
done
# Event type mapping function (for compatibility)
get_event_type_name() {
case $1 in
0) echo "Dropped";;
10) echo "Status";;
11) echo "BestBlockChanged";;
12) echo "FinalizedBlockChanged";;
13) echo "SyncStatusChanged";;
20) echo "ConnectionRefused";;
21) echo "ConnectingIn";;
22) echo "ConnectionInFailed";;
23) echo "ConnectedIn";;
24) echo "ConnectingOut";;
25) echo "ConnectionOutFailed";;
26) echo "ConnectedOut";;
27) echo "Disconnected";;
40) echo "Authoring";;
41) echo "AuthoringFailed";;
42) echo "Authored";;
43) echo "Importing";;
44) echo "BlockVerificationFailed";;
45) echo "BlockVerified";;
46) echo "BlockExecutionFailed";;
47) echo "BlockExecuted";;
*) echo "Unknown($1)";;
esac
}
# Check if API is accessible
check_api() {
if ! curl -sf "http://localhost:$API_PORT/health" > /dev/null; then
echo -e "${RED}Error: TART API is not accessible on port $API_PORT${NC}"
echo "Is the TART backend running?"
exit 1
fi
}
# Check if telemetry port is open
check_telemetry() {
if command -v nc &> /dev/null; then
if ! nc -z localhost "$TELEMETRY_PORT" 2>/dev/null; then
echo -e "${YELLOW}Warning: Telemetry port $TELEMETRY_PORT appears to be closed${NC}"
fi
fi
}
# Get process information
show_processes() {
echo -e "${CYAN}=== Running Processes ===${NC}"
echo ""
# Check TART backend
TART_PID=$(pgrep -f "tart-backend" | head -1)
if [ -n "$TART_PID" ]; then
echo -e "${GREEN}β${NC} TART Backend (PID: $TART_PID)"
ps -p "$TART_PID" -o %cpu,%mem,etime | tail -1 | while read cpu mem time; do
echo " CPU: ${cpu}%, Memory: ${mem}%, Uptime: ${time}"
done
else
echo -e "${RED}β${NC} TART Backend not running"
fi
# Check PolkaJam nodes
echo ""
POLKAJAM_PIDS=$(pgrep -f "polkajam")
if [ -n "$POLKAJAM_PIDS" ]; then
NODE_COUNT=$(echo "$POLKAJAM_PIDS" | wc -l | tr -d ' ')
echo -e "${GREEN}β${NC} PolkaJam Nodes: $NODE_COUNT running"
echo "$POLKAJAM_PIDS" | while read pid; do
if ps -p "$pid" > /dev/null 2>&1; then
ps -p "$pid" -o pid,command | tail -1 | grep -o "dev-validator [0-9]*" || echo " Node PID: $pid"
fi
done
else
echo -e "${YELLOW}β ${NC} No PolkaJam nodes running"
fi
echo ""
}
# Show node status
show_nodes() {
echo -e "${CYAN}=== Connected Nodes ===${NC}"
echo ""
NODES_JSON=$(curl -s "http://localhost:$API_PORT/nodes")
NODE_COUNT=$(echo "$NODES_JSON" | jq '.nodes | length')
if [ "$NODE_COUNT" -eq 0 ]; then
echo -e "${YELLOW}No nodes connected${NC}"
else
echo "$NODES_JSON" | jq -r '.nodes[] |
"\(.implementation_name) v\(.implementation_version)\n" +
" ID: \(.node_id[0:8])...\(.node_id[-8:])\n" +
" Connected: \(.connected_at)\n" +
" Events: \(.event_count)\n" +
" Status: \(if .is_connected then "π’ Connected" else "π΄ Disconnected" end)\n"'
fi
echo ""
}
# Show event statistics
show_event_stats() {
echo -e "${CYAN}=== Event Statistics ===${NC}"
echo ""
# Get event type counts
EVENTS=$(curl -s "http://localhost:$API_PORT/events?limit=1000")
echo "$EVENTS" | jq -r '.events |
group_by(.event_type) |
map({
type: .[0].event_type,
count: length
}) |
sort_by(.count) |
reverse |
.[] |
"\(.type)\t\(.count)"' | while read type count; do
TYPE_NAME=$(get_event_type_name $type)
printf "%-25s %5d\n" "$TYPE_NAME:" "$count"
done
echo ""
TOTAL_EVENTS=$(echo "$EVENTS" | jq '.events | length')
echo -e "${GREEN}Total events in last 1000: $TOTAL_EVENTS${NC}"
echo ""
}
# Show recent events
show_recent_events() {
echo -e "${CYAN}=== Recent Events (Last $SHOW_EVENTS) ===${NC}"
echo ""
curl -s "http://localhost:$API_PORT/events?limit=$SHOW_EVENTS" | \
jq -r '.events[] |
"\(.timestamp | split("T")[1] | split(".")[0]) \(.event_type) \(.node_id[0:8])..."' | \
while read time type node; do
TYPE_NAME=$(get_event_type_name $type)
printf "%-12s %-25s %s\n" "$time" "$TYPE_NAME" "$node"
done
echo ""
}
# Show block information
show_block_info() {
echo -e "${CYAN}=== Blockchain Status ===${NC}"
echo ""
# Get latest block info from events
LATEST_BEST=$(curl -s "http://localhost:$API_PORT/events?limit=100" | \
jq -r '.events[] | select(.event_type == 11) | .data.BestBlockChanged.slot' | \
head -1)
LATEST_FINALIZED=$(curl -s "http://localhost:$API_PORT/events?limit=100" | \
jq -r '.events[] | select(.event_type == 12) | .data.FinalizedBlockChanged.slot' | \
head -1)
# Get total blocks authored from stats endpoint
STATS=$(curl -s "http://localhost:$API_PORT/stats")
TOTAL_AUTHORED=$(echo "$STATS" | jq -r '.total_blocks_authored // 0')
if [ -n "$LATEST_BEST" ]; then
echo -e "Best Block: ${GREEN}#$LATEST_BEST${NC}"
else
echo -e "Best Block: ${YELLOW}Unknown${NC}"
fi
if [ -n "$LATEST_FINALIZED" ]; then
echo -e "Finalized Block: ${GREEN}#$LATEST_FINALIZED${NC}"
else
echo -e "Finalized Block: ${YELLOW}Unknown${NC}"
fi
echo -e "Blocks Authored: ${GREEN}$TOTAL_AUTHORED${NC} (total)"
echo ""
}
# Show system summary
show_summary() {
echo -e "${BLUE}ββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo -e "${BLUE}β TART Telemetry System Status β${NC}"
echo -e "${BLUE}ββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo ""
# Get basic stats
HEALTH=$(curl -s "http://localhost:$API_PORT/health")
VERSION=$(echo "$HEALTH" | jq -r '.version // "unknown"')
echo -e "Version: ${GREEN}$VERSION${NC}"
echo -e "API: ${GREEN}http://localhost:$API_PORT${NC}"
echo -e "Telemetry: ${GREEN}localhost:$TELEMETRY_PORT${NC}"
echo ""
}
# JSON output mode
json_output() {
NODES=$(curl -s "http://localhost:$API_PORT/nodes")
EVENTS=$(curl -s "http://localhost:$API_PORT/events?limit=$SHOW_EVENTS")
HEALTH=$(curl -s "http://localhost:$API_PORT/health")
jq -n \
--argjson health "$HEALTH" \
--argjson nodes "$NODES" \
--argjson events "$EVENTS" \
'{
health: $health,
nodes: $nodes,
recent_events: $events,
timestamp: now | strftime("%Y-%m-%d %H:%M:%S")
}'
}
# Main display function
display_status() {
if [ "$JSON_OUTPUT" = true ]; then
json_output
return
fi
clear
show_summary
show_processes
show_nodes
show_block_info
show_event_stats
show_recent_events
if [ "$WATCH_MODE" = true ]; then
echo -e "${YELLOW}Refreshing every 5 seconds... (Press Ctrl+C to stop)${NC}"
fi
}
# Main execution
check_api
check_telemetry
if [ "$WATCH_MODE" = true ]; then
while true; do
display_status
sleep 5
done
else
display_status
fi