watch_activities 1.45 KB
Newer Older
1
#!/bin/sh
2
# Small watching script based on Sébastien idea.
Łukasz Nowak's avatar
Łukasz Nowak committed
3 4 5 6

# ideas:
#  - more control on what would be displayed
#  - allow to group by tag instead of method_id
7
#    - somehow done, use shell variable text_group
Łukasz Nowak's avatar
Łukasz Nowak committed
8
#  - use python with curses to have runtime control
9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
function show_help ( )
{
  script_name=`basename $0`
  echo """
  Usage:
    $script_name <mysql_opt> [interval seconds]
  Interval is default 5.
  mysql_opt are default mysql command line options.
  Put them in quotes if more than one option is passed.

  Typical usage:
    $script_name erp5
    $script_name \"-h remotehost -u user erp5remote\" 3
  """
}

MYSQL_OPT=$1
INTERVAL=$2

if [ "$MYSQL_OPT" == "" ] ; then
  show_help
31 32 33
  exit 1
fi

34 35 36 37
if [ "$INTERVAL" == "" ] ; then
  INTERVAL=5
fi

38 39 40
SELECT=""
for t in message message_queue ; do
  SELECT=$SELECT"""
41
  SELECT count(*) AS $t, ${text_group:-method_id}, processing, processing_node AS node, min(priority) AS min_pri, max(priority) AS max_pri FROM $t GROUP BY ${text_group:-method_id}, processing, processing_node ORDER BY node;
Łukasz Nowak's avatar
Łukasz Nowak committed
42
  SELECT count(*) AS $t, processing, processing_node, min(priority) AS min_pri, max(priority) AS max_pri FROM $t GROUP BY processing, processing_node;
43
  SELECT priority as pri, MIN(timediff(NOW(), date)) AS min, AVG(timediff(NOW() , date)) AS avg, MAX(timediff(NOW() , date)) AS max FROM $t GROUP BY priority;
Łukasz Nowak's avatar
Łukasz Nowak committed
44
  SELECT count(*) AS ${t}_count FROM $t;
45 46
  """
done
47
watch -n $INTERVAL "mysql $MYSQL_OPT --disable-pager -t -e '$SELECT' "