You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

65 lines
2.1 KiB

  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. func (fs FS) NetTCP() (NetTCP, error) {
  25. return newNetTCP(fs.proc.Path("net/tcp"))
  26. }
  27. // NetTCP6 returns the IPv6 kernel/networking statistics for TCP datagrams
  28. // read from /proc/net/tcp6.
  29. func (fs FS) NetTCP6() (NetTCP, error) {
  30. return newNetTCP(fs.proc.Path("net/tcp6"))
  31. }
  32. // NetTCPSummary returns already computed statistics like the total queue lengths
  33. // for TCP datagrams read from /proc/net/tcp.
  34. func (fs FS) NetTCPSummary() (*NetTCPSummary, error) {
  35. return newNetTCPSummary(fs.proc.Path("net/tcp"))
  36. }
  37. // NetTCP6Summary returns already computed statistics like the total queue lengths
  38. // for TCP datagrams read from /proc/net/tcp6.
  39. func (fs FS) NetTCP6Summary() (*NetTCPSummary, error) {
  40. return newNetTCPSummary(fs.proc.Path("net/tcp6"))
  41. }
  42. // newNetTCP creates a new NetTCP{,6} from the contents of the given file.
  43. func newNetTCP(file string) (NetTCP, error) {
  44. n, err := newNetIPSocket(file)
  45. n1 := NetTCP(n)
  46. return n1, err
  47. }
  48. func newNetTCPSummary(file string) (*NetTCPSummary, error) {
  49. n, err := newNetIPSocketSummary(file)
  50. if n == nil {
  51. return nil, err
  52. }
  53. n1 := NetTCPSummary(*n)
  54. return &n1, err
  55. }