periodic-task-runtimes.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_received_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_date_for_task () {
  41. host="$1"
  42. ssh "$USER@$host" "
  43. grep '$query' $CELERYD_LOGFILE | \
  44. grep 'processed:' | \
  45. perl -nle'
  46. /^\[(.+?): INFO.+?Task\s+(.+?)\s*/;
  47. print \"[\$1] $host \$2\"' | \
  48. sed 's/\s*$//'
  49. "
  50. }
  51. get_processed_for_all_hosts () {
  52. for_hosts="$*"
  53. for host in $for_hosts; do
  54. get_processed_date_for_task $host
  55. done
  56. }
  57. get_processed_for_all_hosts $hosts | sort