Git Product home page Git Product logo

ifplugo's Introduction

ifplugo

GoDoc CircleCI

ifplugo delivers network interface link information and link changes. It does this (on Linux) by querying kernel ioctls to gather the necessary status information, then emits a status summary on a given channel. This summary (LinkStatusSample) is emitted on the first invocation and each time the state changes for at least one monitored interface.

type LinkStatusSample struct {
    Ifaces  map[string]InterfaceStatus
}

where InterfaceStatus can be:

const (
    // InterfaceUnknown represents an interface with no assigned state.
    InterfaceUnknown InterfaceStatus = iota
    // InterfaceUp represents an interface with a cable connected.
    InterfaceUp
    // InterfaceDown represents an interface with no cable connected.
    InterfaceDown
    // InterfaceErr represents an interface with errors querying its status.
    InterfaceErr
)

These summaries can then easily be consumed (example):

outchan := make(chan ifplugo.LinkStatusSample)
mon := ifplugo.MakeLinkStatusMonitor(2 * time.Second, []string{"eth0"}, outchan)
go func() {
    for v := range outchan {
        for k, v := range v.Ifaces {
            fmt.Printf("%s: %s\n", k, v)
        }
    }
}()
mon.Run()

It is also possible to determine the status of an interface from whether any data is flowing or not. This can be useful if, for example, the interesting interface is only connected to one way of the physical connection (RX or TX) or for other reasons can not complete autonegotiation. Use CheckIncomingDelta() in this case, it allows to also mark an interface as 'up' and seeing traffic if a certain threshold of received bytes is exceeded during one polling period. Example:

mon.CheckIncomingDelta(true, 1000)

This would, for example, also mark an interface as up if more than 1000 bytes are received during the polling period, and mark the interface as down if there are ever less than 1000 bytes received in a polling period.

Platform restrictions

Obviously, this works on Linux only.

Example

See the source code of the simple command line tools in cmd/* for more simple examples of how to use ifplugo.

$ ifplugo-watch eth0,eth1,eth2,eth3
eth0: link
eth1: link
eth2: link
eth3: no link
^C
$

Authors

Sascha Steinbiss <sascha (at) steinbiss (dot) name>.

License

MIT

ifplugo's People

Contributors

hillu avatar satta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

hillu triplekill

ifplugo's Issues

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.