ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] > [github](https://github.com/rfyiamcool/go-netflow) ## 概述 ## 依赖 ``` yum install libpcap yum install libpcap-devel ``` ## 示例 ### go run cmd/main.go <details> <summary>main.go</summary> ``` package main import ( "encoding/json" "fmt" "time" "github.com/rfyiamcool/go-netflow" ) func main() { nf, err := netflow.New( netflow.WithCaptureTimeout(5 * time.Second), ) if err != nil { panic(err) } err = nf.Start() if err != nil { panic(err) } defer nf.Stop() <-nf.Done() var ( limit = 5 recentSec = 5 ) rank, err := nf.GetProcessRank(limit, recentSec) if err != nil { panic(err) } bs, err := json.MarshalIndent(rank, "", " ") if err != nil { panic(err) } fmt.Println(string(bs)) } ``` </details> <br/> ``` +---------+-------+------------------------------------------------+--------+--------+---------+---------+----------+ | PID | NAME | EXE | INODES | SUM IN | SUM OUT | IN RATE | OUT RATE | +---------+-------+------------------------------------------------+--------+--------+---------+---------+----------+ | 2256431 | Wget | /usr/bin/wget | 1 | 1.0 MB | 0 B | 339 kB | 0 B | +---------+-------+------------------------------------------------+--------+--------+---------+---------+----------+ | 2257200 | Wrk | /usr/bin/wrk | 5 | 2.0 MB | 16 kB | 653 kB | 5.2 kB | +---------+-------+------------------------------------------------+--------+--------+---------+---------+----------+ | 3707954 | Java | /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java | 10 | 457 B | 648 B | 152 B | 216 B | +---------+-------+------------------------------------------------+--------+--------+---------+---------+----------+ | 2245136 | Wget | /usr/bin/wget | 1 | 444 kB | 0 B | 148 kB | 0 B | +---------+-------+------------------------------------------------+--------+--------+---------+---------+----------+ | 2034103 | Nginx | /usr/sbin/nginx | 41 | 0 B | 0 B | 0 B | 0 B | +---------+-------+------------------------------------------------+--------+--------+---------+---------+----------+ ```