synapse/cmd.sh
author Peter Gervai <grin@grin.hu>
Wed, 03 Aug 2022 10:43:29 +0200
changeset 11 3d9a0d238469
parent 10 aaa61e5b4526
permissions -rwxr-xr-x
Add check.server.pl: checks whether a matrix server is real and responding * uses both spec based checks and MSC1929 and nodeinfo2 * not pretty, not robust, just works
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 " "
9
c636ea2e8ee1 cmd.sh: I dislike shell escaping, and it doesn't like me either. (fix escaped ')
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
    59
	SQL="CREATE OR REPLACE FUNCTION public.unts(bigint)
8
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
9
c636ea2e8ee1 cmd.sh: I dislike shell escaping, and it doesn't like me either. (fix escaped ')
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
    63
AS \$function$
c636ea2e8ee1 cmd.sh: I dislike shell escaping, and it doesn't like me either. (fix escaped ')
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
    64
  SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \$1/1000 * INTERVAL '1 second'
c636ea2e8ee1 cmd.sh: I dislike shell escaping, and it doesn't like me either. (fix escaped ')
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
    65
\$function$"
8
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'"
10
aaa61e5b4526 cmd.sh: set ordering on some longer outputs.
Peter Gervai <grin@grin.hu>
parents: 9
diff changeset
    79
	$CMD "SELECT name,password_hash,to_timestamp(creation_ts) AS creation,admin,is_guest,deactivated,shadow_banned FROM users WHERE name='$ARG'"
2
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    80
	$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
    81
	$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
    82
	
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    83
 	echo "=== Logins ==="
10
aaa61e5b4526 cmd.sh: set ordering on some longer outputs.
Peter Gervai <grin@grin.hu>
parents: 9
diff changeset
    84
 	$CMD "SELECT user_id,device_id,ip,unts(last_seen) AS last_seen,user_agent FROM user_ips WHERE user_id='$ARG' ORDER BY last_seen DESC"
aaa61e5b4526 cmd.sh: set ordering on some longer outputs.
Peter Gervai <grin@grin.hu>
parents: 9
diff changeset
    85
 	$CMD "SELECT device_id, user_agent, unts(timestamp) AS stamp FROM user_daily_visits WHERE user_id='$ARG' ORDER BY 1 ASC, 3 DESC LIMIT 10"
2
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    86
 	
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    87
 	echo "=== Shared private rooms ==="
10
aaa61e5b4526 cmd.sh: set ordering on some longer outputs.
Peter Gervai <grin@grin.hu>
parents: 9
diff changeset
    88
 	$CMD "select * from users_who_share_private_rooms where user_id='$ARG' ORDER BY room_id,other_user_id"
2
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    89
 	
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    90
 	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
    91
 	$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
    92
       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
    93
       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
    94
 FROM room_memberships  rm
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    95
 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
    96
 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
    97
 WHERE user_id='$ARG'
10
aaa61e5b4526 cmd.sh: set ordering on some longer outputs.
Peter Gervai <grin@grin.hu>
parents: 9
diff changeset
    98
 ORDER BY e.origin_server_ts DESC" | more
2
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    99
	
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   100
 	exit
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   101
fi
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
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   104
if [ "$MODE" = "userevents" ]; then
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   105
        egy_arg 'user'
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   106
        $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
   107
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
   108
 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
   109
 WHERE sender='$ARG'"
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   110
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   111
	exit
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   112
fi
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
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   115
if [ "$MODE" = "active1" ]; then
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   116
	$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
   117
		 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
   118
		 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
   119
		 ORDER BY last_seen DESC"
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   120
 	exit
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   121
fi
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   122
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   123
if [ "$MODE" = "lastreg" ]; then
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   124
	if [ "x$ARG" = "x" ]; then
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   125
		ARG=25
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   126
	fi
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   127
	
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   128
	$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
   129
		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
   130
		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
   131
		ORDER BY 2 DESC 
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   132
		LIMIT $ARG"
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   133
fi
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   134
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   135
if [ "$MODE" = "active1u" ]; then
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   136
	$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
   137
		 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
   138
		 ORDER BY 1" | cat
2
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   139
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   140
	$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
   141
		 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
   142
		 ORDER BY 1" | cat
2
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   143
 	exit
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   144
fi
c3f49b58aff6 Add synapse/cmd.sh: query db for various user statistics
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   145
7
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   146
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   147
if [ "$MODE" = "room" ]; then
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   148
	$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
   149
	$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
   150
	$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
   151
	$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
   152
	# $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
   153
fi
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
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   156
if [ "$MODE" = "evt" ]; then
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   157
	$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
   158
	$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
   159
	evt='$'"${ARG}"
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   160
	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
   161
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   162
	#echo "Room_id=$room!"
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   163
        $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
   164
        $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
   165
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   166
fi
6aea45bf033b Add room and event display to cmd.sh
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   167