Skip to content

Instantly share code, notes, and snippets.

@deevis
deevis / gist:989d6f5a34b2c25bbeb0
Last active August 29, 2015 14:13
Subscribe to Redis expired key events
redis.subscribe("__keyevent@0__:expired") { |on| on.subscribe { |channel, subscriptions| puts "Subscribed to ##{channel} (#{subscriptions} subscriptions)" }; on.message { |channel, message| puts "Key expired: [#{message}]" }; on.unsubscribe { |channel, subscriptions| puts "Unsubscribed from ##{channel} (#{subscriptions} subscriptions)" }}
@deevis
deevis / gist:2601b62a842006547289
Created January 8, 2015 18:39
MySQL table storage summary
SELECT table_name AS "Tables", table_rows, round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB" FROM information_schema.TABLES WHERE table_schema = "pyr_revel_prod" ORDER BY (data_length + index_length) DESC;
@deevis
deevis / gist:4c025f365cc44589a603
Last active February 13, 2018 13:59
Git Bash Prompt
bash_prompt_command() {
local K="\[\033[0;30m\]" # black
local R="\[\033[0;31m\]" # red
local G="\[\033[0;32m\]" # green
local Y="\[\033[0;33m\]" # yellow
local B="\[\033[0;34m\]" # blue
local M="\[\033[0;35m\]" # magenta
local C="\[\033[0;36m\]" # cyan
local W="\[\033[0;37m\]" # white
local NONE="\[\033[0m\]"
@deevis
deevis / gist:7d675e1824ed845e1d2e
Created January 9, 2015 17:38
MySQL Storage summary into Ruby Hash
db_name = Rails.configuration.database_configuration[Rails.env]["database"]
sql = "SELECT table_name AS name, table_rows, data_length, index_length FROM information_schema.TABLES WHERE table_schema = '#{db_name}' ORDER BY (data_length + index_length) DESC;"
table_data = ActiveRecord::Base.connection.execute(sql).map{|r| {name: r[0], rows: r[1], data_size: r[2], index_size: r[3]}}
@deevis
deevis / gist:3d34499cd441fe3f3375
Last active August 29, 2015 14:15
Show requests by IP address from NGINX access log (for a particular day)
grep "19\/Feb\/2015" /var/log/nginx/access.log.1 | sed 's/\(.*\) - - .*/\1/g' | sort | uniq -c | sort -n
@deevis
deevis / gist:580ffc503d4bf7dc8182
Created February 19, 2015 22:53
Count requests by hour from NGINX logfile from a particular IP address
for h in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24;do echo ""; echo "19/Feb/$h:00"; echo "----------------------"; grep "199.102.210.214 - - \[19\/Feb\/2015\:$h" /var/log/nginx/access.log.1 | wc -l ;done
@deevis
deevis / gist:b4f71ba52067531575ca
Created February 24, 2015 19:35
Get list of users with occurrence count who had a certain type of error occur
for request in `grep -e "undefined local variable or method .*html_safe" log/production.log -B 1 | grep FATAL | sed 's/.*FATAL.*\[\(.*\)\]/\1/g'`;do grep "$request" log/production.log | head -n 20 | grep current_user;done | sed 's/.*current_user\(.*\).*/\1/g' | sort | uniq -c | sort -n
@deevis
deevis / gist:61113a95429e219fd108
Last active October 26, 2015 21:01
Parse Vibe logs for slowest showing time to render, user, path, and time of request
zgrep "END: current_user" production.log.2.gz | sed 's/\(.*\) \[.*INFO.*current_user\[\(.*\)\] (\(.*\)) \(.*\)/\3\t\4\t\2\t\1/g' | sort -n | tail -n 20
# with process:request
grep "END: current_user" production.log | sed 's/\(.*\) \[.*INFO.*\[\(.*\)\].*current_user\[\(.*\)\] (\(.*\)) \(.*\)/\4\t\2\t\1\t\3\t\5/g' | sort -n | tail -n 100
# find with process:request, then loop back and find problems for each...
# Part 1
grep "END: current_user" production.log | sed 's/\(.*\) \[.*INFO.*\[\(.*\)\].*current_user\[\(.*\)\] (\(.*\)) \(.*\)/\4\t\2\t\1\t\3\t\5/g' | sort -n | tail -n 100 > slow_requests_10_26_2015.txt
# Part 2
for rqid in `cat slow_requests_10_26_2015.txt | sed 's/.*seconds\t\(.*\)\s.*2015.*/\1/g'`;do echo -e "API Calls for [$rqid]\n---------------------------\n"; grep $rqid production.log | grep "request to api.exigo.com" -A 1; echo -e "\n\n";done > exigo_slow_calls_report_10_26_2015.txt
sudo lsof -p $MYSQL_PID | grep localhost | for x in `sed 's/.*mysql->localhost:\(.*\) .*/\1/g'`; do sudo netstat -tapen | grep "0 127.0.0.1:$x"; done | sed 's/.* \(.*\)/\1/g' | sort | uniq -c | sort -n
# Must be root
sudo su -
vi /etc/hostname
# To prevent reboot (also as root)
cat /etc/hostname > /proc/sys/kernel/hostname