2010-12-03 07:29:36 +01:00
#!/bin/sh
set -e -u
2016-06-13 03:30:19 +02:00
FILTER_DEVS = "1"
2014-02-24 17:00:21 +01:00
ROOMS = ""
2016-06-13 03:30:19 +02:00
CONNNAMES = ''
2013-09-18 16:03:25 +02:00
2010-12-03 07:29:36 +01:00
LIMIT = 10000
usage( ) {
2016-06-13 03:30:19 +02:00
echo " usage: $0 [--limit <n>] \\ "
echo " [--no-filter-devices] # default is to show only devices involved in games shown \\"
echo " [--room <room>]* # filter on specified room[s] \\"
echo " [--connname <connname>]* # filter on specified connname[s]"
2011-12-07 03:50:04 +01:00
exit 1
2010-12-03 07:29:36 +01:00
}
while [ $# -gt 0 ] ; do
case $1 in
--limit)
LIMIT = $2
shift
; ;
2016-06-13 03:30:19 +02:00
--no-filter-devices)
FILTER_DEVS = ''
2013-09-18 16:03:25 +02:00
; ;
2014-02-24 17:00:21 +01:00
--room)
[ -n " $ROOMS " ] && ROOMS = " ${ ROOMS } , "
ROOMS = " $ROOMS ' $2 ' "
shift
; ;
2016-06-13 03:30:19 +02:00
--connname)
[ -n " $CONNNAMES " ] && CONNNAMES = " ${ CONNNAMES } , "
CONNNAMES = " $CONNNAMES ' $2 ' "
shift
; ;
2010-12-03 07:29:36 +01:00
*) usage
; ;
esac
shift
done
2014-02-24 17:00:21 +01:00
QUERY = "WHERE NOT -NTOTAL = sum_array(nperdevice) AND NOT DEAD"
if [ -n " $ROOMS " ] ; then
QUERY = " $QUERY AND room IN ( $ROOMS ) "
fi
2016-06-13 03:30:19 +02:00
if [ -n " $CONNNAMES " ] ; then
QUERY = " $QUERY AND connname IN ( $CONNNAMES ) "
fi
2010-12-03 07:29:36 +01:00
2013-02-04 15:08:39 +01:00
echo -n " Device (pid) count: $( pidof xwords | wc | awk '{print $2}' ) "
echo " ; relay pid[s]: $( pidof xwrelay) "
2017-12-09 22:30:08 +01:00
echo -n "Row count:" $( psql -t xwgames -c " select count(*) FROM games $QUERY ; " )
echo " ; Relay sockets: $( for PID in $( pidof xwrelay) ; do ls /proc/$PID /fd; done | sort -un | tr '\n' ' ' ) "
2010-12-03 07:29:36 +01:00
2013-09-18 16:03:25 +02:00
# Games
2017-11-12 03:46:02 +01:00
echo "SELECT dead as d,connname,cid,room,lang as lg,clntVers as cv ,ntotal as t,nperdevice as npd,nsents as snts, seeds,devids,tokens,ack, mtimes " \
2015-02-24 03:24:01 +01:00
" FROM games $QUERY ORDER BY NOT dead, ctime DESC LIMIT $LIMIT ; " \
2010-12-03 07:29:36 +01:00
| psql xwgames
2013-09-18 16:03:25 +02:00
# Messages
2017-10-31 03:07:13 +01:00
echo "Unack'd msgs count:" $( psql -t xwgames -c " select count(*) FROM msgs where stime = 'epoch' AND connname IN (SELECT connname from games $QUERY ); " )
2017-10-19 06:19:42 +02:00
echo "SELECT id,connName,hid as h,token,ctime,stime,devid,msg64 " \
2017-10-31 03:07:13 +01:00
" FROM msgs WHERE stime = 'epoch' AND connname IN (SELECT connname from games $QUERY ) " \
2014-02-24 17:00:21 +01:00
" ORDER BY ctime DESC, connname LIMIT $LIMIT ; " \
2012-11-03 18:58:01 +01:00
| psql xwgames
2013-09-18 16:03:25 +02:00
# Devices
LINE = "SELECT id, model, osvers, array_length(mtimes, 1) as mcnt, mtimes[1] as mtime, array_length(devTypes, 1) as dcnt, devTypes[1] as dTyp, devids[1] as devid FROM devices "
2016-06-13 03:30:19 +02:00
if [ -n " $FILTER_DEVS " ] ; then
2013-09-18 16:03:25 +02:00
LINE = " ${ LINE } WHERE id IN (select UNNEST(devids) FROM games $QUERY ) "
fi
LINE = " $LINE ORDER BY mtimes[1] DESC LIMIT $LIMIT ; "
echo " $LINE " | psql xwgames
2012-09-12 04:07:16 +02:00