Skip to content

Commit

Permalink
Fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
srebhan committed May 29, 2024
1 parent 475d573 commit 1ec628a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
22 changes: 11 additions & 11 deletions plugins/inputs/procstat/os_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/coreos/go-systemd/v22/dbus"
"github.com/prometheus/procfs"
gopsnet "github.com/shirou/gopsutil/v3/net"
"github.com/shirou/gopsutil/v3/net"
"github.com/shirou/gopsutil/v3/process"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -162,15 +162,15 @@ func mapFdToInode(pid int32, fd uint32) (uint32, error) {
return uint32(inode), nil
}

func statsTCP(conns []gopsnet.ConnectionStat, family uint8) ([]map[string]interface{}, error) {
func statsTCP(conns []net.ConnectionStat, family uint8) ([]map[string]interface{}, error) {
if len(conns) == 0 {
return nil, nil
}

// For TCP we need the inode for each connection to relate the connection
// statistics to the actual process socket. Therefore, map the
// file-descriptors to inodes using the /proc/<pid>/fd entries.
inodes := make(map[uint32]gopsnet.ConnectionStat, len(conns))
inodes := make(map[uint32]net.ConnectionStat, len(conns))
for _, c := range conns {
inode, err := mapFdToInode(c.Pid, c.Fd)
if err != nil {
Expand Down Expand Up @@ -226,15 +226,15 @@ func statsTCP(conns []gopsnet.ConnectionStat, family uint8) ([]map[string]interf
return fieldslist, nil
}

func statsUDP(conns []gopsnet.ConnectionStat, family uint8) ([]map[string]interface{}, error) {
func statsUDP(conns []net.ConnectionStat, family uint8) ([]map[string]interface{}, error) {
if len(conns) == 0 {
return nil, nil
}

// For UDP we need the inode for each connection to relate the connection
// statistics to the actual process socket. Therefore, map the
// file-descriptors to inodes using the /proc/<pid>/fd entries.
inodes := make(map[uint32]gopsnet.ConnectionStat, len(conns))
inodes := make(map[uint32]net.ConnectionStat, len(conns))
for _, c := range conns {
inode, err := mapFdToInode(c.Pid, c.Fd)
if err != nil {
Expand Down Expand Up @@ -285,11 +285,11 @@ func statsUDP(conns []gopsnet.ConnectionStat, family uint8) ([]map[string]interf
return fieldslist, nil
}

func statsUnix(conns []gopsnet.ConnectionStat) ([]map[string]interface{}, error) {
func statsUnix(conns []net.ConnectionStat) ([]map[string]interface{}, error) {
// We need to read the inode for each connection to relate the connection
// statistics to the actual process socket. Therefore, map the
// file-descriptors to inodes using the /proc/<pid>/fd entries.
inodes := make(map[uint32]gopsnet.ConnectionStat, len(conns))
inodes := make(map[uint32]net.ConnectionStat, len(conns))
for _, c := range conns {
inodes[c.Fd] = c
}
Expand Down Expand Up @@ -330,7 +330,7 @@ func statsUnix(conns []gopsnet.ConnectionStat) ([]map[string]interface{}, error)
return fieldslist, nil
}

func unixConnectionsPid(pid int32) ([]gopsnet.ConnectionStat, error) {
func unixConnectionsPid(pid int32) ([]net.ConnectionStat, error) {
file := fmt.Sprintf("/proc/%d/net/unix", pid)

// Read the contents of the /proc file with a single read sys call.
Expand All @@ -343,7 +343,7 @@ func unixConnectionsPid(pid int32) ([]gopsnet.ConnectionStat, error) {
}

lines := bytes.Split(contents, []byte("\n"))
conns := make([]gopsnet.ConnectionStat, 0, len(lines)-1)
conns := make([]net.ConnectionStat, 0, len(lines)-1)
duplicate := make(map[string]bool, len(conns))
// skip first line
for _, line := range lines[1:] {
Expand All @@ -365,11 +365,11 @@ func unixConnectionsPid(pid int32) ([]gopsnet.ConnectionStat, error) {
path = tokens[len(tokens)-1]
}

c := gopsnet.ConnectionStat{
c := net.ConnectionStat{
Fd: uint32(inode),
Family: unix.AF_UNIX,
Type: uint32(st),
Laddr: gopsnet.Addr{IP: path},
Laddr: net.Addr{IP: path},
Pid: pid,
Status: "NONE",
}
Expand Down
3 changes: 1 addition & 2 deletions plugins/inputs/procstat/os_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"

"github.com/shirou/gopsutil/v3/net"
gopsnet "github.com/shirou/gopsutil/v3/net"
"github.com/shirou/gopsutil/v3/process"
)

Expand Down Expand Up @@ -34,7 +33,7 @@ func collectTotalReadWrite(Process) (r, w uint64, err error) {
return 0, 0, errors.ErrUnsupported
}

func unixConnectionsPid(int32) ([]gopsnet.ConnectionStat, error) {
func unixConnectionsPid(int32) ([]net.ConnectionStat, error) {
return nil, errors.ErrUnsupported
}

Expand Down
3 changes: 1 addition & 2 deletions plugins/inputs/procstat/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"unsafe"

"github.com/shirou/gopsutil/v3/net"
gopsnet "github.com/shirou/gopsutil/v3/net"
"github.com/shirou/gopsutil/v3/process"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/svc/mgr"
Expand Down Expand Up @@ -91,7 +90,7 @@ func collectTotalReadWrite(Process) (r, w uint64, err error) {
return 0, 0, errors.ErrUnsupported
}

func unixConnectionsPid(int32) ([]gopsnet.ConnectionStat, error) {
func unixConnectionsPid(int32) ([]net.ConnectionStat, error) {
return nil, errors.ErrUnsupported
}

Expand Down

0 comments on commit 1ec628a

Please sign in to comment.