Skip to content

Instantly share code, notes, and snippets.

View iAnatoly's full-sized avatar

Anatoly Ivanov iAnatoly

View GitHub Profile
@iAnatoly
iAnatoly / softnetstat.py
Created March 24, 2021 18:01
Ad-hoc monitoring for time_squeeze changes in /proc/net/softnet_stat
#!/usr/bin/env python3
#
# Ad-hoc monitoring for time_squeeze changes in /proc/net/softnet_stat .
#
# usage: ./softnetstat.py <refresh_interval_seconds>
#
# see https://blog.packagecloud.io/eng/2016/06/22/monitoring-tuning-linux-networking-stack-receiving-data/
#
from time import sleep
from datetime import datetime
@iAnatoly
iAnatoly / bpftrace.sh
Created March 24, 2021 21:10
bpftrace oneliners
# see https://github.com/iovisor/bpftrace/blob/master/docs/tutorial_one_liners.md
# histogram for udp_recvmsg timing
sudo bpftrace -e 'kprobe:udp_recvmsg { @start[tid] = nsecs; } kretprobe:udp_recvmsg /@start[tid]/ { @ns[comm] = hist(nsecs - @start[tid]); delete(@start[tid]); }'
# histogram for retval of udp_recvmsg (which is message size in bytes)
sudo bpftrace -e 'kretprobe:udp_recvmsg { @bytes[comm] = hist(retval); }'
@iAnatoly
iAnatoly / kube_client_cert_validity.sh
Last active December 7, 2021 17:10
check kube client cert validity period
cat ~/.kube/config | grep client-certificate | sed -e ‘s/ client-certificate-data: //’ | base64 -d | openssl x509 -in - -noout -text
@iAnatoly
iAnatoly / UDR-UDT.md
Last active March 16, 2022 21:04
Quicky Transferring large viles over high-latency WAN link using UDR/UDT

Motivation

At some point, you might find yourself in need to transfer a file (i.e. a dump of the database, or a backup tarball) quickly over a WAN link. Unfortunately, regular copy speeds are impaired by TCP protocol and latency and speed of light - and link bandwidth has very limited effect on the transfer speeds. However, there is a workaround: one can use UDP-based file transfer (UDT). Here is a proof-of-concept experiment that demonstrates the transfer speed improvement.

Experiment

Create a large file to transfer:

SSH_ENV="$HOME/.ssh/agent-environment"
function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add;
}
@iAnatoly
iAnatoly / MACOS-LIST.md
Last active April 13, 2022 18:24
List of tools to make MacOS usable
  • iTerm2
  • iStat menus
  • VS code
  • ObjeciveSee: BlockBlock, KnockKnock
  • Homebrew: ansible, telegraf, bash5, curl, wget, sqlite, python3, go,
  • Commons: Chrome, Chromium, FF, Kindle, VLC
go install -v github.com/projectdiscovery/dnsx/cmd/dnsx@latest
go install -v github.com/projectdiscovery/subfinder/v2/cmd/subfinder@latest
brew install ipinfo-cli
./go/bin/subfinder -d google.com | ./go/bin/dnsx -resp-only | ipinfo summarize
@iAnatoly
iAnatoly / gist:77fcafc884a80faadf015edf28a9c938
Created April 27, 2022 21:47
Emulating packetloss and latency
https://stackoverflow.com/questions/614795/simulate-delayed-and-dropped-packets-on-linux
https://wiki.linuxfoundation.org/networking/netem
```bash
TARGET1='8.8.8.8'
DEV='eth0'
tc qdisc delete dev $DEV root
tc qdisc add dev $DEV root handle 1: prio
@iAnatoly
iAnatoly / generate_self_signed.sh
Created May 4, 2022 01:54
openssl self-signed cert one line
#!/bin/bash
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365 -nodes
@iAnatoly
iAnatoly / generate-random.sh
Last active May 6, 2022 18:15
Generate given number of random files
#!/bin/bash
TARGET_FILE_NUM=$1
CURRENT_FILE_NUM=`ls -l | wc -l`
FILES_TO_GENERATE=$((TARGET_FILE_NUM - CURRENT_FILE_NUM))
if [[ $FILES_TO_GENERATE -lt 0 ]]; then
echo "We already have $CURRENT_FILE_NUM files, no need to generate more"
exit
fi