summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/CMakeLists.txt2
-rw-r--r--scripts/python_stat.sh3
-rw-r--r--scripts/shell_stat.sh59
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