Commit Graph

178 Commits (master)

Author SHA1 Message Date
shirou 0969c9436b delete v2 directory, move v3 to top #1078 3 years ago
shirou 3d97fc18f4 add check if it runs on CI 4 years ago
shirou c6bd05a3e9 relax net/NetIOCountersAll test.
It often fails in CI.
4 years ago
MashaSamoylova 7631bb0e5e Fix lsof args for udp4 in unix 4 years ago
shirou 34412e0b7f [net] relax NetIOCounterAll test 4 years ago
shirou 6286bea32a
Merge pull request #989 from Lomanic/issue734tests
[ci] Implement automatic tests on GH Actions on linux, windows and darwin
4 years ago
Lomanic 64e16cc8c3 [net][darwin] Fix tests with mismatched types 4 years ago
Lomanic 7f0ba43398 [net][darwin][freebsd] Fix tests with func not returning common.ErrNotImplementedError 4 years ago
MashaSamoylova 860f332c22 Fix getting udp6 ports 4 years ago
shirou f377a07e5a fix test and openbsd errors. 4 years ago
Sergey Vinogradov 8ff2ab3187 Add "vet" target to the Makefile
Making the "vet" target will run "go vet ./..." for each supported
GOOS.

Also, some of the warnings produced by go 1.15 vet were mitigated.
4 years ago
Lomanic 4cfc60d68b
Merge pull request #928 from Lomanic/skip-tests-when-not-implemented 5 years ago
Lomanic e1925b853e
Merge pull request #935 from Lomanic/issue900
[linux] Fix #900, skip or fix failing tests in docker
5 years ago
Lomanic 1b3e0c6643 [linux] Fix #900, skip or fix failing tests in docker
TestGetProcInodesAll: create a server so there are some opened inodes
TestUsers: skip if Users is empty, because of an empty /var/run/utmp
Test_Process_Groups: skip if Groups is empty
TestConnectionsMax: skip on CI, not only CircleCI
5 years ago
Lomanic ab084b525c [net] Skip tests on non-implemented platforms #446 5 years ago
Disconnect3d 5c1a9e709d net_linux.go: decode port as 16-bit uint
Changes the port parsing from `/proc/net/*` files records from parsing them as 64-bit integers to parse them as 16-bit unsigned integers.

While this is mostly a cosmetic change, it will also make so that the code fails faster in case the entry is malformed (for whatever reason).

Note that the returned value is still casted to uint32 when an  `Addr` object is created.
It seems to me that the `Addr.port` field should be changed to `uint16` but maybe some other APIs/systems wants it to be `uint32` and also changing it there may require changes in users code if they update. This being said I am not changing that field's type.
5 years ago
gtosh4 936d3b27f1
Don't ignore context for io counters 5 years ago
shirou 53cec6b37e
Merge pull request #839 from tklauser/move-parse-funcs
net: move parseNetLine and parseNetAddr to net_unix.go
5 years ago
Tobias Klauser 22d8ee41e5 net: move parseNetLine and parseNetAddr to net_unix.go
These funcs are only used in net_unix.go which is only compiled for
darwin and freebsd.
5 years ago
Clément Chigot 77ff16c081 net: add AIX support 5 years ago
Brian C. Williams f00df5cffe Add WithoutUids funcs 5 years ago
Snow Fox 018950cf06
Merge pull request #2 from shirou/master
merge master
6 years ago
litong 1f9466536e Add ifIndex support 6 years ago
litong 7ffe40e0db Add ifIndex support 6 years ago
Lomanic 6a8ab0308e [net][linux] Go fmt net/net_linux.go 6 years ago
chi-chi weng 809306b78a
Fix the net.ConnectionsMax BUG
`connectionsList, err := net.ConnectionsMax("tcp4", 1000)`
when you run net.ConnectionsMax,you will find some proc is not equal with the `netstat -lptn`
6 years ago
Lomanic 658804ae70
Merge pull request #697 from Lomanic/issue693
[net][windows] Fix #693 use MIB_IF_ROW2/GetIfEntry2 to get real uint64 values from win32 API
6 years ago
Lomanic 3fb9243fc2 [net][windows] Fix #693 use MIB_IF_ROW2/GetIfEntry2 to get real uint64 values from win32 API 6 years ago
Curtis Mattoon 648bf4eebc Adds ConntrackStats to get conntrack summary stats 6 years ago
Segflow 86c7289ccc Fix: use filename in exec.LookPath instead of full path
exec.LookPath searches for the file in the $PATH, which mean giving it an absolute path is against it's own purposes.
6 years ago
mingrammer 017c9f9cbc Fix typos 6 years ago
Joe Stringer f87d9813da [net][linux] Support socket tables in nested namespaces
Signed-off-by: Joe Stringer <joe@cilium.io>
6 years ago
Iskander Sharipov 3684fce88a net: use multi-value case clause instead of fallthrough
Found using https://go-critic.github.io/overview#emptyFallthrough-ref
7 years ago
Lomanic eb1f1ab16f
Merge pull request #549 from pytimer/win_net
[net] Implements windows net package Connections and ConnectionsPid
7 years ago
Lomanic ef54649286 [windows] Use windows.NewLazySystemDLL to (possibly) prevent DLL hijacking
Might be useless because of https://docs.microsoft.com/en-us/windows/desktop/dlls/dynamic-link-library-search-order#search-order-for-desktop-applications
but better be safe than sorry.

Ref: https://github.com/shirou/gopsutil/issues/570#issuecomment-413951653
7 years ago
pytimer 0ffcfc901f [net][windows] Remove exported types and convert ALL_CAPS to mixedCaps 7 years ago
pytimer 1c2cebbbc4 [net] Implements windows net package function Connections and ConnectionsPid 7 years ago
Kamil Dziedzic b76d065dff
PMM-2643: Support listing unix sockets in ConnectionsPid and ConnectionsPidWithContext.
Signed-off-by: Kamil Dziedzic <arvenil@klecza.pl>
7 years ago
Michal Rostecki 9d003ad2e1 net: Check for error object 7 years ago
shirou 145dca90f7 change to use CommandContext. 7 years ago
Laurie Clark-Michalek 413cb32b6c Use static initialisation for invoke instances, instead of init funcs
The order of init function execution is dependant on the order that the
source files are passed to the compiler. This causes issues when
building under other build systems, such as bazel or buck, as they are
not guarenteed to maintain the same file order as the default go tool.
7 years ago
shirou 4c73494c78 Add WithContext functions. 7 years ago
Daniel Nelson 6abd227e48
[net] linux: skip if not exist error on getProcInodesAll 7 years ago
Marco Pfatschbacher df6462b50e Fix PR comments made by shirou 7 years ago
Marco Pfatschbacher 6e7aca41d7 Implement Connection support for OpenBSD
This retrieves open TCP/UDP connections by using netstat(1)
File descriptors and pids are not supported.
7 years ago
shirou e01a14e318 [net] linux: skip if permission error on getProcInodesAll
This fixes #433
8 years ago
WAKAYAMA Shirou 09e9859714 [net]linux: return err. 8 years ago
better88 86af477d1a err omit in getProcInodes 8 years ago
Sean Chittenden 635b971c0e
Move from the `syscall` package to the `golang.org/x/sys/{unix,windows}` 8 years ago
Alexander Blagoev b32353f094 Add comments with a short explanation and link to the PR request 8 years ago
Alexander Blagoev 531f9507d2 Read /proc/net files with a single read syscall.
The /proc/net files are not guaranteed to be consistent, they are only
consitent on the row level. This is probably one of the reasons why
consequent read calls might return duplicate entries - the kernel is
changing the file as it is being read. In certain situations this might
lead to loop like situations - the same net entry is being returned when
reading the file as new connections are added to the kernel tcp table, i.e
there can be a lot of duplications.

This commit is trying to reduce the duplications, by fetching the contents
of the net files with a single read syscall.
8 years ago
shirou c251591dc7 Merge pull request #355 from sean-/fix-lint-errors
Fix lint errors
8 years ago
shirou 9af92986dd Merge pull request #358 from ablagoev/optimize-net-connections
Fromat socketType properly in tcp duplication check key
8 years ago
Alexander Blagoev 5a0a97f400 Fromat socketType properly in tcp duplication check key 8 years ago
shirou b066db40c7 Merge pull request #356 from ablagoev/optimize-net-connections
Optimize memory usage for net.Connections on Linux
8 years ago
Alexander Blagoev 11e78812ae Build duplicate tcp connection ID in Connections for better readbility 8 years ago
Alexander Blagoev f7dd4f97c7 Improve /proc/net/dev parsing to include all edge cases 8 years ago
Alexander Blagoev 51e4fb77cf Add socket state to TCP connection key 8 years ago
Alexander Blagoev daaadd4f1e Optimize memory usage for net.Connections on Linux 8 years ago
Sean Chittenden 23a4ae3369
`gofmt -s -w .` 8 years ago
Sean Chittenden d0e40ff723
Fix issues reported by golint. 8 years ago
Toshi Piazza 5e1c2fa23b Fixes memory leak 8 years ago
Peter De Cleyn e8fc31359b Added support to alias interfaces (e.g., ifname0:1) 8 years ago
Cameron Sparr a213bf5e6d
run go fmt ./... 8 years ago
Conor Branagan 276c873f0d Fast duplication check in inodes processing.
Instead of encoding a JSON string of each connection (non-trivial at high
connection volumes) we can use the connTmp struct for map look-ups if we
eliminate the unused `uids` field.

Also switches to using the empty struct instead of bool for zero memory
overhead.
8 years ago
WAKAYAMA Shirou 42156fdf0d [net]linux: fix NetFilterCounters filename 8 years ago
Conor Branagan df61ef6d5f Add stub functions for ConnectionsMax in other OS versions. 8 years ago
Conor Branagan 198e65c801 Add ConnectionsMax function that limits connections per pid.
The goal is to improve performance of connection fetching connections across
all processes when some processes can have several hundred or thousands of file
descriptors. Right now when you have many thousands of fds the process spends
lots of time inside the syscalls from Readdir and Readlink.

The public API works as before with two new functions:

- `ConnectionsMax`
- `ConnectionsPidMax`

Each function takes an additional int argument that sets the max number of fds
read per process.
8 years ago
Cameron Sparr d74d84e593 Fix /proc/net/dev dropOut and fifoOut indices
fixes #284
8 years ago
Marco Pfatschbacher b4846b445b Add support for OpenBSD/amd64
This code is based on the FreeBSD version
and implements roughly the same feature set.
8 years ago
Cameron Sparr 5af5f08785 Fix NetIOCounter windows interface behavior
addresses a few things:

- Windows has a concept of both a network "interface" and an "adapter"
- These are almost always a one-to-one relationship, though there can be
esoteric instances where they are not.
- I believe the gopsutil NetIOCounters function should only return on a
per-interface level, since this is the behavior on linux/darwin.

Previously, the plugin was basically ignoring the actual interfaces
returned from net.Interfaces(). Instead, it was looping over the net
adapters for each interface, somewhat uselessly.

FWIW, the code for getAdapterList() doesn't exist in the Go standard lib
anymore.

closes #245
9 years ago
Jean Kahrs e004ef15e1 remove unused code 9 years ago
Jean Kahrs d6f5a9e920 fix net_test.go 9 years ago
Jean Kahrs 98a0a30dca update test 9 years ago
Jean Kahrs ab24c97439 break import cycle 9 years ago
Jean Kahrs cba0992ab3 add Uids field to net_linux 9 years ago
Bruno Clermont 3f96312057 only run ifconfig/netstat if necessary, add some tests 9 years ago
Bruno Clermont 145e48efdb actually there is 13 columns, not 12 9 years ago
Bruno Clermont 57ffe3b1ef Support interface with multiple digits 9 years ago
Lukas Fittl da9fa1162b Add fallback code for all unsupported operating systems.
This enables using gopsutil in a codebase that gets built on other OSes
than the ones supported. Instead of a build failure as before, due to
the build tags, gopsutil will now throw an "not implemented" runtime
error.

Fixes #234.
9 years ago
sandlbn 480ccb89e1 Added support for linux net interface fifo errors 9 years ago
Shirou WAKAYAMA 57f6aebc7e add Timeout to invoke command and use common.Invoke refs: #201 9 years ago
Shirou WAKAYAMA bce9212def fix build bugs. 9 years ago
Shirou WAKAYAMA 613a8a90e1 fixed by golint. 9 years ago
Shirou WAKAYAMA 4bb84648bf JSON representation is renamed to fit Google JSON style, camelCase. 9 years ago
Shirou WAKAYAMA ea152ea901 [BREAKING CHANGE] rename functions to pass golint. ex) net.NetIOCounters -> net.IOCounters 9 years ago
Shirou WAKAYAMA 1f32ce1bb3 [net]linux: skip if "/proc/sys/net" is not exists on test environment. 9 years ago
Shirou WAKAYAMA 34b63e671b [net]linux: add a test and fix private field name. 9 years ago
Shirou WAKAYAMA 567da004c5 [net]linux: explicit skip CI. 9 years ago
Shirou WAKAYAMA 32fa88eb49 [net]linux: TestGetProcInodes will fail on CI. 9 years ago
Shirou WAKAYAMA 31439aa6b5 [net]linux: fix valious bugs in NetConnections. 9 years ago
Shirou WAKAYAMA e4ddff09d5 [net]linux: add process_unix for NetConnections. 9 years ago
Shirou WAKAYAMA 32c62b5d48 [net]linux: implement processInet(). 9 years ago
Shirou WAKAYAMA 6c352016d8 [net]linux: start replacing lsof. still work in progress. 9 years ago
Shirou WAKAYAMA d680853370 net,process[linux]: add process.NetIOCounter and net.NetIOCounterByFile. 9 years ago
Masayoshi Sekimura 3a1fa5dc80 format go program with go 1.5.2 "go fmt" 9 years ago
shirou f58654fa1c Merge pull request #122 from jimmystewpot/add_netfilter
Add nf_conntrack counter support
9 years ago
Cameron Sparr 432bcbd056 Add -W flag to netstat on BSD systems
This prevents netstat from truncating the interface name to 5
characters. See https://github.com/influxdb/telegraf/issues/438
9 years ago
shirou dc452207f2 Merge pull request #128 from ontsysmattholcomb/use-env-proto-counters
using HostProc for protocounters in linux
9 years ago
Nikolay Sivko 906df3ed85 [net] fix panic on freebsd (netstat error with exit code 0) 9 years ago