net_udp.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // NetUDP represents the contents of /proc/net/udp{,6} file without the header.
  16. NetUDP []*netIPSocketLine
  17. // NetUDPSummary provides already computed values like the total queue lengths or
  18. // the total number of used sockets. In contrast to NetUDP it does not collect
  19. // the parsed lines into a slice.
  20. NetUDPSummary NetIPSocketSummary
  21. )
  22. // NetUDP returns the IPv4 kernel/networking statistics for UDP datagrams
  23. // read from /proc/net/udp.
  24. func (fs FS) NetUDP() (NetUDP, error) {
  25. return newNetUDP(fs.proc.Path("net/udp"))
  26. }
  27. // NetUDP6 returns the IPv6 kernel/networking statistics for UDP datagrams
  28. // read from /proc/net/udp6.
  29. func (fs FS) NetUDP6() (NetUDP, error) {
  30. return newNetUDP(fs.proc.Path("net/udp6"))
  31. }
  32. // NetUDPSummary returns already computed statistics like the total queue lengths
  33. // for UDP datagrams read from /proc/net/udp.
  34. func (fs FS) NetUDPSummary() (*NetUDPSummary, error) {
  35. return newNetUDPSummary(fs.proc.Path("net/udp"))
  36. }
  37. // NetUDP6Summary returns already computed statistics like the total queue lengths
  38. // for UDP datagrams read from /proc/net/udp6.
  39. func (fs FS) NetUDP6Summary() (*NetUDPSummary, error) {
  40. return newNetUDPSummary(fs.proc.Path("net/udp6"))
  41. }
  42. // newNetUDP creates a new NetUDP{,6} from the contents of the given file.
  43. func newNetUDP(file string) (NetUDP, error) {
  44. n, err := newNetIPSocket(file)
  45. n1 := NetUDP(n)
  46. return n1, err
  47. }
  48. func newNetUDPSummary(file string) (*NetUDPSummary, error) {
  49. n, err := newNetIPSocketSummary(file)
  50. if n == nil {
  51. return nil, err
  52. }
  53. n1 := NetUDPSummary(*n)
  54. return &n1, err
  55. }