debug/

Monitor open connections

This command will plot open connections:

{ while true; do ss -ant | grep ESTAB | wc -l; sleep 0.1; done } | ttyplot
| 24 Feb 2024

Monitor number of open sockets by a process

Example with watch command:

watch -n 1 'ps aux | kazy -i cmproxy -e kazy | kazy -r "[\d]+" -x | xargs -I % ls -l /proc/%/fd/ | kazy -i socket | wc -l'

Example with ttyplot command:

{ while true; do ps aux | kazy -i cmproxy -e kazy | kazy -r "[\d]+" -x | xargs -I % ls -l /proc/%/fd/ | kazy -i socket | wc -l; sleep 1; done } | ttyplot
| 16 Apr 2023

Monitor DNS query time

{ while true; do dig google.com | kazy -i "Query time" | kazy -r -x "[\d.]*"; sleep 1; done } | ttyplot -t "dig to google.com"
| 12 Apr 2023

Plot real time ping data in terminal

Install ttyplot:

grm install tenox7/ttyplot -n ttyplot

Ping plot:

ping 8.8.8.8 | sed -u 's/^.*time=//g; s/ ms//g' | ttyplot -t "ping to 8.8.8.8" -u ms

More examples

| 12 Apr 2023

Log Varnish hash data

When starting Varnish, add -p vsl_mask=+Hash argument to the command. Print varnish logs with this command:

sudo varnishlog -n /opt/varnish -q 'ReqURL ~ "my_request"'
| 17 Dec 2021

Show top 10 process with open files

lsof | awk '{print $1}' | sort | uniq -c | sort -r -n | head
| 13 Jul 2021

One liners to check open files limit

Check open files limit for the process named redis:

cat /proc/$(ps aux | grep redis | head -n 1 | kazy -x -r "\d+")/limits | kazy -i "open files" -i Limit

Check current number of open files for the process named redis:

sudo ls -l /proc/$(ps aux | grep redis | head -n 1 | kazy -x -r "\d+")/fd | wc -l
| 12 Jul 2021

Open file limits

Print system limits:

14:53 $ ulimit -a
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 514130
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 514130
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Print just open files limit

16:52 $ ulimit -Sn
1024

Get number of open files for a specific process:

# Get process id

16:56 $ ps aux | grep wshub
cobro    3200102  2.0  0.0 3676920 86488 ?       Ssl  16:12   0:54 /opt/cobro/src/wshub/wshub -port 8015 -redis 127.0.0.1:6379 -auxport 8016
client   3212070  0.0  0.0  12132  1160 pts/0    S+   16:57   0:00 grep --color=auto wshub

# Check current limits for the process

16:57 $ cat /proc/3200102/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        unlimited            unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             514130               514130               processes
Max open files            1024                 262144               files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       514130               514130               signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us

# Print number of open files for the process

17:03 $ sudo ls -l /proc/3200102/fd | wc -l
157

Systemd needs this limit specified per service (otherwise it will be 1024):


[Service]
LimitNOFILE=2048

| 12 Jul 2021

Check DNS propagation worldwide

Service from Constellix: DNS Propagation

| 26 May 2021

Forward remote port to a local one via SSH tunnel

ssh -L <LOCAL_PORT>:127.0.0.1:<REMOTE_PORT> remote_server

TCP connections to <LOCAL_PORT> will be forwarded to 127.0.0.1:<REMOTE_PORT> on remote host remote_server

| 25 May 2021