forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(inputs.procstat): add tcp related metrics
For a given process, return the number of connections in each state: SYN_SENT, SYN_RECV, ESTABLISHED, etc. Also added a new measurement, procstat_tcp, that returns the endpoints where the process is connected to and where it is listening. If it is listening in "[::]" or "0.0.0.0", resolve with the local IPs.
- Loading branch information
Showing
13 changed files
with
1,284 additions
and
58 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,36 @@ | ||
package procstat | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
) | ||
|
||
const ( | ||
// dockerMACPrefix https://macaddress.io/faq/how-to-recognise-a-docker-container-by-its-mac-address | ||
dockerMACPrefix = "02:42" | ||
//nolint:lll // avoid splitting the link | ||
// 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 | ||
) | ||
|
||
// errPIDNotFound is the error generated when the pid does not have network info | ||
var errPIDNotFound = fmt.Errorf("pid not found") | ||
|
||
// inodeInfo represents information of a proc associated with an inode | ||
type inodeInfo struct { | ||
pid 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 @@ | ||
//go:build !linux | ||
// +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 nil | ||
} | ||
|
||
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.