Skip to content

Instantly share code, notes, and snippets.

View tairov's full-sized avatar

Aydyn Tairov tairov

  • London, UK
View GitHub Profile

Using strace and lsof to debug blocked processes

You can use strace on a specific pid to figure out what a specific process is doing, e.g.:

strace -fp <pid>

You might see something like:

select(9, [3 5 8], [], [], {0, 999999}) = 0 (Timeout)

var current_id; // id of first record on current page.
// go to page current+N
db.collection.find({_id: {$gt: current_id}}).
skip(N * page_size).
limit(page_size).
sort({_id: 1});
// go to page current-N
db.collection.find({_id: {$lt: current_id}}).
@tairov
tairov / gist:5411066
Created April 18, 2013 08:13
stats, all collections, all databases, mongodb
/opt/mongodb/bin/mongo --port 27017 --eval "db._adminCommand(\"listDatabases\").databases.forEach(function (d) {mdb = db.getSiblingDB(d.name); mdb.getCollectionNames().forEach(function(c) {s = mdb[c].stats(1024 * 1024); printjson(s)})})" | less
@tairov
tairov / gist:5481840
Last active December 16, 2015 18:59
Vagrant file draft provisioning with shell
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "quantal64"
@tairov
tairov / gist:5696524
Created June 3, 2013 07:08
mongodb slow-log analyzer https://github.com/dcrosta/professor indexes should be added for solving problems with some queries
db.profiles.ensureIndex({collection: 1});
db.profiles.ensureIndex({collection: 1, op: 1});
db.profiles.ensureIndex({collection: 1, op: 1, skel: 1});
@tairov
tairov / gist:5900317
Last active December 19, 2015 04:49
useful shell commands, sed replace, mongodb log
perl -ne '/([0-9a-z]{24,24})/ and print $1, "\n"' 01_07.txt
# run command with only 1 argument (-L 1, --max-lines 1) and ask before each command
ls -la | xargs --interactive -L 1 echo
# substitution in xargs
xargs -L 1 -I{} echo "ID IS: {}"
sed -i -e s/\,\.\$comment:.\".*\"// mongodb_short_sed.log
@tairov
tairov / gist:5966349
Last active December 19, 2015 13:59
Chart load average
=======load_avg.sh=========
#! /bin/bash
#if [ 0 == 1 ]; then
HOSTS=('pm.mongo1' 'pm.mongo2' 'pm.mongo3' 'pm.mongo4')
out="[new Date(\"$(date +"%F %H:%M:%S")\")"
for host in ${HOSTS[@]}; do
load_avg=$(ssh -p 60222 user@$host "cat /proc/loadavg")
@tairov
tairov / gist:5973070
Last active December 19, 2015 14:59
mongodb queries
db.pin.tagtask.find().forEach(function(t) {if (t.status == 1) { var photo = db.photo.findOne({_id: t.photo_id}); printjson(photo)} });
@tairov
tairov / gist:5984246
Created July 12, 2013 12:55
remove documents from mongo js, shell, perl, grep
perl -ne '/([0-9a-z]{24,24})/ and print $1, "\n"' 12_07.txt | xargs -L 1 -I{} mongo 127.0.0.1:2707/db --eval \
"var _pid = '{}';
print(_pid);
var pin = db.pin.find({_id: ObjectId(_pid)});
if (pin && pin[0]._id) {
print('pin found: ' + pin[0]._id);
var photo = db.photo.find({_id: pin[0].p});
if (photo && photo[0]._id) {
print('photo_id: ', photo[0]._id);
print('remove photo: ', db.photo.remove({_id: photo[0]._id}) );
@tairov
tairov / gist:5997864
Created July 15, 2013 06:30
load avg, large data set
#! /bin/bash
#if [ 0 == 1 ]; then
HOSTS=('pm.mongo1' 'pm.mongo2' 'pm.mongo3' 'pm.mongo4')
out="[new Date(\"$(date +"%F %H:%M:%S")\")"
for host in ${HOSTS[@]}; do
load_avg=$(ssh -p 60222 atairov@$host "cat /proc/loadavg")
read avg1 avg5 avg15 _tmp <<< $load_avg
out="$out, $avg1, null"