-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Procstat: collect connections and listener for each proc
Procstat modified to add a new metric "procstat_tcp" with to values "conn" and "listen". It also adds number of connections for each TCP state. Those metrics will be added only if it they are activated specifically. Those values will contain a comma separated value of the endpoints where the proc is connecting to or listening (IPv4 and IPv6). Only for linux. Local, virtual and docker interfaces are ignored. If some proc is listening on 0.0.0.0, an endpoint for each of the "public" (those not ignored as internal) IPv4 IPs is created. If it is listening on :: (IPv6) an endpoint is created for each IPv4 and IPv6. For programs with one parent and several children, all listening in some endpoint, only the parent process is taken into account. Child endpoints are ignored. Connections made to this cost (local port is one of the listening ports) are ignored. To avoid having servers with thousands of connections. We prefer to collect that info in the clients. It is also added connection info (number of connections in each of the TCP states) for each proc. Improving PR #5402 To gather tcp connections netlink is used, to avoid the cost of parsing /proc/net/tcp(6), but /proc should be readed to get the mapping between inodes and pids.
- Loading branch information
Showing
13 changed files
with
1,245 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package procstat | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
) | ||
|
||
const ( | ||
// DockerMACPrefix https://macaddress.io/faq/how-to-recognise-a-docker-container-by-its-mac-address | ||
DockerMACPrefix = "02:42" | ||
// VirtualBoxMACPrefix https://github.com/mdaniel/virtualbox-org-svn-vbox-trunk/blob/2d259f948bc352ee400f9fd41c4a08710cd9138a/src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdp.c#L93 | ||
VirtualBoxMACPrefix = "0a:00:27" | ||
// HardwareAddrLength is the number of bytes of a MAC address | ||
HardwareAddrLength = 6 | ||
) | ||
|
||
var ( | ||
// ErrorPIDNotFound is the error generated when the pid does not have network info | ||
ErrorPIDNotFound = fmt.Errorf("pid not found") | ||
) | ||
|
||
// InodeInfo represents information of a proc associated with an inode | ||
type InodeInfo struct { | ||
pid uint32 | ||
ppid uint32 | ||
} | ||
|
||
// NetworkInfo implements NetworkInfo using the netlink calls and parsing /proc to map sockets to PIDs | ||
type NetworkInfo struct { | ||
// tcp contains the connection info for each pid | ||
tcp map[uint32][]ConnInfo | ||
// listenPorts is a map with the listen ports in the host, used to ignore inbound connections | ||
listenPorts map[uint32]interface{} | ||
// publicIPs list of IPs considered "public" (used to connect to other hosts) | ||
publicIPs []net.IP | ||
// privateIPs list of IPs considered "private" (loopback, virtual interfaces, point2point, etc) | ||
privateIPs []net.IP | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// +build !linux | ||
|
||
package procstat | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
) | ||
|
||
type ConnInfo struct { | ||
} | ||
|
||
func (n *NetworkInfo) IsAListenPort(port uint32) bool { | ||
return false | ||
} | ||
|
||
func (n *NetworkInfo) Fetch() error { | ||
return fmt.Errorf("platform not supported") | ||
} | ||
|
||
func (n *NetworkInfo) GetConnectionsByPid(pid uint32) (conn []ConnInfo, err error) { | ||
return conn, fmt.Errorf("platform not supported") | ||
} | ||
|
||
func (n *NetworkInfo) GetPublicIPs() []net.IP { | ||
return []net.IP{} | ||
} | ||
|
||
func (n *NetworkInfo) GetPrivateIPs() []net.IP { | ||
return []net.IP{} | ||
} | ||
|
||
func (n *NetworkInfo) IsPidListeningInAddr(pid uint32, ip net.IP, port uint32) bool { | ||
return false | ||
} |
Oops, something went wrong.