Skip to content

Instantly share code, notes, and snippets.

@iAnatoly
Created March 24, 2021 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iAnatoly/b8925aadae725f5ba0203522d2af168d to your computer and use it in GitHub Desktop.
Save iAnatoly/b8925aadae725f5ba0203522d2af168d to your computer and use it in GitHub Desktop.
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
import sys
FILE='/proc/net/softnet_stat'
def process(file):
s = 0
with open(file) as f:
lines = f.readlines()
for line in lines:
vals = line.split(' ')
s += int(vals[2],16)
return s
def main(interval):
print('timestamp\t\tdelta\tcur\tprev')
prev = 0 #float('Inf')
while True:
cur = process(FILE)
delta = cur-prev
timestamp = datetime.now().replace(microsecond=0).isoformat()
if delta>0:
print('{0}\t{1}\t{2}\t{3}'.format(timestamp,delta, cur, prev), flush=True)
sleep(interval)
prev = cur
if __name__ == '__main__':
if len(sys.argv) < 2:
interval = 1
else:
interval = int(sys.argv[1])
main(interval)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment