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. // 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. }