Skip to content

Instantly share code, notes, and snippets.

@kevinbin
kevinbin / gist:4093953
Created November 17, 2012 07:09
统计binlog中每个表的DML数量
mysqlbinlog mysql-bin.000045 | \
grep -i -e "^update" -e "^insert" -e "^delete" -e "^replace" -e "^alter" | \
cut -c1-100 | tr '[A-Z]' '[a-z]' | \
sed -e "s/\t/ /g;s/\`//g;s/(.*$//;s/ set .*$//;s/ as .*$//" | sed -e "s/ where .*$//" | \
sort | uniq -c | sort -nr
@kevinbin
kevinbin / gist:4093997
Created November 17, 2012 07:21
mysql逻辑备份单表文件
user=""
passwd=""
dbname=""
for table in `mysql -u$user -p$passwd $dbname -BNe 'show tables'; do
mysqldump -u$user -p$passwd --single-transaction $dbname $table |gzip > $table.sql.gz
done
@kevinbin
kevinbin / gist:4094000
Created November 17, 2012 07:22
监测mysql连接动态
mysqladmin ext -i1 | awk '
/Queries/{q=$4-qp;qp=$4}
/Threads_connected/{tc=$4}
/Threads_running/{printf "%5d %5d %5d\n", q, tc, $4}'
@kevinbin
kevinbin / gist:4094031
Created November 17, 2012 07:30
sysbench批量io测试
for size in 256M 16G; do
for mode in seqwr seqrd rndrd rndwr rndrw; do
sysbench --test=fileio --file-num=1 --file-total-size=$size prepare
for threads in 1 4 8 16; do
echo PARAMS $size $mode $threads> sysbench-size-$size-mode-$mode-threads-$threads
sysbench --test=fileio --file-total-size=$size --file-test-mode=$mode\
--max-time=60 --max-requests=10000000 --num-threads=$threads --init-rng=on\
--file-num=1 --file-extra-flags=direct --file-fsync-freq=0 run \
>> sysbench-size-$size-mode-$mode-threads-$threads 2>&1
done
@kevinbin
kevinbin / gist:4094440
Created November 17, 2012 09:17
dstat监控
#!/bin/sh
DATETIME=`date +%y%m%d.%H%M`
LOG_DIR="/var/log/monitor/"
INTERVAL=5
COUNT=`expr 3600 \/ $INTERVAL`
LOG_FILE=${LOG_DIR}os.${DATETIME}.${INTERVAL}.txt
CSV_LOG_FILE=${LOG_DIR}os.${DATETIME}.${INTERVAL}.csv
MYSQL_LOG_FILE=${LOG_DIR}os.${DATETIME}.${INTERVAL}.csv
@kevinbin
kevinbin / gist:4094502
Created November 17, 2012 09:34
iptable rule
#!/bin/sh
#
modprobe ipt_MASQUERADE
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
iptables -F
iptables -t nat -F
iptables -X
iptables -t nat -X
###########################INPUT键###################################
#!/bin/sh
# set -x
# Shell script to monitor or watch the disk space
# It will send an email to $ADMIN, if the (free available) percentage of space is >= 90%.
# -------------------------------------------------------------------------
# Set admin email so that you can get email.
ADMIN="root"
# set alert level 90% is default
ALERT=90
# Exclude list of unwanted monitoring, if several partions then use "|" to separate the partitions.
@kevinbin
kevinbin / tpcc-mysql-format
Created March 31, 2013 03:29
tpcc-mysql result format
awk 'BEGIN {printf "%s\t%s\n", "Connect","TpmC"}; {if ($0 ~ /connection/){printf "%s\t", $2} ;if ($0 ~/[0-9].*TpmC/) {print $1}}' tpcc_result_file
@kevinbin
kevinbin / sysbench-mysql-format
Created March 31, 2013 03:39
sysbench mysql benchmark result format
awk 'BEGIN {printf "%s%5s%15s%15s\n", "Connect","TPS","QPS","RT"}; {if ($0 ~ /threads:/){printf "%s\t", $4} ;if ($0 ~/transactions:/){sub(/\(/,"");printf "%s\t", $3};if($0~/requests:/){sub(/\(/,"");printf "%s\t",$4};if ($0~/avg:/){print $2}}'
@kevinbin
kevinbin / nagios_install.sh
Created May 17, 2013 04:55
nagios & nagios plugin install script
#!/bin/sh
# Any Failing Command Will Cause The Script To Stop
set -e
# Treat Unset Variables As Errors
set -u
NAGIOS_VERSION=3.5.0
PLUGIN_VERSION=1.4.16