Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. # Many of these are obvious and stupidly simple, but for your reference and copy-pasting pleasure…
  2.  
  3.  
  4. # Mextify all (with workaround for pesky samples that contain multi-line RSA key that breaks pt-mext)
  5. for i in $(ls $1/*-mysqladmin); do { (cat $i | sed -e '/\-\-\-\-\-BEGIN\ PUBLIC\ KEY/,+9d' | pt-mext -r -- cat -) > $i.mext && echo $i.mext;} done;
  6.  
  7. # Inspect given variable through multiple mext samples (revealing ;-))
  8. grep Table_locks_waited *.mext |less -S
  9.  
  10. #Find contentious tables
  11. grep -h waiting_table_lock *-lock-waits |sort|uniq -c |sort -nr
  12.  
  13. #Find the sample with the most lock waits
  14. grep --count "LOCK WAIT" */*-innodb* |tr ":" " " |sort -nk2
  15.  
  16. #Aggregate semaphore waits
  17. grep waited */*-innodb* |awk '{print $6, $8}'|sort |uniq -c |sort -nr
  18.  
  19. #Average gauge-type counters from mysqladmin ext samples:
  20. for i in $(ls -1 *-mysqladmin); do { echo -n "$i --> "; grep Innodb_data_pending_reads $i|awk '{t+=$4} END {print (t/NR)}'; } done
  21.  
  22. #Totalize/Average counters from mext samples:
  23. for i in $(ls -1 *.mext); do { echo -n "$i --> "; grep Com_select $i|awk '{$1=""; $2=""; print $0}'|tr " " "\n" |awk '{t+=$1} END {print ("total: ", t, ", avg: ", t/NR)}' } done;
  24.  
  25. #Find the samples with the heaviest loads; Useful when you have a ton of stalk samples and you are unsure which one to look at:
  26. grep Threads_running *-mysqladmin |sort -grk4 |head -n10
  27. grep "load average" *-top;
  28.  
  29. Aggregate threads by sample and state
  30. #!/bin/bash
  31. source=$1
  32. f=0, l=0; grep -n ^TS $source |awk -F: '{print $1}'|while read n; do {
  33. if [[ $f == 0 ]]; then { f=$n; continue; } fi;
  34. l=$n;
  35. tail -n +${f} $source |head -n $(($l - $f)) > $source-sample-$n;
  36. f=$l;
  37. } done;
  38. for i in $(ls -1 ${source}-sample-*|sort -t"-" -k4 -h); do { echo $i; grep State $i|sort|uniq -c |sort -nr|head -n5; echo "============================================="; } done
  39.  
  40. #Totalize mutexes from mutex-statusX files:
  41. f="2017_01_09_10_45_28-mutex-status1";
  42. cat $f |awk -F"=" '{print $1}'|awk '{print $2}'|sort |uniq|egrep -v "Name|combined"|while read k; do {
  43. echo -n $k;
  44. fgrep "$k" $f | awk -F"=" '{ s+=$2 } END { print " --> ", s }';
  45. } done |sort -nrk3
  46. grep "MySQL thread" 2016_04_11_12_06_52-innodbstatus2 |awk '{$1=""; $2=""; $3=""; $4=""; $5=""; $6=""; $7=""; $8=""; $9=""; $10=""; $11=""; $12=""; $13=""; $14=""; print $0}'|sort|uniq -c|sort -nr
  47. #
  48. # Extracts thread state from SHOW ENGINE INNODB STATUS
  49. #
  50. # results:
  51. # 898 sleeping
  52. # 89 statistics
  53. # 70 innobase_commit_low():trx_commit_for_mysql(-1)
  54. # 55 Sending data
  55. # 41 wsrep in pre-commit stage
  56. # 37 update
  57. # 37 Copying to tmp table
  58. # 34
  59. # 3 preparing
  60. # 3 Opening tables
  61. # 3 exit open_tables()
  62. # 1 updating
  63. # 1 removing tmp table
  64. # 1 init
  65. # 1 ha_commit_one_phase(-1)
  66.  
  67.  
  68. grep "\-\-\-TRANSACTION" 2016_04_11_12_06_52-innodbstatus2 |awk '{$1=""; $2=""; $3=""; $4=""; $5=""; print $0 }'|sort |uniq -c |sort -nr
  69. #
  70. # Extract InnoDB thread status
  71. # 998
  72. # 97 index read
  73. # 70 committing
  74. # 55 starting index read
  75. # 35 inserting
  76. # 8 rollback
  77. # 7 fetching rows
  78. # 1 preparing
  79. # 1 estimating records in index range
  80.  
  81. pt-diskstats --group-by=all 2016_11_09_14_44_23-diskstats --device=sda2 |grep -v in_prg |awk '{t+=$11} END {print t/NR}'
  82.  
  83. #This one is pt-query-digest but useful nonetheless: find top 20 queries from report A in report B:
  84. grep -A22 "Profile" report-A|tail -n +3|awk '{print $3}'|while read fingerprint; do { grep $fingerprint report-B|head -n1; } done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement