synapse/cmd.sh
author Peter Gervai <grin@grin.hu>
Fri, 04 Mar 2022 10:54:52 +0100
changeset 8 b92f5cceab78
parent 7 6aea45bf033b
child 9 c636ea2e8ee1
permissions -rwxr-xr-x
Add unts() function creation to cmd.sh
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     1
#!/bin/bash
8
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
     2
#$Id: cmd.sh,v efd1721dba68 2022/03/04 09:54:35 grin $
7
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
     3
#
2
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     4
#
3
99e6c1cdae3b synapse/cmd.sh: add description comment
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
     5
# This program queries PostgreSQL directly for various user statistics.
99e6c1cdae3b synapse/cmd.sh: add description comment
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
     6
# Set psql access below (CMD=...), ensure that .pgpass lets user to login
99e6c1cdae3b synapse/cmd.sh: add description comment
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
     7
#  without password entry.
99e6c1cdae3b synapse/cmd.sh: add description comment
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
     8
# Start without arguments for help.
99e6c1cdae3b synapse/cmd.sh: add description comment
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
     9
#
8
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    10
# You need to run 'unts' the first time with write access or copy the
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    11
# output into psql.
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    12
#
7
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    13
# (c)Peter Gervai, 2020-22
3
99e6c1cdae3b synapse/cmd.sh: add description comment
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
    14
# @grin:grin.hu
2
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    15
# Licensed under GPLv3+ and CC_By-Sa-4.0-int
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    16
#
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    17
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    18
#CMD='sudo -u postgres psql synapse -tAc'
7
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    19
#CMD='psql -h 1.2.3.4 -U synapse synapse -c'
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    20
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    21
. ./_config.sh
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    22
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    23
CMD="${PSQL_CMD}"
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    24
CMDQ='-At'
2
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    25
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    26
MODE="$1"
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    27
ARG="$2"
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    28
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    29
if [ "x$MODE" = "x" ]; then
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    30
	echo "Usage: $0 <mode> <args> ...."
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    31
	echo " modes: user @someuser:grin.hu       - user stats"
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    32
	echo "        userevents @someuser:grin.hu - user events"
7
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    33
	echo "        active1                      - last 1 day active users"
3
99e6c1cdae3b synapse/cmd.sh: add description comment
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
    34
	echo "        active1u                     - last 1 day users (unique results)"
2
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    35
	echo "        lastreg [<n>]	           - last <n> (25) registrations"
7
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    36
	echo "        room <room_id without !>     - room info"
8
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    37
	echo "        evt <event w/o $             - event info"
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    38
	echo "        unts                         - create unts() function for human-readable"
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    39
	echo "                                       timestamps; requires Write access or copy displayed sql."
2
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    40
	exit
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    41
fi
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    42
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    43
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    44
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    45
egy_arg() {
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    46
	local s=$1
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    47
	if [ "x$ARG" = "x" ]; then
7
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    48
		echo "MIssing arg ${s}!"
2
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    49
		echo "$0 $MODE $s"
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    50
		exit
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    51
	fi
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    52
}
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    53
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    54
8
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    55
### create unts() func
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    56
if [ "$MODE" = "unts" ]; then
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    57
	echo "Creating unts() function; needs write access or you can simply copy the following code into psql."
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    58
	echo " "
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    59
	SQL='CREATE OR REPLACE FUNCTION public.unts(bigint)
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    60
 RETURNS timestamp with time zone
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    61
 LANGUAGE sql
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    62
 IMMUTABLE STRICT
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    63
AS $function$
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    64
  SELECT TIMESTAMP WITH TIME ZONE ''epoch'' + $1/1000 * INTERVAL ''1 second''
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    65
$function$'
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    66
	echo "${SQL}"
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    67
	echo " "
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    68
	$CMD "${SQL}"
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    69
	exit
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    70
fi
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    71
b92f5cceab78 Add unts() function creation to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
    72
2
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    73
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    74
if [ "$MODE" = "user" ]; then
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    75
	egy_arg 'user'
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    76
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    77
	echo "=== User data ==="
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    78
	$CMD "SELECT display_name FROM user_directory WHERE user_id='$ARG'"
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    79
	$CMD "SELECT medium, address, unts(validated_at) AS validated_at, unts(added_at) AS added_at FROM user_threepids WHERE user_id='$ARG'"
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    80
	$CMD "SELECT joined_rooms FROM user_stats_current WHERE user_id='$ARG'"
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    81
	
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    82
 	echo "=== Logins ==="
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    83
 	$CMD "SELECT user_id,device_id,ip,unts(last_seen) AS last_seen,user_agent FROM user_ips WHERE user_id='$ARG'"
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    84
 	$CMD "SELECT device_id, user_agent, unts(timestamp) FROM user_daily_visits WHERE user_id='$ARG' ORDER BY 1 ASC, 3 DESC LIMIT 10"
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    85
 	
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    86
 	echo "=== Shared private rooms ==="
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    87
 	$CMD "select * from users_who_share_private_rooms where user_id='$ARG'"
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    88
 	
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    89
 	echo "=== Rooms the user has been ==="
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    90
 	$CMD "SELECT rm.room_id, rm.event_id, rm.sender, rm.membership, 
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    91
       rss.canonical_alias, rss.join_rules, rss.encryption, 
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    92
       unts(e.origin_server_ts), rss.name
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    93
 FROM room_memberships  rm
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    94
 JOIN room_stats_state rss USING(room_id) 
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    95
 JOIN events e USING(event_id)
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    96
 WHERE user_id='$ARG'
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    97
 ORDER BY e.origin_server_ts" | more
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    98
	
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    99
 	exit
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   100
fi
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   101
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   102
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   103
if [ "$MODE" = "userevents" ]; then
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   104
        egy_arg 'user'
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   105
        $CMD "SELECT * FROM events WHERE sender='@sztg:grin.hu';
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   106
SELECT stream_ordering,type,e.room_id,content,sender,unts(origin_server_ts) AS orig_s,json 
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   107
 FROM events e LEFT JOIN event_json j USING(event_id) 
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   108
 WHERE sender='$ARG'"
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   109
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   110
	exit
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   111
fi
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   112
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   113
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   114
if [ "$MODE" = "active1" ]; then
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   115
	$CMD "SELECT user_id,device_id,ip,unts(MAX(last_seen)) AS last_seen,user_agent FROM user_ips 
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   116
		 WHERE unts(last_seen)> NOW()-'1 day'::interval 
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   117
		 GROUP BY 1,2,3,5
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   118
		 ORDER BY last_seen DESC"
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   119
 	exit
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   120
fi
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   121
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   122
if [ "$MODE" = "lastreg" ]; then
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   123
	if [ "x$ARG" = "x" ]; then
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   124
		ARG=25
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   125
	fi
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   126
	
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   127
	$CMD "SELECT name,unts(creation_ts*1000) AS created,is_guest,deactivated,shadow_banned,
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   128
		device_id,ip,unts(last_seen) AS last_seen, user_agent
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   129
		FROM users LEFT JOIN user_ips ON(name=user_id)
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   130
		ORDER BY 2 DESC 
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   131
		LIMIT $ARG"
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   132
fi
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   133
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   134
if [ "$MODE" = "active1u" ]; then
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   135
	$CMD "SELECT DISTINCT user_id FROM user_ips 
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   136
		 WHERE unts(last_seen)> NOW()-'1 day'::interval 
3
99e6c1cdae3b synapse/cmd.sh: add description comment
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
   137
		 ORDER BY 1" | cat
2
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   138
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   139
	$CMD "SELECT DISTINCT user_id,device_id,ip FROM user_ips 
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   140
		 WHERE unts(last_seen)> NOW()-'1 day'::interval 
3
99e6c1cdae3b synapse/cmd.sh: add description comment
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
   141
		 ORDER BY 1" | cat
2
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   142
 	exit
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   143
fi
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   144
7
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   145
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   146
if [ "$MODE" = "room" ]; then
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   147
	$CMD "SELECT rs.name, rs.canonical_alias,rs.join_rules,rs.topic FROM room_stats_state rs WHERE room_id='!${ARG}'" | cat
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   148
	$CMD "SELECT room_alias, creator FROM room_aliases WHERE room_id='!${ARG}'" | cat
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   149
	$CMD "SELECT * FROM rooms WHERE room_id='!${ARG}'" | cat
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   150
	$CMD "SELECT * FROM room_stats_current WHERE room_id='!${ARG}'" | cat
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   151
	# $CMD "SELECT COUNT(*), type FROM state_groups_state WHERE room_id='!${ARG}' GROUP BY 2 ORDER BY 1 DESC" | cat
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   152
fi
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   153
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   154
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   155
if [ "$MODE" = "evt" ]; then
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   156
	$CMD "SELECT event_id,type,room_id,content,processed,depth,sender,instance_name,state_key,unts(origin_server_ts) AS orig, unts(received_ts) AS rcv FROM events WHERE event_id='\$${ARG}'" | cat
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   157
	$CMD "SELECT * FROM event_json WHERE event_id='\$${ARG}'" | cat
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   158
	evt='$'"${ARG}"
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   159
	room=`$CMD "SELECT room_id FROM events WHERE event_id='${evt}'" $CMDQ`
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   160
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   161
	#echo "Room_id=$room!"
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   162
        $CMD "SELECT rs.name, rs.canonical_alias,rs.join_rules,rs.topic FROM room_stats_state rs WHERE room_id='$room'" | cat
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   163
        $CMD "SELECT room_alias, creator FROM room_aliases WHERE room_id='$room'" | cat
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   164
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   165
fi
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   166