Merge lp:~percona-toolkit-dev/percona-toolkit/use-mktemp-871438 into lp:~percona-toolkit-dev/percona-toolkit/pt-stalk-2.0
- use-mktemp-871438
- Merge into pt-stalk-2.0
Proposed by
Daniel Nichter
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Daniel Nichter | ||||
Approved revision: | 151 | ||||
Merged at revision: | 185 | ||||
Proposed branch: | lp:~percona-toolkit-dev/percona-toolkit/use-mktemp-871438 | ||||
Merge into: | lp:~percona-toolkit-dev/percona-toolkit/pt-stalk-2.0 | ||||
Diff against target: |
1194 lines (+349/-173) 6 files modified
bin/pt-mext (+44/-1) bin/pt-mysql-summary (+122/-76) bin/pt-sift (+56/-11) bin/pt-summary (+120/-78) t/pt-mysql-summary/get_mysql_info.sh (+3/-3) util/test-bash-functions (+4/-4) |
||||
To merge this branch: | bzr merge lp:~percona-toolkit-dev/percona-toolkit/use-mktemp-871438 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel Nichter | Approve | ||
Review via email:
|
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Daniel Nichter (daniel-nichter) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bin/pt-mext' |
2 | --- bin/pt-mext 2011-09-01 16:00:38 +0000 |
3 | +++ bin/pt-mext 2012-02-01 16:31:24 +0000 |
4 | @@ -17,7 +17,50 @@ |
5 | usage; |
6 | fi |
7 | |
8 | -FILE=/tmp/mext_temp_file; |
9 | +# ########################################################################### |
10 | +# tmpdir package |
11 | +# This package is a copy without comments from the original. The original |
12 | +# with comments and its test file can be found in the Bazaar repository at, |
13 | +# lib/bash/tmpdir.sh |
14 | +# t/lib/bash/tmpdir.sh |
15 | +# See https://launchpad.net/percona-toolkit for more information. |
16 | +# ########################################################################### |
17 | + |
18 | +# pt-mext isn't ready for this yet |
19 | +#set -u |
20 | + |
21 | +TMPDIR="" |
22 | + |
23 | +mk_tmpdir() { |
24 | + local dir=${1:-""} |
25 | + |
26 | + if [ -n "$dir" ]; then |
27 | + if [ ! -d "$dir" ]; then |
28 | + mkdir $dir || die "Cannot make tmpdir $dir" |
29 | + fi |
30 | + TMPDIR="$dir" |
31 | + else |
32 | + local tool=`basename $0` |
33 | + local pid="$$" |
34 | + TMPDIR=`mktemp -d /tmp/${tool}.${pid}.XXXXX` \ |
35 | + || die "Cannot make secure tmpdir" |
36 | + fi |
37 | +} |
38 | + |
39 | +rm_tmpdir() { |
40 | + if [ -n "$TMPDIR" ] && [ -d "$TMPDIR" ]; then |
41 | + rm -rf $TMPDIR |
42 | + fi |
43 | + TMPDIR="" |
44 | +} |
45 | + |
46 | +# ########################################################################### |
47 | +# End tmpdir package |
48 | +# ########################################################################### |
49 | + |
50 | +mk_tmpdir |
51 | + |
52 | +FILE=`mktemp -p $TMPDIR mext_temp_file.XXXXXX`; |
53 | NUM=0; |
54 | REL=0; |
55 | rm -f $FILE*; |
56 | |
57 | === modified file 'bin/pt-mysql-summary' |
58 | --- bin/pt-mysql-summary 2011-09-01 16:00:38 +0000 |
59 | +++ bin/pt-mysql-summary 2012-02-01 16:31:24 +0000 |
60 | @@ -13,6 +13,46 @@ |
61 | exit 1 |
62 | } |
63 | |
64 | +# ########################################################################### |
65 | +# tmpdir package |
66 | +# This package is a copy without comments from the original. The original |
67 | +# with comments and its test file can be found in the Bazaar repository at, |
68 | +# lib/bash/tmpdir.sh |
69 | +# t/lib/bash/tmpdir.sh |
70 | +# See https://launchpad.net/percona-toolkit for more information. |
71 | +# ########################################################################### |
72 | + |
73 | +set -u |
74 | + |
75 | +TMPDIR="" |
76 | + |
77 | +mk_tmpdir() { |
78 | + local dir=${1:-""} |
79 | + |
80 | + if [ -n "$dir" ]; then |
81 | + if [ ! -d "$dir" ]; then |
82 | + mkdir $dir || die "Cannot make tmpdir $dir" |
83 | + fi |
84 | + TMPDIR="$dir" |
85 | + else |
86 | + local tool=`basename $0` |
87 | + local pid="$$" |
88 | + TMPDIR=`mktemp -d /tmp/${tool}.${pid}.XXXXX` \ |
89 | + || die "Cannot make secure tmpdir" |
90 | + fi |
91 | +} |
92 | + |
93 | +rm_tmpdir() { |
94 | + if [ -n "$TMPDIR" ] && [ -d "$TMPDIR" ]; then |
95 | + rm -rf $TMPDIR |
96 | + fi |
97 | + TMPDIR="" |
98 | +} |
99 | + |
100 | +# ########################################################################### |
101 | +# End tmpdir package |
102 | +# ########################################################################### |
103 | + |
104 | # ######################################################################## |
105 | # Some global setup is necessary for cross-platform compatibility, even |
106 | # when sourcing this script for testing purposes. |
107 | @@ -62,9 +102,9 @@ |
108 | # symlink them to /etc/passwd and then run this program as root. Call this |
109 | # function with "rm" or "touch" as an argument. |
110 | temp_files() { |
111 | - for file in /tmp/percona-toolkit{,-mysql-variables,-mysql-status,-innodb-status} \ |
112 | - /tmp/percona-toolkit{2,-mysql-databases,-mysql-processlist,-noncounters} \ |
113 | - /tmp/percona-toolkit-mysql{dump,-slave}; |
114 | + for file in $TMPDIR/percona-toolkit{,-mysql-variables,-mysql-status,-innodb-status} \ |
115 | + $TMPDIR/percona-toolkit{2,-mysql-databases,-mysql-processlist,-noncounters} \ |
116 | + $TMPDIR/percona-toolkit-mysql{dump,-slave}; |
117 | do |
118 | case "$1" in |
119 | touch) |
120 | @@ -127,16 +167,16 @@ |
121 | }' |
122 | } |
123 | |
124 | -# gets a value from /tmp/percona-toolkit-mysql-variables. Returns zero if it doesn't |
125 | +# gets a value from $TMPDIR/percona-toolkit-mysql-variables. Returns zero if it doesn't |
126 | # exist. |
127 | get_var () { |
128 | - v="$($AP_AWK "\$1 ~ /^$1$/ { print \$2 }" /tmp/percona-toolkit-mysql-variables)" |
129 | + v="$($AP_AWK "\$1 ~ /^$1$/ { print \$2 }" $TMPDIR/percona-toolkit-mysql-variables)" |
130 | echo "${v:-0}" |
131 | } |
132 | |
133 | # Returns true if a variable exists |
134 | var_exists () { |
135 | - $AP_GREP "$1" /tmp/percona-toolkit-mysql-variables >/dev/null 2>&1; |
136 | + $AP_GREP "$1" $TMPDIR/percona-toolkit-mysql-variables >/dev/null 2>&1; |
137 | } |
138 | |
139 | # Returns "Enabled", "Disabled", or "Not Supported" depending on whether the |
140 | @@ -145,7 +185,7 @@ |
141 | # (string equal) to some value. |
142 | feat_on() { |
143 | if var_exists $1 ; then |
144 | - var="$($AP_AWK "\$1 ~ /^$1$/ { print \$2 }" /tmp/percona-toolkit-mysql-variables)" |
145 | + var="$($AP_AWK "\$1 ~ /^$1$/ { print \$2 }" $TMPDIR/percona-toolkit-mysql-variables)" |
146 | if [ "${var}" = "ON" ]; then |
147 | echo "Enabled" |
148 | elif [ "${var}" = "OFF" -o "${var}" = "0" -o -z "${var}" ]; then |
149 | @@ -172,10 +212,10 @@ |
150 | fi |
151 | } |
152 | |
153 | -# gets a value from /tmp/percona-toolkit-mysql-status. Returns zero if it doesn't |
154 | +# gets a value from $TMPDIR/percona-toolkit-mysql-status. Returns zero if it doesn't |
155 | # exist. |
156 | get_stat () { |
157 | - v="$($AP_AWK "\$1 ~ /^$1$/ { print \$2 }" /tmp/percona-toolkit-mysql-status)" |
158 | + v="$($AP_AWK "\$1 ~ /^$1$/ { print \$2 }" $TMPDIR/percona-toolkit-mysql-status)" |
159 | echo "${v:-0}" |
160 | } |
161 | |
162 | @@ -195,14 +235,17 @@ |
163 | # Functions for parsing specific files and getting desired info from them. |
164 | # These are called from within main() and are separated so they can be tested |
165 | # easily. The calling convention is that the data they need to run is prepared |
166 | -# first by putting it into /tmp/percona-toolkit. Then code that's testing just needs to |
167 | -# put sample data into /tmp/percona-toolkit and call it. |
168 | +# first by putting it into $TMPDIR/percona-toolkit. Then code that's testing |
169 | +# just needs to put sample data into $TMPDIR/percona-toolkit and call it. |
170 | # ############################################################################## |
171 | |
172 | # Parses the output of 'ps -e -o args | $AP_GREP mysqld' or 'ps auxww...' |
173 | -# which should be in /tmp/percona-toolkit. |
174 | +# which should be in $TMPDIR/percona-toolkit. |
175 | parse_mysqld_instances () { |
176 | local file=$1 |
177 | + local socket=${socket:-""} |
178 | + local port=${port:-""} |
179 | + local datadir=${datadir:-""} |
180 | echo " Port Data Directory Socket" |
181 | echo " ===== ========================== ======" |
182 | $AP_GREP '/mysqld ' $file | while read line; do |
183 | @@ -224,11 +267,11 @@ |
184 | } |
185 | |
186 | # Tries to find the my.cnf file by examining 'ps' output, which should be in |
187 | -# /tmp/percona-toolkit. You have to specify the port for the instance you are |
188 | +# $TMPDIR/percona-toolkit. You have to specify the port for the instance you are |
189 | # interested in, in case there are multiple instances. |
190 | find_my_cnf_file() { |
191 | local file=$1 |
192 | - local port=$2 |
193 | + local port=${2:-""} |
194 | if test -n "$port" && $AP_GREP -- "/mysqld.*--port=$port" $file >/dev/null 2>&1 ; then |
195 | $AP_GREP -- "/mysqld.*--port=$port" $file \ |
196 | | $AP_AWK 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }' \ |
197 | @@ -240,7 +283,7 @@ |
198 | fi |
199 | } |
200 | |
201 | -# Gets the MySQL system time. Uses input from /tmp/percona-toolkit-mysql-variables. |
202 | +# Gets the MySQL system time. Uses input from $TMPDIR/percona-toolkit-mysql-variables. |
203 | get_mysql_timezone () { |
204 | tz="$(get_var time_zone)" |
205 | if [ "${tz}" = "SYSTEM" ]; then |
206 | @@ -249,14 +292,14 @@ |
207 | echo "${tz}" |
208 | } |
209 | |
210 | -# Gets the MySQL system version. Uses input from /tmp/percona-toolkit-mysql-variables. |
211 | +# Gets the MySQL system version. Uses input from $TMPDIR/percona-toolkit-mysql-variables. |
212 | get_mysql_version () { |
213 | name_val Version "$(get_var version) $(get_var version_comment)" |
214 | name_val "Built On" "$(get_var version_compile_os) $(get_var version_compile_machine)" |
215 | } |
216 | |
217 | # Gets the system start and uptime in human readable format. Last restart date |
218 | -# should be in /tmp/percona-toolkit. |
219 | +# should be in $TMPDIR/percona-toolkit. |
220 | get_mysql_uptime () { |
221 | local file=$1 |
222 | restart="$(cat $file)" |
223 | @@ -265,7 +308,7 @@ |
224 | echo "${restart} (up ${uptime})" |
225 | } |
226 | |
227 | -# Summarizes the output of SHOW MASTER LOGS, which is in /tmp/percona-toolkit |
228 | +# Summarizes the output of SHOW MASTER LOGS, which is in $TMPDIR/percona-toolkit |
229 | summarize_binlogs () { |
230 | local file=$1 |
231 | name_val "Binlogs" $(wc -l $file) |
232 | @@ -282,7 +325,7 @@ |
233 | } |
234 | |
235 | # Takes as input a file that has two samples of SHOW STATUS, columnized next to |
236 | -# each other. These should be in /tmp/percona-toolkit. Outputs fuzzy-ed numbers: |
237 | +# each other. These should be in $TMPDIR/percona-toolkit. Outputs fuzzy-ed numbers: |
238 | # absolute, all-time per second, and per-second over the interval between the |
239 | # samples. Omits any rows that are all zeroes. |
240 | format_status_variables () { |
241 | @@ -387,7 +430,7 @@ |
242 | echo |
243 | } |
244 | |
245 | -# Pretty-prints the my.cnf file, which should be in /tmp/percona-toolkit. It's super |
246 | +# Pretty-prints the my.cnf file, which should be in $TMPDIR/percona-toolkit. It's super |
247 | # annoying, but some *modern* versions of awk don't support POSIX character |
248 | # sets in regular expressions, like [[:space:]] (looking at you, Debian). So |
249 | # the below patterns contain [<space><tab>] and must remain that way. |
250 | @@ -545,8 +588,8 @@ |
251 | name_val "Pending I/O Writes" "$(find_pending_io_writes "${file}")" |
252 | name_val "Pending I/O Flushes" "$(find_pending_io_flushes "${file}")" |
253 | $AP_AWK -F, '/^---TRANSACTION/{print $2}' "${file}" \ |
254 | - | $AP_SED -e 's/ [0-9]* sec.*//' | sort | uniq -c > /tmp/percona-toolkit2 |
255 | - name_val "Transaction States" "$(group_concat /tmp/percona-toolkit2)" |
256 | + | $AP_SED -e 's/ [0-9]* sec.*//' | sort | uniq -c > $TMPDIR/percona-toolkit2 |
257 | + name_val "Transaction States" "$(group_concat $TMPDIR/percona-toolkit2)" |
258 | if $AP_GREP 'TABLE LOCK table' "${file}" >/dev/null ; then |
259 | echo "Tables Locked" |
260 | $AP_AWK '/^TABLE LOCK table/{print $4}' "${file}" \ |
261 | @@ -633,9 +676,9 @@ |
262 | printf fmt, db, counts[db ",tables"], counts[db ",views"], counts[db ",sps"], counts[db ",trg"], counts[db ",func"], counts[db ",fk"], counts[db ",partn"]; |
263 | } |
264 | } |
265 | - ' $file > /tmp/percona-toolkit |
266 | - head -n2 /tmp/percona-toolkit |
267 | - tail -n +3 /tmp/percona-toolkit | sort |
268 | + ' $file > $TMPDIR/percona-toolkit |
269 | + head -n2 $TMPDIR/percona-toolkit |
270 | + tail -n +3 $TMPDIR/percona-toolkit | sort |
271 | |
272 | echo |
273 | # Now do the summary of engines per DB |
274 | @@ -693,9 +736,9 @@ |
275 | print ""; |
276 | } |
277 | } |
278 | - ' $file > /tmp/percona-toolkit |
279 | - head -n1 /tmp/percona-toolkit |
280 | - tail -n +2 /tmp/percona-toolkit | sort |
281 | + ' $file > $TMPDIR/percona-toolkit |
282 | + head -n1 $TMPDIR/percona-toolkit |
283 | + tail -n +2 $TMPDIR/percona-toolkit | sort |
284 | |
285 | echo |
286 | # Now do the summary of index types per DB. Careful -- index is a reserved |
287 | @@ -766,9 +809,9 @@ |
288 | print ""; |
289 | } |
290 | } |
291 | - ' $file > /tmp/percona-toolkit |
292 | - head -n1 /tmp/percona-toolkit |
293 | - tail -n +2 /tmp/percona-toolkit | sort |
294 | + ' $file > $TMPDIR/percona-toolkit |
295 | + head -n1 $TMPDIR/percona-toolkit |
296 | + tail -n +2 $TMPDIR/percona-toolkit | sort |
297 | |
298 | echo |
299 | # Now do the summary of datatypes per DB |
300 | @@ -857,10 +900,10 @@ |
301 | print ""; |
302 | } |
303 | } |
304 | - ' $file > /tmp/percona-toolkit |
305 | - hdr=$($AP_GREP -n Database /tmp/percona-toolkit | cut -d: -f1); |
306 | - head -n${hdr} /tmp/percona-toolkit |
307 | - tail -n +$((${hdr} + 1)) /tmp/percona-toolkit | sort |
308 | + ' $file > $TMPDIR/percona-toolkit |
309 | + hdr=$($AP_GREP -n Database $TMPDIR/percona-toolkit | cut -d: -f1); |
310 | + head -n${hdr} $TMPDIR/percona-toolkit |
311 | + tail -n +$((${hdr} + 1)) $TMPDIR/percona-toolkit | sort |
312 | echo |
313 | } |
314 | |
315 | @@ -878,6 +921,7 @@ |
316 | export PATH="/usr/gnu/bin/:/usr/xpg4/bin/:${PATH}" |
317 | |
318 | # Set up temporary files. |
319 | + mk_tmpdir |
320 | temp_files "rm" |
321 | temp_files "touch" |
322 | |
323 | @@ -887,25 +931,26 @@ |
324 | section Percona_Toolkit_MySQL_Summary_Report |
325 | name_val "System time" "`date -u +'%F %T UTC'` (local TZ: `date +'%Z %z'`)" |
326 | section Instances |
327 | - ps auxww 2>/dev/null | $AP_GREP mysqld > /tmp/percona-toolkit |
328 | - parse_mysqld_instances /tmp/percona-toolkit |
329 | + ps auxww 2>/dev/null | $AP_GREP mysqld > $TMPDIR/percona-toolkit |
330 | + parse_mysqld_instances $TMPDIR/percona-toolkit |
331 | |
332 | # ######################################################################## |
333 | # Fetch some basic info so we can start |
334 | # ######################################################################## |
335 | - mysql "$@" -ss -e 'SELECT CURRENT_USER()' > /tmp/percona-toolkit |
336 | + mysql "$@" -ss -e 'SELECT CURRENT_USER()' > $TMPDIR/percona-toolkit |
337 | if [ "$?" != "0" ]; then |
338 | echo "Cannot connect to mysql, please specify command-line options." |
339 | temp_files "rm" |
340 | + rm_tmpdir |
341 | exit 1 |
342 | fi |
343 | - user="$(cat /tmp/percona-toolkit)"; |
344 | - mysql "$@" -ss -e 'SHOW /*!40100 GLOBAL*/ VARIABLES' > /tmp/percona-toolkit-mysql-variables |
345 | - mysql "$@" -ss -e 'SHOW /*!50000 GLOBAL*/ STATUS' > /tmp/percona-toolkit-mysql-status |
346 | - mysql "$@" -ss -e 'SHOW DATABASES' > /tmp/percona-toolkit-mysql-databases 2>/dev/null |
347 | - mysql "$@" -ssE -e 'SHOW SLAVE STATUS' > /tmp/percona-toolkit-mysql-slave 2>/dev/null |
348 | - mysql "$@" -ssE -e 'SHOW /*!50000 ENGINE*/ INNODB STATUS' > /tmp/percona-toolkit-innodb-status 2>/dev/null |
349 | - mysql "$@" -ssE -e 'SHOW FULL PROCESSLIST' > /tmp/percona-toolkit-mysql-processlist 2>/dev/null |
350 | + user="$(cat $TMPDIR/percona-toolkit)"; |
351 | + mysql "$@" -ss -e 'SHOW /*!40100 GLOBAL*/ VARIABLES' > $TMPDIR/percona-toolkit-mysql-variables |
352 | + mysql "$@" -ss -e 'SHOW /*!50000 GLOBAL*/ STATUS' > $TMPDIR/percona-toolkit-mysql-status |
353 | + mysql "$@" -ss -e 'SHOW DATABASES' > $TMPDIR/percona-toolkit-mysql-databases 2>/dev/null |
354 | + mysql "$@" -ssE -e 'SHOW SLAVE STATUS' > $TMPDIR/percona-toolkit-mysql-slave 2>/dev/null |
355 | + mysql "$@" -ssE -e 'SHOW /*!50000 ENGINE*/ INNODB STATUS' > $TMPDIR/percona-toolkit-innodb-status 2>/dev/null |
356 | + mysql "$@" -ssE -e 'SHOW FULL PROCESSLIST' > $TMPDIR/percona-toolkit-mysql-processlist 2>/dev/null |
357 | now="$(mysql "$@" -ss -e 'SELECT NOW()')" |
358 | port="$(get_var port)" |
359 | |
360 | @@ -920,16 +965,16 @@ |
361 | |
362 | uptime="$(get_stat Uptime)" |
363 | mysql "$@" -ss -e "SELECT LEFT(NOW() - INTERVAL ${uptime} SECOND, 16)" \ |
364 | - > /tmp/percona-toolkit |
365 | - name_val Started "$(get_mysql_uptime /tmp/percona-toolkit)" |
366 | + > $TMPDIR/percona-toolkit |
367 | + name_val Started "$(get_mysql_uptime $TMPDIR/percona-toolkit)" |
368 | |
369 | - name_val Databases "$($AP_GREP -c . /tmp/percona-toolkit-mysql-databases)" |
370 | + name_val Databases "$($AP_GREP -c . $TMPDIR/percona-toolkit-mysql-databases)" |
371 | name_val Datadir "$(get_var datadir)" |
372 | procs="$(get_stat Threads_connected)" |
373 | procr="$(get_stat Threads_running)" |
374 | name_val Processes "$(fuzz ${procs}) connected, $(fuzz ${procr}) running" |
375 | - if [ -s /tmp/percona-toolkit-mysql-slave ]; then slave=""; else slave="not "; fi |
376 | - slavecount=$($AP_GREP -c 'Binlog Dump' /tmp/percona-toolkit-mysql-processlist) |
377 | + if [ -s $TMPDIR/percona-toolkit-mysql-slave ]; then slave=""; else slave="not "; fi |
378 | + slavecount=$($AP_GREP -c 'Binlog Dump' $TMPDIR/percona-toolkit-mysql-processlist) |
379 | name_val Replication "Is ${slave}a slave, has ${slavecount} slaves connected" |
380 | |
381 | # TODO move this into a section with other files: error log, slow log and |
382 | @@ -942,7 +987,7 @@ |
383 | # Processlist, sliced several different ways |
384 | # ######################################################################## |
385 | section Processlist |
386 | - summarize_processlist /tmp/percona-toolkit-mysql-processlist |
387 | + summarize_processlist $TMPDIR/percona-toolkit-mysql-processlist |
388 | |
389 | # ######################################################################## |
390 | # Queries and query plans |
391 | @@ -951,7 +996,7 @@ |
392 | sleep 10 |
393 | # TODO: gather this data in the same format as normal: stats, TS line |
394 | mysql "$@" -ss -e 'SHOW /*!50000 GLOBAL*/ STATUS' \ |
395 | - | join /tmp/percona-toolkit-mysql-status - > /tmp/percona-toolkit |
396 | + | join $TMPDIR/percona-toolkit-mysql-status - > $TMPDIR/percona-toolkit |
397 | # Make a file with a list of things we want to omit because they aren't |
398 | # counters, they are gauges (in RRDTool terminology). Gauges are shown |
399 | # elsewhere in the output. |
400 | @@ -975,9 +1020,9 @@ |
401 | Threads_cached Threads_connected Threads_running \ |
402 | Uptime_since_flush_status; |
403 | do |
404 | - echo "${var}" >> /tmp/percona-toolkit-noncounters |
405 | + echo "${var}" >> $TMPDIR/percona-toolkit-noncounters |
406 | done |
407 | - format_status_variables /tmp/percona-toolkit | $AP_GREP -v -f /tmp/percona-toolkit-noncounters |
408 | + format_status_variables $TMPDIR/percona-toolkit | $AP_GREP -v -f $TMPDIR/percona-toolkit-noncounters |
409 | |
410 | # ######################################################################## |
411 | # Table cache |
412 | @@ -1054,22 +1099,22 @@ |
413 | trg_arg="${trg_arg} ${triggers}"; |
414 | fi |
415 | # Find out which databases to dump |
416 | - num_dbs="$($AP_GREP -c . /tmp/percona-toolkit-mysql-databases)" |
417 | + num_dbs="$($AP_GREP -c . $TMPDIR/percona-toolkit-mysql-databases)" |
418 | echo "There are ${num_dbs} databases. Would you like to dump all, or just one?" |
419 | echo -n "Type the name of the database, or press Enter to dump all of them. " |
420 | read dbtodump |
421 | mysqldump "$@" --no-data --skip-comments \ |
422 | --skip-add-locks --skip-add-drop-table --compact \ |
423 | --skip-lock-all-tables --skip-lock-tables --skip-set-charset \ |
424 | - ${trg_arg} ${dbtodump:---all-databases} > /tmp/percona-toolkit-mysqldump |
425 | + ${trg_arg} ${dbtodump:---all-databases} > $TMPDIR/percona-toolkit-mysqldump |
426 | # Test the result by checking the file, not by the exit status, because we |
427 | # might get partway through and then die, and the info is worth analyzing |
428 | # anyway. |
429 | - if $AP_GREP 'CREATE TABLE' /tmp/percona-toolkit-mysqldump >/dev/null 2>&1; then |
430 | - format_overall_db_stats /tmp/percona-toolkit-mysqldump |
431 | + if $AP_GREP 'CREATE TABLE' $TMPDIR/percona-toolkit-mysqldump >/dev/null 2>&1; then |
432 | + format_overall_db_stats $TMPDIR/percona-toolkit-mysqldump |
433 | else |
434 | echo "Skipping schema analysis due to apparent error in dump file" |
435 | - rm -f /tmp/percona-toolkit-mysqldump |
436 | + rm -f $TMPDIR/percona-toolkit-mysqldump |
437 | fi |
438 | else |
439 | echo "Skipping schema analysis" |
440 | @@ -1079,23 +1124,23 @@ |
441 | # Noteworthy Technologies |
442 | # ######################################################################## |
443 | section Noteworthy_Technologies |
444 | - if [ -e /tmp/percona-toolkit-mysqldump ]; then |
445 | - if $AP_GREP FULLTEXT /tmp/percona-toolkit-mysqldump > /dev/null; then |
446 | + if [ -e $TMPDIR/percona-toolkit-mysqldump ]; then |
447 | + if $AP_GREP FULLTEXT $TMPDIR/percona-toolkit-mysqldump > /dev/null; then |
448 | name_val "Full Text Indexing" Yes |
449 | else |
450 | name_val "Full Text Indexing" No |
451 | fi |
452 | - if $AP_GREP 'GEOMETRY\|POINT\|LINESTRING\|POLYGON' /tmp/percona-toolkit-mysqldump > /dev/null; then |
453 | + if $AP_GREP 'GEOMETRY\|POINT\|LINESTRING\|POLYGON' $TMPDIR/percona-toolkit-mysqldump > /dev/null; then |
454 | name_val "Geospatial Types" Yes |
455 | else |
456 | name_val "Geospatial Types" No |
457 | fi |
458 | - if $AP_GREP 'FOREIGN KEY' /tmp/percona-toolkit-mysqldump > /dev/null; then |
459 | + if $AP_GREP 'FOREIGN KEY' $TMPDIR/percona-toolkit-mysqldump > /dev/null; then |
460 | name_val "Foreign Keys" Yes |
461 | else |
462 | name_val "Foreign Keys" No |
463 | fi |
464 | - if $AP_GREP 'PARTITION BY' /tmp/percona-toolkit-mysqldump > /dev/null; then |
465 | + if $AP_GREP 'PARTITION BY' $TMPDIR/percona-toolkit-mysqldump > /dev/null; then |
466 | name_val "Partitioning" Yes |
467 | else |
468 | name_val "Partitioning" No |
469 | @@ -1175,8 +1220,8 @@ |
470 | name_val "Adaptive Flushing" $(get_var innodb_adaptive_flushing) |
471 | name_val "Adaptive Checkpoint" $(get_var innodb_adaptive_checkpoint) |
472 | |
473 | - if [ -s /tmp/percona-toolkit-innodb-status ]; then |
474 | - format_innodb_status /tmp/percona-toolkit-innodb-status |
475 | + if [ -s $TMPDIR/percona-toolkit-innodb-status ]; then |
476 | + format_innodb_status $TMPDIR/percona-toolkit-innodb-status |
477 | fi |
478 | fi |
479 | |
480 | @@ -1211,15 +1256,15 @@ |
481 | section Binary_Logging |
482 | binlog=$(get_var log_bin) |
483 | if [ "${binlog}" ]; then |
484 | - mysql "$@" -ss -e 'SHOW MASTER LOGS' > /tmp/percona-toolkit 2>/dev/null |
485 | - summarize_binlogs /tmp/percona-toolkit |
486 | + mysql "$@" -ss -e 'SHOW MASTER LOGS' > $TMPDIR/percona-toolkit 2>/dev/null |
487 | + summarize_binlogs $TMPDIR/percona-toolkit |
488 | format="$(get_var binlog_format)" |
489 | name_val binlog_format "${format:-STATEMENT}" |
490 | name_val expire_logs_days $(get_var expire_logs_days) |
491 | name_val sync_binlog $(get_var sync_binlog) |
492 | name_val server_id $(get_var server_id) |
493 | - mysql "$@" -ss -e 'SHOW MASTER STATUS' > /tmp/percona-toolkit 2>/dev/null |
494 | - format_binlog_filters /tmp/percona-toolkit |
495 | + mysql "$@" -ss -e 'SHOW MASTER STATUS' > $TMPDIR/percona-toolkit 2>/dev/null |
496 | + format_binlog_filters $TMPDIR/percona-toolkit |
497 | fi |
498 | |
499 | # Replication: seconds behind, running, filters, skip_slave_start, skip_errors, |
500 | @@ -1252,8 +1297,8 @@ |
501 | # If there is a my.cnf in a standard location, see if we can pretty-print it. |
502 | # ######################################################################## |
503 | section Configuration_File |
504 | - ps auxww 2>/dev/null | $AP_GREP mysqld > /tmp/percona-toolkit |
505 | - cnf_file=$(find_my_cnf_file /tmp/percona-toolkit ${port}); |
506 | + ps auxww 2>/dev/null | $AP_GREP mysqld > $TMPDIR/percona-toolkit |
507 | + cnf_file=$(find_my_cnf_file $TMPDIR/percona-toolkit ${port}); |
508 | if [ ! -e "${cnf_file}" ]; then |
509 | name_val "Config File" "Cannot autodetect, trying common locations" |
510 | cnf_file="/etc/my.cnf"; |
511 | @@ -1266,13 +1311,14 @@ |
512 | fi |
513 | if [ -e "${cnf_file}" ]; then |
514 | name_val "Config File" "${cnf_file}" |
515 | - cat "${cnf_file}" > /tmp/percona-toolkit |
516 | - pretty_print_cnf_file /tmp/percona-toolkit |
517 | + cat "${cnf_file}" > $TMPDIR/percona-toolkit |
518 | + pretty_print_cnf_file $TMPDIR/percona-toolkit |
519 | else |
520 | name_val "Config File" "Cannot autodetect or find, giving up" |
521 | fi |
522 | |
523 | temp_files "rm" |
524 | + rm_tmpdir |
525 | |
526 | # Make sure that we signal the end of the tool's output. |
527 | section The_End |
528 | @@ -1325,8 +1371,8 @@ |
529 | |
530 | pt-mysql-summary works by connecting to a MySQL database server and querying |
531 | it for status and configuration information. It saves these bits of data |
532 | -into files in /tmp, and then formats them neatly with awk and other scripting |
533 | -languages. |
534 | +into files in a temporary directory, and then formats them neatly with awk |
535 | +and other scripting languages. |
536 | |
537 | To use, simply execute it. Optionally add the same command-line options |
538 | you would use to connect to MySQL, like C<pt-mysql-summary --user=foo>. |
539 | |
540 | === modified file 'bin/pt-sift' |
541 | --- bin/pt-sift 2011-09-01 16:00:38 +0000 |
542 | +++ bin/pt-sift 2012-02-01 16:31:24 +0000 |
543 | @@ -13,6 +13,47 @@ |
544 | exit 1 |
545 | } |
546 | |
547 | +# ########################################################################### |
548 | +# tmpdir package |
549 | +# This package is a copy without comments from the original. The original |
550 | +# with comments and its test file can be found in the Bazaar repository at, |
551 | +# lib/bash/tmpdir.sh |
552 | +# t/lib/bash/tmpdir.sh |
553 | +# See https://launchpad.net/percona-toolkit for more information. |
554 | +# ########################################################################### |
555 | + |
556 | +# pt-sift isn't ready for this yet. |
557 | +#set -u |
558 | + |
559 | +TMPDIR="" |
560 | + |
561 | +mk_tmpdir() { |
562 | + local dir=${1:-""} |
563 | + |
564 | + if [ -n "$dir" ]; then |
565 | + if [ ! -d "$dir" ]; then |
566 | + mkdir $dir || die "Cannot make tmpdir $dir" |
567 | + fi |
568 | + TMPDIR="$dir" |
569 | + else |
570 | + local tool=`basename $0` |
571 | + local pid="$$" |
572 | + TMPDIR=`mktemp -d /tmp/${tool}.${pid}.XXXXX` \ |
573 | + || die "Cannot make secure tmpdir" |
574 | + fi |
575 | +} |
576 | + |
577 | +rm_tmpdir() { |
578 | + if [ -n "$TMPDIR" ] && [ -d "$TMPDIR" ]; then |
579 | + rm -rf $TMPDIR |
580 | + fi |
581 | + TMPDIR="" |
582 | +} |
583 | + |
584 | +# ########################################################################### |
585 | +# End tmpdir package |
586 | +# ########################################################################### |
587 | + |
588 | # Show current help and settings |
589 | print_help() { |
590 | cat <<-HELP |
591 | @@ -89,19 +130,22 @@ |
592 | fi |
593 | done |
594 | |
595 | + # Make a secure tmpdir. |
596 | + mk_tmpdir |
597 | + |
598 | # We need to generate a list of timestamps, and ask the user to choose one if |
599 | # there is no PREFIX yet. NOTE: we rely on the "-df" files here. |
600 | - ls "${BASEDIR}" | grep -- '-df$' | cut -d- -f1 | sort > /tmp/pt-sift.prefixes |
601 | + ls "${BASEDIR}" | grep -- '-df$' | cut -d- -f1 | sort > $TMPDIR/pt-sift.prefixes |
602 | if [ -z "${PREFIX}" ]; then |
603 | - if [ "$(grep -c . /tmp/pt-sift.prefixes)" = "1" ]; then |
604 | + if [ "$(grep -c . $TMPDIR/pt-sift.prefixes)" = "1" ]; then |
605 | # If there is only one sample, we use it as the prefix. |
606 | - PREFIX="$(cat /tmp/pt-sift.prefixes)" |
607 | + PREFIX="$(cat $TMPDIR/pt-sift.prefixes)" |
608 | fi |
609 | fi |
610 | if [ -z "${PREFIX}" ]; then |
611 | echo |
612 | i=0 |
613 | - cat /tmp/pt-sift.prefixes | while read line; do |
614 | + cat $TMPDIR/pt-sift.prefixes | while read line; do |
615 | i=$(($i + 1)) |
616 | echo -n " $line" |
617 | if [ "${i}" = "3" ]; then |
618 | @@ -111,14 +155,14 @@ |
619 | done |
620 | # We might have ended mid-line or we might have printed a newline; print a |
621 | # newline if required to end the list of timestamp prefixes. |
622 | - awk 'BEGIN { i = 0 } { i++ } END { if ( i % 3 != 0 ) { print "" } }' /tmp/pt-sift.prefixes |
623 | + awk 'BEGIN { i = 0 } { i++ } END { if ( i % 3 != 0 ) { print "" } }' $TMPDIR/pt-sift.prefixes |
624 | echo |
625 | - while [ -z "${PREFIX}" -o "$(grep -c "${PREFIX}" /tmp/pt-sift.prefixes)" -ne 1 ]; do |
626 | - DEFAULT="$(tail -1 /tmp/pt-sift.prefixes)" |
627 | + while [ -z "${PREFIX}" -o "$(grep -c "${PREFIX}" $TMPDIR/pt-sift.prefixes)" -ne 1 ]; do |
628 | + DEFAULT="$(tail -1 $TMPDIR/pt-sift.prefixes)" |
629 | read -e -p "Select a timestamp from the list [${DEFAULT}] " ARG |
630 | ARG="${ARG:-${DEFAULT}}" |
631 | - if [ "$(grep -c "${ARG}" /tmp/pt-sift.prefixes)" -eq 1 ]; then |
632 | - PREFIX="$(grep "${ARG}" /tmp/pt-sift.prefixes)" |
633 | + if [ "$(grep -c "${ARG}" $TMPDIR/pt-sift.prefixes)" -eq 1 ]; then |
634 | + PREFIX="$(grep "${ARG}" $TMPDIR/pt-sift.prefixes)" |
635 | fi |
636 | done |
637 | fi |
638 | @@ -130,7 +174,7 @@ |
639 | if [ "${ACTION}" != "INVALID" ]; then |
640 | # Print the current host, timestamp and action. Figure out if we're at |
641 | # the first or last sample, to make it easy to navigate. |
642 | - PAGE="$(awk "/./{i++} /${PREFIX}/{c=i} END{print c, \"of\", i}" /tmp/pt-sift.prefixes)" |
643 | + PAGE="$(awk "/./{i++} /${PREFIX}/{c=i} END{print c, \"of\", i}" $TMPDIR/pt-sift.prefixes)" |
644 | HOST="$(cat "${BASEDIR}/${PREFIX}-hostname" 2>/dev/null)" |
645 | echo -e "======== ${HOST:-unknown} at \033[34m${PREFIX} \033[31m${ACTION}\033[0m (${PAGE}) ========" |
646 | fi |
647 | @@ -438,7 +482,7 @@ |
648 | if ( printed == 0 ) { |
649 | print \"${PREFIX}\"; |
650 | } |
651 | - }" /tmp/pt-sift.prefixes)" |
652 | + }" $TMPDIR/pt-sift.prefixes)" |
653 | ;; |
654 | 1) |
655 | ACTION="DEFAULT" |
656 | @@ -475,6 +519,7 @@ |
657 | esac |
658 | done |
659 | |
660 | + rm_tmpdir |
661 | } |
662 | |
663 | # Execute the program if it was not included from another file. This makes it |
664 | |
665 | === modified file 'bin/pt-summary' |
666 | --- bin/pt-summary 2011-09-01 16:00:38 +0000 |
667 | +++ bin/pt-summary 2012-02-01 16:31:24 +0000 |
668 | @@ -44,13 +44,53 @@ |
669 | echo $1 | $AP_AWK "{fuzzy_var=\$1; ${fuzzy_formula} print fuzzy_var;}" |
670 | } |
671 | |
672 | +# ########################################################################### |
673 | +# tmpdir package |
674 | +# This package is a copy without comments from the original. The original |
675 | +# with comments and its test file can be found in the Bazaar repository at, |
676 | +# lib/bash/tmpdir.sh |
677 | +# t/lib/bash/tmpdir.sh |
678 | +# See https://launchpad.net/percona-toolkit for more information. |
679 | +# ########################################################################### |
680 | + |
681 | +set -u |
682 | + |
683 | +TMPDIR="" |
684 | + |
685 | +mk_tmpdir() { |
686 | + local dir=${1:-""} |
687 | + |
688 | + if [ -n "$dir" ]; then |
689 | + if [ ! -d "$dir" ]; then |
690 | + mkdir $dir || die "Cannot make tmpdir $dir" |
691 | + fi |
692 | + TMPDIR="$dir" |
693 | + else |
694 | + local tool=`basename $0` |
695 | + local pid="$$" |
696 | + TMPDIR=`mktemp -d /tmp/${tool}.${pid}.XXXXX` \ |
697 | + || die "Cannot make secure tmpdir" |
698 | + fi |
699 | +} |
700 | + |
701 | +rm_tmpdir() { |
702 | + if [ -n "$TMPDIR" ] && [ -d "$TMPDIR" ]; then |
703 | + rm -rf $TMPDIR |
704 | + fi |
705 | + TMPDIR="" |
706 | +} |
707 | + |
708 | +# ########################################################################### |
709 | +# End tmpdir package |
710 | +# ########################################################################### |
711 | + |
712 | # The temp files are for storing working results so we don't call commands many |
713 | # times (gives inconsistent results, maybe adds load on things I don't want to |
714 | # such as RAID controllers). They must not exist -- if they did, someone would |
715 | # symlink them to /etc/passwd and then run this program as root. Call this |
716 | # function with "rm" or "touch" as an argument. |
717 | temp_files() { |
718 | - for file in /tmp/percona-toolkit /tmp/percona-toolkit2; do |
719 | + for file in $TMPDIR/percona-toolkit $TMPDIR/percona-toolkit2; do |
720 | case "$1" in |
721 | touch) |
722 | if ! touch "${file}"; then |
723 | @@ -128,12 +168,12 @@ |
724 | # Functions for parsing specific files and getting desired info from them. |
725 | # These are called from within main() and are separated so they can be tested |
726 | # easily. The calling convention is that the data they need to run is prepared |
727 | -# first by putting it into /tmp/percona-toolkit. Then code that's testing just needs to |
728 | -# put sample data into /tmp/percona-toolkit and call it. |
729 | +# first by putting it into $TMPDIR/percona-toolkit. Then code that's testing |
730 | +# just needs to put sample data into $TMPDIR/percona-toolkit and call it. |
731 | # ############################################################################## |
732 | |
733 | # ############################################################################## |
734 | -# Parse Linux's /proc/cpuinfo, which should be stored in /tmp/percona-toolkit. |
735 | +# Parse Linux's /proc/cpuinfo, which should be stored in $TMPDIR/percona-toolkit. |
736 | # ############################################################################## |
737 | parse_proc_cpuinfo () { |
738 | local file=$1 |
739 | @@ -189,8 +229,8 @@ |
740 | start = index($0, " at ") + 4; |
741 | end = length($0) - start - 4 |
742 | print substr($0, start, end); |
743 | - }' "$1" | sort | uniq -c > /tmp/percona-toolkit2 |
744 | - name_val "Speeds" "$(group_concat /tmp/percona-toolkit2)" |
745 | + }' "$1" | sort | uniq -c > $TMPDIR/percona-toolkit2 |
746 | + name_val "Speeds" "$(group_concat $TMPDIR/percona-toolkit2)" |
747 | } |
748 | |
749 | # ############################################################################## |
750 | @@ -292,7 +332,7 @@ |
751 | } |
752 | |
753 | # ############################################################################## |
754 | -# Parse the output of 'netstat -antp' which should be in /tmp/percona-toolkit. |
755 | +# Parse the output of 'netstat -antp' which should be in $TMPDIR/percona-toolkit. |
756 | # ############################################################################## |
757 | parse_netstat () { |
758 | local file=$1 |
759 | @@ -397,7 +437,7 @@ |
760 | } |
761 | |
762 | # ############################################################################## |
763 | -# Parse the output of fdisk -l, which should be in /tmp/percona-toolkit; there might be |
764 | +# Parse the output of fdisk -l, which should be in $TMPDIR/percona-toolkit; there might be |
765 | # multiple fdisk -l outputs in the file. |
766 | # ############################################################################## |
767 | parse_fdisk () { |
768 | @@ -431,7 +471,7 @@ |
769 | } |
770 | |
771 | # ############################################################################## |
772 | -# Parse the output of dmesg, which should be in /tmp/percona-toolkit, and detect |
773 | +# Parse the output of dmesg, which should be in $TMPDIR/percona-toolkit, and detect |
774 | # virtualization. |
775 | # ############################################################################## |
776 | parse_virtualization_dmesg () { |
777 | @@ -463,7 +503,7 @@ |
778 | } |
779 | |
780 | # ############################################################################## |
781 | -# Parse the output of lspci, which should be in /tmp/percona-toolkit, and detect |
782 | +# Parse the output of lspci, which should be in $TMPDIR/percona-toolkit, and detect |
783 | # Ethernet cards. |
784 | # ############################################################################## |
785 | parse_ethernet_controller_lspci () { |
786 | @@ -474,7 +514,7 @@ |
787 | } |
788 | |
789 | # ############################################################################## |
790 | -# Parse the output of lspci, which should be in /tmp/percona-toolkit, and detect RAID |
791 | +# Parse the output of lspci, which should be in $TMPDIR/percona-toolkit, and detect RAID |
792 | # controllers. |
793 | # ############################################################################## |
794 | parse_raid_controller_lspci () { |
795 | @@ -497,7 +537,7 @@ |
796 | } |
797 | |
798 | # ############################################################################## |
799 | -# Parse the output of dmesg, which should be in /tmp/percona-toolkit, and detect RAID |
800 | +# Parse the output of dmesg, which should be in $TMPDIR/percona-toolkit, and detect RAID |
801 | # controllers. |
802 | # ############################################################################## |
803 | parse_raid_controller_dmesg () { |
804 | @@ -516,7 +556,7 @@ |
805 | |
806 | # ############################################################################## |
807 | # Parse the output of "hpacucli ctrl all show config", which should be stored in |
808 | -# /tmp/percona-toolkit |
809 | +# $TMPDIR/percona-toolkit |
810 | # ############################################################################## |
811 | parse_hpacucli () { |
812 | local file=$1 |
813 | @@ -524,7 +564,7 @@ |
814 | } |
815 | |
816 | # ############################################################################## |
817 | -# Parse the output of arcconf, which should be stored in /tmp/percona-toolkit |
818 | +# Parse the output of arcconf, which should be stored in $TMPDIR/percona-toolkit |
819 | # ############################################################################## |
820 | parse_arcconf () { |
821 | local file=$1 |
822 | @@ -634,7 +674,7 @@ |
823 | } |
824 | |
825 | # ############################################################################## |
826 | -# Parse the output of MegaCli64 -AdpAllInfo -aALL from /tmp/percona-toolkit. |
827 | +# Parse the output of MegaCli64 -AdpAllInfo -aALL from $TMPDIR/percona-toolkit. |
828 | # ############################################################################## |
829 | parse_lsi_megaraid_adapter_info () { |
830 | local file=$1 |
831 | @@ -653,7 +693,7 @@ |
832 | } |
833 | |
834 | # ############################################################################## |
835 | -# Parse the output (saved in /tmp/percona-toolkit) of |
836 | +# Parse the output (saved in $TMPDIR/percona-toolkit) of |
837 | # /opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuStatus -aALL |
838 | # ############################################################################## |
839 | parse_lsi_megaraid_bbu_status () { |
840 | @@ -665,7 +705,7 @@ |
841 | } |
842 | |
843 | # ############################################################################## |
844 | -# Parse physical devices from the output (saved in /tmp/percona-toolkit) of |
845 | +# Parse physical devices from the output (saved in $TMPDIR/percona-toolkit) of |
846 | # /opt/MegaRAID/MegaCli/MegaCli64 -LdPdInfo -aALL |
847 | # OR, it will also work with the output of |
848 | # /opt/MegaRAID/MegaCli/MegaCli64 -PDList -aALL |
849 | @@ -694,7 +734,7 @@ |
850 | } |
851 | |
852 | # ############################################################################## |
853 | -# Parse virtual devices from the output (saved in /tmp/percona-toolkit) of |
854 | +# Parse virtual devices from the output (saved in $TMPDIR/percona-toolkit) of |
855 | # /opt/MegaRAID/MegaCli/MegaCli64 -LdPdInfo -aALL |
856 | # OR, it will also work with the output of |
857 | # /opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -Lall -aAll |
858 | @@ -826,6 +866,7 @@ |
859 | export PATH="${PATH}:/usr/StorMan/:/opt/MegaRAID/MegaCli/"; |
860 | |
861 | # Set up temporary files. |
862 | + mk_tmpdir |
863 | temp_files "rm" |
864 | temp_files "touch" |
865 | section Percona_Toolkit_System_Summary_Report |
866 | @@ -833,7 +874,7 @@ |
867 | # ######################################################################## |
868 | # Grab a bunch of stuff and put it into temp files for later. |
869 | # ######################################################################## |
870 | - sysctl -a > /tmp/percona-toolkit.sysctl 2>/dev/null |
871 | + sysctl -a > $TMPDIR/percona-toolkit.sysctl 2>/dev/null |
872 | |
873 | # ######################################################################## |
874 | # General date, time, load, etc |
875 | @@ -939,19 +980,19 @@ |
876 | # available to non-root users and usually has telltale signs. It's most |
877 | # reliable to look at /var/log/dmesg if possible. There are a number of |
878 | # other ways to find out if a system is virtualized. |
879 | - cat /var/log/dmesg > /tmp/percona-toolkit 2>/dev/null |
880 | - if [ ! -s /tmp/percona-toolkit ]; then |
881 | - dmesg > /tmp/percona-toolkit 2>/dev/null |
882 | + cat /var/log/dmesg > $TMPDIR/percona-toolkit 2>/dev/null |
883 | + if [ ! -s $TMPDIR/percona-toolkit ]; then |
884 | + dmesg > $TMPDIR/percona-toolkit 2>/dev/null |
885 | fi |
886 | - if [ -s /tmp/percona-toolkit ]; then |
887 | - virt="$(parse_virtualization_dmesg /tmp/percona-toolkit)" |
888 | + if [ -s $TMPDIR/percona-toolkit ]; then |
889 | + virt="$(parse_virtualization_dmesg $TMPDIR/percona-toolkit)" |
890 | fi |
891 | if [ -z "${virt}" ]; then |
892 | if which lspci >/dev/null 2>&1; then |
893 | - lspci > /tmp/percona-toolkit 2>/dev/null |
894 | - if grep -qi virtualbox /tmp/percona-toolkit; then |
895 | + lspci > $TMPDIR/percona-toolkit 2>/dev/null |
896 | + if grep -qi virtualbox $TMPDIR/percona-toolkit; then |
897 | virt=VirtualBox |
898 | - elif grep -qi vmware /tmp/percona-toolkit; then |
899 | + elif grep -qi vmware $TMPDIR/percona-toolkit; then |
900 | virt=VMWare |
901 | elif [ -e /proc/user_beancounters ]; then |
902 | virt="OpenVZ/Virtuozzo" |
903 | @@ -962,10 +1003,10 @@ |
904 | virt="FreeBSD Jail" |
905 | fi |
906 | elif [ "${platform}" = "SunOS" ]; then |
907 | - if which prtdiag >/dev/null 2>&1 && prtdiag > /tmp/percona-toolkit.prtdiag 2>/dev/null; then |
908 | - virt="$(parse_virtualization_generic /tmp/percona-toolkit.prtdiag)" |
909 | - elif which smbios >/dev/null 2>&1 && smbios > /tmp/percona-toolkit.smbios 2>/dev/null; then |
910 | - virt="$(parse_virtualization_generic /tmp/percona-toolkit.smbios)" |
911 | + if which prtdiag >/dev/null 2>&1 && prtdiag > $TMPDIR/percona-toolkit.prtdiag 2>/dev/null; then |
912 | + virt="$(parse_virtualization_generic $TMPDIR/percona-toolkit.prtdiag)" |
913 | + elif which smbios >/dev/null 2>&1 && smbios > $TMPDIR/percona-toolkit.smbios 2>/dev/null; then |
914 | + virt="$(parse_virtualization_generic $TMPDIR/percona-toolkit.smbios)" |
915 | fi |
916 | fi |
917 | name_val Virtualized "${virt:-No virtualization detected}" |
918 | @@ -975,23 +1016,23 @@ |
919 | # ######################################################################## |
920 | section Processor |
921 | if [ -f /proc/cpuinfo ]; then |
922 | - cat /proc/cpuinfo > /tmp/percona-toolkit 2>/dev/null |
923 | - parse_proc_cpuinfo /tmp/percona-toolkit |
924 | + cat /proc/cpuinfo > $TMPDIR/percona-toolkit 2>/dev/null |
925 | + parse_proc_cpuinfo $TMPDIR/percona-toolkit |
926 | elif [ "${platform}" = "FreeBSD" ]; then |
927 | - parse_sysctl_cpu_freebsd /tmp/percona-toolkit.sysctl |
928 | + parse_sysctl_cpu_freebsd $TMPDIR/percona-toolkit.sysctl |
929 | elif [ "${platform}" = "SunOS" ]; then |
930 | - psrinfo -v > /tmp/percona-toolkit |
931 | - parse_psrinfo_cpus /tmp/percona-toolkit |
932 | + psrinfo -v > $TMPDIR/percona-toolkit |
933 | + parse_psrinfo_cpus $TMPDIR/percona-toolkit |
934 | # TODO: prtconf -v actually prints the CPU model name etc. |
935 | fi |
936 | |
937 | section Memory |
938 | if [ "${platform}" = "Linux" ]; then |
939 | - free -b > /tmp/percona-toolkit |
940 | - cat /proc/meminfo >> /tmp/percona-toolkit |
941 | - parse_free_minus_b /tmp/percona-toolkit |
942 | + free -b > $TMPDIR/percona-toolkit |
943 | + cat /proc/meminfo >> $TMPDIR/percona-toolkit |
944 | + parse_free_minus_b $TMPDIR/percona-toolkit |
945 | elif [ "${platform}" = "FreeBSD" ]; then |
946 | - parse_memory_sysctl_freebsd /tmp/percona-toolkit.sysctl |
947 | + parse_memory_sysctl_freebsd $TMPDIR/percona-toolkit.sysctl |
948 | elif [ "${platform}" = "SunOS" ]; then |
949 | name_val Memory "$(prtconf | awk -F: '/Memory/{print $2}')" |
950 | fi |
951 | @@ -1007,8 +1048,8 @@ |
952 | fi |
953 | fi |
954 | |
955 | - if which dmidecode >/dev/null 2>&1 && dmidecode > /tmp/percona-toolkit 2>/dev/null; then |
956 | - parse_dmidecode_mem_devices /tmp/percona-toolkit |
957 | + if which dmidecode >/dev/null 2>&1 && dmidecode > $TMPDIR/percona-toolkit 2>/dev/null; then |
958 | + parse_dmidecode_mem_devices $TMPDIR/percona-toolkit |
959 | fi |
960 | |
961 | # ######################################################################## |
962 | @@ -1023,25 +1064,25 @@ |
963 | if [ "${platform}" = "Linux" ]; then |
964 | cmd="df -h -P" |
965 | fi |
966 | - $cmd | sort > /tmp/percona-toolkit2 |
967 | - mount | sort | join /tmp/percona-toolkit2 - > /tmp/percona-toolkit |
968 | - parse_filesystems /tmp/percona-toolkit "${platform}" |
969 | + $cmd | sort > $TMPDIR/percona-toolkit2 |
970 | + mount | sort | join $TMPDIR/percona-toolkit2 - > $TMPDIR/percona-toolkit |
971 | + parse_filesystems $TMPDIR/percona-toolkit "${platform}" |
972 | fi |
973 | fi |
974 | |
975 | if [ "${platform}" = "Linux" ]; then |
976 | section "Disk_Schedulers_And_Queue_Size" |
977 | - echo "" > /tmp/percona-toolkit |
978 | + echo "" > $TMPDIR/percona-toolkit |
979 | for disk in $(ls /sys/block/ | grep -v -e ram -e loop -e 'fd[0-9]'); do |
980 | if [ -e "/sys/block/${disk}/queue/scheduler" ]; then |
981 | name_val "${disk}" "$(cat /sys/block/${disk}/queue/scheduler | grep -o '\[.*\]') $(cat /sys/block/${disk}/queue/nr_requests)" |
982 | - fdisk -l "/dev/${disk}" >> /tmp/percona-toolkit 2>/dev/null |
983 | + fdisk -l "/dev/${disk}" >> $TMPDIR/percona-toolkit 2>/dev/null |
984 | fi |
985 | done |
986 | |
987 | - # Relies on /tmp/percona-toolkit having data from the Disk Schedulers loop. |
988 | + # Relies on $TMPDIR/percona-toolkit having data from the Disk Schedulers loop. |
989 | section "Disk_Partioning" |
990 | - parse_fdisk /tmp/percona-toolkit |
991 | + parse_fdisk $TMPDIR/percona-toolkit |
992 | |
993 | section "Kernel_Inode_State" |
994 | for file in dentry-state file-nr inode-nr; do |
995 | @@ -1064,15 +1105,15 @@ |
996 | # often available to non-root users. It's most reliable to look at |
997 | # /var/log/dmesg if possible. |
998 | # ######################################################################## |
999 | - if which lspci >/dev/null 2>&1 && lspci > /tmp/percona-toolkit 2>/dev/null; then |
1000 | - controller="$(parse_raid_controller_lspci /tmp/percona-toolkit)" |
1001 | + if which lspci >/dev/null 2>&1 && lspci > $TMPDIR/percona-toolkit 2>/dev/null; then |
1002 | + controller="$(parse_raid_controller_lspci $TMPDIR/percona-toolkit)" |
1003 | fi |
1004 | if [ -z "${controller}" ]; then |
1005 | - cat /var/log/dmesg > /tmp/percona-toolkit 2>/dev/null |
1006 | - if [ ! -s /tmp/percona-toolkit ]; then |
1007 | - dmesg > /tmp/percona-toolkit 2>/dev/null |
1008 | + cat /var/log/dmesg > $TMPDIR/percona-toolkit 2>/dev/null |
1009 | + if [ ! -s $TMPDIR/percona-toolkit ]; then |
1010 | + dmesg > $TMPDIR/percona-toolkit 2>/dev/null |
1011 | fi |
1012 | - controller="$(parse_raid_controller_dmesg /tmp/percona-toolkit)" |
1013 | + controller="$(parse_raid_controller_dmesg $TMPDIR/percona-toolkit)" |
1014 | fi |
1015 | |
1016 | name_val Controller "${controller:-No RAID controller detected}" |
1017 | @@ -1085,29 +1126,29 @@ |
1018 | # ######################################################################## |
1019 | notfound="" |
1020 | if [ "${controller}" = "AACRAID" ]; then |
1021 | - if arcconf getconfig 1 > /tmp/percona-toolkit 2>/dev/null; then |
1022 | - parse_arcconf /tmp/percona-toolkit |
1023 | + if arcconf getconfig 1 > $TMPDIR/percona-toolkit 2>/dev/null; then |
1024 | + parse_arcconf $TMPDIR/percona-toolkit |
1025 | elif ! which arcconf >/dev/null 2>&1; then |
1026 | notfound="e.g. http://www.adaptec.com/en-US/support/raid/scsi_raid/ASR-2120S/" |
1027 | fi |
1028 | elif [ "${controller}" = "HP Smart Array" ]; then |
1029 | - if hpacucli ctrl all show config > /tmp/percona-toolkit 2>/dev/null; then |
1030 | - parse_hpacucli /tmp/percona-toolkit |
1031 | + if hpacucli ctrl all show config > $TMPDIR/percona-toolkit 2>/dev/null; then |
1032 | + parse_hpacucli $TMPDIR/percona-toolkit |
1033 | elif ! which hpacucli >/dev/null 2>&1; then |
1034 | notfound="your package repository or the manufacturer's website" |
1035 | fi |
1036 | elif [ "${controller}" = "LSI Logic MegaRAID SAS" ]; then |
1037 | - if MegaCli64 -AdpAllInfo -aALL -NoLog > /tmp/percona-toolkit 2>/dev/null; then |
1038 | - parse_lsi_megaraid_adapter_info /tmp/percona-toolkit |
1039 | + if MegaCli64 -AdpAllInfo -aALL -NoLog > $TMPDIR/percona-toolkit 2>/dev/null; then |
1040 | + parse_lsi_megaraid_adapter_info $TMPDIR/percona-toolkit |
1041 | elif ! which MegaCli64 >/dev/null 2>&1; then |
1042 | notfound="your package repository or the manufacturer's website" |
1043 | fi |
1044 | - if MegaCli64 -AdpBbuCmd -GetBbuStatus -aALL -NoLog > /tmp/percona-toolkit 2>/dev/null; then |
1045 | - parse_lsi_megaraid_bbu_status /tmp/percona-toolkit |
1046 | + if MegaCli64 -AdpBbuCmd -GetBbuStatus -aALL -NoLog > $TMPDIR/percona-toolkit 2>/dev/null; then |
1047 | + parse_lsi_megaraid_bbu_status $TMPDIR/percona-toolkit |
1048 | fi |
1049 | - if MegaCli64 -LdPdInfo -aALL -NoLog > /tmp/percona-toolkit 2>/dev/null; then |
1050 | - parse_lsi_megaraid_virtual_devices /tmp/percona-toolkit |
1051 | - parse_lsi_megaraid_devices /tmp/percona-toolkit |
1052 | + if MegaCli64 -LdPdInfo -aALL -NoLog > $TMPDIR/percona-toolkit 2>/dev/null; then |
1053 | + parse_lsi_megaraid_virtual_devices $TMPDIR/percona-toolkit |
1054 | + parse_lsi_megaraid_devices $TMPDIR/percona-toolkit |
1055 | fi |
1056 | fi |
1057 | |
1058 | @@ -1122,8 +1163,8 @@ |
1059 | # ##################################################################### |
1060 | if [ "${platform}" = "Linux" ]; then |
1061 | section Network_Config |
1062 | - if which lspci > /dev/null 2>&1 && lspci > /tmp/percona-toolkit 2>/dev/null; then |
1063 | - parse_ethernet_controller_lspci /tmp/percona-toolkit |
1064 | + if which lspci > /dev/null 2>&1 && lspci > $TMPDIR/percona-toolkit 2>/dev/null; then |
1065 | + parse_ethernet_controller_lspci $TMPDIR/percona-toolkit |
1066 | fi |
1067 | if sysctl net.ipv4.tcp_fin_timeout > /dev/null 2>&1; then |
1068 | name_val "FIN Timeout" "$(sysctl net.ipv4.tcp_fin_timeout)" |
1069 | @@ -1135,15 +1176,15 @@ |
1070 | # /proc/sys/net/netfilter/nf_conntrack_max or /proc/sys/net/nf_conntrack_max |
1071 | # in new kernels like Fedora 12? |
1072 | |
1073 | - if which ip >/dev/null 2>&1 && ip -s link > /tmp/percona-toolkit 2>/dev/null; then |
1074 | + if which ip >/dev/null 2>&1 && ip -s link > $TMPDIR/percona-toolkit 2>/dev/null; then |
1075 | section Interface_Statistics |
1076 | - parse_ip_s_link /tmp/percona-toolkit |
1077 | + parse_ip_s_link $TMPDIR/percona-toolkit |
1078 | fi |
1079 | |
1080 | if [ "${platform}" = "Linux" ]; then |
1081 | section Network_Connections |
1082 | - if netstat -antp > /tmp/percona-toolkit 2>/dev/null; then |
1083 | - parse_netstat /tmp/percona-toolkit |
1084 | + if netstat -antp > $TMPDIR/percona-toolkit 2>/dev/null; then |
1085 | + parse_netstat $TMPDIR/percona-toolkit |
1086 | fi |
1087 | fi |
1088 | fi |
1089 | @@ -1164,12 +1205,12 @@ |
1090 | fi |
1091 | if which vmstat > /dev/null 2>&1 ; then |
1092 | section "Simplified_and_fuzzy_rounded_vmstat_(wait_please)" |
1093 | - vmstat 1 5 > /tmp/percona-toolkit |
1094 | + vmstat 1 5 > $TMPDIR/percona-toolkit |
1095 | if [ "${platform}" = "Linux" ]; then |
1096 | - format_vmstat /tmp/percona-toolkit |
1097 | + format_vmstat $TMPDIR/percona-toolkit |
1098 | else |
1099 | # TODO: simplify/format for other platforms |
1100 | - cat /tmp/percona-toolkit |
1101 | + cat $TMPDIR/percona-toolkit |
1102 | fi |
1103 | fi |
1104 | fi |
1105 | @@ -1179,6 +1220,7 @@ |
1106 | # ######################################################################## |
1107 | temp_files "rm" |
1108 | temp_files "check" |
1109 | + rm_tmpdir |
1110 | section The_End |
1111 | } |
1112 | |
1113 | @@ -1238,9 +1280,9 @@ |
1114 | =head1 DESCRIPTION |
1115 | |
1116 | pt-summary runs a large variety of commands to inspect system status and |
1117 | -configuration, saves the output into files in /tmp, and then runs Unix |
1118 | -commands on these results to format them nicely. It works best when |
1119 | -executed as a privileged user, but will also work without privileges, |
1120 | +configuration, saves the output into files in a temporary directory, and |
1121 | +then runs Unix commands on these results to format them nicely. It works |
1122 | +best when executed as a privileged user, but will also work without privileges, |
1123 | although some output might not be possible to generate without root. |
1124 | |
1125 | =head1 OPTIONS |
1126 | |
1127 | === modified file 't/pt-mysql-summary/get_mysql_info.sh' |
1128 | --- t/pt-mysql-summary/get_mysql_info.sh 2011-08-18 17:46:13 +0000 |
1129 | +++ t/pt-mysql-summary/get_mysql_info.sh 2012-02-01 16:31:24 +0000 |
1130 | @@ -3,14 +3,14 @@ |
1131 | TESTS=3 |
1132 | |
1133 | TEST_NAME="get_mysql_timezone" |
1134 | -cp samples/mysql-variables-001.txt /tmp/percona-toolkit-mysql-variables |
1135 | +cp samples/mysql-variables-001.txt $TMPDIR/percona-toolkit-mysql-variables |
1136 | is $(get_mysql_timezone) "EDT" |
1137 | |
1138 | TEST_NAME="get_mysql_uptime" |
1139 | cat <<EOF > $TMPDIR/expected |
1140 | 2010-05-27 11:38 (up 0+02:08:52) |
1141 | EOF |
1142 | -cp samples/mysql-status-001.txt /tmp/percona-toolkit-mysql-status |
1143 | +cp samples/mysql-status-001.txt $TMPDIR/percona-toolkit-mysql-status |
1144 | echo "2010-05-27 11:38" > $TMPDIR/in |
1145 | get_mysql_uptime $TMPDIR/in > $TMPDIR/got |
1146 | no_diff $TMPDIR/got $TMPDIR/expected |
1147 | @@ -20,6 +20,6 @@ |
1148 | Version | 5.0.51a-24+lenny2 (Debian) |
1149 | Built On | debian-linux-gnu i486 |
1150 | EOF |
1151 | -cp samples/mysql-variables-001.txt /tmp/percona-toolkit-mysql-variables |
1152 | +cp samples/mysql-variables-001.txt $TMPDIR/percona-toolkit-mysql-variables |
1153 | get_mysql_version > $TMPDIR/got |
1154 | no_diff $TMPDIR/got $TMPDIR/expected |
1155 | |
1156 | === modified file 'util/test-bash-functions' |
1157 | --- util/test-bash-functions 2011-12-06 20:23:47 +0000 |
1158 | +++ util/test-bash-functions 2012-02-01 16:31:24 +0000 |
1159 | @@ -93,7 +93,7 @@ |
1160 | # Print a TAP-style test result. |
1161 | result() { |
1162 | local result=$1 |
1163 | - local test_name=$2 |
1164 | + local test_name=${2:-""} |
1165 | if [ $result -eq 0 ]; then |
1166 | echo "ok $testno - $TEST_FILE $test_name" |
1167 | else |
1168 | @@ -115,7 +115,7 @@ |
1169 | no_diff() { |
1170 | local got=$1 |
1171 | local expected=$2 |
1172 | - local test_name=$3 |
1173 | + local test_name=${3:-""} |
1174 | test_command="diff $got $expected" |
1175 | eval $test_command > $TEST_TMPDIR/failed_result 2>&1 |
1176 | result $? "$test_name" |
1177 | @@ -124,7 +124,7 @@ |
1178 | is() { |
1179 | local got=$1 |
1180 | local expected=$2 |
1181 | - local test_name=$3 |
1182 | + local test_name=${3:-""} |
1183 | test_command="\"$got\" == \"$expected\"" |
1184 | test "$got" = "$expected" |
1185 | result $? "$test_name" |
1186 | @@ -132,7 +132,7 @@ |
1187 | |
1188 | cmd_ok() { |
1189 | local test_command=$1 |
1190 | - local test_name=$2 |
1191 | + local test_name=${2:-""} |
1192 | eval $test_command |
1193 | result $? "$test_name" |
1194 | } |