Git Product home page Git Product logo

cnetstat's Introduction

cnetstat: a container-aware netstat

cnetstat dumps a list of TCP connections on a host, with their Kubernetes container and pod names if they are from a container. It currently assumes that the containers run on Docker, with labels in the format that my version of Kubelet uses.

To get an x86-64 binary, download the latest release like this:

curl -L https://github.com/microsoft/cnetstat/releases/latest/download/cnetstat.x86_64 > cnetstat

Make it executable:

chmod +x ./cnetstat

and then run it like this:

sudo ./cnetstat

You should see output like this:

Namespace  Pod       Container    Protocol  Local Host        Local Port  Remote Host  Remote Port  Connection State
myapp      frontend  fe-server    https     aks-nodepool1-23  4592        10.2.9.76    https        ESTABLISHED
myapp      backend   be-server    https     aks-nodepool1-23  6820        10.2.10.82   https        ESTABLISHED
myapp      backend   log-scraper  https     aks-nodepool1-23  7819        10.2.9.83    https        TIME_WAIT

If you want JSON output, try this:

sudo ./cnetstat --format=json

If you want to count connections per origin/destination pair, use the --summaryStatistics option.

(To run on other architectures, you'll need to build from source. There are instructions in the contributing doc.

Why cnetstat?

We built cnetstat to help figure out which containers in a Kubernetes cluster were using up TCP ports by opening lots of short-lived outbound connections.

You might want to use cnetstat if you have that problem, or any problem related to the interaction of container-level and host-level networking. We hope cnetstat will be helpful to you too.

Design and Roadmap

See the design doc.

Getting Involved

Is there a feature that would make cnetstat more useful for you? Are you hitting a bug? Is the documentation unclear or lacking? Please let us know!

See the contributing doc for the details.

Whether it's a feature, a bug report, or anything else, your contributions make cnetstat better for everyone. Thank you.

cnetstat's People

Contributors

microsoft-github-operations[bot] avatar microsoftopensource avatar noahl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cnetstat's Issues

After install cnetstat only returns error message

after installing cnetstat into my Docker image like so:

FROM ubuntu:22.04
...
RUN curl -L "https://github.com/microsoft/cnetstat/releases/latest/download/cnetstat.x86_64" > /usr/local/bin/cnetstat \
 && chmod +x /usr/local/bin/cnetstat
...

and running it like so:

$ docker run --rm -it example.com/debug:latest /bin/bash
root@57c6ee799ba3:/# cnetstat 
Error: exit status 1

volume mounting /var/run/docker.sock does not help:

$ docker run --rm -it --volume /var/run/docker.sock:/var/run/docker.sock example.com/debug:latest /bin/bash
root@57c6ee799ba3:/# cnetstat 
Error: exit status 1

tools such as lsns, nsenter, etc. exist in the image

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.