periodic-task-runtimes.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. #---------------------------------------------------------------------------#
  3. #
  4. # Tool to find race conditions in the Periodic Task system.
  5. # Outputs times of all runs of a certain task (by searching for task name
  6. # using a search query).
  7. #
  8. # Usage:
  9. #
  10. # $ bash periodic-task-runtimes.sh query host1 [host2 ... hostN]
  11. #
  12. # Example usage:
  13. #
  14. # $ bash periodic-task-runtimes.sh refresh_all_feeds host1 host2 host3
  15. #
  16. # The output is sorted.
  17. #
  18. #---------------------------------------------------------------------------#
  19. USER="root"
  20. CELERYD_LOGFILE="/var/log/celeryd.log"
  21. query="$1"
  22. shift
  23. hosts="$*"
  24. usage () {
  25. echo "$(basename $0) task_name_query host1 [host2 ... hostN]"
  26. exit 1
  27. }
  28. [ -z "$query" -o -z "$hosts" ] && usage
  29. get_processed_date_for_task () {
  30. host="$1"
  31. ssh "$USER@$host" "
  32. grep '$query' $CELERYD_LOGFILE | \
  33. grep 'Got task from broker:' | \
  34. perl -nle'
  35. /^\[(.+?): INFO.+?Got task from broker:(.+?)\s*/;
  36. print \"[\$1] $host \$2\"' | \
  37. sed 's/\s*$//'
  38. "
  39. }
  40. get_processed_for_all_hosts () {
  41. for_hosts="$*"
  42. for host in $for_hosts; do
  43. get_processed_date_for_task $host
  44. done
  45. }
  46. get_processed_for_all_hosts $hosts | sort