commit 1ced32c441385a44aed7237a01c1953cdd6ee6a4
parent 5654142d459afc960708de4bf28c8c38f9be5cf6
Author: MS <ms@taler.net>
Date: Wed, 22 Nov 2023 15:50:48 +0100
/monitor testing: script to populate the database.
Diffstat:
1 file changed, 62 insertions(+), 0 deletions(-)
diff --git a/contrib/populate-stats.sh b/contrib/populate-stats.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+# This script populates the stats table, to test the /monitor API.
+
+usage() {
+ echo "Usage: ./populate-stats.sh CONFIG_FILE"
+ echo
+ echo "Populates the stats table with random data"
+}
+
+# Detecting the help case.
+if test "$1" = "--help" -o "$1" = "-h" -o -z ${1:-};
+ then usage
+ exit
+fi
+set -eu
+
+DB_NAME=$(taler-config -c $1 -s libeufin-bankdb-postgres -o config)
+echo Running on the database: $DB_NAME
+
+# random number in range $1-$2
+rnd () {
+ shuf -i $1-$2 -n1
+}
+
+# $1 == timestamp
+insert_cmd () {
+ echo "
+ INSERT INTO libeufin_bank.bank_stats (
+ timeframe
+ ,start_time
+ ,taler_in_count
+ ,taler_in_volume
+ ,taler_out_count
+ ,taler_out_volume
+ ,cashin_count
+ ,cashin_regional_volume
+ ,cashin_fiat_volume
+ ,cashout_count
+ ,cashout_regional_volume
+ ,cashout_fiat_volume
+ ) VALUES (
+ 'hour'
+ ,TO_TIMESTAMP($1)
+ ,$(rnd 1 3000)
+ ,($(rnd 1 1000000), $(rnd 0 99999999))
+ ,$(rnd 1 3000)
+ ,($(rnd 1 1000000), $(rnd 0 99999999))
+ ,$(rnd 1 3000)
+ ,($(rnd 1 1000000), $(rnd 0 99999999))
+ ,($(rnd 1 1000000), $(rnd 0 99999999))
+ ,$(rnd 1 3000)
+ ,($(rnd 1 1000000), $(rnd 0 99999999))
+ ,($(rnd 1 1000000), $(rnd 0 99999999))
+ );"
+}
+
+for n_hour_ago in `seq 1 100`; do
+ echo -n .
+ TIMESTAMP=$(date --date="${n_hour_ago} hour ago" +%s)
+ psql $DB_NAME -c "$(insert_cmd ${TIMESTAMP})" > /dev/null
+done