Code Monkey home page Code Monkey logo

softnet-stat's Introduction

softnet-stat

Build Status

Parse the /proc/net/softnet_stat file into something more readable. For more information about /proc/net/softnet_stat, I suggest reading Monitoring and Tuning the Linux Networking Stack: Receiving Data.

Compatible Systems

This parser should work on all Linux kernels since v2.6.32. In later versions of the kernel, more fields were added. Currently, the parser will default these fields to a value of 0 if they are not found in the file.

Distribution

The softnet-stat binary is distributed via the hjr3/softnet-stat repository on packagecloud.io

Build

This software was built Rust using v1.56.0. All dependencies are listed in Cargo.toml. To build: $ cargo build.

The v1.x.x releases were built using Rust v1.10.0.

Static Binary

To build a completely static binary for production use, the binary can use musl as a target.

For Linux:

$ cargo build --target=x86_64-unknown-linux-musl

For macOS:

docker run --rm -it -v "$(pwd)":/home/rust/src ekidd/rust-musl-builder cargo build --release

Release

To create a new rpm, do the following:

$ mkdir target/x86_64-unknown-linux-musl/release/$VERSION
$ docker run --rm -v $(pwd):/data skandyla/fpm -s dir -t rpm -n "softnet_stat" -v $VERSION -p /data -C /data/target/x86_64-unknown-linux-musl/release ./

This will put something like softnet_stat-1.2.0-1.x86_64.rpm in the current directory.

Tests

This program has been tested against /proc/net/softnet_stat files from these Linux versions:

  • v2.6.32
  • v2.6.36
  • v3.11.x
  • v5.10.47
  • v6.4.x

To exercise these tests: $ cargo test.

Examples

Formatted

./softnet-stat

Cpu            Processed      Dropped        Time Squeezed  Cpu Collision  Received RPS   Flow Limit Count
0              1842008611     0              1              0              0              0
1              1863193957     0              2              0              0              0
2              1711764716     0              3              0              0              0
3              1640600369     0              0              0              0              0
4              1737798067     0              5              0              0              0
5              1686686610     0              1              0              0              0

Json

./softnet-stat --json
[{"processed":1842008611,"dropped":0,"time_squeeze":1,"cpu_collision":0,"received_rps":null,"flow_limit_count":null},{"processed":1863193957,"dropped":0,"time_squeeze":2,"cpu_collision":0,"received_rps":null,"flow_limit_count":null},{"processed":1711764716,"dropped":0,"time_squeeze":3,"cpu_collision":0,"received_rps":null,"flow_limit_count":null},{"processed":1640600369,"dropped":0,"time_squeeze":0,"cpu_collision":0,"received_rps":null,"flow_limit_count":null},{"processed":1737798067,"dropped":0,"time_squeeze":5,"cpu_collision":0,"received_rps":null,"flow_limit_count":null},{"processed":1686686610,"dropped":0,"time_squeeze":1,"cpu_collision":0,"received_rps":null,"flow_limit_count":null}]

Read From Stdin

$ cat /path/to/file | ./target/debug/softnet-stat -s
Cpu            Processed      Dropped        Time Squeezed  Cpu Collision  Received RPS   Flow Limit Count
0              1842008611     0              1              0              0              0
1              1863193957     0              2              0              0              0
2              1711764716     0              3              0              0              0
3              1640600369     0              0              0              0              0
4              1737798067     0              5              0              0              0
5              1686686610     0              1              0              0              0

softnet-stat's People

Contributors

hjr3 avatar karuboniru avatar totallyunknown avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

softnet-stat's Issues

Add ability to parse other file or stdin

I'm trying to parse a saved file from a different server, but it looks like the /proc/net path is hardcoded. Would be great if this tool would also work on stdin or a supplied file.

(This project is the first result when searching google for "softnet stat")

Error while parsing /proc/net/softnet_stat

Build

✔  ~/git/softnet-stat [master {origin/master}|✔ ] 
10:44 $ cargo build
  Downloaded serde_derive_internals v0.19.0
  Downloaded serde v1.0.27
  Downloaded quote v0.3.15
  Downloaded dtoa v0.4.2
  Downloaded itoa v0.3.4
  Downloaded unicode-xid v0.0.4
  Downloaded serde_derive v1.0.27
  Downloaded syn v0.11.11
  Downloaded serde_json v1.0.9
  Downloaded synom v0.11.3
  Downloaded libc v0.2.36
  Downloaded num-traits v0.1.43
  Downloaded memchr v2.0.1
  Downloaded num-traits v0.2.0
  Downloaded getopts v0.2.17
  Downloaded nom v4.0.0-beta2
  Downloaded 16 crates (785.8 KB) in 3.14s
   Compiling unicode-xid v0.0.4
   Compiling quote v0.3.15
   Compiling libc v0.2.36
   Compiling num-traits v0.2.0
   Compiling serde v1.0.27
   Compiling dtoa v0.4.2
   Compiling itoa v0.3.4
   Compiling getopts v0.2.17
   Compiling synom v0.11.3
   Compiling memchr v2.0.1
   Compiling num-traits v0.1.43
   Compiling syn v0.11.11
   Compiling nom v4.0.0-beta2
   Compiling serde_derive_internals v0.19.0
   Compiling serde_derive v1.0.27
   Compiling serde_json v1.0.9
   Compiling softnet-stat v1.0.0 (/home/tilmanb/git/softnet-stat)
warning: use of deprecated macro `try`: use the `?` operator instead
   --> src/main.rs:180:5
    |
180 |     try!(handle.read_to_end(&mut buf));
    |     ^^^
    |
    = note: `#[warn(deprecated)]` on by default

warning: 1 warning emitted

    Finished dev [unoptimized + debuginfo] target(s) in 14.46s

Run

 $ RUST_BACKTRACE=1 target/debug/softnet-stat
thread 'main' panicked at 'Error while parsing /proc/net/softnet_stat: Code([48, 48, 48, 48, 53, 102, 97, 52, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 10, 48, 48, 48, 48, 54, 99, 51, 52, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 49, 10, 48, 48, 48, 48, 52, 100, 102, 98, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 50, 10, 48, 48, 48, 100, 48, 101, 101, 56, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 51, 10], Many1)', src/main.rs:161:54
stack backtrace:
   0: rust_begin_unwind
             at /build/rustc-kr1vkI/rustc-1.51.0+dfsg1+llvm/library/std/src/panicking.rs:493:5
   1: std::panicking::begin_panic_fmt
             at /build/rustc-kr1vkI/rustc-1.51.0+dfsg1+llvm/library/std/src/panicking.rs:435:5
   2: softnet_stat::main
             at ./src/main.rs:161:54
   3: core::ops::function::FnOnce::call_once
             at /build/rustc-kr1vkI/rustc-1.51.0+dfsg1+llvm/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Environment Ubuntu 21.10

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.