-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Procstat: collect connections and listener for each proc #8755
Closed
adrianlzt
wants to merge
4
commits into
influxdata:master
from
datadope-io:feature/procstat_network_info
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
21d8899
Procstat: collect connections and listener for each proc
adrianlzt 15144a0
procstat: option to select which metrics collect
adrianlzt 81657b5
Procstat: close /proc/n/fd dirs earlier
adrianlzt 660f86f
procstat: avoid collection inode info if not being used
adrianlzt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,35 @@ Processes can be selected for monitoring using one of several methods: | |
## the native finder performs the search directly in a manor dependent on the | ||
## platform. Default is 'pgrep' | ||
# pid_finder = "pgrep" | ||
|
||
## Select wich extra metrics should be added: | ||
## - "threads": to enable collection of number of file descriptors | ||
## - "fds": to enable collection of context switches | ||
## - "ctx_switches": to enable collection of page faults | ||
## - "page_faults": to enable collection of IO | ||
## - "io": to enable collection of proc creation time | ||
## - "create_time": to enable collection of CPU time used | ||
## - "cpu": to enable collection of percentage of CPU used | ||
## - "cpu_percent": to enable collection of memory used | ||
## - "mem": to enable collection of memory percentage used | ||
## - "mem_percent": to enable collection of procs' limits | ||
## - "limits": to enable collection of procs' limits | ||
## - "tcp_stats": tcp_* and upd_socket metrics | ||
## - "connections_endpoints": new metric procstat_tcp with connections and listeners endpoints | ||
## Default value: | ||
# metrics_include = [ | ||
# "threads", | ||
# "fds", | ||
# "ctx_switches", | ||
# "page_faults", | ||
# "io", | ||
# "create_time", | ||
# "cpu", | ||
# "cpu_percent", | ||
# "mem", | ||
# "mem_percent", | ||
# "limits", | ||
# ] | ||
``` | ||
|
||
#### Windows support | ||
|
@@ -157,11 +186,49 @@ the `win_perf_counters` input plugin as a more mature alternative. | |
- running (int) | ||
- result_code (int, success = 0, lookup_error = 1) | ||
|
||
If ``connections_stats`` enabled, added fields: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be tcp_stats? |
||
- procstat | ||
- fields: | ||
- tcp_close (int) | ||
- tcp_close_wait (int) | ||
- tcp_closing (int) | ||
- tcp_established (int) | ||
- tcp_fin_wait1 (int) | ||
- tcp_fin_wait2 (int) | ||
- tcp_last_ack (int) | ||
- tcp_listen (int) | ||
- tcp_none (int) | ||
- tcp_syn_recv (int) | ||
- tcp_syn_sent (int) | ||
|
||
If ``connections_endpoints`` enabled, added fields: | ||
- procstat_tcp | ||
- tags: | ||
- pid (when `pid_tag` is true) | ||
- cmdline (when 'cmdline_tag' is true) | ||
- process_name | ||
- pidfile (when defined) | ||
- exe (when defined) | ||
- pattern (when defined) | ||
- user (when selected) | ||
- systemd_unit (when defined) | ||
- cgroup (when defined) | ||
- fields: | ||
- conn (string) | ||
- listen (string) | ||
|
||
To gather connection info, if Telegraf is not run as root, it needs the following capabilities | ||
``` | ||
sudo setcap "CAP_DAC_READ_SEARCH,CAP_SYS_PTRACE+ep" telegraf | ||
``` | ||
|
||
*NOTE: Resource limit > 2147483647 will be reported as 2147483647.* | ||
|
||
### Example Output: | ||
|
||
``` | ||
procstat_lookup,host=prash-laptop,pattern=influxd,pid_finder=pgrep,result=success pid_count=1i,running=1i,result_code=0i 1582089700000000000 | ||
procstat,host=prash-laptop,pattern=influxd,process_name=influxd,user=root involuntary_context_switches=151496i,child_minor_faults=1061i,child_major_faults=8i,cpu_time_user=2564.81,cpu_time_idle=0,cpu_time_irq=0,cpu_time_guest=0,pid=32025i,major_faults=8609i,created_at=1580107536000000000i,voluntary_context_switches=1058996i,cpu_time_system=616.98,cpu_time_steal=0,cpu_time_guest_nice=0,memory_swap=0i,memory_locked=0i,memory_usage=1.7797634601593018,num_threads=18i,cpu_time_nice=0,cpu_time_iowait=0,cpu_time_soft_irq=0,memory_rss=148643840i,memory_vms=1435688960i,memory_data=0i,memory_stack=0i,minor_faults=1856550i 1582089700000000000 | ||
procstat,host=laptop,pattern=httpd,process_name=httpd,user=root child_major_faults=0i,child_minor_faults=70i,cpu_time=0i,cpu_time_guest=0,cpu_time_guest_nice=0,cpu_time_idle=0,cpu_time_iowait=0,cpu_time_irq=0,cpu_time_nice=0,cpu_time_soft_irq=0,cpu_time_steal=0,cpu_time_system=0.01,cpu_time_user=0.02,cpu_usage=0,created_at=1611738400000000000i,involuntary_context_switches=15i,listen=1i,major_faults=0i,memory_data=999424i,memory_locked=0i,memory_rss=4677632i,memory_stack=135168i,memory_swap=0i,memory_usage=0.013990458101034164,memory_vms=6078464i,minor_faults=1636i,nice_priority=20i,num_fds=8i,num_threads=1i,pid=1738811i,read_bytes=0i,read_count=4397i,realtime_priority=0i,rlimit_cpu_time_hard=2147483647i,rlimit_cpu_time_soft=2147483647i,rlimit_file_locks_hard=2147483647i,rlimit_file_locks_soft=2147483647i,rlimit_memory_data_hard=2147483647i,rlimit_memory_data_soft=2147483647i,rlimit_memory_locked_hard=65536i,rlimit_memory_locked_soft=65536i,rlimit_memory_rss_hard=2147483647i,rlimit_memory_rss_soft=2147483647i,rlimit_memory_stack_hard=2147483647i,rlimit_memory_stack_soft=8388608i,rlimit_memory_vms_hard=2147483647i,rlimit_memory_vms_soft=2147483647i,rlimit_nice_priority_hard=0i,rlimit_nice_priority_soft=0i,rlimit_num_fds_hard=1048576i,rlimit_num_fds_soft=1048576i,rlimit_realtime_priority_hard=0i,rlimit_realtime_priority_soft=0i,rlimit_signals_pending_hard=127473i,rlimit_signals_pending_soft=127473i,signals_pending=0i,tcp_close=0i,tcp_close_wait=0i,tcp_closing=0i,tcp_established=0i,tcp_fin_wait1=0i,tcp_fin_wait2=0i,tcp_last_ack=0i,tcp_listen=1i,tcp_syn_recv=0i,tcp_syn_sent=0i,voluntary_context_switches=169i,write_bytes=53248i,write_count=10i 1611738522000000000 | ||
procstat_tcp,host=laptop,pattern=httpd,process_name=httpd,user=root conn="",listen="192.168.1.35:80,192.168.1.48:80,[da01:beef:234:3830:aeda:f001:a00c:0091]:80,[aa01:beef:234:3830:e8e:0000:000a:6b0f]:80" 1611738522000000000 | ||
``` |
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 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing h update to
which