net_tcp.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2020 The Prometheus Authors
  2. // Licensed under the Apache License, Version 2.0 (the "License");
  3. // you may not use this file except in compliance with the License.
  4. // You may obtain a copy of the License at
  5. //
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. package procfs
  14. type (
  15. // NetTCP represents the contents of /proc/net/tcp{,6} file without the header.
  16. NetTCP []*netIPSocketLine
  17. // NetTCPSummary provides already computed values like the total queue lengths or
  18. // the total number of used sockets. In contrast to NetTCP it does not collect
  19. // the parsed lines into a slice.
  20. NetTCPSummary NetIPSocketSummary
  21. )
  22. // NetTCP returns the IPv4 kernel/networking statistics for TCP datagrams
  23. // read from /proc/net/tcp.
  24. // Deprecated: Use github.com/mdlayher/netlink#Conn (with syscall.AF_INET) instead.
  25. func (fs FS) NetTCP() (NetTCP, error) {
  26. return newNetTCP(fs.proc.Path("net/tcp"))
  27. }
  28. // NetTCP6 returns the IPv6 kernel/networking statistics for TCP datagrams
  29. // read from /proc/net/tcp6.
  30. // Deprecated: Use github.com/mdlayher/netlink#Conn (with syscall.AF_INET6) instead.
  31. func (fs FS) NetTCP6() (NetTCP, error) {
  32. return newNetTCP(fs.proc.Path("net/tcp6"))
  33. }
  34. // NetTCPSummary returns already computed statistics like the total queue lengths
  35. // for TCP datagrams read from /proc/net/tcp.
  36. // Deprecated: Use github.com/mdlayher/netlink#Conn (with syscall.AF_INET) instead.
  37. func (fs FS) NetTCPSummary() (*NetTCPSummary, error) {
  38. return newNetTCPSummary(fs.proc.Path("net/tcp"))
  39. }
  40. // NetTCP6Summary returns already computed statistics like the total queue lengths
  41. // for TCP datagrams read from /proc/net/tcp6.
  42. // Deprecated: Use github.com/mdlayher/netlink#Conn (with syscall.AF_INET6) instead.
  43. func (fs FS) NetTCP6Summary() (*NetTCPSummary, error) {
  44. return newNetTCPSummary(fs.proc.Path("net/tcp6"))
  45. }
  46. // newNetTCP creates a new NetTCP{,6} from the contents of the given file.
  47. func newNetTCP(file string) (NetTCP, error) {
  48. n, err := newNetIPSocket(file)
  49. n1 := NetTCP(n)
  50. return n1, err
  51. }
  52. func newNetTCPSummary(file string) (*NetTCPSummary, error) {
  53. n, err := newNetIPSocketSummary(file)
  54. if n == nil {
  55. return nil, err
  56. }
  57. n1 := NetTCPSummary(*n)
  58. return &n1, err
  59. }