Created
September 1, 2021 03:57
-
-
Save chn-lee-yumi/43e3e9d02ad78931c76f67359653b898 to your computer and use it in GitHub Desktop.
nprocnetdev.go: print /proc/net/dev via netlink socket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// go version of https://gist.github.com/javiermon/43a0b9e1c07abd4b13df | |
import ( | |
"log" | |
"github.com/jsimonetti/rtnetlink" | |
"fmt" | |
) | |
func main() { | |
// Dial a connection to the rtnetlink socket | |
conn, err := rtnetlink.Dial(nil) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer conn.Close() | |
// Request a list of interfaces | |
msg, err := conn.Link.List() | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println("Inter-| Receive | Transmit") | |
fmt.Println(" face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed") | |
for _, value := range msg { | |
attr := value.Attributes | |
stat := attr.Stats64 | |
fmt.Printf("%6s: %7d %7d %4d %4d %4d %5d %10d %9d %8d %7d %4d %4d %4d %5d %7d %9d\n", attr.Name, | |
stat.RXBytes, stat.RXPackets, stat.RXErrors, stat.RXDropped, stat.RXFIFOErrors, stat.RXFrameErrors, stat.RXCompressed, stat.Multicast, | |
stat.TXBytes, stat.TXPackets, stat.TXErrors, stat.TXDropped, stat.TXFIFOErrors, stat.Collisions, stat.TXCarrierErrors, stat.TXCompressed) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment