periodic-task-runtimes.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 'processed:' | \
  34. perl -nle'
  35. /^\[(.+?): INFO/; print \$1' | \
  36. sed 's/\s*$//'
  37. "
  38. }
  39. get_processed_for_all_hosts () {
  40. for_hosts="$*"
  41. for host in $for_hosts; do
  42. get_processed_date_for_task $host
  43. done
  44. }
  45. get_processed_for_all_hosts $hosts | sort