Skip to content

Instantly share code, notes, and snippets.

TCP Send-Q Trace

tcp_sendq_trace.py monitors per-socket TCP send buffer utilization over time using the Linux ss command. It produces a CSV time series that lets you identify which client connections are slow (not reading data), causing the server's kernel send buffer to back up.

How It Works

  1. Runs ss -tinm state established at a configurable interval to capture all established TCP connections.
  2. Parses each connection's Send-Q (bytes queued in the kernel send buffer waiting to be ACKed or read by the remote side) and snd_buf (tb field from skmem) which is the kernel's current send buffer size.
  3. Computes utilization as Send-Q / snd_buf (0.0 = idle, 1.0 = buffer full).
  4. Writes timestamped rows to a CSV file for offline analysis or graphing.
@mcai4gl2
mcai4gl2 / README.md
Created May 24, 2021 14:14 — forked from jgoodall/README.md
This is a sample of how to send some information to logstash via the TCP input from node.js or python.

This is a sample of how to send some information to logstash via the TCP input in nodejs or python. It assumes the logstash host is on 10.10.10.100 and the TCP listening input is 9563.

The logstash.conf should look something like the sample file.

The log message should be a stringified JSON object with the log message in the @message field.

To use, run the node script node sendMessageToLogstash.js, or the python script python sendMessageToLogstash.js

@mcai4gl2
mcai4gl2 / markdown.py
Created April 30, 2017 21:00
Print DataFrame as markdown table
import pandas as pd
from StringIO import StringIO
input_data = StringIO("""col1,col2,col3
1,2,3
4,5,6
7,8,9
""")
df = pd.read_csv(input_data, sep=",")
import tabulate
// Restify Server CheatSheet.
// More about the API: http://mcavage.me/node-restify/#server-api
// Install restify with npm install restify
// 1.1. Creating a Server.
// http://mcavage.me/node-restify/#Creating-a-Server
var restify = require('restify');
task prefixNewMigrations {
fileTree(dir: 'dev/src/db/listhub').exclude({ isFilePrefixed(it.file) }).each { file ->
doLast {
def timestamp = new Date().format('yyyyMMddHHmmssSSS', TimeZone.getTimeZone('GMT'))
println "Renaming $file.name to ${timestamp}__$file.name"
file.renameTo("$file.parentFile.absolutePath$file.separator${timestamp}__$file.name")
@mcai4gl2
mcai4gl2 / gist:d32a985b695ef58cd31b
Created December 27, 2014 22:02
Example to access Github API using github.js
QUnit.test('Read user details', function() {
var github = ghClient.Github;
var user = github.getUser();
console.log(user);
QUnit.ok(user, "User shall not be undefined");
QUnit.stop();