Skip to content

Commit 29f1414

Browse files
wip
1 parent 1a5bea8 commit 29f1414

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

scripts/monitor_metrics.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ while true; do
3535
TIMESTAMP=$(date +%s)
3636
METRICS=$(curl -s http://localhost:30080/metrics)
3737

38-
GO_GOROUTINES=$(echo "$METRICS" | grep '^go_goroutines' | awk '{print $2}')
39-
OPEN_FDS=$(echo "$METRICS" | grep '^process_open_fds' | awk '{print $2}')
40-
DB_IDLE=$(echo "$METRICS" | grep 'go_sql_stats_connections_idle{db_name="broker"}' | awk '{print $2}')
41-
DB_MAX_OPEN=$(echo "$METRICS" | grep 'go_sql_stats_connections_max_open{db_name="broker"}' | awk '{print $2}')
42-
DB_IN_USE=$(echo "$METRICS" | grep 'go_sql_stats_connections_in_use{db_name="broker"}' | awk '{print $2}')
43-
MEM_ALLOC=$(echo "$METRICS" | grep -w '^go_memstats_alloc_bytes' | awk '{printf "%.2f", $2/1048576}')
44-
MEM_STACK=$(echo "$METRICS" | grep '^go_memstats_stack_inuse_bytes' | awk '{printf "%.2f", $2/1048576}')
45-
MEM_HEAP=$(echo "$METRICS" | grep '^go_memstats_heap_inuse_bytes' | awk '{printf "%.2f", $2/1048576}')
38+
GO_GOROUTINES=$(echo "$METRICS" | awk '/^go_goroutines/ {print $2}')
39+
OPEN_FDS=$(echo "$METRICS" | awk '/^process_open_fds/ {print $2}')
40+
DB_IDLE=$(echo "$METRICS" | awk '/go_sql_stats_connections_idle\{db_name="broker"\}/ {print $2}')
41+
DB_MAX_OPEN=$(echo "$METRICS" | awk '/go_sql_stats_connections_max_open\{db_name="broker"\}/ {print $2}')
42+
DB_IN_USE=$(echo "$METRICS" | awk '/go_sql_stats_connections_in_use\{db_name="broker"\}/ {print $2}')
43+
MEM_ALLOC=$(echo "$METRICS" | awk '/^go_memstats_alloc_bytes / {printf "%.2f", $2/1048576}')
44+
MEM_STACK=$(echo "$METRICS" | awk '/^go_memstats_stack_inuse_bytes/ {printf "%.2f", $2/1048576}')
45+
MEM_HEAP=$(echo "$METRICS" | awk '/^go_memstats_heap_inuse_bytes/ {printf "%.2f", $2/1048576}')
4646

4747
echo "{\"timestamp\": $TIMESTAMP, \"goroutines\": $GO_GOROUTINES, \"open_fds\": $OPEN_FDS, \"db_idle\": $DB_IDLE, \"db_max_open\": $DB_MAX_OPEN, \"db_in_use\": $DB_IN_USE, \"mem_alloc\": $MEM_ALLOC, \"mem_stack\": $MEM_STACK, \"mem_heap\": $MEM_HEAP}" >> "$METRICS_FILE"
4848

0 commit comments

Comments
 (0)