diff options
| author | luwenpeng <[email protected]> | 2024-08-21 13:59:44 +0800 |
|---|---|---|
| committer | luwenpeng <[email protected]> | 2024-08-21 18:18:40 +0800 |
| commit | 7625f62a8056fee02b92e6ddb022af61cc6d26f2 (patch) | |
| tree | 196b21584e66b708b40bb68ec63b3f5ab7340a1e /scripts | |
| parent | b9d663780035d74dd2b4288d4702f3e7dde0d775 (diff) | |
refactor: rename script to scripts
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | scripts/python_stat.sh | 3 | ||||
| -rw-r--r-- | scripts/shell_stat.sh | 59 |
3 files changed, 64 insertions, 0 deletions
diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt new file mode 100644 index 0000000..7243c1d --- /dev/null +++ b/scripts/CMakeLists.txt @@ -0,0 +1,2 @@ +install(FILES python_stat.sh DESTINATION ./ COMPONENT PROGRAM) +install(FILES shell_stat.sh DESTINATION ./ COMPONENT PROGRAM)
\ No newline at end of file diff --git a/scripts/python_stat.sh b/scripts/python_stat.sh new file mode 100644 index 0000000..2cfb69b --- /dev/null +++ b/scripts/python_stat.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +/opt/MESA/bin/fieldstat_exporter.py local -j /opt/tsg/stellar/log/stellar_fs4.json -l --clear-screen -e diff --git a/scripts/shell_stat.sh b/scripts/shell_stat.sh new file mode 100644 index 0000000..056f882 --- /dev/null +++ b/scripts/shell_stat.sh @@ -0,0 +1,59 @@ +#!/bin/bash +x + +#cat stellar_fs4.json |jq +#[ +# { +# "name": "stellar", +# "tags": {}, +# "fields": { +# "aaaa": 1111111, +# "bbbb": 2222222, +# }, +# "timestamp_ms": 1713053113549 +# } +#] + +calculate() { + local curr_data=$1 + local prev_data=$2 + + local fields=($(echo "$curr_data" | jq -r '.[].fields | to_entries | .[] | .key' | grep -v timestamp_ms)) + local curr_ts=$(echo "$curr_data" | jq -r '.[].timestamp_ms') + local prev_ts=$(echo "$prev_data" | jq -r '.[].timestamp_ms') + local diff_ts=$(($curr_ts - $prev_ts)) + local seconds=$((curr_ts / 1000)) + local buffer=() + + local curr_fileds=$(echo "$curr_data" | jq -r '.[].fields' | grep -v timestamp_ms) + local prev_fileds=$(echo "$prev_data" | jq -r '.[].fields' | grep -v timestamp_ms) + + buffer+=("====================================$(date -d "@$seconds" +"%Y-%m-%d %H:%M:%S")====================================\n") + buffer+=("$(printf "%-30s" Field)$(printf "%-20s" Sum)$(printf "%-20s" Speed)\n") + local result=() + for field in "${fields[@]}"; do + local curr_val=$(echo "$curr_fileds" | grep $field | awk '{print $2}' | sed 's/,//g') + local prev_val=$(echo "$prev_fileds" | grep $field | awk '{print $2}' | sed 's/,//g') + local diff_val=$((curr_val - prev_val)) + local speed=0 + if [ $diff_ts -eq 0 ]; then + speed=0 + else + speed=$((diff_val * 1000 / diff_ts)) + fi + buffer+=("$(printf "%-30s" $field)$(printf "%-20s" $curr_val)$(printf "%-20s" $speed)\n") + done + buffer+=("===========================================================================================\n") + clear + echo -e "${buffer[@]}" +} + +prev_data="" + +while true; do + curr_data=$(cat /opt/tsg/stellar/log/stellar_fs4.json) + if [ ! -z "$prev_data" ]; then + calculate "$curr_data" "$prev_data" + fi + prev_data="$curr_data" + sleep 1 +done |
